akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys


def solve(N: int, L: int):
    ab = []
    sum_teste = 0
    for i in range(N):
        taste = L + i
        sum_teste += taste
        ab.append(abs(taste))
    if sum_teste > 0:
        result = sum_teste - min(ab)
    else:
        result = sum_teste + min(ab)
    print(result)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    solve(N, L)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << x << endl
using namespace std;
int input() {
	int r;
	cin >> r;
	//scanf("%lld", &r);
	return r;
}
signed main() {
	int x; cin >> x;
	int k = 100;
	for1(i, 1000000) {
		k *= 1.01;
		if (x <= k) { puts(i); return 0; }
	}
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int l=s.size()-2;
  cout << s[0] << l << s[s.size()-1] << endl;
  return 0;
    

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    
    int n,k;cin>>n>>k;
    vector<int> arr(n+1),dp(n+1,INT_MAX);
    for(int i=1;i<=n;i++) cin>>arr[i];
    dp[0] = dp[1] = 0;  
    for(int i=2;i<=n;i++)
        for(int j=max(1,i-k);j<i;j++)
            dp[i] = min(dp[j]+abs(arr[i]-arr[j]), dp[i]); 
    cout<<dp[n];
}

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

using namespace std;

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

    if (N%2) {
        if (K <= (N+1)/2) cout << "YES\n";
        else cout << "NO\n";
    }
    else {
        if (K <= N/2) cout << "YES\n";
        else cout << "NO\n";
    }
}
   

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

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

int dp[45];

int fib(int n) {
	if(dp[n] >= 0) return dp[n];
	else return dp[n] = fib(n - 1) + fib(n - 2);
}

int main() {
	memset(dp, -1, sizeof(dp));
	dp[0] = 1;
	dp[1] = 1;
	int n;
	scanf("%d", &n);
	printf("%d\n", fib(n));
	return 0;
}

Measured memory_bytes: 3184
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val s = sc.next()

  var count = 0L
  var ans = 0L

  for (c in s) {
    if (c == 'B') {
      count++
    } else {
      ans += count
    }
  }

  println(ans)
}


Measured memory_bytes: 40960
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CompLib.Util;

public class Program
{
    private int N;
    private HashSet<string> Hs;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();

        // 標準形 + 使われている文字
        //       + 使われてない最小
        Hs = new HashSet<string>(StringComparer.Ordinal);
        Search(0, 'a', "");

        var ar = Hs.ToArray();
        Array.Sort(ar,StringComparer.Ordinal);
        Console.WriteLine(string.Join("\n",ar));
    }


    void Search(int n, char max, string s)
    {
        // sが標準形か?
        int t = 0;
        var map = (new int[N]).Select(i => -1).ToArray();
        for (int i = 0; i < n; i++)
        {
            if (map[s[i] - 'a'] == -1)
            {
                map[s[i] - 'a'] = t++;
            }

            if (map[s[i] - 'a'] != s[i] - 'a') return;
        }

        if (n >= N)
        {
            Hs.Add(s);
            return;
        }

        for (char c = 'a'; c <= max; c++)
        {
            Search(n + 1, (char) Math.Max(max, c + 1), $"{s}{c}");
        }
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

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

    int x = ceil(n / 1.08F);
    if ((int)(x * 1.08) == n) {
        cout << x << endl;
    } else {
        cout << ":(" << endl;
    }

    return 0;
}

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

char incrementChar(char x){
    return static_cast<char>(x + 1);
}

int weekToInt(string x){
    int num;
    if(x == "SUN"){
        num = 1;
    }else if(x == "MON"){
        num = 2;
    }else if(x == "TUE"){
        num = 3;
    }else if(x == "WED"){
        num = 4;
    }else if(x == "THU"){
        num = 5;
    }else if(x == "FRI"){
        num = 6;
    }else if(x == "SAT"){
        num = 7;
    }else{
        num = 0;
    }

    return num;
}

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

    cout << N * N * N << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
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; }

