akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;

const int N_MAX = 1000;

int n, m;
int p[N_MAX];

int main () {
	while (cin >> n >> m, n || m) {
		int sum = 0;
		for (int i = 0; i < n; i++) {
			cin >> p[i];
			sum += p[i];
		}
		sort(p, p + n, greater<int>());
		for (int i = m - 1; i < n; i += m) {
			sum -= p[i];
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;
    cout << (A < 0 ? (-A) * C + D + B * E : (B - A) * E) << endl;
}


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

int main() {
  int n, k, s;
  cin >> n >> k >> s;  

  rep(i,k){
    cout << s << endl;
  }
  rep(i,n-k){
    if (s==1e9) cout << 1 << endl;
    else cout << s+1 << endl;
  }

  return 0;
}


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

int main(){

    string s;
    cin >> s;

    int ans = 1000;
    for(int c = 0; c < 26; c++){
        vector<int> v;
        int left = -1;
        for(int i = 0; i < s.size(); i++){
            if(s[i] - 'a' == c ){
                v.push_back(i - left - 1);
                left = i;
            }
        }
        sort(v.rbegin(), v.rend());

        int ans_tmp;
        if(v.size() == 0) ans_tmp = s.size() - 1;
        else ans_tmp =  max(v[0] , (int)s.size() - left - 1 );
        ans = min(ans, ans_tmp );
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#include <math.h>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
  int H,W;
  cin >> H >> W;
  char a[H][W];
  int ans=0;
  for(int i=0;i<H;i++){
	for(int j=0;j<W;j++){
		cin >> a[i][j];
      	if(a[i][j]=='#')ans++;
    }
  }
  if(ans==H+W-1)cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define _GLIBCXX_DEBUG
static const int MAX = 100000;


int main(){
  int N, d[MAX], x;
  cin >> N;
  rep(i, N) cin >> d[i];
  sort(d, d+N);
  
  x = N/2 - 1;
  cout << d[x+1] - d[x] << endl;
}

Measured memory_bytes: 640
import java.util.*;

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

        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }

        int bigTall = a[0];

        long count = 0;
        for(int i = 1; i<n; i++){
            if(bigTall > a[i]){
                int sub = bigTall - a[i];
                count += sub;
            }
            else{
                bigTall = a[i];
            }
        }
        System.out.println(count);
    }
}

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

int main() {
  long long int n, l = 0, count = 1; cin >> n;
  long long int a[n]; 
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    if (l == 0 && a[i] < a[i-1]) 
        l = 2;
    else if (l == 1 && a[i] < a[i-1]) 
        l = 0, count++;
    else if (l == 0 && a[i] > a[i-1]) 
        l = 1;
    else if (l == 2 && a[i] > a[i-1]) 
        l = 0, count++;
  }
  cout << count << endl;
  return 0;
}
    
  
  


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

const double PI = acos(-1);


int main() {
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    
    double tm = double(m)/60 * 2 * PI; 
    double th = double(60*h + m)/720 * 2 * PI;

    double t = abs(tm - th);
    double x = sqrt(a*a + b*b - 2*a*b*cos(t));
    printf("%.10f\n",x);

    return 0;
}

Measured memory_bytes: 4200
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define print(n) std::cout << n << std::endl;
#define FOR(i,n) for(int i = 0; i < n; i++);
using namespace std;

int main(){
    string n;
    cin >> n;
    if(n[0] == '9' || n[1] == '9'){
        print("Yes")
    }else print("No")
}


Measured memory_bytes: 256
#include "vector"
#include "set"
#include "map"
#include "unordered_set"
#include "unordered_map"
#include "string"
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

#define ll long long
#define INF 2e9
#define INF2 4611686018427387904
//#define MOD 1000000007
#define MOD 998244353
#define MAX_SIZE 1000000000

typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { bool first = true; for (const auto& j: v) { if (!first) { os << " "; } first = false; os <<j; } os << "\n"; return os; }
template<typename T>
istream& operator>>(istream& is, vector<T>& v) { for (auto& elem : v) { is >> elem; } return is; }

vector<ll> f;
void set_f(int n) { f.resize(n+1); f[0] = 1; for (int i=1; i<= n; i++) { f[i] = (f[i-1] * i) % MOD;} }
ll nod(ll a, ll b) { if (b == 0) { return a; } else { return nod(b, a % b); } }
ll pw(ll x, ll n, ll m=MOD) { if (n == 0) { return 1;} if (n%2 == 0) { return pw((x*x) % m, n/2, m); } return (pw(x, n-1, m) * x) % m; }
ll dv(ll a, ll b) { return (a * pw(b, MOD - 2)) % MOD; }
ll c_n_k(int n, int k) { if (k > n) { return 0; } if (k < 0) { return 0; } return dv(dv(f[n], f[k]), f[n-k]); }

