akhauriyash/Code-Regression huggingface dataset:
n=int(input())
d,x=map(int,input().split())
a=[int(input()) for i in range(n)]
ans=0
for i in range(1,d+1):
    for j in range(n):
        if a[j]==1:
            ans+=(i%a[j]==0)
        else:
            ans+=(i%a[j]==1)
print(ans+x)

Measured memory_bytes: 38896
$routes=[]
$distance=[]
$condition=[]
def counter
  count = 0
  ->{
    count += 1
    return count
  }
end

def get_fatigue (now,m,n,now_place)
  inner=[]
  now.upto(m-n+now) do |i|
    inner.push($distance[now_place]*$condition[i-1])#疲労度
  end
  $routes.push(inner)
end

a=gets.split("\s")
n=a[0].to_i
m=a[1].to_i
n.times do $distance.push(gets.chomp.to_i) end
  m.times do $condition.push(gets.chomp.to_i) end

    c=counter
    n.times do |i|
      get_fatigue(c.call,m,n,i)
    end
    0.upto(m-n) do |y|
      0.upto(n-1) do |x|
        if x>0 && y>0  then
          if $routes[x-1][y]+$routes[x][y]>$routes[x][y-1] then
            $routes[x][y]=$routes[x][y-1]
          else
            $routes[x][y]+= $routes[x-1][y]
          end
        elsif x>0
          $routes[x][y]+=$routes[x-1][y]
        elsif y>0
          if $routes[x][y]>$routes[x][y-1] then
            $routes[x][y]=$routes[x][y-1]
          end
        else
        end
      end
    end
    p $routes[n-1].min



Measured memory_bytes: 9448
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>

#define all(v) v.begin(), v.end()
typedef long long ll;
#define rep(i, z, n) for(ll i = z; i < n; i++)
//const int INF = 1<<29;
//const ll MOD = 1000000007;
using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    int ans = (B  + A - 3) / (A - 1);
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)

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

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdlib>
#include <cmath>
#include <string.h>
#include <memory.h>
#include <algorithm>
#include <iomanip>
#include <string>
#include <bitset>

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

typedef long long ll;

using namespace std;

double const PI = acos(-1);
int dx[] = { 0, 1, 0, -1 };
int dy[] = { 1, 0, -1, 0 };
// int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
// int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };

long long gcd(long long a, long long b) {
	return b == 0 ? a : gcd(b, a % b);
}

long long lcm(long long a, long long b) {
	return a * (b / gcd(a, b));
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  int res = 0, lol = 1;
  while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    if(lol == 1e6 + 1) {
      cout << -1 << endl;
      return 0;
    }
    
    int tmpa = a / 2;
    int tmpb = b / 2;
    int tmpc = c / 2;
    
    a = tmpb + tmpc;
    b = tmpa + tmpc;
    c = tmpa + tmpb;
    
    res++;
    lol++;
  }
  
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2773>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(){
    ll N; cin >> N;
    ll res = 1;
    vector<ll> S(N); for(auto& in:S) cin >> in;
    for(ll t = 1; t <= N; t++){
        if(N%t != 0) continue;
        ll k = N/t;
        
        bool flag = false;
        for(int i = 0; i < N-t;i++){
            if(S[i] == S[i+t]) continue;
            flag = true;
        }
        if(flag) continue;
        res = k;
        break;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 4416
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define N_MAX 100
#define M_MAX 200000
#define INF 10000000
#define SMAP(a, b) ((a)!=(b))&&((a)^=((b)^=((a)^= (b))))

typedef unsigned long long ull;
typedef   signed long long dll;

int n, m;
int i, j, k;
int a;

char s[N_MAX + 1];

typedef struct {
	int in;
	int out;
} twoway;

void deb(){
	return;
}

void solve(){
	int result = 0;
	int prev = 0;

	for (i = 0; i < n; i++) {
		switch (s[i]) {
		case 'I':
			prev++;
			if (result < prev) result = prev;
			break;
		case 'D':
			prev--;
			break;
		}
	}

	printf("%d\n", result);

	return;
}

int main (void) {
	scanf("%d%s", &n, s);

	solve();
	return 0;
}




Measured memory_bytes: 128
import java.util.*;
 
public class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int d=0;
		int a=sc.nextInt();
		int b[]=new int [a];
		for(int i=0;i<a;i++)
		{
			b[i]=sc.nextInt();
		}
		Arrays.sort(b);
		for(int j=0;j<a;j++)
		{
			d=(b[a-1]-b[0]);
		}
		System.out.println(d);
	}
}

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

using namespace std;

void solve();
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("error.txt", "w", stderr);
    freopen("output.txt", "w", stdout);
#endif

    int t = 1;
    //cin>>t;
    while (t--)
    {
        solve();
        cout << "\n";
    }

    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}
