akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
	class Program
	{
		public static void Main()
		{
			var taskNum = IO.ReadInt();
			var taskGroup = Enumerable.Range(0 , taskNum).Select(iIndex =>
			{
				var intArray = IO.ReadLongArray();
				return new
				{
					Time = intArray[0],
					Limit = intArray[1]
				};
			})
			.GroupBy(iTask => iTask.Limit)
			.OrderBy(iGroup => iGroup.Key);

			var time = 0L;
			var isOK = true;
			foreach(var iGroup in taskGroup)
			{
				var useTime = iGroup.Sum(iTask => iTask.Time);
				time += useTime;
				if(time > iGroup.Key)
				{
					isOK = false;
					break;
				}
			}
			IO.Write(isOK);
		}
	}

	public static class IO
	{
		public static string   Read()							   { return Console.ReadLine(); }
		public static string[] ReadArray(char iSplitter = ' ')	   { return Read().Split(iSplitter); }
		public static int	   ReadInt()						   { return int.Parse(Read()); }
		public static int[]	   ReadIntArray(char iSplitter = ' ')  { return ReadArray().Select(iText => int.Parse(iText)).ToArray(); }
		public static long	   ReadLong()						   { return int.Parse(Read()); }
		public static long[]   ReadLongArray(char iSplitter = ' ') { return ReadArray().Select(iText => long.Parse(iText)).ToArray(); }
		public static char[]   ReadCharArray()					   { return Read().ToCharArray(); }

		public static void Write(string iValue)			  { Console.WriteLine(iValue); }
		public static void Write(int iValue)			  { Console.WriteLine(iValue); }
		public static void Write(IEnumerable<int> iValue) { Console.WriteLine(string.Join(" " , iValue)); }
		public static void Write(long iValue)			  { Console.WriteLine(iValue); }
		public static void Write(decimal iValue)		  { Console.WriteLine(iValue); }
		public static void Write(bool iValue)			  { Console.WriteLine(iValue ? "Yes" : "No"); }
	}

	public static class Util
	{
		public static long Gcd(long i0 , long i1) { return (i0 > i1) ? _Gcd(i0 , i1) : _Gcd(i0 , i1); }
		public static long Lcm(long i0 , long i1) { return (i0 * i1) / Gcd(i0 , i1); }
		public static long ModPow(long iBaseNumber , long iPow , long iModNumber)
		{
			var num = 1L;
			while(iPow != 0)
			{
				if((iPow & 0x1) != 0)
				{
					num = (num * iBaseNumber) % iModNumber;
				}
				iBaseNumber = (iBaseNumber * iBaseNumber) % iModNumber;
				iPow >>= 1;
			}
			return num;
		}

		private static long _Gcd(long i0 , long i1)	{ return (i1 == 0) ? i0 : _Gcd(i1 , i0 % i1); }
	}
}


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

int main() {
	int A, B;
  	cin >> A >> B;
  	
  	int total = 0;
  	for(int i = 0; i < A; i++){
      total += B + i;
    }
    
  	if( B >= 0 ) cout << total - B << endl;
  	else if( B < 0 && A + B -1 > 0) cout << total << endl;
    else cout << total - (B  + A - 1)  << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INF 1000000000000000000
#define MOD 1000000007
#define MAX 3000000
using Graph=vector<vector<int>>;

int main(){
  int N,Z,W;
  cin>>N>>Z>>W;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }

  vector<vector<int>> dp(N,vector<int>(N));
  for(int i=0;i<N-1;i++){
    dp.at(i).at(N-1)=abs(a.at(i)-a.at(N-1));
  }
  for(int j=0;j<N-1;j++){
    dp.at(N-1).at(j)=abs(a.at(N-1)-a.at(j));
  }

  if(N==1){
    cout<<abs(W-a.at(N-1))<<endl;
  }else{
    cout<<max(abs(W-a.at(N-1)),abs(a.at(N-1)-a.at(N-2)))<<endl;
  }
}


Measured memory_bytes: 16000
n = int(input())
a = [int(k) for k in input().split()]

