akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
bool vis[81][81][30000];
int n,m,a[81][81],b[81][81];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
            scanf("%d",&a[i][j]);
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
            scanf("%d",&b[i][j]);
    vis[1][1][15000+a[1][1]-b[1][1]]=1;
    vis[1][1][15000-a[1][1]+b[1][1]]=1;
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            if(i==1&&j==1)
                continue;
            for(int k=0;k<=30000;++k)
            {
                if(i-1>0&&vis[i-1][j][k])
                {
                    int x=k+a[i][j]-b[i][j];
                    if(x>=0&&x<=30000)
                        vis[i][j][x]=1;
                    x=k-a[i][j]+b[i][j];
                    if(x>=0&&x<=30000)
                        vis[i][j][x]=1;
                }
                if(j-1>0&&vis[i][j-1][k])
                {
                    int x=k+a[i][j]-b[i][j];
                    if(x>=0&&x<=30000)
                        vis[i][j][x]=1;
                    x=k-a[i][j]+b[i][j];
                    if(x>=0&&x<=30000)
                        vis[i][j][x]=1;
                }
            }
        }
    }
    int ans=30000;
    for(int k=0;k<=30000;++k)
        if(vis[n][m][k])
            ans=min(ans,abs(15000-k));
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 190208
STDIN.gets.chomp.to_i.times do
  STDIN.read.split("\n").each do |data|
    x1, y1, x2, y2, x3, y3 = data.split.map { |i| i.chomp.to_f }
    a1 = 2 * (x2 - x1)
    b1 = 2 * (y2 - y1)
    c1 = x1**2 - x2**2 + y1**2 - y2**2
    a2 = 2 * (x3 - x1)
    b2 = 2 * (y3 - y1)
    c2 = x1**2 - x3**2 + y1**2 - y3**2
    x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1)
    y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1)
    r = Math.sqrt((x1 - x)**2 + (y1 - y)**2)

    puts format('%.3f %.3f %.3f', x, y, r)
  end
end

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, a, b, c[3];

int main() {
	cin >> n >> a >> b;
	inc(i, n) {
		int p;
		cin >> p;
		if(         p <= a) { c[0]++; }
		if(a < p && p <= b) { c[1]++; }
		if(b < p          ) { c[2]++; }
	}
	
	int mi = n;
	inc(i, 3) { setmin(mi, c[i]); }
	
	cout << mi << endl;
	
	return 0;
}


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

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

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

	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());

	cout << a.size() - (n - a.size()) % 2 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int N = int(S.length()), red = 0;
  for(int i = 0; i < N; i++){
    if(S[i] == '0') red += 1;
  }
  cout << min(red, N - red) * 2 << endl;
  return 0; 
}

Measured memory_bytes: 512
X,Y = map(int, input().split())

def getM(x):
    res = 0
    if x==1:
        res += 300000
    elif x==2:
        res += 200000
    elif x==3:
        res += 100000
    return res

ans = 0
ans = getM(X)+getM(Y)

if X==1 and Y==1:
    ans += 400000

print(ans)

Measured memory_bytes: 3060
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	s := getNextString(scanner)
	t := getNextString(scanner)
	fmt.Printf("%s%s\n", t, s)
	writer.Flush()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
#define con 1000000007
using namespace std;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll i,j,m,n,k;
    ll t;
    cin>>n;
    cout<<n+n*n+n*n*n;
}





Measured memory_bytes: 3636
package main

import (
        "bytes"
        "fmt"
        "strconv"
)

func main() {
        var s string
        fmt.Scan(&s)
        nums := make([]int, 4)
        for i := 0; i < 4; i++ {
                nums[i], _ = strconv.Atoi(s[i : i+1])
        }
        for i := 0; i < 1<<uint(len(nums)-1); i++ {
                if exp, ok := calcExp(nums, i); ok {
                        fmt.Println(exp)
                        return
                }
        }
}

