akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvvl vector<vector<vector<long long>>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define bitcheck(bit,i) (bit)&(1LL<<(i))
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define Lin(s) getline(cin,(s))

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//切り上げ除算
long long cutup(long long a,long long b){return (a+b-1)/b;}

//累乗
template<typename t>
constexpr t my_pow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
    }
    return x;
}
#define pow my_pow

//chmin,chmax
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;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

ll to(string a,int p){
    return (a[p]-'0')*100+(a[p+1]-'0')*10+(a[p+2]-'0');
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin>>s;
    ll c=INF;
    rep(i,Size(s)-2){
        chmin(c,abs(to(s,i)-753));
    }
    cout<<c<<endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define Mod 1000000007
char a[110],b[110];
int main()
{
    int n,i,j,k,flag;
    long long s;
    scanf("%d",&n);
    scanf("%s%s",a,b);
    if(n==1)
    {
        printf("3\n");
        return 0;
    }
    if(n==2)
    {
        printf("6\n");
        return 0;
    }
    if(a[0]==b[0])
    {
        s=3;
        flag=2;
        for(i=1;i<n;i++)
        {
            if(a[i]==b[i])
            {
                if(flag==2)
                    s=s*2%Mod;
                flag=2;
            }
            else
            {
                if(flag==1)
                s=s*3%Mod;
                else
                s=s*2%Mod;
                flag=1;
                i++;
            }
        }
    }
    else
    {
        s=6;
        flag=1;
        for(i=2;i<n;i++)
        {
            if(a[i]==b[i])
            {
                if(flag==2)
                    s=s*2%Mod;
                flag=2;
            }
            else
            {
                if(flag==1)
                    s=s*3%Mod;
                else
                s=s*2%Mod;
                flag=1;
                i++;
            }
        }
    }
    printf("%lld\n",s);
    return 0;
}

Measured memory_bytes: 128
from collections import Counter

def main():
  while True:
    n, m = map(int, input().split())
    if n == 0:
      break
  
    tmp = [0]
    h_lst = []
    for _ in range(n):
      h = int(input())
      new = [i + h for i in tmp]
      h_lst.extend(new)
      tmp = [0] + new
    
    tmp = [0]
    w_lst = []
    for _ in range(m):
      w = int(input())
      new = [i + w for i in tmp]
      w_lst.extend(new)
      tmp = [0] + new
  
    h_count = Counter(h_lst)
    w_count = Counter(w_lst)
    ans = 0
    for k in h_count:
      ans += h_count[k] * w_count[k]
  
    ans -= h_count[0] * w_count[0]
    print(ans)

main()


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

int main(){
    int n,m;cin>>n>>m;
    priority_queue<int> value;
    rep(i,n){
        int a;cin>>a;
        value.push(a);
    }
    rep(i,m){
        int top=value.top()/2;
        value.pop();
        value.push(top);
    }
    ll sum=0;
    while(!value.empty()){
        sum+=value.top();
        value.pop();
    }
    cout <<sum;
}

Measured memory_bytes: 3928
#include<bits/stdc++.h>
#define ld long double
#define ll long long
#define st first
#define nd second
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	int a;
	int ans = 0;
	for(int i=1; i<=n; ++i) {
		cin>>a;
		if(a%2==1 && i%2==1) ans++;
	}
	cout<<ans;
}


Measured memory_bytes: 3644
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int n, m, x;
  cin >> n >> m >> x;
  int a, price[n + 1];
  for (int i = 0; i < n + 1; i++) price[i] = 0;
  for (int i = 0; i < m; i++) {
    cin >> a;
    price[a] = 1;
  }
  int p = 0, q = 0;
  for (int i = 1; i < x; i++) if (price[i] == 1) p++;
  for (int i = x + 1; i < n + 1; i++) if (price[i] == 1) q++;
  cout << min(p, q) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b,ans=0 ;
    char s[15] ;
    scanf ("%d%d%s",&a,&b,s) ;
    
    for (int i=0; i<a; i++ ){
        if ( s[i]!='-' ){
            ans++ ;
        }
    }
    
    if ( s[a]=='-' ){
        ans++ ;
    }
    
    for (int i=0; i<b; i++ ){
        if ( s[a+1+i]!='-' ){
            ans++ ;
        }
    }
    
    if ( ans==a+b+1 ){
        printf ("Yes\n") ;
    } else {
        printf ("No\n") ;
    }
    
    return 0 ;
    
}

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


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

