akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <string>
#include <utility>
#include <map>
#include <queue>

#define rep(i,s,n) for(int i = s; n > i; i++)
#define REP(i,n) rep(i,0,n)
#define ll long long int
#define ALL(a) a.begin(), a.end()
using namespace std;

template<class T>
class segtree {
	vector<T> tree;
public:
	segtree(const int n) :tree(n * 2) {}
	int base() const { return tree.size() / 2; }
	void update(int i, const T&v) {
		i += base();
		tree[i] = v;
		while (i /= 2)
			tree[i] = tree[i * 2] + tree[i * 2 + 1];
	}
	T fold(int f, int l)const {
		f += base();
		l += base();
		T accl, accr;
		while (f < l) {
			if (f & 1)
				accl = accl + tree[f++];
			f /= 2;
			if (l & 1)
				accr = tree[--l] + accr;
			l /= 2;
		}
		return accl + accr;
	}
};


ll k;

struct hoge {
	bool flip;
	ll sum;
	hoge(bool x = 0, ll y = 0) :flip(x), sum(y) {}
	hoge operator+(const hoge &r)const {
		if (flip)
			return hoge(!r.flip, (sum - r.sum + k) % k);
		else
			return hoge(r.flip, (sum + r.sum) % k);
	}
};

ll getmod(const ll a) {
	return (a%k + k) % k;
}

hoge make(const ll a) {
	if (a != 0)
		return hoge(0, a);
	else
		return hoge(1, 0);
}


int gcd(int a, int b) {
	if(a < b) swap(a, b);
	while (b != 0)
		a %= b, swap(a, b);
	return a;
}

#define Getbit(a,n) (a & (1LL << n))

typedef pair<int, int> pii;
int main() {
	int n, k;
	cin >> n >> k;

	vector<ll> b(n),a(n*(n+1)/2);

	REP(i, n) cin >> b[i];

	int cc = 0;
	REP(i, n) {
		ll sum = 0;
		rep(j, i, n) {
			sum += b[j];
			a[cc] = sum;
			cc++;
		}
	}

	ll ans = 0;

	for (ll i = 51; 0 <= i; i--) {
		ll cou = 0;

		REP(j, n*(n+1)/2) {
			cou += Getbit(a[j], i) >> i;
		}

		if (cou >= k) {
			ans ^= (1LL << i);
			REP(j, n*(n + 1) / 2) {
				if (!Getbit(a[j], i)) 
					a[j] = 0;
			}
		}

	}


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4224
n=int(input())

ans=0
lastk=n
for i in range(1,n+1):
    k=n//i
    ans+=i*(i-1)//2*(lastk+k+1)*(lastk-k)//2
    if i>k:
        break
    ans+=k*(k+1)//2*i
    if i==k:
        break
    lastk=k

print(ans)


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

class Program
{
	public static int Main(string[] args)
	{
        
        string[] str = Console.ReadLine().Split(' ');
        int x1 = int.Parse(str[0]);
        int y1 = int.Parse(str[1]);
        int x2 = int.Parse(str[2]);
        int y2 = int.Parse(str[3]);
        int answer = 0;

        Console.WriteLine((y1 - y2 + x2).ToString() + " " + (x2 - x1 + y2).ToString() + " " +(y1-y2+x1).ToString() + " " + (x2-x1+y1).ToString());

        return 0;
	}
}


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

namespace cswork
{

    class Program
    {
        public Program() { }

        Scanner cin;

        void Omame()
        {
            cin = new Scanner();

            int a = cin.nextInt();
            int b = cin.nextInt();
            int c = cin.nextInt();
            int x = cin.nextInt();
            int y = cin.nextInt();

            int ans = int.MaxValue;
            for (int i = 0; i <= 100000; i++)
            {
                int value = c * i * 2 + a * Math.Max(x - i, 0) + b * Math.Max(y - i, 0);

                ans = Math.Min(ans, value);
            }

            Console.WriteLine(ans);
        }

        static void Main(string[] args)
        {
            new Program().Omame();
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();

            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next();
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }
    }
}

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

#define ll long long
#define siz 100005
typedef pair<int ,int> pii;

int main(){

    ios_base::sync_with_stdio(0);
    //freopen("overcode.in","r",stdin);
    //freopen("out.txt","w",stdout);

    int n; cin>>n;
    ll dp[100005][4];
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>dp[i][j];
        }
    }

    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            ll sm=0;
            for(int m=0;m<3;m++){
                if(j==m) continue;
                sm=max(sm,dp[i-1][m]);

            }
            dp[i][j]+=sm;
        }
    }

    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);

    return 0;
}