func calcExp(nums []int, selection int) (exp string, found bool) {
        sum := nums[0]
        buf := bytes.NewBufferString(fmt.Sprintf("%d", nums[0]))
        for idx := 1; idx < len(nums); idx++ {
                if selection&1 == 1 {
                        buf.WriteString(fmt.Sprintf("+%d", nums[idx]))
                        sum += nums[idx]
                } else {
                        buf.WriteString(fmt.Sprintf("-%d", nums[idx]))
                        sum -= nums[idx]
                }
                selection >>= 1
        }
        if sum == 7 {
                return buf.String() + "=7", true
        }
        return "", false
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	static int n;
	static int[][] g;
	static int[] d;
	static int[] f;
	static int[] color;
	static int time;

	static final int WHITE = 0;
	static final int GRAY = 1;
	static final int BLACK = 2;

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

		g = new int[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				g[i][j] = 0;
			}
		}

		for (int i = 0; i < n; i++) {
			int u = sc.nextInt();
			u--;
			int k = sc.nextInt();

			for (int j = 0; j < k; j++) {
				int v = sc.nextInt();
				v--;
				if (v >= 0) g[u][v] = 1;
			}
		}
		sc.close();

		dfs();

		for (int i = 0; i < n; i++) {
			System.out.print(i + 1);
			System.out.print(" " + d[i] + " " + f[i]);
			System.out.print("\n");
		}
	}

	static void dfs() {
		color = new int[n];
		for (int i = 0; i < n; i++) {
			color[i] = WHITE;
		}
		time = 0;
		d = new int[n];
		f = new int[n];
		for (int i = 0; i < n; i++) {
			if (color[i] == WHITE) dfsVisit(i);
		}
	}

	static void dfsVisit(int i) {
		color[i] = GRAY;
		time++;
		d[i] = time;
		for (int j = 0; j < n; j++) {
			if (color[j] == WHITE && g[i][j] == 1) dfsVisit(j);
		}
		color[i] = BLACK;
		time++;
		f[i] = time;
	}


}

Measured memory_bytes: 28684
#include<bits/stdc++.h>
#define ssg set<long long int , greater<long long int>>
using namespace std;

int main()
{
    long long int a, b, c, d, e, f, max1, max2, max3, max4;
    cin>>a>>b>>c>>d;
    e=a;
    f=c;
    max1=e*f;
    e=b;
    f=c;
    max2=e*f;
    e=a;
    f=d;
    max3=e*f;
    e=b;
    f=d;
    max4=e*f;
    ssg set1;
    set1.insert(max1);
    set1.insert(max2);
    set1.insert(max3);
    set1.insert(max4);
    set<int > :: iterator it;
    cout<<*set1.begin()<<endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  bool ans = false;
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < 16; j++) {
      if (4*i + 7*j == N) {
        ans = true;
      }
    }
  }
  if (ans) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner scan = new Scanner(System.in);
		// ?????¢?????°??????????????????
		int l1 = scan.nextInt();
		int l2 = scan.nextInt();
		int l3 = scan.nextInt();
		int l4 = scan.nextInt();
		int l5 = scan.nextInt();
		int l6 = scan.nextInt();
		// ?????????????????????
		String s = scan.next();
		int l = s.length();
		for(int i = 0; i<l; i++){
			String meirei = s.substring(i, i+1);
			int lx =0;
			if(meirei.equals("S")){
				lx = l1;
				l1 = l5;
				l5 = l6;
				l6 = l2;
				l2 = lx;
			}
			else if(meirei.equals("N")){
				lx = l1;
				l1 = l2;
				l2 = l6;
				l6 = l5;
				l5 = lx;
			}
			else if(meirei.equals("W")){
				lx = l1;
				l1 = l3;
				l3 = l6;
				l6 = l4;
				l4 = lx;
			}
			else if(meirei.equals("E")){
				lx = l1;
				l1 = l4;
				l4 = l6;
				l6 = l3;
				l3 = lx;
			}
		}
		System.out.println(l1);
		
		
	}

}

Measured memory_bytes: 26212
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

signed main(void) {
    string s;
    cin >> s;
    int n = s.size();
    vi fact(10);
    fact[0] = fact[1] = 1;
    loop(i,1,10)fact[i] = fact[i-1] * i;
    if(n < 3){
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    loop(i,3,n){
        loop(x,1,i)loop(y,1,i){
            int z = i-x-y;
            if(z < 1)continue;
            ans += fact[i]/fact[x]/fact[y]/fact[z];
        }
    }
    int dp[10][2][2][2][2] = {};
    dp[0][0][0][0][0] = 1;
    rep(i,n)rep(j,2)rep(k,2)rep(l,2)rep(m,2)if(dp[i][j][k][l][m]){
        int ne = s[i] - '0';
        if(j == 0){
            if(ne >= 3)dp[i+1][ne != 3][1][l][m] += dp[i][j][k][l][m];
            if(ne >= 5)dp[i+1][ne != 5][k][1][m] += dp[i][j][k][l][m];
            if(ne >= 7)dp[i+1][ne != 7][k][l][1] += dp[i][j][k][l][m];
        }else{
            dp[i+1][1][1][l][m] += dp[i][j][k][l][m];
            dp[i+1][1][k][1][m] += dp[i][j][k][l][m];
            dp[i+1][1][k][l][1] += dp[i][j][k][l][m];
        }
    }

    ans += dp[n][0][1][1][1] + dp[n][1][1][1][1];

    cout << ans << endl;
}


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

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

ll n,a,b;

int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	if(b<a)swap(a,b);
	if((b-a)%2==0){
		printf("%lld\n",(b-a)/2);
		return 0;
	}
	printf("%lld\n",min(a-1,n-b)+1+(b-a)/2);
	return 0;
}



