akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int s[301][301], k[301], n, m, ans = 114514;

int main() {
  cin >> n >> m;

  rep(i, 0, n) s[n][0] = 1;
  rep(i, 0, n) {
    rep(j, 1, m + 1) {
      cin >> s[i][j];
    }
  }

  rep(j, 0, m) {
    int p[301] = {};
    int max = 0, in;

    for(int i = 0; i < n; i++) {
      int g = s[i][s[i][0]];
      if(k[g]) {
        s[i][0]++;
        i--;
        continue;
      }
      if(max < ++p[g]) max = p[g], in = g;
    }
    k[in] = 1;
    ans = min(ans, max);
  }

  cout << ans << endl;
}


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

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

    static class BJudgeStatusSummary {
        public void solve(int testNumber, Scanner s, PrintWriter sout) {
            int n = s.nextInt(), ac = 0, wa = 0, tle = 0, re = 0;
            String x;
            char a;
            while (n-- != 0) {
                x = s.next();
                a = x.charAt(0);
                if (a == 'A') ac++;
                else if (a == 'T') tle++;
                else if (a == 'R') re++;
                else wa++;
            }
            sout.println("AC x " + ac);
            sout.println("WA x " + wa);
            sout.println("TLE x " + tle);
            sout.println("RE x " + re);
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

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

    }
}