Measured memory_bytes: 3328
Module Module1
  Sub main()
    Dim N = Console.ReadLine()
    If N Mod 2 = 0 Or N Mod 5 = 0 Then
      Console.WriteLine("-1")
    Else
      Dim num as Integer = 0
      Dim m as Integer = 0
      Do
        num = num + 1
        m = (m * (10 Mod N) + (7 Mod N)) Mod N
      Loop While(m <> 0)

      Console.WriteLine(num)
     End If
  End Sub
End Module

Measured memory_bytes: 28384
//我是菜鸡
#include<bits/stdc++.h>
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _defor(i,a,b) for((i) = (a);(i)<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto p:st)
#define debug(q,x) cout<<q<<x<<endl
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
const double ext = 1e-6;
void deprint() {
	//ofstream cout("E:\\acm dream\\debug.txt");
	return;
}
int main() {
	//ifstream cin("E:\\acm dream\\in.txt");
	//ofstream cout("E:\\acm dream\\out.txt");
	//srand((unsigned)time(nullptr));
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int a, b;
	while (cin >> a >> b) {
		int ans;
		if (a >= 13)ans = b;
		else if (a > 5 && a < 13)ans = b / 2;
		else ans = 0;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int trape(int a, int b, int h) {
    return ((a + b) * h)/ 2;
}

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

    printf("%d\n", trape(a, b, h));
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);

int main() {
int n;
cin >> n;
map<string,int> mp;
vector<int> t(n);
rep(i,n){
  string s;
  int x;
  cin >> s >> x;
  mp[s]+=i;
  t.at(i) = x;
}
string a;
cin >> a;
int ans = 0;
for(int i = mp[a]+1; i < n; i++){
  ans += t.at(i);
}
cout << ans << endl;
}


Measured memory_bytes: 3616
#include <iostream>
#include <inttypes.h>

int main() {
	uint64_t a, b, x;
	std::cin >> a >> b >> x;
	uint64_t s, e;
	s = a / x;
	e = b / x;

	if (a == s * x) {
		std::cout << e - s + 1 << std::endl;
	} else {
		std::cout << e - s << std::endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

int main() {

    ll A,B;
    cin >> A >> B;
    ll res = -(1 << 30);

    res = max(res,A+B);
    res = max(res,A-B);
    res = max(res,A*B);


    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long lint;
 
int main(){
   int r;
   cin >> r;
   
   cout << 2*r*3.14156535 << endl;
   
   return 0;
}


Measured memory_bytes: 3744
n = int(input())
a = [[int(input()), True] for i in range(n)]

current = a[0]
cnt = 0
while current[0] <= n:
    if current[0] == 2:
        cnt += 1
        break
    if not current[1]:
        cnt = -1
        break

    current[1] = False
    current = a[current[0]-1]
    cnt += 1

print(cnt)


Measured memory_bytes: 18416
#include<bits/stdc++.h> 
using namespace std;
#define rush             ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll               long long int
#define FOR(a,x,n)       for(ll a=x;a<n;a++)
#define ROF(a,x,n)       for(ll a=x;a>=n;a--)
#define pb               push_back
#define lb               lower_bound
#define ub               upper_bound
#define MOD              1000000007

ll a[100005][3];
ll ans[100005][3];

void solve() {
     ll n;
     cin >> n; 

     FOR(i,0,n) {
         FOR(j,0,3) {
             cin >> a[i][j];    
         }    
     }

     ans[0][0] = a[0][0];
     ans[0][1] = a[0][1];
     ans[0][2] = a[0][2];

     FOR(i,1,n) {
         ans[i][0] = a[i][0] + max(ans[i-1][1], ans[i-1][2]);
         ans[i][1] = a[i][1] + max(ans[i-1][0], ans[i-1][2]);
         ans[i][2] = a[i][2] + max(ans[i-1][0], ans[i-1][1]);    
     }

     cout << max(ans[n-1][0], max(ans[n-1][1], ans[n-1][2]));
}
 
int main() {
        rush
        solve();
}

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

int main(){
  int q;
  list<int>L;
  list<int>::iterator it=L.begin();
  cin>>q;
  while(q--){
    int a,b;
    cin>>a;
    if(a<2)cin>>b;
    if(!a)it=L.insert(it,b);
    else if(a==1){
      r(i,abs(b)){
        if(b<0)it--;
        else it++;
      }
    }
    else it=L.erase(it);
  }
  it=L.begin();
  for(;it!=L.end();it++){
    cout<<*it<<endl;
  }
}


Measured memory_bytes: 18648
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  string s;
  cin >> s;
  int n = s.size();
  for(int i=0;i<n-1;i++){
    if(s[i]=='P' && s[i+1]=='?')s[i+1]='D';
  }
  for(int i=1;i<n;i++){
    if(s[i-1]=='?' && s[i]=='D')s[i-1]='P';
  }
  rep(i,n-1){
    if(s[i]=='?' && s[i+1] =='?'){
      s[i]='P';
      s[i+1]='D';
    }
  }
  rep(i,n)if(s[i]=='?')s[i]='D';
  cout << s << endl;
  return 0;     
}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define inrep int t;cin>>t; while(t--)
#define pb emplace_back
using namespace std;
using namespace __gnu_pbds; 


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;
const ll MOD = 1e9+7;
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {

    for ( unsigned   i=0; i<v.size(); i++ )
        in>>v[i];
    return in;
}

ll extended_GCD(ll a , ll b , ll &x , ll &y){
    if(a == 0){
        x = 0;
        y = 1;
        return b;
    }
    ll x1 , y1;
    ll gcd = extended_GCD(b%a , a , x1 , y1);
    x = y1 - (b/a)*x1; 
    y = x1;
    return gcd;
}
ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinv(ll a , ll mod ){
    ll x , y;
    extended_GCD(a , mod , x , y);
    if(x < 0) x += mod;
    return x;
}

ll mul(ll a,ll b,ll m)
{
    return (a%m*b%m)%m;
}
  
 


int main()
{
   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    int count[1000005] = {0};
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        count[a[i]]++;
    }
    int ans = 0;
    for(int i=0;i<n;i++)
    {
        int flag = 0;
        count[a[i]]--;
        for(int j=1;j<=sqrt(a[i]);j++)
        {
            if(a[i]%j==0)
            {
                if(count[j]||count[a[i]/j])
                {
                    flag=1;
                    break;
                }
            }
        }
        count[a[i]]++;
        if(flag==0)
        {
            ans++;
        }
    }
    cout<<ans;

    
    
    return 0;
}

Measured memory_bytes: 8292
#include <iostream>

int main()
{
	int a, b, c;
	std::cin >> a >> b >> c;

	if (a < b && b < c)
	{
		std::cout << "Yes" << std::endl;
	}

	else
	{
		std::cout << "No" << std::endl;
	}

	return 0;
}

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

using namespace std;
#define deb(x) cout << #x << ": " << x << endl
#define fo(i, n) for (ll i = 0; i < n; i++)
#define fkn(i, k, n) for (i = k; i < n; i++)
#define ll long long
#define F first;
#define S second;
#define PB(x) push_back(x);
#define MP(x,y) make_pair(x,y);
typedef vector<ll> vll;

bool powerOfTwo(ll x)
{
    return !(x & (x - 1));
}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;

    vector<string> v(n);
   fo(i,n) { cin >> v[i];}

   unordered_map<string,int> mp;
   mp["AC"] = 0;
   mp["WA"] = 0;
   mp["TLE"] = 0;
   mp["RE"] = 0;

   fo(i, n) {
       
        mp[v[i]]++; }

   cout << "AC" << " x " << mp["AC"] << endl;
   cout << "WA"
        << " x " << mp["WA"] << endl;
   cout << "TLE"
        << " x " << mp["TLE"] << endl;
   cout << "RE"
        << " x " << mp["RE"] << endl;
}




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

int N;
int A[200001];
int B[200001];
int cA[200001]={};
int cB[200001]={};
int ans[200001];

int main(){
 scanf("%d",&N);
 rep(i,N){ scanf("%d",&A[i]); cA[A[i]]++; A[i]--; }
 rep(i,N){ scanf("%d",&B[i]); cB[B[i]]++; B[i]--; }
 A[N] = B[N] = 1000000000;

 rep(i,N){ if(cA[i+1]+cB[i+1]>N){ printf("No\n"); return 0; } }
 rep(i,N){ cA[i+1]+=cA[i]; cB[i+1]+=cB[i]; }

 int d = 0;
 rep(i,N) d = max(d,cA[i+1]-cB[i]);

 printf("Yes\n");
 rep(i,N){
  if(i) printf(" ");
  printf("%d",B[(i+N-d)%N]+1);
 } printf("\n");

 return 0;
}




Measured memory_bytes: 6984
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long ll;
typedef long double ld;
#define INF (1LL<<60)
#define MOD1 1000000007
/*swap 交換*/
void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
/*2つのうち大きい数を返す*/
ll max2(ll a,ll b){return a>=b?a:b;}
/*2つのうち小さい数を返す*/
ll min2(ll a,ll b){return a>=b?b:a;}
/*絶対値*/
ll ABS(ll a){return a>=0?a:(-a);}
typedef struct{
    ll aa;
    ll bb;
}frequent;
// 小大
int compare(const void *a, const void *b){return *(ll *)a - *(ll *)b;}

int main(void){
    char s[105];
    ll n,k,i,j,ans=0,l;
    scanf("%s%lld",s,&k);
    n=strlen(s);
    if(n==1){
        printf("%lld\n",k/2);
        return 0;
    }
    i=n;
    ll parts=2;
    if(s[0]==s[n-1]){
        parts=0;
        for(i=n-1;i>=1;i--){
            if(s[i]!=s[i-1]) break;
        }
    }
    if(i==0){
        printf("%lld\n",n*k/2);
        return 0;
    }
    // printf("%lld ",i);
    ll count;
    l=1;
    ans+=(n-i)/2;
    for(j=0;j<i;j++){
        // if(j==0) l+=n-i;
        // printf("%lld ",l);
        if(s[j]==s[j+1]){
            l++;
            // count=l;
        }else{
            if(parts==0){
                count=l;
                ans+=l/2;
                parts++;
            }else{
                ans+=l/2*k;
            }
            l=1;
        }
    }
    if(parts==1) ans+=(n-i+count)/2*(k-1);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main() {
  int a, b, c;
  int ans;
  scanf("%d %d %d", &a, &b, &c);
  if (a * b > c) {
  	ans = c;
  } else {
  	ans = a * b;
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;
 
public class Main {
 
	void submit() {
	    int N = nextInt();
        int[] param = new int[3];
        int g = 0;
        long sum = 0;

        for(int i=1; i<=N; i++){
            param[0] = i;
            for(int j=1; j<=N; j++){
                param[1] = j;
                for(int k=1; k<=N; k++){
                    param[2] = k;
                    g = gcd(param[0], param[1]);
                    g = gcd(g, param[1]);
                    g = gcd(g, param[2]);
                    sum += g;
                }
            }
        }
        out.println(sum);
    }

    public static final int gcd(int a, int b) {
        //a > b にする（スワップ）
        if (a < b) {
            int tmp = a;
            a = b;
            b = tmp;
        }
    
        //ユークリッドの互除法
        int r = -1;
        while (r != 0) {
            r = a % b;
            a = b;
            b = r;
        }
    
        return a;    //b には r=0 の値が入るため、a を返す
    }

	void preCalc() {
 
	}
 
	void stress() {
 
	}
 
	void test() {
 
	}
 
	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}
 
	static final Random rng = new Random();
 
	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}
 
	public static void main(String[] args) throws IOException {
		new Main();
	}
 
	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
 
	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}
 
	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
 
	int nextInt() {
		return Integer.parseInt(nextToken());
	}
 
	long nextLong() {
		return Long.parseLong(nextToken());
	}
 
	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 33608
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const int MAXA = 200000;

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

    int N; cin >> N;
    vector<int> A(N);
    vector<ll> v(MAXA+1);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        v[A[i]]++;
    }
    ll res = 0;
    for (int i = 0; i <= MAXA; i++) {
        if (v[i] < 2) continue;
        res += v[i] * (v[i]-1) / 2;
    }
    for (int i = 0; i < N; i++) {
        cout << res - v[A[i]] + 1 << "\n";
    }
}

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