Measured memory_bytes: 256
/*
 *created by Kraken on 12-04-2020 at 17:13
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int k = sc.nextInt();
        long sum = 0;
        for (int a = 1; a <= k; a++) {
            for (int b = 1; b <= k; b++) {
                for (int c = 1; c <= k; c++) {
                    sum += gcd(a, gcd(b, c));
                }
            }
        }
        System.out.println(sum);
    }

    private static long gcd (long a, long b) {
        if (a == 0) return b;
        else return gcd(b % a, a);
    }

    static class FastReader {

        BufferedReader br;

        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 32756
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

 
int main(){  
  int q;
  cin >> q;
  rep(i,q){
    ll ans=0;
    ll a,b; cin >> a >> b;
    if(a>b){swap(a,b);}
    ll sq = floor(sqrt((ld)a*b-1));
    if(a==b || b-a==1 ){cout << (a-1)*2 << endl; continue;}
    ans = (a-1)*2 + 1 + (sq-a)*2;
    if(sq*(sq+1)>a*b-1){ ans--; }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<functional>
#include<cstring>
using namespace std;
int main(void)
{
	int i,len,cnt;
	char s[101];
	scanf("%s",s);
	len=strlen(s);
	cnt=0;
	for(i=0;i<len;i++)	{
		if(s[i]=='(')	cnt++;
		if(s[i]==')')	cnt--;
		if(s[i]=='*')	break;
	}
	printf("%d\n",cnt);
	return 0;
}


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

int N, M;
int X[(int)1e5];

int main() {
    cin >> N >> M;
    rep(i, M) cin >> X[i];

    if (N > M) {
        cout << 0 << endl;
        return 0;
    }

    sort(X, X + M);

    int dp[M - 1] = {0};
    rep(i, M - 1) {
        dp[i] = X[i + 1] - X[i];
        // printf("i: %d %d %d dp[i]: %d\n", i, X[i], X[i + 1], dp[i]);
    }
    int sum = accumulate(dp, dp + M - 1, 0);
    // cout << sum << endl;

    sort(dp, dp + M - 1);

    for (int i = 1; i <= N - 1; i++) {
        sum -= dp[M - 1 - i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC045C - たくさんの数式
  // bit全探索
  string S; cin >> S;
  int N = S.size();
  ll ans = 0;
  REP(i, 1 << N-1){
    string tmp = S.substr(0, 1);
    REP(j, N-1){
      if((i >> j) & 1 == 1){
        ans += stoi(tmp);
        tmp = S.substr(j+1, 1);
      }else{
        tmp += S.substr(j+1, 1);
      }
    }
    ans += stoll(tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

// go run ./main.go < in

func main() {
	var inputs string
	fmt.Scan(&inputs)

	var format = [4]string{
		"eraser",
		"erase",
		"dreamer",
		"dream",
	}

	for _, v := range format {
		inputs = strings.Replace(inputs, v, "", -1)
	}

	if inputs == "" {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}

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

int main(){

  int N,K,ans=0;
  int num;
  cin >> N >> K;
  string S;
  cin >> S;

  for(int i=0; i<N-1; i++){
    if(S[i]==S[i+1]) ans++;
  }
  for(int i=0; i<K; i++){
    ans += 2;
  }
  ans = min(ans, N-1);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e17;
const ll MOD = 1e9 + 7;

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




int main() {
    int n, r;
    cin >> n >> r;
    
    while(n != 0 || r != 0){
        vector<int> k(n);
        REP(i, n){
            k[i] = n - i;
        }
        
        REP(i, r){
            int p, c;
            cin >> p >> c;
            vector<int> t(c);
            REP(j, c){
                t[j] = k[p - 1 + j];
            }
            for(int j = p + c - 2; j >= c; j--){
                k[j] = k[j - c];
            }
            REP(j, c){
                k[j] = t[j];
            }
        }
        
        cout << k[0] << endl;
        
        cin >> n >> r;
    }
}


Measured memory_bytes: 3020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<60;

const ll Mod=998244353;


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


int main(){
  ll i,j;
  ll n;
  cin>>n;
  ll a[n];
  VVI cnt(1000010); 
  VI u(1000010);

  for(i=0;i<n;i++) {
      cin>>a[i];
      cnt[a[i]].pb(i);
      u[1]+=a[i];
      u[1]%=Mod;
  }

  VI mul(1000010,0);

  ll ans=0;

  for(i=1000009;i>=2;i--){
      ll gen=0;
      for(j=1;i*j<1000010;j++){
          for(int l=0;l<cnt[i*j].size();l++){
              mul[i]+=a[cnt[i*j][l]];
              mul[i]%=Mod;
          }
          if(j>=2) gen=(gen+u[i*j])%Mod;
      }
      u[i]=mul[i]*mul[i]%Mod;
      u[i]=(u[i]+Mod-gen)%Mod;
      //if(u[i]>0) cout<<i<<" "<<u[i]<<endl;
  }
  //cout<<u[1]<<endl;
  u[1]=u[1]*u[1]%Mod;
  for(i=2;i<1000010;i++){
      u[1]=u[1]-u[i]+Mod;
      u[1]%=Mod;
  }
  

  for(i=1;i<1000010;i++){
      ans+=u[i]*modinv(i);
      ans%=Mod;
  }
  for(i=0;i<n;i++){
      ans=(ans+Mod-a[i])%Mod;
  }
  ans=ans*modinv(2)%Mod;
  cout<<ans<<endl;

}


Measured memory_bytes: 46592
#!/usr/bin/env python3
import sys


def solve(S: str):
    prev = ''
    pres = ''

    for x in S:
        pres = x
        if pres == prev:
            print('Bad')
            return

        prev = pres

    print('Good')

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: str
    solve(S)


if __name__ == '__main__':
    main()


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

int main() {
  int a, b, c, k;
  long long int p = 0;
  std::cin >> a >> b >> c >> k;
  long long x = std::min(a, k);
  p += (x*1);
  k -= x;
  if (k <= 0) {
    std::cout << p << std::endl;
    return 0;
  }
  long long y = std::min(b, k);
  k -= y;
  if (k <= 0) {
    std::cout << p << std::endl;
    return 0;
  }
  long long z = std::min(c, k);
  k -= z;
  p -= z;
  std::cout << p << std::endl;
  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
using namespace std;
struct shi{
    int p,f,num;
    long long y;
};
bool compare1(shi a,shi b){
    if (a.p==b.p)
        return a.y<b.y;
    return a.p<b.p;
}
bool compare2(shi a,shi b){
    return a.f<b.f;
}
int main(){
    int n,m,i,j,k=0,c,d=0;
    cin >> n >> m;
    struct shi a[m];
    for (i=0;i<m;i++){
        cin >> a[i].p >> a[i].y;
        a[i].f=i;
    }
    sort(a,a+m,compare1);
    for (i=0;i<m;i++){
        k++;
        a[i].num=k;
        if (i==m-1)
            break;
        if (a[i].p!=a[i+1].p)
            k=0;
    }
    sort(a,a+m,compare2);
    for (i=0;i<m;i++){
        c=a[i].p;
        while (c>0){
            c/=10;
            d++;
        }
        for (j=1;j<=6-d;j++)
            cout << 0;
        cout << a[i].p;
        d=0;
        c=a[i].num;
        while (c>0){
            c/=10;
            d++;
        }
        for (j=1;j<=6-d;j++)
            cout << 0;
        cout << a[i].num << endl;
        d=0;
    }
    return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
int main(int, char**)
{
	int M, D;
	cin >> M >> D;
	int counter = 0;
	for (int m = 4; m <= M; ++m)
	{
		for (int d = 22; d <= D; ++d)
		{
			if ((d % 10) < 2 || (d / 10) < 2)	continue;
			if ((d % 10) * (d / 10) == m)
			{
				++counter;
			}
		}
	}
	cout << counter << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <bitset>

//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//std::cout << std::fixed << std::setprecision(10)
//std::ios::sync_with_stdio(false);
constexpr long long MOD = 1000000007;

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

int N, M, Q;
struct X
{
  int a, b, c, d;
};
int dfs(int i, int n, std::vector<int>& A, const std::vector<X>& x)
{
  if(i == N)
  {
    int ans = 0;
    for(auto& val: x)
    {
      if(A[val.b-1] - A[val.a-1] == val.c)
        ans += val.d;
    }
    return ans;
  }

  int ans = 0;
  for(int m = n; m <= M; ++m)
  {
    A[i] = m;
    ans = std::max(ans, dfs(i + 1, m, A, x));
  }
  return ans;
}

int main()
{
  std::cin >> N >> M >> Q;
  std::vector<X> vec(Q);
  std::vector<int> A(N);
  for(auto& val: vec)
    std::cin >> val.a >> val.b >> val.c >> val.d;
  std::cout << dfs(0, 1, A, vec) << std::endl;
  return 0;
}



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

using ll = long long;
set<ll> prime_factors;

void factorize(long long a) {
    if (a % 2 == 0) {
        prime_factors.insert(2);
    }
    while (a % 2 == 0) {
        a = a / 2;
    }
    for (long long i = 3; i * i <= a; i += 2) {
        if (a % i == 0) {
            prime_factors.insert(i);
            while (a % i == 0) {
                a = a / i;
            }
        }
    }
    if (a > 2) {
        prime_factors.insert(a);
    }
}

int main() {
    long long a, b;
    cin >> a >> b;
    prime_factors.insert(1);

    factorize(a);
    long long ans = 0;
    for (auto x : prime_factors) {
        if (b % x == 0) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <utility>
using namespace std;

#define x first
#define y second

typedef pair<int,int> pii;

const int margin = 2;
int maze[128][128];
bool visited[128][128];
int h, w;

int main() {
	while(cin >> w >> h, w || h) {
		for(int i = 0; i < 128; i++){
			for(int j = 0; j < 128; j++) {
				maze[i][j] = -1;
				visited[i][j] = false;
			}
		}
		pii s, g;
		cin >> s.x >> s.y; s.x--; s.y--;
		cin >> g.x >> g.y; g.x--; g.y--;
		int n;
		cin >> n;
		for(int i = 0; i < n; i++) {
			int c, d, x_, y_;
			int l[][2] = {{2,4},{4,2}};
			cin >> c >> d >> x_ >> y_; x_--; y_--;
			for(int i = 0; i < l[d][0]; i++) {
				for(int j = 0; j < l[d][1]; j++) {
					maze[y_+i + margin][x_+j + margin] = c;
				}
			}
		}

		queue<pii> q;
		q.push(s);
		bool flg = false;
		while(!q.empty()) {
			pii cur;
			cur = q.front(); q.pop();

			if(cur == g) {
				flg = true;
				break;
			}

			int dx[] = {1,-1,0,0};
			int dy[] = {0,0,1,-1};
			for(int i = 0; i < 4; i++) {
				if(maze[cur.y+margin][cur.x+margin] == maze[cur.y+dy[i]+margin][cur.x+dx[i]+margin] && !visited[cur.y+dy[i]+margin][cur.x+dx[i]+margin]) {
					q.push(pii(cur.x+dx[i], cur.y+dy[i]));
					visited[cur.y+dy[i]+margin][cur.x+dx[i]+margin] = true;
				}
			}
		}

		if(flg)
			cout << "OK" << endl;
		else
			cout << "NG" << endl;
	}
}

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

int main(){
  int n,k,a[110],sum=0;
  cin>>n>>k;
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++) sum+=2*min(a[i],abs(k-a[i]));
  cout<<sum;
}


Measured memory_bytes: 256
import sys
n = int(input())
d = {}
for i in input().split():
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

m = int(input())
for i in input().split():
    if i in d and d[i] > 0:
        d[i] -= 1
    else:
        print("NO")
        sys.exit()
print("YES")


Measured memory_bytes: 46432
n = int(input())
h = list(map(int, input().split()))
INF = 10**18

dp = [INF] * (n)
dp[0] = 0

for i in range(n):
    if i+1 < n:
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]))
    if i+2 < n:
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]))
print(dp[-1])

Measured memory_bytes: 52592
h,w = map(int, input().split())
can = []
if h%3 == 0 or w%3 == 0:
    can.append(0)
if h > 3:
    can.append(w)
if w > 3:
    can.append(h)

for a in range(w//3, w//2+1):
    size = [h * a]
    if h%2 == 0:
        size.append(h//2 * (w-a))
        size.append(h//2 * (w-a))
    else:
        size.append(h//2 * (w-a))
        size.append((h//2 + 1) * (w-a))
    can.append(max(size) - min(size))

for a in range(h//3, h//2+1):
    size = [w * a]
    if w%2 == 0:
        size.append(w//2 * (h-a))
        size.append(w//2 * (h-a))
    else:
        size.append(w//2 * (h-a))
        size.append((w//2 + 1) * (h-a))
    can.append(max(size) - min(size))
print(min(can))

Measured memory_bytes: 4368
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long mod = 1000000007;
		
		long ans = powmod(10,N)-powmod(9,N)-powmod(9,N)+powmod(8,N);
		ans %= mod;
		ans = (ans + mod) % mod;
		System.out.println(ans);
		
	}
	public static long powmod(long x, long n){
		long mod = 1000000007;
      	long res = 1;
      
		for(long i = 0; i < n; i++){
			res = res * x % mod;
		}
		return res;
	}
}


Measured memory_bytes: 35672
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.nio.Buffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.util.Vector;

public class Main {
    public static Scanner r=new Scanner(System.in);
    public static void main(String[] args) {
        int n=r.nextInt();
        int k=r.nextInt();
        ArrayList<Integer> p=new ArrayList<>();
        for(int i=0;i<n;++i){
            int x=r.nextInt();
            p.add(x);
        }
        Collections.sort(p);
        int ans=0;
        for(int i=0;i<k;++i) ans+=p.get(i);
        System.out.println(ans);
    }
}


Measured memory_bytes: 38952
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

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 (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

ll dp[2010][2010];

int main() {
    int N,M; cin>>N>>M;
    vector<int> S(N),T(M);
    for (int i = 0; i < N; ++i) {
        cin>>S[i];
    }
    for (int i = 0; i < M; ++i) {
        cin>>T[i];
    }

    dp[0][0]=1ll;
    for (int i = 0; i <= N; ++i) {
        dp[i][0]=1ll;
    }
    for (int i = 0; i <= M; ++i) {
        dp[0][i]=1ll;
    }
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= M; ++j) {
            dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+MOD)%MOD;
            if(S[i-1]==T[j-1]) (dp[i][j]+=dp[i-1][j-1])%=MOD;

        }
    }

    cout<<dp[N][M]<<endl;

    return 0;
}


Measured memory_bytes: 31744
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long N, A, B;
  cin >> N >> A >> B;
  if((B-A)%2==0){
    cout << (B-A)/2 << endl;
  }else{
    if(N-A<=B-1){
      cout << N+1-B + (N-(A+(N+1-B)))/2 << endl;
    }else{
      cout << A + ((B-A)-1)/2 << endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
#include <math.h>   
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>

using namespace std;


int main(){
    int N;
    cin >> N;
    int digit = log10(N)+1;
    int answer = 0;

    for(int i=1;i<digit; i+=2){
        answer+=9*pow(10, i-1);
    }


    if(digit%2==1){
        answer += N - pow(10, digit-1)+1;
    }

    cout<< answer << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s[3];
  cin>>s[0]>>s[1]>>s[2];
  int cnt[3]={};
  int x=0;
  while(1){
    if(cnt[x]==s[x].size()){
      if(x==0)cout<<'A'<<endl;
      if(x==1)cout<<'B'<<endl;
      if(x==2)cout<<'C'<<endl;
      break;
    }
    char tmp=s[x][cnt[x]++];
    if(tmp=='a')x=0;
    if(tmp=='b')x=1;
    if(tmp=='c')x=2;
  }
  return 0;
}


Measured memory_bytes: 256
//
// Created on 2020/08/28.
//

#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
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



int main() {
    int x;
    cin>>x;
    if(x == 7 || x==5 || x==3){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3628
#include <stdio.h>
#define N 100000

int main(){

  int S[N],SA[N],i,num,num2;
  int cnt = 0;
  int right,left;
  
  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d",&S[i]);
  }
  
  int mid;
 
  scanf("%d",&num2);
  for(i=0;i<num2;i++){
    scanf("%d",&SA[i]);
  }
  
  for(i=0;i<num2;i++){
    
  left = 0;
  right = num;

  while(left < right){
      mid = (left + right)/2;
      if(SA[i] == S[mid]) {
	cnt++;
	break;
      }
      if(SA[i] > S[mid]) left = mid +1;
      else if(SA[i] < S[mid]) right = mid;
    }
  }

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


  return 0;
}



Measured memory_bytes: 2356
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#include<map>
#include<iostream>
#include<math.h>
#define ll long long
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;



int main(){
    string S, T;
    cin >> S;
    cin >> T;
    int cnt = 0;
    for(int i = 0; i < S.length(); i++){
        if(S[i] != T[i]) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3916
def main():
    X, Y = map(int, input().split())

    ans = 0;

    if X == 1:
        ans += 300000
    elif X == 2:
        ans += 200000
    elif X == 3:
        ans += 100000

    if Y == 1:
        ans += 300000
    elif Y == 2:
        ans += 200000
    elif Y == 3:
        ans += 100000

    if X == 1 and Y == 1:
        ans += 400000

    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

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

    int N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    ll ans = 0;
    ll ret = 0;
    rep(i,N) {
        ans += ret*A[i]%MOD;
        ans %= MOD;
        ret += A[i];
        ret %= MOD;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4764
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int x;
  int i = 1;
  while (1) {
    cin >> x;
    if (x == 0) break;
    cout << "Case " << i << ": " << x << endl;
    ++i;
  }
  return 0;
}


Measured memory_bytes: 3084
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main() {
	int top, stack[101];
	char input[8];

	top = 0;
	while (scanf("%s", input) != EOF) {
		if ('+' == input[0]) {
			top--;
			stack[top] += stack[top + 1];
		}
		else if ('-' == input[0]) {
			top--;
			stack[top] -= stack[top + 1];
		}
		else if ('*' == input[0]) {
			top--;
			stack[top] *= stack[top + 1];
		}
		else {
			top++;
			stack[top] = atoi(input);
		}
	}
	printf("%d\n", stack[top]);

	return 0;
}


Measured memory_bytes: 2140
#include<iostream>
#include<functional>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef unsigned long long ll;
using namespace std;


ll gcd(ll a,ll b)
{
    if(a!=0 && b==0)
    {
        return a;
    }
    if(a%b==0)
    {
        return b;
    }
    else
    {
        return(gcd(b,a%b));
    }
    
}

ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

int main()
{
    int n;
    cin>>n;
    ll ans=1;

    rep(i,n)
    {
        ll t;
        cin>>t;
        ans=lcm(ans,t);
        
    }
    cout<<ans;


}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifndef U_L_LONG
typedef unsigned long long ULLONG;
#endif
#ifndef L_LONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static void ABC093C_SameIntegers();

#if 1
int main()
{
	ABC093C_SameIntegers();
	fflush(stdout);
	return 0;
}
#endif

static void ABC093C_SameIntegers()
{
	int ints[4] = { 0 };

	for (int i = 0; i < 3; i++) {
		get1int(ints[i]);
	}
	std::sort(ints, ints + 3);
	
	int diff1 = ints[1] - ints[0];

	int ope = 0;
	ope += diff1 / 2;
	ints[0] = ints[1];
	if (diff1 % 2) {
		ope++;
		ints[2]++;
	}

	int diff2 = ints[2] - ints[0];
	ope += diff2;

	printf("%d\n", ope);
}



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;
using P = pair<int,int>;

int main() {
  int k,x;
  cin >> k >> x;
  if(500 * k >= x) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef long double ld;
const ld pi = 4*atan((ld)1);
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll nax = 0;

struct info{
	ll w, x, y;
};

struct cmp{
	bool operator()(info xx, info yy){
		return xx.w > yy.w;
	}
};

ll n, m;
ll vis[1005][1005];
vector<vector<ll>> dis(1005, vector<ll> (1005, inf));
ll baris[] = {1, -1, 0, 0}, kolom[] = {0, 0, 1, -1};
string s[1005];
pair<ll,ll> c, d;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	cin >> n >> m;
	cin >> c.ff >> c.ss;
	cin >> d.ff >> d.ss;
	c.ff--, c.ss--, d.ff--, d.ss--;
	for(ll i = 0; i < n; i++){
		cin >> s[i];
	}
	
	priority_queue<info, vector<info>, cmp> q;
	q.push({0, c.ff, c.ss});
	dis[c.ff][c.ss] = 0;
	while(!q.empty()){
		auto cur = q.top();
		q.pop();
		
		if(vis[cur.x][cur.y]){
			continue;
		}
		vis[cur.x][cur.y] = 1;
		for(ll i = 0; i < 4; i++){
			ll x = cur.x + baris[i];
			ll y = cur.y + kolom[i];
			if(x >= 0 && x < n && y >= 0 && y < m && s[x][y] != '#'){
				if(dis[x][y] > dis[cur.x][cur.y]){
					dis[x][y] = dis[cur.x][cur.y];
					q.push({dis[x][y], x, y});
				}
			}
		}
		for(ll i = -2; i < 3; i++){
			for(ll j = -2; j < 3; j++){
				ll x = cur.x + i;
				ll y = cur.y + j;
				if(x >= 0 && x < n && y >= 0 && y < m && s[x][y] != '#'){
					if(dis[x][y] > dis[cur.x][cur.y] + 1){
						dis[x][y] = dis[cur.x][cur.y] + 1;
						q.push({dis[x][y], x, y});
					}
				}
			}
		}
	}	
	ll ans = dis[d.ff][d.ss];
	if(ans == inf){
		ans = -1;
	}
	cout << ans << '\n';
}



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

/** AOJ_No.1147 ICPC_2007_A */
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			/* 審査員数 */
			int n = sc.nextInt();
			if(n == 0) break;
			
			int[] score = new int[n];
			for(int i = 0; i < n; i++) {
				score[i] = sc.nextInt();
			}
			
			int sum = 0;
			Arrays.sort(score);
			/* 最高評価と最低評価は除く合計 */
			for(int i = 1; i < n - 1; i++) {
				sum += score[i];
			}
			
			/* 平均を出力 */
			System.out.println(sum/(n - 2));
		}
	}
}



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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
typedef long long ll;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b>=c)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
n = input()
print("ABC"+n)
#B

