akhauriyash/Code-Regression huggingface dataset:
from scipy.sparse.csgraph import dijkstra, shortest_path
from scipy.sparse import csr_matrix
K = int(input())

class Graph(object):

    def __init__(self, K):
        self.K = K
        self.weights = {}

    def add_edge(self, node1, node2, weight):
        if (node1, node2) in self.weights:
            self.weights[(node1, node2)] = min(self.weights[(node1, node2)], weight)
        else:
            self.weights[(node1, node2)] = weight

    def get_csr_matrix(self):
        n1, n2, w = [], [], []
        for (node1, node2), weight in self.weights.items():
            n1.append(node1)
            n2.append(node2)
            w.append(weight)
        return csr_matrix((w, (n1, n2)), shape=(self.K, self.K))

g = Graph(K)

for i in range(K - 1):
    g.add_edge(i, i + 1, 1)
    g.add_edge(i, (i * 10) % K, 10**(-16))

g.add_edge(K - 1, 0, 1)
g.add_edge(K - 1, ((K - 1) * 10) % K, 10**(-16))
d = dijkstra(g.get_csr_matrix(), directed=True, indices=1)
print(int(d[0]) + 1)

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

struct card{
    char s;
    int n;
};

void trace(card a[], int n){
	for (int i = 0; i < n; i++){
		cout << a[i].s << a[i].n;
		if (i != n - 1) cout << " ";
		else cout << endl;
	}
}

void swap(card *a, card *b){
	card temp = *a;
	*a = *b;
	*b = temp;
}

void bubbleSort(card a[], int n){
	int flag = 1;
	for(int i = 0; flag; i++){
		flag = 0;
		for(int j = n - 1; j > i; j--){
			if(a[j - 1].n > a[j].n){
				swap(a[j - 1], a[j]);
				flag = 1;
			}
		}
	}
}

void selectionSort(card a[], int n){
	for(int i = 0; i < n - 1; i++){
		int minj = i;
		for(int j = i + 1; j < n; j++){
			if(a[minj].n > a[j].n) minj = j;
		}
		swap(a[i], a[minj]);
	}
}

string orderCheck(string a[], string b[]){
    string message = "Stable";
    for(int i = 0; i < 9; i++)
        if(a[i] != b[i]) message = "Not stable"; 
    return message;
}

int main(void){
    int n;
    string str[36];
    card cards[36];
    string suitOrder[9], originalOrder[9];

    cin >> n;
    for(int i = 0; i < n; i++) cin >> str[i];

    for(int i = 0; i < n; i++){
        cards[i].s = str[i][0];
        cards[i].n = str[i][1] - 48;
        originalOrder[cards[i].n - 1] += cards[i].s;
    }

    bubbleSort(cards, n);
    trace(cards, n);
    for(int i = 0; i < n; i++) suitOrder[cards[i].n - 1] += cards[i].s;
    cout << orderCheck(suitOrder, originalOrder) << endl;

    for(int i = 0; i < n; i++){
        cards[i].s = str[i][0];
        cards[i].n = str[i][1] - 48;
    }

    selectionSort(cards, n);
    trace(cards, n);
    for(int i = 0; i < 9; i++) suitOrder[i] = "";
    for(int i = 0; i < n; i++) suitOrder[cards[i].n - 1] += cards[i].s;
    cout << orderCheck(suitOrder, originalOrder) << endl;

    return 0;
}



Measured memory_bytes: 3164
s = input()
q = int(input())
qs = [input().split() for i in range(q)]
n = False
left= right = ""
for operation in qs:
    if operation[0] == '1':
        n = not n
    if operation[0] == '2':
        t , f, c = operation
        f = int(f)
        if n:
            f = 1 if f != 1 else 2
        if f == 1:
            left=c+left
        elif f == 2:
            right+=c
s = left+s+right
print(s[::-1] if n else s)

Measured memory_bytes: 40676
X, Y = map(int, input().split(' '))

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

if X < Y:
    print(X)
elif X % Y == 0:
    print(-1)
elif gcd(X, Y) == 1:
    print(X)
else:
    tmp = X * gcd(X, Y)
    if tmp % Y != 0:
        print(tmp)
    else:
        print(X * int(X / gcd(X, Y)))

Measured memory_bytes: 3064
#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//using i128 = __int128_t;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
inline int topbit(int x) {return x == 0 ? -1 : 31-__builtin_clz(x);}
inline int topbit(long long x) {return x == 0 ? -1 : 63-__builtin_clzll(x);}
inline int botbit(int x) {return x == 0 ? 32 : __builtin_ctz(x);}
inline int botbit(long long x) {return x == 0 ? 64 : __builtin_ctzll(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
inline void print() {cout << "\n";}
template<class T>
inline void print(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cout << *itr << " ";
    print();
}
template<class T, class... Args>
inline void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
#ifdef MINATO_LOCAL
#define dump(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
inline void debug() {cerr << endl;}
template<class T>
inline void debug(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cerr << *itr << " ";
    debug();
}
template<class T, class... Args>
inline void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
#else
#define dump(x) void(0)
inline void debug() {}
template<class T> inline void debug(const vector<T> &v) {}
template<class T, class... Args> inline void debug(const T &x, const Args &... args) {}
#endif
struct Fast_ios {Fast_ios() {cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);};} fast_ios;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    string S,T; cin >> S >> T;
    int N = S.size();
    int M = T.size();

    int ans = 1e9;
    rep(i,N-M+1) {
        int cnt = 0;
        rep(j,M) {
            if (S[i+j]!=T[j]) cnt++;
        }
        chmin(ans,cnt);
    }

    cout << ans << ln;
}