using ll = long long;

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 29)

using namespace std;

//long C(long n, long r);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);

void solve()
{
    char x, y;
    cin >> x >> y;
    if(x < y){
        cout << "<" << endl;
    }
    else if(x > y){
        cout << ">" << endl;
    }
    else{
        cout << "=" << endl;
    }
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
program abc107c
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,k,i,l,r,ans
    integer(int32), allocatable:: x(:)

    read*, n,k
    allocate(x(n))
    read*, x(:)
    ans = 1000000000
    do i=1,n-k+1
        l = x(i)
        r = x(i+k-1)
        ans = min(ans,abs(l)+abs(r-l), abs(r)+abs(r-l))
    end do
    print'(i0)', ans
end program abc107c

Measured memory_bytes: 1152
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    
    double n,a,b;
    cin>>n>>a>>b;
    vector<double> v;
    rep(i,n){
        ll vv;cin>>vv;
        v.push_back(vv);
    }
    sort(v.rbegin(),v.rend());
    double ave=0;
    rep(i,a){
        ave+=v[i];
    }
    ave=ave/a;
    //cout<<ave<<endl;
    printf("%f\n",ave);
    
    
    if(n==1){cout<<v[0]<<endl;return 0;}
    
    
    if(v[0]==v[a-1]&&v[a-1]==v[a]){
        ll h=a;
        while(true){
            if(v[a-1]==v[h]&&h<v.size()){
                h++;
            }else{
                break;
            }
        }
        ll zentai=h;
        
        double ans=0;
        // cout<<"a"<<a<<h<<endl;
        for(int aa=a;aa<=b;aa++){
            
            double cc=1,rr=1;
            for(int i=0;i<aa;i++){
                cc*=(zentai-i);
            }
            for(int i=0;i<aa;i++){
                rr*=(aa-i);
            }
            //  cout<<zentai<<" "<<aa<<" "<<cc/rr<<endl;
            ans+=cc/rr;
        }
        
        ll anss=ans;
        //  printf("%f\n",ans);
        cout<<anss<<endl;
        
    }else{
        ll csum=1;
        ll o=a-2;
        while(true){
            if(v[a-1]==v[o]&&o>=0){
                csum++;
                o--;
            }else{
                break;
            }
        }
        o=a;
        ll tsum=0;
        while(true){
            if(v[a-1]==v[o]&&o<v.size()){
                o++;
                tsum++;
            }else{
                break;
            }
        }
        tsum+=csum;
        long double c=1,r=1;
        for(int i=0;i<csum;i++){
            c*=(tsum-i);
        }
        for(int i=0;i<csum;i++){
            r*=(csum-i);
        }
        // cout<<"b"<<endl;
        ll ansm=c/r;
        cout<<ansm<<endl;
    }
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int i,j,c,n,d,x,r,a[10][10],m,k;
int main(){
  for(cin>>n>>d;i<n;i++)for(j=0;j<d;j++)cin>>a[i][j];
  for(i=0;i<n;i++){
    for(k=1;k<n-i;k++){
      for(r=0,m=0,j=0;j<d;j++) m+=pow(a[i][j]-a[i+k][j],2);
      r=sqrt(m);
      if(pow(r,2)==m)c++;
    }
  }
  cout<<c;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#include<bitset>

#define MOD 1000000007
using namespace std;

int main()
{
	int N, L;	cin >> N >> L;
	int ans = 0;
	int mini = 99999;
	for (int i = 0; i < N; i++)
	{
		ans += L + i;
		if (abs(mini) > abs(L + i))	mini = L + i;
	}

	cout << ans - mini;
	return 0;
}

Measured memory_bytes: 256
import sys
a,b,c,d = map(int,input().split())

if not (1 <= a <= 100 and 1 <= b <= 100 and 1 <= c <= 100 and 1 <= d <= 100):
    sys.exit()

if ( abs(c - a) <= d*2 and abs(b - a) <= d and (c - b) <= d )or abs(c - a) <= d:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9060
#include "stdio.h"

int main(){
    
    int A,B,C;
    int A_temp,B_temp,C_temp;
    
    scanf("%d %d %d",&A,&B,&C);
    int roomcounter=0;
    while (1)
    {
        
        if ((A%2==1)||(B%2==1)||(C%2==1)) {
            break;
        }
        
        if (A==B) {
            if (A==C) {
            if (B==C) {
            roomcounter=-1;
            break;
            }}}
        
        A_temp=A;
        B_temp=B;
        C_temp=C;
        
        A=0;
        B=0;
        C=0;
        
        A+=B_temp/2+C_temp/2;
        B+=A_temp/2+C_temp/2;
        C+=A_temp/2+B_temp/2;
        
        roomcounter++;
        
        
    }
    
    printf("%d\n",roomcounter);
    
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
    int H,W;
    for(int k=0;;k++){

    scanf("%d %d",&H,&W);
        if(H==0 && W==0)break;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(j==0 || i==0 || i==H-1 || j==W-1){
                printf("#");
            }else{
                printf(".");
            }

            
        }printf("\n");
    }
        printf("\n");
    }
    return 0;
}



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

