akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() {
		String s = in.next();
		StringBuilder sb = new StringBuilder();

		for (int i=0; i<s.length(); i++) {
			if (s.charAt(i) == '@') {
				int c = s.charAt(i+1) - '0';
				for (int j=0; j<c; j++) {
					sb.append(s.charAt(i+2));
				}
				i += 2;
			} else {
				sb.append(s.charAt(i));
			}
		}

		out.println(sb);
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		while(in.hasNext()) solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 25936
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

ll choco[3];

void solve(void){
    ll H, W;
    cin >> H >> W;
    ll dif = INF;
    if (H%3==0||W%3==0) dif = 0LL;
    else dif = min(H, W);
    Rep(1, H-1, h) {
        choco[0] = h*W;
        choco[1] = (H-h)*(W/2);
        choco[2] = (H-h)*(W-W/2);
        sort(choco, choco+3);
        dif = min(dif, choco[2]-choco[0]);
    }
    Rep(1, W-1, w) {
        choco[0] = H*w;
        choco[1] = (W-w)*(H/2);
        choco[2] = (W-w)*(H-H/2);
        sort(choco, choco+3);
        dif = min(dif, choco[2]-choco[0]);
    }

    cout << dif << '\n';
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 256
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

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

    ll n, m;
    cin >> n >> m;

    ll soma = 0;
    for(int i = 0;i < m; i++) {
        ll x;
        cin >> x;
        soma += x;
    }
    if(soma > n) cout << -1 << "\n";
    else cout << n-soma << "\n";
}


Measured memory_bytes: 3636
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

use std::io::Write;

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        h: usize,
        w: usize,
        q: usize,
        s: [chars; h],
        ask: [(usize1, usize1, usize, usize); q],
    }
    let mut s: Vec<Vec<bool>> = s.into_iter().map(|s| s.into_iter().map(|c| c == '1').collect()).collect();
    for s in s.iter_mut() {
        s.push(false);
    }
    s.push(vec![false; w + 1]);
    let mut cnt = vec![vec![0; w + 1]; h + 1];
    let mut row = vec![vec![0; w + 1]; h + 1];
    let mut col = vec![vec![0; w + 1]; h + 1];
    for i in (0..h).rev() {
        for j in (0..w).rev() {
            for a in [&mut cnt, &mut row, &mut col].iter_mut() {
                a[i][j] = a[i + 1][j] + a[i][j + 1] - a[i + 1][j + 1];
            }
            if s[i][j] {
                cnt[i][j] += 1;
            }
            if s[i][j] && s[i][j + 1] {
                row[i][j] += 1;
            }
            if s[i][j] && s[i + 1][j] {
                col[i][j] += 1;
            }
        }
    }
    let func = |sum: &Vec<Vec<usize>>, a: usize, b: usize, c: usize, d: usize| -> usize {
        sum[a][b] - sum[a][d] - sum[c][b] + sum[c][d]
    };
    for (a, b, c, d) in ask {
        let mut ans = func(&cnt, a, b, c, d);
        ans -= func(&row, a, b, c, d - 1);
        ans -= func(&col, a, b, c - 1, d);
        writeln!(out, "{}", ans).ok();
    }
}

fn main() {
    run();
}


Measured memory_bytes: 153072
from string import ascii_lowercase 

S = ""
while True:
    try:
        S += input().lower()
    except EOFError:
        break

d = {a:0 for a in ascii_lowercase}
for s in S:
    if s in d:
        d[s] += 1

for a in ascii_lowercase:
    print('{} : {}'.format(a, d[a]))


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