def gcd(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x
ans = gcd(a[0],a[1])
for i in a[2:]:
	ans = gcd(ans,i)
print(ans)

Measured memory_bytes: 14224
#include <stdio.h>

int main(void)
{
  int item[100];
  int a, b, t;
  int count,x=0;
  scanf("%d",&count);
  for(a = 0; a < count; a++){
    scanf("%d", &item[a]);
  }
  
  for(a = 1; a < count; a++){
   for(b = count - 1; b >= a; b--){
     if(item[b] < item[b-1]){
       t = item[b];
       item[b] = item[b-1];
       item[b-1] = t;
       x++;
     }
   }
  }
  
  for(a = 0; a < count; a++){
    if(a == count -1)printf("%d\n", item[a]);
    else printf("%d ", item[a]);
  }
  printf("%d\n",x);
  return 0;
}

Measured memory_bytes: 600
N,C = map(int,input().split())
wrongness = [list(map(int,input().split())) for x in range(C)]
grid = [list(map(int,input().split())) for x in range(N)]

choices = [[0 for x in range(C)] for x in range(3)]
for i in range(N):
    for j in range(N):
        choices[(i+j)%3][grid[j][i]-1] += 1

ans = 10**18
for i in range(C):    
    for j in range(C):
        if j == i:
            continue
        for k in range(C):
            if k != i and k != j:
                temp = 0
                for l in range(C):
                    temp += wrongness[l][i]*choices[0][l]
                    temp += wrongness[l][j]*choices[1][l]
                    temp += wrongness[l][k]*choices[2][l]
                ans = min(ans,temp)

print(ans)
    


Measured memory_bytes: 5620
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

int main() {
	uint64_t N, M, A, B, count = 0;
	map<uint64_t, uint64_t> mp;
	cin >> N >> M;
	for (uint64_t i = 0; i < N; i++) {
		cin >> A >> B;
		mp[A] += B;
	}

	map<uint64_t, uint64_t>::iterator it;

	for (it = mp.begin(); it != mp.end(); it++) {
		if (M > it->second) {
			count += it->first * it->second;
			M -= it->second;
		}
		else {
			count += M * it->first;
			break;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 6528
N = gets.to_i
h = []
h = gets.split.map(&:to_i)

d = 0
low = 0
1.upto (N-1) do |i|
  d = h[i] - h[i-1]
  # 減少したor変わらない場合のみなんかする
  if d <= 0
    low += (-d)
    if low >= 2
      puts "No"
      exit
    end
  else
    low = 0
  end
end
puts "Yes"

Measured memory_bytes: 8580
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int N;
    cin >> N;
    ul orig[N] = {};
    unsigned int X[N] = {};
    for(int i = 0; i < N; i++){
        cin >> X[i];
        orig[i] = X[i];
    }
    sort(X, X+N);
    ul medS = X[N/2 - 1];
    ul medL = X[N/2];
    for(int i = 0; i < N; i++){
        ul ans = 0;
        if(orig[i] <= medS){
            ans = medL;
        }else{
            ans = medS;
        }
        cout << ans << endl;
    }

}

Measured memory_bytes: 4608
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root = {NIL, NIL};

Node treeMinimum(Node x);
Node treeMaximum(Node x);
Node treeSuccessor(Node x);
void treeDelete(Node z);
void inorder( Node );
void preorder( Node );
void insert( int );
Node treeSearch( Node, int );

//-----------------------------------------------------------
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }/* else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }*/
  }

  return 0;
}
/*
//----------------------------------------------------------
Node treeMinimum(Node x){


}

//------------------------------------------------------------
Node treeMaximum(Node x){


}
*/
//----------------------------------------------------------
Node treeSearch(Node u, int k){
    while(u != NIL){
	if(k == u->key) return u;
	else if(k < u->key) u = u->left;
	else u = u->right;
    }
    return NIL;
}

//----------------------------------------------------------
/*
Node treeSuccessor(Node x){


}

//----------------------------------------------------------
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}*/

//-----------------------------------------------------------
void insert(int k){
  Node y = NIL;   //y is parent of the k 
  Node x = root;   //x is the root node
  Node z;   //z is new node for the k

  //initialization
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  //decide where to place the z node
  while(x != NIL){  //when Binary Tree T is not empty.
      y = x;  //substitute x for y as a parent
      if(z->key < x->key) x = x->left;
      else  x = x->right;
  }
  z->parent = y;
  //connect them
  if(y == NIL) root = z;//when Binary Tree T is empty
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

//-------------------------------------------------------------
void inorder(Node u){
    if(u != NIL){
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
    }
    return ;
}

//-------------------------------------------------------------
void preorder(Node u){
    if(u != NIL){
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
    }
    return ;
}



Measured memory_bytes: 20452
import java.util.Scanner;

public class Main {

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

    int N = scanner.nextInt();

    for (int i = 0; i < N; i++) {
      int a = scanner.nextInt();
      int b = scanner.nextInt();
      int c = scanner.nextInt();

      if ((a * a + b * b == c * c) ||
          (a * a + c * c == b * b) ||
          (c * c + b * b == a * a)) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    }
  }

}



Measured memory_bytes: 33064
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	int N, M;
	cin >> N >> M;

	vector<pair<int, int>> sc(M);
	for (int i = 0; i < M; i++) cin >> sc[i].first >> sc[i].second;

	for (int i = 0; i < 1000; i++) {
		string si = to_string(i);
		if (si.size() != N) continue;
		bool ok = true;
		for (const auto& [s, c] : sc) {
			if (si.size() >= s) {
				ok &= si[s - 1] == c + '0';
			}
			else {
				ok = false;
				break;
			}
		}
		if (ok) {
			cout << i << "\n";
			return 0;
		}
	}

	cout << -1 << "\n";

	return 0;
}



Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;	
		


int32_t main()
{   
	IOS
	int n;cin>>n;
	//int _5 = n/5;
	//int _3 = n/3;
	//int _15 = n/15;
	//cout << n*(n+1)/2 - _5*(2*5+(_5-1)*5)/2 - _3*(2*3+(_3-1)*3)/2 + _15*(2*15-(_15-1)*15)/2 <<endl;
	int sum = 0;
	for(int i=1;i<=n;i++){
		if( i%5==0 || i%3==0 )continue;
		sum+=i;
	}
	cout<<sum<<endl;
}





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

#define int long long

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

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

	int n;
	cin >> n;

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

	sort(a.begin(), a.end(), greater<int>());

	int res = a[0], j = 1, c = 0;
	for (int i = 1; i < n - 1; ++i) {
		res += a[j];
		++c;
		if (c == 2) {
			++j;
			c = 0;
		}
	}

	cout << res;

	return 0;
}

