akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,k,m=-1;
vector<vector<int>> G;
vector<int> p,depth,ans;
vector<P> seg;

void dfs1(int s,int par){
    if (par==-1) depth[s]=0;
    else depth[s]=depth[par]+1;
    if (p[s]!=-1){
        if (m==-1) m=(p[s]-depth[s])%2;
        else if (m!=(p[s]-depth[s])%2) {
            cout << "No" << endl;
            exit(0);
        }
    }
    rep(i,G[s].size()){
        int t=G[s][i];
        if (t==par) continue;
        dfs1(t,s);
    }
}

void dfs2(int s,int par){
    int maxl=-mod,minr=mod;
    rep(i,G[s].size()){
        int t=G[s][i];
        if (t==par) continue;
        dfs2(t,s);
        maxl=max(maxl,seg[t].first-1);
        minr=min(minr,seg[t].second+1);
    }
    //cout << s << " " << maxl << " " << minr << endl;
    if (p[s]!=-1) {
        if (maxl>p[s] || minr<p[s]) {
            cout << "No" << endl;
            exit(0);
        }
        else seg[s]=P(p[s],p[s]);
    }
    else{
        if (maxl<=minr) seg[s]=P(maxl,minr);
        else {
            cout << "No" << endl;
            exit(0);
        }
    }
    //cout << s << " " << seg[s].first << " " << seg[s].second << endl;
}

void dfs3(int s,int par){
    if (par==-1) ans[s]=seg[s].first;
    else{
        if (seg[s].first<=ans[par]-1 && ans[par]-1<=seg[s].second) ans[s]=ans[par]-1;
        else ans[s]=ans[par]+1;
    }
    rep(i,G[s].size()){
        int t=G[s][i];
        if (par==t) continue;
        dfs3(t,s);
    }
}

void solve(){
    cin >> n;
    G.resize(n,{});
    p.resize(n,-1);
    depth.resize(n,0);
    ans.resize(n,0);
    seg.resize(n,P(-mod,mod));
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    cin >> k;
    rep(i,k){
        int v;
        cin >> v;
        cin >> p[v-1];
    }
    dfs1(0,-1);
    //rep(i,n) cout << i << " depth:" << depth[i] << endl;
    dfs2(0,-1);
    //rep(i,n) cout << i << " seg:" << seg[i].first << " " << seg[i].second << endl;
    dfs3(0,-1);
    cout << "Yes" << endl;
    rep(i,n) cout << ans[i] << endl;
}

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

Measured memory_bytes: 16128
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#include<tuple>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
#define REP(i,n) for (int i = 1; i <= (int)n; i++)//i=1からi=nまで
#define RREP(i,n)for(int i=n;i>=1;i--) 
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
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; }

int main(){
	long double a, b; cin >> a >> b;
	long double h, m; cin >> h >> m;	
	long double x =abs(m* 6 - m / 2-h*30);
	x = min(x, 360 - x);
	long double ans = a * a + b * b - 2 * a * b * cos(x / 180 * pi);
	cout << fixed<<setprecision(12)<<sqrt(ans) << endl;

}

	








Measured memory_bytes: 4152
use text_io::*;

fn main() {
    let n: usize = read!();
    let k: usize = read!();
    let mut v = Vec::new();
    for _ in 0..n {
        let a: usize = read!();
        v.push(a);
    }
    for i in 0..n-k {
        if v[i] < v[i+k] {
            println!("Yes");
        }
        else {
            println!("No");
        }
    }
}

Measured memory_bytes: 3768
#include <iostream>
#include <cmath>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair <int, int> pii;
long long F(long long A, long long B) {
	//get number of digits in A
	long long c = 0, c2 = 0;
	while (A != 0) {
		c++;
		A /= 10;
	}
	while (B != 0) {
		c2++;
		B/= 10;
	}
	return max(c, c2);
}
int main (void) {
	long long n; cin >> n;
	//find all divisors
	long long m = (long long)1e10;
	for (int div = 1; div <= sqrt(n); div++) {
		if (n % div == 0) {
			// div and n/div are  divisors
			int a = F(div, n/div);
			if (m > a)
				m = a;
		}
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
## coding: UTF-8
#memo:重なっている位置に爆弾があるかないかで、1こ増減することが考えられる
#import numpy as np

H, W, M = map(int,input().split())

tate = [0] * H
yoko = [0] * W


bomb = set()
for i in range(M):
    hi, wi = map(int,input().split())
    tate[hi-1] += 1
    yoko[wi-1] += 1
    bomb.add((hi,wi))
    

#print(tate)
#print(yoko)
#print(bomb)
'''
tate_max = max(tate)
yoko_max = max(yoko)
index_tate = [i for i, v in enumerate(tate) if v == tate_max]
index_yoko = [i for i, v in enumerate(yoko) if v == yoko_max]
'''
tate_max = 0
index_tate = []
for i, v in enumerate(tate):
    if(tate_max < v):
        tate_max = v
        index_tate = [i]
    elif(tate_max == v):
        index_tate.append(i)
#print(tate_max, index_tate)

yoko_max = 0
index_yoko = []
for i, v in enumerate(yoko):
    if(yoko_max < v):
        yoko_max = v
        index_yoko = [i]
    elif(yoko_max == v):
        index_yoko.append(i)
#print(yoko_max, index_yoko)


#print(index_tate, index_yoko)

dammy = True
#1子でも「そこにない」ものがあれば、そのまま加算、そうでなければ、1こ引く
there_is = True
flg = False
for i in index_tate:
    for j in index_yoko:
        #print(i+1, j+1)
        if((i+1, j+1) in bomb):
            dammy = True
        else:
            there_is = False
            flg = True
            break
    if flg:
        break

if(there_is):
    print(tate_max + yoko_max - 1)
else:
    print(tate_max + yoko_max)


        




'''
#tate_max = [i for i, v in enumerate(tate) if v == max(tate)]
np_list_tate = np.array(tate)
np_list_yoko = np.array(yoko)
tate_max = np_list_tate.argmax()
yoko_max = np_list_yoko.argmax()
print(tate_max, yoko_max)
'''

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

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

	if (a + b > c + d) {
		cout << "Left" << endl;
	}else if (a + b < c + d){
		cout << "Right" << endl;
	}else{
		cout << "Balanced" << endl;
	}
}


Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	K := getInt()
	s := getString()

	if len(s) <= K {
		out(s)
	} else {
		out(s[:K] + "...")
	}
}


