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

using namespace std;

#define int long long

const int maxn = 5e5;
vector <int> g[maxn];
vector <int> c(maxn);

int c1 = 0;

void dfs(int v, int tc) {
    c[v] = tc;
    if (tc == 1) ++c1;
    for (auto u : g[v]) if (c[u] == 0) dfs(u, 3 - tc);
}

void solve() {
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        int v, u;
        cin >> v >> u;
        --v;
        --u;
        g[v].push_back(u);
        g[u].push_back(v);
    }
    dfs(0, 1);
    vector <int> ans(n);
    if (c1 <= n / 3) {
        int val = 3;
        for (int i = 0; i < n; ++i) {
            if (c[i] == 1) {
                ans[i] = val;
                val += 3;
                if (val > n) break;
            }
        }
        int id = 0;
        for (int i = val; i <= n; i += 3) {
            while (ans[id] != 0) {
                ++id;
            }
            ans[id] = i;
            ++id;
        }
        id = 0;
        for (int i = 1; i <= n; i += 3) {
            while (ans[id] != 0) ++id;
            ans[id] = i;
            ++id;
        }
        id = 0;
        for (int i = 2; i <= n; i += 3) {
            while (ans[id] != 0) ++id;
            ans[id] = i;
            ++id;
        }
    }
    else if (n - c1 <= n / 3) {
        int val = 3;
        for (int i = 0; i < n; ++i) {
            if (c[i] == 2) {
                ans[i] = val;
                val += 3;
                if (val > n) break;
            }
        }
        int id = 0;
        for (int i = val; i <= n; i += 3) {
            while (ans[id] != 0) {
                ++id;
            }
            ans[id] = i;
            ++id;
        }
        id = 0;
        for (int i = 1; i <= n; i += 3) {
            while (ans[id] != 0) ++id;
            ans[id] = i;
            ++id;
        }
        id = 0;
        for (int i = 2; i <= n; i += 3) {
            while (ans[id] != 0) ++id;
            ans[id] = i;
            ++id;
        }
    }
    else {
        int id = 0;
        for (int i = 1; i <= n; i += 3) {
            while (c[id] != 1) ++id;
            ans[id] = i;
            ++id;
        }
        id = 0;
        for (int i = 2; i <= n; i += 3) {
            while (c[id] != 2) ++id;
            ans[id] = i;
            ++id;
        }
        id = 0;
        for (int i = 3; i <= n; i += 3) {
            while (ans[id] != 0) ++id;
            ans[id] = i;
            ++id;
        }
    }
    for (int i = 0; i < n; ++i) cout << ans[i] << ' ';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 27520
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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();}
template<class T> inline T sqr(T x) {return x*x;}

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int N = 10001;

int main(void){
    for(int n, a, b, c, x, res; cin >> n >> a >> b >> c >> x, n; cout << res << endl){
        res = -1;

        vi y(n);
        rep(i, n) cin >> y[i];

        int cur = 0;
        rep(i, N){
            x = i ? (a * x + b) % c:x;
            if(x == y[cur]){
                cur++;

                if(cur == n){
                    res = i;
                    break;
                }
            }
        }
    }

	return 0;
}

Measured memory_bytes: 1196
/*Problem Statement
There are 
N
 stones, numbered 
1
,
2
,
…
,
N
. For each 
i
 (
1
≤
i
≤
N
), the height of Stone 
i
 is 
h
i
.

There is a frog who is initially on Stone 
1
. He will repeat the following action some number of times to reach Stone 
N
:

If the frog is currently on Stone 
i
, jump to Stone 
i
+
1
 or Stone 
i
+
2
. Here, a cost of 
|
h
i
−
h
j
|
 is incurred, where 
j
 is the stone to land on.
Find the minimum possible total cost incurred before the frog reaches Stone 
N
.

Constraints
All values in input are integers.
2
≤
N
≤
10
5
1
≤
h
i
≤
10
4
*/
#include<vector>
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;

