akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll int MOD=1e9+7;
#define INF 2*1e9
#define N 310000 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

main(){
    int n,k;
    cin>>n>>k;
    bitset<N> b;
    string ss;
    cin>>ss;
    for(int i=ss.size()-1;i>=0;i--){
        if(ss[i]=='A') b[(int)ss.size()-1-i]=1;
    }
    int s=ss.size()-1,sss=ss.size()-1;
    int count[N]={},t=1,a=1;
    while(sss>=0){
        if(t==b[sss]) count[a]=count[a-1]+2;
        else count[a]=count[a-1]+1;
        if(count[a]>k) break;
        t^=1; a++; sss--;
    }
    if(count[a]>k){
        a--;
        b<<=a;
        if(a%2) b.flip();
        if(count[a]<k){
            b[s]=0;
        }
        rep(i,a){
            b[i]=(i+1)%2;
        }
    }
    else{
        k-=count[s+1];
        rep(i,ss.size()){
            b[i]=(i+1)%2;
        }
        if(k%2&&n%2) b[s]=0;
    }
    while(s>=0){
        if(b[s]) cout<<'A';
        else cout<<'B';
        s--;
    }
}



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

// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
    ll N, M; cin >> N >> M;
    vector<int> p(N);
    rep(i, N){
        cin >> p[i];
    }
    UnionFind U(N+1);
    rep(i, M){
        int x, y; cin >> x >> y;
        U.merge(x, y);
    }
    int ans = 0;
    rep(i, N){
        if(p[i] == i+1){
            ans++;
        } else if(U.issame(p[i], i+1)){
            ans++;
        } else {
            continue;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4996
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n;

	public static void main(String[] args){
		read();
		slove();
	}
	static boolean read(){
		n = sc.nextInt();
		return true;
	}
	static void slove(){
		double Debt = 100000;
		for(int i = 1; i <= n; i++){
			Debt = Debt*1.05;
			int r = (int)Debt%1000;
			if(r != 0){
				Debt += 1000;
				Debt -= r;
				Debt = Math.round(Debt);
			}
		}
		System.out.println((int)Debt);
	}


}

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

using namespace std;

int main() {
    int n,ans,count = 0;
    cin >> n;
    vector<int> tmp(n-1);
    vector<int> A(n);

    for (int i=0; i<n-1; ++i)
        cin >> tmp.at(i);

    for (int i=0; i<n-1; ++i) {
        if (count == 0 || tmp.at(i) < A.at(i))
            A.at(i) = tmp.at(i);
        A.at(i+1) = tmp.at(i);
        ++count;
    }

    ans = accumulate(A.begin(), A.end(), 0);
    cout << ans;
}


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

int main()
{
	int n;
	stack<int> s;
	while (cin >> n){
		if (n == 0){
			cout << s.top() << endl;
			s.pop();
		}else{
			s.push(n);
		}
	}
	return 0;
}

Measured memory_bytes: 1200
package main

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

var sc = bufio.NewScanner(os.Stdin)

func StrStdin() (stringInput string){
  sc.Scan()
  OneLineString := sc.Text()
  stringInput = strings.TrimSpace(OneLineString)
  return 
}

func IntStdin() (int, error){
  stringInput := StrStdin()
  return strconv.Atoi(stringInput)
}

// ?????????????l??????????Split()
func SplitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
    stringSplited := strings.Split(stringTargeted, delim)

    for _, str := range stringSplited {
        if str != "" {
            stringReturned = append(stringReturned, str)
        }
    }

    return
}

// ?f???~?^??????????????X???C?X???��
func SplitStrStdin(delim string) (stringReturned []string) {
    // ???????1?s?��
    stringInput := StrStdin()
  
    // ???????
    // stringSplited := strings.Split(stringInput, delim)
    stringReturned = SplitWithoutEmpty(stringInput, delim)

    return
}

// ?f???~?^?????????????l?X???C?X???��
func SplitIntStdin(delim string) (intSlices []int, err error) {
    // ??????X???C?X???��
    stringSplited := SplitStrStdin(delim)
	
    // ?????X???C?X????
    for i := range stringSplited {
        var iparam int
        iparam, err = strconv.Atoi(stringSplited[i])
        if err != nil {
            return
        }
        intSlices = append(intSlices, iparam)
    }
    return
}

func main(){
  intlist, _ := SplitIntStdin(" ")
  result := 0
  for i:=1;i <= intlist[0];i++ {
    num := i
    sum := 0
    for num > 0 {
      sum += num % 10
      num = num / 10
    }
    if sum <= intlist[2] && sum >= intlist[1] {
		result += i
    }
  }
  fmt.Println(result)
}

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