Measured memory_bytes: 3552
use proconio::input;
use proconio::fastout;
use proconio::marker::{Chars};

#[fastout]
fn main() {
    input! {
        s: Chars,
    }
    let mut ans=0;
    for c in s{
        if c=='+'{
            ans+=1;
        }
        else{
            ans-=1;
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 2104
<?php

// 標準入力を一行ずつ配列に代入します
//$line = fgets(STDIN); // 標準入力からの入力値を変数に代入

while ($line = fgets(STDIN)) {
   $tmp[] = trim($line);
}

// 配列を展開
$i = 0;
foreach ($tmp as $value){
 //echo $value."\n";
 if($i==0){
     $line = $value;
 } else {
     $K = $value;
 }
 $i++;
}

$arr1 = str_split($line);

$i =1;
foreach ($arr1 as $value) {
    // code...
    //echo $value."\n";
    if($value<>1){
        echo $value;
        exit();
    }
    if ($i==$K){
        echo 1;
        exit();
    }
    
    $i++;
}
echo 1;

?>

Measured memory_bytes: 3700
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (1e+18) + 7;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

ll mod_pow(ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%mod;
		a = a * a%mod; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

void solve() {
	int n; cin >> n;
	vector<int> p(n), q(n);
	rep(i, n)cin >> p[i];
	rep(i, n)cin >> q[i];
	vector<int> v(n);
	rep(i, n)v[i] = i + 1;
	int a, b;
	int tmp = 0;
	while (true) {
		if (v == p)a = tmp;
		if (v == q)b = tmp;

		tmp++;
		if (!next_permutation(v.begin(), v.end()))break;
	}
	cout << abs(a - b) << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(17);
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}


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

long long const mod = 998244353;

int N, S;
long long A[3100];
long long dp[3100][3100] = {};

int main() {
    cin >> N >> S;
    for(int i=0; i<N; ++i) cin >> A[i];

    dp[0][0] = 1;
    for(int i=0; i<N; ++i) {
        for(int j=0; j<=S; ++j) {
            dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * 2 % mod) % mod;
            if(j + A[i] <= S) dp[i + 1][j + A[i]] = (dp[i + 1][j + A[i]] + dp[i][j]) % mod;
        }
    }

    cout << dp[N][S] << '\n';
}

Measured memory_bytes: 76320
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	enum Color {
		R, G, B;
	}

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

		int inputCount = Integer.parseInt(sc.nextLine());

		for (int i = 0; i < inputCount; i++) {
			ArrayList<Card> hand = inputHand(sc.nextLine(), sc.nextLine());

			if (VictoryDecision(hand)) {
				System.out.println("1");
			} else {
				System.out.println("0");
			}
		}

		sc.close();
	}

	private static ArrayList<Card> inputHand(String numLine, String colorLine) {
		String[] colorStr = colorLine.split("[\\s]+");
		String[] numStr = numLine.split("[\\s]+");
		ArrayList<Card> hand = new ArrayList<Card>();
		for (int i = 0; i < numStr.length; i++) {
			hand.add(new Card(Integer.parseInt(numStr[i]), Color.valueOf(colorStr[i])));
		}
		return hand;
	}

	static boolean VictoryDecision(ArrayList<Card> hand) {
		ArrayList<Integer> r = new ArrayList<Integer>();
		ArrayList<Integer> g = new ArrayList<Integer>();
		ArrayList<Integer> b = new ArrayList<Integer>();
		for (Card c : hand) {
			switch (c.color) {
			case R:
				r.add(c.num);
				break;
			case G:
				g.add(c.num);
				break;
			case B:
				b.add(c.num);
				break;
			}
		}

		if (3 == PairSearch(r) + PairSearch(g) + PairSearch(b)) {
			return true;
		}

		return false;

	}

	static int PairSearch(ArrayList<Integer> list) {
		int pairCount = 0;
		while (list.size() >= 3) {
			Collections.sort(list);

			int num = list.get(0);
			int secondIndex = Arrays.binarySearch(list.toArray(), num + 1);
			int thirdIndex = Arrays.binarySearch(list.toArray(), num + 2);
			if (secondIndex > 0 && thirdIndex > 0) {
				pairCount++;
				list.remove(thirdIndex);
				list.remove(secondIndex);
				list.remove(0);
			} else if (num == list.get(1) && num == list.get(2)) {
				pairCount++;
				list.remove(2);
				list.remove(1);
				list.remove(0);
			} else {
				list.remove(0);
			}
		}
		return pairCount;

	}

	static class Card {
		int num;
		Color color;

		Card(int num, Color color) {
			this.num = num;
			this.color = color;
		}
	}
}



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

using namespace std;

int main()
{
    int N, tmp = 0, answer = 0;

    cin >> N;
    vector<int> d(N);
    for (int count = 0; count < d.size(); count++)
    {
        cin >> d.at(count);
    }

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

    for (int count = 0; count < d.size(); count++)
    {
        if (d.at(count) != tmp)
        {
            answer++;
            tmp = d.at(count);
        }
    }

    cout << answer << endl;
}

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

int main(){
  long long a,b,c;
  cin >> a >> b >> c;
  if(c<=(a+b))
    cout <<"No"<< endl;
  else{
    if((c-a-b)*(c-a-b)-4*a*b>0)
      cout << "Yes"<< endl;
    else
      cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define int long long
#define float long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'
#define pii pair<int, int>
#define tii tuple<int, int, int>
#define min3(a,b,c) min(a, min(b, c))
#define max3(a,b,c) max(a, max(b, c))
#define all(x) x.begin(), x.end()
#define fill(a,b) memset(a, b, sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
vector<int> v;
map<int,int> pos;

signed main()
{
 
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int n,x,m; cin>>n>>x>>m;
    while(pos[x]==0){
    	v.pb(x);
    	pos[x]=sz(v);
    	x=(x*x)%m;
    }
	if(sz(v)>=n){
    	int ans=0;
    	for(int i=0;i<n;i++) ans+=v[i];
    	cout<<ans<<endl;
    	return 0;
    }
    int a=0,b=0;
    for(int i=0;i<sz(v);i++){
    	if(i<pos[x]-1) a+=v[i];
    	else b+=v[i];
    }
    int ans=a+b*((n-pos[x]+1)/(sz(v)-pos[x]+1));
    for(int i=0;i<((n-pos[x]+1)%(sz(v)-pos[x]+1));i++) ans+=v[i+pos[x]-1];
    cout<<ans<<endl;

}

Measured memory_bytes: 6688
#include<bits/stdc++.h>
#define INF 2100000000
using namespace std;
int main(void)
{
	int i,j,k,a,b,c,mini;
	char color[8][15]={"black","blue","lime","aqua",
				  "red","fuchsia","yellow","white"};
	int suu[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
		red[8]={0,0,0,0,255,255,255,255},
		lime[8]={0,0,255,255,0,0,255,255},
		blue[8]={0,255,0,255,0,255,0,255};
	char sin[17]={"0123456789abcdef"};
	char pu[8];
	while(1) {
		cin>>pu;
		if(pu[0]=='0') break;
		a=b=c=0;
		for(i=1;i<8;i++) {
			for(j=0;j<16;j++) {
				if(pu[i]==sin[j]) {
					if(i<=2) {
						if(i%2==1)a+=suu[j]*16;
						else a+=suu[j];
					}
					else if(i<=4) {
						if(i%2==1) b+=suu[j]*16;
						else b+=suu[j];
					}
					else {
						if(i%2==1) c+=suu[j]*16;
						else c+=suu[j];
					}
					break;
				}
			}
		}
		mini=INF;
		int d,x=0;
		for(i=0;i<8;i++) {
			d=((a-red[i])*(a-red[i]))+
				((b-lime[i])*(b-lime[i]))+
				((c-blue[i])*(c-blue[i]));
			if(mini>d) {
				mini=d;
				x=i;
			}
		}
		cout<<color[x]<<endl;
	}
}

Measured memory_bytes: 3040
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    // 0, 1をBooleanでもつ
    val fList: List<List<Boolean>> = (0 until n).map {
        readLine()?.split(" ")?.map { it.toInt() }?.map { it == 1 }!!
    }
    val pList: List<List<Long>> = (0 until n).map {
        readLine()?.split(" ")?.map { it.toLong() }!!
    }

    // 10個の時間から任意の1つ以上の時間帯を選ぶ組み合わせは1023通りなので
    // 全部試して最大金額を得る

    var max = Long.MIN_VALUE

    for (i in 1..1023) {
        // お姉ちゃん店と開店時間帯か被っている各店の数
        val openShopCount = mutableListOf<Int>().apply {
            for (s in 0 until n) add(0)
        }
        var timeZone = 0
        var timeZoneBit = 0b0000000001
        // 時間帯ごとに見ていく
        while (timeZone < 10) {
            // bitが立っている = お姉ちゃん店の開店時間帯
            if (i.and(timeZoneBit) == timeZoneBit) {
                for (s in 0 until n) {
                    // 同時間帯で開店している店舗カウントをincrement
                    if (fList[s][timeZone]) {
                        openShopCount[s]++
                    }
                }
            }
            timeZone++
            timeZoneBit = timeZoneBit.shl(1)
        }
        var price = 0L
        for ((shop, count) in openShopCount.withIndex()) {
            price += pList[shop][count]
        }
        if (price > max) {
            max = price
        }
    }

    println(max)
}

Measured memory_bytes: 41992
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>	
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================
int ketawa(int a) {
	if (a < 10)return a;
	else return a % 10 + ketawa(a / 10);
}

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;

int main()
{
	int n, k; cin >> n >> k;
	ll ans = k; rep(i, n - 1)ans *= k - 1;
	cout << ans << endl;

	return 0;
}


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

using namespace std;


template<typename T>
class UF {
public:
	UF() {
		size = 0;
	}

	//値を挿入する
	void push( T a ) {
		M[a] = size;
		V.push_back( size );
		rank.push_back( 0 );
		C.push_back( 1 );
		size++;
	}

	//同じグループにする
	void unite( T a, T b ) {
		long long int x = find( M[a] );
		long long int y = find( M[b] );
		if( x == y )return;
		if( rank[x] < rank[y] ) {
			V[x] = y;
			C[y] += C[x];
		} else {
			V[y] = x;
			C[x] += C[y];
			if( rank[x] == rank[y] )rank[x]++;
		}
	}

	void merge( T a, T b ) {
		unite( a, b );
	}

	//同じグループにいるかどうか判定する
	bool same( T a, T b ) {
		return find( M[a] ) == find( M[b] );
	}

	//今何グループあるか数を返す
	long long int group() {
		set<long long int>S;
		for( long long int i = 0; i < V.size(); i++ ) {
			S.insert( find( V[i] ) );
		}
		return S.size();
	}

	//グループに属している数を返す
	long long int count( T a ) {
		return C[find( M[a] )];
	}

	//今属しているグループのIDを返す
	long long int groupID( T a ) {
		return find( M[a] );
	}

	//同じグループのメンバーを返す
	vector<T>friendList( T a ) {
		long long int inputID = find( M[a] );
		vector<T>ret;
		for( auto now : M ) {
			if( find( now.second ) == inputID ) {
				ret.emplace_back( now.first );
			}
		}
		return ret;
	}

private:
	vector<long long int>C, V, rank;
	map < T, long long int>M;
	long long int size;

	//祖先までたどる
	long long int find( long long int x ) {
		if( V[x] == x )return x;
		else return V[x] = find( V[x] );
	}
};



int main() {
	long long int N;
	cin >> N;
	UF<long long int>uf;
	vector<pair<long long int, long long int>>D( N ), E( N );
	for( size_t i = 0; i < N; i++ ) {
		cin >> D[i].first;
		D[i].second = i;
		cin >> E[i].first;
		E[i].second = i;
		uf.push( i );
	}
	sort( D.begin(), D.end() );
	sort( E.begin(), E.end() );

	priority_queue<pair<long long int, pair<long long int, long long int>>, vector<pair<long long int, pair<long long int, long long int>>>, greater<pair<long long int, pair<long long int, long long int>>>>que;
	for( size_t i = 0; i < N - 1; i++ ) {
		que.push( make_pair( D[i + 1].first - D[i].first, make_pair( D[i + 1].second, D[i].second ) ) );
		que.push( make_pair( E[i + 1].first - E[i].first, make_pair( E[i + 1].second, E[i].second ) ) );
	}
	long long int ans = 0;
	while( que.size() ) {
		auto now = que.top(); que.pop();
		if( !uf.same( now.second.first, now.second.second ) ) {
			uf.merge( now.second.first, now.second.second );
			ans += now.first;
		}
	}
	cout << ans << endl;
}

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

using namespace std;

typedef long long int lli;

int main() {
    int s;

    cin >> s;

    int a = 0, b = 0;
    a += s%10;
    s /= 10;
    a += 10 * (s%10);
    s /= 10;
    
    b += s%10;
    s /= 10;
    b += 10 * (s%10);
    s /= 10;

    if (1 <= a && a <= 12) {
        if (1 <= b && b <= 12)
        {
            cout << "AMBIGUOUS" << endl;
        }
        else {
            cout << "YYMM" << endl;
        }
    }
    else
    {
        if (1 <= b && b <= 12)
        {
            cout << "MMYY" << endl;
        }
        else {
            cout << "NA" << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string.h>
using namespace std;
 
int main() {
	string str;
	getline(cin,str);
	int arr[26];
	memset(arr,0,sizeof arr);
	for(int i=0;i<str.length();i++){
		arr[str[i]-'a']++;
	}
	bool found = false;
	for(int i=0;i<26;i++){
		if(arr[i]==0){
			found = true;
			char c = i+'a';
			cout<<c<<endl;
break;
		}
	}
	if(found==false){
		cout<<"None"<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll long long
#define cat(p) cout<<p<<endl
#define catA(p,n) for(int i=0;i<n;i++)cout<<p[i]<<((i==n-1)?"\n":" ")
ll k,a,b;
ll ans=0;
int main(){
  cin>>k>>a>>b;
  ans=1;
  ll br=a-1;//cnt for waru
  k-=br;
  ans+=br;
  //cout<<ans<<" "<<k<<endl;
  if(2<=k){
    ll kai=k/2;
    if(2<=(b-a)){
      ans+=kai*(b-a);
      k-=kai*2;
    }
  }

  //cout <<k<<" "<<ans<<endl;
  if(k>0){
    ans+=k;
    k=0;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
    int a,b;
    cin>>a>>b;
    int c=a+b;
    if(a%3==0||b%3==0||c%3==0) cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

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

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int x; cin >> x;
  cout << (x ? 0 : 1) << endl;

  return 0;
}








Measured memory_bytes: 3628
using System;
using System.Collections.Generic;

public class Test
{
	public static int goodSequence(int[] arr)
    {
        int count = 0;
        Dictionary<int, int> goodSeq = new Dictionary<int, int>();
        for (int i = 0; i < arr.Length; i++)
        {
            if (goodSeq.ContainsKey(arr[i]))
                goodSeq[arr[i]]++;
            else
                goodSeq.Add(arr[i], 1);
        }
        foreach (var ele in goodSeq)
        {
            if (ele.Value > ele.Key)
            	count += ele.Value - ele.Key;
            else if (ele.Value != ele.Key)
            	count += ele.Value;
        }
        return count;
    }
	public static void Main()
	{
		// your code goes here
		int n = Convert.ToInt32(Console.ReadLine());
		string[] inp = Console.ReadLine().Split(' ');
		int[] arr = new int[n];
		for(int q=0; q<n;q++)
		{
			arr[q] = Convert.ToInt32(inp[q]);
		}
		Console.WriteLine(goodSequence(arr));
	}
}

Measured memory_bytes: 41024
#include<stdio.h>

typedef struct
{
  char type[11];
  int num;
}q;

int main()
{
  q q[200000];
  int n;
  int p;
  int r = 0;
  int temp = 0;
  
  scanf("%d %d", &n, &p);
  int f = n-1;
  for(int i = 0 ; i < n; i++)
    {
      scanf("%s%d", q[i].type, &q[i].num);
    }
  while(r <= f)
    {
      if(q[r].num > p)
	{
	  temp += p;
	  q[r].num -=p;
	  q[++f] = q[r];
	}
      else
	{
	  temp += q[r].num;
	  printf("%s %d\n", q[r].type, temp);
	}
      r++;
    }
}



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

#define MOD 1000000007
#define INF 1000000001

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


template <class T>
ostream &operator<<(ostream &o, const vector<T>&obj) {
    o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U>&obj) {
    o << "(" << obj.first << ", " << obj.second << ")"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const queue<T>&obj) {
    queue<T> obj_cp = obj;
    bool first = true;
    o << "{";
    while (!obj_cp.empty()) { o << (!first ? ", " : "") << obj_cp.front(); obj_cp.pop(); first = false; }
    o << "}"; return o;
}

void print() {
    cout << "\n";
}
template<class Head, class... Body>
void print(Head head, Body... body) {
    cout << head << " ";
    print(body...);
}


int main(int argc, char const *argv[]) {
    int N;
    cin >> N;
    vector<vector<int>> p(N, vector<int>(3));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> p[i][j];
        }
    }

    vector<vector<int>> dp(N+1, vector<int>(3, 0));
    for (int i = 1; i <= N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                dp[i][j] = max(dp[i][j], dp[i-1][k] + p[i-1][j]);
            }
        }
    }
    cout << *max_element(dp[N].begin(), dp[N].end()) << endl;

    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<string>
#include <sstream>
using namespace std;

int main(){
  long long i = 0;
  long long X;
  long long N = 100;
  cin >> X;
  
  while(N < X){
    N = N * 1.01;
    i++;
  }
  
  cout << i << endl;
}



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

void MyPrint(string str, int a, int b)
{
	string s = str.substr(a, b - a + 1);
	cout << s << endl;
}

string MyReverse(string str, int a, int b)
{
	string s;
	int l = str.length();
	for (int i = 0; i < a; i++) {
		s += str[i];
	}
	for (int i = b; i >= a; i--) {
		s += str[i];
	}
	for (int i = b + 1; i < l; i++) {
		s += str[i];
	}
	return s;
}

string MyReplace(string str, int a, int b, string p)
{
	string s;
	s = str.replace(a, b - a + 1, p);
	return s;
}

int main()
{
	string s;
	cin >> s;
	int q = 0;
	cin >> q;

	for (int i = 0; i < q; i++) {
		string o;
		cin >> o;
		if (o == "print") {
			int a, b;
			cin >> a >> b;
			MyPrint(s, a, b);
		}
		else if (o == "reverse")
		{
			int a, b;
			cin >> a >> b;
			s = MyReverse(s, a, b);
		}
		else if (o == "replace")
		{
			int a, b;
			string p;
			cin >> a >> b >> p;
			s = MyReplace(s, a, b, p);
		}
	}

	return 0;
}


Measured memory_bytes: 3236
//============================================================================
// Name        : TopCoderCompetition.cpp
// Author      : taguchi
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <bitset>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <numeric>
#include <list>
#include <sstream>
using namespace std;
//#define P pair<int,int>
//#define max 999999
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(ull i = 0;i<n;i++)
#define pb(n) push_back(n)
#define clear(n) memset(n,0,sizeof(n))

typedef vector<int> vi;
typedef vector<string> vs;
struct edge{int cost,to;};

vector<string> split(string &in,char delimiter){
	vector<string> re; uint cur = 0,next;
	while((next = in.find_first_of(delimiter,cur)) != string::npos){
		re.pb(string(in,cur,next-cur));
		cur = next + 1;
	}
	re.pb(string(in,cur,in.size()-cur));
	return re;
}
vector<int> split_int(string &in, char delimiter){
	vector<string> str = split(in,delimiter);
	vector<int> re;
	rep(i,str.size()){
		re.pb(strtol(str[i].c_str(),NULL,10));
	}
	return re;
}

class Range{
public:
	int a,b;
	Range(int an,int bn) : a(an),b(bn){}

	bool operator()(int n){
		return a<=n&&n<=b;
	}
	bool isCross(Range x){
		return x(a) || x(b);
	}
	bool contains(Range x){
		return this->a <= x.a && x.b <= this->b;
	}
};


int main(){
	int dx[] = {0,1,0,-1};
	int dy[] = {1,0,-1,0};
	while(1){
		double prob[16][5][5];
		memset(prob,0,sizeof(prob));
		int n;
		cin >> n;
		if(n == 0) break;
		char s,t,b;
		cin >> s >> t >> b;
		int map[5][5];
		memset(map,0,sizeof(map));
		rep(i,5){
			map[i][0] = 1;
			map[0][i] = 1;
			map[i][4] = 1;
			map[4][i] = 1;
		}
		int kb = b - 'A';
		map[kb%3 + 1][kb/3 + 1] = 1;
		int ks = s - 'A';
		prob[n][ks%3 + 1][ks/3 + 1] = 1;
		for(int batt = n;batt>=1;batt--){
			for(int x = 3;x>=1;x--){
				for(int y = 3;y>=1;y--){
					for(int p = 0;p<4;p++){
						int nx = x + dx[p];
						int ny = y + dy[p];
						if(map[nx][ny] == 0){
							prob[batt-1][nx][ny] += prob[batt][x][y] * 0.25;
						}else{
							prob[batt-1][x][y] += prob[batt][x][y] * 0.25;
						}
					}
				}
			}
		}
		int kt = t - 'A';
		cout << prob[0][kt%3 + 1][kt/3+1] << endl;
	}

	return 0;
}

Measured memory_bytes: 0
package main

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

/*-----------Main-----------*/

func main() {
	a := readI()
	b := a % 10
	switch b {
	case 2:
		fallthrough
	case 4:
		fallthrough
	case 5:
		fallthrough
	case 7:
		fallthrough
	case 9:
		fmt.Println("hon")
	case 0:
		fallthrough
	case 1:
		fallthrough
	case 6:
		fallthrough
	case 8:
		fmt.Println("pon")
	case 3:
		fmt.Println("bon")
	}
}

/*-----------Utilities-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func debug() {
	testFile, err := os.Open("./test/sample-3.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error : There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readSs(a int) []string {
	b := make([]string, a)
	for i := 0; i < a; i++ {
		b[i] = readS()
	}
	return b
}

func readI() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readIs(a int) []int {
	b := make([]int, a)
	for i := 0; i < a; i++ {
		b[i] = readI()
	}
	return b
}

func readF() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

func readFs(a int) []float64 {
	b := make([]float64, a)
	for i := 0; i < a; i++ {
		b[i] = readF()
	}
	return b
}

func max(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] > m {
			m = a[i]
		}
	}
	return m
}

func min(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] < m {
			m = a[i]
		}
	}
	return m
}

func sortI(a []int) []int {
	sort.Ints(a)
	return a
}

func reverse(a []int) []int {
	l := len(a)
	r := make([]int, l)
	for i := 0; i < l; i++ {
		r[i] = a[l-i-1]
	}
	return r
}

func countI(a []int, b int) int {
	l := len(a)
	var c int
	for i := 0; i < l; i++ {
		if a[i] == b {
			c++
		}
	}
	return c
}


Measured memory_bytes: 1780
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

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

  cin >> n;

  int now_x = 0, now_y = 0, now_t = 0;
  REP(i, n) {
    int t, x, y;
    cin >> t >> x >> y;

    int d = abs(now_x - x) + abs(now_y - y);
    if(t - now_t >= d && (t - now_t - d) % 2 == 0) {
      now_x = x;
      now_y = y;
      now_t = t;
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pil pair<int,along long>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define pb push_back
#define mk make_pair
#define maxn 100009
#define eps 1e-12
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	ll n,x;
	cin>>n>>x;
	ll base=n;
	ll repeat=n-x;
	ll ans=x;
	if(base%repeat==0)
	{
		ans+=((base/repeat)-1)*2*repeat;
		cout<<ans<<"\n";
		return 0;
	}
	if(base%repeat!=0)
	{
		ans+=(((base/repeat)*2*repeat)-repeat);
		ll temp=base;
		base=repeat;
		repeat=temp%repeat;
	}
	while(base%repeat!=0)
	{
		ans+=((base/repeat)*2*repeat);
		ll temp=base;
		base=repeat;
		repeat=temp%repeat;
	}
	ans+=((base/repeat)*2*repeat);
	ans-=repeat;
	cout<<ans<<"\n";
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int main() {
	string s;
	cin >> s;
	
	int l = -1, r = -1;
	
	REP(i, s.size() - 1) {
		if (s[i] == s[i + 1]) l = i + 1, r = i + 2;
		if (i + 1 < s.size() - 1 && s[i] == s[i + 2]) l = i + 1, r = i + 3;
	}
	
	printf("%d %d\n", l, r);
	
	return 0;
}


Measured memory_bytes: 512
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int M = s.nextInt();
		int[] A = new int[M];
		int[] B = new int[M];
		int tmpa = 0;
		int tmpb = 0;
		Map<Integer, Set<Integer>> map = new HashMap<>(); 
		for(int i = 0; i< M; i++) {
			tmpa = s.nextInt();
			tmpb = s.nextInt();
			map.computeIfAbsent(tmpa, m -> new HashSet<>()).add(tmpb);
			map.computeIfAbsent(tmpb, m -> new HashSet<>()).add(tmpa);
		}
		
		Map<Integer, Integer> result = new HashMap<Integer, Integer>();
		
		Deque<int[]> q = new ArrayDeque<>();
		q.add(new int[] {1, 0}); // 現在地、前の部屋
		
		boolean[] used = new boolean[N + 1];
		used[0] = used[1] = true;
		while(!q.isEmpty()) {
			int[] current = q.poll();
			for(Integer next : map.getOrDefault(current[0], Collections.emptySet())) {
				if(!used[next]) {
					used[next] = true;
					q.add(new int[] {next, current[0]});
					result.put(next, current[0]);
				}
			}
		}
		
		for(boolean b : used) {
			if(!b) {
				System.out.println("No");
			}
		}
		
		System.out.println("Yes");
		for(int i = 2; i < N + 1; i++) {
			System.out.println(result.get(i));
		}
    }
}

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

int main() {

	ll n, k; cin >> n >> k;
	vector<ll> h(n);
	for (ll i = 0; i < n; i++) {
		cin >> h[i];
	}
	sort(h.rbegin(), h.rend());
	ll ans = 0;
	if (k < n) {
		for (ll i = k; i < n; i++) {
			ans += h[i];
		}
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
  ll N;
  ll s[1100];
  cin>>N;
  while(N){
  ll sum=0;
  for(ll i = 0; i < N; ++i){
      cin >> s[i];
  }
  sort(s,s+N);
  for(ll i = 1; i < N-1; ++i){
    sum+=s[i];
  }
  cout<<sum/(N-2)<<endl;
  cin>>N;
  }
}

    
  
  
  





Measured memory_bytes: 3056
N = int(input())
s = [input() for _ in [0]*N]
ni = [0]*N
for i,si in enumerate(s):
    for j,c in enumerate(si[:-1]):
        if c == "A" and si[j+1] == "B":
            ni[i] += 1
cntA,cntB,cntAB = 0,0,0
for si in s:
    if si[0]=="B" and si[-1]=="A":
        cntAB += 1
    elif si[0]=="B":
        cntB += 1
    elif si[-1]=="A":
        cntA += 1
ans = sum(ni) + max(0,cntAB - (cntA==0 and cntB==0)) + min(cntA,cntB)
print(ans)

Measured memory_bytes: 46168
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,1,-1,-1};
const vector<int> dy={1,-1,1,-1};

int main(){
  int n;
  cin>>n;
  vector<in> x(n),y(n);
  rep(i,n){
    cin>>x.at(i);
    cin>>y.at(i);
  }
  vector<vector<in>> f(n,vector<in>(4,0));
  rep(i,n){
    rep(j,4){
      f.at(i).at(j)=(dx.at(j)*x.at(i)+dy.at(j)*y.at(i));
    }
  }
  
  vector<in> f_min(4,INF);
  vector<in> f_max(4,-1*INF);
  
  rep(j,4){
    for(int i=0;i<n;i++){
      f_min.at(j)=min(f.at(i).at(j),f_min.at(j));
      f_max.at(j)=max(f.at(i).at(j),f_max.at(j));
    }
  }
  in ans=0;
  rep(i,4){
    ans=max(ans,f_max.at(i)-f_min.at(i));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 20420
x1, y1, x2, y2 = list(map(int, input().split()))

dx = x2 - x1 
dy = y2 - y1

x3 = x2 - dy
y3 = y2 + dx
x4 = x3 - dx
y4 = y3 - dy

print(x3,y3,x4,y4)

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


int main(){


    int n, k, t, i;

    int s = 0;

    int g = 0;

    vector<int> a(200001);

 
    cin >> n >> k;


    for( i = 0 ; i < n ; i = i + 1 ){

         cin >> t;

         a.at(t) += 1;

         }


    for( i = 0 ; i < a.size() ; i = i + 1 ){

         if( a.at(i) > 0 ) s += 1;

         }


    if( s <= k ){

        cout << 0 << endl;

        return 0;

        }


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


    for( i = 0 ; i < a.size() ; i = i + 1 ){

         if( a.at(i) > 0 ){

             g += a.at(i);

             s -= 1;

             }

         if( s == k ) break;

         }


    cout << g << endl;


    return 0;


    }

Measured memory_bytes: 1152
succDivisor :: Int -> Int -> Int -> Int
succDivisor d x sum = if (mod d x == 0) then (sum + 1) else sum

main :: IO ()
main = do
  input <- getLine
  let [a, b, c] = map read $ words input :: [Int]
  putStrLn $ show $ foldr (succDivisor c) 0 [a..b]

Measured memory_bytes: 4148
#include<iostream>
#include <stdio.h>
using namespace std;
int main(){
	int a,b;
	while(cin>>a>>b){
	int c=a+b;
	if(c>=1000000){
		cout<<7<<endl;}else
	if(c>=100000){
		cout<<6<<endl;}else
	if(c>=10000){
		cout<<5<<endl;}else
	if(c>=1000){
		cout<<4<<endl;}else
	if(c>=100){
		cout<<3<<endl;}else
	if(c>=10){
		cout<<2<<endl;}else{
		cout<<1<<endl;}
	}
	return 0;}


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

using ll = long long;
using ld  = long double;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll)(n) ; i++ )
#define DREP(i,m,n) for(ll i=(ll)(m) ; i > (ll)(n) ; i-- )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define p_b push_back
#define SZ(x) ((ll)(x).size()) //size()がunsignedなのでエラー避けに
#define endk '\n'


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //




// --------- library end - //


int main(){

  ll n, x, t;
  cin >> n >> x >> t;

  ll ans = (n / x) * t;

  n %= x;

  if (n > 0) ans += t;

  cout << ans << endk;


  
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  int a;
  cin >> a;
  cout << a*a*a + a*a + a << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */


/** Problem0263 : Beat Panel **/
int N, C;
vector<int> ptn;
vector<int> push;

int dp[31][1<<16];

int solve(int n, int state)
{
	if (n==N) return 0;
	if (dp[n][state]>=0) return dp[n][state];
	
	int res=0;
	for (int i=0; i<C; i++) {
		res = max(res, solve(n+1, ((state^push[i])&state)|ptn[n+1])+__builtin_popcount(state&push[i]));
	}
	
	return dp[n][state] = res;
}

int main()
{
	while (cin>>N>>C, N) {
		ptn.clear(); push.clear();
		memset(dp, -1, sizeof(dp));
		
		rep(i, N) {
			int tmp=0;
			rep(j, 16) {
				int t; cin>>t;
				tmp<<=1;
				tmp|=t;
			}
			ptn.push_back(tmp);
		}
		
		rep(i, C) {
			int tmp=0;
			rep(j, 16) {
				int t; cin>>t;
				tmp<<=1;
				tmp|=t;
			}
			push.push_back(tmp);
		}
		
		cout << solve(0, ptn[0]) << endl;
	}
}

Measured memory_bytes: 9164
import math

while True:
  e = int(raw_input())
  if e==0: break
  m = 10 ** 4
  for z in xrange(10 ** 2 + 1):
    if e < z ** 3: break
    y = int(math.sqrt(e - z ** 3))
    x = e - z ** 3 - y ** 2
    m = min(m, x+y+z)
  print m

Measured memory_bytes: 6340
#include <iostream>
using ll = long long;
using namespace std;

int main() {
    string a;
    cin >> a;
    for (int i = 0; i < 2; ++i) {
        if (a[i] != a[i+1] || a[i+1] != a[i+2]) continue;
        else cout << "Yes"; return 0;
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
using namespace std;

ll calc(ll x){
    return x * (x-1) / 2;
}


int main() {
    ll n, count = 0;
    
    cin >> n ;
    vector<string> s(n);
    vector<ll> a;
    
    rep(i,n) cin>>s[i];
    
    rep(i, n) Sort(s[i]);
    
    Sort(s);
    
    for(int i = 1; i<n;i++){
        if(s[i] == s[i-1]) count++;
        
        else{
            a.push_back(count + 1);
            count = 0;
        }
    }
    a.push_back(count+1);
    count = 0;
    
    rep(i, a.size()) count+=calc(a[i]);//cout<<a[i]<<endl;
    
    cout<<count<<endl;
    
    return 0;
}


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

using namespace std;
#define int long long
const int inf = 9999999999999999999;
signed main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int ans=-inf;
	ans=max(a*c,a*d);
	ans=max(ans,max(b*c,b*d));
	cout<<ans;
	return 0;
}

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

int n, a[300010], ans = 1e9; char c[300010];
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf(" %c", &c[i]);
		a[i] = a[i-1] + (c[i] == 'W');
	}
	for(int i = 1; i <= n; i++) ans = min(ans, a[i-1] + (n-i) - a[n] + a[i]);
	printf("%d", ans);
}

Measured memory_bytes: 1664