akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N >> K;
	cin >> L >> R;
	if ((R&L) != L) {
		cout << 0 << endl;
		return 0;
	}
	vector<int>v;
	for (int i = 0; i < N; i++) {
		cin >> M;
		if ((L&M) != L)continue;
		if ((R | M) != R)continue;
		v.push_back(M);
	}
	R -= L;
	L = 0;
	for (auto &i : v)i -= L;
	vector<vector<long long int>>binom(N + 1, vector<long long int>(N + 1, 0));
	for (int i = 1; i <= N; i++) {
		binom[i][1] = i;
	}
	for (int i = 2; i <= N; i++) {
		for (int j = 2; j <= i; j++) {
			binom[i][j] += binom[i - 1][j] + binom[i - 1][j - 1];
		}
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 2; j <= K; j++) {
			binom[i][j] += binom[i][j - 1];
		}
	}
	long long int ans = 0;
	ans+=binom[v.size()][K];
	for (int i = 1; i < (1 << 18); i++) {
		if ((i&R) != i)continue;
		map<int, int>mp;
		for (auto j : v) {
			mp[j&i]++;
		}
		int box = i;
		int num = 0;
		while (box) {
			num += box & 1;
			box >>= 1;
		}
		for (auto j : mp) {
		//	cout << i << " " << j.first << " " << j.second << endl;
			if (num & 1) {
				ans -= binom[j.second][K];
		//		ans %= MOD;
			}
			else {
				ans += binom[j.second][K];
		//		ans %= MOD;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3668
def solve(a, b, n):
    return a * min(b-1, n) // b - a * (min(b-1, n) // b)


def solve_baka(a, b, n):
    ans = -1e9
    for x in range(n+1):
        ans = max((a * x) // b - a * (x//b), ans)
        print('    ', x, (a * x) // b - a * (x//b))
    return ans


def main():
    a, b, n = [int(v) for v in input().split()]
    print(solve(a, b, n))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9104
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 2e5 + 5, mo = 1e9 + 7 ;
using namespace std ;

int n, st[N] ;
struct poi {
	int x, v, l, r, f ;
} a[N] ;

bool cmp(poi a, poi b) {
	return a.v < b.v ;
}

bool cmp2(poi a, poi b) {
	return (a.l < b.l || (a.l == b.l && a.r < b.r)) ;
}

void upd(int &x, int y) {
	x = (x + y) % mo ;
}

int main() {
	scanf("%d", &n) ;
	rep(i, 1, n) scanf("%d%d", &a[i].x, &a[i].v) ;
	sort(a + 1, a + n + 1, cmp) ;
	int top = 0, sum = 0, tot = 0, ans = 0 ;
	rep(i, 1, n) {
		if (!top || a[i].x > a[st[top]].x) st[++ top] = i ; 
		int l = 1, r = top ;
		for ( ; l <= r ; ) {
			int mid = (l + r) / 2 ;
			if (a[st[mid]].x >= a[i].x) a[i].l = st[mid], r = mid - 1 ; else l = mid + 1 ;
		}
	}
	top = 0 ;
	for (int i = n; i; -- i) {
		if (!top || a[i].x < a[st[top]].x) st[++ top] = i ;
		int l = 1, r = top ;
		for ( ; l <= r ; ) {
			int mid = (l + r) / 2 ;
			if (a[st[mid]].x <= a[i].x) a[i].r = st[mid], r = mid - 1 ; else l = mid + 1 ;
		}
	}
	sort(a + 1, a + n + 1, cmp2) ;
	//rep(i, 1, n) cout << a[i].l << " " << a[i].r << endl ;
	top = 1 ; 
	rep(i, 1, n) {
		for ( ; top <= n && a[top].r < a[i].l - 1 ; ++ top) upd(sum, a[top].f) ;
		a[i].f = (tot - sum) % mo ;
		if (a[i].l == 1) upd(a[i].f, 1) ;
		if (a[i].r == n) upd(ans, a[i].f) ;
		upd(tot, a[i].f) ;
	}
	printf("%d\n", (ans + mo) % mo) ;
	return 0 ;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
int n,x;
double t,a,y=10000000;
int main(void){
    cin>>n>>t>>a;
    for(int i=0;i<n;i++){
        D h;
        cin>>h;
        h=t-h*0.006;
        D d=abs(h-a);
        if(d<y){
            x=i;
            y=d;
        }
    }
    cout<<x+1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
const long long INF = numeric_limits<long long>::max();

ll GCD(ll a, ll b) {
    if (a > b) swap(a, b);
    while (b != 0) {
        ll c = b;
        ll d = a % b;
        a    = c;
        b    = d;
    }
    return a;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> vec(N);

    vector<ll> L(N + 1, 0);
    vector<ll> R(N + 1, 0);

    REP(i, N) {
        cin >> vec[i];
        L[i + 1] = GCD(L[i], vec[i]);
    }

    for (ll i = N - 1; i >= 0; --i) {
        R[i] = GCD(R[i + 1], vec[i]);
    }

    ll ans = 0;
    REP(i, N) {
        ans = max(ans, GCD(L[i], R[i + 1]));
    }
    PR(ans);
    return 0;
}

Measured memory_bytes: 5516
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        int n;
        string s;
        cin >> n >> s;
        int ans = 0;
        for (int i = 2; i < n; ++i) {
            unordered_map<char, ll> mp1, mp2;
            for (int j = 0; j < i; ++j) {
                mp1[s[j]]++;
            }
            for (int j = i; j < n; ++j) {
                mp2[s[j]]++;
            }
            int tmp = 0;
            each(m1, mp1) {
                each(m2, mp2) {
                    if (m1.first == m2.first) tmp++;
                }
            }
            ans = max(tmp, ans);
        }
        cout << ans << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
n,m= map(int, input().split())
x=[[] for j in range(n)]
for i in range(m):
    p,ye= map(int, input().split())
    x[p-1].append([ye,i])
for i in range(n):
    x[i].sort()
y=[0]*m
cnt=1
for i in range(n):
    for a in range(len(x[i])):
        j=str(i+1)
        k=str(cnt)
        y[x[i][a][1]]="0"*(6-len(j))+j+"0"*(6-len(k))+k
        cnt+=1
    cnt=1
for i in range(m):
    print(y[i])

Measured memory_bytes: 39104
#include<iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main() {

  int n ;
  cin >> n  ;
  set<string> s ;
  
  for(int i=0;i<n;i++){
    string ss ;
    cin >> ss ;
    s.insert(ss) ;
  } 

  cout << s.size() << endl ;

 return 0 ;
}  


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

using namespace std;

int main()
{
    string s;
    cin>>s;
    int f=1;
    if(s[0]!='A') f=0;
    int cnt=0;
    for(int i=0;i<s.size();i++)
        if(s[i]>='A' && s[i]<='Z')
        cnt++;
    if(cnt!=2) f=0;
    int ff=0;
    for(int i=2;i<s.size()-1;i++)
    {
        if(s[i]=='C') ff++;
        if(s[i]=='A') {
            ff=0;break;
        }
    }
    if(ff==0 || f==0) cout<<"WA"<<endl;
    else cout<<"AC"<<endl;
    return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int k;
    cin >> k;

    int s = 7, stmp;
    for(int ik=0;ik<=k;++ik) {
        if(s%k==0) { 
            cout << ik+1 << endl;
            return 0;
        }
        else {
            stmp = s;
            s = (stmp%k)*10 + 7;
            s %= k;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
int main()
{
    long int n,t,i,sum=0,a[10005];
    
    scanf("%ld %ld",&n,&t);
    for(i=0; i<t; i++)
    {
        scanf("%ld",&a[i]);
        sum=sum+a[i];
    }
    if(n>=sum){
    printf("%ld\n",n-sum);
    }
    else
    {
        printf("-1\n");
    }
return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<ll> X;
    rep(i, N) X.push_back(i + 1);
    vector<ll> P(N), Q(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];

    ll a = 0;
    ll b = 0;
    int x = 0;
    do {
        x++;
        bool ok1 = true;
        rep(i, N) {
            if (X[i] != P[i]) ok1 = false;
        }
        if (ok1) a = x;
        bool ok2 = true;
        rep(i, N) {
            if (X[i] != Q[i]) ok2 = false;
        }
        if (ok2) b = x;
    } while (next_permutation(X.begin(), X.end()));
    cout << abs(a - b) << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

int main(){

  int i=1,n;
  float base=100000;
  scanf("%d",&n);

  while(i<=n){
    base =ceil(base*1.05/1000)*1000;
    i++;
  }
    printf("%.0f\n",base);

    return 0;
}

Measured memory_bytes: 632
#include <stdio.h>

int main() {
	int n, l, i, sum;

	scanf("%d%d", &n, &l);
	sum = 0;
	for (i = 1; i <= n; i++)
		sum += (l + i - 1);
	printf("%d\n", sum - (l > 0 ? l : (l + n - 1 >= 0 ? 0 : l + n - 1)));
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int mod = 1e9 + 7;
int main()
{
	SPEED
	ld l;
	cin >> l;
	ld t = l/3;
	std::cout << std::fixed;
    std::cout << std::setprecision(7);
	cout << t*t*t;
	return 0;
}

Measured memory_bytes: 256
nums = gets.split(' ').map(&:to_i)
if nums[0] == nums[1] && nums[1] != nums[2]
  puts 'Yes'
elsif nums[1] == nums[2] && nums[2] != nums[0] 
  puts 'Yes'
elsif nums[0] == nums[2] && nums[0] != nums[1]
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
import java.util.*;
public class Main {
	private static Scanner sc;
	public static void main(String[] args){
		sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
	if ((a==b&&a!=1)|(a==1&&a==b))
		System.out.println("Draw");
	else if (a==1)
		System.out.println("Alice");
	else if (b==1)
		System.out.println("Bob");
	else if (a<b)
		System.out.println("Bob");
	else
		System.out.println("Alice");
	}
}

Measured memory_bytes: 9808
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define repran(i, a,b) for (int i = a; i<b;i++)
#define all(x) (x).begin(), (x).end()
#define v(T) vector<T>
#define vv(T) vector<v(T)>
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
int main()
{
    long double n, m, d;
    cin >> n >> m >> d;
    long double p;
    if (d == 0) {p = 1/n;}
    else p = 2*(n-d)/(n*n);
    cout << fixed << setprecision(7) << (m-1)*p << endl;
}


Measured memory_bytes: 3796
let rec read u =
  try let line = read_float () in
      let w = match line with
        i when i <= 48. -> "light fly"
      | i when i <= 51. -> "fly"
      | i when i <= 54. -> "bantam"
      | i when i <= 57. -> "feather"
      | i when i <= 60. -> "light"
      | i when i <= 64. -> "light welter"
      | i when i <= 69. -> "welter"
      | i when i <= 75. -> "light middle"
      | i when i <= 81. -> "middle"
      | i when i <= 91. -> "light heavy"
      | _ -> "heavy" in
      print_endline w;read u
  with End_of_file -> ();;

let () = read ();;

Measured memory_bytes: 2072
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

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

    int A, B;
    cin >> A >> B;

    if (A == 2 || B == 2) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>
#include<numeric>
#define rep(i,n) for(int i=0;i<n;++i)
#define mod 1000000007
using namespace std;
int main(){
    vector<pair<int,int> > map;
    while(true){
        int H,W;    cin>>H>>W;
        if(H==0&&W==0)break;
        map.push_back(make_pair(H,W));
    }
    rep(i,map.size()){
        rep(j,map[i].first){
            rep(k,map[i].second){
                if(j==0||k==0||j==map[i].first-1||k==map[i].second-1)  cout<<'#';
                else    cout<<'.';
            }
            cout<<endl;
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3112
use proconio::{input, fastout};
use num::BigInt;
use num_rational::BigRational;

#[fastout]
fn main() {
    input! {
        a: BigInt,
        mut b: String,
    }

    b.retain(|c| c != '.');

    let num = b.parse::<i64>().unwrap();
    let mut mul = a * num;

    mul /= 100;

    println!("{}", mul);
}


Measured memory_bytes: 2900
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(NULL);
typedef long long ll;
using namespace std;


void solve(){
    int n,cnt=0; cin>>n;
    vector<int>v(n);
    for(auto &i: v) cin>>i;
    for(int i =0; i<n; i++){
        if(((i+1)&1) && (v[i]&1)) cnt++;
    }
    cout<<cnt;
}


int main(){
    fast;
    solve();
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define PB push_back
#define F first
#define S second
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const ll MOD = 1e9+7;
 
int gcd(int a, int b){
	return (b ? gcd(b, a%b) : a);
}

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
 
	int n; cin >> n;
	ll sum = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			for(int k = 1; k <= n; k++){
				sum += gcd(gcd(i, j), k);
			}
		}
	}

	cout << sum << '\n';
 
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	string s, t; cin >> s >> t;
	cout << t << s << endl;

	return 0;
}


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

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

while(A>0&&C>0)
{
  C -= B;
  if(C>0)
  A -= D;
}
if(C<=0)
cout << "Yes" << endl;
else
{
  cout << "No" << endl;
}
}

Measured memory_bytes: 3600
import java.util.stream.*;
import java.io.*;

public class Main {
  
  static int n, k;
  static int[] a; 

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in;
    in = br.readLine().split(" ");
    k = Integer.parseInt(in[0]);
    n = Integer.parseInt(in[1]);

    in = br.readLine().split(" ");
    a = Stream.of(in).mapToInt(Integer::parseInt).toArray();

    br.close();

    int maxDistance = a[0] + k - a[n-1];

    for(int i = 0; i < n-1; i++){
      maxDistance = Math.max(maxDistance, a[i+1] - a[i]);
    }
    
    System.out.println(k - maxDistance);
  }
}

Measured memory_bytes: 51796
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,K;
  cin>>N>>K;
  int M=(N+1)*N/2;
  vector<int> A(N+1),B(M);
  for(int i=0;i<N;i++){
    cin>>A[i+1];
    A[i+1]+=A[i];
  }
  int cnt=0;
  for(int i=0;i<N;i++)
    for(int j=i+1;j<=N;j++,cnt++)B[cnt]=A[j]-A[i];
  int ans=0;
  for(int i=40;i>=0;i--){
    int cnt=0;
    for(int j=0;j<M;j++)
      if((B[j]>>i)&1)cnt++;
    if(cnt>=K){
      ans|=(1LL<<i);
      for(int j=0;j<M;j++)
        if(!((B[j]>>i)&1))B[j]=0;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 7196
n = int(input())
a = list(map(int,input().split()))
q = int(input())
for i in range(q):
    b,e,t = map(int,input().split())
    for k in range(e-b):
        a[b+k],a[t+k] = a[t+k],a[b+k]
print(*a)


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

int main() {
  int N; cin >> N;
  int ans;
  if (N%2==0)
  {
    ans = N/2;
  } else {
    ans = N/2 +1;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import math
def yaku(n,p,q):
    lcm = (p*q)//math.gcd(p,q)
    return (n//p + n//q - n//lcm)
a,b,c,d = map(int,input().split())
print((b-a+1)-((yaku(b,c,d)) - yaku(a-1,c,d)))

Measured memory_bytes: 9032
#include<iostream>
#include<vector>
#include<set>

int main () {
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    std::set<int> an;
    for (int i = 0; i < n; i++)
    {
        std::cin >> a[i];

    }

    int cnt = 1;
    for (int i = 0; i < n; i++) {
        if(cnt == a[i] ) {
            cnt++;
        }
    }
    if(cnt - 1 == 0) {
        std::cout << -1 << "\n";
    } else {
        std::cout << n - cnt + 1 << "\n";
    }
}

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

using namespace std;

typedef long long ll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse

//総和を出す。そこから、10で割れない数を引く

int main(){
    int N,sum=0,M=INF;
    cin>>N;
    vector<int> A(N);
    rep(i,N){
        cin>>A[i];
        sum+=A[i];
        if(A[i]%10!=0)M=min(M,A[i]);
    }
    if(M==INF)cout<<0;
    else if(sum%10!=0)cout<<sum<<endl;
    else cout<<sum-M<<endl;


    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct solve
{
	solve(){}
	ll operator()(int n, int k, vi&a) {
		vll s(n+1);
		for(int i=0;i<n;i++)
		{
			s[i+1]=(s[i]+a[i])%k;
		}
		for(int i=0;i<=n;i++)
		{
			s[i]=(s[i]+n-i)%k;
		}

		ll ans=0;
		map<int,ll> m;
		m[s[0]]++;
		for(int i=1;i<=n;i++)
		{
			if(i>=k)
			{
				m[s[i-k]]--;
			}
			ans+=m[s[i]];
			m[s[i]]++;
		}
		return ans;
	}
};

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

	for(;;)
	{
		int n, k;
		cin >> n >> k;
		if(cin.fail()) break;

		vi a(n);
		for(auto&m:a) cin >> m;

		cout << solve()(n, k, a) << "\n";
	}
	return 0;
}


Measured memory_bytes: 15104
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll ans = 0;
  ll n;cin>>n;
  reps(p,n){
    ans += (n / p) * (n/p + 1) / 2 * p;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3648
// https://atcoder.jp/contests/abc150/tasks/abc150_e

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

//------------------------------------------------------------------------------
ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

//------------------------------------------------------------------------------
const int N_MAX = 2*1e5;
const int C_I_MAX = 1e9;
const int MOD = 1e9+7;

int N;
ll C[N_MAX];

void solve() {
  sort(C, C + N, greater<ll>());
  ll ans = 0;
  REP(i, N) {
    ans = (ans + C[i] * (i + 2) % MOD) % MOD;
  }
  ans = ans * mod_pow(4, N - 1, MOD) % MOD;
  printf("%lld\n", ans);
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%lld", C + i);
}

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


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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    ll ans = 0;
    vector<ll> minus(m+2, 0), plus(m+2, 0), sum(m+2, 0);
    int t = 0;
    for (int i = 1; i < n; i++) {
        if (a[i-1] < a[i]) {
            ans += a[i]-a[i-1];
            sum[a[i]+1] += a[i]-a[i-1]-1;
        }
        else {
            ans += a[i];
            sum[a[i]+1] += a[i]+m-a[i-1]-1;
            if (a[i] != 1)t++;
        }
        plus[a[i-1]+1]++;
        minus[a[i]]++;
    }
    ll now = ans;
    for (int i = 2; i <= m; i++) {
        now -= t;
        now += sum[i];
        ans = min(ans, now);
        t = t - minus[i] + plus[i];
        //cout << i << " " << now << endl;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define int long long
inline long long in(){long long x=0;char c=getchar();bool neg=false;while(c!='-'&&('0'>c||c>'9')) c=getchar();if(c=='-') neg=true,c=getchar();while('0'<=c&&c<='9') x=10*x+c-'0',c=getchar();if(neg) x=-x;return x;}
inline void out(long long x){if(x<0) putchar('-'),x=-x;if(x>9) out(x/10);putchar(x%10+'0');}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "xxxxxxxxxx"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define _ putchar(' ')
#define __ putchar('\n')
const int N=200010;
int n,f,kq;
int bit[N],h[N],a[N];
void up(int i,int x)
{
    for(;i<=n;i+=i&-i) bit[i]=max(bit[i],x);
}
int get(int i)
{
    int re=0;
    for(;i;i-=i&-i) re=max(re,bit[i]);
    return re;
}
main()
{
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    cin>>n;
    forinc(i,1,n) cin>>h[i];
    forinc(i,1,n) cin>>a[i];
    forinc(i,1,n)
    {
        f=get(h[i])+a[i];
        kq=max(kq,f);
        up(h[i],f);
    }
    cout<<kq;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*--------------------------------------------------------------------*/
signed main(){
  int n;
  cin>>n;
  vi a(n);
  rep(i,n)cin>>a[i];

  int total=0;
  rep(i,n) total^=a[i];

  rep(i,n){
    int ans=total^a[i];
    cout<<ans<<endl;
  }





  return 0;
}


Measured memory_bytes: 4748
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>

using namespace std;

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef pair<ll,ll> pll;

int fds(int x) {
  int ans = 0;
  while(x > 0) {
    ans += x % 10;
    x /= 10;
  }
  return ans;
}
int main() {
  int n;
  int ans = 999999999;
  scanf("%d", &n);
  for(int i = 1; i < n; ++i) {
    int j = n - i;
    int sum = fds(i) + fds(j);
    if(sum < ans) ans = sum;
  }
  printf("%d\n", ans);
  return 0;
}


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

#define INF 1234567890
#define ll long long

int N;
int res[10101];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	for(int x=1; x<=100; x++)
		for(int y=1; y<=100; y++)
			for(int z=1; z<=100; z++)
			{
				int val = x*x+y*y+z*z+x*y+y*z+z*x;
				if (val <= 10000)
					res[val]++;
			}
	for(int i=1; i<=N; i++)
		cout << res[i] << "\n";
	return 0;
}

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

template <typename T>
void print_vector(vector<T>& vec) {
    cout << "print_vector -> ";
    for(int i=0; i<vec.size(); i++) {
        if(i == vec.size()-1) {
            cout << vec[i] << endl;
        }
        else {
            cout << vec[i] << " ";
        }
    }
    return;
}

vector<int> v;

void solve(int n) {
    if(n<=1) return;
    int l = sqrt(n);
    for(int i=2; i<=l; i++) {
        if(n%i==0) {
            solve(i); solve((int)(n/i)); return;
        }
    }
    v.push_back(n); return;
}

int main() {

    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    vector<int> map(1000010, 0);

    for(int i=0; i<N; i++) {
        if(map[A[i]] >= 1) {
            map[A[i]]++;
            continue;
        }
        for(int j=A[i]; j<1000010; j+=A[i]) {
            map[j]++;
        }
    }

    int ans = 0;
    for(int a : A) {
        if(map[a] == 1) ans++;
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
    long long n,m;
    cin >> n >> m;
    vector<long long> a(n),b(m),c(m);
    for(int i = 0;i < n;i ++){
        cin >> a.at(i);
    }
    for(int i = 0;i < m;i ++){
        cin >> b.at(i) >> c.at(i);
    }

    sort (a.begin(),a.end());
    vector<pair<long long,long long>> bc(m);
    for(int i = 0;i < m;i ++){
        bc.at(i) = make_pair(c.at(i),b.at(i));
    }
    sort (bc.begin(),bc.end());

    for(int i = 0;i < m;i ++){
        b.at(i) = bc.at(i).second;
        c.at(i) = bc.at(i).first;
    }

    vector<long long> d(n);
    int x = 0;
    for(int i = m-1;i >= 0;i --){
        for(int j = 0;j < b.at(i);j ++){
            d.at(x) = c.at(i);
            x ++;
            if(x == n){
                break;
            }
        }
        if(x == n){
            break;
        }
    }

    sort (d.begin(),d.end());

    long long ans = 0;

    for(int i = 0;i < n;i ++){
        if(a.at(a.size()-1) > d.at(d.size()-1)){
            ans += a.at(a.size()-1);
            if(a.size() == 1){
                a.at(0) = 0;
            }else{
                a.pop_back();
            }
        }else{
            ans += d.at(d.size()-1);
            if(d.size() == 1){
                d.at(0) = 0;
            }else{
                d.pop_back();
            }

        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4992
#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>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 998244353;
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 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-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;

int main() {
	int n, a, b; cin >> n >> a >> b;
	cout << min(a, b)<<" "<<max(0,a+b-n) << endl;
	//stop
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n;
    for(;;){
        scanf("%d",&n);
        if(n==0) break;
        vector<int> ar(n);
        for(int &x : ar){
            scanf("%d",&x);
        }
        sort(ar.begin(),ar.end());
        int sum=0;
        for(int i=1;i<n-1;i++){
            sum+=ar[i];
        }
        printf("%d\n",sum/(n-2));
    }
}

Measured memory_bytes: 1032
n,C,*H=map(int,open(0).read().split());p=[0];P=[0]
for i in range(1,n):
 h=H[i];f=lambda I:p[P[I]]+H[P[I]]*(H[P[I]]-2*h)
 while len(P)>1and f(0)>f(1):P.pop(0)
 p+=[f(0)+h*h+C];h=0;P+=[i];g=lambda x,y:(f(y)-f(x))/(H[P[x]]-H[P[y]]);
 while len(P)>2and g(-1,-2)>g(-2,-3):P.pop(-2)
print(p[-1])

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define gsort(x) sort((x).begin(), (x).end(), greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define pii pair<int, int>
#define int int64_t
#define re(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

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

   int n, cnt = 0, ans = 0, wa, ac;
   cin >> n;
   vector<int> x(n);

   rep(i, n)
   {
      cin >> x[i];
      cnt += x[i];
   }

   rep(i, n)
   {
      cnt -= x[i];
      ans += x[i];

      wa = min(wa, abs(cnt - ans));
   }

   cout << wa << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define df 0
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;


int main(){
  if(df) printf("*debug mode*\n");
  vector<li> now(10,0),prev(10,0);
  int n; cin >>n; n--;
  prev.at(0)=prev.at(1)=1;
  prev.at(2)=2;

  rep(i,n){
    now.at(0)=prev.at(0)+prev.at(2)+prev.at(4)+prev.at(5)+prev.at(6)+prev.at(8);
    now.at(1)=prev.at(1)+prev.at(2)+prev.at(7)+prev.at(8)+prev.at(9);
    now.at(2)=prev.at(1)*2+prev.at(2)*2+prev.at(4)*2+prev.at(5)*2
      +prev.at(7)+prev.at(8)+prev.at(9);
    now.at(3)=prev.at(0)+prev.at(6);
    now.at(4)=prev.at(0);
    now.at(5)=prev.at(0)+prev.at(6);
    now.at(6)=prev.at(1)+prev.at(3)+prev.at(7)+prev.at(9);
    now.at(7)=prev.at(3);
    now.at(8)=prev.at(3);
    now.at(9)=prev.at(5);
    rep(j,10){now.at(j)%=MOD;}
    prev=now;
    vector<li> re(10);
    now=re;
  }
  li sum=0;
  rep(i,10){
    sum+=prev.at(i);
    if(df)printf("%ld ",prev.at(i));
    sum%=MOD;
  }
  if(df)printf("\n");
  
  printf("%ld",sum);
    
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>

using namespace std;


int main(){
  int n, m, c;
  int ans = 0;
  cin >> n >> m >> c;
  vector<int> b(m);
  vector< vector<int> > a(n, vector<int>(m));

  for(int i = 0; i < m; i++) cin >>b[i];

  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; ++j){
      cin >> a[i][j];
    }
  }

  for(int i = 0; i < n; i++){
    int sum = c;
    for(int j = 0; j < m; j++){
      sum += a[i][j] * b[j];
    }
    if(sum > 0){
      ++ans;
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define frfr  freopen("input.text","r",stdin); freopen("output.text","w",stdout)
#define LL long long int
#define wh int T;cin >> T;while(T--)
#define foro(i,n) for(int i=0;i<n;i++)
#define forn(i,k,n) for(int i=k;i<n;i++)
#define PB push_back
#define mod 1000000007 
#define UMP unordered_map<int,int>

LL solvedp(LL* height , LL n,LL k){
  LL dp[n];
  dp[0] = 0;
  for(int i=1;i<n;i++){
    dp[i] = INT_MAX;
  }
  for(LL  i=0 ; i<n ; i++ ){
    for(LL j=i+1;j<=i+k;j++){
      if(j < n){
        dp[j] = min(dp[j] ,dp[i] + abs(height[j] - height[i]));
       }
      }
    }
  return dp[n-1];
}


int main(){
   // frfr;
    LL n , k;
    cin >> n >> k;
    LL height[n];
    for(int i=0;i<n;i++){
      cin >> height[i];
    }
     cout << solvedp(height,n,k) << endl;
   
   return 0;
}
  


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

int main() {
  int N, K;
  cin >> N >> K;
  
  vector<int> sticks(N, 0);
    
  for (int i = 0; i < N; i++) cin >> sticks.at(i);
  
  sort(sticks.begin(), sticks.end());
  reverse(sticks.begin(), sticks.end());
  
  int length = 0;
  
  for (int i = 0; i < K; i++) length += sticks.at(i);
  
  cout << length << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;

int main() {

	vector<long long int> a;
	vector<long long int> b;

	long long int n;
	cin >> n;
	for (long long int i = 0; i < n; i++) {
		long long int c;
		cin >> c;
		if (i % 2 == 0) {
			a.push_back(c);
		}
		else {
			b.push_back(c);
		}
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	vector<P> a2;
	vector<P> b2;

	P pa, pb;

	for (long long int i = 0; i < n / 2; i++) {
		if (i == 0) {
			pa = P(1, a[i]);
			pb = P(1, b[i]);
		}
		else {
			if (a[i] == a[i - 1]) {
				pa.first++;
			}
			else {
				a2.push_back(pa);
				pa = P(1, a[i]);
			}
			if (b[i] == b[i - 1]) {
				pb.first++;
			}
			else {
				b2.push_back(pb);
				pb = P(1, b[i]);
			}
		}
	}
	a2.push_back(pa);
	b2.push_back(pb);

	sort(a2.begin(), a2.end(), greater<P>());
	sort(b2.begin(), b2.end(), greater<P>());

	if (a2[0].second == b2[0].second) {
		if (a2.size() == 1) {
			if (b2.size() == 1) {
				cout << n / 2 << endl;
			}
			else {
				cout << n - b2[1].first << endl;
			}
		}
		else {
			if (b2.size() == 1) {
				cout << n - a2[1].first << endl;
			}
			else {
				cout << n - max(a2[0].first + b2[1].first, a2[1].first + b2[0].first) << endl;
			}
		}
	}
	else {
		cout << n - a2[0].first - b2[0].first << endl;
	}

	return 0;
}

Measured memory_bytes: 3440
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
struct node{
int a,b,c;
}aa[200005];
int comp(const node t,node tt)
{
if(t.b==tt.b)
return t.c<tt.c;
else
return t.b<tt.b;


}
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d %d",&aa[i].a,&aa[i].b);
aa[i].c=aa[i].b-aa[i].a;
}
sort(aa,aa+n,comp);
int sum=0;
int f=0;
for(int i=0;i<n;i++)
{
sum+=aa[i].a;
//printf("%d %d",sum,aa[i].b);
if(sum>aa[i].b)
{f=1;
break;
}

}
if(f==0)
printf("Yes\n");
else
printf("No\n");
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <string>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

const int Maxn = 1010;
const int INF = (int) 1e9;
char f[Maxn][Maxn];
int d[Maxn][Maxn];

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

typedef pair<int, int> P;

int main() {
    int h, w;
    cin >> h >> w;
    queue<P> que;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> f[i][j];
            if (f[i][j] == '.') d[i][j] = INF;
            else {
                d[i][j] = 0;
                que.emplace(P(i, j));
            }
        }
    }

    while (!que.empty()) {
        P p = que.front();
        que.pop();
        for (int i = 0; i < 4; ++i) {
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if (0 <= nx && nx < h && 0 <= ny && ny < w) {
                if (d[nx][ny] == INF) {
                    d[nx][ny] = d[p.first][p.second] + 1;
                    que.emplace(P(nx, ny));
                }
            }
        }
    }


    int ans = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            ans = max(ans, d[i][j]);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 13456
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        boolean flag = false;
        int cnt = 0;
        for (int i=0; i<n; i++) {
            int s = sc.nextInt();
            int t = sc.nextInt();
            if (s == t) cnt++;
            else cnt = 0;
            if (3 <= cnt) flag = true;
        }

        if (flag) System.out.println("Yes");
        else System.out.println("No");
    }


}



Measured memory_bytes: 36088
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,i,j,k,l,m,n,x,y;
	ll		ans = 0;
	string	s;
	cin >> n >> a >> b;
	ans = min( a*n , b);
	//vector<ll>	aa(n);
	//for(i=0;i<n;i++) cin >> aa[i];
	//vector<ll>	dp(n+1,INFL);
	//vector<vector<ll>>	dp2(x , vector<ll>(y,INFL));

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


Measured memory_bytes: 3600
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;*/

int n, m, X;
int c[15];
int a[15][15];
int lei[15];
const int inf = 1000000000;

int check(int mask)
{
    forn(i, m) lei[i] = 0;
    int cost = 0;
    forn(i, n)
    {
        if(mask&1)
        {
            cost += c[i];
            forn(j, m) lei[j] += a[i][j];
        }
        mask>>=1;
    }
    forn(j, m) if(lei[j]<X) return inf;
    return cost;
}

int main()
{
    cin.tie(0);ios_base::sync_with_stdio(false);
    cin >> n >> m >> X;
    forn(i, n)
    {
        cin >> c[i];
        forn(j, m) cin >> a[i][j];
    }
    int ans = inf;
    forn(mask, (1<<n))
    {
        ans = min(ans, check(mask));
    }
    if(ans == inf) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 3668
u,s,e,w,n,b = list(map(int, input().split()))
rolls = input()

for roll in rolls:
    if roll == 'N':
        n,u,e,w,b,s = u,s,e,w,n,b
    elif roll == 'S':
        s,b,e,w,u,n = u,s,e,w,n,b
    elif roll == 'E':
        e,s,b,u,n,w = u,s,e,w,n,b
    elif roll == 'W':
        w,s,u,b,n,e = u,s,e,w,n,b
    else:
        print('Error')
        raise(-1)

print(u)

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

long long n,k;
long long ans;

int main()
{
	cin >> n >> k;
	for(long long i = k;i<=n+1;i++)
	{
		long long a = i*(i-1)/2;
		long long b = (n+n-i+1)*i/2;
		ans += b-a+1;
		ans %= 1000000007;
	}
	cout << ans;
}

Measured memory_bytes: 3636
#include <iostream>
#include <map>

using namespace std;

int main() {
	int N, a;
	cin >> N;
	bool ok = true;
	map<int, bool> lol;
	for (int i = 1; i <= N; ++i) {
		cin >> a;
		if(lol.find(a)!=lol.end()) ok = false;
		else lol[a] = true;
	}
	if (ok) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	string s;
	cin >> s;
	int a[30] = {} , b[15] = {};
	rep(i,s.size()){
		if('a' <= s[i] && s[i] <= 'z')a[s[i]-'a'] ++;
		else b[s[i]-'0'] ++;
	}
	
	//rep(i,26)printf("%d ",a[i]); cout << endl;
	//rep(i,15)printf("%d ",b[i]); cout << endl;
	
	int ret = 0;
	rep(i,26){
		while(1){
			int k = i;
			while(a[k] > 0)k ++;
			if(k <= i+3)break;
			for(int j = i ; j < k ; j ++){
				a[j] --;
			}
			ret += 3;
		}
	}
	rep(i,10){
		while(1){
			int k = i;
			while(b[k] > 0)k ++;
			if(k <= i+3)break;
			for(int j = i ; j < k ; j ++){
				b[j] --;
			}
			ret += 3;
		}
	}
	
	//rep(i,26)printf("%d ",a[i]); cout << endl;
	//rep(i,15)printf("%d ",b[i]); cout << endl;
	
	rep(i,26)ret += a[i];
	rep(i,10)ret += b[i];
	cout << ret << endl;
}

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

int main() {
  unsigned long long int H, W;
  cin >> H >> W;
  if ((H == 1) || (W == 1)) cout << 1 << endl;
  else if ((H % 2 == 1) && (W % 2 == 1)) cout << (H * W + 1)/2 << endl;
  else cout << H * W /2 << endl;
}


Measured memory_bytes: 256