akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::{min, max};
use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        m: usize,
        xy: [(usize1, usize1); m],
    }

    let mut g = vec![vec![]; n];
    for (x, y) in xy {
        g[x].push(y);
    }

    let mut ans = 0;
    let mut tbl = HashMap::new();
    for i in 0..n {
        ans = max(ans, rec(i, None, &g, &mut tbl));
    }
    println!("{}", ans);
}

fn rec(cur: usize, prev: Option<usize>, g: &Vec<Vec<usize>>, tbl: &mut HashMap<(usize, usize), usize>) -> usize {
    let key = (cur, prev.unwrap_or(g.len()));
    if tbl.get(&key).is_some() {
        return *tbl.get(&key).unwrap();
    }

    let mut ans = 0;
    for &next in g[cur].iter() {
        if Some(next) == prev {
            continue;
        }
        ans = max(ans, rec(next, Some(cur), g, tbl) + 1);
    }

    tbl.insert(key, ans);
    return ans;
}

Measured memory_bytes: 41384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>

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

using namespace std;

int prime[10000001];
int num[1000001];

void CreatePrime()
{
	rep(i,1000001) prime[i] = 1;

	prime[0] = prime[1] = 0;

	REP(i,2,sqrt(1000001)+1)
	{
		for(int j=0;i*(j+2)<1000001;j++)
		{
			prime[i*(j+2)] = 0;
		}
	}
	
	memset(num,0,sizeof(num));
	int cnt = 1;
	REP(i,1,1000001)
	{
		if(prime[i]) 
		{
			num[i] = cnt;	
			cnt++;
		}
		else
		{
			num[i] = num[i-1];
		}
	}
}