typedef pair<ll,ll> P;
const ll MO = 1000000007;

int main(){
    ll n,k;
    cin >> n >> k;
    vector<int>a(n),D(n+1,-1);
    // queue<ll> q;
    vector<int> q;

    rep(i,n){
        cin >> a[i];
        a[i];
    }
    int t = 1;
    // q.push_back(t);
    while(D[t]==-1){
        D[t]=q.size();
        q.push_back(t);
        // 飛び先
        t = a[t-1];
    }
    int lp = q.size() - D[t];
    int l = D[t];
    if(l>k){
        cout << q[k]<<endl;
        return 0;
    }
    else{
        k-=l;
        k%=(lp);
        cout << q[k+l]<< endl;
        return 0;
    }
}

Measured memory_bytes: 5892
#include <iostream>
using namespace std;
int main()
{
	int n, m;
	int s = 0;
	cin >> n >> m;
	int *a = new int[m];
	for (int i = 0; i < m; i++) {
		cin >> a[i];
		s += a[i];
	}
	if (s > n)  cout << "-1"; 
	else  cout << n - s; 
	return 0;
}


Measured memory_bytes: 3196
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793


vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main(){
  int N;
  cin >> N;
  map<ll, ll> mp;
  for(int i=2; i<=N; i++){
    for(auto p: prime_factorize(i)){
      mp[p.first] += p.second;
    }
  }
  int tmp[75] = {0};
  for(auto k: mp){
    if(k.second>=2) tmp[2]++;
    if(k.second>=4) tmp[4]++;
    if(k.second>=14) tmp[14]++;
    if(k.second>=24) tmp[24]++;
    if(k.second>=74) tmp[74]++;
  }
  int ans = 0;
  ans += tmp[74];
  ans += tmp[24]*(tmp[2]-1);
  ans += tmp[14]*(tmp[4]-1);
  ans += tmp[4]*(tmp[4]-1)*(tmp[2]-2)/2;
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(string, s);

    if (s == "RRR") {
        print(3);
    } else if (s == "RRS" || s == "SRR") {
        print(2);
    } else if (s == "SSS") {
        print(0);
    } else {
        print(1);
    }
    return 0;
}


