akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n, k;
	cin >> n >> k;
	vi pos, neg, zero;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if(x < 0) {
			neg.pb(x);
		}
		else if(x > 0) {
			pos.pb(x);
		}
		else {
			zero.pb(x);
		}
	}
	sort(all(pos));
	sort(all(neg));
	int ans = 1;
	if(pos.empty() && zero.empty()) {
		if(k % 2 == 0) {
			reverse(all(neg));
		}
		while(k--) {
			ans = ans * ((neg.back() + mod) % mod) % mod;
			neg.pop_back();
		}
		cout << ans;
		return 0;
	}
	if(k & 1) {
		if(!pos.empty()) {
			ans = ans * pos.back() % mod;
			pos.pop_back();
		}
		else if(!zero.empty()) {
			cout << 0;
			return 0;
		}
		k--;
	}
	reverse(all(neg));
	while(k > 0) {
		int p_sz = pos.size();
		int n_sz = neg.size();
		if(p_sz >= 2 && n_sz >= 2) {
			if(neg[n_sz - 1] * neg[n_sz - 2] > pos[p_sz - 1] * pos[p_sz - 2]) {
				ans = ans * ((neg.back() + mod) % mod) % mod;
				neg.pop_back();
				ans = ans * ((neg.back() + mod) % mod) % mod;
				neg.pop_back();
			}
			else {
				ans = ans * pos.back() % mod;
				pos.pop_back();
				ans = ans * pos.back() % mod;
				pos.pop_back();
			}
		}
		else if(n_sz >= 2) {
			ans = ans * ((neg.back() + mod) % mod) % mod;
			neg.pop_back();
			ans = ans * ((neg.back() + mod) % mod) % mod;
			neg.pop_back();
		}
		else if(p_sz >= 2) {
			ans = ans * pos.back() % mod;
			pos.pop_back();
			ans = ans * pos.back() % mod;
			pos.pop_back();
		}
		else {
			if(!zero.empty()) {
				cout << 0;
				return 0;
			}
			else {
				ans = ans * pos.back() % mod;
				pos.pop_back();
				ans = ans * ((neg.back() + mod) % mod) % mod;
				neg.pop_back();
			}
		}
		k -= 2;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 5696
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
ll inf = llmax / 2;
double eps = 1e-11;

bool b[4][100010];

int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    b[0][0] = true;
    b[0][1] = true;
    b[1][0] = true;
    b[1][1] = false;
    b[2][0] = false;
    b[2][1] = true;
    b[3][0] = false;
    b[3][1] = false;
    int ok = -1;
    for (int i = 0; i < 4; i++) {
        for (int j = 2; j < N; j++) {
            if (s[j - 1] == 'o') {
                if (b[i][j - 1]) {
                    b[i][j] = b[i][j - 2];
                } else {
                    b[i][j] = !b[i][j - 2];
                }
            } else {
                if (b[i][j - 1]) {
                    b[i][j] = !b[i][j - 2];
                } else {
                    b[i][j] = b[i][j - 2];
                }
            }
        }
        bool subok = true;
        if (s[N - 1] == 'o') {
            if (b[i][N - 1]) {
                if (b[i][N - 2] != b[i][0]) {
                    subok = false;
                }
            } else {
                if (b[i][N - 2] == b[i][0]) {
                    subok = false;
                }
            }
        } else {
            if (b[i][N - 1]) {
                if (b[i][N - 2] == b[i][0]) {
                    subok = false;
                }
            } else {
                if (b[i][N - 2] != b[i][0]) {
                    subok = false;
                }
            }
        }
        if (s[0] == 'o') {
            if (b[i][0]) {
                if (b[i][N - 1] != b[i][1]) {
                    subok = false;
                }
            } else {
                if (b[i][N - 1] == b[i][1]) {
                    subok = false;
                }
            }
        } else {
            if (b[i][0]) {
                if (b[i][N - 1] == b[i][1]) {
                    subok = false;
                }
            } else {
                if (b[i][N - 1] != b[i][1]) {
                    subok = false;
                }
            }
        }
        if (subok) {
            ok = i;
            break;
        } 
    }
    if (ok == -1) {
        cout << -1 << endl;
    } else {
        string ans = "";
        for (int i = 0; i < N; i++) {
            if (b[ok][i] == true) {
                ans += "S";
            } else {
                ans += "W";
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <string.h>
#include<algorithm>
#include<math.h>

using namespace std;

int main() {
	int N,X,Y,Z;
	cin >> N;
	X = N / 1.08;
	Y = X * 1.08;
	Z = (X + 1) * 1.08;
	if (Y == N)cout << X << endl;
	else if (Z == N)cout << X+1 << endl;
	else cout << ":(" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
using namespace std;
long long a[26]; string S;
int main() {
	cin >> S;
	for (int i = 0; i < S.size(); i++)a[S[i] - 'a']++;
	long long T = S.size();
	long long U = 1LL * T*(T - 1) / 2;
	for (int i = 0; i < 26; i++)U -= (a[i] * (a[i] - 1)) / 2;
	cout << U + 1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//最大公約数
ll gcd(ll a,ll b)
{
    if(a%b == 0)
        return b;
    else
        return gcd(b, a % b);
}

double arr[10];
int main(){
    int n;
    cin >> n;
    double sum = 0;
    for (int i = 0; i < n;i++)
    {
        cin >> arr[i];
        sum += arr[i];
    }
    sort(arr, arr + n);
    cout << sum - (arr[n - 1]/2);
}

Measured memory_bytes: 256
'use strict'

function main(input) {
  input = input.split('\n')
  const P = input[1].split(' ').map(str => parseInt(str))
  const Q = input[2].split(' ').map(str => parseInt(str))

  // P, Qを辞書順に並べる
  const pDic = [...P].sort()
  const qDic = [...Q].sort()

  // 順列の何番目かを取得
  const a = permutation(pDic).findIndex(e => e.toString() === P.toString()) + 1
  const b = permutation(qDic).findIndex(e => e.toString() === Q.toString()) + 1

  console.log(Math.abs(a-b))
}

// 順列作成
const permutation = (list) => {
  if(!list.length) return;

  if(list.length === 1) {
    return [list]
  }

  let res = []
  let tmpList
  list.forEach((e, i) => {
    tmpList = [...list]
    tmpList.splice(i, 1) // 先頭にする数値を取り除く

    let perm = permutation(tmpList) // 再帰で順列作成
    
    perm.forEach((f) => {
      f.unshift(e)
      res.push(f)
    })
  })

  return res
}

main(require("fs").readFileSync("/dev/stdin", "utf8"))

Measured memory_bytes: 70772
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    string s;
    cin >> s;
    if (s == "SUN")
        cout << 7;
    else if (s == "SAT")
        cout << 1;
    else if (s == "FRI")
        cout << 2;
    else if (s == "THU")
        cout << 3;

    else if (s == "WED")
        cout << 4;
    else if (s == "TUE")
        cout << 5;
    else if (s == "MON")
        cout << 6;
}


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

int main(int argc, char const *argv[]) {
  ll w, h, n;std::cin >> w >> h >> n;
  ll a, b, c;
  ll l=-10000000000000,r=10000000000000,u=10000000000000, d=-10000000000000;
  re(i, n){
    std::cin >> a >> b >> c;
    if(c==1) l = max(l, a);
    else if(c==2) r = min(r, a);
    else if(c==3) d = max(d, b);
    else u = min(b, u);
  }
  ll W = max((ll)0, min(w, r) - max((ll)0, l));
  ll H = max((ll)0, min(h, u) - max((ll)0, d));
  std::cout << H*W << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n,k;cin>>n>>k;
  string s;
  ll ans=INF,temp;
  rep(i,pow(2,n)){
    temp=1;
    s=bitset<10>(i).to_string();
    FOR(j,10-n,10){
      if(s[j]=='1'){
        temp*=2;
      }else{
        temp+=k;
      }
    }
    ans=min(ans,temp);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    int nCount = 100000;
    for(int a = 0; a < 6; a++){  //1
        for(int b = 0; b < 3; b++){  //6
            for(int c = 0; c < 4; c++){  //9
                for(int d = 0; d < 6; d++){  //36 (36 * 6 = 216)
                    for(int e = 0; e < 8; e++){  //81 (81 * 8 = 216 * 3)
                        for(int f = 0; f < 6; f++){  //216 (216 * 6 = 729) 
                            for(int g = 0; g < 9; g++){  //729
                                for(int h = 0; h < 6; h++){  //1296
                                    for(int i = 0; i < 9; i++){  //6561
                                        for(int j = 0; j < 6; j++){  //7776
                                            for(int k = 0; k < 2; k++){  //59049
                                                for(int l = 0; l < 3; l++){  //46656
                                                    if(a+b*6+c*9+d*36+e*81+f*216+g*729+h*1296+i*6561+j*7776+k*59049+l*46656 == n){
                                                        nCount = min(nCount, a+b+c+d+e+f+g+h+i+j+k+l);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
    printf("%d", nCount);
    return 0;
}


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

typedef long long int ll;


int main()
{
    ll a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll k;
    cin >> k;
    cout << a[k - 1];
    
    return 0;
}


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

int main() {
  int N, A;
  A = 0;
  cin >> N;
  vector<int> vec(2*N);
  for(int i = 0; i < 2*N; i++){
    cin >> vec.at(i);
  }
  for(int i = 0; i < 2*N; i++){
    if(i % 2 == 1){
      A = A + vec.at(i);
    }
    else{
      A = A - vec.at(i);
    }
  }
  cout << A + N << endl;
}


Measured memory_bytes: 256
<?php
$N = int();
for($i = 0; $i < $N-1; $i++){
  list($from, $to, $d) = array_map("intval", explode(" ", trim(fgets(STDIN))));
  $G[$from][$to] = $d;
  $G[$to][$from] = $d;
}
$distance = array_fill(1, $N, 10**18);
function dfs($from, $current, $d){global $G,$distance;
    $distance[$current] = $d;
    foreach($G[$current] as $next => $dd){
        if($next != $from){
            dfs($current, $next, $d+$dd);
        }
    }
}

list($Q, $K) = ints();
dfs(-1, $K, 0);

for($i = 0; $i < $Q; $i++){
    list($from, $to) = ints();
    $result[] = $distance[$from]+$distance[$to];
}
echo implode("\n", $result),"\n";


function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}
/**
 * 座圧対象の配列を渡すと以下の値を返す
 * ・圧縮された配列
 * ・復元用のMap
 * ・圧縮用のMap
 **/
function atsu($array){
    $a = array_flip($array);
    $fuku = array_flip($a);
    sort($fuku);
    $atsu = array_flip($fuku);
    foreach($array as $i => $val)$array[$i] = $atsu[$val];
    return [$array, $fuku, $atsu];
}
//配列の最大公約数
function gcdAll($array){
    $gcd = $array[0];
    for($i = 1; $i < count($array); $i++){
        $gcd = gcd($gcd, $array[$i]);
    }
    return $gcd;
}

//最大公約数
function gcd($m, $n){
    if(!$n)return $m;
    return gcd($n, $m % $n);
}

//配列の最小公倍数
function lcmAll($array){
    $lcm = $array[0];
    for($i = 1; $i < count($array); $i++){
        $lcm = lcm($lcm, $array[$i]);
    }
    return $lcm;
}

//最小公倍数
function lcm($a, $b) {
    return $a / gcd($a, $b) * $b;
}
//ビットカウント-1の数を数える
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}


Measured memory_bytes: 86644
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	
	public static final String[] hands = 
		{"Rock",
		 "Fire",
		 "Scissors",
		 "Snake",
		 "Human",
		 "Tree",
		 "Wolf",
		 "Sponge",
		 "Paper",
		 "Air",
		 "Water",
		 "Dragon",
		 "Devil",
		 "Lightning",
		 "Gun"
		};
	
	public static final int SIZE = 15;
			
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		HashMap<String, Integer> dict = new HashMap<String, Integer>();
		
		for(int i = 0; i < hands.length; i++){
			dict.put(hands[i], i);
		}
		
		boolean[][] win = new boolean[SIZE][SIZE];
		for(int i = 0; i < SIZE; i++){
			for(int j = 1; j <= 7; j++){
				win[i][(i + j) % SIZE] = true;
			}
		}
		
		HashSet<Integer> set = new HashSet<Integer>();
		
		while(true){
			final int N = sc.nextInt();
			
			if(N == 0){
				break;
			}
			
			set.clear();
			
			for(int i = 0; i < N; i++){
				set.add(dict.get(sc.next()));
			}
			
			boolean def = false;
			for(int hand : set){
				boolean flag = false;
				
				for(int other_hand : set){
					if(hand == other_hand){
						continue;
					}else if(win[hand][other_hand]){
						flag = true;
					}else if(!win[hand][other_hand]){
						flag = false;
						break;
					}
				}
				
				if(flag){
					System.out.println(hands[hand]);
					def = true;
					break;
				}
			}
			
			if(!def){
				System.out.println("Draw");
			}
		}
	}

}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  vi32 v(5);
  int ans = 0, k;
  rep(i, 5) cin >> v[i];
  cin >> k;
  rep(i, 5) repi(j, i + 1, 5) {
    if (v[j] - v[i] > k) ans++;
  }
  if (ans > 0) cout << ":(" << endl; else cout << "Yay!" << endl;
  return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
const ll C = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i=0; i<n; i++) cin >> a[i];

    for(int i=0; i<n; i++) {
        if(i % 2 == 0) {
            b[i/2] = a[n-1-i];
        }
        else {
            b[n-1-i/2] = a[n-1-i];
        }
    }

    for(int i=0; i<n; i++) {
        if(i) cout << " ";
        cout << b[i];
    }
    cout << endl;
}

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

int main(){
  string s;
  cin >> s;
  bool can = false;
  if(s[6] == '1' || s[6] == '2' || s[6] == '3' || s[6] == '4') can = true;
  if(s[5] == '1' || s[5] == '1') can = false;
  if(can) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <utility>
#include <iterator>
#include <sstream>
#include <fstream>
#include <functional>
#include <ctime>
#include <cassert>
#include <limits>

using namespace std;

#define SyncFalse ios::sync_with_stdio(0); cin.tie(0)
#define MEM(a, v) memset(a, v, sizeof(a))
#define CLRV(a, sz, v) a.clear(); a.resize(sz, v)
#define CLR(a, sz) a.clear(); a.resize(sz)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.end(), a.begin()
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define SZ(a) (int)a.size()
#define LNG(a) (int)a.length()
#define LPI 3.141592653589793238462643383279502884L
#define SI(n) scanf("%d", &n)
#define SL(n) scanf("%lld", &n)
#define SD(n) scanf("%lf", &n)
#define SLD(n) scanf("%llf", &n)
#define SC(n) scanf(" %c", &n)
#define SS(n) scanf("%s", n)
#define FR(i, n) for (int i = 0; i < n; i++)
#define RFR(i, n) for (int i = n - 1; i >= 0; i--)
#define FR1(i, n) for (int i = 1; i <= n; i++)
#define RFR1(i, n) for (int i = n; i >= 1; i--)
#define FOREACH(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define endl '\n'

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<ld> VLD;
typedef vector<double> VD;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef vector<PII> VPII;
typedef vector<VPII> VVPII;

const double PI = acos(-1.0);
const double EPS = numeric_limits<double>::epsilon();
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int MOD = (int) 1e9 + 7;

//------------------------------------------------------------------------

int main() {
	string a, b, c; cin >> a >> b >> c;
	if (a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0]) {
		cout << "YES\n";
	} else {
		cout << "NO\n";
	}
	return 0;
}

Measured memory_bytes: 256
queue = []
n_process, quantum = gets.chomp.split.map(&:to_i)
n_process.times{
    name, ms = gets.chomp.split
    queue.push [name, ms.to_i]
}

time = 0
until queue.empty?
    process = queue.shift
    if process[1] <= quantum
        time += process[1]
        puts "#{process[0]} #{time}"
    else
        time += quantum
        queue.push [process[0], process[1] - quantum]
    end
end

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

int main() {
    char a,b;
    cin >> a >> b;
    string ans = "";

    if(a>=b){//4,3->bをa回
        for(int i=0;i<int(a-'0');i++) ans += b;
    }else{
        for(int i=0;i<int(b-'0');i++) ans += a;
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	int N, M;
	cin >> N >> M;

	for (int i = 0; i < M; i++) {
		int a;
		cin >> a;
		N -= a;

	}

	cout << (N < 0 ? -1 : N)  << "\n";

	return 0;
}



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

int main() {

  int N;
  cin >> N;

  vector<int> L(N);

  for(int i = 0; i < N; i++){
    cin >> L[i];
  }

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

  int cnt = 0;

  for(int i = 0; i < L.size(); i++){
    for(int j = i + 1; j < L.size(); j++){
      for(int k = j + 1; k < L.size(); k++){
        if(L[i] != L[j] && L[j] != L[k] && L[k] < L[i] + L[j]){
          cnt++;
        }
      }
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef long long ll;

const int    INF = 1000000000;
const int    MOD = 1000000007;
const double EPS = 1e-8;

inline bool valid(int x, int y, int W, int H){
    return x >= 0 && y >= 0 && x < W && y < H;
}
int ddx[4][2] = {
    {1, 1},
    {0, 1},
    {0, 0},
    {0, 1},
};
int ddy[4][2] = {
    {0, 1},
    {1, 1},
    {0, 1},
    {0, 0}
};
int ddr[4][2] = {
    {1, 3},
    {0, 2},
    {1, 3},
    {0, 2}
};

typedef pair<int, int> P;
typedef pair<int, P> S;

int main(){
    int W, H, N;
    while(cin >> W >> H >> N){
        int sx, sy, gx, gy;
        cin >> sx >> sy >> gx >> gy;
        int cost[555][555][4] = {};
        const int dx[4] = {1, 0, -1, 0};
        const int dy[4] = {0, 1, 0, -1};
        int ds[256] = {};
        ds[ 'R' ] = 0;
        ds[ 'D' ] = 1;
        ds[ 'L' ] = 2;
        ds[ 'U' ] = 3;

        REP(_, N){
            int x, y, T;
            cin >> x >> y >> T;
            string s;
            cin >> s;
            REP(iter, T){
                REP(i, s.size()){
                    int r = ds[s[i]];
                    int nx = x + dx[r];
                    int ny = y + dy[r];
                    if(valid(nx, ny, W, H)){
                        REP(j, 2) {
                            cost[y + ddy[r][j]][x + ddx[r][j]][ddr[r][j]] ++;
                        }
                        x = nx, y = ny;
                    }
                }
            }
        }

        priority_queue< S, vector<S>, greater<S> > que;
        int dist[555][555] = {};
        REP(y, H + 1) REP(x, W + 1) dist[y][x] = INF;
        dist[sy][sx] = 0;
        que.push(S(0, P(sx, sy)));
        while(!que.empty()){
            S s = que.top(); que.pop();
            int x = s.second.first;
            int y = s.second.second;
            int c = s.first;
            //printf("%d %d %d\n", x, y, c);
            if(dist[y][x] < c) continue;
            if(x == gx && y == gy){
                cout << c << endl;
                break;
            }
            REP(r, 4){
                int nx = x + dx[r];
                int ny = y + dy[r];
                if(valid(nx, ny, W + 1, H + 1)){
                    int nc = c + cost[y][x][r];
                    if(dist[ny][nx] > nc){
                        dist[ny][nx] = nc;
                        que.push(S(nc, P(nx, ny)));
                    }
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 10196
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		String S = sc.next();
		String[] ary = S.split("");
		sc.close();
		String res = "";
		if (S.length() <= K) {
			System.out.println(S);
		} else{
			for (int i = 0; i < K; i++){
			res = res + ary[i];
			}
		System.out.println(res + "...");
		}
	}
}

Measured memory_bytes: 39700
#include <iostream>

#define ll long long

using namespace std;

int n;
ll a, b, c, d;

int main() {
    cin >> n >> a >> b >> c >> d;

    ll s = a - (n - 1) * d, l = (n - 1) * (d - c), dist = 2 * c - (n - 2) * (d - c);
    //cout << s << " " << l << " " << dist << "\n";

    if (dist <= 0) {
        if (b >= a - (n - 1) * d && b <= a + (n - 1) * d) cout << "YES\n";
        else cout << "NO\n";
        exit(0);
    }

    for (int i = 0; i < n; ++i) {
        if (b >= s & b <= s + l) {
            cout << "YES\n";
            return 0;
        }
        s += l + dist;
    }

    cout << "NO\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define PI acos(-1)
#define INF 0x7f3f3f3f
#define L first
#define R second
#define pii  pair<int ,int>
#define pll  pair<long,long>
#define pb push_back
#define lowbit(x)  (x&-x)
#define fr(i,m,n) for( int i=m;i<n;++i)
#define fo(i,m,n) for(int i=m;i<=n;++i)
#define MM(a,b) memset(a,b,sizeof(a));
#define fin freopen("C:\\Users\\w\\Desktop\\ACM\\in.txt","r",stdin)
#define fot freopen("C:\\Users\\w\\Desktop\\ACM\\out.txt","w",stdout)
#define fcs fclose(stdin);fclose(stdout);


using namespace std;

inline void read(int&a){char ch;while(!(((ch=getchar())>='0')&&(ch<='9')));a=ch-'0';while(((ch=getchar())>='0')&&(ch<='9'))(a*=10)+=ch-'0';}


int main()
{
    ll i,n=1;
    scanf("%lld",&i);
    while(n*(n+1)/2 <i)
    {
        n++;
    }
    cout<<n<<endl;
}













Measured memory_bytes: 256
using System;

namespace AtcoderCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int X = int.Parse(Console.ReadLine());

            if(X >= 30)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 27288
#include <stdio.h>
#include <math.h>
 
#define DEBUG	(0)

int main(void)
{
  long a,b,c = 0;
  long ans = 0;
  
  scanf("%ld %ld %ld",&a,&b,&c);

  if(c - a - b < 0){
    printf("No\n");
    return 0;
  }
  ans = c*c - 2*c*(a+b) +(a+b)*(a+b) - 4*a*b;
  
#if DEBUG
  printf("ans:%ld\n",ans);
#endif
  
  if(ans > 0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l = sc.nextInt();

		int a[][] = new int[n][m];
		int b[][] = new int[m][l];
		long c[][] = new long[n][l];

		for(int i=0; i<n; i++) {
			for(int j=0; j<m; j++) {
				a[i][j] = sc.nextInt();
			}
		}

		for(int i=0; i<m; i++) {
			for(int j=0; j<l; j++) {
				b[i][j] = sc.nextInt();
			}
		}

		//ここから行列cの計算

		for(int i=0; i<n; i++) {
			for(int j=0; j<l; j++) {
				for(int k=0; k<m; k++) {
					c[i][j] += a[i][k] * b[k][j];
				}
			}
		}

		for(int i=0; i<n; i++) {
			for(int j=0; j<l; j++) {
				if(j != 0) System.out.print(" ");
				System.out.print(c[i][j]);
			}
			System.out.println();
		}
	}
}



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

int main() {
  int64_t N, K;
  cin >> N >> K;
  
  int64_t sum = 0;
  
  for (int64_t i = K; i <= N+1; i++) {
    sum = sum + ((2*N - i + 1)*i - (i - 1)*i)/2 + 1;
  }
  
  int64_t res;
  res = sum % ((int64_t)pow(10, 9) + 7);
  
  cout << res << endl;

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define oo 0x3f3f3f3fLL
#define sz(s) (int)(s.size())
#define RT(s) return cout<<s,0
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
vector<T> create(size_t n) {
	return vector<T>(n);
}
template<typename T, typename ... Args>
auto create(size_t n, Args ... args) {
	return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef EZZAT
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#else
#endif
}

int main() {
	run();
	int x;
	cin >> x;
	cout << (x / 500) * 1000LL + ((x % 500) / 5 * 5) << endl;
}


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

int main() {
    int a, b;
    cin >> a >> b;

    if (a < b) {
        cout << "a < b" << '\n';
    } else if (a > b) {
        cout << "a > b" << '\n';
    } else {
        cout << "a == b" << '\n';
    }

    return 0;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n,m;cin >>n>>m;
    ll x=-1;
    vector<P>p;
    for (int i = 0; i < m; ++i) {
        ll a,b;cin >>a>>b;
        p.push_back({b,a});
    }
    sort(all(p));
    ll ans=0;
    for (int i = 0; i < m; ++i) {
        if(p[i].second<x)continue;
        else {
            x=p[i].first;
            ans++;
        }
    }
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 5320
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<climits>
#include<algorithm>
#include<vector>
#include<stack>
#include<set>
#include<queue>
#include<map>
#include<cmath>
#include<sstream>
#include<string>
#define INF 1000000000

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int dp[7005][2005],head[7005];
bool inq[7005],mark[7005];
map<string,int> mapp;

struct edge{
	int to,w,next;
}edges[7005];
int em=0;

void addedge(int u,int v,int w){
	edges[em].next=head[u];
	edges[em].to=v;
	edges[em].w=w;
	head[u]=em++;
	edges[em].next=head[v];
	edges[em].to=u;
	edges[em].w=w;
	head[v]=em++;
}

int main(){
	int n,m,cap;
	while(~scanf("%d%d%d",&n,&m,&cap)&&(n||m||cap)){
		int cnt=1;
		em=0;
		cap*=10;
		string s,t,tt,mm;
		mapp.clear();
		cin>>s>>t;
		mapp[s]=cnt++;//s:1
		mapp[t]=cnt++;//t:2
		memset(head,-1,sizeof(head));
		while(n--){
			int w;
			cin>>tt>>mm;
			scanf("%d",&w);
			if(mapp[tt]==0)
				mapp[tt]=cnt++;
			if(mapp[mm]==0)
				mapp[mm]=cnt++;
			addedge(mapp[tt],mapp[mm],w);
		}
		memset(mark,false,sizeof(mark));
		while(m--){
			cin>>tt;
			mark[mapp[tt]]=true;
		}
		queue<int> q;
		memset(inq,false,sizeof(inq));
		for(int i=0;i<=cnt;i++)
			for(int j=0;j<=cap;j++)
				dp[i][j]=INF;
		dp[1][cap]=0;
		q.push(1);
		inq[1]=true;
//		cout<<1<<endl;
		while(!q.empty()){
//			cout<<3<<endl;
			int now=q.front();
			q.pop();
			inq[now]=false;
			if(mark[now])
				for(int i=0;i<cap;i++)
					dp[now][cap]=min(dp[now][i],dp[now][cap]);
			for(int e=head[now];e!=-1;e=edges[e].next){
//				cout<<4<<endl;
				int v=edges[e].to,w=edges[e].w;
				bool flag=false;
				for(int i=cap;i>=0;i--)
					if(i>=w){
						if(dp[v][i-w]>dp[now][i]+w){
//							cout<<5<<endl;
							dp[v][i-w]=dp[now][i]+w;
							flag=true;
						}
					}
				if(flag&&!inq[v]){
//					cout<<6<<endl;
					inq[v]=true;
					q.push(v);
				}
			}
		}
//		cout<<2<<endl;
		int ans=INF;
		for(int i=0;i<=cap;i++)
			ans=min(dp[2][i],ans);
		if(ans==INF)
			printf("-1\n");
		else
			printf("%d\n",ans);
	}
	return 0;
}

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

int main(){
  string s; cin >> s;
  int size = s.size();
  //cout << size << endl;
  vector<int> amari(2019,0);
  amari[0]++;
  int ten = 1;
  int ans = 0;
  for(int i = size - 1; i >= 0; i--){
    int tmp = ( tmp + (s[i] - '0') * ten ) % 2019;
    ans += amari[tmp]++;
    ten = ( ten * 10 ) % 2019;
  }

  cout << ans << endl;
}



Measured memory_bytes: 3752
w, h, n = map(int, input().split())
l, r, t, b = 0, w, h, 0
for i in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    l = max(x, l)
  elif a == 2:
    r = min(x, r)
  elif a == 3:
    b = max(y, b)
  else:
    t = min(y, t)
if (r - l) <= 0 or (t - b) <= 0:
  print(0)
else:
  print((r - l) * (t - b))

Measured memory_bytes: 9204
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

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

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

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    int a, b;
    cin >> a >> b;
    rep(i, 5000) {
        if (8 * i / 100 == a && 10 * i / 100 == b) {
            print(i);
            return 0;
        }
    }

    print(-1);

    return 0;
}



Measured memory_bytes: 256
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    L, R = il()
    ret = 2019
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            ret = min(ret, (i * j) % 2019)
            if ret == 0:
                break
        else:
            continue
        break

    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3832
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CsTest
{
    public class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long min = long.MaxValue;
            for (long i = 1; i <= (long)Math.Sqrt(N); ++i)
            {
                long j = N / i;
                if (j * i != N) continue;
                min = Math.Min(min, i + j);
            }
            Console.WriteLine(min - 2);
        }
    }
}

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

int main(){
    long long N;
    cin>>N;
    vector<ll> L(N,0);
    for(ll i=0;i<N;i++)
    {
        cin>>L[i];
    }
    sort(L.begin(),L.end());
    // L.erase(std::unique(L.begin(), L.end()), L.end()); 
    ll res=0;
    for(ll a=0;a<N;a++){
        for(ll b=a+1;b<N;b++){
            for(ll c=b+1;c<N && L[c]<L[a]+L[b];c++){
                if(L[a]<L[b]+L[c] && L[b]<L[a]+L[c])
                {
                    res++;
                }
            }
        }
    }
    cout<<res;
}

Measured memory_bytes: 3632
#include<stdio.h>

int main()
{
	int tate[31];
	int w,n;
	int a,b;
	int i;
	int temp;
	
	for(i=1;i<=30;i++)tate[i]=i;
	scanf("%d",&w);
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{

		scanf("%d,%d",&a,&b);
		temp=tate[a];
		tate[a]=tate[b];
		tate[b]=temp;
	}
	
	for(i=1;i<=w;i++)printf("%d\n",tate[i]);
	
	return 0;
}

Measured memory_bytes: 596
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.StringTokenizer; 
import java.util.*;
 
public class Main 
{ 
   
    
    public static void main(String[] args) throws IOException 
    { 
  
       BufferedReader br = new BufferedReader( 
                              new InputStreamReader(System.in));
                              
                   int n =  Integer.parseInt(br.readLine());
                   HashMap<Integer,Integer>h=new HashMap<>();
                  StringTokenizer sa=new StringTokenizer(br.readLine());
                for(int i=0;i<n-1;i++){
                  
                     int p =  Integer.parseInt(sa.nextToken());
                     if(h.containsKey(p))
                     h.put(p,h.get(p)+1);
                     else
                     h.put(p,1);
                
                }
               
            //System.out.println(h.get(1));
                for(int i=0;i<n;i++){
                    if(h.containsKey(i+1))
                     System.out.println(h.get(i+1));
                     else
                System.out.println("0");
                }
                   
                
                     
    }
    }
 


Measured memory_bytes: 71152
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define MOD 1000000007
#define CAP 10000000
#define inf 1000000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}
#define dbg(x) cout <<#x<<":"<<x<<endl;
ll max1(ll a, ll b, ll c=-inf, ll d=-inf) {ll mx1=(a>b)?a:b, mx2=(c>d)?c:d; return ((mx1>mx2)?mx1:mx2);}
#define int ll

struct node {
	vector<int> v,w;
	lld len;
	lld lenEx;
};

bool cmp(pii a, pii b) {
	return a.f - a.s > b.f - b.s;
}

node nodes[601];
int n,m;

set<pii> candidates;

void dfs(int index) {
	if(nodes[index].len >= 0) return;

	if(index==n-1) {
		nodes[index].len = 0;
		nodes[index].lenEx = 0;
		return;
	}

	lld ans = 0;
	int len = nodes[index].v.size();

	lld mx = -inf;
	int mnx = -1;

	for(int i=0;i<len;i++) {
		dfs(nodes[index].v[i]);

		if(mx < nodes[nodes[index].v[i]].len) {
			mx = nodes[nodes[index].v[i]].len;
			mnx = i;
		}
		ans += (nodes[nodes[index].v[i]].len);
	}

	candidates.insert({index, nodes[index].v[mnx]});

	ans /= 1.0*len;
	ans += 1.0;

	nodes[index].len = ans;
}

pii cur;

void dfs1(int index) {
	if(nodes[index].len >= 0) return;

	if(index==n-1) {
		nodes[index].len = 0;
		nodes[index].lenEx = 0;
		return;
	}

	lld ans = 0;
	int len = nodes[index].v.size();

	int off = 0;

	for(int i=0;i<len;i++) {
		dfs1(nodes[index].v[i]);

		if(index==cur.f && nodes[index].v[i]==cur.s) off++;
		else ans += (nodes[nodes[index].v[i]].len);
	}

	if(len-off==0) ans = inf;
	else ans /= 1.0*(len-off);
	ans += 1.0;

	nodes[index].len = ans;
}

signed main() {
	fast;

	cin>>n>>m;

	for(int i=0;i<n;i++) nodes[i].len = nodes[i].lenEx = -1;

	for(int i=0;i<m;i++) {
		int u,v;
		cin>>u>>v;
		u--;
		v--;
		nodes[u].v.pb(v);
	}

	dfs(0);
	lld ans = nodes[0].len;

	for(auto x: candidates) {
		cur = x;
		for(int i=0;i<n;i++) nodes[i].len = -1;

		dfs1(0);
		ans = min(ans, nodes[0].len);
	}

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


}

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

int main(){
    int n;
    cin >> n;
    vector<ll> x(n), y(n);
    rep(i, 0, n) cin >> x[i] >> y[i];
    int array[]={0,1,2,3,4,5,6,7};
    double sum = 0;
    do{
        for(int i=0; i<n-1; i++){
            auto ix = array[i];
            auto iy = array[i+1];
            double dx = x[ix] - x[iy];
            double dy = y[ix] - y[iy];
            sum += sqrt(dx * dx + dy * dy);
        }
    }while(next_permutation(array,array+n));
    double div = 1;
    rep(i, 1, n+1) div *= (i);
    cerr << div << endl;
    printf("%.10lf\n", sum/div);
    return 0;
}

Measured memory_bytes: 3852
import sys

input = sys.stdin.readline
N = int(input())
Ss = [''.join(sorted(input().rstrip("\n"))) for _ in range(N)]

import collections

Co = collections.Counter(Ss)
Su = 0
for _, c in Co.most_common():
    if c < 2:
        break
    Su += (c - 1) * c // 2

print(Su)

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

#define rep(i, j) for(int i=0; i < (int)(j); i++)
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }

int main() {
    int N; cin >> N;
    vector<string> S(N); cin >> S;
    int ans = 0;
    int a = 0, b = 0, ab = 0;
    rep(i, N) {
        assert(S[i].size() >= 2);
        a += S[i].back() == 'A';
        b += S[i].front() == 'B';
        ab += S[i].back() == 'A' and S[i].front() == 'B';
        rep(j, S[i].size() - 1) if(S[i][j] == 'A' and S[i][j + 1] == 'B') ans++;
    }
    a -= ab;
    b -= ab;
    ans += max(0, ab - 1);
    if(ab > 0 and a > 0 and b > 0) {
        ans += 2;
        a--; b--;
        ans += min(a, b);
    } else if (ab > 0 and (a > 0 or b > 0)) {
        ans += 1;
    } else {
        ans += min(a, b);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

constexpr ll mod = 1000000007;
constexpr ll modsize = 5000010;
vector<ll> fac(modsize);
vector<ll> inv(modsize);
vector<ll> facinv(modsize);

void modcalc() {
	if (modsize == 0) abort();
	fac[0] = 1; fac[1] = 1; inv[1] = 1;
	facinv[0] = 1; facinv[1] = 1;
	for (ll i = 2; i < modsize; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		facinv[i] = facinv[i - 1] * inv[i] % mod;
	}
}

ll modinv(ll a) {
	if (a == 0) abort();
	ll b = mod, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= mod;
	if (u < 0) u += mod;
	return u;
}

ll modpow(ll a, ll b) {
	ll ans = 1;
	a %= mod;
	while (b) {
		if (b & 1) ans = ans * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans;
}

ll modcomb(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[k] % mod * facinv[n - k] % mod;
}

ll modperm(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[n - k] % mod;
}

ll modhom(ll n, ll k) {
	if (n < 0 || k < 0 || n == 0 && k > 0) return 0;
	if (n == 0 && k == 0) return 1;
	return fac[n + k - 1] * facinv[k] % mod * facinv[n - 1] % mod;
}

ll dp[1000010], sum[1000010];

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	modcalc();

	ll n, h, d;
	cin >> n >> h >> d;
	ll coeff = 0;
	for (int i = 1; i <= n; i++) coeff += fac[i];
	coeff %= mod;
	dp[0] = sum[0] = 1;
	for (int i = 1; i <= h; i++) {
		int idx = i - d - 1;
		if (idx < 0) dp[i] = coeff * sum[i - 1] % mod;
		else dp[i] = coeff * (sum[i - 1] - sum[idx] + mod) % mod;
		sum[i] = sum[i - 1] + dp[i];
		if (sum[i] >= mod) sum[i] -= mod;
	}
	cout << dp[h] * fac[n] % mod * modinv(coeff) % mod << '\n';
}

Measured memory_bytes: 133120