Measured memory_bytes: 4764
from collections import defaultdict
N = int(input())
a = defaultdict(list)
for i in range(N):
    s, p = map(str, input().split())
    a[s].append([int(p),int(i+1)])
a = sorted(a.items())
for b in a:
    b[1].sort(reverse=True)
    for c in b[1]:
        print(c[1])


Measured memory_bytes: 3316
#include <bits/stdc++.h>
            #include<iostream>
            #include<cstdio>
            #include<vector>
            #include<queue>
            #include<map>
            #include<cstring>
            #include<string>
            #include <math.h>
            #include<algorithm>
        //    #include <boost/multiprecision/cpp_int.hpp>
            #include<functional>
          #define int long long
            #define inf  1000000007
            #define pa pair<int,int>
    #define ll long long
            #define pal pair<ll,ll>
            #define ppa pair<int,pa>
            #define  mp make_pair
            #define  pb push_back
            #define EPS (1e-10)
            #define equals(a,b) (fabs((a)-(b))<EPS)
     
            using namespace std;
     
            class Point{
            	public:
            	double x,y;
            	Point(double x=0,double y=0):x(x),y(y) {}
            	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
            	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
            	Point operator * (double a) {return Point(x*a,y*a);}
            	Point operator / (double a) {return Point(x/a,y/a);}
            	double absv() {return sqrt(norm());}
            	double norm() {return x*x+y*y;}
            	bool operator < (const Point &p) const{
            		return x != p.x ? x<p.x: y<p.y;
            	}
            	bool operator == (const Point &p) const{
            		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
            	}
            };
            typedef Point Vector;
     
            struct Segment{
            Point p1,p2;
            };
     
        double hen(Vector a){
        if(fabs(a.x)<EPS && a.y>0) return acos(0);
        else if(fabs(a.x)<EPS && a.y<0) return 3*acos(0);
        else if(fabs(a.y)<EPS && a.x<0) return 2*acos(0);
        else if(fabs(a.y)<EPS && a.x>0) return 0.0;
        else if(a.y>0) return acos(a.x/a.absv());
        else return 2*acos(0)+acos(-a.x/a.absv());
     
        }
     
int gcd(int v,int b){
	if(v>b) return gcd(b,v);
	if(v==b) return b;
	if(b%v==0) return v;
	return gcd(v,b%v);
}
            double dot(Vector a,Vector b){
            	return a.x*b.x+a.y*b.y;
            }
            double cross(Vector a,Vector b){
            	return a.x*b.y-a.y*b.x;
            }
        
            //----------------kokomade tenpure------------

int dp[400][400][400]={0};
    signed main(){
	
	dp[0][1][1]=1;
    	
    	int n,m;
    	cin>>n>>m;
    	
    	for(int i=0;i<=m;i++)for(int j=1;j<=i+1;j++)for(int k=1;k<=j;k++){
    	//	cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl; 
    		int u=dp[i][j][k];
    		
    		dp[i+1][j][j] += k*u;
    		dp[i+1][j][j] %= inf;
    		dp[i+1][j][k] += (j-k)*u;
    		dp[i+1][j][k] %= inf;
    		dp[i+1][j+1][k] += (n-j)*u;
    		dp[i+1][j+1][k] %=inf;
    	}
    
    
    	
    	cout<<dp[m][n][n]<<endl;
    	
    //	printf("%.10f\n",ans);
    	return 0;
    }

Measured memory_bytes: 144128
X, K, D = map(int, input().split())

ans = 0
if abs(X) >= K*D:
    ans = abs(X) - K*D