int main() {
  ll n,m,q;
  cin>>n>>m>>q;
  vector<vector<ll>> v(n+5,vector<ll>(n+5,0));
  vector<vector<ll>> s(n+5,vector<ll>(n+5,0));
  vector<vector<ll>> S(n+5,vector<ll>(n+5,0));


  rep(i,m){
    ll l1,r1;
    cin>>l1>>r1;
    l1;r1;
    v[l1][r1]+=1;
  }
  rep(i,n){
    s[1][i]=v[1][i];
  }
  rep(i,n){
    s[i][1]=v[i][1];
  }
  rep(i,n+1)rep(j,n){
    s[i][j+1]=s[i][j]+v[i][j+1];
  //  cout<<s[i][j+1]<<' '<<i<<' '<<j+1<<endl;
  }
  S=s;
  rep(i,n)rep(j,n+1){
    S[i+1][j]=S[i+1][j]+S[i][j];
  //  cout<<S[i+1][j]<<' '<<i+1<<' '<<j<<endl;
  }
  rep(i,n+1)rep(j,n+1){
  //  S[i+1][j]=S[i+1][j]+S[i][j];
//    cout<<S[i][j]<<' '<<i<<' '<<j<<endl;
  }
  rep(i,q){
    ll p1,q1;
    cin>>p1>>q1;
    p1;q1;

    ll t1,t2,t3,t4;
    t1=S[q1][q1];
    t2=S[p1-1][q1];
    t3=S[q1][p1-1];
    t4=S[p1-1][p1-1];
    ll ans=t1-t2-t3+t4;
    cout<<ans<<endl;
  }


}


Measured memory_bytes: 6912
/*
 * Aizu Online Judge
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author yoshkur
 */
public class Main {

	/**
	 * @param args the command line arguments
	 */
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			InputData inputData = new InputData(br);
			Processing processing = new Processing(inputData);
			System.out.println(processing.getResult());

		} catch (IOException | NumberFormatException e) {
			System.err.println(e.getLocalizedMessage());
		}
	}
}

class InputData {

	private Integer a;
	private Integer b;
	private Integer c;

	public InputData(BufferedReader br) throws IOException {
		String line = br.readLine().trim();
		String[] values = line.split(" ");
		this.a = Integer.valueOf(values[0]);
		this.b = Integer.valueOf(values[1]);
		this.c = Integer.valueOf(values[2]);
	}

	public Integer getA() {
		return a;
	}

	public void setA(Integer a) {
		this.a = a;
	}

	public Integer getB() {
		return b;
	}

	public void setB(Integer b) {
		this.b = b;
	}

	public Integer getC() {
		return c;
	}

	public void setC(Integer c) {
		this.c = c;
	}
}

class Processing {

	private InputData inputData;

	public Processing(InputData inputData) {
		this.inputData = inputData;
	}

	public String getResult() {
		String result = null;
		if (this.inputData.getA() < this.inputData.getB()
				&& this.inputData.getB() < this.inputData.getC()) {
			result = "Yes";
		} else {
			result = "No";
		}
		return result;
	}
}

