akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }

    static Scanner cin;

    // メンバ変数---
    struct edge { public long C; public long S; public long F; public edge(long c, long s, long f) { C = c;S = s;F = f; } }
    long N;
    edge[] edges;
    // -------------

    void calc()
    {
        N = cin.nextLong();
        edges = new edge[N-1];
        for(
            long i = 0;i < N-1; i++)
        {
            edges[i] = new edge(cin.nextLong(), cin.nextLong(), cin.nextLong());
        }
        // 駅ごとのループ
        for(long i = 0;i < N; i++)
        {
            long time = 0;
            for(long j = i;j < N-1; j++)
            {
                // 待ち時間の計算
                time = Math.Max(edges[j].S, time);
                if(time % edges[j].F > 0)
                {
                    time += edges[j].F - (time % edges[j].F);
                }

                // 移動時間の加算
                time += edges[j].C;
            }

            Write(time);
        }

    }

    void Write<T>(T v)
    {
        Console.WriteLine(v);
    }

    int Pow(int x, int y)
    {
        return (int)Math.Pow(double.Parse(x.ToString()), double.Parse(y.ToString()));
    }

    double Pow(double x, double y)
    {
        return Math.Pow(x, y);
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}


Measured memory_bytes: 11220
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

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

    ll low = 2, high = 2;
    reverse(ALL(a));

    rep(i, k){
        if((low/a[i])*a[i] < low)low=(low/a[i])*a[i]+a[i];
        high = (high/a[i])*a[i]+a[i]-1;
        if(high < a[i] || low > high){
            cout << -1;
            return 0;
        }
        // cout << a[i] << " in " << low << " & " << high << endl;
    }
    cout << low << " " << high << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
using namespace std;
long long n,a,b,f[1000001],flag=1;
int cnt;
bool use[1000010];
int main()
{
	cin>>n>>a>>b;
	if(a+b>n+1)
	{
		cout<<-1;
		return 0;
	}
	if((long long)a*b<(long long)n)
	{
		cout<<-1;
		return 0;
	}
	for(int i=n-a+1;i<=n;i++)
	{
		f[++cnt]=i;
		use[i]=1;
	}
	if(cnt<n)
	{
		for(int i=b-1;i>=1;i--)
		{
			f[++cnt]=i;
			use[i]=1;
			if(cnt==n) break;
		}
		for(int i=b;i<=n-a+1;i+=(b-1))
		{
			for(int j=i+b-2;j>=i;j--)
			{
				if(!use[j]&&j<=n)
				{
					f[++cnt]=j;
					use[j]=1;
				}
				if(cnt==n) break;
			}
		}
	}
	for(int i=1;i<=cnt;i++)
	{
		cout<<f[i]<<" ";
	}
	return 0;
}


Measured memory_bytes: 5632
#include"bits/stdc++.h"
using namespace std;

int main()
{

    int a,b,c;
    cin>>a>>b>>c;

    if((a+b+c)>=22)
    {
        cout<<"bust"<<endl;
    }
    else
    {

        cout<<"win"<<endl;
    }
    return 0;
}


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