else:
    if (K - abs(X)//D)%2 == 0:
        ans = abs(X)%D
    else:
        ans = D - abs(X)%D

print(ans)

Measured memory_bytes: 9124
#include <bits/stdc++.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

string s;
int ans;

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

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

	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
int A,B;
int P[104];
int a[4];
int main(){
	cin >> N;
	cin >> A >> B;
	for(int i=0;i<N;i++){
		cin >> P[i];
		if(P[i]<=A)a[0]++;
		else if(P[i]<=B)a[1]++;
		else a[2]++;
	}
	cout << min(min(a[0],a[1]),a[2]) << endl;
	return 0;
}

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

int N,M;

bool d[100001];
int v[100001];
vector<pair<int,int>>e[100001];

void dfs(int i){
	d[i]=true;
	for(auto a:e[i]){
		if(d[a.first]){
			if(v[i]+a.second!=v[a.first]){
				cout<<"No";
				exit(0);
			}
		}else{
			v[a.first]=v[i]+a.second;
			dfs(a.first);
		}
	}
}

main(){
	cin>>N>>M;
	for(int i=0;i<M;++i){
		int L,R,D;
		cin>>L>>R>>D;
		e[L].push_back({R,D});
		e[R].push_back({L,-D});
	}
	for(int i=1;i<=N;++i){
		if(!d[i]){
			dfs(i);
		}
	}
	cout<<"Yes";
}


Measured memory_bytes: 11136
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TupleSections         #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    cs <- getLine
    putStrLn.maybe"-1"id $ solve cs

solve :: String -> Maybe String
solve cs
  | length cs < 26 = Just $ cs ++ take 1 [c | c<-['a'..], notElem c cs]
  | otherwise = runST $ do
      mv <- U.thaw $ U.fromList cs
      hasNext <- nextPermutation mv
      if hasNext
      then do
          ps <- U.toList <$> U.freeze mv
          return . Just . head . filter(>cs) $ inits ps
      else return Nothing

nothing :: Int
nothing = -1

nextPermutation :: (PrimMonad m, Ord a, GM.MVector v a) => v (PrimState m) a -> m Bool
nextPermutation v = do
    h <- GM.unsafeRead v 0
    (k, l) <- go nothing h nothing h 1
    if k /= nothing
    then do
        GM.unsafeSwap v k l
        GM.reverse $ GM.unsafeSlice (k+1) (n-k-1) v
        return True
    else return False
  where
    !n = GM.length v
    go !k !vk !l !prev !i
      | i < n = do
          vi <- GM.unsafeRead v i
          if prev < vi
          then go (i-1) prev i vi (i+1)
          else if vk < vi
          then go k vk i vi (i + 1)
          else go k vk l vi (i + 1)
      | otherwise = return (k, l)

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

long long n;
vector<long long> v;
string s;

void solve();

int main() {
  cin >> n;
  solve();
  return 0;
}

void solve() {
  long long l = 0, r = n - 1;
  bool gend = 0;
  v.assign(n, 0);
  cout << 0 << endl;
  cin >> s;
  gend = s == "Male";
  while(s != "Vacant") {
    long long now = (l + r) / 2;
    if(r - l == 1) now = r;
    bool nowgend = 0;
    cout << now << endl;
    cin >> s;
    nowgend = s == "Male";
    if((nowgend ^ (now - l) % 2) == gend) {
      l = now;
      gend = nowgend;
    }
    else
      r = now;
  }
}


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


void solve(long long A, long long B, long long C){
    cout << (A xor B xor C) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

	int n, i, j;
	int r, rmax,rmin;

	scanf("%d",&n);

	int R[200000];

	for(i = 0; i < n; i++){
		scanf("%d",&R[i]);
	}

	
	rmax = -1000000000;
	rmin = R[0];

	for(i = 1; i < n; i++){
		int x;
		x = R[i] - rmin;
		if(x > rmax) rmax = x;

		if(rmin > R[i]) rmin = R[i];
	}

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


	return 0;
}

Measured memory_bytes: 1804
package main

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

func main() {
	log.SetFlags(log.Lshortfile)
	N := nextInt()
	a := nextInts(N)
	sama := Sum(a)
	p := float64(sama) / float64(N)
	l := p * 2
	idx := 0
	for i := 0; i < N; i++ {
		if l > Abs(float64(a[i])-p) {
			idx = i
			l = Abs(float64(a[i]) - p)
		}
	}
	fmt.Println(idx)
}
func Max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func Min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func Sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func Abs(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	return p[i].b < p[j].b
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

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

		while (true) {
			final int n = sc.nextInt();
			final int k = sc.nextInt();
			
			if(n == 0 && k == 0){
				break;
			}
			
			int[][] adj = new int[n][n];
			
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					adj[i][j] = Integer.MAX_VALUE / 4;
				}
			}
			
			for(int i = 0; i < k; i++){
				final int op = sc.nextInt();
				if(op == 0){
					final int a = sc.nextInt() - 1;
					final int b = sc.nextInt() - 1;
					
					System.out.println(adj[a][b] == Integer.MAX_VALUE / 4 ? -1 : adj[a][b]);
				}else{
					final int c = sc.nextInt() - 1;
					final int d = sc.nextInt() - 1;
					final int e = sc.nextInt();
					
					int old = adj[c][d];
					
					if(old <= e){
						continue;
					}
					adj[c][d] = e;
					adj[d][c] = e;
					
					final int min = Math.min(c, d);
					final int max = Math.max(c, d);
					
					for(int ii = 0; ii < n; ii++){
						for(int j = 0; j < n; j++){
							adj[ii][j] = Math.min(adj[ii][j], adj[ii][min] + adj[min][j]);
						}
					}
					
					for(int ii = 0; ii < n; ii++){
						for(int j = 0; j < n; j++){
							adj[ii][j] = Math.min(adj[ii][j], adj[ii][max] + adj[max][j]);
						}
					}
				}
			}
			
		}
	}

}

Measured memory_bytes: 49172
import java.util.Scanner;
class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);

	int n = sc.nextInt();
	int[] X = new int[n];
	int[] T = new int[2021];

	for(int i=0;i<2021;i++){
	    T[i] = 0;
	}
	T[2020] = 1;
	for(int i=0;i<n;i++){
	    X[i] = sc.nextInt();
	    T[X[i]] = 1; 
	}
	int m = sc.nextInt();
	int[] A = new int[m];

	for(int i=0;i<m;i++){
	    A[i] = sc.nextInt();
	}

	for(int i=0;i<m;i++){
	    if(T[X[A[i]-1] +1] == 1 || X[A[i]-1] +1 == 2020){
		//System.out.print(X[A[i]-1]);
		//System.out.print(T[X[A[i]-1]]);
		continue;
	    }else{
		T[X[A[i]-1]+1] = 1;
		T[X[A[i]-1]] = 0;	
		X[A[i]-1] += 1;
	    }
	}

	for(int i=0;i<n;i++){
	    System.out.println(X[i]);
	}
    }

}