vi a;
vector<vi> g;
vi d;
vi ans;

void dfs(int x, int prev) {
//    cout << x << ' ' << prev << endl;
//    cout << "d=" << d << endl;

    int l_prev = -1;
    int d_prev = -1;

    if (d[d.size()-1] < a[x]) {
        d.push_back(a[x]);
    } else {
        int l = 1;
        int r = d.size() - 1;
        while (l < r) {
            int m = (l + r) / 2;
            if (d[m] < a[x]) {
                l = m + 1;
            } else {
                r = m;
            }
        }

        l_prev = l;
        d_prev = d[l];

        d[l] = min(d[l], a[x]);
    }
    ans[x] = d.size() - 1;

    for (int y : g[x]) {
        if (y != prev) {
            dfs(y, x);
        }
    }

    if (l_prev == -1) {
        d.pop_back();
    } else {
        d[l_prev] = d_prev;
    }
}

void solve() {
    int n;
    cin >> n;

    a.resize(n);
    cin >> a;

    g.resize(n);
    ans.resize(n);

    for (int i=0; i<n-1; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    d.resize(1);
    d[0] = 0;
    dfs(0, -1);

    for (int i=0; i<n; i++) {
        cout << ans[i] << "\n";
    }
}

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

    if (0) {
        int tests;
        cin >> tests;
        for (int t = 1; t <= tests; t++) {
            //cout << "Case #" << t << ": ";
            solve();
            //cout << "\n";
        }
    } else {
        solve();
        //cout << endl;
    }

    return 0;
}

Measured memory_bytes: 27092
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1000000007;
const long double PI=3.14159265358979;

int main() {
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  if(a>=k){
    cout<<k;
  }
  else if(a+b>=k){
    cout<<a;
  }
  else{
    k=k-a-b;
    cout<<a-k;
  }
}


Measured memory_bytes: 3636
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

n,m=LI()

print(n*~-n//2+m*~-m//2)




Measured memory_bytes: 39532
def main():
  #n = int(input())
  #s = input()
  #s = input().split()
  a,b = list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = 0
  count = 0
  lis = []
  
  if b%a == 0:
    print(a+b)
  else:
    print(b-a)

if __name__ == '__main__':
  main()

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

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

	int N = scan.nextInt();

	int[] a_ = new int[N];
	for(int i = 0; i < N; i++){
	    a_[i] = scan.nextInt();
	}
	
	//連想配列を使用
	int[] num_ = new int[100000];
	for(int i = 0; i < N; i++){
	    num_[a_[i]]++;
	}

	int max = 0;
	for(int i = 0; i < 99998; i++){
	    int tmp = num_[i]+num_[i+1]+num_[i+2];
	    if(tmp > max){
		max = tmp;
	    }
	}
	System.out.println(max);
    }
}


Measured memory_bytes: 49656
def swap(a, j)
  temp = a[j]
  a[j] = a[j-1]
  a[j-1] = temp
end

def bubble_sort(a, n)
  swap_count = 0
  (0..n).each do |i|
    (n-1).step(i+1, -1) do |j|
      if a[j] < a[j-1]
        swap(a, j)
        swap_count += 1
      end
    end
  end
  puts a.join(' ')
  puts swap_count
end

N = gets.to_i
A = gets.chop.split.map(&:to_i)

bubble_sort(A, N)



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

using ll = long long;
using pii = pair<int, int>;

int n, m;
vector<int> adj[666];

double cache[666][666];

double dp(int v, int b) {
  if(v == n) return 0;
  if(adj[v].size() == 0) return 1e18;
  if(cache[v][b] != 0) return cache[v][b];

  vector<double> e;
  int d = adj[v].size();
  for(int u : adj[v]) {
    e.push_back(dp(u, b));
  }

  if(v == b) {
    sort(e.begin(), e.end());
    e.pop_back();
    d--;
  }

  double res = 0;
  for(double t : e) res += t;
  res /= d;
  res += 1.0;

  return cache[v][b] = res;
}