#C
"""
def dijkstra():
    d[0] = 0
    q = [[0,0]]
    while q:
        dx, x = heappop(q)
        for y in v[x]:
            if d[y] > dx+1:
                d[y] = dx+1
                heappush(q,[d[y],y])
n,m = LI()
v = [[] for i in range(n)]
for i in range(m):
    a,b = LI()
    a -= 1
    b -= 1
    v[a].append(b)
    v[b].append(a)
d = [float("inf") for i in range(n)]
dijkstra()
if d[n-1] <= 2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
"""

#D
"""
k = I()
ans = [i+k//50 for i in range(50)]
k %= 50
for i in range(k):
    ans[i] += 51
    for j in range(50):
        ans[j] -= 1
print(50)
print(*ans)
"""

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 38512
#include<iostream>
#include<stack>
using namespace std;
const int N=1010;
int main()
{
    int T,Z;
    stack<int> s[N];
    cin>>Z>>T;
    while(T--)
    {
        int c;
        cin>>c;
        switch (c)
        {
            case 0:
        {
            int n,m;
            cin>>n>>m;
            s[n].push(m);
        }break;
        case 1:
        {
            int n;
            cin>>n;
            if(s[n].size())
            cout<<s[n].top()<<endl;
        }break;
        case 2:
        {
            int n;
            cin>>n;
            if(s[n].size())
            {
                s[n].pop();
            }
        }break;
        default: break;
        }
        
    }
}