int main()
{
	CreatePrime();
	
	int n;
	while(cin >> n && n)
	{
		int ans = -n;

		rep(i,n)
		{
			int p,m;
			cin >> p >> m;

			int s = p-m;
			int e = p+m;

			if(s < 0) s = 0;
			if(e > 1000000) e = 1000000;
			
			int count = num[e] - num[s];
			if(prime[s]) count++;

			if(count < 0) ans--;
			else ans += count;
		}
		
		if(ans < 0) cout << 0 << endl;
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 9352
import sys
# from collections import Counter
input = sys.stdin.readline

h = []
d = []
n, k = map(int, input().split())
for _ in range(n):
        h.append(int(input()))
h=sorted(h)

for i in range(n-k+1):
        d.append(h[k+i-1] - h[i])
print(min(d))


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

vector<ll> divisor(ll n) {
    vector<ll> ret;
    for(ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    ret.push_back(n);
    return (ret);
}


int main(){
    ll n;
    cin >> n;
    if (n == 2){
        cout << 1 << endl;
        return 0;
    }
    ll N[2] = {n, n-1};
    vector<ll> vec = divisor(N[0]);
    vector<ll> vecc = divisor(N[1]);

    ll ans = 0;
    for(auto v : vec){
        ll tmp = n;
        while (tmp % v == 0) tmp /= v;
        if (tmp % v == 1) ans ++;
    }

    cout << ans + vecc.size() << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>

int main(){
  int N, M;
  std::cin >> N >> M;
  std::vector<long int> A(N), B(M), C(M);
  for(int i=0; i<N; ++i) std::cin >> A[i];
  for(int i=0; i<M; ++i) std::cin >> B[i] >> C[i];
  std::vector<std::pair<long int, long int> > vec(N+M);
  for(int i=0; i<N; ++i){  
    vec[i].first = A[i]; vec[i].second = 1;
  }
  for(int i=0; i<M; ++i){
    vec[N+i].first = C[i]; vec[N+i].second = B[i];
  } 
  typedef std::pair<long int, long int> P;
  sort(vec.begin(), vec.end(), [](const P &p1, const P &p2) {
        if(p1.first > p2.first) return true;
        if(p1.first == p2.first) return p1.second > p2.second;
        return false;});
/*  for(int i=0; i<M; ++i) {
    for(int j=0; j<B[i]; j++){
      A.push_back(C[i]);
    }
  }*/
//  std::sort(A.begin(), A.end(), std::greater<int>() );
  long int ans=0;
  int i=0, count=0;
  while(count<N) {
    if(count+vec[i].second < N){
      ans += vec[i].first*vec[i].second;
      count+=vec[i].second;
    }
    else{
      ans += vec[i].first*(N-count);
      count+=vec[i].second;
    }
    i++;
  }
  std::cout << ans << std::endl;
  return 0;
}

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

using namespace std;

int main() {
  int N, W;
  cin >> N;
  cin >> W;
  
  vector <int> wei(N), val(N);
  for (int i = 0; i < N; ++i) {
    cin >> wei[i];
    cin >> val[i];
  }
  
  vector <vector <long> > dp(N, vector <long> (W + 1, 0));
  dp[0][wei[0]] = val[0];
  for (int n = 1; n < N; ++n) {
    for (int w = 0; w <= W; ++w) {
      if (w - wei[n] >= 0) {
        dp[n][w] = max(dp[n - 1][w - wei[n]] + val[n], 
                       dp[n - 1][w]);
      } else {
        dp[n][w] = dp[n - 1][w];
      }
    }
  }
  
  vector <long> cand = *dp.rbegin();
  sort(cand.begin(), cand.end());
  cout << *cand.rbegin() << endl;
  return 0;
}

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

double A, B;

int tmp() {
    for (int i = 1; i <= 2000; i++) {
        if (floor((double)i * 0.08) == A && floor((double)i * 0.1) == B) {
            return i;
        }
    }
    return -1;
}

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

    int ans = tmp();

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int dens[10][10];
void sink(int x, int y) {
  if (0 <= x && x < 10 && 0 <= y && y < 10) {
    dens[y][x]++;
  }
}

int main() {
  string line;
  while (getline(cin, line)) {
    int x, y, size;
    sscanf(line.c_str(), "%d,%d,%d", &x, &y, &size);
    if (size == 1) {
      sink(x+0,y+0);
      sink(x+1,y+0);
      sink(x-1,y+0);
      sink(x+0,y+1);
      sink(x+0,y-1);
    } else if (size == 2) {
      sink(x+0,y+0);
      sink(x+1,y+0);
      sink(x-1,y+0);
      sink(x+0,y+1);
      sink(x+0,y-1);
      sink(x+1,y+1);
      sink(x-1,y+1);
      sink(x+1,y-1);
      sink(x-1,y-1);
    } else if (size == 3) {
      sink(x+0,y+0);
      sink(x+1,y+0);
      sink(x-1,y+0);
      sink(x+0,y+1);
      sink(x+0,y-1);
      sink(x+1,y+1);
      sink(x-1,y+1);
      sink(x+1,y-1);
      sink(x-1,y-1);
      sink(x+2,y+0);
      sink(x-2,y+0);
      sink(x+0,y+2);
      sink(x+0,y-2);
    }
  }
  int m = 0;
  int count = 0;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      if (dens[i][j] == 0) count++;
      m = max(m, dens[i][j]);
    }
  }
  cout << count << endl;
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

#define REP(i,m,M) for(int i=m; i<M; i++)
#define REPR(i,M,m) for(int i=M; i>m; i—-)
#define REPLL(i,m,M) for(ll i=m; i<M; i++)
#define REPLLR(i,M,m) for(ll i=M; i>m; i—-)
#define ALL(v) v.begin(),v.end()

ll factTable[1000001];
ll factInvTable[1000001];
ll fact(int n){
    if(factTable[n]!=0) return factTable[n];
    else if (n>1) {
        return factTable[n] = (n * fact(n-1))%MOD;
    } else
        return 1;
}
ll pow(ll n, int k){
    if (k==0) return 1;
    if (k==1) return n % MOD;
    if (k%2==0) {
        ll tmp = pow(n, k/2);
        return tmp*tmp%MOD;
    } else {
        ll tmp = pow(n, k/2);
        return (tmp*tmp%MOD)*n%MOD;
    }
}
ll invFact(int n){
    if(factInvTable[n]!=0) return factInvTable[n];
    else return pow(fact(n), MOD-2);
}
ll comb(int n, int m){
    return (fact(n)*invFact(m)%MOD)*invFact(n-m)%MOD;
}
ll num(int N, int K){
    return (fact(K)*fact(N-K-1)%MOD)*comb(K-1, N-K-1)%MOD;
}

int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    
    ll res = 0;
    for(int i=(N+1)/2; i<=N-1; ++i){
        res += num(N, i);
        res %= MOD;
        //cout << res << endl;
    }
    cout << (fact(N)+MOD-res)%MOD << endl;

    return 0;
}


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

int main() {
    int H,W;
    cin >> H >>W;
    vector<vector<int>> a(H);
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            int b;
            cin >> b;
            a[i].push_back(b);
        }
    }
    vector<tuple<int,int,int,int>> ans;
    for(int i=0;i<H;i++){
        for(int j=0;j<W-1;j++){
            if(a[i][j] %2 == 1){
                ans.emplace_back(i+1,j+1,i+1,j+2);
                a[i][j+1]++;
            }
        }
    }
    for(int i=0;i<H-1;i++){
        if(a[i][W-1] %2==1){
            ans.emplace_back(i+1,W,i+2,W);
            a[i+1][W-1]++;
        }
    }
    cout << ans.size() << endl;
    for(int i=0;i<ans.size();i++){
        cout << get<0>(ans[i]) << " "<<get<1>(ans[i]) <<" "<<get<2>(ans[i])<<" "<<get<3>(ans[i])<<endl;
    }

    return 0;
}

Measured memory_bytes: 5232
/*
* * * * * * * * * * * * * * * * * * *
*       Author : Ganzaki            *
*                                   *
*       language : c++              *
*                                   *
* * * * * * * * * * * * * * * * * * *
*/
#include <bits/stdc++.h>


#define FOR(i,j,k) for(ll i=j;i<k;i++)
#define FOR1(i,j,k) for(ll i=j;i<=k;i++)
#define FOR2(i,j,k) for(ll i=j;i>=k;i--)
#define FILL(a,i) memset(a,i,sizeof(a))
#define db(i) printf("lol %d \n",i)
#define el '\n'
#define dbg(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
#define MOD 1000000007


using namespace std;


typedef long long ll;
typedef unsigned long ul;
typedef std::string str;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef std::vector<str> vs;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::vector<char> vc;
typedef map<int,int> mii;
typedef map<string,int> msi;
void desperate_optimization(int precision){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(precision);
}




void solve()
{
    str s;
    cin>>s;
    bool a = true;
    FOR(i,0,s.length())
    {
        if(i%2)
        {
            if(s[i]=='R')
            {
                a=false;
                break;
            }
        }
        else
        {
            if(s[i]=='L')
            {
                a=false;
                break;
            }
        }
    }
    if(a)
    {
        cout<<"Yes"<<el;
    }
    else
    {
        cout<<"No"<<el;
    }
}




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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2")

int a, b;