void solve()
{
    int n, c1 = 0, c2 = 0, c3 = 0, c4 = 0;
    cin >> n;
    string str;
    for (int i = 0; i < n; ++i)
    {
        cin >> str;
        if (str == "AC")
            c1++;
        else if (str == "WA")
            c2++;
        else if (str == "TLE")
            c3++;
        else if (str == "RE")
            c4++;
    }
    cout << "AC" << " x " << c1 << endl;
    cout << "WA" << " x " << c2 << endl;
    cout << "TLE" << " x " << c3 << endl;
    cout << "RE" << " x " << c4 << endl;
}


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

// 2辺固定して残り1辺を二分探索

int main()
{
    int N;
    cin >> N;
    vector<long long> L(N);
    for (int i = 0; i < N; i++)
        cin >> L[i];
    sort(L.begin(), L.end());

    long long cnt = 0;

    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            int k = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin();

            cnt += max(k - (j + 1), 0);
        }
    }
    cout << cnt << endl;
    return 0;
}

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

long long N, X[1 << 18], Y[1 << 18]; pair<long long, int> A[1 << 18];
long long SIZE_ = 1;

bool flag1 = false, flag2 = false, used[1 << 18];
int col[1 << 18], cnts;
vector<int> G[1 << 18], H[1 << 18], I;

void build_edge(int u, int v) {
	G[u ^ SIZE_].push_back(v);
	G[v ^ SIZE_].push_back(u);
}

void add_edge(int x, int l, int r, int a, int b, int u) {
	// x -> [l, r)
	if (l <= a && b <= r) {
		int u1 = x, v1 = u;
		if (flag1 == true) u1 ^= SIZE_;
		if (flag2 == true) v1 ^= SIZE_;
		build_edge(u1, v1);
		return;
	}
	if (r <= a || b <= l) return;

	add_edge(x, l, r, a, (a + b) >> 1, u * 2);
	add_edge(x, l, r, (a + b) >> 1, b, u * 2 + 1);
}

void dfs1(int pos) {
	used[pos] = true;
	for (int i : G[pos]) {
		if (used[i] == false) dfs1(i);
	}
	I.push_back(pos);
}

void dfs2(int pos) {
	col[pos] = cnts;
	for (int i : H[pos]) {
		if (col[i] == 0) dfs2(i);
	}
}

bool solve(int D) {
	// ---------------------- 初期化 -------------------------
	for (int i = 0; i < SIZE_ * 2; i++) { G[i].clear(); H[i].clear(); used[i] = false; col[i] = 0; }
	I.clear(); cnts = 0;

	// --------------------- 辺を張る ------------------------
	for (int i = 0; i < N; i++) {
		build_edge(X[i] + (1 * SIZE_ / 2), Y[i] + (1 * SIZE_ / 2));
		build_edge(X[i] + (3 * SIZE_ / 2), Y[i] + (3 * SIZE_ / 2));
	}
	for (int i = 0; i < 2 * N; i++) {
		int pos1 = lower_bound(A, A + N * 2, make_pair(A[i].first - D + 1, -1000000)) - A;
		int pos2 = lower_bound(A, A + N * 2, make_pair(A[i].first + D - 1, 1000000)) - A;
		flag1 = false; flag2 = false;
		add_edge(i + (SIZE_ / 2), pos1, i, 0, SIZE_ / 2, 1);
	}
	for (int i = 1; i < SIZE_ / 2; i++) {
		build_edge(i + SIZE_, i * 2);
		build_edge(i + SIZE_, i * 2 + 1);
	}

	// ------------------- SAT を求める --------------------
	for (int i = 0; i < SIZE_ * 2; i++) {
		for (int j : G[i]) H[j].push_back(i);
	}
	for (int i = 0; i < SIZE_ * 2; i++) {
		if (used[i] == true) continue;
		dfs1(i);
	}
	reverse(I.begin(), I.end());
	for (int i : I) {
		if (col[i] >= 1) continue;
		cnts++; dfs2(i);
	}

	// ------------------- 最終チェック --------------------
	for (int i = 0; i < SIZE_; i++) {
		if (col[i] == col[i + SIZE_]) return false;
	}
	return true;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> X[i] >> Y[i];
		A[i * 2 + 0] = make_pair(X[i], i);
		A[i * 2 + 1] = make_pair(Y[i], i + (int)N);
	}
	sort(A, A + N * 2);
	for (int i = 0; i < N * 2; i++) {
		X[i] = lower_bound(A, A + N * 2, make_pair(X[i], i)) - A;
		Y[i] = lower_bound(A, A + N * 2, make_pair(Y[i], i + (int)N)) - A;
	}
	while (SIZE_ < N * 4) SIZE_ *= 2;

	int cl = 0, cr = 1000000009, cm, maxn = -1;
	for (int i = 1; i <= 35; i++) {
		cm = (cl + cr) / 2;
		if (solve(cm) == true) { maxn = max(maxn, cm); cl = cm; }
		else { cr = cm; }
	}
	cout << maxn << endl;
	return 0;
}

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