Measured memory_bytes: 4444
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> trp;
typedef vector<ll> vi;
typedef vector<pll> vp;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define pob         pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define sc3(a,b,c)  cin>>a>>b>>c
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"Yes"<<endl
#define prN         cout<<"No"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define	mp3(a,b,c)  make_pair(a,make_pair(b,c))
#define se          second
#define fi          first 
#define sse         second.second
#define sfi         second.first
#define soA         sort(A+1,A+1+n)
#define so(A,n)     sort(A+1,A+1+n)
#define sov(v)      sort(all(v))
#define sovr(v)     sort(all(v),greater<ll>())
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5];

ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	sc2(n,m);
	f1(i,n)sc(A[i]); soA;
	f1(i,n-m)sum+=A[i];
	pr(sum);
	
	
	
	
	
	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	if(fopen("locin.txt", "r"))INPUT;
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	} 		
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
       Scanner s = new Scanner (System.in);
       
       int E = s.nextInt();
       int Y = s.nextInt();
       
       if(1912 > Y && Y > 1867){
           int A = Y-1867;
           System.out.print("M");
           System.out.println(A);
       }else if(1926 > Y && Y >1911){
           int B = Y-1911;
           System.out.print("T");
           System.out.println(B);
       }else if(1989 > Y && Y > 1925){
            int C = Y-1925;
            System.out.print("S");
            System.out.println(C);
       }else if(2017 > Y && Y > 1988){
           int D = Y-1988;
           System.out.print("H");
           System.out.println(D);
       }else if(E == 1){
           System.out.println(Y+1867);
       }else if(E == 2){
           System.out.println(Y+1911);
       }else if(E == 3){
            System.out.println(Y+1925);
       }else if(E == 4){
            System.out.println(Y+1988);
       }
}}
       
       