Measured memory_bytes: 1756
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>

using namespace std;

const int MAX = 101;
int N,T,L,B;
double pro[MAX][MAX][2];
char field[MAX];

void init(){
  //  memset(pro,0,sizeof(pro));

  for(int i = 0; i < MAX; i++)
    for(int j = 0; j < MAX; j++)
      for(int k = 0; k < 2; k++)
	pro[i][j][k] = 0;

  fill(field,field+MAX,'N');
}

double getans(){

  double ans = 0;

  for(int t = 0; t <= T; t++)
    ans += pro[t][N][0];

  return ans;
}

void solve(){
  
  pro[0][0][0] = 1.0;



  for(int t = 0; t <= T; t++)
    for(int i = 0; i < N; i++)
      for(int j = 1; j <= 6; j++){
	int nex = i+j;	
	if(i+j > N) nex = N-(i+j-N);
	
	if(field[nex] == 'N'){
	  pro[t+1][nex][0] += pro[t][i][0]*(1.0/6.0);
	  if(t > 0) pro[t+1][nex][0] += pro[t-1][i][1]*(1.0/6.0);
	}
	
	if(field[nex] == 'L'){	  
	  pro[t+1][nex][1] += pro[t][i][0]*(1.0/6.0);
	  if(t > 0) pro[t+1][nex][1] += pro[t-1][i][1]*(1.0/6.0);
	}
	
	if(field[nex] == 'B'){
	  pro[t+1][0][0] += pro[t][i][0]*(1.0/6.0);
	  if(t > 0) pro[t+1][0][0] += pro[t-1][i][1]*(1.0/6.0);
	}
	
      }
 
}