Measured memory_bytes: 24160
class PrimeFactor():

    def __init__(self, n):                  # エラトステネス　O(N loglog N)
        self.n = n
        self.table = list(range(n+1))       # 最小素因数のリスト
        self.table[2::2] = [2]*(n//2)
        for p in range(3, int(n**0.5) + 2, 2):
            if self.table[p] == p:
                for q in range(p * p, n + 1, 2 * p):
                    if self.table[q] == q:
                        self.table[q] = p

    def is_prime(self, x):  # 素数判定　O(1)
        if x < 2:
            return False
        return self.table[x] == x

p = PrimeFactor(10**6)

X = int(input())

while True:
    if p.is_prime(X):
        print(X)
        exit()
    else:
        X += 1


Measured memory_bytes: 77116
#include<stdio.h>

int main(void){
	int i,j;
	int n;

	scanf("%d",&n);

	for(i=0;i*7 <= n;i++){
		for(j=0;j*4+i*7 <= n;j++){
			if(j*4+i*7 == n){
				printf("Yes\n");
				return 0;
			}

		}
	}

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



Measured memory_bytes: 128
#E 復習復習
N = int(input())
K = int(input())
 
from functools import lru_cache
 
@lru_cache(None)
def f(n, K):
    if n <= 10:
        if K == 0:
            return 1
        if K == 1:
            return n
        return 0
    div_n = n//10
    mod_n = n%10
    ans = 0
#     if K >= 1:
    ans += f(div_n, K-1) * mod_n
    ans += f(div_n-1, K-1) * (9 - mod_n)
    ans += f(div_n, K)
    return ans
 
print(f(N, K))

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

int main() {
  int64_t a,b=0;
  string S;
  cin>>a>>S;
  b+=(S.at(0)-'0')*100+(S.at(2)-'0')*10+(S.at(3)-'0');
  int64_t x=a/100,y=a%100;
  int64_t N=x*b;
  while(x!=0&&b!=0){
    if((N-1)/x>=b){
      N--;
    }
    else{
      break;
    }
  }
  int q=y*b;
  q/=100;
  N+=q;
  cout<<N<<endl;
}

Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	final int _intMax = Integer.MAX_VALUE; //=2147483647>10^9
	final int _intMin = Integer.MIN_VALUE;
	final long _longMax = Long.MAX_VALUE; //=9223372036854775807L>10^18
	final long _longMin = Long.MIN_VALUE;
	static boolean bElapsed = false;

	void solve() {
		String[] flds = readFlds();
		long a = pint(flds[0]);
		long b = pint(flds[2]);
		long ans = 0;
		if ("+".equals(flds[1])) {
			ans = a + b;
		} else if ("-".equals(flds[1])) {
			ans = a - b;
		}
		pln(ans);
	}

	int pint(String s) {
		return Integer.parseInt(s);
	}
	long plong(String s) {
		return Long.parseLong(s);
	}
	String readLine() {
		try {
			return _in.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
	int readNum() {
		String line = readLine();
		return pint(line);
	}
	String[] readFlds() {
		String line = readLine();
		return line.split(" ");
	}
	int[] readNums() {
		String[] flds = readFlds();
		int[] nums = new int[flds.length];
		for (int i=0; i<flds.length; i++) {
			nums[i] = pint(flds[i]);
		}
		return nums;
	}
	void p(char c) {
		_out.print(c);
	}
	void pln(char c) {
		_out.println(c);
	}
	void p(double d) {
		_out.print(d);
	}
	void pln(double d) {
		_out.println(d);
	}
	void p(long l) {
		_out.print(l);
	}
	void pln(long l) {
		_out.println(l);
	}
	void p(String s) {
		_out.print(s);
	}
	void pln(String s) {
		_out.println(s);
	}
	static BufferedReader _in;
	static PrintWriter _out;
	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		_in = new BufferedReader(new InputStreamReader(System.in));
		_out = new PrintWriter(System.out);
		new Main().solve();
		_out.flush();
		long end = System.currentTimeMillis();
		if (bElapsed) {
			System.err.println((end-start) + "ms");
		}
	}
}


Measured memory_bytes: 8276
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#define rep(i,n) for(int i = 0;i < n;i++)
#define N 20005
using namespace std;

int h[N],wh[N];
int nh;
string S;

int main(){
    std::cin >> S;
    int l = S.length();
    h[0]=0;
    for(int i=1;i<=l;i++){
        switch(S[i-1]){
            case '\\':
                h[i]=h[i-1]-1;
                break;
            case '/':
                h[i]=h[i-1]+1;
                break;
            case '_':
                h[i]=h[i-1];
                break;
        }
    }
    int nwh=0;
    int ans = 0;
    wh[0]=0;
    for(int i = 1;i<=l;i++){
        nwh=max(nwh,h[i]);
        wh[i]=nwh;
    }
    nwh=h[l];
    wh[l]=min(wh[l],nwh);
    for(int i = l-1;i>=0;i--){
        nwh=max(nwh,h[i]);
        wh[i]=min(wh[i],nwh);
    }
    vector<int> ws;
    int left = 0;
    int ar2=0;
    for(int i = 1;i<=l;i++){
        ar2 += wh[i]+wh[i-1]-h[i]-h[i-1];
        if(wh[left]==h[i]){
            if(ar2){ws.push_back(ar2/2);
                }
            ans+=ar2;
            left=i;
            ar2=0;
        }else if(wh[i]!=wh[left]){
            left = i;
        }
    }
    cout<<ans/2<<endl;
    if(!ws.empty()){
        cout<<ws.size()<<" ";
        rep(i,ws.size()-1){
            cout<<ws[i]<<" ";
        }
        cout<<ws.back()<<endl;
    }else{
        cout<<0<<endl;
    }
}

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

int main()
{
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	
	int cnt = 0, check = 1;
	for (int i = 0; i < n; ++i)
	{
		if (a[i] == check)
		{
			check++;
		}
		else
		{
			cnt++;
		}
	}
	
	if (n == cnt)
	{
		cout << -1 << endl;
	}
	else
	{
		cout << cnt << endl;
	}
	
	
	
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main()
{
  int a,b,c,d,e;
  
  cin>>a>>b>>c>>d>>e;
  
  if(a==0)
    cout<<1;
  
  else if(b==0)
    cout<<2;
  
  else if(c==0)
    cout<<3;
  
  else if(d==0)
    cout<<4;
  
  else
    cout<<5;
  
  return 0;
}

Measured memory_bytes: 3596
package main

import (
	"fmt"
	"sort"
)

func primeFactors(n int) map[int]int {
	res := make(map[int]int, 0)
	for i := 2; i*i <= n; i++ {
		for n > 0 {
			if n%i == 0 {
				n /= i
				res[i]++
			} else {
				break
			}
		}
	}
	if n > 1 {
		res[n]++
	}
	return res
}

func main() {
	var n int
	fmt.Scan(&n)
	// fmt.Println("prime factors of n", primeFactors(n))
	pf := primeFactors(n)
	ks := make([]int, 0)
	for k := range pf {
		ks = append(ks, k)
	}
	sort.Ints(ks)
	fmt.Printf("%d:", n)
	for i := range ks {
		for j := 0; j < pf[ks[i]]; j++ {
			fmt.Printf(" %d", ks[i])
		}
	}
	fmt.Println()
}



Measured memory_bytes: 1228
import java.util.*;import java.io.*;import java.math.*;

public class Main
{

    public static void process()throws IOException
    {
    	int n=ni();
    	TreeSet<Integer> set = new TreeSet<Integer>();

    	for(int i=1;i<=n;i++){
    		set.add(ni());
    	}

    	if(set.size()==n)
    		pn("YES");
    	else
    		pn("NO");
    }


   	static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new AnotherReader();
        boolean oj = true;

    	//oj = System.getProperty("ONLINE_JUDGE") != null;
    	if(!oj) sc=new AnotherReader(100);

        long s = System.currentTimeMillis();
        int t=1;
        while(t-->0)
            process();
        out.flush();
        if(!oj)
            System.out.println(System.currentTimeMillis()-s+"ms");
        System.out.close();  
    }

    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);System.out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    static boolean multipleTC=false;



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

    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
	
	
	

Measured memory_bytes: 59664
#include<stdio.h>
  int A[100000];

int Partition(int p, int r){
  int t;
  int x,i,j;
  x = A[r];
  i = p-1;
  for( j = p; j< r;j++){
    if (A[j] <= x){
	i = i+1;
	t=A[i];
	A[i]=A[j];
	A[j]=t;
      }
  }
    t = A[i+1];
    A[i+1] = A[r];
    A[r] = t;
  return i+1;
}
int main(){
  int i,p,n;
  int c;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  p=0;
  c=Partition(p, n-1);
  for(i=0;i<n;i++){
    if(i!=0)printf(" ");
    if(c==i)printf("[%d]",A[i]);
    else printf("%d",A[i]);
    }
  printf("\n");
  return 0;
}

Measured memory_bytes: 800
#include <iostream>
#include <string>
#include <set>

using namespace std;

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

  set<string> words;

  char last_letter = ' ';

  bool flag = true;
  
  for (int n=0; n<N && flag; ++n) {
    string word;
    cin >> word;

    cerr << word << endl;
    
    if (last_letter != ' ' && word[0] != last_letter)
      flag = false;
    else if (words.count(word) > 0)
      flag = false;
    else {
      last_letter = word[word.size()-1];
      words.insert(word);
    }
  }

  cout << (flag? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define unique(a)        (a).erase(unique((a).begin(), (a).end()),(a).end())
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define mod 1000000007 
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
inline LL moduloMultiplication(LL x, LL y) { return (x%mod * 1LL * y%mod) % mod; }
inline LL power(LL a, LL b) {
	LL x = 1 % mod;
	while (b) {
		if (b & 1) x = moduloMultiplication(x, a);
		a = moduloMultiplication(a, a);
		b >>= 1;
	}
	return x % mod;
}

LL gcd(LL a, LL b)
{
	if (!a)
		return b;
	return gcd(b%a, a);
}
inline LL add(LL x, LL y) { x += y; if (x >= mod) x -= mod; return x; }
int main()
{
	int n;
	cin >> n;
	VI v(n);
	VI v1(n);
	int count = 1;
	rep(i, n) {
		cin >> v[i];
		if (i) { v1[i] = min(v[i], v1[i - 1]); 
		if (v[i] <= v1[i])count++;

		}
		else
			v1[i] = v[i];
	}
	cout << count << endl;

	
}


Measured memory_bytes: 1792
import java.io.*;
import java.util.*;
import java.util.function.*;

class Child {
	Child(int x, int a) {
		this.x = x;
		this.a = a;
	}

	int x;
	int a;

	long happiness(long moveTo) {
		return a * Math.abs(moveTo - x);
	}
}

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		int[] A = new int[N];
		Arrays.setAll(A, $ -> Integer.parseInt(sc.get()));

		Child[] children = new Child[N];
		for (int i = 0; i < children.length; i++) {
			children[i] = new Child(i, A[i]);
		}

		Arrays.sort(children, Comparator.comparingInt(c -> -c.a));

		var memo = new long[N + 1][N + 1];
		for (int placed = 0; placed < N; placed++) {
			for (int left = 0; left <= placed; left++) {
				var prev = memo[placed][left];
				var next = children[placed];

				var right = N - 1 - (placed - left);

				memo[placed + 1][left] = Math.max(memo[placed + 1][left], prev + next.happiness(right));
				memo[placed + 1][left + 1] = Math.max(memo[placed + 1][left + 1], prev + next.happiness(left));
			}
		}

		long max = 0;

		for (long l : memo[N]) {
			max = Math.max(max, l);
		}

		System.out.println(max);
	}
}

class Main {
	public static void main(String... args) {
		var reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
	}
}

Measured memory_bytes: 82412
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def main():
    d, n = map(int, input().split())
    if d == 0:
        ans = n
        if n == 100:
            ans += 1
    else:
        ans = 100 ** d * n
        if d == 1 and n == 100:
            ans += 100
        elif d == 2 and n == 100:
            ans += 10000
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 12144
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
vector<pair<ll, ll> > buf;

int opt(vector<pair<ll, ll> >& vv) {
	for (int i = 0; i < vv.size(); ++i)
		if (vv[i].second <= vv[i].first)
			return 1;
	sort(vv.begin(), vv.end());
	if (vv[0].first == 0)
		return 1;
	buf.clear();
	for (int i = 0; i < vv.size(); ++i) {
		if (!buf.empty() && buf.back().second >= vv[i].first)
			buf.back().second = max(buf.back().second, vv[i].second);
		else
			buf.push_back(vv[i]);
	}
	vv = buf;
	return 0;
}

int n;
ll a[120000];
vector<pair<ll, ll> > vv;

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%lld", a + i);
	ll now = 1;
	int ans = 0;
	for (int it = 0; it <= 16; ++it, now *= 10) {
		for (int k = 9; k >= 1; --k) {
			vv.clear();
			vv.push_back(make_pair(k * now, (k + 1) * now));
			int fl = 0;
			for (int i = 0; i < n; ++i) {
				ll x = a[i] % (10 * now);
				int sz = vv.size();
				for (int j = 0; j < sz; ++j) {
					ll l = vv[j].first - x;
					ll r = vv[j].second - x;
					if (l < 0)
						l += 10 * now;
					if (r <= 0)
						r += 10 * now;
					vv.push_back(make_pair(l, r));
				}
				if (opt(vv)) {
					fl = 1;
					break;
				}
			}
			if (fl) {
				ans += k;
			//	cerr << k << "\n";
				break;
			}
		}
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main() {
  int i,j,k;
  string s;
  while(1){
    cin>>i;
    if(i==0)break;
    string c[i][2];
    for(j=0;j<i;j++) {
      cin>>s,c[j][0]=s;
      cin>>s,c[j][1]=s;
    }
    cin>>k;
    for(j=0;j<k;j++){
      cin>>s;
      for(int l=0;l<i;l++){
	if(s==c[l][0]) {
	  s=c[l][1];
	  break;
	}
      }
      cout<<s;
    }
    cout<<"\n";
  }
}

Measured memory_bytes: 908
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n, k = map(int, input().split())
    h = [int(hi) for hi in input().split()]
    h.sort()
    for _ in range(k):
        if h:
            h.pop()

    print(sum(h))


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 99592
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var R = Sarray()[0];
            var G = Sarray()[0];
            WriteLine(2 * G - R);
        }


        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28016
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define vpli vector<pair<long long,int>>
#define deb(x) cout<<x<<endl;
#define all(x) x.begin(),x.end()
ll MOD = 1e9+7;


void solve()
{
    int x,n,t;
    cin>>x>>n;
    unordered_set<int> st;
    for(int i=0;i<n;i++)
    {
        cin>>t;
        st.insert(t);
    }
    int ans = 0;
    int left=x;
    while(st.find(left) != st.end()) left--;
    int right=x;
    while(st.find(right) != st.end()) right++;
    if(x-left <= right-x )
    {
        cout<<left;
    }    
    else
    {
        cout<<right;
    }
    
}

int main()
{
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int k = sc.nextInt();

        if ((e - a) > k) {
            System.out.println(":(");
        }
        else {
            System.out.println("Yay!");
        }
    }
}