Measured memory_bytes: 3648
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n:usize = iter.next().unwrap().parse().unwrap();
    let m:i32 = iter.next().unwrap().parse().unwrap();

    let mut accepted = vec![false; n];
    let mut penalty = vec![0; n];
    let mut acceptedNum = 0;
    let mut penaltyNum = 0;

    for _i in 0..m {
        let p:usize = iter.next().unwrap().parse::<usize>().unwrap() - 1;
        let s:&str = iter.next().unwrap();
        if accepted[p] { continue; }
        if s == "AC" {
            accepted[p] = true;
            penaltyNum += penalty[p];
            acceptedNum+=1;
        } else {
            penalty[p]+=1;
        }
    }

    println!("{} {}", acceptedNum, penaltyNum);
}


Measured memory_bytes: 4352
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!(k: i64);
    let n = 50;
    let mut a = vec![n as i64 - 1 + k / n as i64; n];
    let r = k % n as i64;
    for i in 0..r as usize {
        a[i] += n as i64 + 1;
    }
    for i in 0..n {
        a[i] -= r;
    }
    puts!("{}\n", n);
    for i in 0..n {
        puts!("{}{}", a[i], if i + 1 == n { "\n" } else { " " });
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

using namespace std;
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define MOD 1000000007
#define fix(n) cout << fixed << setprecision(n)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for(long i=a; i<=b; i++)
#define REN(i, a, b) for(long i=b; i>=a; i--)
// Debugging 
#define line cout << endl
#define out(n) cout << n << " "
#define bug(n) cout << n << "\n"
#define print(arr, start, end) REP(i, start, end) out(arr[i]); line

typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pi;
typedef map<int, int> mii;

///// General Purpose functions /////

/////////////////

void solve(){
	float D, T, S;
  	cin >> D >> T >> S;
  	
  	float t = D/S;
  
    if(T >= t)
      bug("Yes");
 	else
      bug("No"); 
}

void prep(){

}

int main()
{
	//code
	io;
	int t = 1;
	//cin >> t;
	prep();
	fix(12);
	while(t--){
	    solve();
	}
	
	return 0;
}

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

int main(int argc, const char * argv[]) {
    double a,b,C;
    double PI = acos(-1.0);
    double rad;
    
    double S,L,h;
    
    scanf("%lf %lf %lf",&a,&b,&C);
    
    rad = C * PI / 180;
    
    S = a * b * sin(rad) / 2;
    
    L = a + b + sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(rad));
    
    if(C==90){
        h=b;
    }else{
        h = b * sin(rad);
    }
    
    printf("%f\n",S);
    printf("%f\n",L);
    printf("%f\n",h);
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    ll a,b,c; cin >> a >> b >> c;

    set<ll> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);

    if(s.size() == 2) cout<< "Yes" << endl;
    else cout<< "No" << endl;

    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    ll n, x; cin >> n >> x;
    ll a[n];
    for(ll i = 0; i < n; i++){
        cin >> a[i];
    }
    ll cnt = 0;
    if(a[0] > x){
        cnt += a[0]-x;
        a[0] = x;
    }
    for(ll i = 1; i < n; i++){
        if(a[i-1] + a[i] > x){
            cnt += a[i-1]+a[i]-x;
            a[i] = x-a[i-1];
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;



int main() {
  int n;
  scanf("%d",&n);
  cout<<n*n<<endl;
  return 0;
}






















Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;

vector<pair<long long, long long>> prime_factorize(long long N)
{
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= N; ++a)
    {
        if (N % a != 0)
            continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0)
        {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1)
        res.push_back({N, 1});
    return res;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    const auto &res = prime_factorize(n);
    ll cnt = 0;
    for (auto p : res)
    {
        ll num = p.second;
        ll i = 1;
        while (num-i >= 0)
        {
            num -= i;
            i++;
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
 
using namespace std;
 
 
int main()
{
    
    int n,k;
    cin>>n>>k;
    int d[k];
     int i,a;
     set<int >s;
     int j;
     for(i=0;i<k;++i)
       {
           cin>>d[i];
           for(j=0;j<d[i];++j)
             {
                 cin>>a;
                 s.insert(a);
             }
       }
       
      cout<<n-s.size(); 
   
       
       
    
     
     return 0;   
    
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int n;
  cin >> n;
  map<int, int> mp;
  const int MOD = 1e9+7;
  REP(i,n){
    int a;
    cin >> a;
 	mp[a]++;
  }
  int ini = (n%2==0 ? 1 : 0);
  bool flag = false;
  for(int i=ini; i<n; i+=2){
    if((i==0 && mp[i]!=1) || (i>0 && mp[i]!=2)){
      flag = true;
      break;
    }
  }
  ll ans = 1;
  if(flag) ans = 0;
  else{
    REP(i,n/2){
      ans *= 2;
      ans = ans % MOD;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3200
S = list(input())
Y = S[0] + S[1]
M = S[2] + S[3]
if 1 <= int(M) and int(M) <= 12:
    if 1 <= int(Y) and int(Y) <= 12:
        print("AMBIGUOUS")

    elif int(Y) == 0 or int(Y) > 12:
        print("YYMM")

    else:
        pass
    
elif 1 <= int(Y) and int(Y) <= 12:
    print("MMYY")

else:
    print("NA")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long int
int main()
{
    int i,n,c1=0,c2=0;
    cin>>n;
    vector<int>v;
    for(i=n;i>0;i--)
        v.pb(i);
        for(i=0;i<v.size();i++)
        {
            if(v[i]%2)
                c1++;
            else
                c2++;
        }
        cout<<c1*c2<<endl;

    return 0;

}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)

def d(tree, array, v):
  next_v = tree.get(v)
  
  for nv, nd in next_v:
    if array[nv] == -1:
      array[nv] = array[v] + nd
      d(tree, array, nv)
  

n = int(input())
tree = {}

for i in range(n-1):
  a,b,c = map(int, input().split())
  a -= 1
  b -= 1
  
  array = tree.get(a, [])
  array.append((b,c))
  tree[a] = array
  
  array = tree.get(b, [])
  array.append((a,c))
  tree[b] = array
  
q,k = map(int, input().split())
k -= 1

array = [-1] * n
array[k] = 0

d(tree, array, k)

ans = []
for i in range(q):
  x, y = map(int, input().split())
  x -= 1
  y -= 1
  
  ans.append(array[x] + array[y])
  
for i in range(len(ans)):
  print(ans[i])

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

int counts = 0;
const int SENTINEL = 1000000005;

template<typename T>
void merge(vector<T> & A, int left, int mid, int right){
    auto n1 = mid - left;
    auto n2 = right - mid;
    vector<T> L(n1);
    vector<T> R(n2);
    copy(A.begin() + left, A.begin() + mid  , L.begin());
    copy(A.begin() + mid , A.begin() + right, R.begin());
    L.push_back(SENTINEL);
    R.push_back(SENTINEL);
    auto itL = L.begin();
    auto itR = R.begin();
    for (auto itA = A.begin() + left; itA != A.begin() + right; ++itA){
        if (*itL <= *itR){
            *itA = *itL;
            ++itL;
        }else{
            *itA = *itR;
            ++itR;
        }
    }
    counts += right - left;
}

template<typename T>
void merge_sort(vector<T> & A, int left, int right){
    if (left + 1 < right){
        auto mid = (left + right) / 2;
        merge_sort(A, left, mid);
        merge_sort(A, mid, right);
        merge(A, left, mid, right);
    }
}


int main()
{
    int n = 0;
    cin >> n;
    vector<int> A(n);
    for (auto & element : A) cin >> element;
    merge_sort(A, 0, n);
    cout << *A.begin();
    for (auto it = A.begin() + 1; it != A.end(); ++it) cout << ' ' << *it;
    cout << endl;
    cout << counts << endl;
    return 0;
}

Measured memory_bytes: 8568
main = do
  (n:x:_) <- getLine >>= return . map read . words :: IO [Int]
  as <- getLine >>= return . map read . words :: IO [Int]

  print $ solve as x

  where
    solve (a:as) x = sum $ zipWith (-) (a:as) (solve' ((if a<x then a else x) : as) x)

    solve' (a:[]) _ = [a]
    solve' (a:b:as) x = if a+b<=x then a : (solve' (b:as) x) else a : (solve' ((x-a):as) x)


Measured memory_bytes: 36220
n, m = list(map(int, input().split()))
list_gyouretsu = []
for i in range(n):
  g = list(map(int, input().split()))
  list_gyouretsu.append(g)
  g = []
list_gyou = []
for j in range(m):
  list_gyou.append(int(input()))
for k in range(n):
  sum = 0
  for l in range(m):
    sum += list_gyouretsu[k][l]*list_gyou[l]
  print(sum)


Measured memory_bytes: 6012
# AOJ 0048 Class
# Python3 2018.6.14 bal4u

r = [0.0,48.0,51.0,54.0,57.0,60.0,64.0,69.0,75.0,81.0,91.0,1000.0]
s = ["light fly","fly","bantam","feather","light","light welter","welter","light middle","middle","light heavy","heavy"]

while True:
	try:
		w = float(input())
	except EOFError:
		break
		
	for i in range(12):
		if r[i] < w and w <= r[i+1]:
		   print(s[i])
		   break


Measured memory_bytes: 5572
#include <iostream>
using namespace std;
int N,a[101],ans=987654321;
int main()
{
	cin >> N;
	
	for(int i=0; i<N; i++)
	cin >> a[i];
	
	for(int i=-100; i<=100; i++)
	{
		int cost=0;
		
		for(int j=0; j<N; j++)
		{
			cost+=(a[j]-i)*(a[j]-i);
		}
		ans=min(cost,ans);
	}
	cout << ans;
}

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

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

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

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
/*
	ID: Loxilante
	Time: 2020/08/29
	Prog: D
	Lang: cpp
*/
#ifdef ONLINE_JUDGE
#pragma GCC optimize("O3")
#endif
#include <bits/extc++.h>
#define rep(i, l, r) for(int i = l; i < r; i++)
#define hrp(i, l, r) for(int i = l; i <= r; i++)
#define rev(i, r, l) for(int i = r; i >= l; i--)
#define ms(n, t) memset(n, t, sizeof(n))
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...) 97
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn = int> inline tn next(void) { tn k; cin>>k; return k; }
const int U = 3e5;
int father[U];
inline int find(const int& k)
{
	if (father[k] == k) return k;
	return father[k] = find(father[k]);
}
inline void merge(int a, int b)
{
	if (a < b) swap(a, b);
	father[find(a)] = find(b);
}
int cnt[U];
signed main(void)
{
	clock_t Begin = clock();

	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m, ans = 0;
	cin>>n>>m;
	hrp(i, 1, n) father[i] = i; 
	while(m--)
	{
		int a, b;
		cin>>a>>b;
		merge(a, b);
	}
	
	clock_t InputFinished = clock();
	
	hrp(i, 1, n) cnt[find(i)]++;

	hrp(i, 1, n) if (cnt[i]) ans = max(ans, cnt[i]);

	cout<<ans<<endl;
	
	clock_t End = clock();
	
	D((double)(End-Begin)/CLOCKS_PER_SEC);
	D((double)(End-InputFinished)/CLOCKS_PER_SEC);
	
	return 0;
}
/*
10 10
1 2
2 3
3 4
5 6
4 5
7 8
8 9
9 10
10 9
1 10
 */


Measured memory_bytes: 6740
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int[] G => ReadLine().Split().Select(int.Parse).ToArray();
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int V, Mod;
	List<int>[] es;
	long[] dp0, dp1;
	void Solve()
	{
		var I = G;
		V = I[0];
		Mod = I[1];
		es = new List<int>[V];
		dp0 = new long[V];
		dp1 = new long[V];
		for (var u = 0; u < V; u++) es[u] = new List<int>();
		for (var e = 0; e < V - 1; e++)
		{
			I = G;
			es[I[0] - 1].Add(I[1] - 1);
			es[I[1] - 1].Add(I[0] - 1);
		}
		x = new long[V + 1];
		y = new long[V + 1];
		DFS0(0, -1);
		DFS1(0);
		for (var u = 0; u < V; u++) WriteLine(dp0[u] * (dp1[u] + 1) % Mod);
	}
	long DFS0(int u, int p)
	{
		dp0[u] = 1L;
		es[u].Remove(p);
		foreach (var v in es[u]) dp0[u] = dp0[u] * (DFS0(v, u) + 1) % Mod;
		return dp0[u];
	}
	long[] x, y;
	void DFS1(int u)
	{
		var W = es[u].Count;
		x[0] = y[W] = 1;
		for (var i = 0; i < W; i++) x[i + 1] = x[i] * (dp0[es[u][i]] + 1) % Mod;
		for (var i = W - 1; i >= 0; i--) y[i] = y[i + 1] * (dp0[es[u][i]] + 1) % Mod;
		for (var i = 0; i < W; i++) dp1[es[u][i]] = (dp1[u] + 1) * x[i] % Mod * y[i + 1] % Mod;
		foreach (var v in es[u]) DFS1(v);
	}
}


Measured memory_bytes: 42368