int main(int argc, char **argv) {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  cin >> n >> m;
  for(int i=0; i<m; i++) {
    int x, y; cin >> x >> y;
    adj[x].push_back(y);
  }

  double res = 1e18;
  for(int i=0; i<=n; i++) {
    if(adj[i].size() == 1) continue;
    double t = dp(1, i);
    res = min(res, t);
  }

  cout.precision(9);
  cout << fixed;
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 4608
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>

#define rep(i,n) for (long long int i = 0; i < (n); i++)
#define rep1(i,n) for (long long int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

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

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

int x[10], y[10];

double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}

int main()
{
    int n; cin >> n;
    rep1(i,n+1) {
        cin >> x[i] >> y[i];
    }

    double sum = 0.0;
    vector<int> v(n);
    for(int i = 0; i < n; i++) v[i] = i + 1;
    do {
        for(int i = 0; i < n - 1; i++) sum += dist(v[i], v[i+1]);
    } while(next_permutation(v.begin(), v.end()));
    int Factorial = 1;
    for(int i = 2; i <= n; i++) Factorial *= i;
    cout << fixed << setprecision(10) << sum / Factorial << endl;
    return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int k = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri() - k;
	int64_t sum[n + 1];
	sum[0] = 0;
	for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + a[i];
	std::set<int64_t> all;
	for (int i = 0; i <= n; i++) all.insert(sum[i]);
	int cnt = 0;
	std::map<int64_t, int> compress;
	std::vector<int64_t> decompress;
	for (auto i : all) compress[i] = cnt++, decompress.push_back(i);
	int cnt2 = 1;
	while (cnt2 < cnt) cnt2 *= 2;
	std::vector<int> data;
	data.resize(2 * cnt2);
	int64_t ans = 0;
	for (int i = 1; i <= n; i++) {
		int cur = compress[sum[i - 1]] + cnt2;
		for (; cur; cur >>= 1) data[cur]++;
		
		int l = 0;
		int r = compress[sum[i]] + 1;
		int res = 0;
		for (l += cnt2, r += cnt2; l < r; l >>= 1, r >>= 1) {
			if (r & 1) r--, res += data[r];
			if (l & 1) res += data[l], l++;
		}
		ans += res;
	}
	std::cout << ans << std::endl;
	
	
	return 0;
}


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

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

  if(n[0] == '1') cout << 9;
  else cout << 1;
  if(n[1] == '1') cout << 9;
  else cout << 1;
  if(n[2] == '1') cout << 9;
  else cout << 1;
  cout << endl;
  return 0;
}


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

#define int long long
const int INF = 100000000000000000;

const int MAX_N = 100005;
const int MAX_M = 100005;

int N, M;
int A[MAX_M], B[MAX_M];

bool used[MAX_M];
vector<int> L[MAX_N];
vector<int> R[MAX_N];

signed main()
{
    cin >> N >> M;
    for(int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
        L[A[i]].push_back(i);
        R[B[i]].push_back(i);
    }

    queue<int> S;

    int ans = 0;

    for(int i = 0; i < N; i++) {
        if(R[i].size() > 0) {
            // cerr << i << " YES" << endl;
            for(int j = 0; j < R[i].size(); j++) {
                if(!used[R[i][j]]) {
                    // cerr << "USED YES " << R[i][j] << endl;
                    while(S.size() > 0) {
                        int SS = S.front(); S.pop();
                        used[SS] = true;
                        // cerr << SS << " ";
                    }
                    // cerr << endl;
                    ans++;
                    break;
                }
            }
        }
        if(L[i].size() > 0) {
            for(int j = 0; j < L[i].size(); j++) {
                S.push(L[i][j]);
                // cerr << L[i][j] << " ";
            }
            // cerr << endl;
        }
        // cerr << "S: " << S.size() << endl;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 12284
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int n,i;
  const int mod=1e9+7;
  ll ans=1;
  
  cin >> n;
  
  for (i=2;i<=n;i++){
    ans=ans*i%mod;
  }
  
  cout << ans << endl;
  
  return 0;
}

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

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP0(i,n) for (ll i = 0; i <= (ll)(n); ++i)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define dep(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}

signed main() 
{
  int n,m,x; cin>>n>>m>>x;
  int l,r;
  l=r=0;
  rep(i,m)
  {
    int tmp=in();
    if(tmp<x) ++l;
    else ++r;
  }
  print(min(l,r));

  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M,X,Y;
    cin>>N>>M>>X>>Y;
    int x[N+1],y[M+1];
    for(int i=0;i<N;i++){
        cin>>x[i];
    }
    for(int i=0;i<M;i++){
        cin>>y[i];
    }
    x[N]=X,y[M]=Y;
    sort(x,x+N+1);sort(y,y+M+1);
    cout<<(x[N]<y[0]?"No War":"War")<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(true){
            int max=0,min=10000,sum=0,a=0;
            int n=sc.nextInt();
            if(n==0)break;
            for(int i=0;i<n;i++){
                a=sc.nextInt();
                sum+=a;
                if(a>=max)max=a;
                if(min>=a)min=a;
            }
            sum=sum-max-min;
            System.out.println(sum/(n-2));
        }
        }
    }