Measured memory_bytes: 26436
import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    var arr = scan.nextLine().split(" ").map{ it.trim().toInt() }.toTypedArray()
    var a=arr[0]
    var b=arr[1]

    var x=(a*(a-1)/2)
    var y =(b*(b-1)/2)
    println(x+y)
}


Measured memory_bytes: 34044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
 
int main(){
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    ll p[A], q[B], r[C];
    for(int i=0;i<A;i++)    // 赤色
        cin >> p[i];
    for(int i=0;i<B;i++)    // 緑色
        cin >> q[i];
    for(int i=0;i<C;i++)    // 無色
        cin >> r[i];

    // 降順ソート
    sort(p, p + A, greater<ll>());
    sort(q, q + B, greater<ll>());
    sort(r, r + C, greater<ll>());

    // 着色しない場合
    ll sum = 0;
    for(int i=0;i<X;i++)    // 赤色をX個
        sum += p[i];
    for(int i=0;i<Y;i++)    // 緑色をY個
        sum += q[i];

    ll dp[X+Y+1];
    dp[0] = sum;
    int red = X-1, green = Y-1, white = 0;
    for(int i=1;i<=min(X+Y, C);i++){
        dp[i] = dp[i-1];
        if(red >= 0 && white >= 0){
            dp[i] = max(dp[i], dp[i-1] - p[red] + r[white]);
        }
        if(green >= 0 && white >= 0){
            dp[i] = max(dp[i], dp[i-1] - q[green] + r[white]);
        }

        if(red >= 0 && white >= 0){
            if(dp[i] == dp[i-1] - p[red] + r[white]){
                red--;
                white++;
            }
        }
        if(green >= 0 && white >= 0){
            if(dp[i] == dp[i-1] - q[green] + r[white]){
                green--;
                white++;
            }
        }
        //cout << dp[i] << endl;
    }

    cout << dp[min(X+Y, C)] << endl;

}

Measured memory_bytes: 3328
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(A) A.begin(), A.end() 
typedef long long ll;
const ll mod = 1e9 + 7;
const ll inf = 1e9;