Measured memory_bytes: 48340
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    struct Point
    {
        public int x;
        public int y;
        public int h;
        public Point(int x ,int y,int h)
        {
            this.x = x;
            this.y = y;
            this.h = h;
        }
    }
    static void Main(string[] args)
    {
        int N = int.Parse(System.Console.ReadLine());
        var list = new List<Point>();
        for (int i = 0; i < N; i++)
        {
            string[] temp = System.Console.ReadLine().Split(' ');
            int x = int.Parse(temp[0]);
            int y = int.Parse(temp[1]);
            int h = int.Parse(temp[2]);
            list.Add(new Point(x, y, h));
        }
        for(int cx = 0; cx <= 100; cx++)
        {
            for (int cy = 0; cy <= 100; cy++)
            {
                bool flag=true;
                int ch = -1;
                int hMax = int.MaxValue;
                for(int i = 0; i < N; i++)
                {
                    int x = list[i].x;
                    int y = list[i].y;
                    int h = list[i].h;
                    int d = Math.Abs(cx - x) + Math.Abs(cy - y);
                    if (h > 0)
                    {
                        int buf = h + d;
                        if (ch > 0 && ch != buf)
                        {
                            flag = false;
                            break;
                        }
                        else
                        {
                            ch = buf;
                        }
                    }
                    else
                    {
                        hMax = Math.Min(hMax, d);
                    }
                }
                if (flag && ch <= hMax)
                {
                    Console.WriteLine($"{cx} {cy} {ch}");
                }
            }
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
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 (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

const int MAX_N = 50;
int n, m;
int a[MAX_N], b[MAX_N];
bool G[MAX_N][MAX_N];
bool visited[MAX_N];

void dfs(int v) {
    visited[v] = true;
    rep(v2, n) {
        if(G[v][v2]==false) continue;
        if(visited[v2]==true) continue;
        dfs(v2);
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
	cin >> n >> m;
    rep(i,m) {
        cin >> a[i] >> b[i];
        --a[i], --b[i];
        G[a[i]][b[i]] = G[b[i]][a[i]] = true;
    }
    int ans = 0;
    rep(i,m) {
        G[a[i]][b[i]] = G[b[i]][a[i]] = false;
        rep(j,n) visited[j] = false;
        dfs(0);
        bool bridge = false;
        rep(j,n) if(visited[j]==false) bridge = true;
        if(bridge) ++ans;
        G[a[i]][b[i]] = G[b[i]][a[i]] = true;
    }
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int k;
    cin >> k;
    cout << k/2 * (k-k/2) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <cassert>
#include <queue>
#include <ctime>
#include <string>
#include <cstring>
#include <random>
#define mp make_pair
#define pb push_back
#define NAME ""
#define y1 y1_423
#define list lista

using namespace std;

typedef long long ll;
typedef long double ld;

template<typename T>
ostream& operator << (ostream& cout, const vector<T> &a) {
	if ((int)a.size() == 0) {
		return (cout << "()");
	}
	cout << "(" << a[0];
	for (int i = 1; i < (int)a.size(); i++) {
		cout << "; " << a[i];
	}
	return (cout << ")");
}

template<typename T>
ostream& operator << (ostream& cout, const set<T> &a) {
	if ((int)a.size() == 0) {
		return (cout << "{}");
	}
	auto it = a.begin();
	cout << "{" << *it;
	++it;
	for (; it != a.end(); ++it) {
		cout << "; " << *it;
	}
	return (cout << "}");
}

template<typename T>
ostream& operator << (ostream& cout, const multiset<T> &a) {
	if ((int)a.size() == 0) {
		return (cout << "{}");
	}
	auto it = a.begin();
	cout << "{" << *it;
	++it;
	for (; it != a.end(); ++it) {
		cout << "; " << *it;
	}
	return (cout << "}");
}

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

random_device gen;
mt19937 rnd(gen());

const int nmax = 2000 * 1000;
const int inf = 2000 * 1000 * 1000;
const ll infl = 1000ll * 1000ll * 1000ll * 1000ll * 1000ll * 1000ll;
const int mod = 1000 * 1000 * 1000 + 7;
const ld pi = acos(-1.0);

int n, a[nmax];
vector<int> answer;

int main() {
	//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
	//freopen(NAME".in", "r", stdin);freopen(NAME".out", "w", stdout);
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
	}
	int ans = 1;
	answer.pb(a[0]);
	for (int i = 1; i < n; i++) {
		if (answer.size() >= 2) {
			if (answer.back() <= answer[0] && a[i] <= answer.back()) {
				answer.pb(a[i]);
			} else if (answer.back() >= answer[0] && a[i] >= answer.back()) {
				answer.pb(a[i]);
			} else {
				answer.clear();
				answer.pb(a[i]);
				ans++;
			}
		} else {
			answer.pb(a[i]);
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1276
var
  x,y:array[0..100000]of char;
  ans:int64;
  i,n,m:longint;
Function gcd(x,y:longint):int64;
begin
  if y=0 then exit(x) else
  exit(gcd(y,x mod y));
end;
begin
  readln(n,m);
  for i:=1 to n do
    read(x[i]);
  readln;
  for i:=1 to m do
    read(y[i]);
  for i:=0 to n-1 do
    if i*m mod n=0 then
      if x[i+1]<>y[i*m div n+1] then
        begin
          write(-1);
          exit;
        end;
  ans:=n*m div gcd(n,m);
  write(ans);
end.

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define dfor(i,a,b) for(ll i=(a);i>=(b);i--)
#define mem(u, vis) memset(u, vis, sizeof(u))
#define ll long long
#define ull unsigned long long
#define MOD  1000000007
#define MAX  1e9
#define pb   push_back
#define F    first
#define S    second

signed main(){
	ll t = 1;
	// cin>>t;
	while(t--){
		ll n;
		double d;
		cin>>n>>d;
		ll c = 0;
		rep(i,n){
			ll x, y;
			cin>>x>>y;
			double ans = sqrt(1.0*x*x + 1.0*y*y);
			// cout<<ans<<endl;
			if(ans <= d) c++;

		}
		cout<<c;
	}
}

Measured memory_bytes: 3772
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<functional>

using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);

	char input[200001];

	scanf("%s", input);

	string str = input;

	int tot = 0;

	for (int i = 0; i < str.size(); i++)
	{
		tot = (tot + str[i] - '0') % 9;
	}

	if (tot)
	{
		printf("No\n");
	}

	else
	{
		printf("Yes\n");
	}

	return 0;
}

Measured memory_bytes: 3404
from itertools import combinations
N = int(input())
L = list(map(int, input().split()))
c = combinations(L, 3)

ans = 0
for v in c:
    a = v[0]
    b = v[1]
    c = v[2]
    if a != b and b != c and a != c:
        s = sum(v)
        m = max(a, b, c)
        if s > 2 * m:
            ans += 1
print(ans)


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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

vector<vector<ll>> places(2, vector<ll>());
ll min_val;

void dfs(int idx, ll place, ll total){
    auto near_place = lower_bound(all(places[idx]), place);
    int front_idx = max(0, (int)(near_place - places[idx].begin()) - 1);
    int back_idx = (int)(near_place - places[idx].begin());

    if(total == 0){
        total = abs(place - places[idx][front_idx]);
        dfs(1 - idx, places[idx][front_idx], total);
        total = abs(place - places[idx][back_idx]);
        dfs(1 - idx, places[idx][back_idx], total);
    }else{
        min_val = min(min_val, total + min(abs(place - places[idx][front_idx]), abs(place - places[idx][back_idx])));
    }
}

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

    int a_b[2], q;
    cin >> a_b[0] >> a_b[1] >> q;

    rep(idx, 2){
        places[idx].emplace_back(-1e12);
        rep(i, a_b[idx]){
            ll a;
            cin >> a;
            places[idx].emplace_back(a);
        }
        places[idx].emplace_back(1e12);
    }

    rep(i, q){
        ll place;
        cin >> place;

        min_val = 1e12;
        dfs(0, place, 0);
        dfs(1, place, 0);

        cout << min_val << endl;
    }
}

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
	int n,m,l;
	cin>>n>>m>>l;
	long long a[n][m],b[m][l],ans[n][l] = {};
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<l;j++){
			cin>>b[i][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<l;j++){
			for(int k=0;k<m;k++){
				ans[i][j]+=a[i][k]*b[k][j];
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<l-1;j++){
			cout<<ans[i][j]<<" ";
		}
		cout<<ans[i][l-1]<<endl;
	}
}


Measured memory_bytes: 3340
#ifndef __cplusplus
    cat << EOF
#endif
#include <bits/stdc++.h>
using namespace std;

#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if(lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if(lhs > rhs) { lhs = rhs; return 1; } return 0; }

typedef long long lint;

int N;
int val[16][16];
long long dp[1 << 16];

int main() {

    cin >> N;
    rep(i, N) rep(j, N) cin >> val[i][j];

    rep(S, 1 << N) {
        rep(i, N) rep(j, i) {
            if(((1 << i) & S) > 0 && ((1 << j) & S) > 0) {
                dp[S] += val[i][j];
            }
        }
    }

    rep(S, 1 << N) {
        vector<int> elements;
        rep(i, N) if(!((1 << i) & S)) elements.emplace_back(1 << i);
        int size = elements.size();
        rep(i, 1 << size) {
            int T = 0;
            rep(j, size) if((1 << j) & i) T |= elements[j];
            chmax(dp[S | T], dp[S] + dp[T]);
        }
    }

    cout << dp[(1 << N) - 1] << '\n';
    return 0;

}


Measured memory_bytes: 768
#include<iostream>

using namespace std;

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

	while(1){
		bool judge = false;
		for(int i=0; i<n; i++){
			if(a[i] % 2 != 0)
				judge = true;
		}
		if(judge) //trueのとき
			break;

		for(int i=0; i<n; i++){
			a[i] /= 2;
		}
		count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MM=1013;
const int P=1000000007;
char T[MM][MM];
long long wyn[MM][MM];
long long DD(long long a, long long b)
{
    return (a+b>=P?a+b-P:a+b);
}
int main()
{
    ios_base::sync_with_stdio(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)   T[i][0]='#';
    for(int j=1;j<=m;j++)   T[0][j]='#';
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>T[i][j];
        }
    }
    wyn[1][1]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(T[i][j]!='#')
            {
                wyn[i][j]=DD(wyn[i][j],wyn[i-1][j]);
                wyn[i][j]=DD(wyn[i][j],wyn[i][j-1]);
            }
        }
    }
    cout<<wyn[n][m]<<endl;
    return 0;
}


Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 303+5;
void solve(){
	int n; 
	cin>>n;
	int ans = 0;
	int mx = 0;
	int lst = -2e9; 
	for(int i=1;i<=n;i++){
		int x; 
		cin>>x; 
		if(x<=lst)mx++;
		else mx = 0;
		ans = max(ans,mx);
		lst = x;
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()



int main() {
    int A,B;
    cin >> A >> B;

    if(A<6){
        cout << 0 << endl;
        return 0;
    }else if(A<13){
        cout << B/2 << endl;
        return 0;
    }else{
        cout << B << endl;
        return 0;
    }

}



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

namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                
                var st = Console.ReadLine()
                    .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                    .Select(x => int.Parse(x))
                    .ToArray();
                int n = st[0];
                int m = st[1];
                if (n + m == 0)
                    break;
                var ls = new List<KeyValuePair<int, int>>();
                for (int i = 0; i < n; i++)
                {
                    var x = Console.ReadLine().Split(' ');
                    var d = int.Parse(x[0]);
                    var p = int.Parse(x[1]);

                    var unko = ls.FirstOrDefault(y => y.Value == p);
                    if (unko.Key != 0 && unko.Value != 0)
                    {
                        var a = ls.FindIndex(z => { return z.Key == unko.Key && z.Value == unko.Value; });
                        unko = new KeyValuePair<int, int>(unko.Key + d, p);

                        if (a < 0)
                            continue;
                        ls[a]
                            = unko;
                    }
                    else
                    {
                        ls.Add(new KeyValuePair<int, int>(d, p));
                    }
                }
                
                ls = ls.OrderByDescending(x => x.Value).ToList();
                var oldls = ls.ToList();
                foreach (var item in oldls)
                {
                    if (m == 0)
                        break;
                    var ind = oldls.FindIndex(x => { return x.Value == item.Value && x.Key == item.Key; });
                    var l = ls[ind];

                    if (m-item.Key <= 0)
                    {
                        ls[ind] = new KeyValuePair<int, int>(l.Key - m,l.Value);
                        m = 0;
                    }
                    else
                    {
                        m = m - ls[ind].Key;
                        ls[ind] = new KeyValuePair<int, int>(0, l.Value);
                    }
                }
                var ans = 0;
                foreach (var item in ls)
                {
                    ans += item.Key * item.Value;
                }
                Console.WriteLine(ans);
            }
        }
        
    }

}


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