using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

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

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve() {
	
	int n , d;
	
	cin >> n >> d;
	
	int a[n][d];
	
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < d; ++j) {
			cin >> a[i][j];
		}
	}
	
	int ans = 0;
	
	for(int i = 0; i < n; ++i) {
		for(int j = i+1; j < n; ++j) {
			int res = 0;
			
			for(int z = 0; z < d; ++z) {
				res += (a[i][z] - a[j][z])*(a[i][z] - a[j][z]);
			}
			
			int p = sqrt(res);
			
			if(p*p == res) {
				ans++;
			}
		}
	}
	
	cout << ans;
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3588
#coding: utf-8
from functools import reduce
from fractions import gcd    #py<=3.4
#from math import gcd    # py >= 3.5
N, X = map(int, input().split())
x = list(map(int, input().split()))
res = [abs(x[i] - X) for i in range(N)]
print(reduce(gcd, res))

Measured memory_bytes: 16304
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%lld",&x);
int main(){
    ll x;
    sc(x)
    ll ans = (x / 11) * 2;
    if (x % 11 > 0) ans += 1;
    if (x % 11 > 6) ans += 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <sstream>

using namespace std;

typedef int teamID;

struct TeamResult
{
    int id;
    int correctCount;
    int penalty;
};

struct ICPCResult
{
    map<teamID, TeamResult> tResult;
};

struct ProblemStatus
{
    bool clear;
    int wrongCount;
};

struct TeamStatus
{
    typedef int problemID;
    map<problemID, ProblemStatus> pStatuses;
};

struct MyComp// : public binary_function<TeamResult, TeamResult, bool>
{
    bool operator()(const TeamResult& x, const TeamResult& y) const
    {
        if (x.correctCount > y.correctCount) return false;
        if (x.correctCount == y.correctCount)
        {
            if (x.penalty < y.penalty) return false;
            if (x.penalty == y.penalty) return x.id > y.id;
        }
        return true;
    }
};

int main()
{
    deque<ICPCResult> results;
    string result;
    int T, P, R;
    while (cin >> T >> P >> R)
    {
        if (T == 0 && T == 0 && R == 0) break;
        results.push_back(ICPCResult());
        ICPCResult& curICPCResult = results.back();
        map<teamID, TeamStatus> tStatuses;
        for (int log = 0; log < R; ++log)
        {
            int tID, pID, time;
            string msg;
            cin >> tID >> pID >> time >> msg;
            ProblemStatus& thisProblemStatus = tStatuses[tID].pStatuses[pID];
            if (msg == "CORRECT")
            {
                TeamResult& thisTeamResult = curICPCResult.tResult[tID];
                thisTeamResult.id = tID;
                ++thisTeamResult.correctCount;
                thisTeamResult.penalty += thisProblemStatus.wrongCount*1200 + time;
            }
            else ++thisProblemStatus.wrongCount;
        }
        
        priority_queue<TeamResult, vector<TeamResult>, MyComp> sorted;
        for (int tID = 1; tID <= T; ++tID)
        {
            TeamResult& tResult = curICPCResult.tResult[tID];
            tResult.id = tID;
            sorted.push(tResult);
        }
        
        while (sorted.size() != 0)
        {
            const TeamResult& team = sorted.top();
            stringstream ss;
            ss << team.id << " " << team.correctCount << " " << team.penalty << endl;
            result += ss.str();
            sorted.pop();
        }
    }
    cout << result;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int ans;
  if((a+b)%2 == 1){
    ans = (a+b)/2 + 1;
  }else{
    ans = (a+b)/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
int main(void)
{
    double x1, x2, x3, y1, y2, y3;
    double px, py, r;
    int n, i;

    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
        px = ((y2 - y3)*(x1*x1 + y1*y1) + (y3 - y1)*(x2*x2 + y2*y2) + (y1 - y2)*(x3*x3 + y3*y3))/(2*(x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2)));
        py = ((x2 - x3)*(x1*x1 + y1*y1) + (x3 - x1)*(x2*x2 + y2*y2) + (x1 - x2)*(x3*x3 + y3*y3))/(2*(y1*(x2 - x3) + y2*(x3 - x1) + y3*(x1 - x2)));
        r = sqrt((x1 - px)*(x1 - px) + (y1 - py)*(y1 - py));
        printf("%.3lf %.3lf %.3lf\n", px, py, r);
    }

    return 0;
}

Measured memory_bytes: 664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cii(a);
    cii(b);
    cii(c);
    int ans = min(b / a, c);
    co(ans);
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func different(i, j, node, neigh int) bool {
	return !(i == node && j == neigh) && !(i == neigh && j == node)
}

func dfs(g [][]int, i, j, node int, visited []bool) {
	for _, neigh := range g[node] {
		if !visited[neigh] && different(i, j, node, neigh) {
			visited[neigh] = true
			dfs(g, i, j, neigh, visited)
		}
	}
}

func is_bridge(g [][]int, i, j int) bool {
	visited := make([]bool, len(g))
	visited[0] = true
	dfs(g, i, j, 0, visited)
	for _, b := range visited {
		if !b {
			return true
		}
	}
	return false
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	g := make([][]int, n)
	for i := range g {
		g[i] = make([]int, 0)
	}
	for i := 0; i < m; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		g[a-1] = append(g[a-1], b-1)
		g[b-1] = append(g[b-1], a-1)
	}

	cnt := 0
	for i, l := range g {
		for _, j := range l {
			if i < j && is_bridge(g, i, j) {
				cnt++
			}
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
n = gets.to_i
a = gets.split().map(&:to_i)
b = gets.split().map(&:to_i)

result = 0
(0..n-1).each do |i|
  if a[i] <= b[i]
    result += a[i]
    b[i] -= a[i]
    if a[i+1] <= b[i]
      result += a[i+1]
      a[i+1] = 0
    else
      result += b[i]
      a[i+1] -= b[i]
    end
  else
    result += b[i]
  end
end

puts result

Measured memory_bytes: 15500
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN      
const ll mod=1e9+7;
const int N=1e6+4;
 
int main()                  
{
    ll x,k,d;
    cin>>x>>k>>d;
    
    if(x<0)
    x=-x;
    
    ll step=x/d;
    
    ll ans;
    if(step>=k)
    {
        ans=x-k*d;
    }
    else
    {
        if((k-step)%2==0)
        {
            ans=x-step*d;
        }
        else
        {
            ans=x-(step+1)*d;
        }
    }
    
    if(ans<0)
    ans=-ans;
    
    
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3516
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
 
const int maxn = 109;
int n, s, sum, best = maxn;
 
int main(){
	scanf("%d", &n);
	for (int i=1; i<=n; i++){
		scanf("%d", &s);
		sum += s;
		if (s % 10) best = min(best, s);
	}
	if (sum % 10) printf("%d\n", sum);
	else if (best != maxn) printf("%d\n", sum - best);
	else puts("0");
	return 0;
}

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

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

int main()
{
	int n;
	int min_p, max_p;

	while( true )
	{
		n = in();
		if( n == 0 )break;
		min_p = 501;
		max_p = 0;
		for(int i = 0; i < n; i++)
		{
			int point = 0;
			for(int j = 0; j < 5; j++)
			{
				point += in();
			}
			max_p = max(point, max_p);
			min_p = min(point, min_p);
		}
		printf("%d %d\n", max_p, min_p);
	}
	return (0);
}

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

#define readv(v) for(auto& pepito : v) cin >> pepito;
#define printv(v) for (int pepo = 0; pepo < v.size(); pepo++) cout << (pepo==0?: ) << v[pepo]; cout << endl;
#define queries(maria) int maria; cin >> maria; while (maria--) 
//for (int i = 0; i < n; i++) 

using ll = long long int;
using vi = vector<ll>;
using vvi = vector<vi>;

bool collapse(const vvi& ans, ll l){
    if (ans.size() == 0) return false;
    return l < ans[ans.size()-1][0];
}

int main(){
    ll n; cin >> n;
    vvi intervals(n);
    for (vi& v : intervals) {
        ll x, L;
        cin >> x >> L;
        v = {x+L, x-L};
    }
    sort(intervals.begin(), intervals.end());
    vvi ans;
    for (int i = 0; i < n; i++) 
        if (not collapse(ans, intervals[i][1]))
            ans.push_back(intervals[i]);
    cout << ans.size() << endl;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

void solve()
{
    int A, B, T;
    cin >> A >> B >> T;
    cout << (T / A) * B << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
 
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
vector<int> G[200001];
int p2[200001];
int R[200001];
vector<int> RC[200001];
deque<int> dp[200001][2];

void dfs(int x, int r) {
  R[x] = r, RC[r].pb(x);
  for (int t : G[x]) {
    dfs(t, r+1);
  }
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  p2[0] = 1;
  for (int i=1; i<=200000; i++) p2[i] = (2LL*p2[i-1]) % MOD;
  cin >> N;
  N++;
  rep(i, N-1) {
    int p;
    cin >> p;
    G[p].pb(i+1);
  }
  dfs(0, 0);
  for (int x=N-1; x>=0; x--) {
    P m = P(-1, -1);
    for (int t : G[x]) m = max(m, P(dp[t][0].size(), t));
    int lc = m._2;
    if (lc != -1) {
      swap(dp[x][0], dp[lc][0]);
      swap(dp[x][1], dp[lc][1]);
    }
    int secR = 0;
    for (int t : G[x]) if (t != lc) secR = max(secR, (int)dp[t][0].size());
    vector<int> dump(secR);
    for (int t : G[x]) if (t != lc) {
      rep(r, dp[t][0].size()) {
        int a0 = dp[x][0][r], a1 = dp[x][1][r],
            b0 = dp[t][0][r], b1 = dp[t][1][r];
        dp[x][1][r] = (1LL*a1*b0 + 1LL*b1*a0) % MOD;
        dp[x][0][r] = (1LL*a0*b0) % MOD;
        dump[r] = (1LL*dump[r]*(b0+b1) + 1LL*a1*b1) % MOD;
      }
    }
    rep(r, secR) dp[x][0][r] = (dp[x][0][r] + dump[r]) % MOD;
    dp[x][0].push_front(1);
    dp[x][1].push_front(1);
  }

  int s = 0;
  rep(r, dp[0][1].size()) s = (s + 1LL*dp[0][1][r]*p2[N-RC[r].size()]) % MOD;
  cout << s << "\n";
  return 0;
}


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

int main(){
    double n, k, prob;
    cin >> n >> k;
    rep(i, 1, n+1){
        int cnt = i;
        double toss = 1;
        while (cnt < k){
            cnt *= 2;
            toss *= 0.5;
        }
        prob += toss/n;
    }
    printf("%.10f\n", prob);
    return 0;
}   

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){
    
    int n;
    string s,t;

    cin >> n;
    cin >> s >> t;

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

    cout << endl;

    return 0;
}

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

int main(){
  int a, b, n, ans=-1;
  cin >>a >>b;
  n = 10*b;
  for(int i=0; i<10; i++)
  {
    if(((n+i)*8)/100==a)
    {
      ans = n+i; 
      break;
    }
  }
  cout <<ans;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int num = 0;
  for (int i=A; i<=B; i++) {
    string i_str = to_string(i);
    reverse(i_str.begin(), i_str.end());
    int i_str_num = stoi(i_str);
    if (i == i_str_num) {
      num++;
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] ss = { "Sunny", "Cloudy", "Rainy" };
        String s = sc.next();
        for (int i = 0; i < ss.length; i++) {
            if (ss[i].equals(s)) {
                System.out.println(ss[(i + 1) % 3]);
            }
        }
    }
}

Measured memory_bytes: 21456
s = input()
q = int(input())
query = [input() for i in range(q)]
rvs = 1
s1 = ""
for i in range(q):
    if query[i] == "1":
        rvs = rvs * (-1)
    else:
        if query[i][2:3] == "1":
            if rvs == 1:
   #             s = query[i][4:5] + s
                s1 = s1 + query[i][4:5]
            else:
                s = s + query[i][4:5]
        else:
            if rvs == -1:
    #            s = query[i][4:5] + s
                s1 = s1 + query[i][4:5]
            else:
                s = s + query[i][4:5]
if rvs == -1:
    s = s[::-1] + s1
else:
    s = s1[::-1] + s
#print(rvs,s1,s)
print(s)

Measured memory_bytes: 16972
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
#define ll long long
ll x, y;

ll abso(ll x){
	if (x >= 0) return x;
	return -x;
}

int main(){
	scanf("%lld%lld", &x, &y);
	if (y == 0){
		if (x >= 0){
			printf("%lld\n", (ll)1 + x);
		} else {
			printf("%lld\n", abso(x));
		}
	} else if (x >= 0 && y > 0){
		if (x > y){
			printf("%lld\n", (ll)2 + (x - y));
		} else {
			printf("%lld\n", y - x);
		}
	} else if (x < 0 && y < 0){
		if (y >= x){
			printf("%lld\n", y - x);
		} else {
			printf("%lld\n", (ll)2 + (x - y));
		}
	} else if (x >= 0 && y < 0){
		printf("%lld\n", (ll)1 + abso(abso(x) - abso(y)));
	} else {
		printf("%lld\n", (ll)1 + abso(abso(x) - abso(y)));
	}
}

Measured memory_bytes: 256
import copy
H, W = map(int, input().split())

a = [list(input()) for _ in range(H)]
a_copy = a.copy()
for cs in a_copy:
    for c in cs:
        if c == '#':
            break
    else:
        a.remove(cs)

a_copy = copy.deepcopy(a)
count = 0
for row in range(len(a_copy[0])):
    for line in range(len(a_copy)):
        if a_copy[line][row] == '#':
            break
    else:
        for line in range(len(a_copy)):
            del a[line][row - count]
        count += 1

for cs in a:
    for c in cs:
        print(c, end='')
    print()

Measured memory_bytes: 5108
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    string s;
    cin >> s;
    if(s.front() == s.back()) {
        int n = s.size() - 3;
        if(n%2) {
            cout << "First" << endl;
        } else {
            cout << "Second" << endl;
        }
    } else {
        int n = s.size() - 2;
        if(n%2) {
            cout << "First" << endl;
        } else {
            cout << "Second" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
inline void writeln(int x) {
	int s = 0, p; char f[7];
	while (x) {
		p = x; x /= 10;
		f[s++] = p - (x << 1) - (x << 3);
	}
	if (!s) f[s++] = 0;
	while (s--) putchar_unlocked(f[s] + '0');
	putchar_unlocked('\n');
}
char s[1000009], t[10009];
int main() {
	int sl = 0, tl = 0;
	while ((s[sl++] = getchar_unlocked()) != '\n'); sl--;
	while ((t[tl++] = getchar_unlocked()) != '\n'); tl--;
	unsigned long long hs = 0, ht = 0, pw = 1;
	for (int i = 0; i < tl; i++) {
		hs = (hs << 8) + hs + s[i];
		ht = (ht << 8) + ht + t[i];
		pw = (pw << 8) + pw;
	}
	for (int i = tl; i <= sl; i++) {
		if (hs == ht) writeln(i - tl);
		hs = (hs << 8) + hs + s[i] - s[i - tl] * pw;
	}
	return 0;
}

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

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

    int ans = 0;
    rep(i, s.size()) {
        if (s[i] != t[i])
            ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3852
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int d = int.Parse(input[0]);
        int n = int.Parse(input[1]);

        if (d == 0)
        {
            if(n == 100)
            {
                Console.WriteLine(n + 1);
            }
            else
            {
                Console.WriteLine(n);
            }
        }
        else
        {
            if (n == 100)
            {
                Console.WriteLine((int)Math.Pow(100, d) * (n + 1));
            }
            else
            {
                Console.WriteLine((int)Math.Pow(100, d) * n);
            }
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n=0;
    scanf("%d",&n);
    int d[n]={0};
    int y=0;
    for(int i=0;i<n;i++)scanf("%d",&d[i]);
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            y=y+d[i]*d[j];
        }
    }
    printf("%d",y);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int x,y;cin>>x>>y;
  int a[3];
  if((x==4 or x==6 or x==9) && (y==6 or y==9 or y==11)){
    P("Yes");
  }else if((x==1 or x==3 or x==5 or x==7 or x==8 or x==10) && (y==3 or y==5 or y==7 or y==8 or y==10 or y==12)){
    P("Yes");
  }else{
    P("No");
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

long long int n, a, b;
long long int tmp, z;
long long int z2, z1;

#define MIN(A,B) ((A)<(B)?(A):(B))
int main(){

  scanf("%lld", &n);
  scanf("%lld %lld", &a, &b);
  if (a>b) { tmp=a; a=b; b=tmp;}

  if (((a-b)%2)==0) {
    printf("%lld\n", (b-a)/2);
  } else {
    z1=a+(b-a-1)/2;
    z2=(n-b+1)+(b-a-1)/2;
    printf("%lld\n", MIN(MIN(MIN(b-1, n-a),z1), z2));
  }
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 10000007ll
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
using namespace std;
#define pi (long double)3.14159265358979323846 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 struct sch{
	ll s,e,t;
};
bool sortinrev(const struct sch &a, const struct sch &b) 
{ 
    return (a.s < b.s); 
}
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
int main()
{
	string s,t;
	cin>>s>>t;
	int flag = 1;
	if(s.size()!=t.size()-1)
	{
		flag = 0;
	}
	for(ll i=0;i<s.size();i++)
	{
		if(s[i]!=t[i])
			flag = 0;
	}
	if(flag)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3640
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;

int main()
{
    int H, A;
    cin >> H >> A;
    int i = 0;
    while(1)
    {
        H = H - A;
        i++;
        if (H<=0) break; 
    }
    
    cout << i <<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>

using namespace std;

int main()
{
    int n;
    long long int ids[4001];
    int id;
    long long price, amount;
    bool exist;
    bool used[4001];
    vector<int> rank;
    while(cin >> n && n)
    {
        exist=false;
        for(int i=1;i<4001;++i)
        {
            ids[i] = 0;
            used[i] = false;
        }
        rank.clear();
        for(int i=0;i<n;++i)
        {
            cin >> id >> price >> amount;
            if(!used[id])
            {
                rank.push_back(id);
                used[id] = true;
            }
            ids[id] += price * amount;
        }
        for(int i=0;i<rank.size();++i)
        {
            if(ids[rank[i]] >= 1000000)
            {
                exist = true;
                cout << rank[i] << endl;
            }
        }
        if(!exist) cout << "NA" << endl;
    }
}

Measured memory_bytes: 1272
class UnionFind:
    __slots__ = ["_data_size", "_roots"]

    def __init__(self, N):
        self._data_size = N
        self._roots = [-1] * N

    def __getitem__(self, x: int) -> int:
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def unite(self, x, y):
        x = self[x]
        y = self[y]
        if x == y:
            return
        elif self._roots[y] < self._roots[x]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x

    def is_connected(self, x, y):
        return self[x] == self[y]


import sys

readline = sys.stdin.buffer.readline

N, Q = map(int, readline().split())
tree = UnionFind(N)
res = []
for _ in range(Q):
    t, u, v = map(int, readline().split())
    if t:
        res.append(int(tree.is_connected(u, v)))
    else:
        tree.unite(u, v)
print("\n".join(map(str, res)))


Measured memory_bytes: 84140
S = list(input())
s = len(S)

p = [S[i] for i in range(0,s) if i%2 == 0]
q = [S[i] for i in range(1,s) if i%2 == 1]

p_1 = p.count('1')
p_0 = len(p)-p_1

q_1 = q.count('1')
q_0 = len(q)-q_1

if p_1 > p_0:
    if q_0 > q_1:
        ans = p_0 + q_1

    else:
        if p_1-p_0 > q_1-q_0:
            ans = p_0+q_1
        else:
            ans = p_1+q_0

else:
    if q_1 > q_0:
        ans = p_1 + q_0

    else:
        if p_0-p_1 > q_0-q_1:
            ans = p_1+q_0
        else:
            ans = p_0+q_1

print(ans)


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

namespace ABC150A
{
    class Program
    {
        static void Main(string[] args)
        {
            var word = Console.ReadLine().Split(' ');
            int K = int.Parse(word[0]);
            int X = int.Parse(word[1]);
            if(K*500>=X)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<vector>

using namespace std;

int main()
{
	int n,xw;
	cin >> n >> xw;
	vector<int> w(n),v(n);
	for(int i=0;i<n;i++)
		cin >> w[i] >> v[i];
	vector<vector<long long> > dp(n,vector<long long>(xw+1,0));

	for(int i=0;i<=xw;i++)
	{
		if(i>=w[0])
			dp[0][i]=v[0];
	}
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<=xw;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(j>=w[i])
				if(dp[i][j]<dp[i-1][j-w[i]]+v[i])
					dp[i][j]=dp[i-1][j-w[i]]+v[i];
		}
	}
/*
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=xw;j++)
			cout << dp[i][j] << "  ";
		cout << endl;
	}
*/
	long long ans=0;
	for(int i=0;i<=xw;i++)
	{
		if(ans<dp[n-1][i])
			ans=dp[n-1][i];
	}
	cout << ans << endl;
	
}


Measured memory_bytes: 79488
n = gets.to_i
info = Array.new(n){gets.split(" ").map(&:to_i)}.sort_by{|item| item[0]}

cnt = 0
cnt += info[0][0] - 1
cnt += info[n-1][1]
cnt += info[n-1][0] - info[0][0] + 1
puts cnt

Measured memory_bytes: 24072
#include<stdio.h>


bool solve(int i,int m,int A[],int n){
    if(m == 0){
        return true;
    } 
    if(i >= n || m < 0){
        return false;
    }
    bool res = solve(i+1,m,A,n) || solve(i+1,m - A[i],A,n);
    return res;
}
int main(){
    int n,q,m;
    scanf("%d",&n);
    int A[n];
    for(int i = 0;i < n;i++){
        scanf("%d",&A[i]);
    }
    scanf("%d",&q);
    for(int i = 1;i <= q;i++){
        scanf("%d",&m);
        if(solve(0,m,A,n)){
            printf("yes\n");
        } else {
            printf("no\n");
        }
    }
}


Measured memory_bytes: 2612
#include <cctype>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#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 LL long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

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

int main(){
	int r0, w0, c, r;
	
	while(cin >> r0 >> w0 >> c >> r, r0 + w0 + c + r){
		bool flag = false;
		int ans = 0;
		if(r0/w0 >= c){
			cout << ans << endl;
		}else{ 
			while(1){
				++ans;
				if((r0 + ans * r) / c >= w0){
					break;
				}
			}
			cout << ans << endl;
		}

	}
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

//AtCoder解説動画(https://www.youtube.com/watch?v=TdR816rqc3s&feature=youtu.be)からもらった
struct UnionFind {
	vector<int> d;
	UnionFind(int n=0): d(n,-1) {} //このコロンってなんですか
	int find(int x){
		if (d[x] < 0) return x; //x:根
		return d[x] = find(d[x]);//x:子 -> xの親の根を返す
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);//根同士をくっつける。
		if ( x ==  y) return false ; 
		/*連結成分が一致してるんだったらfalse返す。
			minimum spanning tree (クラスカル法と言うのをやるときに、くっつけたかどうかを取れると嬉しい.
			chmin/chmaxみたいなノリかな
		 */
		if ( d[x] > d[y]) swap(x,y);//xの方が大きいようにする（ただしサイズは負デモっているので不等号が逆）
		d[x] += d[y] ; //xにyをくっつける.
		d[y] = x;
		return true; 
	}
	bool same(int x, int y) { return find(x) == find(y) ; }
	int size(int x) { return -d[find(x)];}
};
int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	rep(i,m) cin >> a[i] >> b[i];
	rep(i,m) a[i]--, b[i]--;
	UnionFind uf(n);
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());

	vector<ll> heru(m,0);
	rep(i,m){
		ll amae = uf.size(a[i]);
		ll bmae = uf.size(b[i]);
		uf.unite(a[i],b[i]);
		if(amae != uf.size(a[i])) heru[i] = amae * bmae ;
	}
	reverse(heru.begin(),heru.end());
	ll ans = 0;
	rep(i,m){
		ans += heru[i];
		cout << ans << endl;
	}
}


Measured memory_bytes: 3328
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    Node[] nodes= new Node[N];
    for (int i = 0; i < N; i++) nodes[i] = new Node(i);
    int[] edges = new int[N - 1];
    int[] colors = new int[N - 1];
    Arrays.fill(colors, -1);

    int k = 0;
    for (int i = 0; i < N - 1; i++) {
      int a = scanner.nextInt() - 1;
      int b = scanner.nextInt() - 1;
      edges[i] = a ^ b;
      nodes[a].edges.add(i);
      nodes[b].edges.add(i);
      k = Math.max(k, nodes[a].edges.size());
      k = Math.max(k, nodes[b].edges.size());
    }

    dfs(nodes[0], nodes, edges, colors, -1);
    StringBuilder sb = new StringBuilder();
    sb.append(k).append('\n');
    for (int i = 0; i < N - 1; i++) sb.append(colors[i] + 1).append('\n');
    System.out.print(sb.toString());
  }

  private static void dfs(Node node, Node[] nodes, int[] edges, int[] colors, int color) {
    int c = 0;
    for (int e : node.edges) {
      if (colors[e] >= 0) continue;
      if (c == color) c++;
      colors[e] = c;
      dfs(nodes[edges[e] ^ node.id], nodes, edges, colors, c);
      c++;
    }
  }

  private static class Node {
    private final int id;
    private final List<Integer> edges = new ArrayList<>();

    private Node(int id) {
      this.id = id;
    }
  }
}


Measured memory_bytes: 104516
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,i,j;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a-b < 0){
		e = a * c;
		printf("%d",e);
	}else{
		e = (a-b) * d;
		printf("%d",e + b*c);
	}
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
static const int NMAX = 100001;

bool BinarySearch(int *arr, int N, int key);

int main() {
    int S[NMAX], times, n, q, key;

    times = 0;

    std::cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%d", &S[i]);
    }
    
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        scanf("%d", &key);
        if (BinarySearch(S, n, key)) {
            times++;
        }
    }
    
    std::cout << times << std::endl;

    return 0;
}

bool BinarySearch(int *arr, int N, int key){
    int left, right, mid;

    left = 0;
    right = N;

    while (left < right) {
        mid = (left + right) / 2;  // integer truncation
        if (key == arr[mid]) {
            return true;
        } else if (key < arr[mid]) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    
    return false;
}


Measured memory_bytes: 3516
#pragma region template 2.2
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), cout, ", ") << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, ostream &os = cout, string sep = " ")
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), os, ", ") << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    IN(string, S);

    map<char, ll> cnt;
    FOR(c, S)
    {
        ++cnt[c];
    }
    ll ans = cnt['R'] * cnt['G'] * cnt['B'];
    REP(i, N)
    {
        REP(j, N)
        {
            ll k = 2 * j - i;
            if (i < j and k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i])
            {
                --ans;
            }
        }
    }
    OUT(ans);
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL n;
  cin >> n;
  cout << n * (n-1) / 2 << endl;
  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    bool ok = false;
    repl(i, 1, n + 1) {
        int x = floor(i * 1.08);
        if(x == n) {
            cout << i << endl;
            ok = true;
            break;
        }
    }
    if(ok == false) cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<cstring>
using namespace std;
const int M=1e9+7;
int main(){
	
	int n,x,t;
	cin>>n>>x>>t;
	if(n%x==0)
	cout<<((n/x))*t;
else cout<<(n/x + 1)*t;
	return 0;
}

Measured memory_bytes: 3636