Measured memory_bytes: 28780
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=1e5+5;
int h[maxn];
bool good[maxn];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>h[i];
    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        if(h[u]>=h[v]) good[v]=true;
        if(h[v]>=h[u]) good[u]=true;
    }
    int ans=0;
    for(int i=1;i<=n;i++)
        ans+=(!good[i]);
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 4104
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int n, r;
	while(cin >> n >> r, n|r){
		vi list(n);
		REP(i, n) list[i] = i + 1;

//		for(auto n:list)
//			LOG("%d ", n);
//		LOG("\n");

		REP(i, r){
			int p, c;
			cin >> p >> c;
			vi stk = {list.end()-(p+c-1),list.end()-(p-1)};
			list.erase(list.end()-(p+c-1),list.end()-(p-1));
			for(auto n:stk)
				list.push_back(n);

//			for(auto n:list)
//				LOG("%d ", n);
//			LOG("\n");
		}

		cout << list[list.size() - 1] << endl;
	}
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define int long long
#define mod 1000000007

double dp[301][301][301];

double solve1(int x, int y, int z, int n) {
	if (x < 0 || y < 0 || z < 0)return 0;
	if (dp[x][y][z] >= 0)return dp[x][y][z];
	double val = n + x * solve1(x - 1, y, z, n) + y * solve1(x + 1, y - 1, z, n) + z * solve1(x, y + 1, z - 1, n);
	return dp[x][y][z] = val / (x + y + z);
}


void solve() {
	int n;
	cin >> n;
	int one = 0, two = 0, three = 0;
	int i;
	for (i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x == 1)one++;
		else if (x == 2)two++;
		else three++;
	}
	memset(dp, -1, sizeof(dp));
	dp[0][0][0] = 0;
	double len = solve1(one, two, three, n);
	cout << fixed << setprecision(10) << len << endl;
	return;
}