int main(){
  
  while(cin >> N >> T >> L >> B && N+T+L+B){
    init();

    for(int i = 0; i < L; i++){
      int pos;
      cin >> pos;
      field[pos] = 'L';
    }

    for(int i = 0; i < B; i++){
      int pos;
      cin >> pos;
      field[pos] = 'B';
    }

    solve();

    double ans = getans();

    printf("%.6f\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1348
H, W, K = map(int, input().split())
A = []
ans = 0
black = 0
for i in range(H):
  A.append(list(input()))

for i in range(1 << H):
  for j in range(1 << W):
    black = 0
    for m in range(H):
      for n in range(W):
        if A[m][n] == "#" and (i>>m)&1 and (j>>n)&1:
          black += 1
    if black == K:
      ans += 1
      
print(ans)

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

typedef long long ll;

ll a,b,n;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>a>>b>>n;
    ll m=n/b*b-1;
    cout<<max(a*m/b-a*(m/b),a*n/b-a*(n/b))<<endl;

    return 0;
}

Measured memory_bytes: 3640
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc016 B
"""

from collections import Counter

n = int(input())
acnt = Counter(map(int, input().split()))

if len(acnt) > 2:
    print('No')
    exit()

if len(acnt) == 1:
    [(a, nn)] = acnt.most_common(1)
    if a in range(1, n//2+1) or a == n-1:
        print('Yes')
    else:
        print('No')
    exit()

if len(acnt) == 2:
    [(a1, n1), (a2, n2)] = sorted(acnt.most_common(2), key=lambda x: x[0])
    if a2-a1 != 1:
        print('No')
    else:
        if 1 <= a2 - n1 <= (n-n1)//2:
            print('Yes')
        else:
            print('No')



Measured memory_bytes: 22636
n,x=gets.split.map(&:to_i)
as=gets.split.map(&:to_i).sort
sum=0
(n-1).times do |i|
  if x-as[i]>=0
    x-=as[i]
    sum+=1
  else
    break
  end
end
puts x-as[n-1]==0 ? sum+1:sum


Measured memory_bytes: 1788
from itertools import groupby
import sys

input = lambda: sys.stdin.readline().rstrip()


def main():

    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupby(S)]
    ans = 0

    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            ans = a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0] + a[-1]) // 2 * (K - 1)
            ans += sum(n // 2 for n in a[1:-1]) * K

    else:
        ans += sum(n // 2 for n in a) * K

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 62272
def fprint(x):
    if x < 10:
        print("   ",end="")
    elif x < 100:
        print("  ",end="")
    elif x < 1000:
        print(" ",end="")
    print(x,end="")

while True:
    N = int(input())
    if N == 0:
        break

    table = [[0 for i in range(N)] for j in range(N)]

    cnt =  1
    row = N // 2 + 1
    col = N // 2
    table[row][col] = cnt
    while cnt < N*N:
        row = (row + 1) % N
        col = (col + 1) % N
        while table[row][col] != 0:
            row = (row + 1) % N
            col = (col - 1 + N) % N
        cnt += 1
        table[row][col] = cnt

    for i in range(N):
        for j in range(N):
            fprint(table[i][j])
        print("")



Measured memory_bytes: 5680
fn main() {
    let s = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    };

    let (t, x) = {
        let mut ws = s.split_whitespace();
        let t: i32 = ws.next().unwrap().parse().unwrap();
        let x: i32 = ws.next().unwrap().parse().unwrap();
        (t, x)
    };

    let t_f: f64 = t as f64;
    let x_f: f64 = x as f64;


    println!("{}", t_f / x_f);
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;
#define FIN freopen("in.txt", "r", stdin);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int h, w;
    cin >> h >> w;
    for(int i = 0; i < h; i++)
    {
string op;
cin >> op;
cout << op << endl;
cout << op << endl;
    }
}

Measured memory_bytes: 256
// #Sazaの1日1AC
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
const long long INF=9e15;
const double PI=3.14159265358979323846;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vP=vector<pair<long long, long long>>;
//ショートカット
#define rep(i,n) for(long long i = 0; i < n; i++)
#define rep2(i,k,n) for(long long i = k; i < n; i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mkp make_pair
//入力
#define vin(v,N) for(long long id=0;id<N;id++) cin>>v.at(id)
#define lin(n) long long n;cin>>n
#define chin(x) char x;cin>>x;
#define sin(s) string s;cin>>s;
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if(n==0) return 1;
  else if(n%2==0){
    long long t=repeat_squaring(x,n/2);
    return t*t%mod;
  }
  else
    return x*repeat_squaring(x,n-1);
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//構造体

/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(2);
  
  char a; cin >> a;
  if(a - 'a' < 0) cout << "A" << endl;
  else cout << "a" << endl;
  //out << a - 'A' << endl;
}

Measured memory_bytes: 3592
#![allow(unused_imports)]
use proconio::input;
use proconio::marker::*;
use std::collections::HashSet;

fn main() {
  input! {
    n: usize
  }
  
  let mut memo: Vec<usize> = vec![0;n];
  let mut base = 11;
  memo[0] = 11;
  for i in 1..n {
    loop {
      base += 10;
      let mut v = 3;
      let mut succeed = true;
      while v * v <= base {
        if base % v == 0 {
          succeed = false;
          break;
        }
        v += 1;
      }
    
      if succeed {
        memo[i] = base;
        break
      }
    }
  }
  
  println!("{}", memo
    .into_iter()
    .map(|v| v.to_string())
    .collect::<Vec<String>>()
    .join(" ")
  );
}

Measured memory_bytes: 2096
import java.util.Scanner;

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

	int N = scan.nextInt();

	int num = 0;
	int tmp = N;
	while(tmp > 0){
	    num += tmp % 10;
	    tmp /= 10;
	}

	if(N % num == 0){
	    System.out.println("Yes");
	}else{
	    System.out.println("No");
	}
    }
}


Measured memory_bytes: 22868
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int[] A = new int[N];
            int[] B = new int[N];
            int[] C = new int[N - 1];
            for (int i = 0; i < N; i++) {
                A[i] = sc.nextInt() - 1;
            }
            for (int i = 0; i < N; i++) {
                B[i] = sc.nextInt();
            }
            for (int i = 0; i < N - 1; i++) {
                C[i] = sc.nextInt();
            }

            int sum = 0;
            for (int i = 0; i < N; i++) {
                sum += B[A[i]] + (i - 1 >= 0 && A[i] == A[i - 1] + 1 ? C[A[i - 1]] : 0);
            }

            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 21332
#include <iostream>
#include <vector>

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

void solve()
{
	int n, m;
	while(cin >> n, n)
	{
		vector<P> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i].first >> Vec[i].second;
		}
		vector<P> Dif(n - 1);
		for(int i = 1; i < n; ++i)
		{
			Dif[i - 1].first = Vec[i].first - Vec[0].first;
			Dif[i - 1].second = Vec[i].second - Vec[0].second;
		}

		cin >> m;
		vector<P> Vec1(m);
		for(int i = 0; i < m; ++i)
		{
			cin >> Vec1[i].first >> Vec1[i].second;
		}
		for(int i = 0; i < m; ++i)
		{
			int count = 0;
			for(int j = 0; j < n - 1; ++j)
			{
				P point;
				point.first = Vec1[i].first + Dif[j].first;
				point.second = Vec1[i].second + Dif[j].second;
				bool flag = false;
				for(int k = 0; k < m; ++k)
				{
					if(point.first == Vec1[k].first  && point.second == Vec1[k].second)
					{
						++count;
						flag = true;
					}
				}
				if(!flag)
				{
					break;
				}
			}
			if(count == n - 1)
			{
				cout << Vec1[i].first - Vec[0].first << " " << Vec1[i].second - Vec[0].second << endl;
				break;
			}
		}
	}
}

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

Measured memory_bytes: 0
def gcd(a,b):
    if b==0:
        return a
    return gcd(b, a%b)

a,b,c = map(int, input().split())

count = int(b/gcd(a,b))
flag = 0

for i in range(count):
    if (a*i) % b == c:
        flag = 1
        break

if flag == 0:
    print("NO")

if flag == 1:
    print("YES")


Measured memory_bytes: 3316
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	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
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 0
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	t := getNextInt(scanner)
	for tt := 0; tt < t; tt++ {
		n := getNextInt64(scanner)
		a := getNextInt64(scanner)
		b := getNextInt64(scanner)
		c := getNextInt64(scanner)
		d := getNextInt64(scanner)
		cc := &coins{}
		heap.Init(cc)
		heap.Push(cc, newCoin(n, 0))
		costs := map[int64]int64{2: a, 3: b, 5: c}
		var ans int64
		ans = math.MaxInt64
		memo := map[int64]int64{}
		for cc.Len() > 0 {
			p := heap.Pop(cc).(coin)
			if memo[p.n] > 0 {
				continue
			}
			memo[p.n] = p.cost
			if p.cost > ans {
				continue
			}
			if p.n == 0 {
				ans = p.cost
				continue
			}
			if p.n > n+5 {
				continue
			}
			for _, div := range [3]int64{2, 3, 5} {
				if p.n%div == 0 {
					heap.Push(cc, newCoin(p.n/div, p.cost+costs[div]))
					continue
				}
				if p.n < div {
					heap.Push(cc, newCoin(0, p.cost+d*p.n))
					continue
				}
				heap.Push(cc, newCoin(p.n/div, p.cost+costs[div]+d*(p.n%div)))
				heap.Push(cc, newCoin(p.n/div+1, p.cost+costs[div]+d*(div-p.n%div)))
				if (math.MaxInt64-p.cost)/d > p.n {
					heap.Push(cc, newCoin(0, p.cost+d*p.n))
				}

			}
		}
		fmt.Fprintln(writer, ans)
	}
}

func newCoin(n, cost int64) coin {
	return coin{
		n:    n,
		cost: cost,
	}
}

type coin struct {
	n, cost int64
}

type coins []coin

func (h coins) Len() int { return len(h) }
func (h coins) Less(i, j int) bool {
	return h[i].cost < h[j].cost
}
func (h coins) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
func (h *coins) Push(x interface{}) {
	*h = append(*h, x.(coin))
}
func (h *coins) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 6096
n,m = map(int,input().split())

s = []
for i in range(m):
    a,b = map(int,input().split())
    s.append((b,a))
s.sort()

ans = 1
start = s[0][1]
end = s[0][0]
for i in range(1,m):
    temp_start = s[i][1]
    temp_end = s[i][0]
    if temp_start >= end:
        ans += 1
        end = temp_end
    
print(ans)

Measured memory_bytes: 17012
n, k = map(int, input().split())
a = [0] * n
d = []
for i in range(k):
    d.append(int(input()))
    at = list(map(int, input().split()))
    for a_ in at:
        a_-=1
        a[a_]+=1
ans = 0
for a_ in a:
    if a_==0:ans+=1
print(ans)

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

#define X first
#define Y second


#define rep(X,Y) for(int (X)=0;(X) < (Y); ++(X))
#define rrep(X,Y) for(int (X)=(Y-1); X >= 0; ++(X))

#define all(X) (X).begin(),(X).end()


using namespace std;



int main(){
  char s[512];
  while(scanf("%s",s),s[0]!='#'){
    int n=strlen(s),re=0;
    rep(i,n){
      int neg,var[128]={};
      //cout<<s[i]<<endl;
      rep(j,3){
	++i;
	neg=s[i]=='~';
	if(neg)++i;
	var[s[i]]|=1<<neg;
	++i;
      }
      int f=1;
      rep(j,128) if(var[j]==3){f=0;break;}
      if(f){
	re=1;
	break;
      }
      ++i;
    }
    cout<<(re?"yes":"no")<<endl;
  }
  return 0;
}

Measured memory_bytes: 1144
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  int n;
  string s;
  cin>>n>>s;
  int ans = 0;
  FOR(i,1,n) {
    string x = s.substr(0,i);
    string y = s.substr(i, n - i);
    int cnt = 0;
    for(int j = 0; j <= 26; j++)
    {
      char al = 'a' + j;
      bool fx = false, fy = false;
      rep(k, i) {
        if(x[k] == al) fx = true;
      }
      rep(k, n - i) {
        if(y[k] == al) fy = true;
      }
      if(fx && fy) cnt++;
    }
    ans = max(ans, cnt);
  }
  cout << ans <<endl;

  return 0;
}


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

signed main() {
    int A, B;
    cin >> A >> B;
    vector<bool> check(4, true);
    check[A] = false;
    check[B] = false;
    for (int i = 1; i <= 3; i++) {
        if (check[i]) {
            cout << i << endl;
            return 0;
        }
    }
}





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

typedef long long ll;

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

int main() {
    ll A, B;
    cin >> A >> B;

    ll n = gcd(A, B);

    int cnt = 0;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i != 0) continue;
        while(n % i == 0) n /= i;
        cnt++;
    }
    if (n != 1) {
        cnt++;
    }
    cout << cnt + 1 << endl;

    return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';        
#define debug(x) cerr << __LINE__ << ' ' << #x << " = " << x << '\n';
#define dln cerr << '\n';
#define dsp cerr << ' ';
#define pln cout << '\n';
#define psp cout << ' ';

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9 + 7;

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

int main(){
  fastio

  ll n, i, j, k;

  cin >> n;

  vl a(n);
  ll p = 1;
  ld sum = 0;
  forn(0, n, i){
    cin >> a[i];
    ld f = 1.0 / a[i];
    sum += f;
  }

  sum = 1 / sum;

  decimal_digits;

  cout << sum << '\n';


  ktj();
}


Measured memory_bytes: 256
q = int(input())
dct = {}
for _ in range(q):
    cmmd = input().split( )
    if cmmd[0] == "0":
        dct[cmmd[1]] = int(cmmd[2])
    elif cmmd[0] == "1":
        try:
            print(dct[cmmd[1]])
        except:
            print(0)
    else:
        try:
            del(dct[cmmd[1]])
        except:
            pass


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

#define SIZE 10000

struct WORD {
	char value[15];
	struct WORD *next;
};

struct WORD* HashTable[SIZE];	//default: all NULL

int HashFunc(char s[]) {
	int hash = 0;
	for (int i = 0; s[i] != '\0'; i++) {
		hash += s[i] * (i + 1);
	}
	return hash * 13 % SIZE;
}

void AddWord(char s[], int hashNum) {
	struct WORD* newWord = (struct WORD*)malloc(sizeof(struct WORD));
	strcpy(newWord->value, s);
	newWord->next = NULL;
	if (HashTable[hashNum] == NULL) HashTable[hashNum] = newWord;
	else {
		newWord->next = HashTable[hashNum];
		HashTable[hashNum] = newWord;
	}
}

void Insert(char s[]) {
	int hash = HashFunc(s);
	AddWord(s, hash);
}

void Find(char s[]) {
	int hash = HashFunc(s);
	struct WORD* pos;
	for (pos = HashTable[hash]; pos != NULL; pos = pos->next) {
		if (!strcmp(s, pos->value)) {
			printf("yes\n");
			return;
		}
	}
	printf("no\n");
	return;
}

int main() {
	int n;
	char command[10], value[15];
	for (int i = 0; i < SIZE; i++) {
		HashTable[i] = NULL;
	}
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s %s", command, value);
		if (!strcmp(command, "insert")) Insert(value);
		else if (!strcmp(command, "find")) Find(value);
	}

	return 0;
}


Measured memory_bytes: 20564
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
using namespace std;
#define ll long long

int main() {
	int N; cin >> N;
	vector<ll> s(N);
	for(int i=0; i<N; ++i) cin >> s[i];
	ll ans=0;
	for(int i=1; i<N/2; ++i){
	    ll now=0;
	    for(int a=1; i*a<N-1-i && ((N-1)%i>0 || i*a<N/2); ++a){
	        now += s[i*a]+s[N-1-i*a];
	        ans=max(now, ans);
	    }
	}
	cout << ans << endl;
	return 0;
}


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

A_even =list()

for i in range(len(A)):
    if A[i] % 2 == 0:
        A_even.append(A[i])

miss = True


for i in range(len(A_even)):
    if A_even[i]%3 == 0 or A_even[i]%5 == 0:
        pass
    else:
        miss = False
        break
if miss:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
  
int main() {
    int N;
    cin >> N;
    
    int64_t ans0 = 2;
    int64_t ans1 = 1;
    int64_t ans;
    
    if (N == 1){
        cout << 1 << endl;
    }
    else {
        for (int i=1;i<N;i++) {
            ans = ans0 + ans1;
            ans0 = ans1;
            ans1 = ans;
            
        }
        cout << ans << endl;
    }
    
   }

 

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ft first
#define sc second
#define sz size()
#define ll long long int
int main()
{
    int n;
    cin>>n;
    if(n%1000==0)
        cout<<0<<endl;
    else
        cout<<1000-(n%1000)<<endl;

}



Measured memory_bytes: 3632
#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 <cmath>
#include <math.h> // sqrt()
#include <iomanip>
#define rep(i , n) for (int i = 1; i <= (int)(n); i++)
#define repz(i , n) for (int i = 0; i < (int) n; i++)
#define repi(i , r, n) for (int i = r; i <= (int)(n); i++)
#define repd(i , r, n) for (int i = r; i >= (int)(n); i--)


using namespace std;
bool check(int64_t x){
    bool ok = false;
    int a = 0; int b = 0; int c = 0;
    for (char l : to_string(x)){
        if (l == '3') a++;
        else if( l == '5') b ++;
        else c++;
    }
    if ( a && b && c) ok = true;
    return ok;
}

int calc(int64_t x , int64_t n){
    int num[3] = {7 , 5 , 3};
    if ( x > n) return 0;
    int s = 0;
    if (check(x)) s = 1;
    else s = 0;
    for (int i : num) s+= calc( 10 * x + i , n);
    return s;
    
}

int main(){
   int64_t n;
    cin >> n;
    cout <<calc( 0 , n) << endl;
}


Measured memory_bytes: 3760
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> x(n),tmp(n);
    for(int i = 0; i < n; i++){
        cin  >> x[i];
        tmp[i] = x[i];
    }
    sort(tmp.begin(), tmp.end());
    int ave = (tmp[n/2]+tmp[n/2-1])/2;
    for(int i = 0; i < n; i++){
        if(ave >= x[i]){
            cout << tmp[n/2] << endl;
        }else{
            cout << tmp[n/2-1] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#define INF 10000000000
using namespace std;

typedef long long ll;

int main() {
    ll H, W, min_s = INF;
    cin >> H >> W;
    for (ll ah = 1; ah < H; ah++) {
        ll sa = ah * W;
        ll ch = (H - ah) / 2;
        ll sc = ch * W;
        ll sb = H * W - sa - sc;
        min_s = min(min_s, max(max(sa, sb), max(sb, sc)) - min(min(sa, sb), min(sb, sc)));    

        ch = H - ah;
        ll cw = W / 2;
        sc = ch * cw;
        sb = H * W - sa - sc;
        min_s = min(min_s, max(max(sa, sb), max(sb, sc)) - min(min(sa, sb), min(sb, sc))); 
    }
    for (ll aw = 1; aw < W; aw++) {
        ll sa = aw * H;
        ll cw = (W - aw) / 2;
        ll sc = cw * H;
        ll sb = H * W - sa - sc;
        min_s = min(min_s, max(max(sa, sb), max(sb, sc)) - min(min(sa, sb), min(sb, sc))); 

        cw = W - aw;
        ll ch = H / 2;
        sc = ch * cw;
        sb = H * W - sa - sc;
        min_s = min(min_s, max(max(sa, sb), max(sb, sc)) - min(min(sa, sb), min(sb, sc))); 
    }
    cout << min_s << endl;
    return 0;
}

Measured memory_bytes: 256
/*
    Mbak Rose Dong
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k,x,y,ans,temp,m,sum,rose;
    char cek;
    cin >> cek;
    if(cek == 'A')
        cout << "T";
    else if(cek == 'T')
        cout << "A";
    else if(cek == 'G')
        cout << "C";
    else if(cek == 'C')
        cout << "G";
    return 0;
}


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

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

using P = pair<int, int>;
 
int main()
{
    int n; cin >> n;
    map<int, int> o, e;
    for (int i = 0; i < n / 2; i++) 
    {
        int vo; cin >> vo; o[vo]++;
        int ve; cin >> ve; e[ve]++;
    }

    priority_queue<P> qo, qe;
    for (auto& x: o) {
        qo.push({x.second, x.first});
    }
    for (auto& x: e) {
        qe.push({x.second, x.first});
    }

    P o1 = qo.top(); qo.pop();
    P e1 = qe.top(); qe.pop();

    int ans;
    if (o1.second != e1.second) {
        ans = n - o1.first - e1.first;
    } else if (qo.empty() && qe.empty()) {
        ans = n / 2;
    } else if (qo.empty()) {
        ans = n - o1.first - qe.top().first;
    } else if (qe.empty()) {
        ans = n - qo.top().first - e1.first;
    } else {
        ans = min(n - o1.first - qe.top().first, n - qo.top().first - e1.first);
    }

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

Measured memory_bytes: 6136
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int cnt[10] = {};
    rep(i,0,4){
        int a;
        cin >> a;
        cnt[a]++;
    }
    if(cnt[1] && cnt[4] && cnt[7] && cnt[9]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

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

int main(){
  int a,b,x,y,ans=0,tmpa,tmpb;
  cin>>a>>b;
  
  x=25*a/2;
  y=10*b;
  ans=min(x,y);
  
  while(ans<1001){
    tmpa=ans*0.08;
    tmpb=ans*0.1;
    if(tmpa==a&&tmpb==b){
      cout<<ans<<endl;
      return 0;
    }
    ans++;
  }
  
  cout<<-1<<endl;
  
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <numeric>
using namespace std;

int main(void) {
	string S;
	int N;

	cin >> N >> S;

	for (int i = 0; i < S.size(); i++) {

		if ((S[i]+N) > 'Z') {

			for (int j = 0; j < N; j++) {

				S[i]++;
				if (S[i] > 'Z') S[i] = 'A';

			}

		}
		else S[i] += N;

	}

	cout << S << endl;


	return 0;

}

Measured memory_bytes: 256
from operator import mul
from functools import reduce


n, k = map(int, input().split())
res = 0
for i in range(k, n+2):
    over = (2*n-i+1)*i/2
    under = (i-1)*i/2
    res += int(over - under + 1)
print(res % (10**9+7))


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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  uint64_t g = gcd(m,n);
  if(m%g==0) return (m/g)*n;
  if(n%g==0) return (n/g)*m;
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t 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 maxNum = 100000;
  char isNotPrime[maxNum+1] = {};
  isNotPrime[0]=isNotPrime[1]=1;
  for(int i=2;i<maxNum;i++){
    if(isNotPrime[i]==1) continue;
    int num = i+i;
    while(num<=maxNum){
      isNotPrime[num]=1;
      num += i;
    }
  }
*/
// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

signed main() {
  ll n;
  cin >> n;
  
  map<ll,ll> count;
  ll a;
  ll totalRem = 0;
  ll maxRem = 0;
  for(int i=0;i<n;i++){
    cin >> a;
    count[a]++;
    if(count[a]>=2){
      totalRem++;
      maxRem = max(maxRem,count[a]-1);
    }
  }

  if(maxRem<=totalRem/2){
    if(totalRem%2==0){
      cout << n-totalRem << endl;
    }
    else{
      cout << n-totalRem-1 << endl;
    }
  }
  else{
    n -= (totalRem-maxRem)*2;
    maxRem -= (totalRem-maxRem);
    n -= maxRem*2;
    if(n<=0){
      n = 1;
    }
    cout << n << endl;
  }

  return 0;
}



Measured memory_bytes: 9656
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long LL;
const int MOD = 1e9 + 7;
int p[1010];
LL num[1010];

int main () {
        int cnt = 1;
        p[1] = 2;
        for (int i = 2; i <= 1000; i++) {
                int flag = 0;
                for (int j = 2; j * j <= i; j++) {
                        if (i % j == 0) {
                                flag = 1;
                                break;
                        }
                }
                if (!flag)      p[++cnt] = i;
        }
        int n;
        cin >> n;
        memset (num, 0, sizeof num);
        for (int i = 2; i <= n; i++) {
                int now = i;
                for (int j = 1; j <= cnt; j++) {
                        while (now % p[j] == 0) {
                                num[j]++;
                                now /= p[j];
                        }
                        if (now == 1)   break;
                }
        }
        LL ans = 1;
        for (int i = 1; i <= cnt; i++) {
                ans = (ans * (num[i] + 1)) % MOD;
        }
        cout << ans << endl;
        return 0;
}


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

int main(){
  int x;
  cin >> x;
  
  //while (1)とかwhile (true)は無限ループのこと
  while (1){
    bool ok=true;//ここでのokは「xは素数だ」ということ
    for (int i=2;i<x;++i){
      if (x%i==0) {
        ok=false;
        break;
      }
    }
    if (ok) break;
    else ++x;
  }
      cout << x << endl;
      return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  string s;
  cin>>s;
  int len=s.size();
  int i=0;
  int wflag=0;
  int swap=0;
  char buf;
  buf=s[0];
  if(buf=='W'){
    wflag=1;
  }
  for(i=1;i<len;i++){
    if(s[i]=='W'){
      wflag=1;
    }
    if(s[i]!=buf){
      swap++;
    }
    buf=s[i];
    //cout<<s[i]<<endl;
  }
  if(wflag==0){
    swap=0;
  }
  cout<<swap<<endl;
  return 0;

}


Measured memory_bytes: 512
#include<iostream>
#include<math.h>
using namespace std;

int n,k;
int cache[100000]={0};
int min_cost(int a[])
{
	if(n==1)
	return 0;
	cache[n-1]=0;
	cache[n-2]=abs(a[n-1]-a[n-2]);
	for(int i=n-3;i>=0;i--)
	{
		long long int min=100000000000;
		for(int j=1;j<=k;j++)
		{
		if(i+j<=n-1)	
	{
	long long int y=abs(a[i+j]-a[i])+cache[i+j];
	if(y<min)
	min=y;
}
}
	//long long int x=abs(a[i+2]-a[i])+cache[i+2];
	cache[i]=min;
	}
	return cache[0];
}






int main()
{
cin>>n>>k;
int a[n];
int i=0;
for(i=0;i<n;i++)
cin>>a[i];
int x=min_cost(a);
cout<<x;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
	int checked[27]={};
	string input;
	cin >> input;
	int size=input.size();
	for(int i=0;i<size;i++){
		checked[input[i] - 'a'] ++;
	}
	for(int i=0;i<26;i++){
		if(checked[i]%2 != 0){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T> void fill_all(T& arr, const T& v) { arr = v; }
template<typename ARR, typename U> void fill_all(ARR& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T>auto&operator<<(ostream&s,const unordered_set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const unordered_map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl

struct edge { int to, cost; };

const int INF = 1LL<<60;
const int MOD = 1e9+7;

void dfs(const vector<vector<int>>& G, vector<int>& group, int v, int k) {
   group[v] = k;
   for (int i = 0; i < G[v].size(); ++i) {
      int u = G[v][i];
      if (group[u] == -1) {
         dfs(G, group, u, k);
      }
   }
}

signed main()
{
   int n, m; cin >> n >> m;
   vector<int> a(n);
   for (int i = 0; i < n; ++i) {
      cin >> a[i];
   }
   vector<vector<int>> G(n);
   for (int i = 0; i < m; ++i) {
      int x, y; cin >> x >> y;
      G[x].push_back(y);
      G[y].push_back(x);
   }

   int k = 0;
   vector<int> group(n, -1);
   for (int i = 0; i < n; ++i) {
      if (group[i] == -1) {
         dfs(G, group, i, k++);
      }
   }

   if (k == 1) {
      cout << 0 << endl;
      return 0;
   }

   vector<vector<int>> as(k);
   for (int i = 0; i < n; ++i) {
      as[group[i]].push_back(a[i]);
   }

   for (int i = 0; i < k; ++i) {
      sort(as[i].begin(), as[i].end());
   }

   int sum = 0;
   vector<int> others;
   for (int i = 0; i < k; ++i) {
      for (int j = 0; j < as[i].size(); ++j) {
         if (j == 0) {
            sum += as[i][j];
         } else {
            others.push_back(as[i][j]);
         }
      }
   }
   sort(others.begin(), others.end());

   if ((int)others.size() < k-2) {
      cout << "Impossible" << endl;
      return 0;
   }

   for (int i = 0; i < k-2; ++i) {
      sum += others[i];
   }
   cout << sum << endl;

   return 0;
}


Measured memory_bytes: 11508
n,m=map(int,input().split())
h=list(map(int,input().split()))
A=[[] for _ in range(n+1)]
for _ in range(m):
    a,b=map(int,input().split())
    A[a].append(b)
    A[b].append(a)

s=0
for x in range(1,n+1):
    if A[x]==[]:s+=1
    else:
        f=True
        for y in A[x]:
            if h[x-1]<=h[y-1]:f=False
        if f==True:s+=1
print(s)



Measured memory_bytes: 92804
#include <iostream>
using namespace std;
long long ryuka[90];
void culryuka(){
    ryuka[0] = 2;
    ryuka[1] = 1;
    for(int i=2; i<90; i++){
        ryuka[i]=ryuka[i-1]+ryuka[i-2];
    }
}
int main(){
    long long N;
    cin>>N;
    culryuka();
    cout<<ryuka[N]<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5010, M = 210;
int n,m,d[N],val[N][M],ans;
struct node {
  int tag,mx;
  inline void operator += (const int& x) {
    tag += x;
    mx += x;
  }
} t[N << 2];
void push_down(int x) {
  t[x<<1|1] += t[x].tag;
  t[x<<1] += t[x].tag;
  t[x].tag = 0;
}
void push_up(int x) {
  if (t[x].tag) push_down(x);
  t[x].mx = max(t[x<<1].mx,t[x<<1|1].mx);
}
void modify(int l,int r,int v,int x=1,int lp=1,int rp=n) {
  if (l > rp || r < lp) return;
  if (lp >= l && rp <= r)
    return (void) (t[x] += v);
  if (t[x].tag) push_down(x);
  int mid = (lp + rp) >> 1;
  modify(l,r,v,x<<1,lp,mid);
  modify(l,r,v,x<<1|1,mid+1,rp);
  push_up(x);
}
int query(int l,int r,int x=1,int lp=1,int rp=n) {
  if (l > rp || r < lp) return 0;
  if (lp >= l && rp <= r)
    return t[x].mx;
  if (t[x].tag) push_down(x);
  int mid = (lp + rp) >> 1;
  return max(query(l,r,x<<1,lp,mid), query(l,r,x<<1|1,mid+1,rp));
}
struct data {
  int l,r,v;
  bool operator < (const data& x) const {
    return v < x.v;
  }
} sta[M][N];
int top[M];
void solve() {
  data tmp,tp;
  for (int i = 1 ; i <= n ; ++ i) {
    if (i != 1) modify(1,i-1,-d[i]);
    for (int j = 1 ; j <= m ; ++ j) {
      tmp = (data) {i,i,val[i][j]};
      while (top[j] && sta[j][top[j]] < tmp) {
	tp = sta[j][top[j]];
	modify(tp.l,tp.r,-tp.v);
	tmp.l = sta[j][top[j]--].l;
      }
      sta[j][++top[j]] = tmp;
      modify(tmp.l,tmp.r,tmp.v);
    }
    ans = max(ans,query(1,i));
  }
  printf("%lld\n",ans);
}
signed main() {
  scanf("%lld%lld",&n,&m);
  for (int i = 2 ; i <= n ; ++ i)
    scanf("%lld",&d[i]);
  for (int i = 1 ; i <= n ; ++ i)
    for (int j = 1 ; j <= m ; ++ j)
      scanf("%lld",&val[i][j]);
  solve();
  return 0;
}


Measured memory_bytes: 31488