inline long long read()
{
	long long ret = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9') ch = getchar();
	while (ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getchar();
	return ret;
}

int main()
{
	ios::sync_with_stdio(false);
    a = read();
    b = read();
    cout << a * b << endl;
	return 0;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
using namespace std;
 
const int N=500010;
struct edge{int s,t,n;}e[2*N];
int n,k,tot,p[N],q[N],h[N],d[N];
set <int> S;
set <int> ::iterator It;
 
void work()
{
	scanf("%d %d",&n,&k);
	for (int i=1; i<=n; i++)  scanf("%d",&p[i]),q[p[i]]=i;
	for (int i=1; i<=n; i++)
		{
			if (i>k)  S.erase(p[i-k]);
			It=S.insert(p[i]).first;
			if ((++It)!=S.end())
				e[++tot]=(edge){i,q[*It],h[i]},h[i]=tot,d[q[*It]]++;
		}
	S.clear();
	for (int i=n; i; i--)
		{
			if (i+k<=n)  S.erase(p[i+k]);
			It=S.insert(p[i]).first;
			if ((++It)!=S.end())
				e[++tot]=(edge){i,q[*It],h[i]},h[i]=tot,d[q[*It]]++;
		}
	S.clear();
	for (int i=1; i<=n; i++)  if (!d[i])  S.insert(i);
	for (int i=1; i<=n; i++)
		{
			It=S.begin(),S.erase(It),p[*It]=i;
			for (int j=h[*It]; j; j=e[j].n)
				if (!(--d[e[j].t]))
					S.insert(e[j].t);
		}
	for (int i=1; i<=n; i++)  printf("%d\n",p[i]);
}
 
int main()
{
	work();
	return 0;
}

Measured memory_bytes: 46464
def f(x):
  A = []
  for i,e in enumerate(x): A += [i]*e
  return A

A = f([61]+[20]*5)
B = f([3]*2+[5]*4)
C = range(600,1800,200)

while 1:
  n = input()
  if n==0: break
  s = 0
  for _ in [0]*n:
    x, y, h, w = map(int, raw_input().split())
    size = x + y + h
    if size <161 and w < 26:
      s += C[max(A[size], B[w])]
  print s

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

signed main(void)
{
	string s;
	int n;
	bool ok;

	cin >> s;
	n = s.size();
	if (n % 2 != 0) n--;
	while (n >= 0)
	{
		n -= 2;
		ok = true;
		for (int j = 0; j < n / 2; j++)
		{
			if (s[j] != s[n / 2 + j])
				ok = false;
		}
		if (ok)
			break;
	}
	cout << n << endl;
	return 0;
}


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

using namespace std;
int a,b,c;
int n= 0;


void solve(){

    return;
}

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

    for(int i=a; i <=b;i++){
        if(!(c%i)){
            n++;
        }
    }
    cout << n << endl;

    return 0;
}


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

using namespace std;

using ull = unsigned long long;

std::vector<ull> xxx;

void Conbination(std::vector<int> v, std::vector<bool> b, ull count, int ss, int now){
	if (ss == 3) {
		if (count > 0) {
			xxx.push_back(count);
		}
	}

	b[now] = false;
	count *= v[now];
	ss++;

	for (size_t i = 0; i < b.size(); i++) {
		if (b[i]) {
			Conbination(v,b,count,ss,i);
		}
	}
}


int main(int argc, char const *argv[]) {
	int n;
	std::cin >> n;
	std::vector<string> s(n);
	std::vector<int> v(5,0);
	string march = "MARCH";
	for (size_t i = 0; i < n; i++) {
		std::cin >> s[i];
		for (size_t j = 0; j < march.size(); j++) {
			if (s[i][0] == march[j]) {
				v[j]++;
			}
		}
	}

	for (size_t i = 0; i < v.size(); i++) {
		Conbination(v,std::vector<bool> (5,true), 1, 0, i);
	}

	ull count = 0;
	for (size_t i = 0; i < xxx.size(); i++) {
		count += xxx[i];
	}


	std::cout << count / 12 << '\n';

	return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main()
{
    int n, m, a, b;
    cin >> n >> m;
    bool c[200004] = {}, d[200004] = {};
    rep(i, m)
    {

        cin >> a >> b;
        if (max(a, b) == n) {
            c[min(a, b)] = true;
        } else if (min(a, b) == 1) {
            d[max(a, b)] = true;
        }
    }
    for (int i = 2; i < n; i++) {
        if (c[i] and d[i]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void){
  int team[100]={0}; 
  int res[100]={0};
  int mach[4], n, i, j, a;

  scanf("%d", &n);

  for(i = 0; i < n*(n-1)/2; i++){
    for(j = 0; j < 4; j++){
      scanf("%d", &mach[j]);
    }

    if(mach[2] == mach[3]){
      team[mach[0]-1]++;
      team[mach[1]-1]++;
    }
    else if(mach[2] > mach[3])
      team[mach[0]-1] += 3;
    else
      team[mach[1]-1] += 3;
  }

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      if(team[i] < team[j])
	res[i]++;
    }
    printf("%d\n", res[i] + 1);
  }

  return 0;
}

Measured memory_bytes: 600
from heapq import heappush, heappop

INF = 10 ** 20
n = int(input())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b, c = map(int, input().split())
    a, b = a - 1, b - 1
    edges[a].append((b, c))
    edges[b].append((a, c))

q, k = map(int, input().split())
k -= 1
dist = [INF] * n
dist[k] = 0
que = []
heappush(que, (0, k))
while que:
    score, node = heappop(que)
    for to, cost in edges[node]:
        newScore = score + cost
        if dist[to] > newScore:
            dist[to] = newScore
            heappush(que, (newScore, to))

for _ in range(q):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    print(dist[x] + dist[y])

Measured memory_bytes: 47792
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<cmath>
#include<functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void sort(int &a,int &b)
{
	if(a>b)
		swap(a,b);
}
void open(const char *s)
{
#ifndef ONLINE_JUDGE
	char str[100];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
	sprintf(str,"%s.out",s);
	freopen(str,"w",stdout);
#endif
}
int rd()
{
	int s=0,c;
	while((c=getchar())<'0'||c>'9');
	do
	{
		s=s*10+c-'0';
	}
	while((c=getchar())>='0'&&c<='9');
	return s;
}
int upmin(int &a,int b)
{
	if(b<a)
	{
		a=b;
		return 1;
	}
	return 0;
}
int upmax(int &a,int b)
{
	if(b>a)
	{
		a=b;
		return 1;
	}
	return 0;
}
const ll p=998244353;
ll inv[1000010];
ll fac[1000010];
ll ifac[1000010];
ll getc(int x,int y)
{
	return fac[x]*ifac[y]%p*ifac[x-y]%p;
}
ll getic(int x,int y)
{
	return ifac[x]*fac[y]%p*fac[x-y]%p;
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	if(n<m)
		swap(n,m);
	inv[0]=inv[1]=fac[0]=fac[1]=ifac[0]=ifac[1]=1;
	int i;
	for(i=2;i<=n+m;i++)
	{
		inv[i]=-p/i*inv[p%i]%p;
		fac[i]=fac[i-1]*i%p;
		ifac[i]=ifac[i-1]*inv[i]%p;
	}
	ll ans=n;
	for(i=1;i<=m;i++)
		ans=(ans+getc(2*i,i)*getc(n+m-2*i,n-i)%p*inv[2]%p*getic(n+m,n))%p;
	ans=(ans+p)%p;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 23552
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
using namespace std;
string s;
int main()
{
	cin>>s;
	for(int i=0;i<=s.size();i++)
	{
		if(s[i]=='C')
		{
			for(int j=i;j<=s.size();j++)
			{
				if(s[j]=='F')
				{
					printf("Yes\n");
					return 0;
				} 
			}
		}
	}
	printf("No\n");
	return 0;
} 

Measured memory_bytes: 256
def readinput():
    n=int(input())
    v=list(map(int,input().split()))
    return n,v

def main(n,v):

    hist=[0]*(10**5+1)
    maxhist=0
    maxvalue=0
    for i in range(n):
        hist[v[i]]+=1
        if (maxhist<hist[v[i]]):
            maxhist=hist[v[i]]
            maxvalue=v[i]
    print('maxvalue: {}, maxhist: {}'.format(maxvalue, maxhist))

    secondhist=0
    for i in range(1,10**5+1):
        if i == maxvalue:
            continue
        secondhist=max(secondhist,hist[i])
    print('secondhist: {}'.format(secondhist))

    nsame=n//2
    nchange=0
    if maxhist>nsame:
        nchange+=maxhist-nsame
    elif maxhist<nsame:
        nchange+=nsame-maxhist
    nchange+=nsame-secondhist
    return nchange

def main2(n,v):
    eList=[]
    oList=[]
    for i in range(n):
        if i%2==0:
            eList.append(v[i])
        else:
            oList.append(v[i])

    #print(eList)
    #print(oList)

    ehist=[0]*(10**5+1)
    for i in eList:
        ehist[i]+=1
    emaxh=0
    emaxv=0
    for i in range(1,10**5+1):
        if emaxh<ehist[i]:
            emaxh=ehist[i]
            emaxv=i
    esech=0
    esecv=0
    for i in range(1,10**5+1):
        if i==emaxv:
            continue
        if esech<ehist[i]:
            esech=ehist[i]
            esecv=i
    
    ohist=[0]*(10**5+1)
    for i in oList:
        ohist[i]+=1
    omaxh=0
    omaxv=0
    for i in range(1,10**5+1):
        if omaxh<ohist[i]:
            omaxh=ohist[i]
            omaxv=i
    osech=0
    osecv=0
    for i in range(1,10**5+1):
        if i == omaxv:
            continue
        if osech<ohist[i]:
            osech=ohist[i]
            osecv=i

    if omaxv==emaxv:
        if omaxh==emaxh:
            if osech>esech:
                omaxv=osecv
            else:
                emaxv=esecv
        elif omaxh>emaxh:
            emaxv=esecv
        else:
            omaxv=osecv
    
    #print('emaxv: {}, omaxv: {}'.format(emaxv,omaxv))

    nchange=0
    for i in range(n//2):
        if eList[i]!=emaxv:
            nchange+=1
        if oList[i]!=omaxv:
            nchange+=1
    return nchange


if __name__=='__main__':
    n,v=readinput()
    ans=main2(n,v)
    print(ans)


Measured memory_bytes: 20544
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<int> A(N);
    rep(i,N)cin >> A[i];
    sort(all(A));
    bool ok = true;
    rep(i,N-1)if(A[i] == A[i+1])ok = false;
    if(ok)cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int cnt[100];
int n;

int main(){
  scanf("%d",&n);
  FOR(i,1,n+1){
    int t = i;
    for(int x=2;x*x<=t;x++){
      while(t%x==0){
        t/=x;
        cnt[x]++;
      }
    }
    if(t>1)cnt[t]++;
  }
  int ans = 0;
  REP(i,100)REP(j,i)REP(k,j){
    if(cnt[i]>=4 && cnt[j]>=4 && cnt[k]>=2)ans++;
    if(cnt[i]>=4 && cnt[j]>=2 && cnt[k]>=4)ans++;
    if(cnt[i]>=2 && cnt[j]>=4 && cnt[k]>=4)ans++;
  }
  REP(i,100)REP(j,i){
    if(cnt[i]>=24 && cnt[j]>=2)ans++;
    if(cnt[i]>=2 && cnt[j]>=24)ans++;
    if(cnt[i]>=4 && cnt[j]>=14)ans++;
    if(cnt[i]>=14 && cnt[j]>=4)ans++;
  }
  REP(i,100){
    if(cnt[i]>=74)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
// AtCoder Beginner Contest 151
// F - Enclose All
// https://atcoder.jp/contests/abc151/tasks/abc151_f
// 最小包含円
#include <bits/stdc++.h>
using namespace std;
struct _I { _I() {cin.tie(0);ios::sync_with_stdio(false);}} __I;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ cin >> p.first >> p.second; return s;}
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

int main()
{
    int D, G; cin >> D >> G;
    vi p(D), c(D); rep(i, D) cin >> p[i] >> c[i];

    int ans = INT_MAX;

    for (int b = 0; b < (1<<D); b++) {
        int n = 0;
        int score = 0;
        for (int i = 0; i < D; i++) {
            if (b & (1<<i)) {
                score += (i+1)*100 * p[i] + c[i];
                n += p[i];
                // cout<<(i+1)*100<<"点問題" <<p[i]<< "問 全完"<<endl;
                // D2(score, n);
            }
        }
        for (int i = D-1; i >= 0 && score < G; i--) {
            if (!(b & (1<<i))) {
                int d = G - score;
                int m = min(p[i]-1, (d+(i+1)*100-1) / ((i+1)*100));
                score += m * (i+1)*100;
                n += m;
                // cout<<(i+1)*100<<"点問題" <<m<< "問 完"<<endl;
                // D2(score, n);
            }            
        }
        if (score >= G)
            ans = min(ans, n);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

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

def main():
    A, B = map(int, input().split())
    print(A + B if B % A == 0 else B - A)

main()


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

static const int MAX = 100;
static const long long INFTY = (1LL << 32);

int n;
long long d[MAX][MAX];

void floyd() {
    for(int k = 0; k < n; k++) {
        for(int i = 0; i < n; i++) {
            if(d[i][k] == INFTY) continue;
            for(int j = 0; j < n; j++) {
                if(d[k][j] == INFTY) continue;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {
    int e, u, v, c;
    cin >> n >> e;
    
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            d[i][j] = ((i == j) ? 0 : INFTY);
        }
    }
    
    for(int i = 0; i < e; i++) {
        cin >> u >> v >> c;
        d[u][v] = c;
    }
    
    floyd();
    
    bool negative = false;
    for(int i = 0; i < n; i++) {
        if(d[i][i] < 0) {
            negative = true;
        }
    }
    
    if(negative) {
        cout << "NEGATIVE CYCLE" << endl;
    }else {
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                if(j) cout << " ";
                if(d[i][j] == INFTY) cout << "INF";
                else cout << d[i][j];
            }
            cout << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3180
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <iostream>
using namespace std;
int main ()
{
	int n,d,x;
	scanf("%i%i%i",&n,&d,&x);
	int a[n+10],r=x,u=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%i",&a[i]);
		r++;
		for(int j=1;j<=d;j=a[i]*u+1)
		{
			if(a[i]*u+1<=d)
			{
				r++;
				u++;
			}
		}
		u=1;
	}
	printf("%i",r);
	return 0;
}


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

void addToSeven(vector<int>& data, vector<char>& op, int sum, int target) 
{
    if (op.at(target) == '+') {
        sum += data.at(target + 1);
    }
    else if (op.at(target) == '-') {
        sum -= data.at(target + 1);
    }

    if (target >= 2) {
        if (sum == 7) {
            cout << data.at(0) << op.at(0) 
                 << data.at(1) << op.at(1) 
                 << data.at(2) << op.at(2)
                 << data.at(3) << "=7"
            << endl;
            exit(0);
        }
    }
    else {
        op.at(target + 1) = '+';
        addToSeven(data, op, sum, target + 1);

        op.at(target + 1) = '-';
        addToSeven(data, op, sum, target + 1);
    }
}

int main() {
    string text;
    cin >> text;
    vector<int> data(4);

    for (uint i = 0; i < 4; ++i) {
        data.at(i) = (int)(text.at(i) - '0');
    }

    int sum = data.at(0);
    vector<char> op(4, '*');
    op.at(0) = '+';
    addToSeven(data, op, sum, 0);

    sum = data.at(0);
    op.at(0) = '-';
    addToSeven(data, op, sum, 0);
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int mod = 1e9 + 7;
int main(){
  int n,k;
  cin >> n >> k;
  long long answer = 0;
  for(int i = k;i <= (n + 1); ++i){
    long long mini = ((long long)i*(i - 1))/2;
    mini %= mod;
    long long maxi = (long long)n*(n + 1)/2 - (long long)(n - i)*(n - i + 1)/2;
    maxi %= mod;
    // cout << mini << ' ' << maxi << '\n';
    answer += (maxi - mini + 1);
    answer %= mod;
    if(answer < mod) answer = (answer + mod)%mod;
  }
  cout << answer;
}

Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int INF = 1e9 + 2;

int stoii(string s){
    int res = 0;
    bool m = 0;
    REP(i,s.length()){
        if (s[i] == '-') m = 1;
        else res = 10*res + s[i]-'0';
    }
    if (m) res *= -1;
    return res;
}

int main() {
    int n;
    while (cin >> n && n){
        VI a(n+2), c(n+2);
        FOR(i,1,n){
            string s;
            cin >> s;
            if (s == "x") {
                c[i] = 1;
                if (i % 2 == 1)
                    a[i] = -INF;
                else
                    a[i] = INF;
            }
            else a[i] = stoii(s);
        }
        a[0] = INF;
        if (n % 2 == 1) a[n+1] = INF;
        else a[n+1] = -INF;
        bool d = 0;
        FOR(i,1,n-1) if (c[i] & c[i+1]) d = 1;
        FOR(i,1,n){
            if (i % 2 == 1 && (a[i] >= a[i-1] || a[i] >= a[i+1])) d = 1;
            if (i % 2 == 0 && (a[i] <= a[i-1] || a[i] <= a[i+1])) d = 1;
        }
        if (d) {
            cout << "none" << endl;
            continue;
        }

        int mi = -INF, ma = INF;
        FOR(i,1,n){
            if (c[i] && i % 2 == 1)
                ma = min({ma, a[i-1]-1, a[i+1]-1});
            else if (c[i] && i % 2 == 0)
                mi = max({mi, a[i-1]+1, a[i+1]+1});
        }

        if (mi == ma) cout << mi << endl;
        else if (mi < ma) cout << "ambiguous" << endl;
        else cout << "none" << endl;
    }
    return 0;
}

Measured memory_bytes: 3000
#include<stdio.h>

int judging(int*,int*);

int main(void)
{
	int i,j,k,n,count;
	int pips[100][6],A[6],B[6];

	scanf("%d",&n);
	for(i = 0;i < n;i++){
		for(j = 0;j < 6;j++){
			scanf("%d",&pips[i][j]);
		}
	}
	count = 0;
	for(i = 0;i < n;i++){
		for(j =(i + 1);j < n;j++){
			for(k = 0;k < 6;k++){
				A[k] = pips[i][k];
			}
			for(k = 0;k < 6;k++){
				B[k] = pips[j][k];
			}
			count += judging(A,B);
		}
	}
	if(count > 0){
		printf("No\n");
	}else{
		printf("Yes\n");
	}
	return 0;
}

int judging(int *a,int *b)
{
	int dice[7][7] = {
		{10,2,4,1,3,10,10}
		,{3,10,0,5,10,2,10}
		,{1,5,10,10,0,4,10}
		,{4,0,10,10,5,1,10}
		,{2,10,5,0,10,3,10}
		,{10,3,1,4,2,10,10}
		,{10,10,10,10,10,10,10}
	};
	int i,j,c,top,front,right,judge;

	top = 6;
	front = 6;
	c = 0;
	for(i = 0;i < 6;i++){
		if(a[i] == b[i])c++;
	}
	for(i = 0;i < 6;i++){
		if(c >= 2){
			if(a[i] == b[0] && a[5 - i] == b[5]){
				if(a[0] == b[i] && a[5] == b[5 - i])top = i;
			}
		}
		else if(a[i] == b[0] && a[5 - i] == b[5])top = i;
	}
	for(i = 0;i < 6;i++){
		if(c >= 2){
			if(a[i] == b[1] && a[5 - i] == b[4]){
				if(a[1] == b[i] && a[4] == b[5 - i])front = i;
			}
		}
		else if(a[i] == b[1] && a[5 - i] == b[4])front = i;
	}
	right = dice[top][front];
	judge = 0;
	if(right != 10){
		j = 0;
		if(a[right] == b[2])j++;
		if(a[5 - right] == b[3])j++;
		if(a[5 - front] == b[4])j++;
		if(a[5 - top] == b[5])j++;
	}
	if(j == 4)judge = 1;
	else judge = 0;
	return judge;
}

Measured memory_bytes: 580
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

n,p = [int(i) for i in input().split()]
l = prime_factors(p)
l = [str(i) for i in l]
s = list(set(l))
a = 1
b = 0
for i in range(len(s)):
    b = l.count(s[i]) // n
    if b > 0:
        a *= int(s[i])**b
print(a)


Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>

FILE *fin, *fout;
void init()
{
#undef DEBUG
#ifdef DEBUG
    fin = fopen("input.txt","r");
    fout = fopen("output.txt","w");
#else
    fin = stdin;
    fout = stdout;
#endif
}


int total;  //total necessary money
int shushi[12*2]; //m[mod 0] n[mod 1]
int month;  //how long it takes
void input(void)
{
    int i;    
    fscanf(fin,"%d",&total);
    //if total is 0, that is the end of all data 
    if( total==0 ){ exit(0); }
    for(i=0;i<12;i++){
        fscanf(fin,"%d %d",&(shushi[i*2+0]), &(shushi[i*2+1]));
    }
}

void calc(void)
{
    int sum = 0; //sum of money 
    int i;    
    month=-1; // if month <0 , it cant save money
    for(i=0;i<12;i++){
        sum += shushi[i*2+0] - shushi[i*2+1];
        if(sum>=total){
            month=i+1; //current month is 'i+1'
            break;
        }
    }
}
        

void output(void)
{
    if(month<0){
        fprintf(fout, "NA\n");
    }
    else{
        fprintf(fout, "%d\n", month);
    }
}

int main(void)
{
    init();
    while(1){
        input();
        calc();
        output();
    }
    return 0;
}

Measured memory_bytes: 0
from math import pi
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

r = float(input())

l = 2 * r * pi
s = r ** 2 * pi
t = Decimal(str(l)).quantize(Decimal('0.000001'), rounding=ROUND_HALF_UP)
u = Decimal(str(s)).quantize(Decimal('0.000001'), rounding=ROUND_HALF_UP)
print(str(u) + " " + str(t))


Measured memory_bytes: 6432
import java.sql.SQLOutput;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        boolean judge = false;
        String s = scan.nextLine();
        int len = s.length();
        s += s;
        String p = scan.nextLine();
        for (int i = 0; i < len; i++) {
            if (s.substring(i, i + p.length()).equals(p)) judge = true;
        }
        if (judge) System.out.println("Yes");
        else System.out.println("No");
    }
}



Measured memory_bytes: 26340
import math
N=int(input())
K=int(math.sqrt(N/6))+1
L=int(math.sqrt(N/3))+1
M=int(math.sqrt(N))+1


ls=[0 for i in range(M**3+1)]

def f(x,y,z):
  return x**2+y**2+z**2+x*y+y*z+z*x

for i in range(1,K):
  ls[f(i,i,i)]+=1

for i in range(1,K):
  for j in range(i+1,M):
    ls[f(i,i,j)]+=3
    ls[f(i,j,j)]+=3
    
for i in range(1,K):
  for j in range(i+1,L):
    for k in range(j+1,M):
      ls[f(i,j,k)]+=6
      
for i in range(1,N+1):
  print(ls[i])
      

      

Measured memory_bytes: 17400
#include<bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    int A,B,M;cin>>A>>B>>M;
    VI a(A),b(B);
    int ma=INF,mb=INF;
    REP(i,A){
        cin>>a[i];
        ma=min(ma,a[i]);
    }
    REP(i,B){
        cin>>b[i];
        mb=min(mb,b[i]);
    }
    int ans=ma+mb;
    REP(i,M){
        int x,y,c;cin>>x>>y>>c;
        x--,y--;
        ans=min(ans,a[x]+b[y]-c);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  int n;
  cin >> n;
  vi t(n+1); vi x(n+1); vi y(n+1);
  t[0] = 0;
  x[0] = 0;
  y[0] = 0;
  rep(i,n) cin >> t[i+1] >> x[i+1] >> y[i+1];
  bool ok = true;
  rep(i,n) {
    int d = abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    int time = t[i+1]-t[i];
    if(d%2 != time%2) ok = false;
    if(d>time) ok = false;
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 1408
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
  [n, m] <- readInts
  ass <- sortOn last <$> replicateM m readInts
  print $ solve 0 ass

readInts :: IO [Int]
readInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

solve :: Int -> [[Int]] -> Int
solve _ [] = 0
solve p ([a, b]:ass)
  | a >= p
    = succ $ solve b ass
  | a < p
    = solve p ass


Measured memory_bytes: 57724
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int Max = 110000;
int N, M;
ll A[Max], C[Max];
int B[Max];
pair<ll, int> cbs[Max];

int bindex_1 = 0;
int bindex_2 = 0;

ll get_next_b() {
    auto& cb = cbs[bindex_1];
    ll ret = cb.first;
    if (++bindex_2 >= cb.second) {
        bindex_2 = 0;
        bindex_1--;
    }
    return ret;
}

int main(int argc, const char * argv[]) {
    cin >> N >> M;
    inputArray(A, N);
    rep(i, M){
        cin >> B[i] >> C[i];
        cbs[i] = make_pair(C[i], B[i]);
    }
    sort(A, A+N);
    sort(cbs, cbs+M);
    bindex_1 = M-1;

    ll suma = 0;
    rep(i, N) {
        suma += A[i];
    }

    ll sumb = 0;
    ll maxs = suma;
    rep(offset, N) {
        if (bindex_1 < 0) break;
        sumb += get_next_b();
        suma -= A[offset];
        // printf("%lld, %lld, \n", sumb, suma);
        chmax(maxs, sumb+suma);
    }
    
    output(maxs);

    return 0;
}

Measured memory_bytes: 3712
// https://atcoder.jp/contests/dp/tasks/dp_b
#include <bits/stdc++.h>
#define ll long long int
#define pr pair<ll, ll>
#define tp tuple<ll, ll, ll>
#define infinity (ll)4e18
using namespace std;
long long int mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n, k;
    cin >> n >> k;
    ll h[n];
    for (ll i = 0; i < n; i++)
        cin >> h[i];
    ll dp[n];
    fill(dp, dp + n, infinity);
    dp[0] = 0;
    for (ll i = 1; i < n; i++)
        for (ll j = i - 1; j >= max(i - k, (ll)0); j--)
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
    cout << dp[n - 1] << endl;
    return 0;
}

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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


signed main(){
    i64 n, a, b;
    cin >> n >> a >> b;
    if(a + b - 1 > n || a * b < n){
        cout << -1 << endl;
        return 0;
    }
    vector<i64> v;
    for(int i = 0; i < a; ++i)
        v.emplace_back(i);
    for(int i = 1; i < b; ++i)
        v.emplace_back(-1L * i * a);
    if(v.size() == n){
        auto w = v;
        sort(w.begin(), w.end());
        for(int k = 0; k < n; ++k){
            cout << distance(w.begin(), lower_bound(w.begin(), w.end(), v[k])) + 1 << " \n"[k == n - 1];
        }
        return 0;
    }
    for(int i = 1; i < b; ++i){
        for(int j = 1; j < a; ++j){
            v.emplace_back(-1L * i * a + j);
            if(v.size() == n){
                auto w = v;
                sort(w.begin(), w.end());
                for(int k = 0; k < n; ++k){
                    cout << distance(w.begin(), lower_bound(w.begin(), w.end(), v[k])) + 1 << " \n"[k == n - 1];
                }
                return 0;
            }
        }
    }
}


Measured memory_bytes: 8684
#include <iostream>
#include <complex>
 
using namespace std;
 int main(void){
 complex <double> p1,p2;
 cin >> p1.real() >> p1.imag() >> p2.real() >> p2.imag();
 double r = abs(p2-p1);
 cout << fixed<< r << endl;
 return 0;
}

Measured memory_bytes: 1296
#include <iostream>
using namespace std;
int main( void )
{
	while ( 1 )
	{
		int d;
		cin >> d;
		if ( cin.eof() )
			break;

		int sum = 0;
		for ( int i = d; i < 600; i += d )
		{
			sum += (i*i*d);
		}

		cout << sum << endl;

	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define M 1000005
#define P 998244353
#define LL long long
using namespace std; 
struct node{
	int x,y;
}s[M];
bool cmpx(node A,node B){
	return A.x<B.x;
}
bool cmpy(node A,node B){
	return A.y<B.y;
}
int F2[M];
void Add(LL &x,int y){
	x+=y;
	if(x<0)x+=P;
	if(x>=P)x-=P;
}
int X[M],Y[M],n;
struct BIT{
	int C[M];
	void clear(){
		for(int i=1;i<=n;i++)C[i]=0;
	}
	void Add(int x){
		while(x<=n){
			C[x]++;
			x+=x&-x;
		}
	}
	int Query(int x){
		int res=0;
		while(x>0){
			res+=C[x];
			x-=x&-x;
		}
		return res;
	}
}bit;
int main(){ 
	cin>>n;
	F2[0]=1;
	for(int i=1;i<=n;i++)F2[i]=F2[i-1]*2%P;
	for(int i=0;i<n;i++){
		scanf("%d %d",&s[i].x,&s[i].y);
		X[i]=s[i].x;
		Y[i]=s[i].y;
	}
	sort(X,X+n);sort(Y,Y+n);
	for(int i=0;i<n;i++){
		s[i].x=lower_bound(X,X+n,s[i].x)-X+1;
		s[i].y=lower_bound(Y,Y+n,s[i].y)-Y+1; 
	} 
	LL ans=1LL*n*(F2[n]-1)%P; 
	sort(s,s+n,cmpx);
	bit.clear(); 
	for(int i=0;i<n;i++){ 
		Add(ans,-(F2[i]-1));
		Add(ans,-(F2[n-1-i]-1)); 
	}
	sort(s,s+n,cmpy);
	for(int i=0;i<n;i++){
		Add(ans,-(F2[i]-1));
		Add(ans,-(F2[n-1-i]-1));
	} 
	for(int i=0;i<n;i++){ 
		Add(ans,F2[bit.Query(s[i].x)]-1);//<x,<y
		Add(ans,F2[i-bit.Query(s[i].x)]-1);//>x,<y
		bit.Add(s[i].x);
	}
	bit.clear(); 
	for(int i=n-1;i>=0;i--){  
		Add(ans,F2[bit.Query(s[i].x)]-1);//<x,>y
		Add(ans,F2[n-1-i-bit.Query(s[i].x)]-1);//>x,>y;
		bit.Add(s[i].x); 
	} 
	cout<<ans<<endl; 
	return 0;
}

Measured memory_bytes: 17408
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define EVEL 1

#ifndef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;

    ll A,B,C;
    int N,M,K,X,Y,W,H;
    ll ans;
    string S;
    ll a[100010];
    int temp[100]={0};
    bool f=false;
    bool fir=true;
    ll sum[10000];

int main(){
    cin>>X>>A>>B;
    if(X+A<B)cout<<"dangerous";
    else if(A>=B)cout<<"delicious";
    else cout<<"safe";
    


    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
typedef pair<int,int> P;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
	int x;
	cin>>x;
	rep(i,-1000,1001){
		rep(j,-1000,1001){
			int a=i*i*i*i*i;
			int b=j*j*j*j*j;
			if(a-b==x){
				cout<<i<<' '<<j<<endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  int n,k;
  int ans=0;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    int h;
    cin>>h;
    if(h>=k)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int d,t,s;
    cin >> d >> t >> s;
    if(t*s >=d ) cout << "Yes" << endl;
    else cout << "No" << endl;
}



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

void solve()
{
    unsigned long long int n;
    cin >> n;
    string ans = "";
    while (n)
    {
        int k = (n % 26 == 0) ? 26 : n % 26;
        string a(1, 'a' + k - 1);
        ans.insert(0, a);
        if (n % 26 == 0)
            n--;
        n /= 26;
    }
    cout << ans;
}

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


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;

int main(){
    int n;
    map<int, int> mp;
    cin >> n;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        mp[a]++;
    }
    int ans = 0;
    for(auto itr = mp.begin(); itr != mp.end(); itr++){
        int first = itr->first;
        int second = itr->second;
        if(first > second) ans += second;
        else ans += second - first;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4736
using System;

public class Hello
{
    public static void Main()
    {
        var a = new int[] { 63, 6, 91, 79, 102, 109, 125, 39, 127, 111,0 };
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == -1) break;
            var pre = 10;
            for (int i = 0; i < n; i++)
            {
                var d = int.Parse(Console.ReadLine().Trim());
                var ret = Convert.ToString(a[pre] ^ a[d], 2);
                Console.WriteLine(getAns(ret));
                pre = d;
            }
        }
    }
    public static string getAns(string a)
    {
        return new string('0', 7 - a.Length) + a;
    }
}




Measured memory_bytes: 8940