int32_t main() {
	std::ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 216916
#include <iostream>
#include <string>

int main(){
	int data;
	std::cin >> data;  //dataset
	std::cin.ignore();
	
	std::string mis = "Hoshino";
	std::string correct = "Hoshina";
	
	for(int i=0; i<data; ++i){
		std::string  sentence;
		
		std::getline(std::cin, sentence);
		
		std::string::size_type index = sentence.find(mis);
		
		if(index == std::string::npos){
			std::cout << sentence << std::endl;
		}else{
			while(index != std::string::npos){
				sentence.replace(index, mis.length(), correct);
				index = sentence.find(mis, index + correct.length());
			}
			std::cout << sentence << std::endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1220
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  a=LI()
  b=LI()

  sm1=sum(a)
  sm2=sum(b)

  cnt=sm2-sm1
  need=0
  for i in range(n):
    need+=max(0,(b[i]-a[i]+1)//2)

  if cnt<need:
    return 'No'
  return 'Yes'

# main()
print(main())


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

int main(){
  ll mod=1e9+7,x,y,z=1,w=0,o,p,r,q,v[93],t[91][91][2],a,b;
  v[0]=1,v[1]=1;
  for(int i=2;i<93;i++)v[i]=v[i-1]+v[i-2];
  for(int i=2;i<91;i++){
    for(int j=0;j<i;j++){
      a=v[i],b=v[i+1];
      if(j==0){
        t[i][j][0]=a,t[i][j][1]=b;
        continue;
      }
      if(j==1){
        t[i][j][0]=b,t[i][j][1]=2*b-a;
        continue;
      }
      t[i][j][0]=t[i-1][j-1][1],t[i][j][1]=t[i-1][j-1][1]+t[i-1][j-1][0];
    }
  }
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>x>>y;
    if(x>y)swap(x,y);
    if(y==1){
      cout<<"1 1"<<endl;continue;
    }
    for(int i=0;i<93;i++){
      if(v[i]>x||v[i+1]>y){
        z=i-1;break;
      }
    }
    cout<<z<<" ";
    if(z==1){
      cout<<x*y%mod<<endl;continue;
    }
    w=0;
    for(int j=0;j<z;j++){
      o=t[z][j][0],p=t[z][j][1];
      if(o>x||p>y)continue;
      r=y-p;
      r/=o;
      w+=r+1;
      w%=mod;
      if(x>=p){
        r=x-p;
        r/=o;
        w+=r+1;
        w%=mod;
      }
    }
    cout<<w<<endl;
  }
}

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

template <typename T>
struct SegmentTree{
  typedef function<T(T,T)> F;
  int n;
  F f;
  T ti;
  vector<T> dat;

  SegmentTree(){}
  SegmentTree(F f,T ti):f(f), ti(ti) {}

  void init(int n_){
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }

  void build(const vector<T> &v){
    int n_=v.size();
    init(n_);
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }

  void set_val(int k,T x){
    dat[k+=n]=x;
    while(k>>=1)
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
  }

  T query(int a,int b){
    if(a>=b) return ti;
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }
};

int main() {
    int n, q;
    cin >>n>>q;
    SegmentTree<int> rmq([](int a, int b){return min(a, b);}, INT_MAX);
    rmq.init(n);
    for(int i=0;i<q;i++){
        int c, x, y;
        cin >> c >> x >> y;
        if(c) cout << rmq.query(x, y+1) << endl;
        else rmq.set_val(x, y);
    }
}


Measured memory_bytes: 3892
H,W,K = list(map(int,input().strip().split()))
M = []
for _ in range(H):
    M += [input()]

rows = []
cols = []
for i in range(H):
    temp = 0
    for j in range(W):
        if M[i][j] == '#':
            temp += 1
    rows += [temp]

for j in range(W):
    temp = 0
    for i in range(H):
        if M[i][j] == '#':
            temp += 1
    cols += [temp]
#print(rows,cols)
total = sum(rows)
ans = 0
for i in range(2**H):
    s1 = "0"*(H-len(bin(i)[2:]))+bin(i)[2:]    
    for j in range(2**W):
        s2 = "0"*(W-len(bin(j)[2:]))+bin(j)[2:]
        delete = 0
        for p in range(H):
            if s1[p] == "1":
                    delete += rows[p]
        for q in range(W):
            if s2[q] == '1':
                delete += cols[q]
        
        for p in range(H):
            for q in range(W):
                if s1[p] == "1" and s2[q] == "1":
                    if M[p][q] == "#":
                        delete -= 1
        if total - delete == K:
            #print(s1,s2,delete,total)
            ans += 1
print(ans)
        
                
                
        
    

Measured memory_bytes: 74984
#include <iostream>
#include <algorithm>
using namespace std;
 
int v[10000], w[10000];
int dp[2][10001];
int main(){
    int N, W, ans = 0; cin >> N >> W;
    for(int i=0; i<N; i++) cin >> v[i] >> w[i];
    for(int i=0; i<N; i++) {
        int mo = i % 2;
        for(int j=0; j<=W; j++) {
            dp[mo^1][j] = max(dp[mo^1][j], dp[mo][j]);
            if(j-w[i] >= 0) dp[mo^1][j] = max(dp[mo^1][j], dp[mo][j-w[i]] + v[i]);
            ans = max(ans, dp[mo^1][j]);
        }
        for(int j=0; j<=W; j++) dp[mo][j] = 0;
    }
    cout << ans << endl;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int p[3][2];
string game[3];

void poyo() {
	memset(p, 0, sizeof(p));
	
	for_(i,0,3) {
		if (i != 0) ++p[i - 1][game[i][0] - 'A'];
		int len = game[i].size();	
		for_(j,1,len) ++p[i][game[i][j] - 'A'];
	}
	
	for_(i,0,3) {
		cout << p[i][0] + (i == 2 ? p[i][0] > p[i][1] : 0) << " " << p[i][1] + (i == 2 ? p[i][0] < p[i][1] : 0) << endl;
	}
}

int main() {
	while (cin >> game[0] >> game[1] >> game[2]) poyo();
}

Measured memory_bytes: 1184
L=int(input())
#D = L//3
#Amari = L%3
#if Amari == 0:
#    print(D**3)
#elif Amari == 1:
#    print(D*D*(D+1))
#else:
#    print(D*(D+1)*(D+1))
print(L**3/27)

Measured memory_bytes: 38256
#include<stdio.h>
int main()
{int A,B,C,D,E,F;
scanf("%d%d%d%d",&A,&B,&C,&D);
E=A+B;
F=C+D;
if(E>F)
printf("Left");
if(E<F)
printf("Right");
if(E==F)
printf("Balanced");
return 0;
}

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

int main(){
  string s;
  cin>>s;
  bool ok=false;
  rep(i,3){
    if(s[i]=='7'){
      ok=true;
    }
  }
  if(ok)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

    

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

int main(){
	int sen[10000];
	int bit[1024];
	int num[1024],s;
	for(int i=0;i<1024;i++)
		for(num[i]=0,s=i;s>0;s >>= 1)num[i]+=s&1;
	
  int r,c,cc;
  while(true){
		scanf("%d %d",&r,&c);
		if (!r&&!c)break;
		for(int i=0;i<c;i++) sen[i] = 0;
		for(int j=0;j<r;j++){
			for(int i=0;i<c;i++){
				scanf("%d",&cc);
				sen[i] <<= 1;
				sen[i] += cc;
			}
		}
		for(int i=0;i<1024;i++) bit[i] = 0;
		for(int i=0;i<c;i++) bit[sen[i]]++;

		int n,sum = 0,smax = 0,k=1,l;
		k <<= r-1;
		for(int i=0;i<k;i++){
			sum = 0;
			for(int j=0;j<k<<1;j++){
				s = j^i;
				sum += num[s] > (r>>1) ? num[s]*bit[j] : (r-num[s])*bit[j];
			}
			if (sum>smax)smax = sum;
		}
		printf("%d\n",smax);
  }
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  
  vector<int> l(n);
  for(int i=0; i<n; i++){
    cin >> l[i];
  }
  
  sort(l.begin(), l.end());
  
  int hen = 0;
  for(int i=0; i<n-1; i++){
    hen += l[i];
  }
  
  if(l[n-1] < hen)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define LL long long
#define st first
#define nd second
#define endl '\n'
using namespace std;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long long n, ans = 0;
	cin >> n;
	for(long long i = 1; i * i <= n; ++i) {
		if(n % i == 0) {
			if((n - i) / i > i)
				ans += (n - i) / i;
			if(i * i != n) {
				long long x = n / i;
				if((n - x) / x > x)
					ans += (n - x) / x;
			}
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  uint64_t n, k;
  cin >> n >> k;
  vector<uint64_t> h(n);
  if (n <= k) {
    cout << 0 << endl;
  } else {
    for (auto& hi : h) {
      cin >> hi;
    }
    sort(h.begin(), h.end());
    uint64_t total = accumulate(h.begin(), h.end() - k, 0LL);
    cout << total << endl;
  }
  return 0;
}


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

int main() {
	int n; cin >> n;
	vector<int>A;
	for (int i = 0; i < n; i++) {
		long tmp; cin >> tmp;
		A.push_back(tmp);
	}
	sort(A.begin(), A.end());	
	long long sum = A[0];
	int ans = 0;
	for (int i = 1; i < A.size(); i++) {
		if (sum * 2 >= A[i])ans++;
		else ans = 0;
		sum += A[i];
	}
	cout << ans + 1 << endl;

	return 0;
}

Measured memory_bytes: 892
# Code for C - Half and Half
# Use input() to fetch data from STDIN
[a, b, c, x, y] = [int(x) for x in input().split()]

p = max(x, y) * c * 2
m = min(x, y)
q = m * c * 2 + (x - m) * a + (y - m) * b
r = a * x + b * y

print(min(p, q, r))


Measured memory_bytes: 2940
#include <stdio.h>
#include <math.h>

int main(void){

	int n,i,ans=0;
  	double ave=0;
  
  	scanf("%d",&n);
  	int a[n];
  	for(i=0;i<n;i++){
    	scanf("%d",&a[i]);
      	ave+=a[i];
    }
  	ave /= n;
	for(i=1;i<n;i++){
    	if(fabs(ave - a[ans]) > fabs(ave - a[i])){
        	ans = i;
        }
    }	
  	
  	printf("%d\n",ans);
  
  
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define CAT(a,b)a b
#define VASIZE(a,b,N,...)N
template<class T>auto size(T&&a)->decltype(a.size(), int()) { return a.size(); }
template<class T>typename make_signed<decltype(T() % 0)>::type size(T a) { return a; }
#define REP(t,a,N)for(decltype(size(N))t=size(a),_l##t=size(N);t<_l##t;t++)
#define RREP(t,a,N)for(decltype(size(N))t=size(N)-1,_l##t=size(a);t>=_l##t;t--)
#define rep(t,...)CAT(REP,VASIZE(__VA_ARGS__,(t,__VA_ARGS__),(t,0,__VA_ARGS__)))
#define rrep(t,...)CAT(RREP,VASIZE(__VA_ARGS__,(t,__VA_ARGS__),(t,0,__VA_ARGS__)))
#define all(a)begin(a),end(a)

void Calc();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0); cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/
string s;

pair<int, ll> dfs(string s) {
  if (size(s) == 0)return{ 1,0 };
  ll ans = 0;
  int cnt = 0;
  rep(j, 1, size(s) + 1) {
    auto p = dfs(s.substr(j));
    ll a = stoll(s.substr(0, j));
    ans += a * p.first + p.second;
    cnt += p.first;
  }
  return{ cnt,ans };
}
void Calc() {
  in, s;
  cout << (dfs(s).second) << endl;
}


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

using namespace std;

using int64 = long long;

constexpr int64 P = 1000000007;

// Verified: ABC133E, ABC132D, ABC130E
struct FiniteField {
 private:
  int64 x;
 public:
  FiniteField(int64 input_x) : x(input_x) {}
  FiniteField() : x(0) {}
  int64 Value() { return x; }
  inline FiniteField operator+(FiniteField o) {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

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

  int n;
  cin >> n;
  vector<vector<int>> mat = Make2DVector(n, n, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> mat[i][j];
    }
  }

  vector<vector<FiniteField>> dp = Make2DVector(n + 1, 1 << n, FiniteField(0));
  vector<vector<int>> dp_solved = Make2DVector(n + 1, 1 << n, 0);

  auto solve = [&](int k, int set, auto& f) -> FiniteField {
    if (dp_solved[k][set]) return dp[k][set];

    if (k == n) return 1;

    FiniteField value = 0;
    for (int i = 0; i < n; i++) {
      if ((set & (1 << i)) == 0) continue;
      if (mat[k][i] == 0) continue;
      value += f(k + 1, set - (1 << i), f);
    }
    dp_solved[k][set] = 1;
    dp[k][set] = value;
    return value;
  };
  cout << solve(0, (1 << n) - 1, solve).Value() << endl;
}


Measured memory_bytes: 549244
n = gets.chomp.to_i
arr_a = gets.chomp.split(' ').map(&:to_i)
arr_b = gets.chomp.split(' ').map(&:to_i)
arr_c = gets.chomp.split(' ').map(&:to_i)
# p "#{arr_a},#{arr_b},#{arr_c}"
sum = 0
i = 0
while i < n
  sum += arr_b[arr_a[i]-1]
  # p "i:#{i}, a:#{arr_a[i]}, b:#{arr_b[arr_a[i]-1]}, sum:[#{sum}]"
  sum += arr_c[arr_a[i]-1]   if arr_a[i]+1 == arr_a[i+1]
  # puts "hi, c:#{arr_c[i-1]}" if arr_a[i]+1 == arr_a[i+1]
  i += 1
end
puts sum

Measured memory_bytes: 14320
#include <iostream>

using namespace std;
static const int mx=107;
static const int inf=(1<<21);

int n,m[mx][mx];

void dijkstra()
{
	int minv;
	int d[mx],color[mx];
	
	for (int i=0;i<n;i++) {
		d[i]=inf;
		color[i]=0;
	}
	
	d[0]=0;
	color[0]=1;
	while (1) {
		minv=inf;
		int u=-1;
		for (int i=0;i<n;i++) {
			if(minv>d[i]&&color[i]!=2)
			{
				u=i;
				minv=d[i];
			}
		}
		if(u==-1)break;
		color[u]=2;
		for (int v=0;v<n;v++) {
			if(color[v]!=2&&m[u][v]!=inf)
			{
				if(d[v]>d[u]+m[u][v])
				{
					d[v]=d[u]+m[u][v];
					color[v]=1;
				}
			}
		}
	}
		for (int i=0;i<n;i++) 
			cout<<i<<" "<<(d[i]==inf?-1:d[i])<<endl;
}
int main(int argc, char *argv[]) {
	cin>>n;
	for (int i=0;i<n;i++) {
		for (int j=0;j<n;j++) {
			m[i][j]=inf;
		}
	}
	int k,c,u,v;
	for (int i=0;i<n;i++) {
		cin>>u>>k;
		for (int j=0;j<k;j++) {
			cin>>v>>c;
			m[u][v]=c;
		}
	}
		
	dijkstra();
	
	return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

#include <bits/stdc++.h>
using namespace std;

signed main(){
    int A,B; cin>>A>>B;
  int ans;
    if(B>=A) ans=A;
  else ans = A-1;
  Out(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
 
vector<int> a(200010);
 
int main() {
  int k,n;
  cin >> k >> n;
  a.resize(n);
  rep(i,n) cin >> a[i];
  int sum = 0;
  int max_diff = 0;
  rep(i,n) {
    if (i == 0) {
      sum += k + a[0] - a[n-1];
      max_diff = max(k + a[0] - a[n-1], max_diff);
    } else {
      sum += a[i] - a[i-1];
      max_diff = max(a[i] - a[i-1], max_diff);
    }
  }
 
  cout << sum - max_diff << endl;
 
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

bool palindrome(string s)
{
    string s1 = s;
    string s2 = s1;
    reverse(s2.begin(), s2.end());
    return s2 == s1;
}

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    string s1 = s.substr(0, (n+1)/2-1);
    string s2 = s.substr((n+1)/2, (n+1)/2);
    if (palindrome(s) && palindrome(s1) && palindrome(s2))
        cout << "Yes";
    else 
        cout << "No";
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	static int n, sum, min;
	static int[] a;
	
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		while (true) {
			n = sc.nextInt();
			if (n == 0) break;
			a = new int[n];
			sum = 0;
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				sum += a[i];
			}
			min = sum;
			solve(0, 0);
			out.println(min);
		}
		out.flush();
	}
	
	static void solve(int index, int sumA) {
		if (index == n) return;
		min = Math.min(min, Math.abs(sum - (sumA + a[index]) * 2));
		solve(index + 1, sumA);
		solve(index + 1, sumA + a[index]);
	}
	
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) { return false; }
		}
		return true;
	}
	
	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	
	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}
	
	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}
	
	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}
	
	public int nextInt() {
		if (!hasNext()) { throw new NoSuchElementException(); }
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) { throw new NumberFormatException(); }
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	
}

Measured memory_bytes: 24600
/*
	  Chase
	   Your
	  Legend

	英雄志逐传奇
*/

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>

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

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

	if (b >= a) {
		cout << a << endl;
	}
	else {
		cout << a - 1 << endl;
	}
}


Measured memory_bytes: 256
import bisect as bi
n=int(input())
l=[input() for i in range(n)]
sto=[]
numl=[[0 for j in range(19)] for i in range(19)]
intcnt=0
for i in range(n):
    s=l[i]
    pal=[0,0]
    if "." not in s:
        pass
    else:
        cs=len(s)-s.index(".")-1
        pal=[-cs,-cs]
    N=int(s.replace(".",""))
    while N%5 == 0:
        N//=5
        pal[0]+=1
    while N%2 == 0:
        N//=2
        pal[1]+=1
    numl[min(18,pal[0]+9)][min(18,pal[1]+9)]+=1
    sto.append(pal)
    if pal[0]>=0 and pal[1]>=0:intcnt+=1
ans=0
accnuml=[[0 for i in range(20)] for j in range(20)]
for i in range(1,20):
    for j in range(1,20):
        accnuml[i][j]=accnuml[i][j-1]+accnuml[i-1][j]-accnuml[i-1][j-1]+numl[i-1][j-1]
for i in range(n):
    x,y=sto[i][0],sto[i][1]
    ans+=n-(accnuml[min(max(0,-x+9),18)][-1]+accnuml[-1][min(max(0,-y+9),18)]-accnuml[min(18,max(0,-x+9))][min(18,max(0,-y+9))])
print((ans-intcnt)//2)

Measured memory_bytes: 115036
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int N;cin>>N;
  int M=sqrt(N);
  P(M*M);
  return 0;
}


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

#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>

using namespace std;

typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define lim 100010
#define mod 1e9 + 7
#define INF 1e9
#define REP(i, n) for (int i = 0; i < n; i++)

ll GCD(int x, int y) { return x % y == 0 ? y : GCD(y, x % y); }

int main() {
  int N;
  scanf("%d", &N);
  ll A[N];
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  sort(A, A + N);
  for (int i = 0; i < N - 1; i++) {
    if (A[i] == A[i + 1]) {
      printf("NO");
      return 0;
    }
  }
  printf("YES");
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cassert>
#include <set>

using namespace std;

using ll = long long;

ll n;

int dfs(ll i, bool b3 = false, bool b5 = false, bool b7 = false) {
    
    if (i > n) {
        return 0;
    }
    
    int ret = b3 && b5 && b7;
    
    ret += dfs(i * 10 + 3, true, b5, b7) + dfs(i * 10 + 5, b3, true, b7) + dfs(i * 10 + 7, b3, b5, true);
    
    return ret;
}

int main() {
    cin >> n;
    
    cout << dfs(0) << endl;
}

Measured memory_bytes: 256