akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
#include <bitset>
#include <unordered_map>
using namespace std;
typedef long long ll;

void print(vector<int> vi) {
    for (int i=0; i<(int)vi.size(); ++i) {
        cout << (i == 0 ? "" : " ") << vi[i];
    }
    cout << endl;
}

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

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

    int ans = 0;
    for (int i=0; i<N; ++i) {
        for (int j=N-1; j>i; --j) {
            if (A[j] < A[j-1]) {
                swap(A[j], A[j-1]);
                ++ ans;
            }
        }
    }
    print(A);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#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 mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


inline double det(const P &a, const P &b) {
	return (conj(a) * b).imag();
}

int main() {
	double x[4], y[4];
	char c;
	for (; cin >> x[0] >> c >> y[0] ; ) {
		rep (i, 3) cin >> c >> x[i + 1] >> c >> y[i + 1];
		double s = 0.0;
		rep(i, 4) x[i] += 200;//, y[i] += 200;
		rep (i, 4) s += det(P(x[i], y[i]), P(x[(i + 1) % 4], y[(i + 1) % 4])) / 2.0;
		s = fabs(s);
		double sub_s = 0;
		rep(j, 4) {
			double ss = 0.0;
			rep(i, 4) if (i != j) {
				int idx = (i + 1) % 4;
				if (idx == j) idx = (i + 2) % 4;
				ss += det(P(x[i], y[i]), P(x[idx], y[idx])) / 2.0;
			}
			ss = fabs(ss);
			sub_s = max(sub_s, ss);
		}
		cout << (s >= sub_s ? "YES" : "NO") << endl;
	}
	return 0;
}

Measured memory_bytes: 0
n = int(input())
lis = [0 for i in range(4)]
mo = ["AC","WA","TLE","RE"]
for ii in range(n):
    i = input()
    if i=="AC":
        lis[0]+=1
    elif i=="WA":
        lis[1]+=1
    elif i=="TLE":
        lis[2]+=1
    elif i == "RE":
        lis[3]+=1

for i in range(4):
    tmp = "{0} x {1}".format(mo[i],lis[i])
    print(tmp)


Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int k,x;
    cin >>k>>x;
    long long int c1=x-k+1,c2=x+k-1;
    for(long long int i=c1;i<=c2;i++)
    {
        if(c1>= -1000000&&c2<= 1000000)cout <<i<<" ";
    }
}


Measured memory_bytes: 256
from math import sqrt, sin, cos, radians

a, b, cc = map(int, input().split())
cc = radians(cc)
sinc = sin(cc)
s = a * b * sinc / 2
c = sqrt(a * a + b * b - 2 * a * b * cos(cc))
h = b * sinc
print(s)
print(a + b + c)
print(h)

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct UnionFind {
    UnionFind(int n) {
        mRank.assign(n, 0);
        mParent.resize(n);
        mCount.resize(n, 1);
        for (int i = 0; i < n; ++i) {
            mParent[i] = i;
        }
    }

    int find(int x) {
        if (x == mParent[x])
            return x;
        return mParent[x] = find(mParent[x]);
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int count(int x) {
        return mCount[find(x)];
    }

    void unit(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;

        if (mRank[x] < mRank[y]) {
            mParent[x] = y;
            mCount[y] += mCount[x];
        }
        else {
            mParent[y] = x;
            mCount[x] += mCount[y];
            if (mRank[x] == mRank[y])
                mRank[x]++;
        }
    }

    vector<int> mRank;
    vector<int> mParent;
    vector<int> mCount;
};

map<pll, ll> M;

int main() {
    ll N, K, L;
    cin >> N >> K >> L;
    UnionFind uf0(N), uf1(N);
    REP(i, K) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        uf0.unit(a, b);
    }
    REP(i, L) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        uf1.unit(a, b);
    }

    REP(i, N) {
        ll p0 = uf0.find(i);
        ll p1 = uf1.find(i);
        M[pll(p0, p1)]++;
    }

    REP(i, N) {
        ll p0 = uf0.find(i);
        ll p1 = uf1.find(i);
        cout << M[pll(p0, p1)] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 16640
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  int k = 0;
  int now = 0;
  while(true) {
    now += n;
    k++;
    if(now % 360 == 0) {
      break;
    }
  }
  cout << k << endl;
  return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

string s;

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

  cin >> s;
  int ans = INF;
  FOR(i, 1, s.size() + 1) {
    if (s[i] != s[i - 1])
      ans = min(ans, max(i, (int)(s.size() - i)));
  }
  
  cout << ans << endl;

  return 0;
}



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

Measured memory_bytes: 3636
#include <iostream>
#include <string.h>
#include <cstdio>

using namespace std;