Measured memory_bytes: 3592
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 233
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
const int n=read(),k=read(),mod=read();
int fac[N],inv[N],ans;
#define ck(x) (x>=mod?x-mod:x)
int qpow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return ans;
}
void init(int n){
	fac[0]=1;
	for(int i=1;i<=n;++i){
		fac[i]=1LL*fac[i-1]*i%mod;
	}
	inv[n]=qpow(fac[n],mod-2);
	for(int i=n-1;i>=0;--i){
		inv[i]=1LL*inv[i+1]*(i+1)%mod;
	}
}
int calc(int X,int Y,int k){
	static int dp[N][N];
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	for(int j=1;j<=Y;++j){
		int s=0;
		for(int i=0;i<X;++i){
			s=ck(s+dp[i][j-1]);
			if((Y-j+1)+(i-1)<=k&&(X-i)+(j-1)<=k){
				dp[i][j]=s;
			}
		}
	}
	int tot=0;
	for(int i=1;i<X;++i){
		tot=ck(tot+dp[i][Y]);
	}
	return tot;
}
int Solve(int n,int k){
	if(n==1)return 1;
	int tot=0;
	for(int i=1;i<=k+1;++i){
		tot=(tot+calc(i,n-i,k))%mod;
	}
	tot=1LL*tot*fac[n-1]%mod;
	return tot;
}
int main(){
	init(n);
	for(int i=0;i<=k;++i){
		ans=(ans+1LL*fac[n]*inv[n-i]%mod*Solve(n-i,k-i))%mod;
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 3908
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int A,B,M;
    cin >> A >> B >> M;
    vector<int> a(A),b(B);
    for(int i = 0;i < A;i++){
        cin >> a[i];
    }
    for(int i = 0;i < B;i++){
        cin >> b[i];
    }
    int minA = *min_element(a.begin(),a.end());
    int minB = *min_element(b.begin(),b.end());
    int ans = minA + minB;
    for(int i = 0;i < M;i++){
        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 pb push_back
#define vt vector
#define ll long long
using namespace std;

const int INF = 1e9 +5;
const ll LLINF = 1e18 +5;

int i4[4] = {1,0,-1,0};
int j4[4] = {0,1,0,-1};


void solve()
{
	int a,b;
	cin >> a >> b;
    cout << (((a*b)&1)? "Odd":"Even") << endl;


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

  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	int res = 0;
	int mn = (int)1 << 60;
	int sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
		if (A[i] > B[i]) {
			mn = min(mn, B[i]);
		}
		sum += A[i];
	}

	if (mn == (int)1 << 60) {
		cout << 0 << endl;
	}else{
		cout << sum - mn << endl;
	}
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
table = [0] * (N + 1)
for i in range(N):
  table[a[i]] += 1

ttable = [0] * (N + 1)
for i in range(N + 1): ttable[i] = table[i] * (table[i] - 1) // 2
cs = [0] * (N + 2)
for i in range(N + 1): cs[i + 1] = cs[i] + ttable[i]
#print(ttable)
#print(cs)

for x in a:
  t = cs[x] + (cs[-1] - cs[x + 1])
  print(t + (table[x] - 1) * (table[x] - 2) // 2)

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

int max(int x, int y) { return x > y ? x : y; }

typedef struct
{
	int parent;
	int depth;
	int height;
	int degree;
	int left;
	int right;
	int sibling;
} node;

int set_level(node *data, int i, int d)
{	
	data[i].depth  = d;
	data[i].height = 0;
	data[i].degree = 0;

	if(data[i].left != -1)
	{
		data[data[i].left].sibling = data[i].right;
		data[i].height = max(data[i].height, 1 + set_level(data, data[i].left, d+1));
		data[i].degree += 1;
	}
	if(data[i].right != -1)
	{
		data[data[i].right].sibling = data[i].left;
		data[i].height = max(data[i].height, 1 + set_level(data, data[i].right, d+1));
		data[i].degree += 1;
	}
	
	return data[i].height;
}

int main()
{
	int n, x;
	node data[25];
	
	scanf("%d", &n);
	for(int i = 0; i < n; ++i)
	{
		data[i].parent  = -1;
		data[i].left    = -1;
		data[i].right   = -1;
		data[i].sibling = -1;
	}

	for(int i = 0; i < n; ++i)
	{
		scanf("%d", &x);
		scanf("%d %d", &data[x].left, &data[x].right);
		
		if(data[x].left != -1)
		{
			data[data[x].left].parent  = x;
		}
		if(data[x].right != -1)
		{
			data[data[x].right].parent  = x;
		}
	}

	for(int i = 0; i < n; ++i)
	{
		if(data[i].parent == -1)
		{
			set_level(data, i, 0);
			break;
		}
	}
	
	for(int i = 0; i < n; ++i)
	{		
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
			i, data[i].parent, data[i].sibling, data[i].degree, data[i].depth, data[i].height);
		
		if(data[i].parent == -1)
		{
			printf("root\n");
		}
		else if(data[i].degree == 0)
		{
			printf("leaf\n");
		}
		else
		{
			printf("internal node\n");
		}
	}
}



Measured memory_bytes: 2056
n = int(input())
ans = ''

n -= 1
li = [26 ** i for i in range(1, 20)]
for i in range(18):
    li[i+1] += li[i]

for i in range(19):
    if n >= li[i]:
        pass
    else:
        tmp = i
        if i == 0:
            pass
        else:
            n -= li[i-1]
        break

for i in range(tmp+1):
    ans += chr(ord('a') + n % 26)
    n //= 26

print(ans[::-1])


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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n,k; cin >> n >> k;
  if(k == 1) cout << 0 << endl;
  else cout << n - k << endl;

  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <string>
using namespace std;
int main()
{
  string C[2];
  cin >> C[0] >> C[1];
  if ((C[0][0]==C[1][2]) && (C[0][1]==C[1][1]) && (C[0][2]==C[1][0])) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
                                                      


Measured memory_bytes: 3628
N, M = gets.chomp.split.map(&:to_i)

neighbors_i = Array.new(N){[]}
neighbors_d = Array.new(N){[]}

M.times do |i|
    l, r, d = gets.chomp.split.map(&:to_i)
    l -= 1
    r -= 1
    #neighbors[l - 1].push([r - 1, d])
    #neighbors[r - 1].push([l - 1, -d])

    neighbors_i[l].push(r)
    neighbors_d[l].push(d)
    neighbors_i[r].push(l)
    neighbors_d[r].push(-d)
end

# diffs[j]: difference between i, j (i is smallest index of cluster)
# j is visited if diffs[j] is not nil
diffs = Array.new(N)

N.times do |i|
    next if diffs[i]

    stack = [i]
    diffs[i] = 0

    while stack.length > 0 do
        t = stack[-1]

        back = true
        #while neighbors[t].length > 0 do
        while neighbors_i[t].length > 0 do
            #ni, nd = neighbors[t].pop
            ni = neighbors_i[t].pop
            nd = neighbors_d[t].pop
            if diffs[ni]
                # cycle
                if diffs[t] - diffs[ni] + nd != 0
                    print 'No'
                    exit
                end
            else
                # not yet visited
                stack.push(ni)
                diffs[ni] = diffs[t] + nd
                back = false
                break
            end
        end

        stack.pop if back
    end
end

print 'Yes'

Measured memory_bytes: 44280
n,m = map(int,input().split())
p = list(map(int,input().split()))
info = [list(map(int,input().split())) for _ in range(m)]

par =[i for i in range(n+1)] 
rank=[0]*(n+1)

# xの根を見つける
def root(x):
  if par[x] == x:
    return x
  else:
    par[x] = root(par[x])
    return par[x]
  
# x,yの根が同じかどうかを返す（根が同じ:True、根が異なる:False）
def find(x, y):
  return root(x) == root(y)

# xとyの根を結合させる
def union(x, y):
  x = root(x)
  y = root(y)
  if rank[x] < rank[y]:
    par[x] = y
  else:
    par[y] = x
    if rank[x] == rank[y]:
      rank[x] += 1

for i in range(m):
  union(info[i][0],info[i][1])

a=[0]*(n+1)
for i in range(n):
  a[p[i]]=i+1

ans = 0 
for i in range(1,n+1):
  if find(i,a[i]):
    ans += 1
    
print(ans)

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

class Dice {
public:
    static int rollingface[][4];
    static int sideface[][4];
    int face[6];

    Dice(string &face_data);
    // ~Dice();
    void roll(const char &op);
    int top();
    int front_face(int top, int right);
    void print_faces();
};

int Dice::rollingface[][4] = {
    {0, 2, 5, 3},
    {0, 4, 5, 1},
    {0, 1, 5, 4},
    {0, 3, 5, 2},
};

int Dice::sideface[][4] = {
    {1, 3, 4, 2},
    {0, 2, 5, 3},
    {0, 4, 5, 1},
    {0, 1, 5, 4},
    {0, 3, 5, 2},
    {1, 2, 4, 3},
};

Dice::Dice(string &face_data) {
    istringstream strm;
    strm.str(face_data);
    for (int i = 0; i < 6; i++) {
        strm >> face[i];
    }
}

void Dice::roll(const char &op) {
    int *fseq;
    switch (op) {
        case 'E': fseq = Dice::rollingface[0]; break;
        case 'N': fseq = Dice::rollingface[1]; break;
        case 'S': fseq = Dice::rollingface[2]; break;
        case 'W': fseq = Dice::rollingface[3]; break;
        default: break;
    }
    int t, p = face[fseq[3]];
    for (int i = 0; i < 4; i++) {
        t = face[fseq[i]];
        face[fseq[i]] = p;
        p = t;
    }
}

int Dice::front_face(int top, int right) {
    int i;
    for (i = 0; i < 6; i++) {
        if (face[i] == top) break;
    }
    int *fseq = Dice::sideface[i];
    for (i = 0; i < 4; i++) {
        if (face[fseq[i]] == right) return face[fseq[(i-1+4)%4]];
    }
    return -1;
}

void Dice::print_faces() {
    cout << "face:" << endl;
    cout << "   " << face[4] << endl;
    cout << face[3] << " " << face[0] << " " << face[2] << endl;
    cout << "   " << face[1] << endl;
    cout << "   " << face[5] << endl;
    cout << endl;
}

int Dice::top() {
    return face[0];
}

int main() {
    string buf;
    int i, q, top, right;
    Dice *dice;

    getline(cin, buf);
    dice = new Dice(buf);
    cin >> q;
    for (i = 0; i < q; i++) {
        cin >> top >> right;
        cout << dice->front_face(top, right) << endl;
    }

    return 0;
}

Measured memory_bytes: 1212
import sys

n = int(input())
aaa = list(map(int, sys.stdin.readlines()))
bbb = [(a, i) for i, a in enumerate(aaa)]
bbb.sort()
am1, im1 = bbb[-1]
am2, im2 = bbb[-2]
for i in range(n):
    if i == im1:
        print(am2)
    else:
        print(am1)


Measured memory_bytes: 33668
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long 
int INF=INT_MAX;
int main(){
  ll n;
  cin>>n;
  vector<int>a(n);
  multiset<int>m;
  rep(i,n)cin>>a[i];
  int kotae=0;
  rep(i,n){
    auto Iter = m.lower_bound(a[i]);
    if(Iter!=m.begin())m.erase(--Iter);
    m.insert(a[i]);
  }
  kotae=m.size();
  cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 8252
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N; cin >> N;
    vector<pair<int, int>> P(N);
    for (int i = 0; i < N; ++i) cin >> P[i].first >> P[i].second;
    sort(P.begin(), P.end());
    long long int ans = ((P[N - 1].first - P[0].first) + 1) + (P[0].first - 1) + P[N - 1].second;
    printf("%d\n", ans);
}


Measured memory_bytes: 4052
/*                    ___          |\    /|           ____   ____   ____  ____
   |     |    /\    /    \ |     | | \  / |    /\    |    \ |    \ |     |    \
   |_____|   /__\   \____  |_____| |  \/  |   /__\   |____/ |____/ |__   |____/
   |     |  /    \       \ |     | |      |  /    \  |      |      |     |   \
   |     | /      \ \____/ |     | |      | /      \ |      |      |____ |    \
*/
#include<bits/stdc++.h>
using namespace std;
#define lb lower_bound
#define ub upper_bound
#define pf push_front
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pi pair<int,int>
#define pl pair<long,long>
#define pll pair<long long,long long>
#define pld pair<long double,long double>
#define gc getchar_unlocked
#define pc putchar_unlocked
#define endl '\n'
#define loop(i,n) for(ll i=0;i<n;i++)
#define mod (ll)(1e9+7)
#define in(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define vl vector<ll>
#define vpll vector<pair<ll,ll>>
#define INF 0x3f3f3f3f
#define mp make_pair

ll dp[1005][1005];

int main()
{
    ll n,ans=0;
    in(n);
    vl v(n);
    for(auto& i:v) in(i);
    sort(v.begin(),v.end());
    ll sum=0;
    for(ll dif=1;dif<n;dif++) {
        sum=0;
        for(ll i=dif;i<n;i++) {
            sum=v[i]+v[i-dif];
            ll lt = lower_bound(v.begin(),v.end(),sum) - v.begin();
            ans+=lt-i-1;
            // cout<<sum<<" "<<lt-i-1<<endl;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
q = []
for i in range(m):
    b,c = map(int,input().split())
    q.append([c,b])
q.sort(reverse=True)
j = 0
for i in range(m):
    while j < len(a) and q[i][1]>0:
        if a[j]<q[i][0]:
            a[j] = q[i][0]
            q[i][1] -= 1
        j+=1
print(sum(a))

Measured memory_bytes: 24048
#define _DEBUG
#include "bits/stdc++.h"
#include <atcoder/all>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace atcoder;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N,M;
	scan(N>>M);
	scc_graph g(N);
	rep(i,M){
		int a,b;//0-indexed
		scan(a>>b);
		g.add_edge(a,b);
	}
	auto scc=g.scc();
	prin(scc.size());
	for(const auto& group:scc){
		printf("%d ",group.size());
		for(const auto& v:group){
			printf("%d ",v);
		}
		kaigyo;
	}
	return 0;
}


Measured memory_bytes: 40612
n, h = io.read("*n", "*n")
katana = {}
amax = 0
for i = 1, n do
  a, b = io.read("*n", "*n")
  katana[i] = {}
  katana[i].a = a
  katana[i].b = b
  amax = math.max(amax, a)
end
table.sort(katana, function(x, y)
    return x.b > y.b
  end
)
cnt = 0
for i = 1, n do
  if(amax <= katana[i].b) then
    cnt, h = cnt + 1, h - katana[i].b
    if(h <= 0) then break end
  end
end
if(0 < h) then
  cnt = cnt + math.ceil(h / amax)
end
print(cnt)


Measured memory_bytes: 10624
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define be(v) v.begin(), v.end()
#define ll long long
ll INF = 1e9;
ll mod = 1e9+7;

ll dp[10001];
int main() {
  int n; cin >> n;
  int ans = 0;
  for(int i=1;i<=n;i++) {
  	string s = to_string(i);
  	if(s.length()%2==1) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void file(){
#ifndef ONLINE_JUDGE
	freopen("a_input.txt", "r", stdin);
	freopen("a_output.txt", "w", stdout);
#endif
}
void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}
int dx[] = { 0, 0, -1, 1, 1, 1, -1, -1 };
int dy[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int main(){
	//file();
	fast();
	int n, k;
	cin >> n >> k;
	int a[100005];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int mn = 1e9;
	for (int i = 0; i + k - 1 < n; i++)
		mn = min(mn, a[i + k - 1] - a[i]);
	cout << mn ;
}

Measured memory_bytes: 640
# require 'pp'
class Node
    attr_accessor :children, :cnt, :sub_root, :is_sub_root, :parent
    attr_reader :idx
    def initialize(idx)
        @idx = idx
        @children = []
        @cnt = 0
        @sub_root = nil
        @parent = nil
        @is_sub_root = false
        @calculated_cnt = nil
    end

    # def add_x(x)
    #     @cnt += x
    #     # @children.each { |i| i.add_x(x) }
    # end

    def update_sub_root(node)
        unless @is_sub_root
            @children.each { |child| child.update_sub_root(node) }
        end
    end

    def calc_cnt
        return @cnt if @parent.nil?
        return @calculated_cnt unless @calculated_cnt.nil?
        @calculated_cnt = @parent.calc_cnt + @cnt
    end
end

n, q = gets.split.map(&:to_i)

nodes = [Node.new(0)]
(n - 1).times do |i| 
    node = Node.new(i + 1)
    node.sub_root = nodes[0]
    nodes << node
end

(n - 1).times do |i|
    from, to = gets.split.map(&:to_i)
    parent_node = nodes[from - 1]
    child_node = nodes[to - 1]

    parent_node.children << child_node
    child_node.parent = parent_node
end

q.times do
    i, x = gets.split.map(&:to_i)
    nodes[i - 1].cnt += x
end

puts nodes.map(&:calc_cnt).join(' ')

# nodes.each_with_index do |n, idx|
#     puts "node #{idx}: (subroot: #{n.sub_root ? n.sub_root.idx : nil})"
#     n.children.each { |child| puts "   => #{child.idx}"  }
# end



Measured memory_bytes: 61436
function generateTrianglesFromInput(input) {
  var max = 1000;

  var lines = getInputAsLines(input, "\n");
  var vertices = lines.map(processLineToVertices);

  for(var i = 0; i < vertices.length; i++) {
    var line = vertices[i];
    if(i === 0) {
      if(line[0] > max) {
        break;
      }
    }
    var tri = new Triangle({
      constraints: {
        min: 1,
        max: 1000
      },
      vertices: {
        a: line[0],
        b: line[1],
        c: line[2]
      }
    });

    if(tri.isValid()) {
      var isRightAngleTriangle = tri.isRightAngleTriangle();
      var logValue = (isRightAngleTriangle) ? 'YES' : 'NO';
      console.log(logValue);
    }
  }
}

function getInputAsLines(input, delimeter) {
  return input.split(delimeter);
}

function processLineToVertices(line) {
  var vertices = line.split(' ');
  return vertices;
}


//Triangle
function Triangle(options) {

  this.constraints = {};
  this.vertices = {};

  //Set up triangle constraints.
  this.constraints.min = options.constraints.min || 1;
  this.constraints.max = options.constraints.max || 1000;

  //Set up triangle vertices
  this.vertices.a = (this.vertexIsWithinConstraints(options.vertices.a)) ? options.vertices.a : null;
  this.vertices.b = (this.vertexIsWithinConstraints(options.vertices.b)) ? options.vertices.b : null;
  this.vertices.c = (this.vertexIsWithinConstraints(options.vertices.c)) ? options.vertices.c : null;

}

Triangle.prototype.vertexIsWithinConstraints = function(vertex) {
  return (vertex >= this.constraints.min && vertex <= this.constraints.max);
}

Triangle.prototype.isValid = function() {
  return (this.vertices.a && this.vertices.b && this.vertices.c);
}

Triangle.prototype.isRightAngleTriangle = function() {
  var value = false;
  if(this.isValid) {
    var vertexArray = [];
    vertexArray.push(this.vertices.a);
    vertexArray.push(this.vertices.b);
    vertexArray.push(this.vertices.c);

    vertexArray.sort(function(a, b) {return a-b});

    var squares = vertexArray.map(function (vertex) { return Math.pow(vertex, 2)});
    value = (squares[2] === (squares[0] + squares[1]));
  }

  return value;
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim();
generateTrianglesFromInput(input);

Measured memory_bytes: 18120
#include <cstdio>

int main()
{
  int a, b;
  scanf("%d %d", &a, &b);
  if (b >= 0 && a <= 0 || a == 0 || b == 0)
  {
    puts("Zero");
    return 0;
  }
  if (a > 0)
  {
    puts("Positive");
    return 0;
  }
  if (b > 0)
  {
    puts((a & 1) == 0 ? "Positive" : "Negative");
    return 0;
  }
  else
  {
    puts(((b - a) & 1) == 1 ? "Positive" : "Negative");
    return 0;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=200010;
ll ans;
int n,L;
ll A[N],B[N];
int a[N],b[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') ch=='-'?o=-1:0,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return o*x;
}
inline void work() {
    for(int i=1;i<=n;i++)
	A[i]=A[i-1]+a[i],B[i]=B[i-1]+b[i];
    for(int i=1;i<=n;i++) {
	int p=min(i-1,n-i),q=min(i,n-i);
	ans=max(ans,max(2*(A[i-1]-A[i-p-1]+B[i+p]-B[i])+a[i],2*(A[i]-A[i-q]+B[i+q]-B[i])-a[i]));
    }
}
int main() {
    cin>>L>>n;
    for(int i=1;i<=n;i++)
	a[i]=gi(),b[i]=L-a[i];
    work();
    swap(a,b);
    reverse(a+1,a+1+n),reverse(b+1,b+1+n);
    work();
    cout<<ans;
    return 0;
}

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

int main(){
	int N;
	cin>>N;
	long long int H[N];
	for(int i=0;i<N;i++)
		cin>>H[i];
	
	long long int sa[N-1];
	for(int i=0;i<N-1;i++){
		if(H[i]<H[i+1]){
			H[i+1]--;
		}
		sa[i]=H[i+1]-H[i];
		if(sa[i]<=-1){
			cout<<"No";
			return 0;
		}
		
	}
	cout<<"Yes";
	
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define pb  					push_back
#define mp 						make_pair
#define all(v) 					((v).begin()) ,((v).end())
#define let(o,v)				memset(o,v,sizeof (o))
typedef long long 				ll;
typedef vector<int>				vi;
typedef vector<vi>				vvi;
typedef vector<string>			vs;

const int MOD = 998244353;
const int oo = (int)1e9;
const ll OO = (ll)1e18;
const double PI = acos(-1.0);
const int N = (int)1e5 + 9;

bool isprime(ll n) {
	if (n <= 1)
		return 0;
	for (ll i = 2; i*i <= n; i++)
		if (n%i == 0)
			return false;
	return 1;
}
ll intlog(ll base, ll x) {
	return (log(x) / log(base));
}
bool prime[N];
void primee()
{

	for (int p = 2; p*p <= N; p++)
	{

		if (prime[p] == true)
		{
			for (int i = p * 2; i < N; i += p)
				prime[i] = false;
		}
	}

}
string decToBinary(ll n)
{
	string z = "";
	int i = 0;
	while (n > 0) {

		z += (n % 2) + 48;
		n = n / 2;
		i++;
	}
	reverse(all(z));
	return z;
}
ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a%b);
}
ll power(ll x, int y)
{
	ll temp;
	if (y == 0)
		return 1;
	temp = power(x, y / 2);
	if (y % 2 == 0)
		return temp * temp;
	else
		return x * temp*temp;
}
int n,ar[100005][3];
ll dp[100005][3];
ll calc(int idx, int last) {
	if (idx == n) return 0;
	ll &ret = dp[idx][last];
	if (ret != -1) return ret;
	ret = 0;
	for (int i = 1; i <= 3; i++)
	{
		if(i!=last)
			ret = max(ret,ar[idx][i-1]+ calc(idx + 1, i));
	}
	return ret;
}
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d %d %d", &ar[i][0], &ar[i][1], &ar[i][2]);
	}
	let(dp, -1);
	printf("%lld\n", calc(0, 0));
	return 0;
}

Measured memory_bytes: 11520
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
using namespace std;

typedef pair<int, int> P;
int W, H, N;
int X1[1000], X2[1000], Y1[1000], Y2[1000];
vector<int> xs, ys;
int TW, TH;
int T[2010][2010];

int main() {
  while (cin >> W >> H) {
    if (W == 0 && H == 0) break;
    cin >> N;
    xs.clear(), ys.clear();
    for (int i=0; i<N; i++) {
      cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
      xs.push_back(X1[i]), xs.push_back(X2[i]);
      ys.push_back(Y1[i]), ys.push_back(Y2[i]);
    }
    xs.push_back(0), xs.push_back(W);
    ys.push_back(0), ys.push_back(H);
    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    ys.erase(unique(ys.begin(), ys.end()), ys.end());
    TW = xs.size()-1, TH = ys.size()-1;
    for (int i=0; i<=TW; i++) {
      for (int j=0; j<=TH; j++) {
        T[i][j] = 0;
      }
    }
    for (int i=0; i<N; i++) {
      int xz1 = lower_bound(xs.begin(), xs.end(), X1[i]) - xs.begin(),
          xz2 = lower_bound(xs.begin(), xs.end(), X2[i]) - xs.begin(),
          yz1 = lower_bound(ys.begin(), ys.end(), Y1[i]) - ys.begin(),
          yz2 = lower_bound(ys.begin(), ys.end(), Y2[i]) - ys.begin();
      for (int x=xz1; x<xz2; x++) {
        T[x][yz1]++;
        T[x][yz2]--;
      }
    }
    for (int x=0; x<TW; x++) {
      int g = 0;
      for (int y=0; y<TH; y++) {
        g += T[x][y];
        T[x][y] = g > 0 ? -1 : 0;
      }
    }
    int m = 0;
    for (int y=0; y<TH; y++) {
      for (int x=0; x<TW; x++) {
        if (T[x][y] == 0) {
          m++;
          queue<P> q;
          q.push(P(x, y));
          T[x][y] = m;
          while (!q.empty()) {
            int x = q.front().first, y = q.front().second; q.pop();
            if (x > 0    && T[x-1][y] == 0) T[x-1][y] = m, q.push(P(x-1, y));
            if (x < TW-1 && T[x+1][y] == 0) T[x+1][y] = m, q.push(P(x+1, y));
            if (y > 0    && T[x][y-1] == 0) T[x][y-1] = m, q.push(P(x, y-1));
            if (y < TH-1 && T[x][y+1] == 0) T[x][y+1] = m, q.push(P(x, y+1));
          }
        }
      }
    }
    cout << m << "\n";
  }
  return 0;
}

Measured memory_bytes: 6484
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    vector <int> dp(n,INT_MAX);
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=i+2;j++)
        {
            if(j<n)
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
        }
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int N=100010;
int n;
int a[N];

int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int i;ll l,r,L,R;
	scanf("%d",&n);
	rep(i,1,n)	scanf("%d",&a[i]);
	if(a[n]!=2)	{printf("-1\n");return 0;}
	l=2;r=3;
	for(i=n-1;i;i--){
		L=l/a[i]+(l%a[i]!=0);
		R=r/a[i];
		if(L>R){printf("-1\n");return 0;}
		l=1ll*L*a[i];r=1ll*(R+1)*a[i]-1;
	}
	printf("%lld %lld\n",l,r);
}

Measured memory_bytes: 512
using System;

namespace ITP1_5_A
{
    class Program
    {
        static void Main()
        {
            for (; ; )
            {
                string[] str = Console.ReadLine().Split(' ');
                int H = int.Parse(str[0]);
                int W = int.Parse(str[1]);

                if (H == 0 && W == 0) break;

                for (int i = 0; i < H; i++)
                {
                    for (int j = 0; j < W; j++) Console.Write("#");

                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 8900
#include<iostream>
using namespace std;
int main()
{
    int n;
    while(cin>>n , n){
        int i[1000],p[1000],q[1000],r[1000];
        int P,Q,R,C;
        bool flg=false;
        
        for(int j=0; j<n; j++){
            cin>>i[j]>>p[j]>>q[j]>>r[j];
        }
        
        cin>>P>>Q>>R>>C;
        
        for(int j=0; j<n; j++){
            if(p[j]<=P && q[j]<=Q && r[j]<=R && ((p[j]*4 + q[j]*9 + r[j]*4)<=C)){
                
                cout<<i[j]<<endl;
                flg=true;
            }
        }
        
        if(flg==false)
            cout<<"NA"<<endl;
    }
    
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  using P = pair<f80, f80>;
  vi32 x(n), y(n);
  vector<P> target;
  rep(i, n) {
    cin >> x[i] >> y[i];
    target.emplace_back(x[i], y[i]);
    target.emplace_back(x[i], y[i] + 0.0001);
    target.emplace_back(x[i], y[i] - 0.0001);
    target.emplace_back(-x[i], -y[i]);
    target.emplace_back(-x[i], -y[i] + 0.0001);
    target.emplace_back(-x[i], -y[i] - 0.0001);
    target.emplace_back(-y[i], x[i]);
    target.emplace_back(-y[i], x[i] + 0.0001);
    target.emplace_back(-y[i], x[i] - 0.0001);
    target.emplace_back(y[i], -x[i]);
    target.emplace_back(y[i], -x[i] + 0.0001);
    target.emplace_back(y[i], -x[i] - 0.0001);
  }
  f80 ans = 0;
  rep(i, sz(target)) {
    f80 nx, ny;
    tie(nx, ny) = target[i];
    int fx = 0, fy = 0;
    rep(j, n) {
      if (nx * x[j] + ny * y[j] >= 0) {
        fx += x[j], fy += y[j];
      }
    }
    f80 sum = sqrt(pow((f80) fx, 2) + pow((f80) fy, 2));
    amax(ans, sum);
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
const int N=2e5+9;
using namespace std;
int a[N],mod[10],n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	for(int i=1;i<=n;++i) mod[a[i]%4]++;
	int flag=1;
	if(mod[2]) mod[2]=1;
	if(mod[0]>=(mod[1]+mod[2]+mod[3])-1) flag=1;
	else flag=0;
	if(flag) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;int N,a,b,i;main(){cin>>N;vector<pair<int,int>>R(N+1,{2e9,-1});for(;i<N;i++){cin>>a>>b;R[i]={a,a+b};}sort(R.begin(),R.end());vector<int>V(N+1,1),f(N);for(;i--;){for(a=i+1;a<N&&R[a].first<R[i].second;a=f[a]);V[i]=(V[i+1]+V[f[i]=a])%998244353;}cout<<V[0]<<'\n';}

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

using ll = long long;

int main()
{
    ll K;
    ll X, Y;
    ll flipx = 1, flipy = 1;
    bool swflag = false; 

    cin >> K;
    cin >> X >> Y;

    
    if ( X < 0 ) flipx = -1, X = -X;
    if ( Y < 0 ) flipy = -1, Y = -Y;
    if ( X < Y ) { swflag = true; swap(X, Y); }

    if ( K % 2 == 0 && (X + Y) % 2 == 1 ) {
        cout << -1 << '\n';
        return ( 0 );
    }
    
    auto print = [&](ll x, ll y) {
        if ( swflag ) swap(x, y);
        cout << flipx * x << " " << flipy * y << '\n';
    };
    
    if ( (X + Y) < K ) {
        if ( (X + Y) % 2 == 1 ) {
            cout << 3 << '\n';
            print(0, -K);
            print(X + (K - X - Y) / 2, -(X + (K - X - Y) / 2));
            print(X, Y);
        } else {
            cout << 2 << '\n';
            print(K - (2 * K - (X + Y)) / 2 , -(2 * K - (X + Y)) / 2);
            print(X, Y);
        }
    } else {
        ll n, y, x;
        if ( ((K - (X + Y) % K) % K) % 2 == 0 ) {
            n = (X + Y + K - 1) / K;
            y = -(K * n - X - Y) / 2;
            x = K + y;
            if ( X < x ) y += x - X, x = X;
            cout << n << '\n';
            print(x, y);
            n--;
        } else {
            n = (X + Y + K - 1) / K + 1;
            cout << n << '\n';
            y = -(K * n - X - Y) / 2;
            if ( -K < y ) {
                x = K + y;
                if ( X < x ) y += x - X, x = X;
                print(x, y);
                n--;
            } else {
                print(0, -K);
                x = 2 * K + y;
                if ( X < x ) y += x - X, x = X;
                print(x, y);
                n -= 2;    
            }
        }
        while ( n-- ) {
            ll dx = min(X - x, K);
            ll dy = K - dx;
            x += dx, y += dy;
            print(x, y);
        }
    }

    return ( 0 );
}


Measured memory_bytes: 2304
#include <stdio.h>
#define true 1
#define false 0

int hantei(int *m,int *f,int *r);
void Grading(int a[][3],int *n);

int main(){
	int student[100][3]={};
	int m,f,r;
	int t,n=0;
	
	
	for(t=0;t<100;t++){
		do{
			printf("");
			scanf("%d %d %d",&m,&f,&r);
		}while(!hantei(&m,&f,&r));
		if(m==-1 && f==-1 && r==-1)break;
		student[t][0]=m;
		student[t][1]=f;
		student[t][2]=r;
	}
	
	
	Grading(student,&t);
	
	
	return 0;
}


int hantei(int *m,int *f,int *r){
	if(*m>=-1 && *m<=50 && *f>=-1 && *f<=50 && *r>=-1 && *r<=100)return true;		return false;
}

void Grading(int a[][3],int *n){
	int t;
	for(t=0;t<*n;t++){
		if(a[t][0]==-1 || a[t][1]==-1){
			printf("F\n");
		}else if(a[t][0]+a[t][1]>=80){
			printf("A\n");
		}else if(a[t][0]+a[t][1]>=65){
			printf("B\n");
		}else if(a[t][0]+a[t][1]>=50){
			printf("C\n");
		}else if(a[t][0]+a[t][1]>=30 && a[t][2]>=50){
			printf("C\n");
		}else if(a[t][0]+a[t][1]>=30){
			printf("D\n");
		}else{
			printf("F\n");
		}
	}
}

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

double dist(vector<int> A, vector<int> B) {
    return sqrt(pow(A[0] - B[0], 2) + pow(A[1] - B[1], 2));
}

int main() {
    int N;
    cin >> N;
    vector<vector<int>> vec(N, vector<int>(2));
    rep(i, N) cin >> vec[i][0] >> vec[i][1];
    double sum = 0;
    rep(i, N) rep(j, i) {
        sum += dist(vec[i], vec[j]);
    }
    printf("%.10lf", 2.0/N*sum);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007ll;


int main(){
	for(;;){
		int n;
		std::cin >> n;
		if(n==0){
			exit(0);
		}else{
			std::vector<int> a(n);
			rep(i,n)std::cin >> a[i];
			sort(all(a));
			std::cout << accumulate(a.begin()+1,a.end()-1,0)/(n-2) << std::endl;
		}
	}
}



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

int main( )
{
    int i, j, k, n;
    int s = 0, mx = 0;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> j;
        mx = max(mx, j);
        s += j;
    }
    s -= mx;
    if (mx < s) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())

T,A = map(int, input().split())

H_list = list(map(int, input().split()))
T_list = []

for i in range(N):
    T_tmp = T - H_list[i]*0.006
    T_list.append(T_tmp)

def f1(tmp):
    return abs(tmp-A)

T_list2 = list(map(f1, T_list))

min_index = T_list2.index(min(T_list2))
print(min_index + 1)

Measured memory_bytes: 3064
import sys
n = int(input())
s = sorted([int(input()) for _ in range(n)])
cnt = 0
x = sum(s)

if x % 10 != 0:
    print(x)
    sys.exit()

for num in s:
    if num % 10 == 0:
        cnt += 1
if cnt == len(s):
    print(0)
    sys.exit()
    
for i in range(n):
    if s[i] % 10 != 0:
        del s[i]
        break
print(sum(s))

Measured memory_bytes: 3064
/* ex4_3
  terakura */

#include <stdio.h>

int num(int diff);      //n番目の塔の高さ nは隣同士の塔の高さの差からわかる

int main(void){
    int west_hight, east_hight, ans;
    scanf("%d %d", &west_hight, &east_hight);
    ans = num(east_hight - west_hight) - east_hight;    //東の塔の元の高さから見えている高さを引く
    printf("%d\n", ans);

    return 0;

}



int num(int diff){
    int i, hight = 0;
    for(i = 1; i < diff + 1; i++){
        hight = hight + i;      //A(n) = A(n-1) + n
    }

    return hight;
}


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

int main(){
        int n,k;
        cin>>n>>k;
        int x[100000];
        for(int i=0; i<n; i++) cin>>x[i];
        int minc=INT_MAX;
        for(int l=0, r=k-1; r<n; l++,r++){
                int m=-min(x[l], 0);
                int p=max(0, x[r]);
                int c=min(2*m+p, m+2*p);
                minc=min(c, minc);
        }
        cout<<minc<<endl;
        return 0;
}


Measured memory_bytes: 640
# 空白区切の入力を数値(整数)の配列で返す
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

A, B = gets_i_list

if B == 1
  puts 0
else
  count = 1
  total = A
  while true
    break if total >= B
    count += 1
    total = (A * count) - (count - 1)
  end
  puts count
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n;
  cin >> n;
  cout << "ABC" << n << endl;
}

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

#define fast ios_base::sync_with_stdio; cin.tie(0); cout.tie(0)
#define ll          long long
#define ull         unsigned long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
//#define endl        '\n'
#define mod        1000000007
//#define mod        998244353
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define INF         numeric_limits<ll>::max();
#define NINF        numeric_limits<ll>::min();
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))
const long double pi=3.14159265359;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

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

int main()
{fast;
 #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
 #endif
 int t=1,n;
 //cin>>t;
 while(t--)
 {cin>>n;
  vll v(n);
  int f=0;
  rep(i,0,n){
    cin>>v[i];
    if(v[i]==0){
        f=1;
    }
  }
  if(f){
    cout<<0<<endl;
    return 0;
  }
  long double x=1;
  ll ans=0;
  rep(i,0,n){
    x*=v[i];
    if(x>1e+18){
        ans=-1;
        break;
    }
  }
  if(ans==-1){
    cout<<-1;
  }
  else{
    ans=x;
    cout<<ans;
  }
 }
 return 0;
}


Measured memory_bytes: 4004
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m,x[100000],ans=0,memo[100000];
    scanf("%d%d",&n,&m);
    rep(i,m){
        scanf("%d",x+i);
    }
    sort(x,x+m);
    if(m==1)printf("0");
    else{
        rep(i,m-1){
            memo[i]=x[i+1]-x[i];
            ans+=x[i+1]-x[i];
        }
        sort(memo,memo+m-1);
        rep(i,n-1){
            ans-=memo[m-i-2];
        }
        printf("%d",ans);
    }
    return 0;
}


Measured memory_bytes: 1024