Measured memory_bytes: 26212
def calc_height(list_child, id_now):
    height_left = 0
    height_right = 0

    id_child_left = list_child[id_now][0]
    if id_child_left != -1:
        height_left = calc_height(list_child, id_child_left) + 1
    
    id_child_right = list_child[id_now][1]
    if id_child_right != -1:
        height_right = calc_height(list_child, id_child_right) + 1

    return max(height_left, height_right)


# INPUT
n = int(input())


list_child = [[] for _ in range(n)]
list_parent = [-1 for _ in range(n)]

for _ in range(n):

    id, *C = map(int, input().split())

    list_child[int(id)].extend(C)

    for c in C:
        if c == -1:
            continue

        list_parent[int(c)] = int(id)


# PROCESS, OUTPUT
for id in range(n):

    parent = list_parent[id]

    if parent == -1:
        sibling = -1
    else:
        if list_child[parent][0] == id:
            sibling = list_child[parent][1]
        else:
            sibling = list_child[parent][0]

    degree = 2 - list_child[id].count(-1)

    depth = 0
    parent_now = parent

    while parent_now != -1:
        depth += 1
        parent_now = list_parent[parent_now]


    if depth == 0:
        type_node = "root"
        height = calc_height(list_child, id)
    elif list_child[id][0] == list_child[id][1] == -1:
        type_node = "leaf"
        height = 0
    else:
        type_node = "internal node"
        height = calc_height(list_child, id)

    print(f"node {id}: parent = {parent}, sibling = {sibling}, degree = {degree}, depth = {depth}, height = {height}, {type_node}")



Measured memory_bytes: 5624