Measured memory_bytes: 23636
import java.util.Scanner;

//implement the selection sort
public class Main {
	//helper functions
	public static void print_arr(int[] arr) {
		int i = 0;
		while(i < arr.length) {
			System.out.print(arr[i]);
			if(i < arr.length - 1) {
				System.out.print(" ");
			}else {
				System.out.print("\n");
			}
			i++;
		}
	}
	
	
	public static int selection_sort(int[] arr) {
		int swap_times = 0;
		for(int i = 0; i< arr.length - 1; i++) {
			//choose the smallest element from a[i:];
			int min = i;
			for(int j = i+1; j < arr.length; j++) {
				if(arr[min] > arr[j]) {
					min = j;
				}
			}
			
			if(min != i) {
				swap_times++;
				//do swap
				int tmp = arr[i];
				arr[i] = arr[min];
				arr[min] = tmp;
			}
		}
		return swap_times;
	}
	
	
	
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n = cin.nextInt();
		int [] arr = new int[n];
		
		for(int i = 0; i < n; i++) {
			arr[i] = cin.nextInt();
		}
		
		int swap_times = selection_sort(arr);
		print_arr(arr);
		System.out.println(swap_times);
		
		
	}

}

Measured memory_bytes: 26148
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//-------------------------------------------------------
long DP[201][100001]; 
int S[100000];
void Calc(){
	int N = rei();
	int X = rei();
	for(int i=0;i<N;i++){
		S[i] = rei();
	}
	sort(S,S+N);
	for(int i=0;i<100001;i++){
		DP[N][i] = i;
	}
	for(int i=N-1;i>=0;i--){
		for(int j=0;j<100001;j++){
			DP[i][j] = DP[i+1][j] * (N-1-i) + DP[i+1][j % S[N-1-i]];
			DP[i][j] %= mod; 
		}
	}
	cout << DP[0][X] << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 157312
object Main extends App {
  val N = io.StdIn.readInt
  val last = N % 10
  val nameList = Array (("pon", Array(0, 1, 6, 8)), ("hon", Array(2, 4, 5, 7, 9)), ("bon", Array(3)))
  val gotList = nameList.filter( _._2.contains(last))
  println(gotList.head._1)
}


Measured memory_bytes: 54604
# include <bits/stdc++.h>
using namespace std;
vector <int> vc;
int n, m, num,mina,col,row ,b,c,d,e,f;
int main()
{
   string s;
   cin>>s;
   m=s.size()-1;
   for (int i=0;i<s.size()/2;i++){
        if (s.size()%2==0){
            if (s[i]!=s[m]){
                num++;
            }
        }
        else {
            if (i!=(s.size()/2)+1){
                if (s[i]!=s[m]){
                    num++;
                }
            }
        }
        m--;
   }
   cout<<num;

}


Measured memory_bytes: 256
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
    
    int n;
    cin>>n;
    
    char s[100];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    
    int d=0;
    
    for(int i=0;i<n;i++){
        if(s[i]=='P'){
            d+=1;
            break;
        }
    }
        for(int i=0;i<n;i++){
            if(s[i]=='W'){
                d+=1;
                break;
            }
        }
            for(int i=0;i<n;i++){
                if(s[i]=='G'){
                    d+=1;
                    break;
                }
            }
                for(int i=0;i<n;i++){
                    if(s[i]=='Y'){
                        d+=1;
                        break;
                    }
                }
        
                    if(d==4){
                        cout<<"Four"<<endl;
                    }else{
                        cout<<"Three"<<endl;
                    }
        
    
    
    return 0;
}








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