int main()
{
    int i,p[100005],N,K,Q,A;
    cin>>N>>K>>Q;
    for(i=1;i<=N;i++)
        p[i]=K;
    for(i=1;i<=Q;i++)
    {
        scanf("%d",&A);
        p[A]++;
    }
    for(i=1;i<=N;i++)
    {
        if(p[i]-Q>0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}

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

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

	int d = 0;
	if (a + w < b) d = b - a - w;
	else if (b + w < a) d = a - b - w;

	cout << d << endl;
}

Measured memory_bytes: 384
N = int(input())
S = list(map(int, input().split()))

ans = 0
for c in range(1, N):
    a = 0
    if (N-1) % c:
        for i in range(1, (N-1)//c):
            a += S[i*c] + S[N-1-i*c]
            ans = max(ans, a)
    else:
        se = set(list(range(N)))
        for i in range(1, (N-1)//c):
            if i*c not in se or N-1-i*c not in se or i*c == N-1-i*c:
                break
            se.remove(i*c)
            se.remove(N-1-i*c)
            a += S[i*c] + S[N-1-i*c]
            ans = max(ans, a)
print(ans)

Measured memory_bytes: 137420
#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdio.h>
using namespace std;
int main(){
	int k;
	cin>>k;
	int sum=0;
	for(int i=1;i<=k;i++){
		for(int j=1;j<=k;j++){
			for(int r=1;r<=k;r++){
				int a=__gcd(i,j);
				sum=sum+__gcd(a,r);
			}
		}
	}
	cout<<sum<<endl;
	return 0;
} 

Measured memory_bytes: 3632
#include <stdio.h>

int main(){
    int ans[100];
    int n, m, i, j, tmp, max, rest;

    while(1){
        scanf("%d%d", &n, &m);

        if(n == 0 && m == 0){
            break;
        }

        for(i=0;i<m;i++){
            ans[i] = 0;
        }

        max = 0;
        for(i=0;i<n;i++){
            for(j=0;j<m;j++){
                scanf("%d", &tmp);
                ans[j] += tmp;
                if(max < ans[j]){
                    max = ans[j];
                }
            }
        }

        rest = m;
        for(i=max;i>=0;i--){
            for(j=0;j<m;j++){
                if(ans[j] == i){
                    rest--;
                    if(rest == 0){
                        printf("%d", j+1);
                    } else{
                        printf("%d ", j+1);
                    }
                }
            }
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 604
fun main(args:Array<String>) {
  val n = readLine()!!.toInt()
  val k = readLine()!!.toInt()
  val xs = readLine()!!.split(" ").map(String::toInt)
  xs.map { listOf( Math.abs(k - it), it ).min()!!*2 }.sum().run(::println)
}

Measured memory_bytes: 37744
//import java.io.*

fun main() {
    val d = readInt()
    val c = readInts()
    val s = mutableListOf<List<Int>>()
    repeat(d) {
        s.add(readInts())
    }

    val last = MutableList(c.size) { 0 }

    fun calcDissatisfaction(currDay: Int): Int {
        return c.mapIndexed { index, num -> num * (currDay - last[index]) }.sum()
    }

    val contests = c.mapIndexed { index, cost -> Contest(index + 1, s[0][index], cost) }

    fun updateContests(day: Int) {
        contests.forEachIndexed { index, contest -> contest.update(day + 1, s[day - 1][index], last[index]) }
    }

    var satisfaction = 0
    var dissatisfaction: Int
    val t = mutableListOf<Int>()
    repeat(d) { day ->
        updateContests(day + 1)
        dissatisfaction = contests.map { it.dissatisfaction }.sum()
        val contestToHold = contests.maxBy { it.contribution(dissatisfaction) }!!
        last[contestToHold.id - 1] = day + 1
//        println("Dissatisfaction on day $day : ${calcDissatisfaction(day + 1)}")
        satisfaction += (s[day][contestToHold.id - 1] - calcDissatisfaction(day + 1))
        t.add(contestToHold.id)
    }

//    println("Satisfaction: $satisfaction")
//    println("Score: ${1000_000 + satisfaction}")

//    writeToFile("output.txt", t.joinToString("\n"))

    // For submission
    println(t.joinToString("\n"))
}

data class Contest(val id: Int, var satisfaction: Int, val cost: Int) {
    var dissatisfaction = cost

    fun update(nextDay: Int, newSatisfaction: Int, lastDayHeld: Int) {
        satisfaction = newSatisfaction

        dissatisfaction = cost * (nextDay - lastDayHeld)
    }

    fun contribution(totalDissatisfaction: Int): Int {
        return satisfaction - totalDissatisfaction + dissatisfaction
    }
}

//// Write to file
//fun writeToFile(filename: String, content: String) {
//    val outputWriter = OutputStreamWriter(FileOutputStream(File(filename)))
//    outputWriter.append(content)
//    outputWriter.close()
//}

//// Read from file
//private val inputReader = InputStreamReader(FileInputStream(File("input.txt")))
//private val lines = inputReader.readLines()
//private var currLine = -1
//private fun readLn(): String {
//    currLine++
//    return lines[currLine]
//}


// Input Reader
private fun readLn() = readLine()!!

private fun readStrings() = readLn().trim().split(" ")
private fun readInt() = readLn().toInt()
private fun readInts() = readStrings().map { it.toInt() }


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

bool A[200],B[200];
int main(){
	int n;scanf("%d",&n);
	int cnt=0;
	int x;scanf("%d",&x);
	rep(i,x){
		int a;scanf("%d",&a);a--;A[a]=true;
	}
	int y;scanf("%d",&y);
	rep(i,y){
		int b;scanf("%d",&b);b--;B[b]=true;
	}
	int z;scanf("%d",&z);
	rep(i,z){
		int c;scanf("%d",&c);c--;
		if(!A[c]||B[c])cnt++;
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 3224
// inputに入力データ全体が入る
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    tmp0 = input[0].split(" ");
    P = Number(tmp0[0])
    Q = Number(tmp0[1])
    R = Number(tmp0[2])
    
    var ans = Math.min(P+Q, P+R, Q+R)
    console.log(ans)
  }
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//   Main("3 2 3");

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N;
    cin >> N;
    ll t = N % 10;
    if (t == 3) {
        cout << "bon" << '\n';
    }else if (t == 0 || t == 1 || t == 6 || t == 8) {
        cout << "pon" << '\n';
    }else {
        cout << "hon" << '\n';
    }

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;



void solve(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    Vl a(n);
    rep(i, 0, n) cin >> a[i];

    ll ans = 0;
    rep(i, 0, n){
        if(a[a[i]-1] == i+1) ans++;
    }

    ans /= 2;
    cout << ans << "\n";
}


int main() {
    solve();
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
//const int64_t MOD = 1000000007;
//const int64_t INF = 998244353;
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; }
using namespace std;
typedef pair<int64_t, int64_t> P;

int main(){
    int N;
    cin >> N;
    vector<vector<int>> c(11, vector<int>(11));
    rep(i, 1, N + 1){
        string S = to_string(i);
        int start = S.at(0) - 48;
        int end = S.at(S.size() - 1) - 48;
        //cout << start << " " << end << endl;
        c.at(start).at(end)++;
    }
    
    int64_t ans = 0;
    rep(i, 1, 10){
        rep(j, 1, 10){
            ans += c.at(i).at(j) * c.at(j).at(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

vector<int>E[202020];
int dist[202020];
void dfs(int now,int p) {
	fore(x, E[now]) {
		if (x != p) {
			dist[x] = dist[now] + 1;
			dfs(x,now);
		}
	}
}

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

	int N;
	cin >> N;
	for (int i = 0; i < N-1; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		E[a].pb(b);
		E[b].pb(a);
	}

	for (int i = 0; i < N; i++)dist[i] = 1010101;
	dist[0] = 0;
	dfs(0,-1);

	int u = 0;
	int r1 = 0;
	for (int i = 0; i < N; i++) {
		if (dist[i] > r1) {
			u = i;
			r1 = dist[i];
		}
	}

	for (int i = 0; i < N; i++)dist[i] = 1010101;
	dist[u] = 0;
	dfs(u, -1);
	int r2 = 0;
	int v = 0;
	for (int i = 0; i < N; i++) {
		if (dist[i] > r2) {
			v = i;
			r2 = dist[i];
		}
	}

	for (int i = 0; i < N; i++)dist[i] = 1010101;
	dist[u] = 0;
	dfs(u, -1);
	int r = dist[v]+1;

	if (r % 3 == 0 || r % 3 == 1)puts("First");
	else puts("Second");


	
	return 0;
}

Measured memory_bytes: 21376
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
	T f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 200003, M = N << 1;

LL k, a, b;

int main()
{
	//File("");
	k = gi <LL> (), a = gi <LL> (), b = gi <LL> ();
	if (a >= b) cout << k + 1 << endl;
	else
	{
		if (k <= a) {cout << k + 1 << endl; return 0;}
		LL sum = k + 1;
		k -= a + 1;
		LL ans = b;
		int now = k / 2, d = k % 2;
		ans += now * (b - a);
		if (d) ++ans;
		cout << max(sum, ans) << endl;
	}
	return 0;
}


Measured memory_bytes: 3528
#include <bits/stdc++.h>		//线段树维护区间和
#define ll long long
#define inf 0x3f3f3f3f 
using namespace std;
const int maxn = 1e5+10;

char sw[200005];
int main()
{
	int n;
	cin>>n;
	scanf("%s",sw+1);
	int pp=0,ans=0;
	for(int i=1;i<=n;i++){
		if(sw[i]=='R') pp++;
	}
	for(int i = 1;i <= pp; i++){
		if(sw[i]=='W') ans++;
	}
	cout<<ans<<endl;
 	return 0;
}

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

int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll dist = b-a;
    if(dist%2==0){
        cout << dist/2 << endl;
        return 0;
    }else{
        if((a-1)<=(n-b)){
            cout << a+ (b-a-1)/2 << endl;
            return 0;
        }else{
            cout << (n-b+1)+ (b-a-1)/2 << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc= new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a>b){
            System.out.println("a > b");
        }
        else if(a<b){
            System.out.println("a < b");
        }
        else{
            System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26124
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    vector<ll> A(N);
    ll min_hp = 1e18;
    ll min_hp_index;
    for(size_t i=0;i<N; i++)
    {
        cin >> A[i];
        min_hp = min(min_hp, A[i]);
        if(min_hp == A[i]) min_hp_index = i;
    }
    bool attack = true;
    while(attack)
    {
        ll next_min_hp = 1e18;
        ll next_min_hp_index;
        attack = false;
        for(size_t i=0;i<N; i++)
        {
            if(i == min_hp_index) continue;
            ll remain_hp = A[i] % min_hp;
            if(A[i] / min_hp > 0 && remain_hp >= 0)
            {
                A[i] = remain_hp;
                attack = true;
                if(remain_hp > 0)
                {
                    next_min_hp = min(min_hp, remain_hp);
                    if(A[i] == next_min_hp) next_min_hp_index = i;
                }
            }
        }
        min_hp = min(min_hp, next_min_hp);
        if(min_hp == next_min_hp) min_hp_index = next_min_hp_index;
    }
    cout << min_hp << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long x,k,d; cin >> x >> k >> d;
  x = abs(x);
  //cout << x << endl;
  long long rem = abs(x / d);
  long long zahyou = x % d;
  if(rem >= k){
    cout << min(abs(x - k * d),abs(x + k * d));
    return 0;
  }
  else{
  if((k-rem) % 2 == 0)
    cout << zahyou;
  else
    cout << min(abs(zahyou -d),abs(zahyou+d));
  }
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
int main(){
    string str_s;
    string str_t;
    cin >> str_s;
    cin >> str_t;
    sort(str_s.begin(),str_s.end());
    sort(str_t.begin(),str_t.end());
    reverse(str_t.begin(),str_t.end());
    if(str_s == min(str_s,str_t) && str_t != min(str_s,str_t)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
 
class Main
{
	static class Pair implements Comparable
	{
		int first;
		double second;
		
		public Pair(int f, double s)
		{
			first = f;
			second = s;
		}
		
		public String toString()
		{
			return first + " " + second;
		}
		
		public int compareTo(Object o)
		{
			Pair p2 = (Pair)o;
			if(this.first < p2.first)
				return -1;
			if(this.first > p2.first)
				return 1;
			if(this.second < p2.second)
				return -1;
			if(this.second > p2.second)
				return 1;
			return 0;
		}
	}
	
	static int log2(double a)
	{
		return (int)(Math.log(a) / Math.log(2));
	}
	
	static long gcd(long a, long b)
	{
		long r;
		while((r = a % b) > 0)
		{
			a = b;
			b = r;
		}
		return b;
	}
	
	public static void main(String[] args) throws IOException
	{
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		boolean ans = false;
		for(int i = 0; i <= n && !ans; i ++)
		{
			for(int j = 0; j <= m && !ans; j ++)
			{
				if((m - j) * i + (n - i) * j == k)
				{
					ans = true;
				}
			}
		}
		sop(ans ? "Yes" : "No");
	}
    
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
	
    static FastReader in = new FastReader();
  
    public static void sop(Object o)
    {
    	System.out.print(o);
    }
}

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

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

    sort(A.begin(), A.end());
    long long ans_center_min = 0, ans_center_max = 0;
    int left, right, left_p, right_p;

    left = A.front(), right = A.front(), left_p = 1, right_p = N - 1;
    while (true) {
        ans_center_min += abs(right - A[right_p]);
        right = A[right_p--];
        if (left_p > right_p) break;

        ans_center_min += abs(left - A[right_p]);
        left = A[right_p--];
        if (left_p > right_p) break;

        ans_center_min += abs(right - A[left_p]);
        right = A[left_p++];
        if (left_p > right_p) break;

        ans_center_min += abs(left - A[left_p]);
        left = A[left_p++];
        if (left_p > right_p) break;
    }

    left = A.back(), right = A.back(), left_p = 0, right_p = N - 2;
    while (true) {
        ans_center_max += abs(left - A[left_p]);
        left = A[left_p++];
        if (left_p > right_p) break;

        ans_center_max += abs(right - A[left_p]);
        right = A[left_p++];
        if (left_p > right_p) break;

        ans_center_max += abs(left - A[right_p]);
        left = A[right_p--];
        if (left_p > right_p) break;

        ans_center_max += abs(right - A[right_p]);
        right = A[right_p--];
        if (left_p > right_p) break;
    }

    cout << max(ans_center_min, ans_center_max) << endl;
}

Measured memory_bytes: 768
//nani?
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1);
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define f(i,a,b) for( int i = a; i < b ; i++ )
#define sor(a) sort( a.begin(), a.end() )
#define rsor(a) sort( a.rbegin(), a.rend() )
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
//#define inf 1LL<<62
typedef long long ll;
typedef double ld;
using namespace std;
using namespace __gnu_pbds;
const int inf=1e7;
const ll MOD=1e9+7;
const ll mod=998244353;
// ac cmtr;
const int MAX_N = 1e5+5;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

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


ll a[MAX_N];

int main(){
    fastio;
    ll n;
    cin>>n;
    ll sum=0;
    f(i,1,n+1){
        if(i%3!=0 && i%5!=0) sum+=i;
    }
    cout<<sum<<endl;
    
} 

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

int main() {
  long long N, M;
  cin >> N >> M;
  if (N == 1 && M == 1)
    cout << 1 << endl;
  else if (N == 1)
    cout << M - 2 << endl;
  else if (M == 1)
    cout << N - 2 << endl;
  else
    cout << (N - 2) * (M - 2) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/

int main()
{
ll a,b,i;
cin>>a>>b;
//cout<<max(a*b,max(a+b,a-b))<<endl;
for(i=max((ll)(-1000000),b-a+1);i<=b;i++)
    cout<<i<<" ";
for(i=b+1;i<=min((ll)1000000,b+a-1);i++)
    cout<<i<<" ";
cout<<endl;
}


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

int main(){
    int h,w;
    cin >> h >> w;
    while(!(h == 0 && w == 0)){
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if((i == 0 || i == h - 1) || (j == 0 || j == w - 1)){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl;
       }
       cin >> h >> w;
       cout << endl;
   }
   return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>

int tenthousand(int price);
int thousand(int price);
int hundred(int price);
int ten(int price);

int main(void)
{
  int n,k,i,j,price,tenth,th,hu,te,on,judge = 0;
  int d[10];

  scanf("%d %d",&n,&k);
  
  for(i = 0;i < k;i++)
    scanf("%d",&d[i]);
  
  //  printf("n = %d,k = %d\n",n,k);
  //for(i = 0;i < k;i++)
  // printf("dislike:%d\n",d[i]);
  
  for(price = n;;price++)
    {
      tenth = tenthousand(price);
      th = thousand(price - tenth * 10000);
      hu = hundred(price - tenth*10000 - th * 1000);
      te = ten(price - tenth * 10000 - th * 1000 - hu * 100);
      on = price - tenth *10000 - th *1000 - hu * 100 - te * 10;

      //      printf("%d %d %d %d %d\n",tenth,th,hu,te,on);

      //printf("start      :judge = %d\n",judge);

      if(tenth != 0)
	for(j = 0;j < k;j++)
	  if(d[j] == tenth)
	    {
	      judge = 1;
	      break;
	    }

      //printf("tenthousand:judge = %d\n",judge);
      
      if( (judge == 0) && (tenth + th != 0) )
	for(j = 0;j < k;j++)
	  if(d[j] == th)
	    {
	      judge = 1;
	      break;
	    }
      
      //printf("thousand   :judge = %d\n",judge);
      
      if( (judge == 0) && (tenth + th + hu != 0) )
	for(j = 0;j < k;j++)
	  if(d[j] == hu)
	    {
	      judge = 1;
	      break;
	    }

      //      printf("hundred    :judge = %d\n",judge);
      
      if( (judge == 0) && (tenth + th + hu + te != 0) )
	for(j = 0;j < k;j++)
	  if(d[j] == te)
	    {
	      judge = 1;
	      break;
	    }

      //   printf("ten        :judge = %d\n",judge);
      
      if(judge == 0)
	for(j = 0;j < k;j++)
	  if(d[j] == on)
	    {
	      judge = 1;
	      break;
	    }

      // printf("one        :judge = %d\n",judge);
      
      if(judge == 0)
	{
	  printf("%d\n",price);
	  break;
	}
      
      else if(judge == 1)
	judge = 0;	    
    }
  
  return 0;  
}

int tenthousand(int price)
{
  int i;

  for(i = 0;;i++)
    if(price - i * 10000 < 0)
      break;

  return i - 1;
} 

int thousand(int price)
{
  int i;

  for(i = 0;;i++)
    if(price - i * 1000 < 0)
      break;

  return i - 1;
}

int hundred(int price)
{
  int i;

  for(i = 0;;i++)
    if(price - i * 100 < 0)
      break;

  return i - 1;
}

int ten(int price)
{
  int i;

  for(i = 0;;i++)
    if(price - i * 10 < 0)
      break;

  return i - 1;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e15+4;
const int Nmax=2e5+1;
const int Nd=61;
ll dfs[3003][3003][4];
ll  v[3003][3003];


int main(){
  string x;// s=(, t=)に該当
  cin>>x;
  int n;
  n=x.size();
  int ph=0,now=0;//

  rep(i,n){
    //入れ子の何層目に相当するかを計算
    //s-> ph+=1;
    // t かつph>0 ->ph-=1;
    // t かつph<=0 -> now+=1;

    if(x[i]=='S'){
      ph++;
    }else{
      if(ph>0){
        ph--;
      }else{
        now++;
      }
    }
  }
  now+=ph;

  cout<<now<<endl;
}


Measured memory_bytes: 3764
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		cout<<'x';
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+10;
int n;
int a[maxn],b[maxn];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n+1;i++)scanf("%d",&a[i]);
    for(int j=1;j<=n;j++)scanf("%d",&b[j]);
    ll ans=0;
    for(int i=n;i>=1;i--){
       // cout<<ans<<endl;
        if(b[i]>=a[i+1]){
            b[i]-=a[i+1];ans+=a[i+1];a[i+1]=0;
        }
        else{
            ans+=b[i];a[i+1]-=b[i];b[i]=0;continue;
        }
        if(b[i]>=a[i]){
            b[i]-=a[i];ans+=a[i];a[i]=0;
        }
        else{
           ans+=b[i]; a[i]-=b[i];b[i]=0;continue;
        }
    }
    printf("%lld\n",ans);
}


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

using namespace std;

inline void Boost() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
typedef long long int ll;
typedef long double ld;

int v[40];
char semn[40];

bool flag = false;
void Back(int lvl, int sum) {
	if(lvl == 4) {
		if(sum == 7) {
			flag = true;
		}
	} else {
		if(flag == true) return;
		semn[lvl] = '+';
		Back(lvl + 1, sum + v[lvl]);
		if(flag == true) return;
		semn[lvl] = '-';
		Back(lvl + 1, sum - v[lvl]);
	}
}

int main() {
	Boost();

	string s;
	cin >> s;

	for(int i = 0; i < 4; ++i) {
		v[i] = (s[i] - '0');
	}	

	Back(0, 0);

	for(int i = 0; i < 4; ++i) {
		cout << v[i];
		if(i + 1 < 4) cout << semn[i + 1];
	}

	cout << "=7\n";
	return 0;
}

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

int N, x;   //人数N, お菓子の数x

int main() {
    cin >> N >> x;
    
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    
    int satisfy = 0;
    for (int i = 0; i < N; i++) {
        int y = a[i];
        if (y <= x) {    //お菓子が足りるなら配る
            x -= y;
            satisfy++;
        } else {
            cout << satisfy << endl;
            return 0;
        }
        
        if (i == N - 1 && x > 0) {  //最後まで配って余っていれば満足する人-1
            satisfy--;
        }
    }
    cout << satisfy << endl;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }




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

    int ans = 0;
    int tmp = 1;

    while(tmp < b) {
        tmp += a-1;
        ans++;
    }

    cout << ans << endl;

    return 0;
}


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

int main(void) {
  int n;
  cin >> n;
  int a4 = 0;
  int a2 = 0;
  int a1 = 0;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a % 4 == 0) a4++;
    else if (a % 2 == 0) a2++;
    else a1++;
  }

  // 1の数が4の数より2以上多いとダメ
  if (a1 > a4 + 1) {
    cout << "No" << endl;
    return 0;
  }

  // 1の数が4の数より一つだけ多いとき、2が一つでもあるとダメ
  if (a1 == a4 + 1 && a2 > 0) {
    cout << "No" << endl;
    return 0;
  }

  // あとはOKじゃない？
  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 3624
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
def count(n):
    t = {}
    while n != 1:
        for p in P:
            while n % p == 0:
                t[p] = t.setdefault(p, 0) + 1
                n //= p
    return t


def p_count(N):
    T = {}
    for n in range(1, N + 1):
        if n in P:
            T[n] = T.setdefault(n, 0) + 1
            continue
        
        t = count(n)
        for k, v in t.items():
            T[k] = T.setdefault(k, 0) + v
    return T


def main():
    N = int(input())
    T = p_count(N)
    L = sorted([t for t in T.keys() if T[t] >= 2])
    res = 0
    q = set()
    for i1, t1 in enumerate(L):
        for i2, t2 in enumerate(L[i1 + 1:]):
            for i3, t3 in enumerate(L[i1 + i2 + 2:]):
                if T[t2] >= 4 and T[t3] >= 4:
                    q.add((t1 ** 2) * (t2 ** 4) * (t3 ** 4))
                    res += 1
                if T[t1] >= 4 and T[t3] >= 4:
                    q.add(t1 ** 4 * t2 ** 2 * t3 ** 4)
                    res += 1
                if T[t1] >= 4 and T[t2] >= 4:
                    q.add(t1 ** 4 * t2 ** 4 * t3 ** 2)
                    res += 1

    for p, c1 in T.items():
        for q, c2 in T.items():
            if p == q:
                continue

            if c1 >= 2 and c2 >= 24:
                res += 1

            if c1 >= 4 and c2 >= 14:
                res += 1

    res += len([t for t in T.keys() if T[t] >= 74])

    print(res)


if __name__ == "__main__":
    main()


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

int n, m, k_;
vector<pair<int, int>> s, t;
string p1, p2;

void solve(int x, int p) {
  int k = k_ - 1;
  if (x != 3) {
    if (x) s.emplace_back(x, p);
    return;
  }
  ++p;
  t.clear();
  while (!s.empty()) {
    int y = s.back().first, q = s.back().second;
    if (q > p) {
      if (x != 3) {
        t.emplace_back(x, p);
        k = -1;
        break;
      } else if (k <= 0) {
        t.emplace_back(3, p);
        k = -1;
        break;
      } else if (q - p > k) {
        t.emplace_back(3, p + k);
        k = -1;
        break;
      } else {
        k -= q - p;
        p = q;
      }
    }
    s.pop_back();
    if (y == 2) {
      if (x == 3) {
        t.emplace_back(1, p);
        x = 2;
      } else if (x == 2) {
        x = 2;
      } else if (x == 1) {
        x = 3;
        --k;
        if (k < 0) {
          t.emplace_back(3, p);
          break;
        }
      }
    } else if (y == 1) {
      if (x == 3) {
        t.emplace_back(2, p);
        x = 1;
      } else if (x == 1) {
        x = 1;
      } else if (x == 2) {
        x = 3;
        --k;
        if (k < 0) {
          t.emplace_back(3, p);
          break;
        }
      }
    } else {
      assert(0);
    }
    ++p;
  }
  if (k >= 0) {
    if (x != 3) {
      s.emplace_back(x, p);
    } else {
      s.emplace_back(3, p + k);
    }
  }
  while (!t.empty()) {
    s.push_back(t.back());
    t.pop_back();
  }
}

int main() {
  cin >> n >> m >> k_ >> p1 >> p2;
  reverse(p1.begin(), p1.end());
  reverse(p2.begin(), p2.end());
  while (n < m) p1.push_back('0'), ++n;
  while (m < n) p2.push_back('0'), ++m;
  for (int i = n - 1; i >= 0; i--) {
    solve(p1[i] - '0' << 1 | p2[i] - '0', i);
  }
  string q1(s[0].second + 1, '0'), q2(s[0].second + 1, '0');
  for (auto x : s) {
    q1[x.second] = '0' + (x.first >> 1);
    q2[x.second] = '0' + (x.first & 1);
  }
  while (q1.length() > 1 && q1.back() == '0') q1.pop_back();
  while (q2.length() > 1 && q2.back() == '0') q2.pop_back();
  reverse(q1.begin(), q1.end());
  reverse(q2.begin(), q2.end());
  cout << q1 << endl << q2 << endl;
}


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

void Main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for (int i = 0; i < 1000; i++)
    {
        c -= b;
        if(c <= 0){
            cout << "Yes" << endl;
            return;
        }
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            return;
        }
    }
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 3592
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('c2.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    N = read_int()
    A = read_int_list()
    res = [0] * N
    for i in range(N - 1):
      j = A[i] - 1
      res[j] += 1    
    print(*res, sep='\n')


main()


Measured memory_bytes: 33908
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define Rep(i, s, n) for (int i = (int)s; i < (int)n; i++)
typedef long long ll;

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

    int n, d;
    cin >> n >> d;
    int x[n][d];
    rep (i, n) {
        rep (j, d) {
            cin >> x[i][j];
        }
    }
    int res = 0;
    rep (i, n - 1) {
        Rep (j, i + 1, n) {
            double dis = 0;
            rep (k, d) {
                dis += pow(x[i][k] - x[j][k], 2);
            }
            dis = sqrt(dis);
            (floor(dis) == dis) ? res++ : 0;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3640
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 1e5 + 5, M = 2e5 + 5 ;
using namespace std ;

int s, t, n, m, fa[N], e, ter[M], nxt[M], lnk[N], d[2], q[N], dep[N] ;
ll ans ;

int getfa(int x) {
	return (fa[x] == x ? x : fa[x] = getfa(fa[x])) ;
}

void merge(int x, int y) {
	x = getfa(x), y = getfa(y) ;
	if (x != y) fa[x] = y ;
}

void add(int x, int y) {
	ter[++ e] = y, nxt[e] = lnk[x], lnk[x] = e ;
} 

void dfs(int p, int las) {
	++ d[dep[p] & 1] ;
	for (int i = lnk[p]; i; i = nxt[i]) if (ter[i] != las) {
		dep[ter[i]] = dep[p] + 1 ;
		dfs(ter[i], p) ;
	}
}

int dfs1(int p, int las) {
	int ret = (dep[p] & 1) ? 1 : - 1 ;
	for (int i = lnk[p] ; i; i = nxt[i]) if (ter[i] != las) {
		ret += dfs1(ter[i], p) ;
	}
	if (las) ans += abs(ret) ;
	return ret ; 
}

pair <int, int> dfs2(int p, int las) {
	int fi = (dep[p] & 1) ? 1 : - 1, se = (p == s) ? 1 : (p == t ? - 1 : 0) ;
	for (int i = lnk[p]; i; i = nxt[i]) if (ter[i] != las) {
		pair <int, int> tmp = dfs2(ter[i], p) ;
		fi += tmp.first, se += tmp.second ;
	}
	if (se) q[++ q[0]] = se * fi ; else ans += abs(fi) ;
	return make_pair(fi, se) ;
}

int dfs3(int p, int las) {
	int ret = (dep[p] & 1) ? 1 : - 1 ;
	if (p == s || p == t) ret += (d[0] - d[1]) / 2 ;
	for (int i = lnk[p] ; i; i = nxt[i]) if (ter[i] != las) {
		ret += dfs3(ter[i], p) ;
	}
	if (las) ans += abs(ret) ;
	return ret ;
}

int main() {
	scanf("%d%d", &n, &m) ;
	int x, y ;
	rep(i, 1, n) fa[i] = i ;
	rep(i, 1, m) {
		scanf("%d%d", &x, &y) ;
		if (getfa(x) == getfa(y)) s = x, t = y ; else 
			add(x, y), add(y, x), merge(x, y) ;
	}
	d[0] = d[1] = 0 ;
	dfs(1, 0) ;
	if (m == n - 1) {
		if (d[0] != d[1]) {
			printf("-1\n") ;
			return 0 ;
		}
		ans = 0 ;
		dfs1(1, 0) ;
		printf("%lld\n", ans) ;
	} else if ((dep[s] & 1) == (dep[t] & 1)) {
		if (abs(d[0] - d[1]) & 1) {
			printf("-1\n") ;
			return 0 ;
		}
		ans = abs(d[0] - d[1]) / 2 ;
		dfs3(1, 0) ;
		printf("%lld\n", ans) ;
	} else {
		if (d[0] != d[1]) {
			printf("-1\n") ;
			return 0 ;
		}
		q[0] = 1, q[1] = ans = 0 ;
		dfs2(1, 0) ;
		sort(q + 1, q + q[0] + 1) ;
		int mid = q[(q[0] + 1) / 2] ;
		rep(i, 1, q[0]) ans += abs(q[i] - mid) ;
		printf("%lld\n", ans) ;
	}
	return 0 ;
}

Measured memory_bytes: 7808
N,T=map(int,input().split())
c=[]
t=[]
d=[]
for _ in range(N):
  c_i,t_i=map(int,input().split())
  c.append(c_i)
  t.append(t_i)
if min(t)>T:
  print("TLE")
  exit()
for i in range(N):
  if t[i]<=T:
    d.append(c[i])
w=min(d)
print(w)  

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    int n ; cin >> n;
    vector<int> o(100001,0),e(100001,0);
    int omx=0,emx=0,oidx,eidx,osec=0,esec=0;
    rep(i,n){
        int x; cin >> x;
        if(i%2){
            o[x]++;
            if(o[x]>omx){
                omx = o[x];
                oidx = x;
            }else{
                if(o[x]>osec){
                    osec = o[x];
                }
            }
        }else{
            e[x]++;
            if(e[x]>emx){
                emx = e[x];
                eidx = x;
            }else{
                if(e[x]>esec){
                    esec = e[x];
                }
            }

        }
       //cout << omx << osec << emx << esec << endl;        
    }

    if(oidx == eidx){
        cout << n - max(omx+esec,osec+emx) ;
    }else{
        cout << n - omx - emx;
    }
    return 0;
}

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

int main()
{
        int x, y, z;

        scanf("%d %d %d", &x, &y, &z);
        
        if( x<y && y<z ){ cout << "Yes\n"; }
        else{ cout << "No\n"; }

        return 0;
}

Measured memory_bytes: 1172
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
int n;
cin>>n;
vector<P> a(n);
for(int i=0;i<n;i++)cin>>a[i].fi>>a[i].se;
sort(all(a));
double tmp=0;
do{
for(int i=0;i<n-1;i++){
    tmp+=(double)(sqrt)((double)((a[i].fi-a[i+1].fi)*(a[i].fi-a[i+1].fi)+(a[i].se-a[i+1].se)*(a[i].se-a[i+1].se)));
}
}while(next_permutation(all(a)));
ll d=1;
for(int i=1;i<=n;i++)d*=i;
cout<<tmp/(double)d<<endl;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int N = scn.nextInt();
    HashMap<Integer, Integer> map = new HashMap<>();

    for (int i = 0; i < N; i++) {
      int a = scn.nextInt();
      if (map.containsKey(a)) {
        map.put(a, map.get(a) + 1);
      } else {
        map.put(a, 1);
      }
    }

    int shouldChangeCount = 0;
    for (int key : map.keySet()) {
      if (key > map.get(key)) {
        shouldChangeCount += map.get(key);
      } else if (key < map.get(key)) {
        shouldChangeCount += map.get(key) - key;
      }
    }

    System.out.println(shouldChangeCount);
  }
}

Measured memory_bytes: 66088
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
char s[nax];

int ct[nax];

int main ()  {
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    reverse(s + 1, s + 1 + n);

    int cur = 0;

    int p10 = 1;

    long long ans = 0;

    ct[0] = 1;

    for (int i = 1 ; i <= n ; ++ i) {
        cur += p10 * (s[i] - '0');
        cur %= 2019;
        p10 = p10 * 10 % 2019;

        ans += ct[cur];
        ct[cur] ++;

    }

    printf("%lld\n", ans);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 3820
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat64() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func abs(x int) int {
	if x < 0 {
		return -1 * x
	} else {
		return x
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	//sc.Buffer(nil, 10000000000)

	n := nextInt()

	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	ans := 0
	highest := 0
	for i := 0; i < n; i++ {
		t := a[i]
		if i > 0 {
			if highest > t {
				ans = ans + (highest - t)
			}
		}
		if highest < t {
			highest = t
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5856