long long gcd(long long aaa,long long bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

int main (){

    int A,B,X;
    cin >> A >> B >> X;
    
    if(A <= X && A+B >= X) {
        cout << "YES" << endl;
    }else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 768
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int R, G, B;
	cin >> R >> G >> B;
	if ((100 * R + 10 * G + B) % 4 == 0)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
// ------ Class ------ //
template <class T> class Graph2 {
public:
	// ------ Variables ------ //
	static const T INF = numeric_limits<T>::max();
	int V, E; vector<vector<pair<int, T> > > G;

	// ------ Constructors ------ //
	Graph2() : V(0), E(0), G(vector<vector<pair<int, T> > >()) {}
	Graph2(int v) : V(v), E(0), G(vector<vector<pair<int, T> > >(v)) {}
	Graph2(vector<vector<pair<int, T> > > g) : V(g.size()), G(g) { for (int i = 0; i < g.size(); i++) E += g[i].size(); }

	// ------ Basic Functions ------ //
	int size() { return V; }
	void add1(int v1, int v2, T w) { G[v1].push_back(make_pair(v2, w)); E++; }
	void add2(int v1, int v2, T w) { add1(v1, v2, w); add1(v2, v1, w); }

	// ------ Operators ------ //
	bool operator==(const Graph2& g) const { return G == g.G; }
	bool operator!=(const Graph2& g) const { return G != g.G; }
	vector<pair<int, T> > operator[](int x) { return G[x]; }

	// ------ Algorithms ------ //
	T minspan() {
		vector<T> d(V, INF);
		vector<bool> used(V, false);
		priority_queue<pair<T, int> > que;
		for (int i = 0; i < V; i++) d[i] = INF;
		d[0] = 0; que.push(make_pair(0, 0));
		while (!que.empty()) {
			pair<T, int> pa = que.top(); que.pop();
			int u = pa.second; used[u] = true;
			for (int i = 0; i < G[u].size(); i++) {
				int v = G[u][i].first;
				if (d[v] > G[u][i].second && !used[v]) {
					d[v] = G[u][i].second; que.push(make_pair(-d[v], v));
				}
			}
		}
		T sum = 0;
		for (int i = 0; i < V; i++) sum += d[i];
		return sum;
	}
};
// ------ Main ------ //
int V, E, s, t, w;
int main() {
	cin >> V >> E;
	Graph2<int> G(V);
	for(int i = 0; i < E; i++) {
		cin >> s >> t >> w;
		G.add2(s, t, w);
	}
	cout << G.minspan() << endl;
}

Measured memory_bytes: 6156
#include <bits/stdc++.h>                  
using namespace std;   
int main(){ 
  string s1, s2; cin >> s1 >> s2;   
  int64_t sum = 0;         
  for(int i=0;i<s1.size();i++)   
     sum += (s1[i] != s2[i]);     
  cout << sum << "\n";                         
return 0;                           
}  

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

using namespace std;

int main() {
 
  int n,sum,a,c;
  sum = 0;
  cin>>n;
  long long b[n];
  for(int i=0;i<n;i++){
        cin >> b[i];
  }
  for(int i=0;i<n-1;i++){
    a = b[0];
  }
   for(int i=0;i<n-1;i++){
    c = b[n-2];
  }
  for(int i=1;i<n-1;i++){
    sum += min(b[i-1],b[i]);
  }
  cout<< sum+a+c <<endl;
  return 0;
}

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

int main() {
  int h, n;
  cin >> h >> n;
  vector<pair<int, int>> a(n);
  for (auto& e : a) cin >> e.first >> e.second;

  vector<int> dp(h + 1, 1e9);
  dp[h] = 0;
  for (auto e : a) {
    for (int i = h; i > 0; i--) {
      dp[max(0, i - e.first)] = min(dp[max(0, i - e.first)], dp[i] + e.second);
    }
  }
  cout << dp[0] << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int n,k,x,y;
  
  scanf("%d %d %d %d",&n,&k,&x,&y);
  
  int ans;
  
  if(n-k>=0)
  {
  ans=x*k+y*(n-k);
  }
  else
  {
    ans=x*n;
  }
  
  printf("%d\n",ans);
  
  return 0;
}


Measured memory_bytes: 128
#(45)コンテスト
a=[]
for i in range(10):
    n=int(input())
    a.append(n)
a.sort(reverse=True)
b=[]
for j in range(10):
    m=int(input())
    b.append(m)
b.sort(reverse=True)
w=0
K=0
for k in range(3):
    w+=a[k]
    K+=b[k]
print(w,K)


Measured memory_bytes: 5600
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stderr, stdin, stdout, Read, BufRead, BufWriter, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::{i64, u64, usize};
#[allow(unused_macros)]
macro_rules !dbg {($(a :expr ) ,*) =>{writeln !(&mut stderr () ,concat !($(stringify !(a ) ," = {:?}, " ) ,*) ,$(a ) ,*) .unwrap () ;} }
#[allow(non_snake_case)]
#[allow(dead_code)]
fn main() {
    let mut buf = String::new();
    let stdin = std::io::stdin();
    let mut handle = stdin.lock();
    handle.read_to_string(&mut buf).unwrap();
    let mut iter = buf.trim().split_whitespace();

    let s: Vec<char> = iter.next().unwrap().chars().collect();

    let mut ans: Vec<u64> = vec![0; s.len()];
    let mut i = 0;
    while i < s.len() {
        let mut r = 0;
        while i < s.len() && s[i] == 'R' {
            r += 1;
            i += 1;
        }
        let mid = i.clone();
        let mut l = 0;
        while i < s.len() && s[i] == 'L' {
            l += 1;
            i += 1;
        }
        ans[mid - 1] += (r + 1) / 2 + l / 2;
        ans[mid] += r / 2 + (l + 1) / 2;
    }
    for x in ans {
        print!("{} ", x);
    }
    println!("");
}


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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
// #define int long long

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

long long a, b, k;
int32_t main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	cin >> a >> b >> k;
	long long ansa = max(0LL, a-k);
	k -= (a-ansa);
	long long ansb = max(0LL, b-k);
	cout << ansa << ' ' << ansb << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <climits>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF 1000000007
#define PI acos(-1.0)
#define endl "\n"
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP_R(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)
#define FOR_R(i,m,n) for(int i=((int)(m)-1);i>=(int)(n);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZ(x) ((int)(x).size())
typedef long long int lli;
using namespace std;

lli updiv(lli n, lli a)
{
  if( n % a == 0 )
    {
      return n/a;
      
    }
  else
    {
      return n/a + 1;
      
    }
}


int main()
{
  lli N;
  vector<lli> a(5);

  scanf("%lld",&N);

  REP(i,5)
    {
      scanf("%lld",&a[i]);
      
    }

  printf("%lld\n", updiv( N, *(min_element(ALL(a))) ) + 4 );
  
  

  
}


Measured memory_bytes: 256
package main

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

var reader = bufio.NewReader(os.Stdin)

func main() {
	s := nextLine()
	f := make([]bool, 26)
	for _, c := range s {
		f[c-97] = true
	}
	for i, e := range f {
		if !e {
			fmt.Println(string(i + 97))
			return
		}
	}
	fmt.Println("None")
	return
}

func nextLine() string {
	var buf, line []byte
	isPrefix := true
	var err error
	for isPrefix {
		buf, isPrefix, err = reader.ReadLine()
		if err != nil {
			panic(err)
		}
		line = append(line, buf...)
	}
	return string(line)

}


Measured memory_bytes: 1280
#include <iostream>
#include <queue>
using namespace std;
int main(){
    int k, cnt = 0;
    cin >> k;
    queue<long long> que;
    for(int i = 1; i <= 9; i++) que.push(i);
    long long x;
    for(int i = 0; i < k; i++){
        x = que.front();
        que.pop();
        if(x % 10 != 0) que.push(10 * x + x % 10 - 1);
        que.push(10 * x + x % 10);
        if(x % 10 != 9) que.push(10 * x + x % 10 + 1);
    }
    cout << x;
    return 0;
}

Measured memory_bytes: 1792
def solve(string):
    s, k = string.split()
    if len(s) == 1:
        return s
    counter = 0
    for _s in str(s):
        if _s == "1":
            counter += 1
            continue
        break
    return "1" if len(k) < 4 and int(k) <= counter else s[counter]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 38384
o=Hash[*%w(N BURLDF E RFDUBL W LFUDBR S FDRLUB R ULFBRD L URBFLD)]
while(n=gets.to_i)>0
d=?0+t="UFRLBD"
s=1
n.times{d.tr!t,o[gets[0]];s+=d.index ?U}
p s
end

Measured memory_bytes: 6104
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;
const int maxn = 1e5 + 10;
int f[maxn], dp[2][maxn];
int *sum = dp[0];
int *sum1 = dp[1];
int L[maxn], R[maxn];//
map<int, int>  ma; //[maxn];
void add(int &a, int b) {
	a += b;
	while (a >= mod) a -= mod;
}
int main(void)
{
	int N, K;
	cin >> N >> K;
	int cnt = 0;
	for (int i = 1; i <= N; ) {
		int j = N / (N / i);
		L[++cnt] = i;
		R[cnt] = j;
		ma[j] = cnt;
		i = j + 1;

	}
	for (int i = 1; i <= cnt; ++i) {
		f[i] = 1;
		sum[i] = (sum[i - 1] + f[i] * (R[i] - L[i] + 1));
		// cout << L[i] << " " << R[i] << endl;
		// cout << sum[i] << endl;
	}

	for (int i = 1; i < K; ++i) {
		swap(sum, sum1);
		for (int j = 1; j <= cnt; ++j) {
			// cout << ma[N / L[j]] << endl;
			f[j] = sum1[ma[N / L[j]]];
			sum[j] = (sum[j - 1] + 1ll * (R[j] - L[j] + 1) * f[j] % mod) % mod;
		}

	}
	cout << sum[cnt] << endl;


	return 0;
}

Measured memory_bytes: 6272
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long MOD = 998244353;

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

	int k, n;
	cin >> k >> n;
	int* a = new int[n];
	rep(i, n) cin >> a[i];

	int sum = a[0] + (k - a[n - 1]);
	int maxLength = a[0] + (k - a[n - 1]);
	REP(i, 1, n) {
		sum += a[i] - a[i - 1];
		maxLength = max(maxLength, a[i] - a[i - 1]);
	}

	cout << sum - maxLength << "\n";

	return 0; 
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
static const int inf = 1 << 30;

int main(void) {
    int A, B, C;
    cin >> A >> B >> C;
    cout << ((A + B >= C) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(vs []int) int {
	m := vs[0]
	for _, v := range vs {
		if v < m {
			m = v
		}
	}
	return m
}

func cost(c, num int) int {
	if num < 0 {
		return 0
	}
	return c * num
}

func main() {
	var a, b, c, x, y int
	fmt.Scan(&a, &b, &c, &x, &y)

	fmt.Println(min([]int{a*x + b*y, x*c*2 + cost(b, y-x), y*c*2 + cost(a, x-y)}))
}


Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#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)

int N;
int a[300010];

int main(){
	scanf("%d" , &N);
	repp(i,0,3*N){
		scanf("%d" , a + i);
	}
	sort(a,a+3*N);
	LL ans = 0;
	repp(i,0,N){
		ans += a[N+2*i];
	}
	printf("%lld\n" , ans);
	return 0;
}


Measured memory_bytes: 1280
import java.util.*;
import static java.lang.Math.*;

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

		// 入力
		int n = sc.nextInt();// お札の枚数（10000万円札、5000円札、1000円札）
		int y = sc.nextInt();// 合計金額(1000の倍数)

		// 計算
		int countA = -1;
		int countB = -1;
		int countC = -1;

		for(int a = 0; a <= n; a++){
			for(int b = 0; a + b <= n; b++){
				if(10000 * a + 5000 * b + 1000 * (n - a - b) == y){
					countA = a;
					countB = b;
					countC = n - a -b;
				}
			}
		}

		// 出力
		System.out.println(countA + " " + countB + " " + countC);
	}

}




Measured memory_bytes: 21972
import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    long W = in.nextLong();
    long H = in.nextLong();
    long x = in.nextLong();
    long y = in.nextLong();
    System.out.println((W * H / 2.0) + " " + (W == x * 2 && H == y * 2 ? 1 : 0));
  }
}