int jump_dp[100001];
int minjump(vector<int> & h, int n);
int minjump(vector<int> & h, int n) {

    //cout << ":n:" << n;
    if (jump_dp[n] != -1)
      return jump_dp[n];
   
    int x = minjump(h, n-1);
    int y = minjump(h, n-2);
    jump_dp[n] = min(x + abs(h[n] - h[n-1]), y + abs(h[n] - h[n-2]));
    return jump_dp[n];
}
int main()
{
    int n;
    scanf("%d" , &n);
    vector<int> heights(n);
    for(auto &x: heights)
      scanf("%d", &x);
    for(auto &x: jump_dp)
      x = -1;
    jump_dp[0] = 0;
    jump_dp[1] = abs(heights[0] - heights[1]);
    cout << minjump(heights, n-1) << endl;
    return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, h; cin >> a >> b >>h;
    int ans = (a+b)*h/2;
    cout << ans;
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
s=list(map(int,input().split()))
ans=[]
a=int(s[1]/10000)
b=int(s[1]/5000)
c=int(s[1]/1000)
for i in range(0,a+1):
    for j in range(0,b+1):
        if(s[0]-i-j>=0):        
            check=10000*i+5000*j+1000*(s[0]-i-j)
            if(check==s[1]):
                ans.append(i)
                ans.append(j)
                ans.append(s[0]-i-j)
                break
                
if(ans==[]):
    print('-1 -1 -1')
else:
    print('{} {} {}'.format(ans[0],ans[1],ans[2]))          

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


int main()
{
	string s;

	cin >> s;
	int j;
	j = s.size() % 2;

	if (j = 0)
	{
		cout << "No";
		return 0;
	}


	int i = 0;
	while (1)
	{
		if (s[i] != s[s.size()-1 - i])
		{
			cout << "No";
			return 0;
		}

		i++;
		if (i == s.size() / 2)
			break;
	}

	for (int i = 0; i < s.size() / 2; i++)
	{
		if (s[i] != s[s.size()/2-1 - i])
		{
			cout << "No";
			return 0;
		}
		if (i == s.size() / 4)
			break;
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
import heapq

a = list(map(lambda x: int(x), input().split()))


a_heap = []
for a_item in a:
  heapq.heappush(a_heap, a_item)

prev = heapq.heappop(a_heap)

answer = 0
while(len(a_heap) > 0):
  next = heapq.heappop(a_heap)
  answer = answer + (next - prev)
  prev = next

print(answer)

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

h1,m1,h2,m2,k=mii()

print(abs(h1*60+m1-(h2*60+m2))-k)

Measured memory_bytes: 72492
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy
# sys.setrecursionlimit(1000000)

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(input())
    an = [int(input()) for i in range(n)]
    assert len(an) == n

    res = 0
    prev = 0
    for i in range(n):
        avail = prev + an[i]
        res += avail // 2
        prev = avail % 2 if an[i] > 1 else 0
    print(res)

main()


Measured memory_bytes: 7708
n, m = map(int, input().split())
p = list(map(int, input().split()))
idx = [0]*(n+1)
for i, v in enumerate(p, 1):
    idx[v] = i
par = list(range(n+1))
sz = [1]*(n+1)
def union(i, j):
    i = find(i)
    j = find(j)
    if sz[i] > sz[j]:
        i, j = j, i
    par[i] = par[j]
    sz[j] += sz[i]
def find(i):
    if par[i] == i:
        return i
    par[i] = find(par[i])
    return par[i]
for _ in range(m):
    x, y = map(int, input().split())
    union(x, y)
print(sum(find(idx[i]) == find(i) for i in range(1, n+1)))

Measured memory_bytes: 16228
#include <stdio.h>
#include <math.h>
 
struct Point{
  double x, y;
};
 
void koch(int n, struct Point a, struct Point b){
  if(n == 0) return;
  struct Point s, t, u;
  double th = M_PI * 60.0 / 180.0;
 
  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
 
  koch(n - 1, a, s);
  printf("%.8f %.8f\n", s.x, s.y);
  koch(n - 1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  koch(n - 1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  koch(n - 1, t, b);
}
 
int main(){
  struct Point a, b;
  int n;
 
  scanf("%d", &n);
 
  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;
 
  printf("%.8f %.8f\n", a.x, a.y);
  koch(n, a, b);
  printf("%.8f %.8f\n", b.x, b.y);
 
  return 0;
}

Measured memory_bytes: 1804
#include <iostream>
#include <cmath>

using namespace std;
using ll = long long;

#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

int main() {
  int N; ll K;
  cin >> N >> K;
  ll A[N];
  rep(i, N)
    cin >> A[i];
  bool lower = false;
  int k_digit = 1+log2(K);

  ll ans = 0;
  rep(i, N)
    ans += A[i] >> k_digit;

  rep(d, k_digit) {
    ans *= 2;
    int D = K >> (k_digit - (d+1)) & 1;
    ll mask = 1LL << (k_digit - (d+1));
    int count = 0;
    rep(i, N)
      if (A[i] & mask)
        ++count;
    int score0 = count,
        score1 = N - count;
    if (lower) {
      ans += max(score0, score1);
      continue;
    }
    if (D == 1) {
      if (score0 >= score1) {
        ans += score0;
        lower = true;
      } else
        ans += score1;
    } else {
      ans += score0;
    }
  }
  out(ans);
  return 0;
}


Measured memory_bytes: 1024
N = int(input())
A = list(map(int,input().split()))
total = sum(A)
snk = A[0]
ari = total - snk
ans = abs(snk - ari)
for i in range(1,N-1):
  snk += A[i]
  ari -= A[i]
  ans = min(ans,abs(snk - ari))

print(ans)


Measured memory_bytes: 76784
#include<iostream>
using namespace std;
int main(){
  int a;
  cin>>a;
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if(i*j==a){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;

int main() {
	double W, H, x, y; cin >> W >> H >> x >> y;
	double gx = W / 2;
	double gy = H / 2;

	 
	printf("%0.10f", W * H / 2);
	cout <<" " << ((gx == x && gy == y) ? 1 : 0)<< endl;

	return 0;
}

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

using namespace std;

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

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

string s;

bool check(string t) {
    int cur = 0;
    rep (i, s.size()) {
        if (s[i] == t[cur]) {
            cur++;
            if (cur == 3) {
                return true;
            }
        }
    }

    return false;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int res = 0;
    int n;
    cin >> n >> s;
    rep (i, 1000) {
        string tmp = "";
        if (i < 100) tmp += '0';
        if (i < 10) tmp += '0';
        tmp += to_string(i);
        if (check(tmp)) res++;
    }
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 384
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;


int main(int argc, char *argv[]) {
	int h, w, n;
	cin >> h >> w >> n;
	cout << n / max(h, w) + (n % max(h, w) > 0 ? 1 : 0) << endl;
}









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

int main() {
  string S;
  cin >> S;
  int red_count = 0;
  int blue_count = 0;
  rep(i, S.size())
  {
    if(S[i] == '0')
      red_count++; 
  }
  blue_count = S.size() - red_count;
  int ans =   min(red_count, blue_count);
  cout << ans * 2 << endl;

  return 0;  

}

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

int main()
{
    long long n,i,counter=1;
    cin >> n;
    string s[n];
    for(i=0; i<n; i++)
    {
        cin >> s[i];
    }
    sort(s,s+n);
    for(i=0; i<n-1; i++)
    {
        if(s[i] != s[i+1])
        {
            counter++;
        }
    }
    cout << counter << endl;
}


Measured memory_bytes: 9800
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int64_t N, ans = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        ans += a - 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long 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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	ll x;
	cin >> x;
	ll ans = 0;
	while (1) {
		if (ans * (ans + 1) / 2 >= x) {
			break;
		}
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll N,P;
    cin >> N >> P;
    vector<ll> v;
    map<ll,ll> mp;
    ll p = P;
    bool isEnd = false;
    while(!isEnd){
        for(ll i=1;i<=sqrt(P);i++){
            if(i!=1&&p%i==0){
                p /= i;
                if(mp.count(i)) mp[i]++;
                else{
                    v.push_back(i);
                    mp.emplace(i,1);
                }
                break;
            }else if(i==(ll)sqrt(P)){
                if(mp.count(p)) mp[p]++;
                else{
                    v.push_back(p);
                    mp.emplace(p,1);
                }
                p /= p;
            }
            if(p==1) isEnd = true;
        }
    }
    ll out = 1;
    ll M = v.size();
    rep(i,M){
        ll n = mp[v[i]];
        while(1){
            if(n>=N){
                out *= v[i];
                n -= N;
            }
            else break;
        }
        
    }
    cout << out << endl;
    return 0;
}


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

int main() {

  int a, b;
  cin >> a >> b;
  string ans;
  
  if ( a < b ) {
	ans = "a < b";
  }else if ( a > b) {
	ans = "a > b";
  }else if ( a == b ) {
	ans = "a == b";
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3176
n, m = map(int, input().split())
a = [0] * m
b = [0] * m
first = set()
second = set()
for i in range(m):
    a[i], b[i] = map(int, input().split())
    if a[i] == 1:
        first.add(b[i])
    if b[i] == n:
        second.add(a[i])


ans = 'IMPOSSIBLE'
if first & second:
    ans = 'POSSIBLE'
print(ans)

Measured memory_bytes: 24932
import std.stdio,std.string,std.conv,std.algorithm;
import std.algorithm:rev=reverse;

int main(){
    auto input=readln.chomp.split;
    auto a=input[0].to!int;
    auto b=input[1].to!int;
    auto at=(a*13).to!int;
    auto bt=(b*10).to!int;
    foreach(y;bt..at+1){
        if((y*0.08).to!int==a&&(y*0.1).to!int==b){
            y.writeln;
            return 0;
        }   
    }   
    "-1".writeln;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

struct edge{
    int a, b, c;
    edge(){}
    edge(int _a, int _b, int _c){
        a = _a;
        b = _b;
        c = _c;
    }
};
int main() {
    class union_find{
        vector<long> parent, tree_size, tree_cost, e_below_c, e_kakutei;
    public:
        union_find(unsigned long _n) : parent(_n), tree_size(_n, 1), tree_cost(_n), e_below_c(_n, 0), e_kakutei(_n, 0){
            for(unsigned long i = 0; i < _n; ++i)parent[i] = i;
        }
        void init(vector<long long> &cost){
            for(int i = 0; i < cost.size(); ++i) tree_cost[i] = cost[i];
        }
        ll find(ll x){
            while(parent[x] != x)x = parent[x] = parent[parent[x]];
            return x;
        }
        void merge(ll a, ll b){
            a = find(a);
            b = find(b);
            if(a==b) return;
            if(tree_size[a] < tree_size[b])swap(a, b);
            tree_size[a] += tree_size[b];
            tree_cost[a] += tree_cost[b];
            e_below_c[a] += e_below_c[b];
            e_kakutei[a] += e_kakutei[b];
            parent[b] = a;
            return;
        }
        bool same(ll a, ll b){
            a = find(a);
            b = find(b);
            return a == b;
        }
        void plus_e(int cost, int a){
            a = find(a);
            ++e_below_c[a];
            if(tree_cost[a] >= cost) e_kakutei[a] = e_below_c[a];
        }
        ll get_edgenum(int a) {
            return find(a) == a ? e_kakutei[a] : 0;
        }
    };
    cin>>N>>M;
    vec x(N), ord(M);
    rep(i,N) cin>>x[i];
    vector<edge> e(0);
    rep(i,M){
        cin>>A>>B>>K;
        --A;
        --B;
        e.emplace_back(A, B, K);
        ord[i] = i;
    }
    sort(ALL(ord), [&](int x, int y){
        return e[x].c < e[y].c;
    });
    union_find uf(N + 10);
    uf.init(x);
    rep(i,M){
        edge ne = e[ord[i]];
        uf.merge(ne.a, ne.b);
        uf.plus_e(ne.c, ne.a);
    }
    int ans = M;
    rep(i,N) {
        ans -= uf.get_edgenum(i);
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
    //cout<<max_cost<<endl;
}

Measured memory_bytes: 7028
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;
int main(){
	int n;
	deque<int> d;
	cin >> n;
	int inv = 0;
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		if(inv == 0){
			d.push_back(a);
		}
		else{
			d.push_front(a);
		}
		inv ^= 1;
	}
	if(inv) reverse(d.begin(),d.end());
	for(int i : d) cout << i << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <deque>

//using namespace std;
using std::cin, std::cout, std::endl, std::string;
using ll = long long;

#define rep(countName, left, right, up) for (auto countName = left; countName < right; countName += up)
#define REP(countName, end) for (auto countName = 0; countName < end; countName++)
#define rev(countName, right, left, down) for (auto countName = right; countName >= left; countName -= down)
#define REV(countName, end) for (auto countName = end; countName >= 0; countName--)

auto solve1(ll x)
{
    auto year = 0;
    ll money = 100;

    do
    {
        year++;
        money += money / 100;
        //cout << year << " " << money << endl;
    } while (money < x);

    return year;
}

int main(void)
{
    ll x;
    cin >> x;

    cout << solve1(x) << endl;

    return 0;
}


Measured memory_bytes: 3636
import itertools
h, w, k = map(int, input().split())
s = [list(input()) for _ in range(h)]

h_list = []
w_list = []

for n in range(0, h+1):
    for conb in itertools.combinations(range(0, h), n):
        h_list.append(list(conb))
for n in range(0, w+1):
    for conb in itertools.combinations(range(0, w), n):
        w_list.append(list(conb))

ans = 0
for hh in h_list:
    for ww in w_list:
        cnt = 0
        for i in range(h):
            if i in hh:
                continue
            for j in range(w):
                if j in ww:
                    continue
                if s[i][j] == '#':
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)


Measured memory_bytes: 9224
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		double a = Double.parseDouble(std.next());
		double b = Double.parseDouble(std.next());
		double c = Math.toRadians(Double.parseDouble(std.next()));

		double s = 0.5 * a * b * Math.sin(c);
		double l = Math.pow(a*a + b*b - 2*a*b*Math.cos(c),0.5) + a + b;
		double h = 2 * s / a;

		System.out.println(String.format("%.5f", s));
		System.out.println(String.format("%.5f", l));
		System.out.println(String.format("%.5f", h));
	}
}

Measured memory_bytes: 26292
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)
#define fork(x) for (int k = 0; k < x; ++k)

int main() {
	int n,m,x;
    int c[20];int a[20][20];
    cin>>n>>m>>x;
    fori(n){
        cin>>c[i];
        forj(m){
            cin>>a[i][j];
        }
    }

    int answer=-1;
    int all=pow(2,n);
    for(int i=0;i<all;++i){
        int money=0;
        bool t[20]={};
        int p[20]={};//学習度
        int num=i;
        for(int j=0,k=2;k!=all*2;++j,k*=2){
            t[j]=(num%2==0);
            num/=2;
        }
        forj(n){
            if(t[j]){
                money+=c[j];
                fork(m){
                    p[k]+=a[j][k];
                }
            }
        }
        bool ok=true;
        forj(m){
            if(p[j]<x){
                ok=false;
                break;
            }
        }
        if(ok){
            if(answer==-1||money<answer){
                answer=money;
            }
        }
    }
    cout<<answer;
}

Measured memory_bytes: 4104
N = int(input())
LR = [list(map(int, input().split())) for _ in range(N)]

def honya(LR):
  l = LR[-1][0]
  r = LR[-1][1]
  D = [0] * N
  for i in range(N - 1, -1, -1):
    l = max(l, LR[i][0])
    r = min(r, LR[i][1])
    D[i] = max(0, r - l + 1)

  l = LR[0][0]
  r = LR[0][1]
  ans = 0
  for i in range(N - 1):
    r = min(r, LR[i][1])
    ans = max(ans, max(r - l + 1, 0) + D[i + 1])

  return ans

LR.sort(reverse = True)
#for i in range(N):
#  print(LR[i], LR[i][1] - LR[i][0])
  
ans = honya(LR)

R = 0
for i in range(N):
  R = max(R, LR[i][1])
for i in range(N):
  LR[i][0], LR[i][1] = R - LR[i][1], R - LR[i][0]
  
LR.sort(reverse = True)
ans = max(ans, honya(LR))

def honyamorake(LR):
  ans = 0
  x = 0
  for i in range(N):
    t = LR[i][1] - LR[i][0] + 1
    if t > ans:
      ans = t
      x = i
  return ans + honyapun(LR, x)

def honyapun(LR, x):
  l = 0
  r = 10 ** 10
  for i in range(N):
    if i != x:
      l = max(l, LR[i][0])
      r = min(r, LR[i][1])
  if l > r:
    return 0
  else:
    return r - l + 1

ans = max(ans, honyamorake(LR))

print(ans)

Measured memory_bytes: 66648
//Δ_E
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 1e6+16;
const int MO = 1e9+7;
int mul(int x,int y){
	return (LL)x*y%MO;
}
int n,m,d,p,fac[N],f[N];
int main()
{
	int i,o;
	cin>>n>>m>>d;
	fac[0]=1;
	for(i=1;i<=n;i=i+1)
		fac[i]=mul(fac[i-1],i);
	for(i=1;i<=n;i=i+1)
		p=(p+fac[i])%MO;
	f[0]=1;
	o=1;
	for(i=1;i<m;i=i+1){
		f[i]=mul(o,p);
		o=(o+f[i])%MO;
		if(i>=d)
			o=(o-f[i-d]+MO)%MO;
	}
	cout<<mul(o,fac[n]);
	return 0;
}

Measured memory_bytes: 8064
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int a[123456];
int main(){
	int n; 
		
		scanf("%d%d%d",&a[1],&a[2],&a[3]);
		sort(a+1,a+4);
		printf("%d\n",a[1]+a[2]);
		
	
	return 0;
} 

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<map>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;

map<int,int> edge[110];

int main(void){
  int n,m,a;
  while(cin>>n>>m>>a,n+m+a){
    rep(i,110)edge[i].clear();
    rep(i,m){
      int h,p,q;
      cin>>h>>p>>q;
      edge[p].insert(make_pair(-h,q));
      edge[q].insert(make_pair(-h,p));
    }

    int h = -1001;
    while(true){
      if(edge[a].upper_bound(h) == edge[a].end())break;
      map<int,int>::iterator it = edge[a].upper_bound(h);
      h = it->first;
      a = it->second;
    }
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 1288
#include <iostream>
#define MAX 50
using namespace std;
typedef long long ll;

ll dp[MAX];

int Fibonacci(int n) {
    if(dp[n] != 0) return dp[n];
    if(n==0 || n == 1) return 1;
    ll tmp = Fibonacci(n-1) + Fibonacci(n-2);
    dp[n] = tmp;
    return tmp;
}

int main() {
    int n; cin >> n;
    cout << Fibonacci(n) << endl;
    return 0;
}



Measured memory_bytes: 3096
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
using namespace std;

#define PI 3.14159265359
#define all(v) v.begin(),v.end()
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define sfstr(v) scanf("%s", v);
#define sz(v) (int)v.size()
#define ndl puts("")
#define flush fflush(stdout)
#define SS stringstream
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

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

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

void PLAY() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}


int main() {
	//PLAY();

	cout << fixed << setprecision(10);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;
	int tmp = n;
	int sum = 0;
	while (tmp) {
		sum += tmp % 10;
		tmp /= 10;
	}
	if (n % sum == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


	return 0;
}

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

using namespace std;

int main() {
  constexpr long long kInf = 1e16;
  long long N, W;
  cin >> N >> W;
  const int V = 1000 * N;
  vector<int> w(N);
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
  }
  vector<vector<long long>> dp(N + 1, vector<long long>(V + 1, kInf));
  dp[0][0] = 0;  // NB

  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= V; j++) {
      if (j + v[i] <= V) {
        dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
      }
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
    }
  }
  int ans = 0;
  for (int j = 0; j <= V; j++) {
    if (dp[N][j] <= W) ans = j;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 80256
#include<stdio.h>
int main(void)
{
    int n,k,a[100005],i,count=0;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]>=k)
            count++;
    }
    printf("%d\n",count);
    return 0;
}


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

int main() {
  // ここにプログラムを追記
  int a;
  int b;
  cin >> a >> b;
  if (( a - b ) % 2 != 0)
  cout << ( a + b ) / 2 + 1 << endl;
  else
  cout << ( a + b ) / 2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
int main(int argc, const char * argv[]) {
    char in,out;
    while(1){
        scanf("%c",&in);
        
        if( in == '\n' ){
            break;
        }
        
        if( in >= 'a' && in <= 'z' ){
            out = toupper ( in );
        }
        else if( in >= 'A' && in <= 'Z' ){
            out = tolower ( in );
        }
        else{
            out = in ;
        }
        printf("%c",out);
    }
    
    printf("\n");
    return 0;
}

Measured memory_bytes: 524
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		String T = sc.nextLine();
		if (S.matches("[a-z]{1,10}") && T.matches("[a-z]{1,}")) {
			if (T.length() == S.length() + 1) {
				if (T.substring(0,S.length()).equals(S)) {
					System.out.println("Yes");
				} else {
					System.out.println("No");
				}
			} else {
				System.out.println("No");
			}

		} else {
			System.out.println("No");
		}
		sc.close();
	}
}


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

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

    vector<int> whitinng(n + 1);
    vector<int> blacking(n + 1);

    whitinng[0] = 0;
    for (int i = 1; i < s.size() + 1; i++)
    {
        whitinng[i] = whitinng[i - 1];
        if (s[i - 1] == '#')
            whitinng[i]++;
    }

    blacking[n] = 0;
    for (int i = n - 1; i < s.size(); i--)
    {
        blacking[i] = blacking[i + 1];
        if (s[i] == '.')
            blacking[i]++;
    }

    if (whitinng[n] == 0 || blacking[0] == 0)
    {
        cout << 0 << endl;
        return 0;
    }

    int ans = s.size();

    for (int i = 0; i < whitinng.size(); i++)
    {
        ans = min(ans, whitinng[i] + blacking[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2180
S=input()
N=len(S)
x=0
y=N-1
p=True
q=True
for i in range(N):
  if S[i]=="A" and p:
    x=i
    p=False
  if S[N-i-1]=="Z" and q:
    y=N-i-1
    q=False
print(y-x+1)


Measured memory_bytes: 3516
/* -*- C -*- */

#include <stdio.h>

convert_time(int x){
	int h,m,s;
    
    h=x/3600;
    m=(x%3600)/60;
    s=(x%3600)%60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}

int main()
{   
    int sec;
    scanf("%d",&sec);
    convert_time(sec);
    return 0;
 }

Measured memory_bytes: 1804
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    string S;
    map<string, int> result;
    for(size_t i=0;i<N; i++)
    {
        cin >> S;
        result[S]++;
    }
    cout << "AC x " << result["AC"] << endl;
    cout << "WA x " << result["WA"] << endl;
    cout << "TLE x " << result["TLE"] << endl;
    cout << "RE x " << result["RE"] << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
    int n, m;
    cin >> n >> m;
    using P = pair<int, int>;
    vector<int> res(n, 1);
    vector<P> prev(n);
    vector<P> arms(m);
    for(int i=0; i<m; ++i) {
        int x, y;
        cin >> x >> y;
        arms[i] = make_pair(x, y-1);
    }
    sort(arms.begin(), arms.end());
    for(int i=0; i<m; ++i) {
        int y = arms[i].second;
        int t1 = res[y] - prev[y].first, t2 = res[y+1] - prev[y].first;
        res[y] += t2;
        res[y+1] += t1;
        prev[y] = make_pair(res[y], res[y+1]);
    }
    for(int i=0; i<n; ++i) {
        cout << res[i] << " \n"[(i == n-1)];
    }
    cout << flush;
}


Measured memory_bytes: 6012
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    vec a(3);
    rep(i, 3) cin >> a[i];

    sort(all(a), greater<int>());

    cout << a[0] * 10 + a[1] + a[2] << endl;
    return 0;
}

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

int main(){
  int N,count=0;
  cin >> N;
  vector<int> L(N);
  rep(i,N) cin >> L.at(i);
  
  for(int i=0; i<N-2; i++){
    for(int j=i+1;j<N-1;j++){
       for(int k=j+1;k<N;k++){
         int a=L.at(i),b=L.at(j),c=L.at(k);
         
         if(a+b>c&&a+c>b&&b+c>a&&a!=b&&b!=c&&a!=c) count++;
       }
    }
  }
  
  cout << count << endl;
}
    


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define SZ(v) (int)v.size()
#define endl "\n"
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 1e9;
const LL INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

void solve() {
  string s;
  int k;
  cin >> k >> s;
  if (SZ(s) <= k) {
    for (int i = 0; i < SZ(s); i++) cout << s[i];
    cout << endl;
  }
  else {
    for (int i = 0; i < k; i++) cout << s[i];
    cout << "..." << endl;
  }
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif
  int t = 1;
//  cin >> t;
  for (int tc = 1; tc <= t; tc++) solve();
  return 0;
}



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

int main() {
	//cout<<"GfG!";
	int a, b, c;
	cin>>a>>b>>c;
	if (a == b && a != c)
	    cout<<"Yes";
	else if (a == c && a != b)
	    cout<<"Yes";
	else if (b == a && b != c)
	    cout<<"Yes";
	else if (b == c && b != a)
	    cout<<"Yes";
	else if (c == a && c != b)
	    cout<<"Yes";
	else if (c == b && c != a)
	    cout<<"Yes";
	else 
        cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
constexpr ll mod = 1000000007;

int main() {
    int n,k,d = 0;
    cin >> n >> k;
    while(n) {
        d++;
        n /= k;
    }
    cout << d << endl;
}

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

typedef long long ll;
typedef long double ld;

const int inf = 1e9;
 
int x;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>x;
	if(x == 0)cout<<1<<endl;
	else cout<<0<<endl;

	return 0;
}


Measured memory_bytes: 3648
# AOJ ITP2_8_C: Map: Range Search
# Python3 2018.6.24 bal4u

from bisect import bisect_left, bisect_right, insort_left
dict = {}
keytbl = []
q = int(input())
for i in range(q):
	a = list(input().split())
	ki = a[1]
	if a[0] == '0':
		if ki not in dict:
			insort_left(keytbl, ki)
		dict[ki] = int(a[2])
	elif a[0] == '1':
		print(dict[ki] if ki in dict else 0)
	elif a[0] == '2':
		if ki in dict: dict[ki] = 0
	else:
		L = bisect_left (keytbl, a[1])
		R = bisect_right(keytbl, a[2], L)
		for j in range(L, R):
			if dict[keytbl[j]] > 0: print(keytbl[j], dict[keytbl[j]])


Measured memory_bytes: 38792
#include<stdio.h>
int main(void){
 int n;
  scanf("%d",&n);
  switch(n%10){
    case 0:
    case 1:
    case 6:
    case 8:puts("pon");break; 
    case 2:
    case 4:
    case 5:
    case 7:
    case 9: puts("hon");break;
    default:puts("bon");break;
  }
  return 0;
}


Measured memory_bytes: 1656
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPEACH(i,k) for(auto& i:k)
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

signed main() {
	int n;
	cin >> n;
	vector<int> b(n-1);
	vector<int> a(n);
	REP(i,n-1){
		cin >> b[i];
	}
	if(n==2){
		cout << b[0]*2 << endl;
		return 0;
	}
	REP(i,n-1){
		if(i==0||i==n-2){
			a[0]=b[0];
			a[n-1]=b[n-2];
			if(i==0){
				a[1]=min(b[0],b[1]);
			}
		}
		else {
			a[i+1]=min(b[i],b[i+1]);
		}
		/*else if(b[i]>b[i-1]&&b[i]>b[i+1]){
			b[i]=max(b[i+1],b[i-1]);
		}
		ans+=b[i];
		if(min>b[i]){
			min=b[i];
		}*/
	}
	int ans=0;
	REP(i,n){
		ans+=a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int x;
    scanf("%d",&x);
    if(x>=1800) puts("1");
    else if(x>=1600) puts("2");
    else if(x>=1400) puts("3");
    else if(x>=1200) puts("4");
    else if(x>=1000) puts("5");
    else if(x>=800) puts("6");
    else if(x>=600) puts("7");
    else puts("8");
    return 0;
}


Measured memory_bytes: 1652
#include<iostream>
#include<string>
#include<cctype>
using namespace std;

string toUpper(string s){
    string t =s;
    for(int i =0;i<s.size();i++){
        t[i]=toupper(s[i]);
    }
    return t;
}

int main(){
    string target,source;
    cin >> target;
    target = toUpper(target);
    int cnt=0;
    
    while(1){
        cin>>source;
        if (source =="END_OF_TEXT")break;
        source = toUpper(source);
        if (target == source)cnt++;
        
    }
    
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3108
use v5.18;
use warnings;
use List::Util qw( max );
sub read_line { chomp(my $str = <STDIN>); $str }
sub splited_read_line { split / /, read_line }

my $n = read_line;
my $s = read_line;

sub char_types {
  my $str = shift;
  +{ map { $_ => 1 } split //, $str };
}

sub same_types {
  my ($right_types, $left_types) = @_;
  my @same_types = 
    grep { $right_types->{$_} && $left_types->{$_} } keys %$right_types;
  \@same_types;
}

my $max = 0;
for my $separate_index (1 .. $n - 1) {
  my ($right, $left) = ( substr($s, 0, $separate_index), substr($s, $separate_index, $n) );
  my $same_types = same_types( char_types($right), char_types($left) );
  $max = max( scalar @$same_types, $max );
}
say $max;


Measured memory_bytes: 896
s = input()

flag = False
count = 0
ans = 0
for i in range(len(s)):
  if s[i] in ['A', 'T', 'C', 'G']:
      count += 1
  else:
    if count > ans:
      ans = count
      count = 0

print(max(ans, count))
    
    
  
  


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

int main(){
    int n;
    cin >> n;
    vector<int> types(3);
    for (int i = 0; i<3; i++) types[i] = 0;
    string s;
    int ans = 0;
    for (int i = 0; i<n; i++){
        cin >> s;
        for (int j = 0; j < s.size()-1; j++){
            if (s[j]=='A' && s[j+1]=='B') ans++;
        }
        if (s.front()=='B' && s.back()=='A') types[0]++;
        else if (s.front()=='B') types[1]++;
        else if (s.back()=='A') types[2]++;
    }
    ans += max(0, types[0] - 1);
    if (types[0] > 0 && types[1] > 0){
        ans += 1;
        types[1]--;
    }
    if (types[0] > 0 && types[2] > 0){
        ans += 1;
        types[2]--;
    }
    ans += min(types[1], types[2]);
    cout << ans << endl;
}




Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

    static void solve() {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();

        int[] values = new int[n];
        int sumNegative = 0;
        int sumPositive = 0;
        int posAmount = 0;
        int negAmount = 0;
        for (int i = 0; i < n; i++) {
            values[i] = scanner.nextInt();
        }

        Arrays.sort(values);

        int firstPositive = -1;
        for (int i = 0; i < n; i++) {
            if (values[i] >= 0) {
                if (firstPositive == -1) {
                    firstPositive = i;
                }
                sumPositive += values[i];
                posAmount++;
            } else {
                sumNegative += values[i];
                negAmount++;
            }
        }
        if (negAmount > 0 && posAmount > 0) {
            System.out.println(sumPositive - sumNegative);

            int sum1 = values[firstPositive];
            for (int i = firstPositive - 2; i > -1; i--) {
                System.out.println(sum1 + " " + values[i]);
                sum1 = sum1 - values[i];
            }
            int sum2 = values[firstPositive - 1];
            for (int i = firstPositive + 1; i < n; i++) {
                System.out.println(sum2 + " " + values[i]);
                sum2 = sum2 - values[i];
            }
            System.out.println(sum1 + " " + sum2);
            return;
        }

        if (sumPositive > 0) {
            int sum = values[0];
            for (int i = 1; i < n - 1; i++) {
                sum -= values[i];
            }
            System.out.println(values[n - 1] - sum);
            sum = values[0];
            for (int i = 1; i < n - 1; i++) {
                System.out.println(sum + " " + values[i]);
                sum -= values[i];
            }
            System.out.println(values[n - 1] + " " +  sum);
            return;
        } else {
            for (int i = 0; i < n; i++) {
                values[i] *= -1;
            }
            Arrays.sort(values);
            int sum = values[0];
            for (int i = 1; i < n - 1; i++) {
                sum -= values[i];
            }
            System.out.println(values[n - 1] - sum);
            sum = -values[0];
            for (int i = 1; i < n - 1; i++) {
                System.out.println(sum + " " + -values[i]);
                sum -= -values[i];
            }
            System.out.println(sum + " " + -values[n - 1]);
        }

    }

}


Measured memory_bytes: 67180
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int n, m;

vector<int> edge[53];

bool used[53];

void visit(int start, int a, int b) {
    used[start] = true;
    for (int i = 0; i < edge[start].size(); i++) {
        int end = edge[start][i];
        if (used[end]) continue;
        if (start == a && end == b) continue;
        if (start == b && end == a) continue;
        visit(end, a, b);
    }
}

bool solve(int a, int b) {
    fill_n(used, 53, false);

    visit(a, a, b);

    for (int i = 1; i <= n; i++) {
        if (!used[i]) return true;
    }

    return false;
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    int count = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < edge[i].size(); j++) {
            if (solve(i, edge[i][j])) {
                count++;
            }
        }
    }
    cout << count / 2 << endl;
}


Measured memory_bytes: 256