int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, 0, N) cin >> L[i];

    sort(all(L));
    int ans = 0;
    rep(i, 0, N) {
        rep(j, i+1, N) {
            int k = lower_bound(all(L), L[i] + L[j]) - L.begin();
            ans += max(k - j - 1, 0);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

size_t N, a, b;
int M;
vector<vector<size_t>> pass;
int cnt = 0;
vector<bool> used;

void dfs(size_t p)
{
    used[p] = true;
    for (size_t q : pass[p]) {
        if (!used[q]) {
            dfs(q);
        }
    }
}


int main()
{
    cin >> N >> M;
    pass.resize(N);
    used.resize(N);
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        pass[a - 1].push_back(b - 1);
        pass[b - 1].push_back(a - 1);
    }

    for (size_t i = 0; i < N; i++) {
        for (size_t j = 0; j < pass[i].size(); j++) {
            for (size_t k = 0; k < N; k++) {
                used[k] = false;
            }

            size_t r = pass[i].back();
            pass[i].pop_back();

            dfs(0);
            for (size_t p = 0; p < N; p++) {
                if (!used[p]) {
                    cnt++;
                    break;
                }
            }

            pass[i].insert(pass[i].begin(), r);
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define FINOUT freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
#define FOR(i, a, b) for (int i = a; i < (b); ++i)
#define FORd(i, a, b) for(int i = (b) - 1; i >= a; --i)
#define trav(a, x) for(auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end() 
#define endl '\n'
const int MOD = 1000000007;
  
int main(){
    IOS;
    // FINOUT;
    int T = 1;
    // cin >> T;
    while(T--){
        int x;
        cin >> x;
        cout << (x >= 30 ? "Yes" : "No");
    }
    return 0;
}

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


typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#define pb push_back
#define popb pop_back
#define si size()
#define be begin()
#define en end()
#define le length()
// #define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define forz(i,n) for( int i=0;i<n;i++)
#define forl(i, n) for(int i = 1; i<= n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)

using namespace std;

void cpc()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w" , stdout);
#endif
}

int main()
{
	// cpc();
	lli n, m, sum = 0;
	cin >> n >> m;
	std::vector<lli> v(m);
	forz(i, m)
	{
		cin >> v[i];
		sum += v[i];
	}
	if (sum > n)
	{
		cout << "-1" << endl;
	}
	else
		cout << n - sum << endl;

	return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1001001001;
int main(){
  int N,Y;
  cin>>N>>Y;
  for(int a=0;a<=N;a++){
    for(int b=0;b<=N-a;b++){
     int c=N-a-b;
     if(10000*a+5000*b+1000*c==Y){
       cout<<a<<" "<<b<<" "<<c<<endl;return 0;}
    }
  }
  cout<<-1<<" "<<-1<<" "<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
// Problem : D - Xor Sum
// Contest : AtCoder Regular Contest 066
// URL : https://atcoder.jp/contests/arc066/tasks/arc066_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <iostream>
#include <map>
#define MOD 1000000007
using namespace std;
map<long long,long long> f;
long long dfs(long long x)
{
 if(f[x])return f[x];
 else return f[x]=(dfs(x/2)+dfs((x-1)/2)+dfs((x-2)/2))%MOD;
}
int main()
{
 long long n;
 cin>>n;
 f[0]=1,f[1]=2;
 cout<<dfs(n)<<endl;
 return 0;
}

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

int main(){
  long long n;
  cin >> n;
  long long a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
    if(a[i] == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  unsigned long long ans=1;
  
  for(int j=0; j<n; j++){
    if(a[j]<=1000000000000000000/ans){
    ans*=a[j];
  } else {
    cout << -1 << endl;
    return 0;
  }
  }
cout << ans << endl;  
}


Measured memory_bytes: 4392
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  int a, b; cin>>a>>b;
  if(a+b<10){
    cout<<a+b<<endl;
  }else{
    cout<<"error"<<endl;
  }


}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long goal = sc.nextLong();
    long yen = 100;
    int ans = 0;
    while(yen < goal) {
      yen = yen + (yen / 100);
      ans++;
    }
    System.out.println(ans);
  }
}

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

struct Node{
	int p, q;
};

const int N = 1e5 + 10;

Node a[N];
long long sum[N];
priority_queue <int, vector <int>, greater <int> > pq;

bool cmp(const Node& x, const Node& y){
	return x.p - x.q < y.p - y.q;
}

int main(){
	int x, y, z, n, n1, n2, n3;
	long long ans, rec, maxx;
	scanf("%d %d %d",&x,&y,&z);
	n = x + y + z;
	ans = 0;
	for (int i = 1; i <= n; i++){
		scanf("%d %d %d",&n1,&n2,&n3);
		a[i].p = n1 - n3; a[i].q = n2 - n3;
		ans += n3;
	}
	sort(a + 1, a + n + 1, cmp);
	memset(sum, 0, sizeof(sum));
	rec = 0;
	for (int i = 1; i <= y; i++){
		pq.push(a[i].q);
		rec += a[i].q;
	}
	sum[y] = rec;
	for (int i = y + 1; i <= n - x; i++){
		if (a[i].q > pq.top()){
			rec += a[i].q - pq.top();
			pq.pop();
			pq.push(a[i].q);
		}
		sum[i] = rec;
	}
	while (!pq.empty()) pq.pop();
	rec = 0;
	for (int i = n; i >= n - x + 1; i--){
		pq.push(a[i].p);
		rec += a[i].p;
	}
	sum[n - x] += rec;
	for (int i = n - x; i > y; i--){
		if (a[i].p > pq.top()){
			rec += a[i].p - pq.top();
			pq.pop();
			pq.push(a[i].p);
		}
		sum[i - 1] += rec;
	}
	maxx = -1e18;
	for (int i = y; i <= n - x; i++) maxx = max(maxx, sum[i]);
	ans += maxx;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2428
'''
方針
    1 ～ 10^6(Aの最大値) までの全ての数について、割り切れる数をカウント
    カウント == 1 ならば、他の数では割り切れないので、そのような数の個数が答え

工夫
    そのままの実装では、最悪ケース : 1 1 1 1 ... で、TLEする
    対策として、
        1. Aを昇順ソートする
        2. A[i]がA[i-1]と同じならば、2倍以上の倍数についてはスキップ
    とする
'''

import numpy as np

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    d = np.zeros(A[-1]+1, dtype=np.uint64)  # 約数カウント。配列長さは、Aの最大値+1 で十分
    for i in range(N):
        a = A[i]
        a1 = A[i-1]
        if a != a1:     # 初出の数なら
            d[a::a] += 1    # aからaごとに+1する (範囲内の全ての倍数に、約数カウント+1)
        else:           # 重複なら
            d[a] += 1       # 自身のカウントを上げるだけで十分 (2倍以上はスキップ)
    print(np.count_nonzero(d[A] == 1))  # Aのうち、約数カウントが1となったものの個数が答え

main()



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

int main()
{
  string words[3];
  for(int i = 0; i < 3; ++i)
  {
    cin >> words[i];
  }
  char initisls[3];
  for(int i = 0; i < 3; ++i)
  {
      initisls[i] = words[i].front();
  }
  	cout << initisls << endl;
}


Measured memory_bytes: 3612
import sys
import numpy as np
from collections import defaultdict

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = np.array([0] + lr())
A = (A-1) % K
Acum = A.cumsum() % K
counter = defaultdict(int)
answer = 0
for i, x in enumerate(Acum):
    answer += counter[x]
    counter[x] += 1
    if i >= K-1:
        counter[Acum[i-(K-1)]] -= 1

print(answer)


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

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

	unsigned long long debt = 100000;
	while(n--)
	{
		debt += debt * 0.05;
		if(debt % 1000)
			debt += 1000 - debt % 1000;
	}

	cout << debt << endl;

	return 0;
}

Measured memory_bytes: 1156
from itertools import permutations

n,m = map(int,input().split())
D = [[0]*n for i in range(n)]
for i in range(m):
	a,b = map(int,input().split())
	D[a-1][b-1] = 1
	D[b-1][a-1] = 1
cnt = 0
for a in permutations(range(n)):
	if a[0] != 0:
		break
	tmp = 1
	for i in range(n-1):
		tmp = tmp * D[a[i]][a[i+1]]
	cnt += tmp
print(cnt)

Measured memory_bytes: 3064
from itertools import product
import bisect
N=int(input())
A=[]
for n in range(3,len(str(N))+1):
    for s in product([3,5,7], repeat=n):
        if '3' in ''.join(map(str, s)) and '5' in ''.join(map(str, s)) and '7' in ''.join(map(str, s)):
            A.append(int(''.join(map(str, s))))
print(bisect.bisect_right(A,N))

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

using namespace std;

typedef long long ll;

const ll N = 2e5+5;
ll a[N], dp[N][5];

int main(){
    ll L, i;
    while(scanf("%lld", &L) != EOF){
        for(i = 1; i <= L; i++) scanf("%lld", &a[i]);
        for(i = 0; i <= 4; i++) dp[0][i] = 0;
        for(i = 1; i <= L; i++){
            dp[i][0] = dp[i-1][0]+a[i];
            ll mindp = min(dp[i-1][0], dp[i-1][1]);
            if(a[i]%2) dp[i][1] = mindp+1;
            else if(a[i]==0) dp[i][1] = mindp+2;
            else dp[i][1] = mindp;
            mindp = min(mindp, dp[i-1][2]);
            dp[i][2] = mindp+(a[i]%2==0);
            mindp = min(mindp, dp[i-1][3]);
            if(a[i]%2) dp[i][3] = mindp+1;
            else if(a[i]==0) dp[i][3] = mindp+2;
            else dp[i][3] = mindp;
            mindp = min(mindp, dp[i-1][4]);
            dp[i][4] = mindp+a[i];
        }

        ll ans = dp[L][0];
        for(i = 1; i <= 4; i++) ans = min(ans, dp[L][i]);
        printf("%lld\n", ans);
    }

    return 0;
}

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

int main() {
  int n; string s; cin >>n >>s;
  // int cut = 0; //ここまでをXとする。これより後がY
  int ans = 0;
  int cnt;
  vector<int> check(26); //アルファベットが確認出来たら1
  for (int cut=0; cut<=n-2; cut++){
    cnt = 0;
    check = vector<int> (26,0);
    for (int i=0; i<=cut; i++){
      if (check.at(s.at(i)-'a')==1) continue;
      check.at(s.at(i)-'a') = 1;
      for (int j=cut+1; j<n; j++){
        if (s.at(i)==s.at(j)){
          cnt++; break;
        }
      }
    }
    if (cnt>ans) ans = cnt;
  }
  
  
  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e5+1;
int dist[nmax];
bool visited[nmax];
vector<int> adj[nmax];
	
int indegree[nmax];
void dfs(int a){
	visited[a]=true;
	for(auto i:adj[a]){
		dist[i]=max(dist[i],dist[a]+1);
		indegree[i]--;
		if(indegree[i]==0){
			dfs(i);
		}
	}
}
int main(){
	int n,e;
	cin>>n>>e;

	while(e--){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		indegree[y]++;
	}

	for(int i=0;i<=n;i++){
		if(!visited[i]&&indegree[i]==0){
			dfs(i);
		}
	}
	int maxs=0;
	for(int i=0;i<=n;i++){
		maxs=max(dist[i],maxs);
	}
	cout<<maxs<<endl;
}

Measured memory_bytes: 9728
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a){return parent[a]!=a?parent[a]=find(parent[a]):a;}
	bool same(int a,int b){return find(a)==find(b);}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
};
int N,M,Q;
vector<pair<int,pair<int,int> > >E;
vector<pair<int,int> >G[4001];
int T[4001][4001];
void dfs(int u,int p,int now,int f)
{
	T[f][u]=now;
	for(pair<int,int>q:G[u])if(q.first!=p)dfs(q.first,u,max(now,q.second),f);
}
main()
{
	cin>>N>>M;
	for(int i=0;i<M;i++)
	{
		int a,b,c;cin>>a>>b>>c;
		E.push_back({c,{a,b}});
	}
	sort(E.begin(),E.end());
	UF uf(N+1);
	long sum=0;
	for(pair<int,pair<int,int> >p:E)
	{
		int u=p.second.first,v=p.second.second;
		if(uf.unite(u,v))
		{
			sum+=p.first;
			G[u].push_back({v,p.first});
			G[v].push_back({u,p.first});
		}
	}
	for(int i=0;i++<N;)dfs(i,0,0,i);
	cin>>Q;
	for(int i=0;i<Q;i++)
	{
		int a,b;cin>>a>>b;
		cout<<sum-T[a][b]<<endl;
	}
}

Measured memory_bytes: 69868
import java.io.*;
import java.util.*;


public class Main{ 

	public static void main(String args[]){
		
		Scanner scan = new Scanner(System.in);
		Heap heap = new Heap(scan.nextInt());
		scan.nextLine();
		heap.Load(scan.nextLine());
		heap.show();
	}
}

class Heap{
	int HeapSize;
	int[] list;
	public Heap(int hs){
		HeapSize = hs;
		list = new int[hs+1];
	}

	public void Load(String line){
		String[] tmp = line.split(" ");
		for(int i=0; i<HeapSize;i++)
			list[i+1]=Integer.parseInt(tmp[i]);
	}
	public void show(){
		for(int i=1; i<HeapSize+1;i++){
			int l=i*2;
			int r=i*2+1;
			System.out.printf("node %d: key = %d, ",i,list[i]);
			if(i!=1){
				int p = (i%2==0) ? i/2 : (i-1)/2;
				System.out.printf("parent key = %d, ",list[p]);
			}
			if(l<=HeapSize)
				System.out.printf("left key = %d, ",list[l]);
			if(r<=HeapSize)
				System.out.printf("right key = %d, ",list[r]);			
			System.out.printf("\n");
		}
		
	}
	
}

Measured memory_bytes: 23380
fold -1|awk '{/^R/?R[++i]=NR:/^G/?G[++j]=NR:b+=B[NR]=/B/}END{for(i in R)for(j in G)a+=b-B[2*(r=R[i])-(g=G[j])]-B[2*g-r]-B[(r+g)/2];printf "%.f",a;}'

Measured memory_bytes: 6180
#include <iostream>
using namespace std;
void pRec(int h, int w) {
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (0 < i && i < (h-1) && 0 < j && j < (w-1))
        cout << ".";
      else
        cout << "#";
    }
    cout << "\n";
  }
  cout << "\n";
}
int main(void) {
  int h, w;
  for(;;) {
    cin >> h >> w;
    if (h == 0 && w == 0)
      return 0;
    pRec(h, w);
  }
}