Measured memory_bytes: 21972
n = int(input())
s = input()
w = []
r = []
for i in range(len(s)):
    if s[i] == "W": w.append(i+1)
    if s[len(s)-i-1] == "R": r.append(len(s)-i)
cnt = 0
# print(w,r)
for i in range(min(len(w), len(r))):
    if w[i] >  r[i]:
        break
    else:
        cnt += 1
print(cnt)

"""
i = 0
while True:
    wi = s.index("W")
    ri = str(s).rindex("R")
    if wi < ri:
        s[wi], s[ri] = s[ri], s[wi]
        i += 1
    else: break
print(cnt)
"""

Measured memory_bytes: 17320
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

c = []
d = []
e = []
b.append(0)
for i in range(n+1):
    if i == 0:
        c.append(0)
        d.append(b[0])
    else:
        c.append(b[i-1] - max(e[i-1] - c[i-1], 0))
        d.append(b[i] + c[i])
    e.append(min(a[i], d[i]))

print(sum(e))

Measured memory_bytes: 21120
import sys

input = sys.stdin.readline


class UnionFind:
    """Union Find class.

    "Path compression" and "Union by rank" are used.

    References:
        <https://en.wikipedia.org/wiki/Disjoint-set_data_structure>
    """

    def __init__(self, N):
        self.N = N
        self.__make_set()

    def __make_set(self):
        self._parent = list(range(self.N))
        self._rank = [0] * self.N
        self._size = [1] * self.N

    def find(self, x):
        if self._parent[x] != x:
            self._parent[x] = self.find(self._parent[x])
        return self._parent[x]

    def union(self, x, y):
        x_root = self.find(x)
        y_root = self.find(y)

        if x_root == y_root:
            return

        x_rank = self._rank[x_root]
        y_rank = self._rank[y_root]
        if x_rank > y_rank:
            self._parent[y_root] = x_root
            self._size[x_root] += self._size[y_root]
        elif x_rank < y_rank:
            self._parent[x_root] = y_root
            self._size[y_root] += self._size[x_root]
        else:
            self._parent[y_root] = x_root
            self._rank[x_root] += 1
            self._size[x_root] += self._size[y_root]

    def same_set(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self._size[self.find(x)]


def main():
    V, E = map(int, input().split())
    stw = [None] * E
    for i in range(E):
        stw[i] = tuple(map(int, input().split()))

    stw.sort(key=lambda x: x[2])
    uf = UnionFind(V)

    ans = 0
    for s, t, w in stw:
        if uf.same_set(s, t):
            continue
        uf.union(s, t)
        ans += w

    print(ans)


if __name__ == "__main__":
    main()



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

int main(){
double a,b,c,d,e,f,x,y;
while(cin>>a>>b>>c>>d>>e>>f){
x=(c*e-b*f)/(a*e-b*d)+0.0000;
y=(c*d-a*f)/(b*d-a*e)+0.0000;
printf("%4.3f %4.3f\n",x,y);}}

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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    string nap;
    cin >> nap;
    int n = nap.size();
    ll odp = 1;
    vector< vector<ll> > wyst(n + 1, vector<ll>(26, 0));
    for (int i = n - 1; i >= 0; --i)
    {
        for (int j = 0; j < 26; ++j)
            wyst[i][j] = wyst[i + 1][j];
        ++wyst[i][nap[i] - 'a'];
    }
    for (int i = 0; i < n - 1; ++i)
        for (int j = 0; j < 26; ++j)
            if (j != nap[i] - 'a')
                odp += wyst[i + 1][j];
    cout << odp;
    return 0;
}


