akhauriyash/Code-Regression huggingface dataset:
import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))



##### main #####
def main():
	n = I()
	x = 0; y = 0
	
	for a,b in zip(LI(),LI()):
		if a > b:
			x += a-b
		else:
			y += (b-a)//2

	print('Yes' if y >= x else "No")

if __name__ == '__main__':
  main()

Measured memory_bytes: 4852
import math
import numpy as np
x = int(input())
fac = []
fac2 = []

for i in range(1, int(math.sqrt(x))+1):
  if x % i == 0:
    fac.append(i)
    fac2.append(int(x/i))

fac = fac + list(reversed(fac2))
#print(fac)

flag = True
for i in range(len(fac)):
  factor = fac[i]
  a = 0
  while flag:
    b = a - factor
    tmp = a*a*a*a+b*b*b*b+a*b*(b*b+a*a+a*b)
    #print("{} {} {} {}".format(a, b, tmp,fac[-int(i+1)]))
    if int(tmp) == int(fac[-int(i+1)]):
      flag = False
      print("{} {}".format(a, b))
      break
    if b > 0 and tmp > fac[-(i+1)]:
      break
    a += 1
      
  if flag == False:
    break


Measured memory_bytes: 27136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    ll X;
    cin >> X;
    ll dp[X + 10];
    for(int i = 0; i < X + 10; i++) dp[i] = 0;
    dp[0] = 1;
    ll price[6] = {100, 101, 102, 103, 104, 105};
    for(int j = 0; j < 6; j++) {
        for(int i = 0; i < X + 10; i++) {
            if(dp[i] == 1)
                if(i + price[j] < X + 10) dp[i + price[j]] = 1;
        }
    }
    cout << dp[X];
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string s;
  while(getline(cin,s)){
    int n=s.size();
    
    stack<double> sd;
    for(int i=0;i<n;i++){
      if(s[i]==' ') continue;
      if(s[i]=='-'&&isdigit(s[i+1])){
	double res=0;
	i++;
	while(isdigit(s[i])) res=res*10+s[i]-'0',i++;
	sd.push(-res);
      }else if(isdigit(s[i])){
	double res=0;
	while(isdigit(s[i])) res=res*10+s[i]-'0',i++;
	sd.push(res);
      }else{
	
	double a,b;
	b=sd.top();sd.pop();
	a=sd.top();sd.pop();
	
	if(s[i]=='+') sd.push(a+b);
	if(s[i]=='-') sd.push(a-b);
	if(s[i]=='*') sd.push(a*b);
	if(s[i]=='/') sd.push(a/b);
	
      }
    }
    
    double ans=sd.top();
    printf("%.12lf\n",ans);
     
  }
  return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
    string str1,str2;cin>>str1>>str2;
    ll len1=str1.size(),len2=str2.size();
    ll dp[len1+1][len2+1];
    for(int i=0;i<=len1;i++){
		for(int j=0;j<=len2;j++){
			if(i==0 || j==0){
				dp[i][j]=0;
			}else if(str1[i-1]==str2[j-1]){
				dp[i][j]=dp[i-1][j-1]+1;
			}else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
    }
    ll len=dp[len1][len2];
    stack<char> myst;
    ll idx1=len1,idx2=len2;
    while(idx1>0 && idx2>0){
		if(str1[idx1-1]==str2[idx2-1]){
			len--;
			myst.push(str1[idx1-1]);
			idx1--;idx2--;
		}else if(dp[idx1][idx2-1]>dp[idx1-1][idx2]){
			idx2--;
		}else{
			idx1--;
		}
    }
    string ans="";
    while(!myst.empty()){
		cout<<myst.top();
		myst.pop();
    }
    return 0;
}


Measured memory_bytes: 70656
N,K=map(int,input().split())
dp=[0]*(10**5)
ans=0
for _ in range(N):
  a,b=map(int,input().split())
  dp[a-1]+=b
for j in range(len(dp)):
  if K<=ans+dp[j]:
    print(j+1)
    exit()
  ans+=dp[j]

Measured memory_bytes: 11724
import java.util.Scanner;
/**
 * @author saiyo
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		//int x = scan.nextInt();
		//int y = scan.nextInt();
		
		//Seisu s = new Seisu(x, y);
		//s.kouyaku();

		int con = scan.nextInt();
		
		int[] num = new int[con];
		for(int i = 0; i < con; i++){
			num[i] = scan.nextInt();
		}
		Seisu s = new Seisu(num);
		s.countSosu();
		/*
		Sort s = new Sort(num);
		s.printSort();
		s.insertionSort();
		*/
	}

}

class Seisu{
	private int x, y;
	private int snum[];
	
	Seisu(int x, int y){
		if(x >= y){
			this.x = x;
			this.y = y;
		}else{
			this.x = y;
			this.y = x;
		}
		
	}
	
	Seisu(int snum[]){
		this.snum = new int[snum.length];
		for(int i = 0; i < snum.length; i++){
			this.snum[i] = snum[i];
		}
	}
	
	public void countSosu(){
		int con = 0;
		for(int nu: this.snum){
			con += isSosu(nu);
		}
		System.out.println(con);
	}
	
	public int isSosu(int num){
		for(int i = 2; i < Math.sqrt(num) + 1; i++){

			if(num % i == 0 && num != 2){
				return 0;
			}
			
		}
		return 1;
	}
	
	public void kouyaku(){
		System.out.println(modSeisu(this.x, this.y));
	}
	
	
	public int modSeisu(int x, int y){
		if(x % y == 0){
			return y;
		}else{
			return modSeisu(y , x % y);
		}
	}
}

class Sort{
	private int[] sorted;
	