int main(){
    int S[30] = {0};
    char temp;
    for(int i = 0; cin >> temp; ++i){
        ++S[temp - 'a'];
        if(S[temp-'a'] > 1){
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}


Measured memory_bytes: 256
N,D = map(int,input().split())
X = [list(map(int,input().split())) for i in range(N)]

ans = 0

for i in range(N):
    for j in range(i):
        d = 0
        for k in range(D):
            d += (X[i][k]-X[j][k])**2
        dsqrt = d**0.5
        if dsqrt == dsqrt//1:
            ans += 1 
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll=long long;
int main(){
  int n;cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  map<int,int> x;
  ll ans=0;
  rep(i,n){
    int m=i-a[i];
    ans+=x[m];
    int s=a[i]+i;
    x[s]++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 20988
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
typedef vector<int> vi;
const int MAX=1e5+5;
const lli INF=1e18;

struct edge{int to; lli cost;};
vector<edge> G[MAX];
lli co[MAX];

int main(){
	int N,Q,K;
	cin>>N;
	rep(i,N-1){
		int a,b;lli c;
		cin>>a>>b>>c;
		edge e1={b,c}, e2={a,c};
		G[a].push_back(e1);
		G[b].push_back(e2);
	}
	cin>>Q>>K;
	
//	rep1(i,N)co[i]=INF;
//	co[K]=0;
	queue<int> q;
	q.push(K);
	while(!q.empty()){
		int v=q.front();q.pop();
		for(int i=0; i<G[v].size() ; i++){
			edge e=G[v][i];
			int u=e.to ; lli c=e.cost;
			if(co[u]!=0)continue;
			co[u]=co[v]+c;
			q.push(u);
		}
	}
	rep(i,Q){
		int x,y;
		cin>>x>>y;
		cout<<co[x]+co[y]<<endl;
	}
}

Measured memory_bytes: 9984
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		if (A == B)
			System.out.println(C);
		else if (A == C)
			System.out.println(B);
		else
			System.out.println(A);

	}
}


Measured memory_bytes: 22740
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 10000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	s := readLine()

	fmt.Println(math.Min(float64(strings.Count(s, "1")), float64(strings.Count(s, "0"))) * 2)
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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 (b<a) { a=b; return 1; } return 0; }

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int k, n;
	cin >> k >> n;
	vi a(n);
	rep(i, n) cin >> a[i];

	priority_queue<int> pq;
	rep(i, n-1){
		pq.push(a[i+1] - a[i]);
	}
	pq.push(k - a.back() + a.front());
	pq.pop();
	ll ans = 0;
	while (!pq.empty())
	{
		cerr << pq.top() << endl;
		ans += pq.top();
		pq.pop();
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

string convert(int n)
{
	if(n==0) return "0";
	string res;
	for(int i=n;i;i/=4)
		res+='0'+i%4;
	reverse(allof(res));
	return res;
}

int main()
{
	for(int n;cin>>n,~n;)
		cout<<convert(n)<<endl;
	
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n, x;
	cin >> n >> x;
	vector<int> l(n);
	rep (i, n) cin >> l[i];
	int pos = 0;
	int res = 1;
	rep (i, n) {
	  pos = pos + l[i];
	  if (pos <= x) res++;
	}
    cout << res << endl;
	
    return 0;
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll r;
int main() {
    cin>>r;
    cout<<r*r<<endl;
    return 0;
}

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

typedef pair<int,int> P;

int main ()
{
    int m, n;
    while (cin >> n >> m, (n || m)) {
        map<string,P> v;
        for (int i = 0; i < n; i++) {
            string str;
            int s, e;
            cin >> str >> s >> e;
            v[str] = P(s,e);
        }

        for (int i = 0; i < m; i++) {
            int y;
            cin >> y;

            bool flag = true;
            for (auto i : v) {
                if (i.second.second - i.second.first < y && y <= i.second.second) {
                    cout << i.first << " " << y - i.second.second + i.second.first << endl;
                    flag = false;
                    break;
                }
            }
            if (flag) cout << "Unknown" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1336
#include <iostream>
#define some 1000000000000000000
using std::cin;
using std::cout;

int main(){
  int n;
  bool containzero = false;
  long long a[100007];
  cin >> n;
  for (int i = 0;i <n;i++){
    cin >> a[i];
    if(!containzero&&a[i] == 0){
      containzero = true;
    }
  }
  if(containzero){
    cout << 0 << '\n';
    return 0;
  }
  long long ans = 1;
  for (int i = 0;i<n;i++){
    if (a[i] <= some / ans){
      ans *= a[i];
    }else{
      cout << -1 << '\n';
      return 0;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4412
#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
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define P pair<ll, ll>
#define V vector<ll>
#define C vector<char>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007
#define rep(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)


int power(ll x, unsigned int y)  
{  
	ll p=mod;
    ll res = 1;      
  
    x = x % p; 
               
   
    if (x == 0) return 0; 
  
    while (y > 0)  
    {  
       
        if (y & 1)  
            res = (res*x) % p;  
  
       
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}  

int main()
{
	int n,p,l;
	cin>>n>>p>>l;

	int d[n+1][n+1];
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n;j++)
			d[i][j]=mod;

	for(int i=0;i<p;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		d[a][b]=c;
		d[b][a]=c;

	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int k=1;k<=n;k++)
			{
				d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
			}
		}
	}
	int m[n+1][n+1];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(d[i][j]<=l)m[i][j]=1;
			else
				m[i][j]=mod;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int k=1;k<=n;k++)
			{
				m[j][k]=min(m[j][k],m[j][i]+m[i][k]);


			}
		}
	}
	int q;
	cin>>q;
	while(q--)
	{
		int a1,b1;
		cin>>a1>>b1;
		if(m[a1][b1]!=mod)cout<<m[a1][b1]-1<<endl;
		else
			cout<<"-1"<<endl;
	}


}


Measured memory_bytes: 1280
#include <stdio.h>
int main()
{
    int i,H,N,A[100010],sum=0;
    scanf("%d%d",&H,&N);
    for(i=1;i<=N;i++)
    {
        scanf("%d",&A[i]);
        sum+=A[i];
    }
    if(sum>=H)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <utility>
#include <iomanip>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int 
#define endl "\n" 

int32_t main()
{

   /*  IOS 
     #ifndef ONLINE_JUDGE 
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
     #endif*/
     int n ;
     cin >> n ;
     long double ans = 0 , num ;
     string s1 ;
     for(int i = 0 ; i <  n ;i ++ )
     {
       cin >> num >> s1 ;
       if(s1 == "BTC")
       {
         ans+= 380000.0*num ;
       }
       else ans += num; 
     }
     cout<<setprecision(12)<<fixed<<ans<<endl;
    return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	//int ans=0;
	cin >>n;
	V ans(n+2,0LL);
	for(int a=1;a<sqrt(n);a++){
		for (int b = 1; b < sqrt(n); b++)
		{
			for (int c = 1; c < sqrt(n); c++)
			{
				ans[min(n+1,a*a+b*b+c*c+a*b+a*c+b*c)]++;
			}
		}
		
	}
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<endl;
	}
}

Measured memory_bytes: 3664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	int N = rei();
	long ans = 0;
	int BA = 0;
	int A = 0;
	int B = 0;
	for(int j=0;j<N;j++){
		string S = res();
		for(int i=0;i<S.length()-1;i++){
			if(S[i] == 'A' && S[i+1] == 'B'){
				ans++;
			}
		}
		if(S[0] == 'B' && S[S.length()-1] == 'A'){
			BA++;
		}
		else if(S[0] == 'B'){
			B++;
		}
		else if(S[S.length()-1] == 'A'){
			A++;
		}
	}
	if(A == 0 && B == 0){
		ans += max(BA-1,0);
	}
	else{
		ans += BA + min(A,B);
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
long long a,b,c,x,y,s=0x7fffffff,i,j;
int main(){
	cin>>a>>b>>c>>x>>y;
	for (i=0;i<=max(x,y);i++){
		s=min(s,i*c*2+max(0ll,x-i)*a+max(0ll,y-i)*b);
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i

n.times do
  stack = gets.chomp.split(/(<\-|\->)/)
  answer = []
  cursor = 0

  stack.each do |str|
    if str !~ /<-|->/
      unless answer.index(str)
        answer.insert(cursor, str)
      end
    else
      if str =~ /->/
        cursor += 1
      else
        cursor -= 1
      end

      cursor = 0 if cursor < 0
    end
  end

  puts answer.join
end

Measured memory_bytes: 9892
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double db;
typedef vector<ll> VI;
typedef vector<pair<ll,ll> > VII;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
//
#define M 1000000007
#define INF (ll)0x3f3f3f3f3f3f3f3f
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define itr iterator
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}

void error_out() { cerr << endl; }
template <typename Head, typename... Tail>
void error_out(Head H, Tail... T) {
  cerr << " " << H;
  error_out(T...);
}
void time_elapsed(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}
#ifndef ONLINE_JUDGE
#define error(...) cerr << "[" << #__VA_ARGS__ << "]:", error_out(__VA_ARGS__)
#define fioe() fileioe()
#define time() time_elapsed()
#else
#define error(...) 1
#define fioe() 1
#define time() 1
#endif


//
int main()
{
	GO
	//fioe();
	ll n,k;
	cin>>n>>k;
	ll arr[n+3];
	for(ll i=0;i<n;i++){
		cin>>arr[i];
	}
	ll dp[n+2];
	for(ll i=0;i<=n+1;i++){
		dp[i]=INF;
	}
	dp[0]=dp[1]=0;
	dp[2]=abs(arr[0]-arr[1]);
	for(ll i=3;i<=n;i++){
		for(ll j=i-1;j>=max(i-k,(ll)0);j--){
			dp[i]=min(dp[j]+abs(arr[j-1]-arr[i-1]),dp[i]);
		}
	}
	cout<<dp[n]<<endl;
	time();
	return 0;
}

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

int main() {
  string s,t;
  cin>>s>>t;
  int sn=s.size();
  int tn=t.size();
  map<string,int>mp;
  string kotae;
  if(sn<tn){
    cout<<"UNRESTORABLE"<<endl;
    return 0;
  }
  for(int i=0;i<sn-tn+1;i++){
    bool hantei=true;
    for(int j=0;j<tn;j++){
      if(s[i+j]==t[j]||s[i+j]=='?')continue;
      else {
        hantei=false;
        break;
      }
    }
    if(hantei){
      //cout<<"i"<<i<<endl;
      for(int k=0;k<i;k++){
        if(s[k]=='?')kotae.push_back('a');
        else kotae.push_back(s[k]);
      }
      for(int k=0;k<tn;k++){
        kotae.push_back(t[k]);
      }
      if(i+tn<sn){
        for(int k=i+tn;k<sn;k++){
          if(s[k]=='?')kotae.push_back('a');
          else kotae.push_back(s[k]);
        }
      }
      mp[kotae]++;
      kotae.clear();
    }
  }
  if(mp.size()>0){
    auto begin=mp.begin(),end=mp.end();
    for(auto iter=begin;iter!=end;iter++){
      string a=iter->first;
      cout<<a<<endl;
      return 0;
    }
  }else{
    cout<<"UNRESTORABLE"<<endl;
  }
  return 0;
}




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

int main()
{   
	int n;
	cin>>n;
	double ans = 1;
	long long res = 1;
	long long limit = 1e18;
	bool ok = 1;
	long long a[n];
	for (int i=0; i<n; i++){
		cin>>a[i];
	}
	for (int i=0; i<n; i++){
		ok &= (a[i]>0);
	}
	if (ok){
		for (int i=0; i<n; i++){
			ans = ans*a[i];
			res = res*a[i];
			if ((res>limit and ans==1e18) or ans>1e18) {
				ok = 0;
				break;
			}
		}
		if (ok) cout<<res<<endl;
		else cout<<-1<<endl;
	}
	else{
		cout<<0<<endl;
	}
	
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    int N,M;
    cin>>N>>M;
    int a;
    priority_queue<int> q;
    rep(i,N){
        cin>>a;
        q.push(a);
    }
    rep(i,M){
        int a=q.top();
        q.pop();
        a/=2;
        q.push(a);
    }
    ll ans=0;
    while(!q.empty()){
        a=q.top();
        q.pop();
        ans+=a;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3920
/*
  AtCoder Regular Contest 095
  C - Many Medians
*/

#include<iostream>
#include<algorithm>
using namespace std;

int N;
int X[200000];
int sortedX[200000];

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &X[i]);
    sortedX[i] = X[i];
  }
  sort(sortedX, sortedX+N);

  int before_med = sortedX[N/2-1], after_med = sortedX[N/2];
  if (before_med == after_med) {
    for (int i = 0; i < N; ++i) printf("%d\n", before_med);
  }
  else {
    for (int i = 0; i < N; ++i) {
      if (X[i] < after_med) printf("%d\n", after_med);
      else printf("%d\n", before_med);
    }
  }
  return 0;
}

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

void solve(long long K, long long N, std::vector<long long> A){
    vector<ll> B(2*N);

    for (int i = 0; i < N; i++)
    {
        B[i] = A[i];
        B[i+N] = A[i]+K;
    }
    ll ans = 100000000;
    for (int i = 0; i < N; i++)
    {
        ans = min(ans,B[i+N-1]-B[i]);
    }
    cout << ans << endl;
    
    
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(K, N, std::move(A));
    return 0;
}


Measured memory_bytes: 4992
def main():
    from itertools import permutations

    n, m, r, *x = map(int, open(0).read().split())
    to = x[:r]

    dis = [[0 if i == j else float("Inf") for j in range(n + 1)] for i in range(n + 1)]

    for a, b, c in zip(*[iter(x[r:])] * 3):
        dis[a][b] = c
        dis[b][a] = c

    for k in range(1, n + 1):
        for i in range(1, n + 1):
            for j in range(1, n + 1):
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j])

    ans = float("Inf")
    for p in permutations(to):
        tmp = 0
        nw = p[0]
        for nx in p[1:]:
            tmp += dis[nw][nx]
            nw = nx

        ans = min(ans, tmp)

    print(ans)


if __name__ == '__main__':
    main()


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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100100;

VI g[MAX];

int U[MAX];
int C[MAX];

int sz;

bool dfs(int x, int c)
{
	U[x] = true;

	C[x] = c;

	int res = false;
	sz++;

	FOR (i, 0, SZ(g[x]))
	{
		int to = g[x][i];
		if (U[to])
		{
			if (C[to] == C[x]) res = true;
		}
		else
		{
			if (dfs(to, c ^ 1)) res = true;
		}
	}

	return res;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n, m;
	scanf("%d%d", &n, &m);
	FOR (i, 0, m)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		y--;

		g[x].PB(y);
		g[y].PB(x);
	}

	LL c1 = 0;
	LL c[2] = {0, 0};

	FOR (i, 0, n)
	{
		if (!U[i])
		{
			sz = 0;
			int r = dfs(i, 0);

			if (sz == 1) c1++;
			else c[r]++;
		}
	}

	LL res = 0;
	res += c1 * c1;


	res += (n-c1) * c1 * 2;

	res += c[1] * c[1];
	res += c[1] * c[0] * 2;
	res += c[0] * c[0] * 2;

	cout<<res<<endl;

}


Measured memory_bytes: 12160
import fractions
import collections
d = collections.defaultdict(int)
n = int(input())
res = 0
for i in range(1, n + 1):
    for j in range(1, n + 1):
        #print(i, j)
        x = fractions.gcd(i, j)
        d[x] += 1
res = 0
#print(d)
for k in d:
    for i in range(1, n + 1):
        #print("gdc:", k, i , "=", fractions.gcd(k, i))
        x = fractions.gcd(k, i)
        res += x * d[k]
print(res)



Measured memory_bytes: 76072
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	static void Main(){
		long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
		long m=1,ans=0;
		List<long> li=new List<long>();
		li.Add(s[1]);
		while(m<=s[1]){m*=2;}
		if(s[1]!=m-1){
			m/=2;
			li.Add(m-1);
			for(long i=m/2;i>=2;i>>=1){
				if((s[1]&i)>0){li.Add(((s[1]-i)&(~(i-1)))+i-1);}
			}
		}
		long[,] dp=new long[s[0]+1,li.Count];
		for(int i=1;i<=s[0];i++){
			long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
			for(int j=0;j<li.Count;j++){
				dp[i,j]=dp[i-1,j];
				if((q[0]&li[j])==q[0]){dp[i,j]+=q[1];}
			}
		}
		for(int j=0;j<li.Count;j++){ans=Math.Max(ans,dp[s[0],j]);}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 29896
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;
int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    map<int, int> mp;
    ll ans = 0;
    for (int i = 0; i<n; ++i) {
        ans += (ll)mp[i-a[i]];
        ++mp[a[i]+i];
    }
    cout << ans << endl;
    return 0;
}


















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

using std::pair;
using std::vector;
using std::string;

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

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 100000;

struct node {
    ll d;
    int id; 

    bool operator < (const node& rhs) const {
        return d > rhs.d;
    }
};

int n;
node t[N + 5];
int fa[N + 5], sz[N + 5];
std::map <ll, int> mp;

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(n);
    for(int i = 1; i <= n; ++i) {
        read(t[i].d), t[i].id = i;
    }

    std::sort(t + 1, t + n + 1);

    for(int i = 1; i <= n; ++i) mp[t[i].d] = i;
    for(int i = 1; i < n; ++i) {
        ++ sz[i];
        fa[i] = mp[t[i].d - n + 2 * sz[i]];
        if(!fa[i]) return !puts("-1");
        sz[fa[i]] += sz[i];
        t[n].d -= sz[i];
    }

    if(t[n].d) return !puts("-1");

    for(int i = 1; i < n; ++i) {
        printf("%d %d\n", t[i].id, t[fa[i]].id);
    }

    return 0;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    map<int, int> counter;
    int N, M;
    bool result = true;
    cin >> N;
    while (N--) {
        int D; cin >> D;
        counter[D]++;
    }
    cin >> M;
    while (M--) {
        int T; cin >> T;
        if (counter[T] == 0) {
            result = false;
            goto OUT;
        }
        counter[T]--;
    }
OUT:
    cout << (result ? "YES\n" : "NO\n");
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct CITY{
	int P;
	int Y;
	int idx;
	char num[12];
};
bool cmp1(const CITY &a, const CITY &b){
	return a.Y < b.Y;
}
bool cmp2(const CITY &a, const CITY &b){
	return a.idx < b.idx;
}
int main(){
	int N, M; cin >> N >> M;
	vector<CITY> city(M);
	int Pref[N+1];
	for(int i = 0; i < N+1; i++) Pref[i] = 0;
	for(int i = 0; i < M; i++){
		cin >> city[i].P >> city[i].Y;
		city[i].idx = i;
	}
	sort(city.begin(), city.end(), cmp1);
	int p, r;
	for(int i = 0; i < M; i++){
		Pref[city[i].P]++;
		for(int j = 0; j < 12; j++) city[i].num[j] = '0';
		p = city[i].P;
		r = Pref[city[i].P];
		for(int j = 0; j < 6; j++){
			city[i].num[5-j] += (p % 10);
			p /= 10;
		}
		for(int j = 0; j < 6; j++){
			city[i].num[11-j] += (r % 10);
			r /= 10;
		}
	}
	sort(city.begin(), city.end(), cmp2);
	for(int i = 0; i < M; i++){
		for(int j = 0; j < 12; j++) cout << city[i].num[j];
		cout << endl;
	}
	
}


Measured memory_bytes: 4224
package main

import (
	"fmt"
	"math"
)

func main() {
	var a,b int
	fmt.Scanf("%d %d", &a,&b)
	//var s string
	//fmt.Scanf("%s", &s)
	n1 := float64(a+b)
	n2 := float64(a-b)
	n3 := float64(a*b)
	fmt.Println(int(math.Max(n1,math.Max(n2,n3))))
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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 (b<a) { a=b; return 1; } return 0; }
typedef pair<int,int> P;

vector<int> to[100005];
vector<int> d(100005);
int dfs(int v) {
  if(d[v]!=-1)return d[v];
  d[v]=0;
  for (int u : to[v]) {
    chmax(d[v],dfs(u)+1);
  }
  return d[v];
}

int main() {
  int n, m;
  cin >> n >> m;
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
  }
  int ans = 0;
  rep(i,n)d[i]=-1;
  rep(i,n)chmax(ans,dfs(i));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7424
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def comb(n, r):
    if n - r < r:
        r = n - r
    res = 1
    for i in range(r):
        res *= (n - i) % mod
        res %= mod
        res *= pow(r - i, mod - 2, mod)
        res %= mod
    return res


n, r = inpl()
print(r + 100 * (10 - min(n, 10)))


Measured memory_bytes: 38512
#include <stdio.h>
#include <math.h>

using namespace std;

int main(void) {
	int a,b,sum;
	
	while(scanf("%d%d",&a,&b)!=EOF){
		int ans;
		ans = (int)log10((double)(a+b))+1;
		printf("%d\n",ans);
	}
	
	return 0;
}

Measured memory_bytes: 1072