using namespace std;

int main(){
    string a,b;
    cin >> a >> b;
    int f=0,s=0;
    string res = "";
    int k = 0;
    for(int i = 0; i < a.length() + b.length(); i++){
        if(i%2==0)res+=a[k];
        else res+=b[k];
        if(i%2==1)k++;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
using System;

namespace MaxProfit
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            //var r = new int[n];
            var min = Int32.MaxValue;
            var max = Int32.MinValue;
            for (var i = 0; i < n; i++)
            {
                var r = int.Parse(Console.ReadLine());
                max = r - min > max ? r - min : max;
                min = r < min ? r : min;
            }
            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 20068
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


yn = 'YNeos'
ynflg = False
cnt = 0
ans = None

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

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas



N = intinput()


# 出力
if N %2 == 1:
    print((N//2 + 1))
else:
    print((N//2))



Measured memory_bytes: 5812
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    string S;
    cin>>S;

    bool flag = false;
    for(int i = 1;i < S.size();i++) {
        if(S[i-1] == S[i])
            flag = true;
    }

    if(flag) {
        cout<<"Bad"<<endl;
    } else {
        cout<<"Good"<<endl;
    }

    return 0;
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

template<typename T>
class DAG{
  private:
    int v;
    std::vector<std::vector<std::pair<int,T>>> to;
    std::vector<int> rank;
    std::vector<T> dp;
  public:
    DAG(int v,const T &x=T(0)):v(v){
        to.resize(v);
        rank.resize(v);
        dp.resize(v,x);
        std::iota(rank.begin(),rank.end(),0);
    }
    void add(int a,int b,const T &c=0){
        to[a].push_back(std::make_pair(b,c));
        if(rank[a]>rank[b]) std::swap(rank[a],rank[b]);
    }
    void set(int i,const T &x){
        dp[i]=x;
    }
    std::vector<T> calc(std::function<T(T,T)> f,std::function<T(ll,T)> h=[](ll a,T b){return b;},std::function<T(T,T)> g = std::plus<T>()){
        std::vector<int> vertex(v);
        std::vector<T> tmp=dp;
        for(int i=0;i<v;++i) vertex[rank[i]]=i;
        for(int i=0;i<v;++i){
            ll sz=to[vertex[i]].size();
            for(const auto &e:to[vertex[i]]){
                tmp[e.first]=f(tmp[e.first],g(h(sz,tmp[i]),e.second));
            }
        }
        return tmp;
    }
};

int main(){
    int N;cin>>N;
    DAG<int> D(3*(N+1));
    REP(i,N){
        int a[3];cin>>a[0]>>a[1]>>a[2];
        REP(j,3) REP(k,3){
            if(j!=k){
                D.add(3*i+j,3*(i+1)+k,a[k]);
            }
        }
    }
    vector<int> res=D.calc([](int a,int b){return max(a,b);});
    int ans=0;
    REP(i,3) ans=max(ans,res[3*N+i]);
    cout<<ans<<endl;
}


Measured memory_bytes: 21376
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int t = sc.nextInt();
        if(X-t > 0)
            System.out.println(X-t);
        else
            System.out.println(0);
    }
}

Measured memory_bytes: 21716
# Keyence 2020 A
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
h=ni()
w=ni()
n=ni()
ans=0
for i in range(10000):
    if n>0:
        t=max(h,w)
        n-=t
        ans+=1
    elif n<=0:
        break
print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using lint=int64_t;
using namespace std;

const lint INF=1e18;

class SegmentTree
{
	public:
	int N;
	vector<lint> tree;

	SegmentTree(int size,lint init)
	{
		N=1;
		while(N<size)N*=2;

		tree.resize(2*N-1);
		for(auto&& i:tree)
			i=init;
	}

	void update(int i,lint value)
	{
		tree[i+N-1]=value;

		i=i+N-1;
		while(i>0)
		{
			i=(i-1)/2;
			tree[i]=max(tree[2*i+1],tree[2*i+2]);
		}
	}

	lint getMax(int tl,int tr,int l=0,int r=-1,int i=0)
	{
		if(r<0)
			r=N;

		if(tr<=l || r<=tl)
			return 0;

		if(tl<=l && r<=tr)
			return tree[i];

		lint retl=getMax(tl,tr,l,(l+r)/2,2*i+1);
		lint retr=getMax(tl,tr,(l+r)/2,r,2*i+2);

		return max(retl,retr);
	}
};

int main()
{
	int N;
	int h[200010]={};
	lint a[200010]={};

	cin >> N;

	map<int,int> m;
	for(int i=0;i<N;i++)
	{
		cin >> h[i];
		m[h[i]]=i;
	}
	for(int i=0;i<N;i++)
		cin >> a[i];

	sort(h,h+N);

	SegmentTree seg(N,0);
	for(int i=0;i<N;i++)
	{
		int index=m[h[i]];
		seg.update(index,seg.getMax(0,index)+a[index]);
	}

	cout << seg.getMax(0,N) << endl;
	return 0;
}


Measured memory_bytes: 16128
// g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;

#define For(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Rep(i,n) For(i,0,n)
#define Each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3

#define MAX_M 16
#define MAX_N 20000

int N, M;
int C[MAX_M], x[MAX_N];
int dp[MAX_N+1][256];

/*
bool sorter(const A& x, const A& y){
	return x.a < y.a;
}

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

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

void solve() {
	Rep(i,MAX_N+1)Rep(j,256) dp[i][j] = INF;
	dp[0][128] = 0;
	Rep(i,N)Rep(j,256)Rep(k,M){
		int xx = j + C[k];
		if(xx < 0) xx = 0;
		if(xx > 255) xx = 255;
		int cost = (x[i]-xx)*(x[i]-xx);
		dp[i+1][xx] = min(dp[i+1][xx], dp[i][j]+cost);
	}
	int res = INF;
	Rep(i,256) res = min(res, dp[N][i]);
	printf("%d\n", res);
}

int main(){
	while(1){
		scanf("%d %d", &N, &M);
		if(N == 0) break;
		Rep(i,M){
			scanf("%d", &C[i]);
		}
		Rep(i,N) scanf("%d", &x[i]);
		solve();
	}
	return 0;
}

Measured memory_bytes: 21264
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
int a[N], m1[N], m2[N];

signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n;	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];	
		if(i&1)
			m1[a[i]]++;
		else
			m2[a[i]]++;
	}
	int mx1 = -1, mx2 = -1;
	int smx1 = -1, smx2 = -1;
	int v1 = 0, v2 = 0, w1 = 0, w2 = 0;
	for(int i = 1; i <= 1e5; i++){
		if(m1[i] >= mx1){
			smx1 = mx1, mx1 = m1[i];
			v2 = v1, v1 = i;
		}
		else if(m1[i] > smx1)
			smx1 = m1[i], v2 = i;
	}
	for(int i = 1; i <= 1e5; i++){
		if(m2[i] >= mx2){
			smx2 = mx2, mx2 = m2[i];
			w2 = w1, w1 = i;
		}
		else if(m2[i] > smx2)
			smx2 = m2[i], w2 = i;
	}
	if(v1 != w1){
		cout << n/2 - mx1 + n/2 - mx2;
	}
	else{
		int a1 = n/2 - mx1;
		if(w2 == 0)	a1 += n/2;
		else	a1 += n/2 - smx2;
		int a2 = n/2 - mx2;
		if(v2 == 0)	a2 += n/2;
		else	a2 += n/2 - smx1;
		cout << min(a1, a2);
	}
	return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int ans = 0, N;
int V[100], C[100];

int main() {
    cin >> N;
    rep(i, N) cin >> V[i];
    rep(i, N) cin >> C[i];

    rep(i, N) {
        if (V[i] > C[i]) ans += V[i] - C[i];
    }
    cout << ans << endl;
    return 0;
}


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

#define mp       make_pair
#define mt       make_tuple
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

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

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
const int MAX_NM = 100100;
int N,M;
vector<int> boxes;
int deg[MAX_NM];
bool red[MAX_NM];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  for (int i = 0; i < N; i++){
    deg[i] = 1;
  }
  red[0] = true;
  for (int i = 0; i < M; i++){
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    if (red[x]){
      deg[x]--;
      if (deg[x] == 0){
	red[x] = false;
      }
      red[y] = true;
      deg[y]++;
    }else{
      deg[x]--;
      deg[y]++;
    }
  }
  int result = 0;
  for (int i = 0; i < N; i++){
    if (red[i]){
      result++;
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    string s;cin>>s;
    int n=0;
    for(char x:s)if(x=='x')n++;
    if(n<=7)cout<<"YES";
    else cout<<"NO";
}


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

int main() {
    unsigned long N;
    cin >> N;
    vector<long> a(N);
    for(auto& i : a)cin >> i;

    long t = accumulate(a.begin(), a.end(), 0L);
    auto k = N * (N + 1) / 2;
    if(t % k != 0 || !(t /= k))return 0 & puts("NO");
    vector<long> b(N);
    b[N - 1] = a[N - 1] - a[0] + t;
    for(unsigned long i = 1; i < N; ++i)b[i - 1] = a[i - 1] - a[i] + t;

    for(const auto i : b)if(i < 0 || i % N != 0)return 0 & puts("NO");
    puts("YES");
    return 0;
}

Measured memory_bytes: 1792
def solve(A):
    n = A[-1]
    is_nodiv = [True for _ in range(n+1)]

    pre = 0
    for a in A:
        if pre == a or not is_nodiv[a]:
            is_nodiv[a] = False
            continue

        for j in range(2*a, n+1, a):
            is_nodiv[j] = False
        
        pre = a
        
    return sum([is_nodiv[a] for a in A])



def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    ans = solve(A)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 32216
import numpy as np
n = int(input())
a = [int(i) for i in input().split()]
a = np.array(a, dtype='int64')
k = np.sum(a < 0)
a = np.absolute(a)
a.dtype ='uint64'
a.sort()

if k % 2 == 0:
    print(int(np.sum(a)))
else :
    print(int(np.sum(a)- a[0]*2))

Measured memory_bytes: 23268
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        BigInteger a = sc.nextBigInteger();
        BigInteger b = sc.nextBigInteger();
        BigInteger x = sc.nextBigInteger();

        BigInteger n = b.divide(x).subtract(a.subtract(BigInteger.ONE).divide(x));

        if(a.compareTo(BigInteger.ZERO) == 0 && x.compareTo(BigInteger.ONE) != 0) n = n.add(BigInteger.ONE);
        System.out.println(n);
    }
}

Measured memory_bytes: 9936
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
a = [readline().rstrip().decode() for _ in range(n)]
b = [readline().rstrip().decode() for _ in range(m)]
print('Yes' if any([aa[x:x + m] for aa in a[y:y + m]] == b for y in range(n - m + 1) for x in range(n - m + 1)) else 'No')


Measured memory_bytes: 3064
#include <cstdio>

int main(){
	int n,l,r,ans=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&l,&r);
		ans+=r-l+1;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int M=924844033,N=300005;
int fac[N],inv[N],n,k,ans,f1[N],f2[N];
int ksm(int x,int y){
	if (!y)return 1;
	int z=ksm(x,y/2);
	z*=z;z%=M;
	if (y&1)z*=x;
	return z%M;
}
int C(int x,int y){
	if (x<y)return 0;
	return fac[x]*inv[y]%M*inv[x-y]%M;
}
void init(int y[],int len){
	for (int i=1,j=len/2;i<len-1;i++){
		if (i<j)swap(y[i],y[j]);
		int k=len/2;
		while (j>=k){
			j-=k;
			k/=2;
		}
		j+=k;
	}
}
void ntt(int y[],int len,int opt){
	init(y,len);
	for (int h=2;h<=len;h<<=1){
		int wn=ksm(5,(M-1)/h);
		if (opt==-1)wn=ksm(wn,M-2);
		for (int j=0;j<len;j+=h){
			int w=1;
			for (int k=j;k<j+h/2;k++){
				int u=y[k],v=w*y[k+h/2]%M;
				y[k]=(u+v)%M;
				y[k+h/2]=(u-v+M)%M;
				w=w*wn%M;
			}
		}
	}
	if (opt==1)return;
	int temp=ksm(len,M-2);
	for (int i=0;i<len;i++)(y[i]*=temp)%=M;
}
signed main(){
	scanf("%lld%lld",&n,&k);
	fac[0]=inv[0]=1;
	for (int i=1;i<N;i++)fac[i]=fac[i-1]*i%M,inv[i]=ksm(fac[i],M-2);
	int cnt=n/k-1,len=1,k1=k-n%k,k2=n%k;
	k1*=2;k2*=2;
	while (len<n+5)len*=2;
	for (int i=0;i<=cnt;i++)f1[i]=C(cnt-i+1,i);
	for (int i=0;i<=cnt+1;i++)f2[i]=C(cnt-i+2,i);
	ntt(f1,len,1);ntt(f2,len,1);
	for (int i=0;i<len;i++)f1[i]=ksm(f1[i],k1)*ksm(f2[i],k2)%M;
	ntt(f1,len,-1);
	for (int i=0;i<=n;i++)(ans+=f1[i]*fac[n-i]%M*ksm(M-1,i))%=M;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  int count = 1;
  for(int i;i<100;i++){
    if (N<K) break;
    N /= K;
    count++;
  }
  cout << count << endl;


}

Measured memory_bytes: 256