Measured memory_bytes: 48916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200005;
const ll inf=0x3f3f3f3f3f3f3f3fll;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,m,a[N];
int check(int mid){
	int t=0;
	for (int i=1;i<=mid;i++) t=max(t,a[i]+a[mid*2-i+1]);
	for (int i=1;i+mid<=n;i++)
	if (a[i+mid*2]+a[n*2-i+1]<m) return -1;
	else t=max(t,a[i+mid*2]+a[n*2-i+1]-m);
	return t;
}
int main(){
	n=read();m=read();
	for (int i=1;i<=n*2;i++) a[i]=read();
	sort(a+1,a+n*2+1);
	int l=0,r=n,mid;
	while (l!=r){
		mid=(l+r)>>1;
		if (check(mid)>=0) r=mid;
		else l=mid+1;
	}
	printf("%d\n",check(l));
	return 0;
}

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

int main(){
    int m,f,r,i;
    i = 0;
    char a[50];
    while(1){
        cin >> m >> f >> r;
        if(m == -1 && f == -1 && r == -1)break;
        else{
            if(m == -1 || f == -1){
                a[i] = 'F';
            }
            else if(m + f >= 80){
                a[i] = 'A';
            }
            else if(65 <= m + f && m + f < 80){
                a[i] = 'B';
            }
            else if(50 <= m + f && m + f < 65){
                a[i] = 'C';
            }
            else if(30 <= m + f && m + f < 50){
                if(50 <= r){
                    a[i] = 'C';
                }
                else{
                    a[i] = 'D';
                }
            }
            else if(m+f < 30){
                a[i] = 'F';
            }
        }
        i++;
    }
    
    for(int j=0;j<i;j++){
        cout << a[j] << endl;
    }
    
}


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