Measured memory_bytes: 3048
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
vector<int>a;
	int n, k;
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;


	scanf("%d %d",&x,&n);

if(n==1){
scanf("%d", &k);
printf("%d\n",k);
if(k==1){
printf("1\n1\n");
}
else{
printf("2\n1 %d\n",k-1);
}
return 0;
}

x=0;
y=0;
z=0;

	f(i, n){
		scanf("%d", &k);
if(k%2==1){
x++;
if(y>0)z=k;
else y=k;
}
else a.push_back(k);
	}


if(x>2){
printf("Impossible\n");
return 0;
}

else if(x>1){
printf("%d",y);
f(i,a.size())printf(" %d",a[i]);
printf(" %d\n",z);

if(z==1){
printf("%d\n",a.size()+1);

printf("%d",y+1);
f(i,a.size())printf(" %d",a[i]);
printf("\n");
}
else{
printf("%d\n",a.size()+2);

printf("%d",y+1);
f(i,a.size())printf(" %d",a[i]);
printf(" %d",z-1);
printf("\n");
}
}


else if(x>0){
printf("%d",y);
f(i,a.size())printf(" %d",a[i]);
printf("\n");

printf("%d\n",a.size()+1);

printf("%d",y+1);
f(i,a.size()-1)printf(" %d",a[i]);
printf(" %d\n",a[a.size()-1]-1);
}