int main(){
    string S,T="",mir="",L="",R="";
    ll a=0,ans=0,l=0,r=0;
    cin>>S;
    for(ll i=0;i<S.size();i++){
        if(S[i]!='x') T+=S[i];
    }
    
    for(ll i=0;i<T.size()/2;i++){
        if(T[i]!=T[T.size()-i-1]){
            cout<<"-1"<<endl;
            return 0;
        }
        mir+=T[i];
    }
    if(T.size()%2==1) mir+=T[T.size()/2]; 
    
    for(ll i=0;i<S.size();i++){
        L+=S[i];
        if(S[i]==mir[a]) a++;
        if(a==mir.size()) break;
    }
    a=0;
     for(ll i=S.size()-1;i>=0;i--){
        R+=S[i];
        if(S[i]==mir[a]) a++;
        if(a==mir.size()) break;
    }
    
    while(1){
        if(L[l]==R[r]){
            l++;
            r++;
        }else if(L[l]=='x'){
            l++;
            ans++;
        }else if(R[r]=='x'){
            r++;
            ans++;
        }
        if(l==L.size()&&r==R.size()) break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcm(ll number1, ll number2) {//lcmを求める
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int s;
	scanf("%d", &s);
	unordered_map<int, bool> p;
	vector<int> dp(1000010);
	dp[0] = s;
	p[s] = true;
	rep1(i, 100010) {
		if (dp[i - 1] & 1)dp[i] = dp[i - 1] * 3 + 1;
		else dp[i] = dp[i - 1] >> 1;
		if (p[dp[i]]) {
			printf("%d\n", ++i);
			Please AC;
		}
		else {
			p[dp[i]] = true;
		}
	}


	Please AC;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
const long long INF = 100;
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main() {
  int H, W; cin >> H >> W;
  vector<vector<char>> s(H, vector<char> (W));
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> s[i][j];
    }
  }
  vector<vector<int>> dp(H, vector<int> (W));
  if(s[0][0] == '#') {
    dp[0][0] = 1;
  } else {
    dp[0][0] = 0;
  }
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(i == 0 && j == 0) {
        continue;
      }
      dp[i][j] = INF;
      if(i == 0) {
        if(s[i][j] == '#') {
          if(s[i][j - 1] == '.') {
            chmin(dp[i][j], dp[i][j - 1] + 1);
          } else {
            chmin(dp[i][j], dp[i][j - 1]);
          }
        } else {
          chmin(dp[i][j], dp[i][j - 1]);
        }
      } else if(j == 0) {
        if(s[i][j] == '#') {
          if(s[i - 1][j] == '.') {
            chmin(dp[i][j], dp[i - 1][j] + 1);
          } else {
            chmin(dp[i][j], dp[i - 1][j]);
          }
        } else {
          chmin(dp[i][j], dp[i - 1][j]);
        }
      } else {
        if(s[i][j] == '#') {
          if(s[i - 1][j] == '.') {
            chmin(dp[i][j], dp[i - 1][j] + 1);
          } else {
            chmin(dp[i][j], dp[i - 1][j]);
          }
          if(s[i][j - 1] == '.') {
            chmin(dp[i][j], dp[i][j - 1] + 1);
          } else {
            chmin(dp[i][j], dp[i][j - 1]);
          }
        } else {
          chmin(dp[i][j], dp[i - 1][j]);
          chmin(dp[i][j], dp[i][j - 1]);
        }
      }
    }
  }
  cout << dp[H - 1][W - 1] << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input().strip())
    a_l = [int(i) for i in input().strip().split()]
    ans = [None] * N
    base = 0
    for a in a_l:
        base ^= a
    for i in range(N):
        ans[i] = str(base ^ a_l[i])
    print(" ".join(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 35516
#include <bits/stdc++.h>
 
using namespace std;
 
/*  テンプレここから */
typedef long long ll;
 
#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define inf (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outpossible(bool_val) cout << (bool_val ? "possible" : "impossible") << endl;
#define outpossible(bool_val) cout << (bool_val ? "possible" : "impossible") << endl;
 
ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}
 
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    string a, b;
    cin >> a >> b;
 
    if(a == "H"){
        cout << b << endl;
    }else{
        if(b == "H"){
            cout << "D" << endl;
        }else{
            cout << "H" << endl;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,A,Q,B,C;
    long long sum;
    cin >> N;
    int M[100001]={0};
    for(int i=0; i<N; i++){
        cin >> A;
        M[A]++;
        sum+=A;
    }
    cin >> Q;
    for(int i=0; i<Q; i++){
        cin >> B >> C;
        M[C]+=M[B];
        sum+=(C-B)*(long long)M[B];
        M[B]=0;
        cout << sum << endl;
    }
    return 0;
}


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

int main() {
     int X,A;
     cin >> X >> A;
     if(X<A){
          cout << 0 << endl; return 0;
     }
    if(X>=A){
        cout << 10 << endl; return 0;
    }
return 0;
}

Measured memory_bytes: 256
N=int(input())
x=[i for i in map(int,input().split())]
y=0
z=0
i=0
while y<N:
    if y<N-1:
        if x[y]>=x[y+1]:
            i+=1
        else:
            if z<i:
                z=i
            i=0
    elif y==N-1:
        if z<i:
            z=i
    y+=1

print(z)

Measured memory_bytes: 14224
from itertools import combinations
N = int(input())


# kC2を満たすもののみ構築可能
creatable = []
for n in range(1, N + 1):
    num = n * (n + 1) // 2
    if num > N:
        break
    creatable.append(num)


# 構築不可能
if N not in creatable:
    print('No')
    exit()


# 部分集合の数
K = creatable.index(N) + 2
ans = [[] for i in range(K)]
for n, (c1, c2) in enumerate(combinations(range(K), 2), start=1):
    ans[c1].append(n)
    ans[c2].append(n)


# 出力
print('Yes')
print(K)
for a in ans:
    print(len(a), ' '.join(map(str, a)))


Measured memory_bytes: 9204
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc106_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] splitted_val = line.Split(' ');
            int a = int.Parse(splitted_val[0]);
            int b = int.Parse(splitted_val[1]);

            Console.WriteLine((a - 1) * (b - 1));
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#define inf 1000000007
#include<cstring>
#define ll long long int
using namespace std;
ll N,W;
vector<ll> w(104);
vector<ll> v(104);

ll dp[105][100005];

ll maxval(ll i ,ll val)
{
    if(val==0)
     return 0;
    if(i==N || val <0)
      return inf;
    if(dp[i][val]!=-1)
       return dp[i][val];
    
    return dp[i][val]=min(maxval(i+1,val-v[i])+w[i], maxval(i+1,val));
}


int main()
{
    ll sum=0;

    cin>>N>>W;
  
    memset(dp,-1,sizeof dp );
    for(ll i=0;i<N;i++)
    {
        cin>>w[i]>>v[i];
        sum+=v[i];
    }
    ll maxv;
    
    for(ll val=sum;val>=0;val--)
    {
        if(maxval(0,val)<=W)
        {
            maxv=val;
            break;
        }
    }
    
    cout<<maxv<<"\n";
}

Measured memory_bytes: 82304
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Console {
    static Console instance;
    final BufferedReader reader;

    public static Console getInstance() {
        if (instance == null) {
            instance = new Console();
        }
        return instance;
    }
    
    public Console() {
        reader = new BufferedReader(new InputStreamReader(System.in));
    }

    public int readInt() throws IOException {
        return Integer.parseInt(reader.readLine());
    }

    public int[] readLineNumbers(int n) throws IOException {
        String[] numStrings = reader.readLine().split(" ");
        int[] result = new int[n];
        for (int i = 0;i < n;i++) {
            result[i] = Integer.parseInt(numStrings[i]);
        }
        return result;
    }
    
    public void output(int n) {
        System.out.println(n);
    }
}

public class Main {
    public static void main(String[] args) throws Exception {
        int n = Console.getInstance().readInt();
        int[] S = Console.getInstance().readLineNumbers(n);
        int q = Console.getInstance().readInt();
        int[] T = Console.getInstance().readLineNumbers(q);
        
        int count = 0;
        for (int i = 0;i < q;i++) {
            int t = T[i];
            int min = 0;
            int max = n;

            while (min < max) {
                int index = (min + max) / 2;
                if (S[index] == t) {
                    count++;
                    break;
                } else if (S[index] > t) {
                    max = index;
                } else if (S[index] < t) {
                    min = index + 1;
                }
            }
        }

        Console.getInstance().output(count);
    }
}

Measured memory_bytes: 47696
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
using namespace std;

int main(){

	ll A,B,N,ans = 99999999999999999,tmp;

	scanf("%lld %lld %lld",&A,&B,&N);

	for(int i = 1; i <= N; i++){
		if(B%i == 0){
			tmp = B/i;
			for(int k = 1; k <= N; k++){
				ans = (ans <= abs(k*tmp-A))?ans:abs(k*tmp-A);
			}
		}
	}

	printf("%lld\n",ans);

	return 0;
}

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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

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

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

ll encode(const vi& a)
{
	ll x=0;
	rep(i,a.size()) x|=ll(a[i])<<i*4;
	return x;
}
vi decode(ll x)
{
	vi a;
	for(;x;x>>=4) a.push_back(x&15);
	return a;
}

//vvi f;
//
//inline int encode(const vi& a)
//{
//	return lower_bound(all(f),a)-begin(f);
//}
//inline vi decode(int x)
//{
//	return f[x];
//}

int main()
{
	for(int n;cin>>n && n;){
		vi a(n);
		rep(i,n) cin>>a[i];
		
		vi b(n); iota(all(b),1);
		if(a==b){
			cout<<0<<endl;
			continue;
		}
		
		queue<pair<ll,int>> q[2];
		unordered_map<ll,int> m[2];
		q[0].emplace(encode(a),0); m[0].insert(mp(encode(a),0));
		q[1].emplace(encode(b),0); m[1].insert(mp(encode(b),0));
		
		int res=INF;
		for(int k=0;;k^=1){
			//dump(q[k].size());
			queue<pair<ll,int>> tmp;
			while(q[k].size()){
				ll x; int t; tie(x,t)=q[k].front(); q[k].pop();
				if(m[k^1].count(x)){
					res=t+m[k^1][x];
					goto end;
				}
				vi a=decode(x);
				rep(i,n) repi(j,i,n){
					reverse(begin(a)+i,begin(a)+j+1);
					ll x=encode(a);
					if(!m[k].count(x)){
						tmp.emplace(encode(a),t+1);
						m[k][x]=t+1;
					}
					reverse(begin(a)+i,begin(a)+j+1);
				}
			}
			swap(q[k],tmp);
		}
		end:
		cout<<res<<endl;
	}
}

Measured memory_bytes: 93216
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<utility>
#include<functional>
#include<chrono>
#include<string>
using namespace std;
using namespace chrono;
#define INF (1<<29)
#define P pair<int,int>

int main()
{
	int dp[10001] = { 0 };
	int n, W, tv, tw, wmax = 0;
	vector<int> v(1001, 0);
	vector<bool> w(1001, false);
	cin >> n >> W;
	for (int i = 0; i < n; ++i) {
		cin >> tv >> tw;
		if (w[tw]) {
			if (v[tw] < tv)v[tw] = tv;

			else continue;
		}
		else {
			wmax = max(wmax, tw);
			w[tw] = true;
			v[tw] = tv;
		}

	}
	for (int i = 1; i <= wmax; i++) {
		if (!w[i])continue;
		for (int j = i; j <= W; j++) {
			dp[j] = max(dp[j], dp[j-i] + v[i]);
		}
	}
	cout << dp[W] << endl;
}

Measured memory_bytes: 1248
n=int(input())
B=list(input().split())
A=[[0 for i in range(n)]for j in range(n)]
C=[[0 for i in range(n)]for j in range(n)]
for i in range(n):
    A[i]=B[i]
    C[i]=B[i]
flag=1
while flag==1:
    flag=0
    for i in range(n-1):
        for j in range(n-1,0,-1):
            if int(A[j][1])<int(A[j-1][1]):
                A[j],A[j-1]=A[j-1],A[j]
                flag=1
for i in range(n-1):
    print(A[i],end=" ")
print(A[n-1])
print("Stable")

for i in range(n):
    min=i
    for j in range(i,n):
        if int(C[j][1])<int(C[min][1]):
            min=j
    if min!=i:
        C[i],C[min]=C[min],C[i]
for i in range(n-1):
    print(C[i],end=" ")
print(C[n-1])
flag=1
for i in range(n):
    if A[i]!=C[i]:
        flag=0
        break
if flag==1:
    print("Stable")
elif flag==0:
    print("Not stable")


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

int main(){
	int a,b;
	cin >> a >> b;
	int ans = max(0, a-2*b);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = int(input())
kakuran = list(itertools.permutations(range(1,N+1)))
# print(kakuran)
PP = tuple(inpl())
QQ = tuple(inpl())

a = kakuran.index(PP)
b = kakuran.index(QQ)

print(abs(a-b))


Measured memory_bytes: 8936
n, f = gets.split.map(&:to_i)
count = Hash.new(0)
n.times do
    a = gets.chomp.split[1..-1]
    a.combination(2).map(&:sort).each {|key| count[key] += 1}
end
pairs = count.select {|key, c| c >= f}.keys.sort
puts pairs.size
pairs.each do |pair|
    puts pair * ' '
end


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int ans;
string s;

int main()
{
    _FastIO;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '+')
            ans++;
        else
            ans--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<iomanip>
#include <string>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;
#define nin(n) int n; cin >> n;
#define kin(k) int k; cin >> k;
int main(){
  int n;
  cin >> n;
  long long int dp[100010][3]; //入力用テーブル
 
  long long h[100010][3];//dpテーブル
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      cin >> h[i][j];//素直に入力
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(j==k){
          continue;//2日連続同じ行動はできない
        }
        dp[i+1][k]=max(dp[i+1][k],dp[i][j]+h[i][k]); //i+1日目の最大値は高々1日前の最大値から求められる
      }
    }
  }
  long long int ans=0;//答えを0で初期化
  for(int i=0;i<3;i++){
    ans=max(dp[n][i],ans); //最終日のMAXを考える
  }
  cout << ans << endl;
}
      