	Sort(int[] sorted){
		this.sorted = new int[sorted.length];
		for(int i = 0; i < sorted.length; i++){
			this.sorted[i] = sorted[i];
		}
	}
	
	public void insertionSort(){
		int v, j;
		for(int i = 1; i < this.sorted.length; i++){
			v = this.sorted[i];
			j = i - 1;
			while(j >= 0 && this.sorted[j] > v){
				this.sorted[j + 1] = this.sorted[j];
				j--;
			}
			this.sorted[j + 1] = v;
			printSort();
		}
	}
	
	public void printSort(){
		for(int i  = 0; i < this.sorted.length - 1; i++){
			System.out.print(this.sorted[i] + " ");
		}
		System.out.println(this.sorted[this.sorted.length - 1]);
	}
}



Measured memory_bytes: 43176
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  vector<P> v;
  ll n, k;
  cin >> n >> k;
  rep(i,n) {
    ll a, b;
    cin >> a >> b;
    v.emplace_back(P(a,b));
  }
  ll sum = 0;
  sort(all(v));
  for (auto p : v) {
    debug(p.first, p.second);
    sum += p.second;
    if (sum >= k) {
      cout << p.first << endl;
      break;
    }
  }
  return 0;
}

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

int main(){
    int n;
    while(scanf("%d",&n)!=EOF && n){
        while(n--){
            int x1,y1,z1,w1,x2,y2,z2,w2;
            scanf("%d%d%d%d%d%d%d%d"
                  ,&x1,&y1,&z1,&w1
                  ,&x2,&y2,&z2,&w2);
            int p = x1*x2 - y1*y2 - z1*z2 -w1*w2;
            int q = x1*y2 + y1*x2 +z1*w2 -w1*z2;
            int r = x1*z2 -y1*w2 + z1*x2 + w1*y2;
            int s = x1*w2 + y1*z2 - z1*y2 + w1*x2;
            printf("%d %d %d %d\n",p,q,r,s);
        }
    }
}

Measured memory_bytes: 1012
#include<bits/stdc++.h>
#define pi acos(-1)
#define el << endl
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	string s;
	cin>>s;
	string s1= "ABC", s2 = "ARC";

	if(s==s1) cout<< s2<< endl;
	else if(s==s2) cout<< s1<< endl;

	return 0;
}




Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const long long INF = 9999999999;
const long long MOD = 1e9 + 7;
const double pi = 3.1415926535897932384626;
const int SIZE = 1 << 17;

int main() {
	int a, b;
	cin >> a >> b;
	if (2 * b - 1 <= a) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }
}

Measured memory_bytes: 384
#include <iostream> 
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 200300;
int n, m, to1[maxn], ton[maxn];


int main(){
	cin >> n >> m;
	to1[1] = 1;
	ton[n] = 1;
	for (int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		if (x == 1) to1[y] = 1;
		if (y == n) ton[x] = 1;
	}
	int lag = 0;
	for (int i = 1; i <= n; i++) if (to1[i] && ton[i]) lag = 1;
	if (lag) cout << "POSSIBLE";
	else cout << "IMPOSSIBLE";
}

Measured memory_bytes: 1792
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            int age = scanner.nextInt();
            if(age == 7 || age == 5 || age == 3) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
}

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

int main(void){

    int a[3];
    int ans = 0;
    cin >> a[0] >> a[1] >> a[2];

    while(1){
        if(a[0]==a[1] && a[1]==a[2] && a[2]==a[0])break;
        sort(a,a+3);
        if(a[0]==a[1]){
            ans++;
            a[0]++;
            a[1]++;
        }else{
            ans++;
            a[0]=a[0]+2;
        }

    }

    cout << ans << endl;

    return 0;
}

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