else{
printf("%d",a[0]);
f(i,a.size()-1)printf(" %d",a[i+1]);
printf("\n");

printf("%d\n",a.size());

printf("%d",a[0]+1);
f(i,a.size()-2)printf(" %d",a[i+1]);
printf(" %d\n",a[a.size()-1]-1);
}

	return 0;
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

VI kouho;
VVI friends;
VVI blocks;
int cluster=0;
VI num;

void func(int p,int type){
    if(kouho[p] != -1){
        return;
    }
    kouho[p] = type;
    num[type]++;

    for (const auto& f : friends[p]) {
        int next = f;
        if(kouho[next] == -1){
            func(next,type);
        }
    }
}


void Main()
{
    int n,m,k;
    cin>>n>>m>>k;

    friends.resize(n);
    blocks.resize(n);
    num.resize(n);

    REP(i,m){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        friends[a].push_back(b);
        friends[b].push_back(a);
    }
    REP(i,k){
        int c,d;
        cin>>c>>d;
        c--;
        d--;
        blocks[c].push_back(d);
        blocks[d].push_back(c);
    }

    kouho.resize(n,-1);

    REP(i,n){
        if(kouho[i] == -1){
            func(i,cluster);
            cluster++;
        }
    }

    REP(i,n){
        int type = kouho[i];
        int result = num[type];

        for (const auto& f : friends[i]) {
            if(kouho[f] == type){
                result --;
            }
        }
        for (const auto& b : blocks[i]) {
            if(kouho[b] == type){
                result --;
            }
        }

        if(i != 0){
            cout << " ";
        }
        cout << result-1;
    }
    cout << endl;




	return;
}

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

Measured memory_bytes: 12672
import math


def mintrial(t):
    tmp = int(math.sqrt(t)) + 1
    for num in range(2, tmp):
        while t % num == 0:
            return num
    return t


S = int(input())
s = math.sqrt(S)
ss = (int(s))**2
if ss == S:
    print(0, 0, int(s), 0, 0, int(s))
else:
    s = int(s)+1
    if s > 10**9:
        s = 10**9
    t = s ** 2 - S
    if t > 10**9:
        t2 = t
        while t2 > 10**9:
            t2 = mintrial(t2)
        t3 = t // t2
        print(0, 0, s, t2, t3, s)
    else:
        print(0, 0, s, 1, t, s)



Measured memory_bytes: 3064
N = int(input())
dic = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
for i in range(N):
    dic[input()] += 1
print('AC x ' + str(dic['AC']))
print('WA x ' + str(dic['WA']))
print('TLE x ' + str(dic['TLE']))
print('RE x ' + str(dic['RE']))

Measured memory_bytes: 74768