Measured memory_bytes: 4992
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
ll n, b, c;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for (ll i = 1; i <= 3500; i++)
    {
        for(ll j=1;j<=3500;j++){
            if(4*i*j-n*i-n*j>0){
            float w=n*i*j/(4*i*j-n*i-n*j);
            if(n*i*j%(4*i*j-n*i-n*j)==0){
                cout<<i<<" "<<j<<" "<<ll(n*i*j/(4*i*j-n*i-n*j))<<"\n";
                return 0;
            }
            }
        }
    }
}


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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;

int main(){
    int n;
    cin >> n;
    int f[n][10],p[n][11],F[n];
    rp(i,n){
        F[i]=0;
        rp(j,10){
            cin >> f[i][j];
        }
    }
    rp(i,n){
        rp(j,11){
            cin >> p[i][j];
        }
    }
    int Max=INT_MIN;
    rep(bit,1,(1<<10)-1){
        rp(i,n){
            F[i]=0;
        }
        int prf=0;
        rp(i,10){
            if(bit&(1<<i)){
                rp(j,n){
                    if(f[j][i]){
                        F[j]++;
                    }
                }
            }
        }
        rp(i,n){
            prf += p[i][F[i]];
        }
        Max=max(Max,prf);
    }
    cout << Max << endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func nextperm(p []int) bool {
	i := len(p) - 1
	for i > 0 && p[i-1] > p[i] {
		i--
	}
	if i == 0 {
		return false
	}
	i--
	j := len(p) - 1
	for p[j] < p[i] {
		j--
	}
	p[i], p[j] = p[j], p[i]
	i, j = i+1, len(p)-1
	for i < j {
		p[i], p[j] = p[j], p[i]
		i, j = i+1, j-1
	}
	return true
}

func match(a, b []int) bool {
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	a := make([]int, n)
	ac := make([]int, n)
	var ba, aa []int
	for i := range a {
		a[i] = nextInt(sc)
	}
	copy(ac, a)
	sort.Ints(ac)
	copy(ba, ac)
	var found bool
	for {
		// fmt.Println(ac)
		if match(a, ac) {
			// fmt.Printf("  Match found! @ %v, previous %v\n", ac, ba)
			found = true
		} else if found {
			if aa == nil {
				aa = make([]int, n)
			}
			copy(aa, ac)
			break
		} else {
			if ba == nil {
				ba = make([]int, n)
			}
			copy(ba, ac)
		}
		if !nextperm(ac) {
			break
		}
		// copy(ba, ac)
	}
	// fmt.Println("ba", ba, "a", a, "aa", aa)
	wtr := bufio.NewWriter(os.Stdout)
	if len(ba) != 0 {
		prarray(ba, wtr)
	}
	prarray(a, wtr)
	if len(aa) != 0 {
		prarray(aa, wtr)
	}
	wtr.Flush()
}

func prarray(a []int, w *bufio.Writer) {
	for i := 0; i < len(a); i++ {
		if i > 0 {
			fmt.Fprintf(w, " ")
		}
		fmt.Fprintf(w, "%d", a[i])
	}
	fmt.Fprintln(w)
}



Measured memory_bytes: 1156
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++) // for簡略表記
#define DUMP(ar) for(int loop=0; loop<(int)ar.size(); loop++) cout << "[" << loop << "]:" << ar[loop] << endl // 配列一覧表示
#define DUMPL(ar) for(int loop=0; loop<(int)ar.size(); loop++) { cout << ar[loop]; if(loop<(int)ar.size()-1) cout << ' '; } cout << endl; // 配列一行一覧表示
#define COUT(x) cout << x << endl // 単要素出力
#define ALL(ar) ar.begin(), ar.end() // コンテナの全要素
#define LOOPD(i) cout << "ループ[" << i << "]回目---------------" << endl // ループ回数デバグ
using namespace std;
// cout << fixed << setprecision(4) で小数点以下4桁の桁そろえ
// cout << setw(5) << ... で表示形式を5桁に設定 5桁未満なら頭に空白がつく 5桁越なら先頭から5桁まで
// cout << setw(5) << setfill('0') << ... で空白部分の埋め文字に5を使う
// getline(cin, [変数]); で空白などを含む入力の受け取り(行ごとの受け取り)
// cin >> ws; でそこまでにストリームに残されたホワイトスペースを取り除く(=以降のgetlineの有効化)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,d,sum=0;
  cin >> n >>d;
  vector<vector<int>>A(n,vector<int>(d,0));
  FOR(i,n){
    FOR(j,d){
    cin>>A[i][j];
    }
     
  }
  double s;
  FOR(i,n-1){
  for(int j=i+1; j<n; j++){
    s=0;
    FOR(k,d){
       s+=pow(abs(A[i][k]-A[j][k]),2);
         
    
    }
    if(abs(sqrt(s)-(int)(sqrt(s)))<0.0001){
    sum++;
    }
    
    
  
  }
     
    
  }
cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>

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

using namespace std;
typedef long long ll;

int main(){
    string s, t;
    cin >> s >> t;
    int target_size = t.size();
    string tmp;
    int cmp_cnt = s.size();
    for(int i = 0; i <= s.size()-target_size; ++i){
        tmp = "";
        for(int j = i; j < i+target_size; ++j){
            tmp += s[j];
        }
        int cnt = 0;
        for(int k = 0; k < target_size; ++k){
            if(tmp[k] != t[k]) ++cnt;
        }
        cmp_cnt = min(cmp_cnt, cnt);
    }
    cout << cmp_cnt << endl;
    return 0;
}

Measured memory_bytes: 3620
function Main(input) {
  const inputs = input.split('\n')
    .filter(v => v);
  const n = Number(inputs[0]);
  const strs = inputs[1]
    .split('');
  
  console.log(strs.map(function(s) {
    var c = s.charCodeAt() + n;
    if (c > 90) {
      c -= 26;
    }
    return String.fromCharCode(c)
  }).join(''));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21192
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main(void) {
    
    int h,w;
    cin>>h>>w;
    vs v(h);
    rep(i,h)cin>>v[i];
    rep(i,w+2)cout<<"#";
    cout<<endl;
    rep(i,h){
        cout<<"#"<<v[i]<<"#"<<endl;
    }
    rep(i,w+2)cout<<"#";
    cout<<endl;
    cout<<endl;

    
    
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
l=[I() for i in range(n)]
l.sort()
print(sum(l)-l[-1]//2)


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

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

int solve(vector<pii> const& g, vector<pii> const& p, int v) {
    int l = 1, r = 1;
    if(g[v].first != -1) {
        l = solve(g, p, g[v].first);
    }
    if(g[v].second != -1) {
        r = solve(g, p, g[v].second);
    }
    int G = __gcd(l * p[v].first, r * p[v].second);
    int L = l * (r * p[v].second / G);
    int R = r * (l * p[v].first / G);
    return L + R;
}

int main() {
    int n;
    while(cin >> n, n) {
        vector<pii> g(n), p(n);
        vector<bool> is_root(n, true);
        for(int i = 0; i < n; ++i) {
            cin >> p[i].first >> p[i].second >> g[i].first >> g[i].second;
            g[i].first--; g[i].second--;
            if(g[i].first >= 0) {
                is_root[g[i].first] = false;
            }
            if(g[i].second >= 0) {
                is_root[g[i].second] = false;
            }
        }
        int r = find(begin(is_root), end(is_root), true) - begin(is_root);
        cout << solve(g, p, r) << endl;
    }
}


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

int main() {
    int x;
    cin >> x;
    int ans = 1;
    for (int b = 1; b <= 1000; b++) {
        for (int p = 2; p <= 1000; p++) {
            int a = pow(b, p);
            if (a <= x && a >= ans) ans = a; 
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//FUNCTION  
vector< int > divisor(int n) {
  vector< int > ret;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
} 
//solve

void solve(void)
{
  int N;
  cin>>N;
  vector<int> vec =  divisor(N);
  int MIN = INF;
  int ANS = -1;
  for (int i = 0; i < vec.size(); i++)
  {
    chmin(MIN,(int)max(log10(vec[i])+1,log10(N/vec[i])+1));
  }
  
  cout<<MIN<<endl;
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

typedef struct tyouten{ll id,x,y;}V;
int xsort(const void*a,const void*b){
	ll p=(*(V*)a).x,q=(*(V*)b).x;
	return p<q?-1:p>q?1:0;
}
int ysort(const void*a,const void*b){
	ll p=(*(V*)a).y,q=(*(V*)b).y;
	return p<q?-1:p>q?1:0;
}

//辺の情報を個別に持つタイプ

typedef struct edge{ll s,g,c;}E;
typedef struct graph{
	ll vcnt,ecnt;
	E  e[200010];//適宜変える
	ll id[100010];//適宜変える
}G;
int csort(const void*a,const void*b){
	ll p=(*(E*)a).c,q=(*(E*)b).c;
	return p<q?-1:p>q?1:0;
}

V v[100010];
G g;
void readgraph(){
	ll n;
	scanf("%lld",&n);
	rep(i,0,n){
		ll x,y;
		scanf("%lld%lld",&x,&y);
		v[i].id=i;
		v[i].x=x;
		v[i].y=y;
	}
	qsort(v,n,sizeof(V),xsort);
	rep(i,0,n-1){
		g.e[i].s=v[i].id;
		g.e[i].g=v[i+1].id;
		g.e[i].c=v[i+1].x-v[i].x;
	}
 
	qsort(v,n,sizeof(V),ysort);
	rep(i,0,n-1){
		g.e[n-1+i].s=v[i].id;
		g.e[n-1+i].g=v[i+1].id;
		g.e[n-1+i].c=v[i+1].y-v[i].y;
	}
	
	g.vcnt=n;
	g.ecnt=(n-1)*2;
	qsort(g.e,g.ecnt,sizeof(E),csort);
}


//union-find
int uniroot[100010],unicnt[100010];
void ufinit(int n){for(int i=0;i<n;i++){uniroot[i]=i;unicnt[i]=1;}}
int root(int x){return uniroot[x]!=x?uniroot[x]=root(uniroot[x]):x;}
int same(int x,int y){return root(x)==root(y);}
void uni(int x,int y){if((x=root(x))==(y=root(y)))return;uniroot[x]=y;unicnt[y]+=unicnt[x];}

//クラスカル法
//最小全域木を構成する辺を求める
//union findが必要
//O(ElogE)
ll saishou[200010];
void kurasukaru(G g){
	ufinit(g.vcnt);
	rep(i,0,g.ecnt){
		if(!same(g.e[i].s,g.e[i].g)){
			uni(g.e[i].s,g.e[i].g);
			saishou[i]=1;
		}
	}
}

int main(){
	readgraph();
	kurasukaru(g);
	
	ll ans=0;
	rep(i,0,g.ecnt)if(saishou[i])ans+=g.e[i].c;
	printf("%lld\n",ans);
	return 0;
}

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

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

    cout << 1/inv_sum << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int main(void)
{
	char s[100 + 1];
	scanf("%s", s);
	int n = strlen(s); // 文字列の長さを得る s
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
 
 			if (s[i] == 'L') {
 				puts("No");
 				return 0;
 			}
			}else {
 				
 				if (s[i] == 'R') {
 					puts("No");
 					return 0;
 			}
 		}
 	}
 
	puts("Yes");
	return 0;
}

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

#if __has_include(<local.h>)
#include <local.h>
#endif

using namespace std;

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())
#define ALL(x) (x).begin(),(x).end()

//As Function
#define UP(a,b) ((a+(b-1))/(b))
#define IPOW(x,y) LL(pow(x,y))

//Debug
#ifdef LOCAL_H
#define TEST cout << "OK\n"
#define DEBUG(a) a
#else
#define TEST
#define DEBUG(a)
#endif

#ifdef LOCAL_H
[[maybe_unused]]
#endif
const double PI = M_PI;
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const int INF = int(999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const LL LL_INF = LL(999999999999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const long long MOD = int(1000000007);

//Settings
#ifdef LOCAL_H
const bool DO_BENCHMARK = true;
#endif
const int DOUBLE_ACCURACY = 15;
const int RUN_SOLVE = 1;

#ifndef LOCAL_H
const bool DO_BENCHMARK = false;
#endif

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    for(int do_solve_time = 0;do_solve_time < RUN_SOLVE;do_solve_time++){
        void solve();
        if(DO_BENCHMARK){
            clock_t clock_start = clock();
            solve();
            clock_t clock_end = clock();
            const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
            cout << "\n------------------------------------\n" << time << "[ms]\n";
        }
        else solve();
    }
}

/*------------------------------↓ここからコード↓----------------------------------*/
void solve(){
    string S;
    cin >> S;
    int sum = 0;
    for(int i = 0;i < S.size();i++){
        sum += (S[i]-'0');
        sum %= 9;
    }
    if(sum == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> roads_A(M*2);
  vector<int> roads_B(M*2);
  vector<int> ans(N,0);
  for(int i=0; i<M; i++){
    cin >> roads_A[i] >> roads_B[i];
  }
  for (int i=0; i<M; i++){
    ans[roads_A[i]-1]+=1;
    ans[roads_B[i]-1]+=1;
  }
  for(int i=0; i<N; i++){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, gcd, lcm 
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <vector> // vectors
#include <string> // string
#include <queue> // queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <unordered_map> // hashed by keys
#include <iomanip> //cout<<setprecision(n)
#define rep(i,n) for(int i = 0; i < n; i++)

typedef long long ll; // at least int64 > 9*10^18
typedef unsigned long long ull; // at least uint64

int main() {
  std::string s;
  std::cin >> s;
  int ocount = 0;
  int xcount = 0;
  for (char i:s) {
    if(i=='o') ocount++;
    if(i=='x') xcount++;
  }
  if(15-xcount>7) std::cout << "YES" << std::endl;
  else std::cout << "NO" << std::endl; 
  return 0;
}

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

int main() {
	vector<int> data;
	int n, num;
	int sum = 0;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> num;
		data.push_back(num);
	}

	sort(data.begin(), data.end(), greater<int>());

	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			sum += data[i];
		}
		else {
			sum -= data[i];
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    string s;
    while(cin >> s, s != "0"){
        string t, u;
        cin >> t >> u;
        reverse(s.begin(),s.end());
        reverse(t.begin(),t.end());
        reverse(u.begin(),u.end());
        int n = s.size();
        vector<vector<int>> dp(n+1, vector<int>(4));
        dp[0][0] = 1;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < 4; ++j) {
                for (int k = (i == n-1); k <= 9; ++k) {
                    if(s[i] != '?' && s[i] -'0' != k) continue;
                    for (int l = (i == n-1); l <= 9; ++l) {
                        if(t[i] != '?' && t[i] -'0' != l) continue;
                        for (int m = (i == n-1); m <= 9; ++m) {
                            if(u[i] != '?' && u[i] -'0' != m) continue;
                            if((j+k+l)%10 != m) continue;
                            (dp[i+1][(j+k+l)/10] += dp[i][j]) %= MOD;
                        }
                    }
                }
            }
        }
        cout << dp[n][0] << "\n";
    }
    return 0;
}


Measured memory_bytes: 3180
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 4000
#define MO 924844033
using namespace std;
int dp[MAXN+5][MAXN+5][2],f[MAXN+5];
int n,k,fact[MAXN+5];
bool ed[MAXN+5];
void prepare()
{
	fact[0]=1;
	for(int i=1;i<=MAXN;i++)
		fact[i]=1LL*fact[i-1]*i%MO;
}
int main()
{
//	freopen("captain.in","r",stdin);
//	freopen("captain.out","w",stdout);
	prepare();
	scanf("%d %d",&n,&k);
	int totlen=0;
	ed[0]=true;
	for(int i=1;i<=k;i++)
	{
		totlen+=(n-i)/k+1;
		ed[totlen]=true;
		totlen+=(n-i)/k+1;
		ed[totlen]=true;
	}
	dp[1][0][0]=1;
	for(int i=2;i<=2*n;i++)
		for(int j=0;j<=n;j++)
		{
			dp[i][j][0]=(1LL*dp[i-1][j][0]+1LL*dp[i-1][j][1])%MO;
			if(ed[i-1]==false&&j-1>=0)
				dp[i][j][1]=dp[i-1][j-1][0];
		}
	for(int i=0;i<=n;i++)
		f[i]=(1LL*dp[2*n][i][0]+1LL*dp[2*n][i][1])%MO;
	int ans=0;
	for(int i=0;i<=n;i++)
	{
		if(i%2==0)
			ans=(1LL*ans+1LL*f[i]*fact[n-i]%MO)%MO;
		else
			ans=((1LL*ans-1LL*f[i]*fact[n-i]%MO)+MO)%MO;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 124416