const int mod = 1000000007;
int n, k;
vector<int> g[200000];
int c[200000];

void rec(int from, int prev, int col) {
  c[from] = col;
  int cnt = 0;
  for (int to : g[from]) {
    if (to == prev) continue;
    rec(to, from, k - (int)g[from].size() + cnt);
    ++cnt;
  }
}

int main() {
  cin >> n >> k;
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  
  rec(0, -1, k);
  long ans = 1;
  for (int i = 0; i < n; ++i) {
    ans = ans * c[i] % mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 13184
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main()
{
    int h, w;
    cin >> h >> w;

    vector<string> vec(h);
    for (int i = 0; i < h; i++)
    {
        cin >> vec[i];
    }
    
    vector<bool> x(h, false);
    vector<bool> y(w, false);
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (vec[i][j] == '#')
            {
                x[i] = true;
                y[j] = true;
            }
        }
    }
    
    for (int i = 0; i < h; i++)
    {
        if (x[i])
        {
            for (int j = 0; j < w; j++)
            {
                if (y[j])
                {
                    cout << vec[i][j];
                }
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)

def dfs(i):
	if i in use:
		return 
	use.add(i)
	for e in edges_r[i]:
		dfs(e)

def bf():
	d = [float('inf') for _ in range(n + 1)]
	d[1] = 0
	for _ in range(n):
		f = False
		for e in edges_f:
			if d[e[1]] > d[e[0]] + e[2]:
				d[e[1]] = d[e[0]] + e[2]
				f = True	
		if not f:
			return max(0, -1 * d[n])
	return -1

n, m, p = list(map(int, input().split()))

edges_f = []
edges_r = [[] for i in range(n + 1)]
for _ in range(m):
	a, b, c = list(map(int, input().split()))
	edges_f.append([a, b, -1 * (c - p)])
	edges_r[b].append(a)

use = set()
dfs(n)

edges_f = [e for e in edges_f if e[0] in use and e[1] in use]
print(bf())

Measured memory_bytes: 60248
// Implementation practice (Have seen the editorial)
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define loop(i, a) for (int i = 0; i < a; i++)
#define revloop(i, a) for (int i = a-1; i > -1; i--)
#define show(a) cout << a << "\n"
#define showloop(a, len) for (int i = 0; i < len; i++) cout << a[i] << "\n"
#define debug(a) cout << #a << ": " << a << "\n"
#define MOD 1000000007
#define V vector
#define S set
#define P pair
#define M map;
#define PQ priority_queue

int main() {
//    freopen("inputs.txt", "w", stdout);
//    int n = maxN;
//    loop(i, n) cout << i+1 << " ";
    //freopen("inputs.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int letter[26];
    memset(letter, 0, sizeof(letter));
    string S;
    cin >> S;
    loop(i, S.length()) letter[S[i]-'a']++;
    int i;
    for (i = 0; i < 26; i++) {
        if (!letter[i]) break;
    }
    if (i == 26) show("None");
    else show((char)('a'+i));

    return 0;
}


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

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

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

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

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

    vector<int> p(m);
    vector<int> y(m);
    vector<vector<int>> id(n+1);
    rep(i, m) {
        cin >> p[i] >> y[i];
        id[p[i]].push_back(y[i]);
    }
    for(int i = 1; i <= n; ++i) {
        sort(id[i].begin(), id[i].end());
    }
    rep(i, m) {
        printf("%012lld\n", ll(p[i])*1000000 + 
            int(lower_bound(id[p[i]].begin(), id[p[i]].end(), y[i]) - id[p[i]].begin() + 1));
    }
    return 0;
}

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

void result_append(vector<pair<int, int>> &scores, vector<int> &results){
  sort(scores.rbegin(), scores.rend());
  for(auto score : scores){
    results.push_back(score.second);
  }
}

int main(){
  int N = 0;
  cin >> N;
  vector<tuple<string, int, int>> inputs;
  for(int i = 0; i < N; i++){
    string A;
    int B;
    cin >> A >> B;
    inputs.push_back(make_tuple(A, B, i+1));
  }
  sort(inputs.begin(), inputs.end());

  vector<pair<int, int>> scores;
  vector<int> results;
  string was_name;
  for(auto input : inputs){
    if (!scores.size() || was_name == get<0>(input)) {
      scores.push_back(make_pair(get<1>(input), get<2>(input)));
    } else {
      result_append(scores, results);
      scores.erase(scores.begin(), scores.end());
      scores.push_back(make_pair(get<1>(input), get<2>(input)));
    }
    was_name = get<0>(input);
  }
  result_append(scores, results);
  
  for(auto result : results){
    cout << result << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long int a,b,k;
  cin >> a >> b >> k;
  if (a >= k) {
    cout << a-k << " " << b << endl;
  } else if (a < k && a+b > k) {
    cout << 0 << " " << b-(k-a) << endl;
  } else {
    cout << 0 << " " << 0 << endl;
  }
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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


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

	bool is_exist = false;
	string s_ = s;
	reverse(s_.begin(), s_.end());
	if (s == s_) {
		
		int n = s.size();
		string tmp = s.substr(0, (n-1)/2);
		string tmp_ = tmp;
		reverse(tmp.begin(), tmp.end());
		
		if (tmp == tmp_) {
			tmp = s.substr((n + 3) / 2-1, n);
			tmp_ = tmp;
			reverse(tmp.begin(), tmp.end());
			
			if (tmp == tmp_) is_exist = true;
		}
	}
	if (is_exist) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

using namespace std;

int n, a[200000],b[200000];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b + n);
	for (int i = 0; i < n; i++) {
		if (a[i] <= b[n / 2 - 1])cout << b[n / 2] << endl;
		else cout << b[n / 2 - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3712
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

vector<vector<ll> > vv;
int flag;

ll f(ll a, ll p){
  if(p!=-1&&vv[a].sz==1)return 1;
  ll c = 0;
  rep(i,0,vv[a].sz){
    if(vv[a][i]==p)continue;
    c += f(vv[a][i],a);
  }
  if(c==0){
    return 1;
  }
  else if(c==1){
    return 0;
  }
  else{
    flag = 1;
    return 0;
  }
}

int main() {
  flag = 0;
  ll n;
  cin>>n;
  vector<vector<ll> > vv_(n,vector<ll>());
  vv = vv_;
  rep(i,0,n-1){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    vv[a].pb(b);
    vv[b].pb(a);
  }
  ll res = f(0,-1);
  if(flag == 1){
    cout << "First" << endl;
    return 0;
  }
  if(res == 0){
    cout << "Second" << endl;
  }
  else{
    cout << "First" << endl;
  }
  return 0;
}

Measured memory_bytes: 8704
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main()
{
    ll n;
    cin >> n;
    vector<ll> x_r;
    vector<ll> y_r;

    for (int i = 0; i < n; i++)
    {
        ll x, y;
        cin >> x >> y;
        x_r.push_back(x - y);
        y_r.push_back(x + y);
    }
    sort(x_r.begin(), x_r.end());
    sort(y_r.begin(), y_r.end());

    ll ans = max(x_r.back() - x_r[0], y_r.back() - y_r[0]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6628
import java.util.Scanner;

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

		Scanner scan = new Scanner(System.in);

		int row = scan.nextInt();
		int column = scan.nextInt();
		int[][] spreadNum = new int[row+1][column+1];

		for(int rowI = 0 ;rowI < row ;rowI++){
			for(int columnI = 0 ;columnI < column ;columnI++){
				//行の入力
				spreadNum[rowI][columnI] = scan.nextInt();

				//行の合計
				spreadNum[rowI][column] += spreadNum[rowI][columnI];
				//列の合計
				spreadNum[row][columnI] += spreadNum[rowI][columnI];
				//行列の合計
				spreadNum[row][column] += spreadNum[rowI][columnI];
			}
		}
		for(int rowI = 0 ;rowI < row ;rowI++){
			for(int columnI = 0 ;columnI < column ;columnI++){
				//すべての出力
				System.out.print(spreadNum[rowI][columnI] + " ");
			}
				System.out.println(spreadNum[rowI][column]);
		}
		for(int columnI = 0 ;columnI < column ;columnI++){
			System.out.print(spreadNum[row][columnI] + " ");
		}
		System.out.println(spreadNum[row][column]);
		scan.close();
	}

}



Measured memory_bytes: 42392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const double PI = acos(-1.0);

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

	int n;
	cin >> n;
	
	int Room[4][3][10] = {0};
	
	for(int i = 0; i < n; i++) {
		int a, b, c, num;
		cin >> a >> b >> c >> num;
		Room[a - 1][b - 1][c - 1] += num;
	}
	
	for(int a = 0; a < 4; a++) {
		for(int b = 0; b < 3; b++) {
			for(int c = 0; c < 10; c++) {
				cout << " " << Room[a][b][c];
				if(c == 9) cout << "\n";
			}
		}
		if(a != 3) cout << "####################\n";
	}
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

string solve(string s, string t) {
  for (size_t i = 0; i < s.size(); ++i) {
    s.push_back(s.front());
    s.erase(s.begin());
    // cout << s << endl;
    if (s == t) {
      return "Yes";
    }
  }
  return "No";
}

int main() {
  string s, t;
  cin >> s >> t;
  cout << solve(s, t) << endl;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;

immutable long mod = 10^^9 + 7;

void main(){
    auto n = readln.chomp.to!int;
    auto s = readln.chomp;

    int stack;
    int lb, rb;

    foreach(ch ; s){
        if (ch == '('){
            stack += 1;
        }
        else {
            if (stack == 0){
                lb += 1;
            } 
            else {
                stack--;
            }
        }
    }

    rb = stack;

    auto ans = repeat("(", lb).join ~ s ~ repeat(")", rb).join;

    writeln(ans);
}


void readVars(T...)(auto ref T args){
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        throw new Exception("args num < input num");
    }
}

Measured memory_bytes: 256
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

@SuppressWarnings("unchecked")
public class Main {
    public static void main(String[] args) throws IOException {
        final String s;

        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            s = reader.readLine();
        }

        int N = Integer.parseInt(s);

        for (int i = N; i < 1000; i++) {
            String str = String.valueOf(i);
            if (str.charAt(0) == str.charAt(1)
                && str.charAt(1) == str.charAt(2)) {
                System.out.println(i);
                break;
            }
        }
    }
}


Measured memory_bytes: 22228
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define dump(o) { cerr << #o << " " << o << endl; }
#define dumpc(o) { cerr << #o; for (auto &e : (o)) cerr << " " << e; cerr << endl; }
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
	int N, K; cin >> N >> K;
	bool b[10] = {};
	for (int i = 0; i < K; i++) {
		int D; cin >> D;
		b[D] = true;
	}
	int ans = -1;
	for (int i = N; i < 100000; i++) {
		bool flag = false;
		string s = to_string(i);
		for (int j = 0; j < 10; j++) {
			if (b[j] == false)continue;
			if (s.find(to_string(j)) != string::npos) {
				flag = true;
				break;
			}
		}
		if (flag)continue;
		ans = i;
		break;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
  input()
  ary = list(map(int, input().split()))
  minv = maxv = ary[0]
  for v in ary:
    if v < minv:
      minv = v
    elif v > maxv:
      maxv = v
  print(str(maxv - minv))
    
if __name__ == '__main__':
  main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int l=(c*d)/(__gcd(c,d));
	int z1=a/c;
	if(a%c==0){
		z1--;
	}
	int z2=b/c;
	int ans=z2-z1;
	z1=a/d;
	if(a%d==0){
		z1--;
	}
	z2=b/d;
	ans+=z2-z1;
	z1=a/l;
	if(a%l==0){
		z1--;
	}
	z2=b/l;
	ans-=z2-z1;
	cout<<b-a+1-ans;







	
	
return 0;	
}


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

typedef long long int Long;
typedef long double Double;
typedef priority_queue<Long, vector<Long>, greater<Long>> minLongPQ;
const int MAXN = 1e5 + 4;

char vis[MAXN];
int n, m, cc;
Long ans, cost[MAXN];
vector<int> a[MAXN];

minLongPQ Q[MAXN];
struct Compare {
    bool operator()(const int &a, const int &b) {
    	int szA(Q[a].size());
    	int szB(Q[b].size());

        if(szA != szB)
        	return szA < szB;
        return Q[a].top() > Q[b].top();
    }
};
priority_queue<int, vector<int>, Compare> pq;

void dfs(int u) {
	vis[u] = 1;
	Q[cc].push(cost[u]);

	for(int v : a[u])
		if(!vis[v])
			dfs(v);
}
Long extractMin(int i) {
	Long val = Q[i].top(); Q[i].pop();
	return val;
}
void mergePQ(int ai, int bi) {
	minLongPQ &a = Q[ai];
	minLongPQ &b = Q[bi];

	if(int(a.size()) < int(b.size())) {
		while(a.size())
			b.push(a.top()), a.pop();
		if(b.size())
			pq.push(bi);
	} else {
		while(b.size())
			a.push(b.top()), b.pop();
		if(a.size())
			pq.push(ai);
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; ++i)
		scanf("%lld", cost + i);
	for(int i = 0, u, v; i < m; ++i) {
		scanf("%d%d", &u, &v);
		a[u].push_back(v);
		a[v].push_back(u);
	}

	memset(vis, 0, sizeof(vis));
	cc = 0;
	for(int i = 0; i < n; ++i)
		if(!vis[i])
			dfs(i), pq.push(cc), ++cc;

	ans = 0;
	while(cc > 1 && int(pq.size()) >= 2)  {
		int ai = pq.top(); pq.pop();
		int bi = pq.top(); pq.pop();

		ans += extractMin(ai);
		ans += extractMin(bi);
		mergePQ(ai, bi);

		--cc;
	}

	if(cc > 1) puts("Impossible");
	else printf("%lld\n", ans);

	return 0;
}


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

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

    if (cof.at(2) == cof.at(3) && cof.at(4) == cof.at(5)){
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

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

int main(void){
    int n;
    cin>>n;
    vector<int> vec(n);
    int i,j,v;
    for(i=0;i<n;i++){
        cin>>vec[i];
        if(i<n-1)cout<<vec[i]<<" ";
        if(i==n-1)cout<<vec[i]<<endl;
    }
    for(i=1;i<n;i++){
        v=vec[i];
        j=i-1;
        while(j>=0&&vec[j]>v){
            vec[j+1]=vec[j];
            j--;
            vec[j+1]=v;
        }
        for(j=0;j<n-1;j++){
            cout<<vec[j]<<" ";
        }
        cout<<vec[n-1]<<endl;
    }
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1000000007;
int main(){
  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  long long ans;
  bool c;
  if(s[0]==t[0]){
    ans=3;
    c=true;
  }
  else{
    ans=6;
    c=false;
  }
  for(int i=1;i<n;i++){
    if(s[i-1]==s[i]){
      continue;
    }
    if(s[i]==t[i]){
      if(c){
        ans*=2;
        ans%=mod;
      }
      else{
        ans%=mod;
        c=true;
      }
    }
    else{
      if(c){
        ans*=2;
        ans%=mod;
        c=false;
      }
      else{
        ans*=3;
        ans%=mod;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;
using P = pair<int, int>;
using ll = long long;
using ld = double;

using bint = boost::multiprecision::cpp_int;

constexpr int MOD = 1e9 + 7;

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin>>n;
    int a,b,c;
    a=0;
    b=2;
    c=8;
    rep(i,n-1){
        a=(a*10+b)%MOD;
        b=(b*9+c*2)%MOD;
        c=c*8%MOD;
    }
    cout<<a<<endl;
}


Measured memory_bytes: 3644
import java.math.BigInteger;
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner in=new Scanner(System.in);
		int a=in.nextInt();
		long f[]=new long[90];
		f[0]=2;
		f[1]=1;
		for(int i=2;i<=86;i++)
			f[i]=f[i-1]+f[i-2];
		System.out.println(f[a]);
	}
}

Measured memory_bytes: 23892
// In the name of God

#include <bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(x) cout << #x ": " << x << endl;

int main() {
	IOS
	string s;
	cin >> s;
	int cnt = 0;
	for(int i=0; s[i]; i++) if(s[i]=='2') cnt++;
	cout << cnt;
	return 0;
}


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

int main() {
  int a, b;
  int taxa, taxb;
  int prise;
  bool flag = false;
  cin >> a >> b;
  
  for (int i = 0; i < 1009; i++) {
    taxa = i * 0.08;
    taxb = i * 0.1;
    if (taxa == a && taxb == b) {
      prise = i;
      flag = true;
      break;
    }
  }
  if (flag) cout << prise << endl;
  else cout << "-1" << endl;
  return 0;
}


Measured memory_bytes: 256