akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
	char * a = new char[1000];
	char * b = new char[1000];

	cin >> a;
	cin >> b;

	int p_a = 0;
	int p_b = 0;
	int p_c = 1;
	char *c = new char[1000];

	while(p_c<1000){
		if(p_c%2==1) {
			c[p_c] = a[p_a];
			p_a++;
		}
		else {
			c[p_c] = b[p_b];
			p_b++;
		}
		p_c++;
	}
	int t = 1;
	while(c[t] != '\0'){
		cout << c[t++];
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define N_MAX 40
#define NIL -1

struct Node{int p, l, r;}; //parent, left, right

Node T[N_MAX];
int pre[N_MAX], in[N_MAX];
int pre_idx = 0;
int shit_counter = 0;

void rec(int parent, int l, int r);
void preorder_treeWalk(int v);
void inorder_treeWalk(int v);
void postorder_treeWalk(int v);

//??¨??????????????????index??¨????????????????????¨????????????????????????????????§????°?????????´????????????

int main()
{
    int n, i;
    cin >> n;

    //input preorder_treeWalk, inorder_treeWalk
    for (i = 0; i < n; i++) cin >> pre[i];
    for (i = 0; i < n; i++) cin >> in[i];

    //??¨????????????
    for (i = 0; i < n; i++)
        T[i].p = T[i].r = T[i].l = NIL;

    //??¨???????§????
    rec(-1, 0, n-1);

    /*
    cout << "tree aray dump [Complete]" << endl;
    for (i = 0; i < 5; i++) {
        cout << i << " (v=" << i+1 << ") " << T[i].p << ", " << T[i].l << ", " << T[i].r << endl;
    }
    */

    //??¨?????????
    /*
    cout << "Preorder" << endl;
    preorder_treeWalk(pre[0]);
    cout << endl;

    cout << "Inorder" << endl;
    inorder_treeWalk(pre[0]);
    cout << endl;
    */
//    cout << "Postorder" << endl;
    postorder_treeWalk(pre[0]);
    cout << endl;

    return 0;
}

//inorder???????????????l????????????r?????§?????¨?????¨???????§?????????????
void rec(int parent, int l, int r) {
    int i, p, in_idx, parent_in_idx;

    /*
    cout << "pre_idx = " << pre_idx << ", rec " << l << ", " << r << endl;
    cout << "tree aray dump" << endl;
    for (i = 0; i < 5; i++) {
        cout << i << " (v=" << i+1 << ") " << T[i].p << ", " << T[i].l << ", " << T[i].r << endl;
    }
    */

    p = pre[pre_idx];

    in_idx = 0;
    while (in[in_idx] != p) in_idx++;

    //???????????¨????????????
    if (parent == -1) {
        T[p - 1].p = -1;
    } else {
        T[p - 1].p = parent;

        //???????????????????????????????????????????????????
        parent_in_idx = 0;
        while (in[parent_in_idx] != parent) parent_in_idx++;

        if (in_idx < parent_in_idx)
            T[parent - 1].l = p;
        else
            T[parent - 1].r = p;
    }

    pre_idx++;

    //??¨?????¨???????????¨??????????????´??????????????????
    if (l == r) {
        return;
    }

    if (l < in_idx)
        rec(p, l, in_idx - 1); //p????????¨?????¨???????§??????????.
    if (in_idx < r)
        rec(p, in_idx + 1, r); //p????????¨?????¨???????§??????????.
}

//root????????????
void preorder_treeWalk(int v) {
    cout << " " << v;

    if (T[v - 1].l == NIL && T[v - 1].r == NIL) return;
    if (T[v - 1].l != NIL)
        preorder_treeWalk(T[v - 1].l);
    if (T[v - 1].r != NIL)
        preorder_treeWalk(T[v - 1].r);
}

void inorder_treeWalk(int v) {
    if (T[v - 1].l != NIL) inorder_treeWalk(T[v - 1].l);
    cout << " " << v;
    if (T[v - 1].r != NIL) inorder_treeWalk(T[v - 1].r);
}

void postorder_treeWalk(int v) {
    if (T[v - 1].l != NIL) postorder_treeWalk(T[v - 1].l);
    if (T[v - 1].r != NIL) postorder_treeWalk(T[v - 1].r);

    if (shit_counter == 0) {
        cout << v;
        shit_counter++;
    } else {
        cout << " " << v;
    }
}

Measured memory_bytes: 3108
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template <class T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
	for (const auto& e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& st) {
	for (const auto& e : st) os << e << " ";
	return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const map<T1, T2>& mp) {
	for (const auto& e : mp) os << e << " ";
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T&& h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head&& h, Tail&&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, K, R, S, P;
	string T;
	cin >> N >> K >> R >> S >> P >> T;

	vector<vector<Int>> dp(N+1, vector<Int>(3));

	for (Int i = 0; i < K; i++) {
		if (T[i] == 's') {
			dp[i+1][0] = R;
		}
		else if (T[i] == 'r') {
			dp[i+1][2] = P;
		}
		else {
			dp[i+1][1] = S;
		}
	}

	for (Int i = 0; i < K; i++) {
		Int temp = K;
		while (temp+i+1<=N) {
			//グーを出す場合
			if (T[i+temp]=='s') {
				dp[i + temp + 1][0] = max(dp[i + (temp - K) + 1][1] + R, dp[i + (temp - K) + 1][2] + R);
			}
			else  {
				dp[i + temp + 1][0] = max(dp[i + (temp - K) + 1][1], dp[i + (temp - K) + 1][2]);

			}

			//チョキを出す場合
			if (T[i+temp]=='p') {
				dp[i + temp + 1][1] = max(dp[i + (temp - K) + 1][0] + S, dp[i + (temp - K) + 1][2] + S);

			}
			else {
				dp[i + temp + 1][1] = max(dp[i + (temp - K) + 1][0] , dp[i + (temp - K) + 1][2] );

			}

			//パーを出す場合
			if (T[i+temp]=='r') {
				dp[i + temp + 1][2] = max(dp[i + (temp - K) + 1][0] + P, dp[i + (temp - K) + 1][1] + P);

			}
			else {

				dp[i + temp + 1][2] = max(dp[i + (temp - K) + 1][0], dp[i + (temp - K) + 1][1]);

			}

			temp += K;
		}
	}

	DMP(dp);

	Int ans = 0;
	for (Int i = N; i >= N-K+1; i--) {
		ans += max({ dp[i][0],dp[i][1],dp[i][2] });
	}
	cout << ans << "\n";
}


Measured memory_bytes: 5840
#include<bits/stdc++.h>
using namespace std;
#define mod (int)(1e9+7)
typedef long long ll;
ll min(ll a,ll b,ll c){
	return min(min(a,b),c);
}
ll max(ll a,ll b,ll c){
	return max(max(a,b),c);
}


int main(){
	ll h,w,ans=(1<<30);
	cin>>h>>w;
	for(ll i=max(1,h*w/3/w,0);i<=h;i++){
		ll l=min(w,h*w/3/i);
		if(i==h){
			ll a=i*l,b=h/2*(w-l),c=(h/2+(h&1))*(w-l);
			ans=min(ans,max(a,b,c)-min(a,b,c));
			b=(w-l)/2*h,c=((w-l)/2+((w-l)&1))*h;
			ans=min(ans,max(a,b,c)-min(a,b,c));
			continue;
		}
		if(l==w){
			ll a=i*l,b=w/2*(h-i),c=(w/2+(w&1))*(h-i);
			ans=min(ans,max(a,b,c)-min(a,b,c));
			b=(h-i)/2*w,c=((h-i)/2+((h-i)&1))*w;
			ans=min(ans,max(a,b,c)-min(a,b,c));
			continue;
		}
		ll a=l*i,b=i*(w-l),c=w*(h-i);
		ans=min(ans,max(a,b,c)-min(a,b,c));
		b=h*(w-l),c=l*(h-i);
		ans=min(ans,max(a,b,c)-min(a,b,c));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
//by szh
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define fi first
#define SZ(x) (int((x).size()))
#define se second
#define ll long long
#define pq priority_queue
#define MP make_pair
#define pii pair<int,int>
#define mod 998244353
#define inf 0x3f3f3f3f
#define debug(x) cerr<<#x<<"="<<x<<'\n'
#define rep(i, a, b) for (int i=a; i<(b); i++)
 
const int maxn=1e6+10;
 
int n;
pii a[maxn];
 
bool cmp(pii x,pii y) {
	return (x.se>y.se||y.fi<0)&&(y.se-y.fi>x.se-x.fi||x.fi>0);
}
 
int main(){
    std::ios::sync_with_stdio(false);
    cin>>n;
    rep(i,0,n) {
    	string s;
    	cin>>s;
    	int mn=mod,val=0; 
    	rep(j,0,SZ(s)) {
    		if (s[j]=='(') val++;
    		else val--;
    		mn=min(val,mn);
		}
		a[i]=MP(val,mn);
	}
	sort(a,a+n,cmp);
	int sum=0;
	rep(i,0,n) {
		if (sum+a[i].se<0) {
			cout<<"No";
			return 0;
		}
		sum+=a[i].fi; 
	}
	if (sum==0) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 11368
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

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

    cout << fixed << setprecision(6);

    cout << a / b << " ";
    cout << a % b << " ";
    cout << (double) a / b << endl;
}

Measured memory_bytes: 1244
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner Input = new Scanner(System.in);
        String A = Input.next();
        String B = Input.next();
        int Count = 0;
        for (int I = Integer.parseInt(A); I <= Integer.parseInt(B); I++) {
            String J = I + "";
            if (J.charAt(0) == J.charAt(4) && J.charAt(1) == J.charAt(3)) {Count++;}}System.out.println(Count);}}

Measured memory_bytes: 32468
#include<iostream>
using namespace std;
int main(){
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    long long ans;
    if((a+b)>=c*2){
        if(x<y){
            if(b>2*c) ans=2*c*y;
            else ans=2*c*x+(y-x)*b;
        }
        else {
            if(a>2*c) ans=2*c*x;
            else ans=2*y*c+(x-y)*a;
        }
    }
    else ans=x*a+y*b;
    cout<<ans;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int x,y,work;
    
    
    while(1){
    scanf("%d%d",&x,&y);
    if(x>y){
        work=x;
        x=y;
        y=work;
    }
      if(x==0&&y==0){
        break;
    }    
    printf("%d %d\n",x,y);
        
    }
    return 0;
}


Measured memory_bytes: 2664
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    s = S()
    t = S()
    ans = ""
    flg = 1

    if len(t) > len(s):
        print("UNRESTORABLE")
        return

    for i in range(len(s) - len(t), -1, -1):
        flg = 1
        clipped = s[i:i+len(t)]
        for j in range(len(t)):
            if clipped[j] != t[j] and clipped[j] != "?":
                flg = 0
                break
        if flg:
            ans = s[:i].replace("?", "a") + t + \
                s[i + len(t):].replace("?", "a")
            break

    if not flg:
        print("UNRESTORABLE")
        return
    print(str(ans))


if __name__ == "__main__":
    main()


Measured memory_bytes: 69376
import sys
sys.setrecursionlimit(200000)
n=int(input())
x=input()

tab=[0]+[i%bin(i).count('1') for i in range(1,200001)]

xcnt=x.count("1")
staxp=0
staxm=0
pl=xcnt+1
mi=xcnt-1
if mi==0:
    mi=1
for i in range(n):
    if x[n-i-1]=="1":
        staxp=(staxp+pow(2,i,pl))%pl
        staxm=(staxm+pow(2,i,mi))%mi
    
def calc(x,now):
    if x==0:
        return now
    else:
        return calc(tab[x],now+1)

for i in range(n):
    if x[i]=="1":
        if xcnt==1:
            print(0)
        else:
            sta=(staxm-pow(2,n-i-1,mi))%mi
            print(1+calc(sta,0))
    else:
        sta=(staxp+pow(2,n-i-1,pl))%pl
        print(1+calc(sta,0))
        

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

const int INF = 2000000;

struct LineTable{
  int cost;
  int times;
  LineTable(){
    cost = INF;
    times = INF;
  }
};

int main(){

    int n,m;
    while(1){
      cin >> n >> m;
      if(n==0&&m==0){
        break;
      }
      LineTable table[m][m];

      for(int i=0;i<m;i++){
        table[i][i].cost = 0;
        table[i][i].times = 0;
      }

      for(int i=0;i<n;i++){
        int a,b,cost,times;
        cin >> a >> b >> cost >> times;
        table[a-1][b-1].cost = cost;
        table[a-1][b-1].times = times;
        table[b-1][a-1].cost = cost;
        table[b-1][a-1].times = times;
      }

      for(int k=0;k<m;k++){
        for(int i=0;i<m;i++){
          for(int j=0;j<m;j++){
            if(table[i][j].cost > table[i][k].cost + table[k][j].cost){
              table[i][j].cost = table[i][k].cost + table[k][j].cost;
            }
          }
        }
      }

      for(int k=0;k<m;k++){
        for(int i=0;i<m;i++){
          for(int j=0;j<m;j++){
            if(table[i][j].times > table[i][k].times + table[k][j].times){
              table[i][j].times = table[i][k].times + table[k][j].times;
            }
          }
        }
      }

      for(int k=m-1;k>=0;k--){
        for(int i=m-1;i>=0;i--){
          for(int j=m-1;j>=0;j--){
            if(table[i][j].cost > table[i][k].cost + table[k][j].cost){
              table[i][j].cost = table[i][k].cost + table[k][j].cost;
            }
          }
        }
      }

      for(int k=m-1;k>=0;k--){
        for(int i=m-1;i>=0;i--){
          for(int j=m-1;j>=0;j--){
            if(table[i][j].times > table[i][k].times + table[k][j].times){
              table[i][j].times = table[i][k].times + table[k][j].times;
            }
          }
        }
      }

      int k,p,q,r;
      cin >> k;
      /*cin >> p >> q >> r;
      if(r==0){
        cout << table[p-1][q-1].cost;
      }
      else{
        cout << table[p-1][q-1].times;
      }
      for(int i=1;i<k;i++){
        cin >> p >> q >> r;
        if(r==0){
          cout << ' ' <<table[p-1][q-1].cost;
        }
        else{
          cout << ' ' <<table[p-1][q-1].times;
        }
      }
      cout << endl;*/

      for(int i=0;i<k;i++){
        cin >> p >> q >> r;
        if(r==0){
          cout << table[p-1][q-1].cost << endl;;
        }
        else{
          cout << table[p-1][q-1].times << endl;
        }
      }
    }
    return 0;
}

Measured memory_bytes: 3068
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;


public class Main
{
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	
	void solve()
	{
		int n = ni(), K = ni();
		int[] a = na(n);
		out.println((n-1+K-2)/(K-1));
	}
	
	void run() throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
	}
	
	public static void main(String[] args) throws Exception 
	{ new Main().run(); }
	
	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;
	
	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf)
		{
			ptrbuf = 0;
			try 
			{ lenbuf = is.read(inbuf); } 
			catch (IOException e) 
			{ throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private boolean isSpaceChar(int c)
	{ return !(c >= 33 && c <= 126); }
	private int skip() 
	{ int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private double nd() 
	{ return Double.parseDouble(ns()); }
	private char nc()
	{ return (char)skip(); }
	
	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b)))
		{ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private String nsl()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b) && b != ' '))
		{ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b)))
		{
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-')
		{
			minus = true;
			b = readByte();
		}
		
		while(true)
		{
			if(b >= '0' && b <= '9')
			{
				num = num * 10 + (b - '0');
			}else
			{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-')
		{
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9')
			{
				num = num * 10 + (b - '0');
			}else
			{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static void tr(Object... o) 
	{ System.out.println(Arrays.deepToString(o)); }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int main(){
    DRI(N);
    LL an=1,sub=1;
    REP(i,N){
        an*=3;
        DRI(x);
        if(x&1){
            sub*=1;
        }
        else{
            sub*=2;
        }
    }
    cout<<an-sub<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


x_list = []
y_list = []
N = int(input())
for i in range(1,N+1):
    x, y = map(int, input().split())
    x_list.append((x,i))
    y_list.append((y,i))
x_list.sort()
y_list.sort()

diff_list = []
for i in range(N-1):
    diff = x_list[i+1][0] - x_list[i][0]
    diff_list.append((diff,x_list[i+1][1],x_list[i][1]))
    diff = y_list[i+1][0] - y_list[i][0]
    diff_list.append((diff,y_list[i+1][1],y_list[i][1]))

diff_list.sort()
uf = UnionFind(N)

cost = 0
for w,f,t in diff_list:
    if uf.same(f-1,t-1):
        continue
    cost += w
    uf.union(f-1,t-1)
    if uf.group_count == 1:
        break

print(cost)

Measured memory_bytes: 117748
A = [1000000000,1000000000]
Q = []

def a(x,y,z)
 Q << [?+,x,y,z]*" "
 A[z] = (A[x]||=0) + (A[y]||=0)
end

def c(x,y,z)
 Q << [?<,x,y,z]*" "
 A[z] = (A[x]||=0) < (A[y]||=0) ? 1 : 0
end

c(3,0,3)
0.upto(30){|i|
 a(3+i,3+i,4+i)
}

def to_b(x,s)
 a(x,3,x)
 31.downto(0){|i|
  a(3+i,s+32+i+1,s+32+i)
  c(s+32+i,x,s+i)
  a(s+i,2,s+32+i)
  i.times{a(s+32+i,s+32+i,s+32+i)}
  a(s+32+i,s+32+i+1,s+32+i)
 }
end

to_b(0,67)
to_b(1,195)

30.times{|i|
 30.times{|j|
  a(67+i,195+j,324)
  c(3,324,325)
  a(326+i+j,325,326+i+j)
 }
}

60.times{|i|
 i.times{a(326+i,326+i,326+i)}
 a(2,326+i,2)
}

# STDERR.puts "Q = #{Q.size}"
# STDERR.puts A.map.with_index{|x,i|x||=0;"#{i}:#{x}"}*" "

puts Q.size
puts Q


Measured memory_bytes: 14948
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn f(u: usize, p: usize, c: u64, edges: &Vec<Vec<(usize, u64)>>, depth: &mut Vec<u64>) {
    depth[u as usize] = c;
    for v in &edges[u] {
        if v.0 == p {
            continue;
        }
        f(v.0, u, c + v.1, edges, depth);
    }
}

fn dist(a: u32, b: u32) -> u32 {
    if a > b {
        a - b
    } else {
        b - a
    }
}

use std::collections::BTreeSet;

fn fun(
    u: usize,
    pvec: &Vec<usize>,
    edges: &Vec<Vec<usize>>,
    vals: &mut BTreeSet<usize>,
    nodes: &mut BTreeSet<usize>,
    checked: &mut BTreeSet<usize>,
) {
    if checked.contains(&u) {
        return;
    }
    checked.insert(u);
    nodes.insert(u);
    vals.insert(pvec[u]);
    for v in &edges[u] {
        fun(*v, pvec, edges, vals, nodes, checked);
    }
}

fn main() {
    let n: usize = read();
    let mut l: Vec<u32> = read_vec();
    l.sort();
    l.push(100000);

    let mut ans: usize = 0;
    for i in 0..n - 2 {
        let mut k = i + 2;
        for j in i + 1..n {
            while l[i] + l[j] > l[k] {
                k += 1;
            }
            ans += k - j - 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4476
//Tournament
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i,b,a) for(int i = (b); i --> int(a);)
#define trav(i,v) for(auto&i:v)
#define all(c) (c).begin(), (c).end()
#define sz(c) int((c).size())
#define vcr(v,n) vi v(n); trav(var,v) cin >> var;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	int n;
	cin >> n;
	vector<vi> v(n);
	rep(i,1,n){
		int m;
		cin >> m;
		v[--m].push_back(i);
	}
	function<int(int)> rekt = [&](int u){
		int ret = sz(v[u]);
		vi r;
		trav(i,v[u]) r.push_back(rekt(i));
		sort(r.rbegin(), r.rend());
		rep(i,0,sz(r)) ret = max(ret,r[i]+i+1);
		return ret;
	};
	cout << rekt(0) << endl;
}

Measured memory_bytes: 18176
import numpy as np
a,b = map(int, input().split())
grid1 = [['.' for j in range(100)] for i in range(50)]
grid2 = [['#' for j in range(100)] for i in range(50)]
a -= 1
b -= 1
x = y = 1

for i in range(a):
    grid2[x][y] = '.'
    y += 2
    if y != y % 100:
        x += 2
    y = y % 100
    if x >= 50 or y >= 100:break

x = y = 1
for i in range(b):
    grid1[x][y] = '#'
    y += 2
    if y != y % 100:
        x += 2
    y = y % 100
    if x >= 50 or y >= 100:break

print(100, 100)
grid = np.concatenate((grid1, grid2), axis=0)
for row in grid:
    print(''.join(row))

Measured memory_bytes: 12504
a,b,c = map(int,input().split())

cnt = 0

if a==b==c and a%2==0:
  print("-1")
  exit()
  
for i in range(10**6):
  if a%2==0 and b%2==0 and c%2==0:
    tmpA = b/2 + c/2
    tmpB = a/2 + c/2
    tmpC = a/2 + b/2
    a = tmpA
    b = tmpB
    c = tmpC
    cnt +=1
  else:
    print(cnt)
    break
    

Measured memory_bytes: 3064
n = gets.to_i
array = gets.chomp.split(' ').map(&:to_i)
puts array.join(' ')
for i in 1..(n-1) do
  v = array[i]
  j = i - 1
  while j >= 0 && array[j] > v
    array[j+1] = array[j]
    j -= 1
  end
  array[j+1] = v
  puts array.join(' ')
end

Measured memory_bytes: 8792
#include<cstdio>
#include<cstring>
using namespace std;

int main() {
	char s[100000];
	scanf("%s", s);
	int n = strlen(s);
	if(s[0] == s[n - 1]){
		if(n % 2 == 0) printf("First\n");
		else printf("Second\n");
	}else{
		if(n % 2 == 0) printf("Second\n");
		else printf("First\n");
	}
	return 0;
}

Measured memory_bytes: 256
import           Control.Monad
import           Control.Applicative
import           Data.List
import qualified Data.Map                      as M
--import qualified Data.Vector as V
--import qualified Data.Vector.Mutable as VM

-- getBysplit = map read . words <$> getLine

main :: IO ()
main = do
  [a, b, c, d] <- getLine
  let yymm = "01" <= [c, d] && [c, d] <= "12"
  let mmyy = "01" <= [a, b] && [a, b] <= "12"
  if yymm && mmyy
    then putStrLn "AMBIGUOUS"
    else if yymm && not mmyy
      then putStrLn "YYMM"
      else if not yymm && mmyy then putStrLn "MMYY" else putStrLn "NA"


Measured memory_bytes: 380
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
int main(){
	int n,t;
	while(~scanf("%d%d",&n,&t)){
		int ans=10000,a,b;
		for(int i=1;i<=n;i++){
			scanf("%d%d",&a,&b);
			if(b<=t) ans=min(ans,a);
		}
		if(ans!=10000) printf("%d\n",ans); else printf("TLE\n");
	}
} 

Measured memory_bytes: 256
import collections

n_list = []

for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            n_list.append(x**2 + y**2 + z**2 + x*y + y*z + z*x)

# print(n_list)

N = collections.Counter(n_list)

# print(N)

for i in range(1,int(input())+1):
    # print("aaa",i)
    try:
        print(N[i])
    except:
        print(0)
    


Measured memory_bytes: 49196
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define mp make_pair
#define debug1(a) cout<<"------\n"<<#a<<" = "<<a<<endl<<"------"<<endl
#define debug2(a,b) cout<<"--------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<endl<<"--------------"<<endl
#define debug3(a,b,c) cout<<"----------------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<" ; "<<#c<<" = "<<c<<endl<<"----------------------"<<endl
#define sz(a) (ll)(a.size())
#define debug4(a) cout<<"chu "<<a<<endl
#define endl "\n"
const ll N = 1e6+5;
ll a[1000005];
ll n;

bool prime_sieve[N]={0};
vector <ll> primes;

void prime(){
  prime_sieve[2]=1;
  for(ll i=3;i<N;i+=2){
    prime_sieve[i]=1;
  }
  for(ll i=3;i<N;i+=2){
    if(prime_sieve[i]==1){
      for(ll j=i*i;j<N;j+=i){
        prime_sieve[j]=0;
      }
  }
  }
  forn(i,2,N) if(prime_sieve[i]) primes.pb(i);
}

ll power(ll x,ll n,ll m)
{
    if(n==0)
        return 1;
    else if((n&1)==0){
        ll y=power(x,n/2,m);
        return (y*y)%m;
    }else{
        return ((x%m)*power(x,n-1,m))%m;
    }
}

ll modInverse(ll a,ll m){
  return power(a,m-2,m);
}

/*ll getlcm(){
  ll lcm=1;
  for(auto p:primes){
    //debug1(p);
    ll x=0;
    forn(i,0,n){
      ll pwr = 0;
      ll y=a[i];
      while(y%p==0){
        pwr++;
        y/=p;
      }
      x = max(x,pwr);
    }
    //debug1(x);
    lcm = (lcm*power(p,x,mod))%mod;
  }
  return lcm;
}*/

map <ll,ll> m;

ll getlcm(){
  for(ll i=0;i<n;i++){
  ll y=a[i];
  ll pf[120]={},pf_freq[120]={};
  ll xb=-1;
  for(ll i=2;i*i<=y;i++){
    if(y%i==0){
      pf[++xb]=i;
      while(y%i==0){ y/=i; ++pf_freq[xb]; }
    }
  }
  if(y>1) {pf[++xb]=y; ++pf_freq[xb];}

  for(ll i=0;i<=xb;i++){
    /*if(m.count(pf[i])==0)
      m[pf[i]] = pf_freq[i];
    else*/
      m[pf[i]] = max(m[pf[i]],pf_freq[i]);
  }

  }

  ll lcm=1;
  for(auto it:m){
    //debug2(it.f,it.s);
    lcm = (lcm*power(it.f,it.s,mod))%mod;
  }
  return lcm;
}

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  prime();
  cin>>n;
  forn(i,0,n){
    cin>>a[i];
  }
  ll lcm = getlcm();
  //debug1(lcm);
  ll ans = 0;
  forn(i,0,n){
    ans = (ans + (lcm*modInverse(a[i],mod))%mod)%mod;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2548
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <climits>
#include <cmath>
#include <queue>
#include <ctime>
using namespace std;


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    map<char, int> occurs;

    string s;
    cin >> s;
    for (int i = 0; i < (int) s.size(); ++i) {
        ++occurs[s[i]];
    }
    bool flag = true;
    for (map<char, int>::iterator it = occurs.begin(); it != occurs.end(); ++it) {
        if (it->second % 2 != 0) {
            flag = false;
            break;
        }
    }
    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}   

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n,l,res;
  cin >> n >> l;
  res=n*(2*l+n-1)/2;
  if(l>0)
    res-=l;
  if(l+n-1<0)
    res-=l+n-1;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int a, b, c, d, e;

int main()
{
    scanf("%d %d", &a, &b);

    if(b < 0)
    {
        if(a < 0)
            printf("%d\n", a*b);

        else
            printf("%d\n", a-b);
    }
    else
    {
        if(a+b <= a*b)
            printf("%d\n", a*b);

        else
            printf("%d\n", a+b);
    }

    return 0;
}


Measured memory_bytes: 128
/**
 *    author:  FromDihPout
 *    created: 2020-08-04
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    set<int> seen;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (seen.count(x)) {
            seen.erase(x);
        }
        else {
            seen.insert(x);
        }
    }
    cout << seen.size() << '\n';
    return 0;
}

Measured memory_bytes: 8160
import Control.Monad

main :: IO ()
main = do
  [n,x] <- map read . words <$> getLine
  ms <- replicateM n $ readLn
  print $ solve n x ms 

solve :: Int -> Int -> [Int] -> Int
solve n x ms = n + (x' `div` m0)
  where
    m0 = minimum ms
    x' = x - sum ms


Measured memory_bytes: 1020
($x,$y)=glob<>;
$l[$_]=[glob<>]for(0..2);
@p=sort{$$b[1]<=>$$a[1]}map{$c=$_;map{[$c,$_]}@{$l[$c]}}(0..2);
$a=$x+$y;
for(;0<$a;$i++){
  $e=$p[$i][0];
  ($e==0)?$x&&($x--,$a--,$d+=$p[$i][1]):
  ($e==1)?$y&&($y--,$a--,$d+=$p[$i][1]):
  ($d+=$p[$i][1],$a--)
}
print$d

Measured memory_bytes: 112004
#include<bits/stdc++.h>
#define maxn 1<<18|5
#define mod 998244353
#define rep(i,j,k) for(int i=(j),LIM=(k);i<=LIM;i++)
#define per(i,j,k) for(int i=(j),LIM=(k);i>=LIM;i--)
using namespace std;

int n,N;
int a[maxn],b[maxn];

int Pow(int b,int k){ int r=1;for(;k;k>>=1,b=1ll*b*b%mod) if(k&1) r=1ll*r*b%mod; return r; }
void FWT(int *a){
	rep(i,0,n-1) rep(j,0,N-1) if(!(j>>i&1)){
		int v = j ^ (1 << i) , x = (a[j] + a[v]) % mod , y = (a[j] - a[v]) % mod;
		a[j] = x , a[v] = y;
	}
}

int main(){
	scanf("%d",&n);N = 1 << n;int S=0;
	rep(i,0,N-1) scanf("%d",&a[i]),S+=a[i];
	S = Pow(S , mod-2);
	rep(i,0,N-1) a[i] = 1ll * a[i] * S % mod;
	a[0]-- , b[0] = 1 << n;
	rep(i,0,N-1) b[i]--;
	FWT(a),FWT(b);
	rep(i,0,N-1) a[i] = 1ll * Pow(a[i],mod-2) * b[i] % mod;
	FWT(a);int ivN = Pow(N , mod-2);
	rep(i,0,N-1) a[i] = 1ll * a[i] * ivN % mod;
	per(i,N-1,0) a[i] = (a[i] - a[0]) % mod;
	rep(i,0,N-1) printf("%d\n",(a[i]+mod)%mod);
}

Measured memory_bytes: 5712
#include <stdio.h>

int main(void) {
	for(;;) {
		int n;
		int i;
		int card[2] = {0};
		int point[2] = {0};
		
		scanf("%d", &n);
		if(n == 0) break;
		for(i = 0; i < n; i++) {
			scanf("%d %d", &card[0], &card[1]);
			if(card[0] == card[1]) {
				point[0] += card[0];
				point[1] += card[1];
			} else if(card[0] > card[1]) {
				point[0] += card[0] + card[1];
			} else {
				point[1] += card[0] + card[1];
			}
		}
		
		printf("%d %d\n", point[0], point[1]);
	}
	return 0;
}

Measured memory_bytes: 600
from math import ceil
n = int(input())
p = [int(i) for i in input().split()]
cnt = 0
ans = 0

for i in range(n):
    if i+1 == p[i]:
        cnt += 1
    else:
        if cnt != 0:
            ans += ceil(cnt/2)
        cnt = 0
else:
    ans += ceil(cnt/2)

print(ans)

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

int main()
{
    ios::sync_with_stdio(false);  cin.tie(0); 
    int n ,temp ,res=0;
    cin >> n;
    for (int i=1; i<=n; i++)
    {
        cin >> temp;
        if (i%2 && temp%2)
            res++;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

    public static int maxSize = 1000000;

    public static boolean[] prime = new boolean[maxSize];

    public static void main(String[] args) {
        setPrime();
        try (Scanner scan = new Scanner(System.in)) {
            String inData = "";
            while ((inData = scan.nextLine()) != null) {
                System.out.println(primeCount(Integer.parseInt(inData)));
            }
        } catch (Exception e) {
            System.exit(0);
        }
    }

    private static void setPrime() {
        prime[2] = true;
        for (int i = 3; i < maxSize; i++) {
            if (i % 2 == 0) {
                continue;
            }
            setOddPrime(i);
        }
    }

    private static void setOddPrime(int i) {
        boolean isPrime = true;
        for (int j = 1; j <= Math.sqrt(i); j++) {
            if (prime[j] && i % j == 0) {
                isPrime = false;
                break;
            }
        }
        prime[i] = (isPrime) ? true : false;
    }

    private static int primeCount(int inData) {
        int count = 0;
        for (int i = 2; i <= inData; i++) {
            if (i != 2 && i % 2 == 0) {
                continue;
            }
            if (prime[i]) {
                count++;
            }
        }
        return count;
    }
}

Measured memory_bytes: 27564
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		
		long n = scan.nextLong();
		
		ArrayList<Long> array = new ArrayList<Long>();
		long total = 0;
		
		for( int i = 0; i < n; i++) {
			array.add(scan.nextLong());
			total += array.get(i);
		}
		
		
		/*
		for(int i = 0; i < n-1; i++) {
			if(total >= 1000000007) {
				total -= 1000000007;
			}
			for(int j = i+1; j < n; j++) {
				
				total += array.get(i) * array.get(j);
				
				long a = total %  1000000007;
				
				total = a;
				
				if(total >= 1000000007) {
					total -= 1000000007;
				}
				
			}
		}*/
		
		long mod = 1000000007;
		long ans = 0;
		
		for(int i = 0; i < n-1; i++) {
			total -= array.get(i);
			long a = total % mod;
			ans += array.get(i) * a;
			ans %= mod;
		}
		
		System.out.print(ans);
	}

}

Measured memory_bytes: 66156
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main(){
    vector<int> a(3);
    REP(i, 3) cin >> a[i];
    sort(All(a));
    REP(i, 2) cout << a[i] << " ";
    cout << a[2] << endl;
}



Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
   int n;
   cin>>n;
   int a,b;
   a=n%100;
   b=n/100;
   if(a<=12&&a>0&&b<=12&&b>0)
    cout<<"AMBIGUOUS"<<endl;
    else if(a<=12&&a>0)
        cout<<"YYMM"<<endl;
    else if(b<=12&&b>0)
        cout<<"MMYY"<<endl;
    else
        cout<<"NA"<<endl;
    return 0;
}


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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

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

  int cnt = 0;
  int n = s.size();
  for(int i=0; i<n; ++i) if(s[i]=='1') cnt++;
  if(cnt==n){
    cout << 1 << endl;
    return 0;
  }

  if(s[0]=='1' && k>=cnt){
    for(int i=0; i<n; ++i){
      if(s[i]=='1') continue;
      else{
        cout << s[i] << endl;
        return 0;
      }
    }
  }
  else cout << s[0] << endl;

}

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

int main(){
    int N;
    cin >> N;
    int x = 0;
    int N_ = N;
    for(int i=8; i>=0 ; i--){
        int pow_;
        pow_ = pow(10,i);
        int Q;
        Q = (int)(N_/pow_);
        x += Q;
        if (pow_ <= N_){
            N_ -= pow_*Q;
        }
    }
    if (N % x == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 384
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		int i = 0;
		if(s.contains("RRR")) i = 3;
		else if(s.contains("RR")) i = 2;
		else if(s.contains("R")) i = 1;
		
		System.out.println(i);
	}
}


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

int main(void){
  int N;
  cin >> N;
  int a[N];
  int b[N];
  for(int i = 0; i < N; i++)
    cin >> a[i] >> b[i];
  bool ans = false;
  
  for(int i = 0; i < N-2; i++){
    if(a[i] == b[i] && a[i+1] == b[i+1] && a[i+2] == b[i+2])
      ans = true;
  }
  
  if(ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main(void)
{
    int X, Y, Z;
    cin >> X >> Y >> Z;

    X -= Z;
    int ans = X / (Y + Z);
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 256
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/04/04.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//  ABC128
//
//

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__

void solve(void){
  
  int A,P;
  
  cin >> A >> P;
  
 
  cout << (A*3+P)/2 << endl;
  
  return;
   
}

#define TESTCASES 1

int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}




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

int main(void) {
  int N, M;
  cin >> N >> M;
  cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
  return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

int cost[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};

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

    int N, M;
    cin >> N >> M;
    vector<int> use(10, 0);
    while (M--)
    {
        int a;
        cin >> a;
        use[a] = 1;
    }
    vector<string> dp(N + 1);
    vector<int> dig(N + 1, -1);
    dp[0] = "";
    dig[0] = 0;
    for (int i = 0; i <= N; i++)
    {
        if (dig[i] == -1)
            continue;
        for (int j = 9; j >= 1; j--)
        {
            if (!use[j])
                continue;
            int next = i + cost[j];
            if (next > N)
                continue;
            if (dig[next] > dig[i] + 1)
                continue;
            if (dig[next] == -1 || dig[next] < dig[i] + 1)
            {
                dp[next] = dp[i] + (char)('0' + j);
                dig[next] = dp[next].size();
            }
            else
            {
                dp[next] = max(dp[next], dp[i] + (char)('0' + j));
            }
        }
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 45312
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	ll a, b, n;
	cin >> a >> b >> n;
	cout << a * min(n, b - 1) / b << '\n';
}



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int x;
  cin>>x;
  if(x==0)cout<<1<<endl;
  else cout<<0<<endl;
  return 0;
}


Measured memory_bytes: 3620
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  string s; readV(s);
  int w; readV(w);

  for (auto i = 0; i < s.length; i += w)
    write(s[i]);
  writeln;
}


Measured memory_bytes: 256
n = int(input())
a_list = [int(input()) for _ in range(n)]
cp_list = a_list.copy()
cp_list.sort()
second_ans = cp_list[-2]
ans = cp_list[-1]
for i in range(n):
    if a_list[i] == ans:
        print(second_ans)
    else:
        print(ans)

Measured memory_bytes: 19220
N = int(input())
P = list(map(float, input().split()))
dp = [[0] * (N + 1) for i in range(N + 1)]
dp[0][0] = 1.0
for i in range(1, N + 1):
    for j in range(N):
        if j < N:
            dp[i][j + 1] += dp[i - 1][j] * P[i - 1]
        dp[i][j] += dp[i - 1][j] * (1 - P[i - 1])

num = 0
for i in range(N + 1):
    if i > N // 2:
        num += dp[N][i]

print(num)


Measured memory_bytes: 253192
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;

using namespace std;


int main(){ 
    long long N;
    cin >> N;

    vector<int> counter(N, 0);
    int first;
    cin >> first;
    ++counter[first];

    for(int i = 1; i < N; ++i){
        int D;
        cin >> D;
        ++counter[D];
    }

    if(first != 0 || counter[0] != 1){
        cout << 0;
        return 0;
    }

    long long num = 1;
    int sum = 0;
    int prev = 1;

    for(int i = 0; i < N; ++i){
        if(counter[i] == 0){
            cout << 0;
            return 0;
        }

        for(int j = 0; j < counter[i]; ++j){
            num *= prev;
            num %= PRIME2;
        }

        prev = counter[i];
        sum += counter[i];

        if(sum == N){
            break;
        }
    }

    cout << num;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long Q,H,S,D;
  long long N;
  cin>>Q>>H>>S>>D>>N;
  long long ONE=min(4*Q,min(2*H,min(2*Q+H,S)));
  long long TWO=min(D,ONE*2);
  cout<<N/2*TWO+N%2*ONE<<endl;
}

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

int main(){
	int x, h;
	while(cin >> x >> h, x!=0 && h!=0){
		double s1 = (double)x * (double)x;
		double e1 = sqrt( (double)x/sqrt(2)*(double)x/sqrt(2) + (double)h*(double)h );
		double e2 = sqrt( e1*e1 - (double)x/2*(double)x/2 );
		double s2 = (double)x * e2 /2;
		printf("%lf\n", s1+4*s2);
	}
} 

Measured memory_bytes: 1188