int main(){
    ll N, W; cin >> N >> W;
    vector<ll> W_(N), V_(N); for(int i = 0; i < N; i++) cin >> W_[i] >> V_[i];
    vector<vector<ll>> DP(N+1, vector<ll>(N*1000+1, 1e13));
    for(int i = 0; i <= N; i++) DP[i][0] = 0;
    for(int i = 1; i <= N; i++){
        ll v = V_[i-1], w = W_[i-1];
        for(int j = 1; j <= N*1000; j++){
            //if(j < v) DP[i][j] = min(DP[i-1][j], DP[i][j-1]);
            //else DP[i][j] = min(DP[i-1][j-v]+w, DP[i-1][j]);
            if(j >= v)DP[i][j] = min(DP[i-1][j-v]+w, DP[i-1][j]);
            else DP[i][j] = DP[i-1][j];
        }
    }
    ll ans = 0;
    for(int i = 1; i <= N*1000; i++) if(DP[N][i] <= W) ans = max(0, i);
    cout << ans << endl;

    
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

int main(){
    int N,M=0;
    cin>>N;
    map<string,int>mp;
    rep(i,N){
        string S;
        cin>>S;
        mp[S]++;
        M=max(mp[S],M);
    }
    for(auto x:mp){
        if(x.second==M){
            cout<<x.first<<endl;
        }
    }



    return 0;
}

//a=97,z=122

Measured memory_bytes: 25216
// スタックサイズ: 100MB

#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1e18;
const double EPS = 1e-10;
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }



int main() {
	fastio;
	
	ll N, M, R;
	cin >> N >> M >> R;
	vll r(R);
	rep(i, R) {
		cin >> r[i];
		--r[i];
	}
	sort(all(r));
	vector<vll> d(N, vll(N, INF));
	rep(i, N) d[i][i] = 0;
	rep(i, M) {
		ll a, b, c;
		cin >> a >> b >> c;
		--a, --b;
		d[a][b] = min(d[a][b], c), d[b][a] = min(d[b][a], c);
	}
	rep(i, N) rep(j, N) rep(k, N) {
		d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
	}


	ll ans = INF;
	do {
		ll tmp = 0;
		rep(i, R - 1) tmp += d[r[i]][r[i + 1]];
		ans = min(tmp, ans);
	} while (next_permutation(r.begin(), r.end()));
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
 
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;
using namespace std;

const ll SIZE = 1e5+10;
ll n;
ll a[SIZE], b[SIZE];


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


Measured memory_bytes: 1792
import itertools

N, M, X = map(int, input().split())
books = [list(map(int, input().split())) for i in range(N)]


All = [0] * (M+1)
for book in books:
  All = [x + y for (x, y) in zip(All, book)]
Min = All[0]
if all([i >= X for i in All[1:]]):
  for bks in itertools.product([0,1], repeat=N):
    ans = [0] * (M+1)
    par = [i for i, x in enumerate(bks) if x == 1]
    for book in par:
      ans = [x + y for (x, y) in zip(ans, books[book])]
    if all([i >= X for i in ans[1:]]) and Min > ans[0]:
      Min = ans[0]
  print(Min)
else: print(-1)



Measured memory_bytes: 9248
#include<bits/stdc++.h>
using namespace std;
#define int long long int

signed main(){
    int t = 1; //cin >> t;
    while(t--){
    	int n; cin >> n;
    	set<int> s;
    	while(n--)
    	{
    		int x; cin >> x;
    		if(s.find(x) == s.end())
    			s.insert(x);
    		else s.erase(x);
    	}
    	cout << s.size();
    }    	
}

Measured memory_bytes: 8128
nums = [*1..gets.to_i]
sets = nums.combination(2).to_a

count = 0
sets.each do |set|
  first = set[0]
  second = set[1]
  if !((first.even? && second.even?) || (!first.even? && !second.even?))
    count += 1
  end
end
p count

Measured memory_bytes: 2172
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var s=sc.Sa;
		string a="";
		for(int i = 0;i<n;i++) {
			a+=s[0][i];
			a+=s[1][i];
		}
		Console.WriteLine("{0}",a);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13140
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <climits>
#include <utility>
#include <deque>
#include <list>
using namespace std;

#define FOR_ALL_CIN(xs) for (auto& x : (xs)) cin >> x

int gcd(unsigned long long a, unsigned long long b) { // a > b
	if (b == 0)return a;
	a = a % b;
	return a > b ? gcd(a, b) : gcd(b, a);
}

int main()
{
	cout << fixed << setprecision(6);
	int n;
	cin >> n;
	vector<pair<int, int>> bals(n);
	for (auto& ba : bals) cin >> ba.second >> ba.first;
	sort(bals.begin(), bals.end());

	int time = 0;
	for (auto ba: bals) {
		time += ba.second;
		if (ba.first < time) {
			cout << "No" << endl;
			return 0;
		}
	}

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

Measured memory_bytes: 1792
#include<iostream>
#include <string>
#include<stdio.h>
#include <math.h>


using namespace std;


int main() {
	int N, X;
	double X2;

	cin >> N;

	X = N / 1.08;
	X2 = N / 1.08;

	int A, B;
	A = X * 1.08;
	B = (X + 1) * 1.08;

	if (X == X2) cout << X << endl;

	else if (A == N || B == N) {
		cout << X + 1 << endl;
	}

	else cout << ":(" << endl;

	
	return 0;
}

	






Measured memory_bytes: 256
a, b = map(int, input().split())
if a < 0 and b > 0:
    print('Zero')
elif a > 0 and b > 0:
    print('Positive')
else:
    if (a - b - 1) % 2 == 0:
        print('Positive')
    else:
        print('Negative')

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int n, x;

int main(int argc, char const *argv[])
{
	scanf("%d %d", &n, &x);
	for(int i = 1; i <= n; i++) {
		scanf("%d", a + i);
	}
	long long ans = 0;
	for(int i = 1; i < n; i++) {
		if(a[i] + a[i + 1] >= x) {
			int need = a[i] + a[i + 1] - x;
			ans += need;

			if(a[i + 1] >= need) {
				a[i + 1] -= need;
			} else {
				a[i] -= need - a[i + 1];
				a[i + 1] = 0;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 640
N, M = map(int, input().split())
S = [True]*(N+1)
for _ in range(M):
  a = int(input())
  S[a] = False
T = [0]*(N+1)
T[0] = 1
T[1] = 1 if S[1] else 0
for i in range(2, N+1):
  if S[i]:
    T[i] = (T[i-1]+T[i-2])%1000000007
print(T[N])


Measured memory_bytes: 44888
n,a,b,c,d = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp
stop = []
(n-1).times do |i|
  if s[i] == '#' && s[i+1] == '#'
    stop.push(i)
  end
end
stop.each do |x|
  if (x+1 > a && x+2 < c) || (x+1 > b && x+2 < d)
    puts "No"
    exit
  end
end
if b < c && c < d
  puts "Yes"
elsif b < c && c > d
  (b-2).upto(d-2) do |i|
    if s[i] == '.' && s[i+1] == '.' && s[i+2] == '.'
      puts "Yes"
      exit
    end
  end
  puts "No"
else
  puts "Yes"
end

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

int main()
{
    int h, w;
    cin >> h >> w;
    string s[h];
    for(int i=0;i<h;i++){cin >> s[i];}
    for(int j=0;j<h;j++){
        for(int k=0;k<w;k++){
            if(s[j].at(k) == '.'){
                int tmp = 48;
                if(j>0){
                    if(k>0) {if(s[j-1].at(k-1) == '#') tmp++;}
                    if(s[j-1].at(k) == '#') tmp++;
                    if(k<w-1) {if(s[j-1].at(k+1) == '#') tmp++;}
                }
                if(k>0) {if(s[j].at(k-1) == '#') tmp++;}
                if(k<w-1) {if(s[j].at(k+1) == '#') tmp++;}
                if(j<h-1){
                    if(k>0) {if(s[j+1].at(k-1) == '#') tmp++;}
                    if(s[j+1].at(k) == '#') tmp++;
                    if(k<w-1) {if(s[j+1].at(k+1) == '#') tmp++;}
                }
                
                s[j].at(k) = (char)tmp;

            }
        }
    }
    for(int i=0;i<h;i++){
        cout << s[i] << endl;
    }

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  bool zero = false;
  vector<int64_t> data(N);
  for(int i = 0; i < N; i++) {
    int64_t a;
    cin >> a;
    if(a == 0) {
      zero = true;
    }
    else {
      data.at(i) = a;
    }
  }
  if(zero) {
    cout << 0 << endl;
  }
  else {
    int64_t ans = data.at(0);
    bool over = false;
    for(int i = 1; i < N; i++) {
      if(ans * data.at(i) > 1000000000000000000 || ans * data.at(i) < ans) {
        over = true;
      }
      else {
        ans *= data.at(i);
      }
    }
    if(over) {
      cout << -1 << endl;
    }
    else {
      cout << ans << endl;
    }
  }
}

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

const ll mo=1000000007;

int main() {
  ll ans=1;
  int n,a;
  cin >> n;
  vector<int>x(n+1);
  vector<int>y(n+1);
  vector<int>z(n+1);
  rep(i,n){
  	int tmp=0;
  	cin >> a;
  	x.at(i+1)=x.at(i);
  	y.at(i+1)=y.at(i);
  	z.at(i+1)=z.at(i);
  	if(x.at(i)==a) x.at(i+1)++;
  	else if(y.at(i)==a) y.at(i+1)++;
  	else z.at(i+1)++;
  	if(x.at(i)==a) tmp++;
  	if(y.at(i)==a) tmp++;
  	if(z.at(i)==a) tmp++;
  	ans=(ans*tmp)%mo;
  }
  cout << ans << endl;
}


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

typedef long long int ll;

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

    if(s[0] == s[1] && s[1] == s[2] && s[0] == s[2]){
        cout << "No";
        return 0;
    }
    cout << "Yes";
    
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

struct UnionFind { // {{{
    vector<int> u;
    explicit UnionFind(int n): u(n+5, -1) {}
    int  size(int x)        { return -u[root(x)]; }
    int  root(int x)        { return (u[x] < 0)? x : (u[x] = root(u[x])); }
    bool same(int x, int y) { return (root(x) == root(y)); }
    bool unite(int x, int y){ return (x=root(x)) == (y=root(y))? false : (u[x]+=u[y], u[y]=x, true); }
}; // }}}

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

    var(i64, N, M);
    UnionFind uf(N);

    rep(i, 0, M) {
        var(int, a, b);
        --a, --b;
        uf.unite(a, b);
    }

    const auto f = [](i64 n) -> i64 { return n * (n - 1) / 2; };

    const i64 x = uf.size(0);
    const i64 y = uf.size(1);
    const i64 other = N - x - y;

    print(max<i64>(
            f(x + other) + f(y) - M,
            f(x) + f(y + other) - M
    ));

    return 0;
}


Measured memory_bytes: 640
import itertools

abcd = []
N,M,Q = map(int,input().split())
for i in range(Q):
    a,b,c,d = map(int,input().split())
    abcd.append([a,b,c,d])
  
A = itertools.combinations_with_replacement(list(range(1,M+1)),N)
ans = 0
for i in A: 
    _sum = 0
    for j in abcd: 
        if i[j[1]-1] - i[j[0]-1] == j[2]:
            _sum += j[3]
    if ans < _sum:
        ans = _sum
    
print(ans)        
            


Measured memory_bytes: 67528
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;

int A[100000],n;

int main(){
    cin>>n;
    for(int i=0;i<n;i++) scanf("%d",&A[i]);

    int q,key,sum=0;
    cin>>q;
    for(int i=0;i<q;i++){
        scanf("%d",&key);
        if( *(lower_bound(A,A+n,key))==key) sum++;
    }
    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 3532
io = STDIN
n=io.gets.chomp.to_i
a=io.gets.chomp.split.map(&:to_i)
def turn(s,x)
  add,cnt,sign=s
  add+=x
  sign*=-1
  if sign==1
    if add<=0
      delta = add.abs+1
      add+=delta
      cnt+=delta
    end
  else
    if add>=0
      delta = add.abs+1
      add-=delta
      cnt+=delta
    end
  end
  [add,cnt,sign]
end
s1=a.inject([0,0,1]) do |s,x|
  turn(s,x)
end
s2=a.inject([0,0,-1]) do |s,x|
  turn(s,x)
end
puts [s1[1],s2[1]].min

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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
using P = pair<int,int>;
//Write FroM this Line

int main()
{
	int N, M;
	cin >> N >> M;
	vector<P> A(N);
	rep(i,N) cin >> A[i].first >> A[i].second;  // A[i] = {days, money};

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

	int count = 0;
	priority_queue<int> que;
	ll ans = 0;
	for(int day = M - 1; day >= 0; day--){
		//day日目に受ける仕事を決める。
		// A[i].first が M - day となる仕事をqueに入れる。
		for(int i = count; i < N; i++){
			if(A[i].first == M - day){
				que.push(A[i].second);
			} else {
				count = i; 
				break;
			}
		}
		if(que.empty()) {
			// day 日に受けれる仕事は無い
			continue;
		} else {
			int kane = que.top(); que.pop();
			ans += kane;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1660
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    a = input().split()
    a.sort(reverse=True)

    print(int(a[0] + a[1]) + int(a[2]))


main()


Measured memory_bytes: 4820
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
using namespace std;

int main() {
	string s,t;
	cin >> s>>t;
	if (s[0]==t[2]&&s[1]==t[1]&&s[2]==t[0]) {
	cout << "YES" << endl;
	}
	else
	cout << "NO" << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;
typedef double D;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }



struct Point2D { 
	double x, y;
	Point2D (double a=0, double b=0) : x(a), y(b) {}
};

double dist2D(const Point2D& a, const Point2D& b) { return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) ); }


// 四角形 頂点座標表記
struct Rectangle {
	Point2D lt, rt, lb, rb;
	Point2D cent;
};

void rectCent(Rectangle& r) {
	r.cent.x = (r.rt.x + r.lt.x)/2.;
	r.cent.y = (r.rt.y + r.rb.y)/2.;
}

bool rect_collision(Rectangle& a, Rectangle& b) {
	rectCent(a); rectCent(b);
	D x_dist = fabs(a.cent.x - b.cent.x), y_dist = fabs(a.cent.y - b.cent.y);
	if (x_dist <= (a.cent.x - a.lt.x) + (b.cent.x - b.lt.x)
		&& y_dist <= (a.lt.y - a.cent.y) + (b.lt.y - b.cent.y)) return true;
	return false;
}


int main() {
	Rectangle a, b;
	
	while (cin>>a.lb.x>>a.lb.y>>a.rt.x>>a.rt.y>>b.lb.x>>b.lb.y>>b.rt.x>>b.rt.y) {
		a.lt.x = a.lb.x; a.lt.y = a.rt.y;
		a.rb.x = a.rt.x; a.rb.y = a.lb.y;
		
		b.lt.x = b.lb.x; b.lt.y = b.rt.y;
		b.rb.x = b.rt.x; b.rb.y = b.lb.y;
		
		if (rect_collision(a, b)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
typedef pair<ll, ll> Pair;
template <class T> T input() {T t; cin>>t; return t;}
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define CHMAX(a,b) a = max(a,b)
#define CHMIN(a,b) a = min(a,b)
#define FIND(x,key) x.find(key) != x.end()
#define IN_RANGE_V2(v,k,x,y) (0<=x+dx[k]&&x+dx[k]<v[y].size()&&0<=y+dy[k]&&y+dy[k]<v.size())
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define PRINT_ARRAY_H(a) REPALL(__i,a) {cout<<a[__i]<<(__i != a.size()-1 ? " " : "");} newline;
#define PRINT_ARRAY_V(a) REPALL(__i,a) {cout<<a[__i]<<endl;}
#define e1 first
#define e2 second
#define newline putchar('\n')
#define cspace ' '
#define sspace " "
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;
const VI dx = {1, 0, -1, 0};
const VI dy = {0, 1, 0, -1};
//const VI dx = {1, 1, 0, -1, -1, -1, 0, 1};
//const VI dy = {0, 1, 1, 1, 0, -1, -1, -1};

VVLL values(3333, VLL(3333));
vector<vector<vector<ll>>> dp(3333, VVLL(3333, VLL(4, 0)));

void solve()
{
    ll R, C, K;
    cin>>R>>C>>K;
    REP(i,K) {
        ll r, c, v;
        cin>>r>>c>>v;
        r--; c--;
        values[r][c] = v;
    }
    dp[0][0][1] = values[0][0];
    REP(i,R+C-1) {
        REP(j,R) {
            ll k = i - j;
            if (k < 0) break;
            else if (k >= C) continue;

            REP(t,4) {
                CHMAX(dp[j][k+1][t], dp[j][k][t]);
                CHMAX(dp[j][k+1][t+1], dp[j][k][t] + values[j][k+1]);
                CHMAX(dp[j+1][k][0], dp[j][k][t]);
                CHMAX(dp[j+1][k][1], dp[j][k][t] + values[j+1][k]);
            }
        }
    }
    cout<<*MAX_ELEMENT(dp[R-1][C-1])<<endl;
}

int main()
{
    cout<<fixed<<setprecision(20);
    int __t = 1;
    //cin>>__t;
    REP(i,__t) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 871356
#include <stdio.h>
int main (void)
{
  int a,b,k;
  char op;
  for( ; ; ) {
    scanf("%d %c %d",&a,&op,&b);
    if (op == '+'){k = a + b;}
    else if (op == '-'){k = a - b;}
    else if (op == '*'){k = a * b;}
    else if (op == '/'){k = a / b;}
    else {break;}
    printf("%d\n",k);
  }
  return 0;
}




Measured memory_bytes: 2696
import numpy as np

S = input()
L = []
N = len(S)

if S[-1] == '<':
    S += '><'
else:
    S += '<>'

index = 0
for n in range(N+1):
    if S[n: n + 2] == '><':
        L.append(S[index: n + 1])
        index = n + 1


def calc(string):
    K = len(string)
    c = K
    for k in range(K - 1):
        if string[k: k + 2] == '<>':
            c = k + 1
            break
    a = min(c, K - c)
    b = max(c, K - c)
    return a * (a - 1) // 2 + b * (b + 1) // 2


ans = 0
for string in L:
    ans += calc(string)

print(ans)


Measured memory_bytes: 21388
#include<bits/stdc++.h>
using namespace std;
long int num(long int n,int k)
{
  long int x=0;
  while(n>0)
  {
    n=n/k;
    x++;
  }
  return x;
}
int main()
{
  long int n,res;
  int k;
  cin>>n>>k;
  res=num(n,k);
  cout<<res<<endl;
  return 0;
}

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

vector< vector<int> > to;
vector<int> ans;

void dfs(int c,int p=-1){
  for(int u:to.at(c)){
    if(u==p){
      continue;
    }
    ans.at(u)+=ans.at(c);
    dfs(u,c);
  }
}
int main(){
  int n,q;
  cin >> n >> q;
  //v.resize(N);
  to.resize(n+1);
  for(int i=0;i<n-1;i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    to.at(a).push_back(b);
    to.at(b).push_back(a);
  }
  ans.resize(n);
  for(int i=0;i<q;i++){
    int p,x;
    cin >> p >> x;
    p--;
    ans.at(p)+=x;
  }
  dfs(0);
  for(int i=0;i<n;i++){
    cout << ans.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 26624
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

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

const ll mod = 1000000007;


map<string, int> memo;

using P=pair<int, int>;




/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/

ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}

void comb(vector<vector <long long int> >& v) {
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}


int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n)cin >> a[i];
	sort(a.begin(), a.end());
	ll ans = 1e9;
	for (ll i = 0; i < n - k+1; i++) {
		ans = min(ans, (a[i + k-1] - a[i]));
	}
	cout << ans << endl;
	return 0;
}













Measured memory_bytes: 1024
#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>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
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 pair<int,int> pii;
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 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 floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
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 / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  ll N, M;
  cin >> N >> M;
  ll s = 0;
  rep(i, M) {
    ll A;
    cin >> A;
    s += A;
  }
  if(s > N) {
    fin(-1);
  } else {
    fin((N - s));
  }
}

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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (ll i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

int cnt = 0;


void solve()
{
	int n; cin >> n;
	set<string> s;
	vector<string> a(n);
	bool ok = true;
	forn(i, n) 
	{
		string p; cin >> p;
		s.insert(p);
		a[i] = p;
		if (i != 0 && a[i][0] != a[i - 1][a[i - 1].length() - 1]) ok = false;
	}
	if (ok && s.size() == n) cout << "Yes";
	else cout << "No";
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;

const ll INF = (1LL<<60);

int main(){

    ll n; cin >> n;
    string s; cin >> s;

    ll ans = 1;
    char color = s[0];
    rep2(i, 1, n){
        if(s[i] != color){
            color = s[i];
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BC
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  [n, k] <- map readInt . BC.words <$> BC.getLine
  print $ solve n k

solve :: Int -> Int -> Int
solve n k = (n + k - 3) `div` (k - 1)

readInt :: BC.ByteString -> Int
readInt = fst . fromJust . BC.readInt


Measured memory_bytes: 380
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AAirplane solver = new AAirplane();
        solver.solve(1, in, out);
        out.close();
    }

    static class AAirplane {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();

            long answer = Integer.MAX_VALUE;
            answer = Math.min(answer, a + b);
            answer = Math.min(answer, b + c);
            answer = Math.min(answer, c + a);

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef long long int ll;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
// online submission
#endif
	map<ll,ll> mp;
	ll n;
	cin>>n;
	for(int i=2;(long long)i*i<=n;i++){
		if(n%i==0){
			int count=0;
			while(n%i==0){
				n/=i;
				count++;
			}
			mp[i]=count;
		}

	}
	if(n>1){
		mp[n]=1;
	}
	int count=0;
	for(auto it: mp){
		int i=1;
		while(i<=it.second){
			count++;
			it.second-=i;
			i++;
		}
	}
	cout<<count;
}

Measured memory_bytes: 3624
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		List<String> list = new ArrayList<String>();
		for (int i = 0; i < 10001; i++) {
			String line = sc.nextLine();
			if (line.equals("0")) {
				break;
			}
			list.add(line);
		}

		for (int j = 1; j < list.size()+1; j++) {
			String string = list.get(j - 1);
			System.out.println("Case " + j + ": " + string);
		}
	}

}

Measured memory_bytes: 68096
#include <stdio.h>

int main(){
int a,b,c,d,e;
while(a=scanf("%d %d",&b,&c) != EOF){
e=10;
for(d=1;d<=16;d++){
if(e>(b+c)) break;
e=e*10;
}
printf("%d\n",d);
}
return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 


int main() {
  int n; cin >> n;
  vi a(n);
  rep(i,n ) cin >> a[i];
  ll stock = 0;
  ll money = 1000;
  ll ans = 1000;
  rep(i,n-1) {
    if (a[i] < a[i+1])  {
      ll maxBuy = money / a[i];
      stock += maxBuy;
      money -= maxBuy * a[i];
    } 
    if (a[i] > a[i+1]) {
      money += stock * a[i];
      stock = 0;
      chmax(ans, money);
    }
  }
  money += stock * a[n-1];
  chmax(ans, money);
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 3720
import sys
import numpy as np
import numba

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

i4 = numba.int32

def get_input():
    D = int(readline())
    C = np.array(readline().split(), np.int32)
    S = np.array([readline().split() for _ in range(D)], np.int32)
    return D, C, S

@numba.njit((i4, i4[:], i4[:, :], i4[:]), cache=True)
def first_computation(D, C, S, T):
    x = 0
    last = np.zeros((26, D), np.int32)
    for d in range(D):
        if d:
            last[:, d] = last[:, d - 1]
        i = T[d]
        x += S[d, i]
        last[i, d] = d + 1
        for i in range(26):
            x -= C[i] * (d + 1 - last[i, d])
    return last, x

@numba.njit((i4, i4[:], i4[:, :], i4[:], i4[:, :], i4, i4), cache=True)
def difference_update(D, C, S, T, last_day, d, q):
    p = T[d]
    T[d] = q
    x = S[d, q] - S[d, p]

    i = np.searchsorted(last_day[p], d + 1)
    d_p = last_day[p, i - 1] if i >= 1 else 0
    coef = 0
    for k in range(d, D):
        if last_day[p, k] == d + 1:
            # k 日目に入るスコアの変更
            coef += d_p - d - 1
            last_day[p, k] = d_p
        else:
            break
    x += coef * C[p]

    coef = 0
    for k in range(d, D):
        if last_day[q, k] < d + 1:
            coef += (d + 1 - last_day[q, k])
            last_day[q, k] = d + 1
        else:
            break
    x += coef * C[q]
    return x

def first_strategy(D, C, S):
    # S - 26C をキーにして greedy
    key = S - 26 * C
    T = np.empty(D, np.int32)
    for d in range(D):
        T[d] = np.argmax(key[d])
    return T

def output(T):
    T += 1
    print(*T, sep='\n')

D,C,S = get_input()

T = first_strategy(D,C,S)
output(T)
#last_days, score = first_computation(D,C,S,T)

Measured memory_bytes: 107464