int main(){
  ll a,b;
  cin >> a >> b;
  if(a%2 != b%2) cout << "IMPOSSIBLE" << endl;
  else cout << (a+b)/2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define SIZE 100

int main(){
  int v,i,j;
  int G[SIZE][SIZE];
  scanf("%d",&v);
  
  for(i=0; i<v; i++){
    for(j=0; j<v; j++){
      G[i][j] = 0;
    }
  }
  
  for(i=0; i<v; i++){
    int u,k;
    scanf("%d %d",&u,&k);
    u--;
    
    for(j=0; j<k; j++){
      int peak;
      scanf("%d",&peak);
      peak--;
      G[u][peak] = 1;
    }
  }
  
  for(i=0; i<v; i++){
    for(j=0; j<v; j++){
      if(j > 0) printf(" ");
      printf("%d",G[i][j]);
    }
    printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2108
S = input()
Q = int(input())
QUERY = []
for i in range(Q):
    QUERY.append(input().split(' '))


def main(s, q, query):
    addflag = 'front'

    s_front = ''
    s_back = ''

    for i in range(q):
        if query[i][0] == '1':
            if addflag == 'front':
                addflag = 'back'
            elif addflag == 'back':
                addflag = 'front'
        elif query[i][0] == '2':
            if addflag == 'front' and query[i][1] == '1':
                s_front = query[i][2] + s_front
                # s = query[i][2] + s
            elif addflag == 'front' and query[i][1] == '2':
                s_back = s_back + query[i][2]
                # s = s + query[i][2]
            elif addflag == 'back' and query[i][1] == '1':
                s_back = s_back + query[i][2]
                # s = s + query[i][2]
            elif addflag == 'back' and query[i][1] == '2':
                s_front = query[i][2] + s_front
                # s = query[i][2] + s

    if addflag == 'back':
        s = ''.join(reversed(list(s)))
        s_tmp = ''.join(reversed(list(s_front)))
        s_front = ''.join(reversed(list(s_back)))
        s_back = s_tmp

    return s_front + s + s_back


print(main(S, Q, QUERY))


Measured memory_bytes: 41488
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#define int long long
#define endre getchar();getchar();return 0
#define moder 1000000007
#define inf 1000000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

class segment_tree {
	int dat[1000005];
public:
	segment_tree(int &x) {
		int s = x;
		x = 1;
		while (1) {
			x *= 2;
			if (s <= x)break;
		}
		rep(i, x * 2 - 1)dat[i] = ((int)1 << 31) - 1;
	}
	void update(int k, int a, int x) {
		k += x - 1;
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	int query(int a, int b, int x, int l, int r) {
		if (r < a ||b < l)return inf;
		if (a <= l && b >= r)return dat[x];
		int vl = query(a, b, x * 2 + 1, l, (l + r) / 2);
		int vr = query(a, b, x * 2 + 2, (l + r) / 2 + 1, r);
		return min(vl, vr);
	}
};
signed main() {
	int n, q;
	cin >> n >> q;
	static segment_tree segtree(n);
	rep(i, q) {
		int a, b, c;
		cin >> a >> b >> c;
		if (a) {
			cout << segtree.query(b, c, (int)0, (int)0, n - 1) << endl;
		}
		else {
			segtree.update(b, c, n);
		}
	}
	endre;
}


Measured memory_bytes: 5136
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    int N; cin >> N;
    vector<vector<int>> dp(N+1, vector<int>(3));
    vector<int> a(N), b(N), c(N);
    for(int i=0; i<N; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    
    
    for(int i=0; i<N; i++){
        dp[i+1][0] = max(dp[i][1], dp[i][2]) + a[i];
        dp[i+1][1] = max(dp[i][2], dp[i][0]) + b[i];
        dp[i+1][2] = max(dp[i][0], dp[i][1]) + c[i];
    }
    cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;
    return 0;
}





Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=603,INF=1<<30;
vector<int> F[MAX],G[MAX];
int N;
double preP[MAX];

double solve(pair<int,int> E){
    vector<double> P(MAX,0.0);//Pはそこにつくまでにかかる回数の期待値、Qはそこにいく確率,childは子の数
    P[N-1]=0.0;
    
    for(int i=N-2;i>=0;i--){
        double cnt=0.0;
        for(int to:F[i]){
            if(i==E.first&&to==E.second) continue;
            cnt+=1.0;
        }
        for(int to:F[i]){
            if(i==E.first&&to==E.second) continue;
            P[i]+=(1+P[to])/cnt;
        }
    }
    /*for(int i=1;i<N;i++){
        double cnt=0.0,sum=0.0;
        for(int from:G[i]){
            if(from==E.first&&i==E.second) continue;
            cnt+=Q[from]/child[from];
            sum+=(P[from]+1.0)*Q[from]/child[from];
        }
        //cout<<no<<" "<<i<<" "<<sum<<" "<<cnt<<endl;
        if(cnt==0.0) continue;
        P[i]=sum/cnt;
        if(i==N-1&&0.9999999>cnt) return INF;
     }*/
    
    if(E==make_pair(-1,-1)){
        for(int i=0;i<N;i++) preP[i]=P[i];
    }
    return P[0];
    
    /*for(int i=0;i<N;i++){
        cout<<Q[i]<<endl;
    }
    cout<<endl;*/
}

int main(){
    
    int M;cin>>N>>M;
    vector<pair<int,int>> edge(M);
    vector<int> inn(N,0),outn(N,0);
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        F[a].push_back(b);
        G[b].push_back(a);
        edge[i]={a,b};
        inn[b]++;
        outn[a]++;
    }
    
    double ans=INF;
    
    ans=min(ans,solve({-1,-1}));
    
    for(int i=0;i<N;i++){
        double num=-1,maxi=-1;
        for(int j=0;j<M;j++){
            int from=edge[j].first,to=edge[j].second;
            if(from==i&&outn[from]!=1){
                if(maxi<preP[to]){
                    maxi=preP[to];
                    num=j;
                }
            }
        }
        if(num!=-1){
            //cout<<num<<" "<<solve(edge[num])<<endl;
            ans=min(ans,solve(edge[num]));
        }
    }
    
    /*for(int i=0;i<M;i++){
        cout<<solve(edge[i])<<endl;
    }*/
    
    cout<<setprecision(25)<<ans<<endl;
    
}



Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
int a[1010];
int main()
{
	int n, m;
	scanf("%d",&n);
	int i;
	for(i=0; i<n; i++) scanf("%d",&a[i]);
	scanf("%d",&m);
	while(m--)
	{
		int l, mid, r;
		scanf("%d%d%d",&l,&mid,&r);
		rotate(a+l, a+mid, a+r);
	}
	for(i=0; i<n; i++) 
	{
		if(i == n-1) printf("%d\n",a[i]);
		else printf("%d ",a[i]);
	}
	return 0;
}


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

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

  if (A + B > C + D) {
    cout << "Left" << endl;
      }
  if (A + B < C + D) {
    cout << "Right" << endl;
      }
  if (A + B == C + D) {
    cout << "Balanced" << endl;
      }
}

Measured memory_bytes: 3548
#include <stdio.h>
#include <string.h>
#define MAX 1001
 
int main(void) {
    int num, m, n, i, j;
    int a[MAX], b[MAX];
    char x[MAX], y[MAX], xi;
 
    scanf("%d ", &num);
    while (num--) {
        scanf("%s %s ", x, y);
        m = strlen(x);
        n = strlen(y);
 
        for (i = 0; i < n+1; i++) {
            b[i] = a[i] = 0;
        }
        for (i = 1; i < m+1; i++) {
            xi = x[i-1];
            for (j = 1; j < n+1; j++) {
                if (xi == y[j-1]) {
                    b[j] = a[j-1] + 1;
                } else if (a[j] >= b[j-1]) {
                    b[j] = a[j];
                } else {
                    b[j] = b[j-1];
                }
            }
            for (j = 1; j < n+1; j++) {
                a[j] = b[j];
            }
        }
        printf("%d\n", a[n]);
    }
    return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = 1e9;

struct UnionFind {
    vector< int > data;

    UnionFind(int sz) {
        data.assign(sz, -1);
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return (false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k) {
        if(data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k) {
        return (-data[find(k)]);
    }
};


signed main() {
    int N, M;
    cin >> N >> M;
    vector<ll> a(N);
    cin >> a;
    auto uf = UnionFind(N);
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }
    vector<multiset<ll>> input(N);
    set<pair<int, int>> check;
    for (int i = 0; i < N; i++) input[uf.find(i)].insert(a[i]);
    for (int i = 0; i < N; i++) check.emplace(uf.size(i), uf.find(i));
    multiset<ll> use;
    {
        // init
        for (auto temp : input[check.rbegin()->second]) use.insert(temp);
    }
    ll ans = 0;
    for (auto itr = next(check.rbegin(), 1); itr != check.rend(); itr++) {
        auto now = *itr;
        if (use.empty()) {
            cout << "Impossible" << endl;
            return 0;
        }
        ans += *use.begin();
        ans += *input[now.second].begin();
        use.erase(use.begin());
        input[now.second].erase(input[now.second].begin());
        for (auto add : input[now.second]) use.insert(add);
    }
    cout << ans << endl;
}


Measured memory_bytes: 15488
h, w = map(int, input().split())
import sys

def yokowari(h, w):
  min_dfr = 10**10
  for h_wareme in range(1, h):
    rest_h = h - h_wareme
    rest_w = w
    if rest_h % 2 == 0 or rest_w % 2 == 0:
      rest_s1 = rest_h * rest_w // 2
      rest_s2 = rest_h * rest_w // 2
    elif rest_w >= rest_h:
      rest_s1 = (rest_w // 2) * rest_h
      rest_s2 = (rest_w // 2 + 1) * rest_h
    else:
      rest_s1 = (rest_h // 2) * rest_w
      rest_s2 = (rest_h // 2 + 1) * rest_w
    s = h_wareme * w
    if s == 0 or rest_s1 == 0 or rest_s2 == 0:
      continue
    dfr = max(s, rest_s1, rest_s2) - min(s, rest_s1, rest_s2)
    min_dfr = min(min_dfr, dfr)
#    print("h", h, "w", w, "hwa", h_wareme, "S", h_wareme*w, "s", rest_s1, rest_s2)
  return min_dfr

"""
def yokowari(h, w):
  o_th = h * w / 3
  print(o_th, h, o_th / h)
  h_wareme = round(o_th / h)
  rest_h = h - h_wareme
  rest_w = w
  print("", rest_h, rest_w)
  if rest_h % 2 == 0 or rest_w % 2 == 0:
    rest_s = rest_h * rest_w // 2
  elif rest_w >= rest_h:
    rest_s = (resr_w // 2) * rest_h
  else:
    rest_s = (resr_h // 2) * rest_w
  dfr = h_wareme * w - rest_s
  print(h_wareme * w, rest_s ,dfr)
  print()
  return abs(dfr)
"""
if h % 3 == 0 or w % 3 == 0:
  print(0)
  sys.exit()
else:
  print(min(yokowari(h, w), yokowari(w, h)))


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

int main(){

  /*********************************************
    writer Torisuto 2020/5/31
    N個の整数をすべて掛け算し、10^18を越えたら−１を出力
    その他はすべてかけた値を出力

    2 <= N <= 10^5
    0 <= A[i] <= 10^18
  **********************************************/

  int N;
  cin >> N;
  vector<long long> A(N);
  // A[i] = 0 がある場合を注意
  for(int i = 0; i < N; i++){
    cin >> A[i];
    if(A[i] == 0){
      cout << 0 << endl;
      return 0;
    }
  }

  /**********************************************************
    そのまま掛け算してしまうとオーバーフローしてしまうことがある。
    そこで1e18を持った変数を用意しておき、かける数で割り続けることで
    1e18を越えるか判定ができる。なぜできるのか例を示す
    1e18の代わりに5で考える。
    5/2 = 2.5　入力される数は整数であることを考慮すると
    よって、次にかける数が5を越えないようには少数を切り捨てた整数までが、
    5を越えないかける数となる。
  ***********************************************************/

  long long judge = 1e18, ans = 1;
  for(int i = 0; i < N; i++){
    if(judge >= A[i]){
      judge /= A[i];
      ans *= A[i];
    }

    else{
      cout << -1 << endl;
      return 0;
    }
  }

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


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

int main() {
  int n;
  cin >> n;
  vector<int> taste(n);
  for(int i = 0; i < n; i++) {
    cin >> taste.at(i);
  }
  
  int sum = 0;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      if(i == j) {
        continue;
      }
      
      sum += taste.at(i) * taste.at(j);
      
    }
  }
  
  sum /= 2;
  
  cout << sum << endl;
}

Measured memory_bytes: 256
while grade = gets.chomp
    m,f,r=grade.split(' ').map{|n| n.to_i}
    case
    when m == -1 && f == -1 && r == -1
        break
    when m == -1 || f == -1
        puts "F"
    when m+f >= 80
        puts "A"
    when m+f >= 65
        puts "B"
    when m+f >= 50 || (m+f>=30 && r >= 50)
        puts "C"
    when m+f >= 30
        puts "D"
    else
        puts "F"
    end
end

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

using namespace std;

const string alphabets = "abcdefghijklmnopqrstuvwxyz";

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  vector<int> count(alphabets.size(), 0);
  for (auto s : S)
    count[s - 'a']++;
  for (auto s : alphabets) {
    if (count[s - 'a'] == 0) {
      cout << S << s << '\n';
      return 0;
    }
  }
  string cand = "", res = "";
  for (int i = S.size() - 1; i > 0; i--) {
    cand += S[i];
    for (auto c : cand) {
      if (res != "" && res < S.substr(0, i - 1) + c)
        continue;
      else if (c > S[i - 1])
        res = S.substr(0, i - 1) + c;
    }
    if (res != "") {
      cout << res << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}


Measured memory_bytes: 384
N,K = map(int, input().split())
A = list(map(int, input().split()))

P = [1e9]*N
P[0] = 0

for i in range(1,N):
  for j in range(1,min(K+1,i+1)):
    P[i] = min(P[i], abs(A[i]-A[i-j])+P[i-j])
  
print(P[N-1])


Measured memory_bytes: 55136
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
public class Remainder {
    static long div = 1000000007;
    
    static public void Main() {
        
        
        var NM =　Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var N = NM[0];
        var M = NM[1];
        if(N==M){
            Console.WriteLine("Yes"); 
        }else
        {
            Console.WriteLine("No"); 
        }
        
            
    }
    
} 


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=1000000;
const ll inf=1e9;
const ll mod=998244353;



int main()
{
    FasterIO;

    int k;
    ll sm=0;
    cin>>k;
    for(int a=1; a<=k; a++)
    {
        for(int b=1; b<=k; b++)
        {
            for(int c=1; c<=k; c++)
            {
                sm+=__gcd(__gcd(a, b), c);
            }
        }
    }
    cout<<sm<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    int maki=m/n;
    while(1){
        if(m%maki==0){
            cout << maki<<endl;
            return 0;
        }
        else{
            maki--;
        }
    }
    return 0;
}




Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(){
	int n;
	int h[20] = {0};
	int cnt=0,i=1,j;

	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&h[i]);

	while(n >= i){
		n--;
		for(j=n;0 <= j;j--){
			if(h[j] > h[n]) break;
		}
		if(j == -1) cnt++;
	}

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

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stack>

using namespace std;

bool Solution()
{
    
    
    int left = 0;
    int right = 0;
    
    int a[10];
    
    for (int i = 0; i < 10; i++)
    {
        cin>>a[i];
    }
        
        for (int i = 0; i < 10; i++)
        {
            if (a[i] > left) // at the beginning, compare with first ball and the ball before first ball (empty)
            {
                left = a[i];
            }
            else if (a[i] > right)
            {
                right = a[i];
            }
            else                 //when can not enter to the both bottles to the end, then return false
            {
                return false;
            }
        }
    
    return true;
}

int main()
{
    int n;
    
    cin>>n;
    
    while(n--)
    {
        if (Solution())
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1152
N = int(input())
A = [None for n in range(N)]
k = -1
ma1 = 0
ma2 = 0
for n in range(N):
	A[n] = int(input())
	if ma2 < A[n]:
		ma2 = A[n]
	if ma1 <= A[n]:
		ma2 = ma1
		ma1 = A[n]
		k = n
for n in range(N):
	if n == k:
		print(ma2)
	else:
		print(ma1)

Measured memory_bytes: 12528
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string.h>
#define REP(i,j,n) for(int i=j;i<n;i++)
#define SORT(x) sort(x.begin(),x.end())

using namespace std;



int main() {
	REP(i, 1, 10) {
		REP(j, 1, 10) {
			cout << i << "x" << j << '=' << i*j << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3088
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<tgmath.h>
#include<stdbool.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

int h, w, c[10][10], a, ans = 0;

int main(){
	scanf("%d%d", &h, &w);
	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++){
			scanf("%d", &c[i][j]);
		}
	}
	for(int k=0; k<10; k++){
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}
	for(int i=0; i<h*w; i++){
		scanf("%d", &a);
		if(a>=0)ans += c[a][1];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
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; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

ll dp[3300][3300];
int main(){
    string s,t;
    cin>>s>>t;
    ll sl=s.length();
    ll tl=t.length();
    rep(i,0,sl){
        rep(j,0,tl){
            if(s[i]==t[j])chmax(dp[i+1][j+1],dp[i][j]+1);
            chmax(dp[i+1][j+1],dp[i+1][j]);
            chmax(dp[i+1][j+1],dp[i][j+1]);
        }
    }
    string ans="";
    ll is=sl,it=tl;
    while(is*it>0){
        if(dp[is][it]==dp[is-1][it])is--;
        else if(dp[is][it]==dp[is][it-1])it--;
        else{
            ans=s[is-1]+ans;
            is--,it--;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 78080
#include<bits/stdc++.h>
using namespace std;
int n,s;
int a[50]; 
int main()
{
	cin>>n;
	for (int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for (int i=0;i<n;i++)
	{
		if (a[i]!=i+1) s++;
	}
	if (s==2||s==0) puts("YES");
	else puts("NO");
	return 0;
}


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

const ll mod = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    unordered_map<ll, ll> factors;
    rep(i, n) {
        int num = a[i];
        for (ll k = 2; k * k <= a[i]; k++) {
            ll power = 0;
            while (num && (num % k == 0)) {
                power++;
                num /= k;
            }
            if (factors[k] < power) factors[k] = power;
        }
        if (num > 1 && factors[num] == 0) factors[num] = 1;
    }
    // for (auto p : factors) {
    //     cout << p.first << "\t: " << p.second << endl;
    // }

    ll ans = 0;
    rep(i, n) {
        ll prod = 1;
        for (auto p : factors) {
            if (p.second == 0) continue;
            ll pwr = p.second;
            if (a[i] % p.first == 0) {
                ll num = a[i];
                while (num && (num % p.first == 0)) {
                    pwr--;
                    num /= p.first;
                }
            }
            while (pwr--) {
                prod *= p.first;
                prod %= mod;
            }
        }
        ans += prod;
        ans %= mod;
    }
    cout << ans << endl;
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> a(N);
    for(auto&& i : a)cin >> i;
    vector edge(N, vector(0, 0UL));
    for(unsigned long i{1}, u, v; i < N; ++i){
        cin >> u >> v;
        edge[--u].push_back(--v);
        edge[v].push_back(u);
    }
    vector<unsigned long> lis(N, numeric_limits<unsigned long>::max()), ans(N);
    [dfs_impl = [&a, &edge, &lis, &ans](auto f, unsigned long now, unsigned long prev) -> void {
        auto it = lower_bound(lis.begin(), lis.end(), a[now]);
        pair<unsigned long, unsigned long> move{it - lis.begin(), *it};
        *it = a[now];
        ans[now] = lower_bound(lis.begin(), lis.end(), numeric_limits<unsigned long>::max()) - lis.begin();
        for(const auto& i : edge[now])if(i != prev)f(f, i, now);
        lis[move.first] = move.second;
    }]{dfs_impl(dfs_impl, 0, 0);}();
    for(const auto& i : ans)cout << i << endl;
    return 0;
}

Measured memory_bytes: 38812
import numpy as np,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M = LI()
ab = np.array([LI() for _ in range(N)])
cd = np.array([LI() for _ in range(M)])
for x in ab:
    print(abs(cd-x).sum(axis=1).argmin()+1)


Measured memory_bytes: 20692
N = int(input())
A = list(map(int, input().split()))
A.sort()
if A[0] == 0:
  print(0)
else:
  ans = 1
  for i in range(N):
    ans *= A[i]
    if ans > 10**18:
      ans = -1
      break
  print(ans)

Measured memory_bytes: 21592
#include <iostream>
#include <algorithm>

int main() {
  int n, m;
  std::cin >> n >> m;
  int l = 1, r = n;
  for (int i = 0; i < m; i++) {
  	int x, y;
    std::cin >> x >> y;
    l = std::max(l, x);
    r = std::min(r, y);
  }
  std::cout << std::max(0, r - l + 1) << std::endl;
  return 0;
}

Measured memory_bytes: 256
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from functools import reduce
from math import gcd
def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    if reduce(gcd, A) != 1:
        print("not coprime")
        return

    M = max(A)
    sieve = list(range(M + 1))
    for p in range(2, M + 1):
        if sieve[p] != p:
            continue
        for i in range(2 * p, M + 1, p):
            sieve[i] = p

    used = [False] * (M + 1)
    for a in A:
        primes = set()
        while a > 1:
            p = sieve[a]
            primes.add(p)
            a //= p
        for p in primes:
            if used[p]:
                print("setwise coprime")
                return
            used[p] = True

    print("pairwise coprime")
resolve()

Measured memory_bytes: 191368
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String S = in.next();

            // 出力
            out.println("ABC" + S);

        }

    }
}



Measured memory_bytes: 23252
#include<iostream>
#include<string>
#include<cstddef>
#include <cassert>
#include<cctype>

using namespace std;

string S;
size_t cur=0;
int n;
void init_S(){
    cur=0;
    
}
char readchar(){
    assert(cur<S.size());
    char ret=S[cur];
    cur+=1;
    return ret;
}
char peek(){
    return S[cur];
}
int digit(){
    assert(isdigit(peek()));
    int n=readchar() - '0';
    return n;
}
int number(){
    int n=digit();
    while(cur<S.size()&&isdigit(peek()))
        n=n*10+digit();
    return n;
}
int factor();
int term(){
    int sum=factor();
    while(cur<S.size()&&(peek()=='*'||peek()=='/')){
        char op=readchar();
        int b=factor();
        if(op=='*')sum*=b;
        else sum/=b;
    }
    return sum;
}
int b;

int expression(){
    int sum=term();
    while(cur<S.size() && (peek()=='+'||peek()=='-')){
        char op=readchar();
        int b=term();
        if(op=='+')sum+=b;
        else sum-=b;
    }
    return sum;
}
           
int factor(){
    if(peek()!='('){
        return number();
    }
    cur++;
    int n=expression();
    assert(peek()==')');
    cur++;
    return n;
}

int parse(){
    return expression();
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>S;
        int a=parse();
        cout<<a<<endl;
        S.clear();
        init_S();
    }
    return 0;
}



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

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans;

int main(void) {
    string s;
    cin >> s;
    bool ok = true;
    int n = (int)s.size();
    if (n%2==1) ok = false;

    for (int i=0; i<(int)s.size(); i+=2) {
        if (s[i]!='h'||s[i+1]!='i') {
            ok = false;
        }
    }
    

    if(ok) puts("Yes");
    else puts("No");

	return 0;
}


Measured memory_bytes: 256
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    x,n=map(int,readline().split())
    a=list(map(int,readline().split()))
    s=set(a)

    ans_1=x
    ans_2=x
    while True:
        if ans_1 not in s:
            print(ans_1)
            break
        elif ans_2 not in s:
            print(ans_2)
            break
        else:
            ans_1-=1
            ans_2+=1

if __name__=="__main__":
    main()

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

#define PB          push_back
#define PF          push_front
#define MP          make_pair
#define FI          first
#define SE          second
#define SIZE( A )   int( ( A ).size( ) )
#define ALL( A )    ( A ).begin( ), ( A ).end( )
#define ALLR( A )   ( A ).rbegin( ), ( A ).rend( )

using namespace std;

typedef long long           ll;
typedef unsigned long long  ull;
typedef long double         lf;
typedef pair< int, int >    pii;
typedef pair< ll, ll >      pll;
typedef vector< bool >      vb;
typedef vector< lf >        vd;
typedef vector< ll >        vll;
typedef vector< int >       vi;
typedef vector< pii >       vpii;

const int MAXN = int( 2e2 )+10;
const int MOD  = 13;
const int oo   = int( 1e6 );
const lf EPS = 1e-7;

int arr[MAXN], N;

int main( ) {

  #ifdef LOCAL
    freopen( "input", "r", stdin );
    //freopen( "input", "w", stdout );
  #else
    //freopen( ".in", "r", stdin );
    //freopen( ".out", "w", stdout );
  #endif

    while( scanf("%d", &N) == 1 ) {
      N += N;
      for( int i = 0; i < N; ++i ) {
        scanf("%d", &arr[i]);
      }
      sort( arr, arr+N );
      int ans = 0;
      for( int i = 0; i < N; i += 2 ) {
        ans += min( arr[i], arr[i+1] );
      }
      printf("%d\n", ans);
    }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int n,i,max=0,max2=0,s;
  cin>>n;
  int a[n+1];
  for(i=1;i<=n;i++){
    cin>>a[i];
  }
  for(i=1;i<=n;i++){
    if(max<a[i]){
      max=a[i];
      a[i]=0;
        s=i;
    }
  }
  for(i=1;i<=n;i++){
    if(max2<a[i]){
      max2=a[i];
     
    }
  }
    for(i=1;i<=n;i++){
      if(s==i) cout<<max2<<endl;
      else cout<<max<<endl;
    }
    return 0;
  }

Measured memory_bytes: 2432
#include <iostream>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

struct p{
	int num[8];
	int pos;	//0?????????
	int t;
};

bool operator <(const p &a,const p &b){
	for (int i=0;i<8;i++){
		if (a.num[i]<b.num[i]){
			return true;
		}
		else if (a.num[i]>b.num[i]){
			return false;
		}
	}
	return false;
}

bool operator >(const p &a,const p &b){
	for (int i=0;i<8;i++){
		if (a.num[i]>b.num[i]){
			return true;
		}
		else if (a.num[i]<b.num[i]){
			return false;
		}
	}
	return false;
}

bool operator ==(const p &a,const p &b){
	for (int i=0;i<8;i++){
		if (a.num[i]!=b.num[i]){
			return false;
		}
	}
	return true;
}

p puzzle;	//?????¨??????????????????

set<p> all;	//??¨?????????????????????

p comp;	//????????¢

int res[1000];	//??????

int solve(){
	//??¨??????????????????????????????
	queue<p> que;
	que.push(comp);
	all.insert(comp);
	while (!que.empty()){
		p puz=que.front();
		que.pop();
		//?§????
		//???
		p temp;
		if (puz.pos>=4){
			temp=puz;
			swap(temp.num[temp.pos],temp.num[temp.pos-4]);
			temp.pos-=4;
			temp.t++;
			if (all.find(temp)==all.end()){
				//????????¨?????????????±???¢?????´???
				que.push(temp);
				all.insert(temp);
			}
		}
		//???
		if (puz.pos<=3){
			temp=puz;
			swap(temp.num[temp.pos],temp.num[temp.pos+4]);
			temp.pos+=4;
			temp.t++;
			if (all.find(temp)==all.end()){
				que.push(temp);
				all.insert(temp);
			}
		}
		//???
		if (puz.pos!=3 && puz.pos!=7){
			temp=puz;
			swap(temp.num[temp.pos],temp.num[temp.pos+1]);
			temp.pos+=1;
			temp.t++;
			if (all.find(temp)==all.end()){
				que.push(temp);
				all.insert(temp);
			}
		}
		//???
		if (puz.pos!=0 && puz.pos!=4){
			temp=puz;
			swap(temp.num[temp.pos],temp.num[temp.pos-1]);
			temp.pos-=1;
			temp.t++;
			if (all.find(temp)==all.end()){
				que.push(temp);
				all.insert(temp);
			}
		}
	}
}

int main(){
	for (int i=0;i<8;i++){
		comp.num[i]=i;
	}
	comp.pos=0;
	comp.t=0;
	solve();
	int a;
	int k=0;
	while (cin>>a){
		puzzle.num[0]=a;
		for (int i=1;i<8;i++){
			cin>>puzzle.num[i];
		}
		set<p>::iterator ite=all.find(puzzle);
		res[k++]=ite->t;
	}
	for (int i=0;i<k;i++){
		cout<<res[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 2828
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("fma,avx")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    map<int, int> mp;
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        mp[x]++;
        ans += x;
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int b, c;
        cin >> b >> c;
        ans += (c - b) * mp[b];
        mp[c] += mp[b];
        mp[b] = 0;
        cout << ans << "\n";
    }


    return 0;
}


Measured memory_bytes: 9572
;;;; mod
(let ((p 1000000007))
  (defun mod+ (a b)
    (mod (+ a b) p))

  (defun mod- (a b)
    (mod (- a b) p))

  (defun mod* (a b)
    (mod (* a b) p))

  (defun mod_expt (a z)
    (loop :with ans := 1
          :with pow := a
          :while (> z 0)
          :do (multiple-value-bind (x y) (floor z 2)
                (setf z x)
                (if (= y 1) (setf ans (mod* ans pow)))
                (setf pow (mod* pow pow)))
          :finally (return ans)))

  (defun mod_inv (a)
    ; TODO use Euclidean
    (mod_expt a (- p 2))))

;;;; main
(let* ((n (read))
       (x (mod_expt 10 n)) ; 0-9
       (y (mod_expt 9 n)) ; 0-8, 1-9
       (z (mod_expt 8 n))) ; 1-8
  (format t "~A~%" (mod- (mod+ x z) (mod* 2 y))))


Measured memory_bytes: 24444
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int H, W;
int ch, cw;
int dh, dw;
vector<string> field;

int color[1005][1005];

int vx[4] = {-1,1,0,0};
int vy[4] = {0,0,-1,1};

void coloring(int c, int y, int x){
  stack<pair<int,int>> st;
  st.push(make_pair(y,x));
  
  while(!st.empty()){
    pair<int,int> p = st.top(); st.pop();
    color[p.first][p.second] = c;

    rep(k,4){
      int ny = p.first + vy[k];
      int nx = p.second + vx[k];
      if(0<=nx && nx<W && 0<=ny && ny<H){
        if(field[ny][nx] == '.' && color[ny][nx] == 0){
          st.push(make_pair(ny,nx));
        }
      }
    }
  }
}

static const ll INF = (ll)(1e18);
set<int> G[1000005];
ll cost[1000005];
int M;

struct Edge {
  int src, dest;
  ll weight;
};
bool operator>(const Edge& a, const Edge& b){
  return a.weight > b.weight;
}

ll dijkstra(int st, int ed){
  rep(i,M){
    cost[i] = INF;
  }
  priority_queue<Edge,vector<Edge>,greater<Edge>> q;
  q.push((Edge){-1,st,0});

  while(!q.empty()){
    Edge e=q.top();
    q.pop();
    if(cost[e.dest] != INF) continue;
    cost[e.dest]=e.weight;
    FOR(it,G[e.dest])
      if(cost[*it]==INF) q.push((Edge){e.dest,*it,e.weight+1});
  }

  if(cost[ed] == INF) return -1;
  return cost[ed];
}



int main(){

  cin >> H >> W;
  cin >> ch >> cw;
  ch--;
  cw--;
  cin >> dh >> dw;
  dh--;
  dw--;
  
  rep(i,H){
    string s;
    cin >> s;
    field.push_back(s);
  }

  int c = 1;
  rep(i,H){
    rep(j,W){
      if(field[i][j] == '#') continue;
      if(color[i][j] != 0) continue;
      coloring(c, i, j);
      c++;
    }
  }

  if(color[ch][cw] == color[dh][dw]){
    cout << 0 << endl;
    return 0;
  }
  M = c;
  
  rep(i,H){
    rep(j,W){
      if(color[i][j] == 0) continue;
      REP(ii,-2,3){
        REP(jj,-2,3){
          int ty = i + ii;
          int tx = j + jj;
          if(0<=tx && tx<W && 0<=ty && ty<H && color[ty][tx] != 0 && color[ty][tx] != color[i][j]){
            G[color[i][j]].insert(color[ty][tx]);
          }
        }
      }
    }
  }

  int st = color[ch][cw];
  int ed = color[dh][dw];

  cout << dijkstra(st, ed) << endl;
  
  return 0;
}



Measured memory_bytes: 74844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b,c,d,e,k;
  
   cin >> a >>b >>c >>d >>e >>k;
   
  if(e-a > k){
  cout << ":(" ;
  }else{
  cout << "Yay!" ;
  }
}



Measured memory_bytes: 256
a,b=map(int,input().split())
s=list(input())
#print(s)

if s[a]!='-':
            print('No')
            exit()
r = s[:a]
v= s[a+1:]
for i in range(len(r)):
            if str(r[i]).isdigit()==False:
                        print('No')
                        exit()
for i in range(len(v)):
            if str(v[i]).isdigit()==False:
                        print('No')
                        exit()
print('Yes')                       


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/









ll N, M;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;
    if (N > M) swap(N, M);

    ll ans;
    if (N == 1) {
        if (M == 1) ans = 1;
        else ans = M - 2;
    } else {
        ans = (N - 2) * (M - 2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

// hona method

int main()
{
	while(1)
	{
		int judges;
		int scores[1024];
		int total = 0;

		::scanf("%i", &judges);

		if(judges == 0)
		{	break;	}
		
		for(int j = 0; j < judges; j ++)
		{
			::scanf("%i", &scores[j]);
		}

		std::sort(scores, scores + judges);

		/*for(int j = 0; j < judges; j ++)
		{
			::printf("%i\n", scores[j]);
		}*/
		for(int j = 1; j < judges - 1; j ++)
		{
			total += scores[j];
		}
		printf("%i\n", total / (judges - 2));
	}
}

Measured memory_bytes: 1048
X, Y, A, B, C = map(int, input().split())
p_A = list(map(int, input().split()))
q_B = list(map(int, input().split()))
r_C = list(map(int, input().split()))
p_A2 = sorted(p_A, reverse=True)
q_B2 = sorted(q_B, reverse=True)
r_C2 = sorted(r_C, reverse=True)

ans = []
ans += p_A2[:X]
ans += q_B2[:Y]
ans = sorted(ans)

cnt = 0
for i in range(len(ans)):
    if cnt <= C-1:
        if ans[i] < r_C2[cnt]:
            ans[i] = r_C2[cnt]
            cnt += 1
print(sum(ans))

Measured memory_bytes: 109420