akhauriyash/Code-Regression huggingface dataset:
<?php
  $stdin = trim(fgets(STDIN));  
  
  $array = explode(" ",$stdin);
  
  foreach($array as $key => $dr){
    
     $array[$key] = intval($dr);
    
  }


  $pre_1 = $array[0] * $array[2];
  $pre_2 = $array[0] * $array[3];
  $pre_3 = $array[1] * $array[2]; 
  $pre_4 = $array[1] * $array[3];

  echo max($pre_1,$pre_2,$pre_3,$pre_4);
  
  ?>

Measured memory_bytes: 16292
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int INF=~0u>>2;
int n; 
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
int main(){
//	freopen("ex.in","r",stdin);
	n=read();
	if(n/10==9||n%10==9) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
/*Har Har Mahadev*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define tr(v,it) for(auto it=v.begin(); it!=v.end(); it++)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define pie 3.141592653589793
#define INF 1e18
using namespace std;

const int N=2e5+10;
int main()
{
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
        
		        long long n,a,b;
		        cin>>n>>a>>b;
		        long long res=0;
		        for(int i=1;i<=n;i++)
		        {
		        	int j=i;
		        	int sum=0;
		        	while(j!=0)
		        	{
		        		sum+=j%10;
		        		j/=10;
		        	}
		        	if(sum>=a&&sum<=b)
		        		res+=i;
		        }

		        cout<<res;


        return 0;
}


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        vector<int> A(N); cin >> A;
        double sum = 0;
        for(int a : A) sum += a;
        double avg = sum / N;
        int ans = 0;
        rep(i, N) {
            if(abs(avg - A[i]) < abs(avg - A[ans])) ans = i;
        }
        cout << ans << endl;
        return 0;
    }
};

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


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
const int N = 100001;
int arr[N][3];
int dp[N][2][2][2];
ll findans(bool f, bool s, bool t, int n){
	if(n < 0) return 0;
	ll ans = 0;
	if(dp[n][(int)f][(int)s][(int)t]) return dp[n][(int)f][(int)s][(int)t];
	if(f && s){
		ans = max(findans(0, 1, 1, n - 1) + arr[n][0], findans(1, 0, 1, n - 1) + arr[n][1]);
	}
	if(f && t){
		ans = max(ans, max(findans(0, 1, 1, n - 1) + arr[n][0], findans(1, 1, 0, n - 1) + arr[n][2]));
	}
	if(s && t){
		ans = max(ans, max(findans(1 ,0 ,1 ,n - 1) + arr[n][1], findans(1, 1, 0, n - 1) + arr[n][2]));
	}
	dp[n][(int)f][(int)s][(int)t] = ans;
	return dp[n][(int)f][(int)s][(int)t];
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	memset(dp, 0, sizeof(dp));
	int n;
	cin >> n;
	for(int i= 0; i < n; i++){
		for(int j = 0; j < 3; j++){
			cin >> arr[i][j];
		}
	}

	cout << findans(1, 1, 1, n - 1);

	
	
}


Measured memory_bytes: 18876
#include <iostream>
#include <string>
#include <vector>


int main(void){
  std::string s;
  std::cin >> s;
  if (s[0]==s[1] or s[1]==s[2] or s[2] == s[3]){
    std::cout << "Bad" << std::endl;
  }else{
    std::cout << "Good" << std::endl;
  }

  return 0;
}

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

using namespace std;

int main(){

    int a,b,c;

    cin>>a>>b>>c;

    if(a==7){
        if(b==5 && c==5){
            cout<<"YES";
        }
        else{
            cout<<"NO";
        }
    }
    else if(b==7){
        if(a==5 && c==5){
            cout<<"YES";
        }
        else{
            cout<<"NO";
        }

    }


    else if(c==7){
        if(b==5 && a==5){
            cout<<"YES";
        }
        else{
            cout<<"NO";
        }
    }

    else{

    }

}


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N; cin >> N;
  VI xs(N);
  LL ans = 0;
  REP(i,N)
	cin >> xs[i];


  REP(i,N){
	ans += xs[i] / 2;
	xs[i] %= 2;
	if(xs[i] && i+1 < N && xs[i+1]){
	  ++ans;
	  xs[i]--;
	  xs[i+1]--;
	}
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

/**
 * https://abc053.contest.atcoder.jp/submissions/1102786
 */
public class Main {
	 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int rate = sc.nextInt();
		sc.close();
		
		String ans = rate>=1200 ? "ARC" : "ABC";
		System.out.println(ans);
 
	}
 
}

Measured memory_bytes: 21972
#include <stdio.h>

int main(void)
{
    int i, j;
    int n;
    int cards[4][14];
    /*cards[suit][rank]
        suit 0: Spade, 1: Heart, 2: Club, 3: Diamond
        rank = 1, 2, ..., 13*/
    char suit[2];
    int rank;

    /*initialize; cards[i][j] = 1 -> exist, 0 -> missing*/
    for (i = 0; i < 4; i++){
        cards[i][0] = 1;
        for (j = 1; j < 14; j++){
            cards[i][j] = 0;
        }
    }

    /*input*/
    scanf("%d", &n);
    for (i = 1; i <= n; i++){
        scanf("%s %d", suit, &rank);
        switch (suit[0]){
            case 'S':
                cards[0][rank] = 1;
                break;
            case 'H':
                cards[1][rank] = 1;
                break;
            case 'C':
                cards[2][rank] = 1;
                break;
            case 'D':
                cards[3][rank] = 1;
                break;
            default:
                printf("ERROR!\n");
                break;
        }
    }

    /*output*/
    for (j = 1; j < 14; j++){
        if (cards[0][j] == 0){
            printf("S %d\n", j);
        }
    }

    for (j = 1; j < 14; j++){
        if (cards[1][j] == 0){
            printf("H %d\n", j);
        }
    }

    for (j = 1; j < 14; j++){
        if (cards[2][j] == 0){
            printf("C %d\n", j);
        }
    }

    for (j = 1; j < 14; j++){
        if (cards[3][j] == 0){
            printf("D %d\n", j);
        }
    }

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
//https://atcoder.jp/contests/abc145/tasks/abc145_d
const long int modo = 1000000007;
const long int modo2 = 1000000005;

long long int powMod(long long int a, long long int b){
    long long int x=1, y = a;
    while(b > 0){
        if(b%2==1){
            x = (x*y);
            if(x > modo) 
                x %= modo;
        }
        y = (y * y);
        if(y > modo) 
            y %= modo;
        b/=2;
    }
    return x;
}
 
 
long long int inverseEuler(long long int n){
    return powMod(n, modo2);
}

 
long long int C(long long int n, long long int r){
    long long int i, *f = malloc((n + 1) * sizeof(long long int));
    f[0] = 1;
    f[1] = 1;
    for(i = 2;i<=n;i++){
        f[i] = (f[i-1]*i);
        if(f[i] > modo)
            f[i] %= modo;
    }
 
    return (f[n]*((inverseEuler(f[r]) * inverseEuler(f[n-r]))%modo))%modo;
}
int main() {
	long int x, y, n1, N;
	scanf("%ld %ld\n", &x, &y);
	n1 =  (x < y) ? (2 * x - y) / 3 : (2 * y - x) / 3;
	N = y + x;
	if((N % 3 != 0) || n1 < 0 || n1 > N)
	    printf("0\n");
	else{
	    N /= 3;
	    printf("%lld\n", C(N, n1));
	}
	return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define ALL(x) std::begin(x), std::end(x)
using namespace std;

int64_t solve(int n, int64_t k, const vector<int64_t> & a) {
    vector<int64_t> acc(n + 1);
    partial_sum(ALL(a), acc.begin() + 1);
    int64_t answer = 0;
    unordered_map<int64_t, int> cnt;
    REP (i, n + 1) {
        if (i - k >= 0) {
            -- cnt[((acc[i - k] - (i - k)) % k + k) % k];
        }
        answer += cnt[((acc[i] - i) % k + k) % k];
        ++ cnt[((acc[i] - i) % k + k) % k];
    }
    return answer;
}

int main() {
    int n; int64_t k; cin >> n >> k;
    vector<int64_t> a(n);
    REP (i, n) {
        cin >> a[i];
    }
    cout << solve(n, k, a) << endl;
    return 0;
}


Measured memory_bytes: 11592
//25
#include<iostream>
#include<algorithm>

using namespace std;

void ma(int &a,int b){
  a=min(a,b);
}

int main(){
  int t;
  cin>>t;
  while(t--){
    bool s[2][20000];
    int n;
    cin>>n;
    for(int i=0;i<4*n;i++){
      char c;
      cin>>c;
      s[i>=2*n][i%(2*n)]=c=='Y';
    }
    int cs[10002][3];
    fill(cs[0],cs[10002],1<<30);
    cs[0][0]=0;
    for(int i=0;i<n+1;i++){
      bool np[2];
      for(int j=0;j<2;j++){
	np[j]=(i&&s[j][2*i-1])||(i<n&&s[j][2*i]);
      }
      if(!(np[0]|np[1])){
	ma(cs[i+1][0],cs[i][0]+1);
	ma(cs[i+1][1],cs[i][1]+1);
	ma(cs[i+1][2],cs[i][2]+1);
      }
      if(!np[1]){
	ma(cs[i+1][1],cs[i][0]+2);
	ma(cs[i+1][0],cs[i][0]+2);
	ma(cs[i+1][0],cs[i][1]+2);
	ma(cs[i+1][1],cs[i][1]+2);
      }
      if(!np[0]){
	ma(cs[i+1][2],cs[i][1]+2);
	ma(cs[i+1][1],cs[i][1]+2);
	ma(cs[i+1][1],cs[i][2]+2);
	ma(cs[i+1][2],cs[i][2]+2);
      }
      ma(cs[i+1][0],min(cs[i][0],min(cs[i][1],cs[i][2]))+3);
      ma(cs[i+1][1],min(cs[i][0],min(cs[i][1],cs[i][2]))+3);
      ma(cs[i+1][2],min(cs[i][0],min(cs[i][1],cs[i][2]))+3);
      ma(cs[i+1][0],min(cs[i+1][1]+1,cs[i+1][2]+2));
      ma(cs[i+1][1],min(cs[i+1][0]+1,cs[i+1][2]+1));
      ma(cs[i+1][2],min(cs[i+1][0]+2,cs[i+1][1]+1));
    }
    cout<<min(cs[n+1][0],min(cs[n+1][1]+1,cs[n+1][2]+2))-1<<endl;
  }
  return 0;
}
	

Measured memory_bytes: 1316
from math import factorial
 
S = int(input())
 
ans = 0
for i in range(S // 3):
    box = i + 1  # 箱の数
    ball = S - 3 * box # あらかじめ箱に３こずつ入れたあとの残りの玉の数
    ans_ = factorial(ball + box - 1) // (factorial(ball) * factorial(box - 1))
    ans += ans_
print(ans % (10 ** 9 + 7))

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

int main(void){
    int x,y;
    cin >> x >> y;

    bool ok = false;
    for(int a=0;a<=x;a++){
        int b = x-a;
        if(2*a+4*b==y) ok = true;
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

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

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = -1 * (((1<<30)-1)*2+1) ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

class Bucket{
  public:
  vector<ll> buc,v;
  ll N,sqn,K;
  Bucket(){};
  Bucket(ll n){
    N = n;
    sqn = sqrt(N);
    K = (n + sqn - 1) /sqn;
    buc.assign(K,-inf);
    v.assign(K * sqn,-inf);
  }
  ll find(int x){
    lazyupdate(x/sqn);
    return v[x];
  }
  void lazyupdate(int k){
    if(k >= K) return ;
    if(buc[k] != -inf){
      for(int i = k * sqn; i < (k+1) * sqn;++i){
        v[i] = buc[k];
      }
    }
    buc[k] = -inf;
  }
  void update(int x,int y,int n){
    for (int k = 0; k < K; ++k) {
      int l = k * sqn, r = (k + 1) * sqn;
      if (r <= x || y <= l)
        continue;
      if (x <= l && r <= y) {
        buc[k] = n;
      } else {
        lazyupdate(k);
        for (int i = max(x, l); i < min(y, r); ++i) {
          v[i] = n;
        }
      }
    }
  }
  void Debug(){
    for(int i = 0; i < N;++i){
      cout << buc[i/sqn] << ' ';
    }
    cout << endl;
    for(int i = 0; i < N;++i){
      cout << v[i] << ' ';
    }
    cout << endl;
  }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, q,s,t,x,a;
  cin >> n >> q;
  Bucket buc(n);
  rep(i,q){
    cin >> a;
    if(a){
      cin >> s;
      cout << buc.find(s) << endl;
    }
    else{
      cin >> s >> t >> x;
      buc.update(s,t+1,x);
    }
  }
  return 0;
}

Measured memory_bytes: 3512
n = input()

if n == 0:
    print(1)
elif n == 1:
    print(1)
else:
    fib = [0 for i in range(n + 1)]

    fib[0] = 1
    fib[1] = 1

    for i in range(2, n + 1):
        fib[i] = fib[i - 1] + fib[i - 2]

    print(fib[n])

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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



int main(void)
{
  ll a[5];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a+3);

  ll d = a[2] - a[0] + a[2] - a[1];
  if(d % 2 == 1) d += 3;
  cout << (d / 2) << endl;
  
}


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

using namespace std;
using ll = long long;

const int sz = 2010;
array<array<int, sz>, sz> hl;
array<array<int, sz>, sz> hr;
array<array<int, sz>, sz> wl;
array<array<int, sz>, sz> wr;

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> grid(H + 1);
	for (int i = 1; i <= H; ++i) {
		cin >> grid[i];
		grid[i] = "x" + grid[i];
	}

	for (int i = 0; i < sz; ++i) {
		hl[i].fill(0);
		hr[i].fill(H + 1);
		wl[i].fill(0);
		wr[i].fill(W + 1);
	}
	for (int i = 1; i <= H; ++i) {
		for (int j = 1; j <= W; ++j) {
			wl[i][j] = wl[i][j - 1];
			if (grid[i][j] == '#') { wl[i][j] = j; }
		}
		for (int j = W; j > 0; --j) {
			wr[i][j] = wr[i][j + 1];
			if (grid[i][j] == '#') { wr[i][j] = j; }
		}
	}
	for (int j = 1; j <= W; ++j) {
		for (int i = 1; i <= H; ++i) {
			hl[i][j] = hl[i - 1][j];
			if (grid[i][j] == '#') { hl[i][j] = i; }
		}
		for (int i = H; i > 0; --i) {
			hr[i][j] = hr[i + 1][j];
			if (grid[i][j] == '#') { hr[i][j] = i; }
		}
	}

	int res = 0;
	for (int i = 1; i <= H; ++i) {
		for (int j = 1; j <= W; ++j) {
			if (grid[i][j] == '#') { continue; }
			res = max(res, (hr[i][j] - hl[i][j] - 1) + (wr[i][j] - wl[i][j] - 1) - 1);
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 67456
a,b,c,d=map(int,input().split())

import math

def lcm(a,b):
  return (a*b)//math.gcd(a,b)

cnt_a=a-a//c-a//d+a//lcm(c,d)
cnt_b=b-b//c-b//d+b//lcm(c,d)

if a%c==0 or a%d==0:
  print(cnt_b-cnt_a)
else:
  print(cnt_b-cnt_a+1)

Measured memory_bytes: 62180
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
const int di[8] = {1, 0, -1, 0, 1, 1, -1, -1},
      dj[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int H, W; cin >> H >> W;

  string S[H];
  rep(i, H)
    cin >> S[i];
  rep(i, H) {
    rep(j, W) {
      int coutn = 0;
      if (S[i][j] == '#') {
        cout << '#';
        continue;
      }
      int count = 0;
      rep(k, 8)
        if (0 <= di[k] + i && di[k] + i < H &&
            0 <= dj[k] + j && dj[k] + j < W &&
            S[di[k]+i][dj[k]+j] == '#')
          ++count;
      cout << count;
    }
    cout << "\n";
  }

  return 0;
}


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N, L;
    cin >> N >> L;
    vector<int> A(N);
    int sum = 0;
    int mi = 1e9;
    int j = 0;
    for (int i = 0; i < N; i++) {
        A[i] = L + i;
        sum += A[i];
        if (mi > abs(A[i])) {
            mi = abs(A[i]);
            j = i;
        }
    }
    sum -= A[j];
    cout << sum << endl;

}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    int S, W;
    cin >> S >> W;
    cout << (S <= W ? "unsafe" : "safe") << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll n, m; cin >> n >> m;

    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> cha(n);

    vector<P> p(m);

    ll num = 0;

    rep(i,m){
        cin >> p[i].second >> p[i].first;
        num += p[i].second;
    }

    sort(all(p));
    reverse(all(p));

    ll cnt = min(n,num);
    ll tmp = 0;

        rep(j,m){
        rep(i,p[j].second){
            cha[tmp] = p[j].first;
            cnt--;
            tmp++;
            if(cnt == 0) break;
        }
        if(cnt == 0) break;
        }

    if(num < n) rep(i,n-num) cha[num+i] = 0;

    sort(all(a));

    rep(i,n){
        if(cha[0] < a[0]) break;
        if(cha[i] >= a[i]) a[i] = cha[i];
        else break;
    }

    ll ans = 0;

    rep(i,n) ans += a[i];

    dunk(ans);
}






Measured memory_bytes: 2560
res = Array.new(4,0)

loop do
    line = gets
    break if line.nil?
    input = line.split.map(&:to_i).sort
    x = input[2]
    y = input[0]
    z = input[1]
    if x >= (y+z) then
        break
    else
        res[0] += 1
        x2 = x**2
        o2 = y**2 + z**2
        if x2 == o2 then
            res[1] += 1
        elsif x2 > o2 then
            res[3] += 1
        else
            res[2] += 1
        end
    end
end
puts res.join(' ')


Measured memory_bytes: 6872
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

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;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;

int n;
vector<vector<int>> g(1000010);
vector<bool> used(1000010,false);
vector<int> dp(1000010,-1);

int dfs(int v){
  if(used[v]) return dp[v];
  used[v]=true;
  int ret=0;
  for(auto itr:g[v]){
    int now=dfs(itr);
    if(now==-1){
      return -1;
    }
    chmax(ret,dfs(itr));
  }
  return dp[v]=ret+1;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  vector<vector<int>> a(n,vector<int>(n-1));
  rep(i,n)rep(j,n-1){
    cin>>a[i][j];
    a[i][j]--;
  }
  vector<vector<int>> num(n,vector<int>(n));
  int now=0;
  rep(i,n)FOR(j,i+1,n){
    num[i][j]=now;
    now++;
  }
  rep(i,n)rep(j,n-2){
    int u=i,v=a[i][j];
    if(u>v) swap(u,v);
    int now=num[u][v];
    int k=i,l=a[i][j+1];
    if(k>l) swap(k,l);
    int nex=num[k][l];
    g[now].push_back(nex);
  }
  rep(i,now){
    if(!used[now]){
      int ret=dfs(i);
      if(ret==-1){
        cout<<-1<<endl;
        return 0;
      }
    }
  }
  int ans=0;
  rep(i,now){
    chmax(ans,dp[i]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 51328
//              **S.M.Shuzatul Hoque**
//             Created : 04 January 2020
//             Updated : 29 May     2020


#include<bits/stdc++.h>

#define sci(x) scanf("%d",&x)
#define sci2(x,y) scanf("%d %d",&x,&y)
#define scll(x) scanf("%lld",&x)
#define scll2(x,y) scanf("%lld %lld",&x,&y)
#define scd(x) scanf("%lf",&x)
#define scd2(x,y) scanf("%lf %lf",&x,&y)
#define scs(s) scanf("%s",s)
#define pfi(x) printf("%d",x)
#define pfll(x) printf("%lld",x)
#define pfd(x) printf("%f",x)
#define pfs(s) printf("%s",s)
#define pn() printf("\n")
#define ps() printf(" ")
#define pfdot() printf("...")

#define TestCase int tstcase,t; cin>>tstcase; while(tstcase--)

#define ll long long
#define pb push_back

#define PI (2*acos(0.0))

using namespace std;


int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stout);
    int a,b;
    sci2(a,b);

    a*=b;

    pfi(a);
    pn();







    return 0;
}
























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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

struct edge {
    int to, cost;
    edge(){}
    edge(int _to, int _cost) : to(_to), cost(_cost) {}
};
using Graph = vector<vector<edge>>;
vector<int> dijkstra(const Graph& G, int s, int g) {
    int n = G.size();
    priority_queue<Pii, vector<Pii>, greater<Pii>> pq;   // cost, vertex
    vi d(n, inf);
    d[s] = 0;
    pq.push(make_pair(0, s));

    while (!pq.empty()) {
        auto p = pq.top(); pq.pop();
        int v = p.second;
        if (v == g) break;
        if (d[v] < p.first) continue;
        for (const auto& e : G[v]) {
            if (d[v] <= e.cost && d[e.to] > e.cost) {
                d[e.to] = e.cost;
                pq.push(make_pair(d[e.to], e.to));
            }
        }
    }
    return d;
}

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

    int N, M;
    cin >> N >> M;
    Graph G(N);
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        G[a].emplace_back(b, c);
    }

    auto d = dijkstra(G, 0, -1);

    int ans = -1;
    rep(i, N) {
        for (auto e : G[i]) {
            if (e.to == N - 1 && d[i] <= e.cost) {
                ans = max(ans, e.cost);
            }
        }
    }

    cout << ans << endl;
}

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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int l = max(A,C);
  int r = min(B,D);
  if(l <= r){
    cout << r - l << endl;
  }else{
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
from collections import Counter

def factorization(n):
    d = Counter()
    m = 2
    while m ** 2 <= n:
        while n % m == 0:
            n //= m
            d[m] += 1
        m += 1
    if n > 1:
        d[n] += 1
    return d

n = int(input())
mod = 10 ** 9 + 7
fs = Counter()
for i in range(1, n + 1):
    fs += factorization(i)

ans = 1
for v in fs.values():
    ans *= v + 1
    ans %= mod
print(ans)


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

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

    int xa, xb, xc;
    xa = min(a, k);
    xb = min(k - xa, b);
    xc = k - xb - xa;

    int ans = 0;
    ans = xa - xc;
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include<stdio.h>

#define MAX_ARRAY 100001

void MergeSort(int array1[],int array2[],int Left,int Right){

    int i,j,k,center;
    int work_A[MAX_ARRAY],work_CO[MAX_ARRAY];

    if(Left<Right){
        center = (Left + Right)/2;
        MergeSort(array1,array2,Left,center);
        MergeSort(array1,array2,center+1,Right);

        for(i = center;i >= Left;i--){
            work_A[i] = array1[i];
            work_CO[i] = array2[i];
        }
        for(j = center + 1;j <= Right;j++){
            work_A[Right-(j-(center+1))] = array1[j];
            work_CO[Right-(j-(center+1))] = array2[j];
        }

        i = Left;
        j = Right;

        for(k = Left;k <= Right;k++){
            if(work_A[i] < work_A[j]){
                array1[k] = work_A[i];
                array2[k] = work_CO[i];
                i++;
            }else{
                array1[k] = work_A[j];
                array2[k] = work_CO[j];
                j--;
            }
        }
    }
}

int main(void){

    int A[MAX_ARRAY],ComeOrder[MAX_ARRAY];
    int N,i;

    scanf("%d",&N);
    for(i = 0;i < N;i++){
        scanf("%d",&A[i]);
        ComeOrder[i] = i+1;
    }

    /*printf("\nソート前；\n");
    for(i = 0;i < N;i++){
        printf("%d ",A[i]);
    }
    printf("\n");
    for(i = 0;i < N;i++){
        printf("%d ",ComeOrder[i]);
    }*/

    MergeSort(A,ComeOrder,0,N-1);

    /*printf("\nソート結果：\n");
    for(i = 0;i < N;i++){
        printf("%d ",A[i]);
    }
    printf("\n");*/
    for(i = 0;i < N;i++){
        printf("%d ",ComeOrder[i]);
    }

    printf("\n");

    return 0;
}

Measured memory_bytes: 14848
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (auto &e : a) cin >> e;
    
    int ans = 0;
    int sum = accumulate(a.begin(), a.end(), 0);
    for (auto e : a) {
        ans += (e * 4 * m >= sum);
    }
    cout << (ans >= m ? "Yes" : "No") << endl;
    return 0;
}

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

ans = 0
for i in range(10):
    a = S.find(str(i))
    if a == -1: continue
    for j in range(10):
        b = S.find(str(j), a + 1)
        if b == -1: continue
        for k in range(10):
            if S.find(str(k), b + 1) != -1:
                ans += 1

print(ans)

Measured memory_bytes: 3060
import sys
for line in sys.stdin:
    a, b, c, d, e, f = map(int, line.rstrip('\n').split(' '))
    x = int((e*c - b*f) * 1000 / (a*e - b*d)) / 1000.0
    y = int((a*f - d*c) * 1000 / (a*e - b*d)) / 1000.0
    print '%.3f %.3f' % (x, y)

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

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int A,B,C;
cin>>A>>B>>C;
int num = A*C <=B ? C:B/A; 
cout<<num<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
n=int(input())
xy=[]
for i in range(n):
  xy.append(list(map(int,input().split()))+[i])
  
x_sort=sorted(xy,key=lambda x:x[0])
y_sort=sorted(xy,key=lambda x:x[1])
edge=[]
for i in range(1,n):
  edge.append([min(abs(x_sort[i][1]-x_sort[i-1][1]),abs(x_sort[i][0]-x_sort[i-1][0])),x_sort[i][2],x_sort[i-1][2]])
  edge.append([min(abs(y_sort[i][1]-y_sort[i-1][1]),abs(y_sort[i][0]-y_sort[i-1][0])),y_sort[i][2],y_sort[i-1][2]])
edge.sort(key=lambda x:x[0])


#Union-Find
par=[i for i in range(n)]
deep=[1 for i in range(n)]
size=[1 for i in range(n)]
def find(x):
  if par[x]==x:
    return x
  else:
    return find(par[x])

def unite(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return
  if deep[x]<deep[y]:
    par[x]=y
    size[y]+=size[x]
  else:
    par[y]=x
    size[x]+=size[y]
    if deep[x]==deep[y]:
      deep[x]+=1

def same(x,y):
  return find(x)==find(y)

#クラスカル法
#n:頂点数　edge:重みでsortした辺のリスト
def kruskal(n,edge):
  res=0
  #w:重さ s:始点　t:終点
  for w,s,t in edge:
    if not same(s,t):
      unite(s,t)
      res+=w
  return res

#連結でコストが最小になるものを求める
#最小全域木

print(kruskal(n,edge))








  

Measured memory_bytes: 149944
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize n, x;
    std::cin >> n >> x;
    x--;
    usize N = 2 * n - 1;

    auto cal = [&]() -> vec<usize> {
        if (n==1) return {0};
        if (x==0 || x==N-1) {
            std::cout << "No" << '\n';
            exit(0);
        }
        if (n==2) return {0, 1, 2};

        vec<usize> ans(N, -1), ckd(N);
        auto assign = [&](usize i, usize j) {
            ans.at(i) = j;
            ckd.at(j) = true;
        };
        if (x+2<N) {
            assign(n-2, x+1);
            assign(n-1, x  );
            assign(n  , x-1);
            assign(n+1, x+2);
        } else {
            assign(n-2, x-1);
            assign(n-1, x  );
            assign(n  , x+1);
            assign(n+1, x-2);
        }

        for (usize i=0, j=0; i<N; i++) if (ans.at(i)==-1) {
            for (; ckd.at(j); j++);
            assign(i, j);
        }
        return ans;
    };

    auto ans = cal();
    std::cout << "Yes" << '\n';
    for (usize y: ans) {
        std::cout << y + 1 << '\n';
    }
}


Measured memory_bytes: 3328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atc_0028
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            string S = Console.ReadLine();

            string result = "";

            for (int i = 0; i < S.Length; i++)
            {
                char c = char.Parse(S.Substring(i, 1));

                c += (char)N;

                if ('Z' < c)
                {
                    c = (char)('A' + (c - 'Z' - 1));
                }

                result += c.ToString();
            }

            Console.WriteLine(result);

        }
    }
}


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

using namespace std;
#define maxv 4000010
bitset<maxv> reach;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int sum = 0;
	int N;
	reach |= 1;
	cin >> N;
	int cur;
	for (int i = 0; i < N; i++) {
		cin >> cur;
		reach |= reach << cur;
		sum += cur;
	}
	for (int i = (sum+1)/2; i <= sum; i++) {
		if (reach[i]) {
			cout << i << endl;
			break;
		}
	}
	cin >> N;
}

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

int main() {
    string S;
    cin >> S;
    const int N = S.size();
    stack<int> stk;
    stack<pair<int, int>> pond;
    for (int j = 0; j < N; ++j) {
        if (S[j] == '_') {
            // pass
        } else if (S[j] == '\\') {
            stk.push(j);
        } else if (S[j] == '/' && !stk.empty()) {
            int p = stk.top(); stk.pop();
            int area = j - p;
            while (!pond.empty() && p < pond.top().first) {
                area += pond.top().second;
                pond.pop();
            }
            pond.emplace(p, area);
        }
    }

    int sum_area = 0;
    while (!stk.empty()) stk.pop();
    while (!pond.empty()) {
        int t = pond.top().second;
        sum_area += t;
        stk.push(t);
        pond.pop();
    }

    cout << sum_area << endl;
    cout << stk.size();
    for (; !stk.empty(); stk.pop()) {
        cout << " " << stk.top();
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3208
import java.io.*;
public class Main {
 public static void main(String[] args){
  try{
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   char botton[][]={{' '},
                            {'\'' , ',' , '.' , '!' , '?'},
                            {'a' , 'b' , 'c' , 'A' , 'B' , 'C'},
                            {'d' , 'e' , 'f' , 'D' , 'E' , 'F'},
                            {'g' , 'h' , 'i' , 'G' , 'H' , 'I'},
                            {'j' , 'k' , 'l' , 'J' , 'K' , 'L'},
                            {'m' , 'n' , 'o' , 'M' , 'N' , 'O'},
                            {'p' , 'q' , 'r', 's' , 'P' , 'Q' , 'R' , 'S'},
                            {'t' , 'u' , 'v' , 'T' , 'U' , 'V'},
                            {'w' , 'x' , 'y' , 'z' , 'W' , 'X' , 'Y' , 'Z'}};
    int n[]={0,5,6,6,6,6,6,8,6,8};
    while(true){
     String s=br.readLine();
     s+="x";
     int sl=s.length();
     int cnt=1;
     
     for(int i=1;i<sl;i++){
      char x,ch;
      if(s.charAt(i-1)!=s.charAt(i)){
      x=s.charAt(i-1);
      if(x!='0'){
       ch=botton[x-'0'][(cnt-1)%n[x-'0']];
       System.out.print(ch);
      }
      else if(x=='0')for(int j=0;j<cnt-1;j++)System.out.print(" ");
      cnt=0;
      cnt++;
     }
     else cnt++;
    }
    System.out.print("\n");
  }
 }
 catch(Exception e){return ;}
}
}


Measured memory_bytes: 25176
//F5で実行 Shift+F5で停止
//F9でブレークポイント
#include<cmath>
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
//Ctrl+PageUpで上部の大半を選択できる
// 1e18 = 10の18乗

//atcoder 1秒は O(10^8)以上でTLE

//関数の中で宣言するとスタック領域に確保してしまい、
//スタックオーバーフローの恐れあり

int N;
int A[2 * 1000 * 100];

//2*10^5 + (ソート速度) = O(2*10^5)

void _main() {
	cin >> N;
	rep(i, 0, N) {
		cin >> A[i];
	}

	string ans = "YES";

	//配列をソート
	sort(A, A + N);

	//forループしてA[i]=A[i+1]なら"NO"を返す
	rep(i, 0, N-1) {
		if (A[i] == A[i + 1]) ans = "NO";
	}


	cout << ans <<  endl;
}

Measured memory_bytes: 1152
N, K = gets.split.map &:to_i
A = gets.split.map &:to_i

A.unshift(0)

if K <= N
  curr = 1
  K.times{ curr = A[curr] }
  p curr
  exit
end

visited = [false] * (N + 1)
route = []
curr = 1
while !visited[curr]
  route << curr
  visited[curr] = true
  curr = A[curr]
end

pre = route.index(curr)
period = route.size - pre
p route[pre + (K - pre) % period]


Measured memory_bytes: 31044
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9+7
S = int(readline())
f = [0]*2001
f[0] = 1
for i in range(3,S+1):
    f[i] = (f[i-1] + f[i-3]) % MOD
print(f[S])

Measured memory_bytes: 63380
#include<iostream>
using namespace std;
long long int a[300000];
long long int b[300000][60];
long long int c[60];
long long int sum;
long long int MOD = 1000000007;
int main() {

	//abc147_d
	long long int i, n, j;
	cin >> n;
	long long int bin[61];
	bin[0] = 1;
	for (i = 1; i < 61; i++) {
		bin[i] = bin[i - 1] * 2;
	}
	for (i = 0; i < n; i++) {
		cin >> a[i];
		j = 0;
		while (a[i] > 0) {
			if (a[i] % 2 == 1) {
				b[i][j] = 1;
				c[j]++;
			}
			else {
				b[i][j] = 0;
			}
			a[i] = a[i] / 2;
			j++;
		}
	}
	for (i = 0; i < 60; i++) {
		j = (c[i] * (n - c[i])) % MOD;
		j = (j * (bin[i] % MOD)) % MOD;
		sum = (sum + j) % MOD;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 146436
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
 
typedef long long ll;
 
 
int main(){
	
	int n;
	cin >>n;
	cout << n * n * n <<endl;
	
	return 0;
}



Measured memory_bytes: 256
/*starting with the name of almighty ALLAH*/
/*solved by RAKIB JOY*/
/*solved by RAKIB JOY*/
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>

int main()
{
    char a[102];
    gets(a);
    int x=strlen(a),i,j;
    for(i=0,j=x-1 ; i<=x/2,j>=x/2 ; i++,j--)
    {
        if(a[i]!=a[j])
        {
            printf("No\n");
            return 0;
        }
    }
    for(i=0,j=x/2-1 ; i<=x/2-1,j>=0 ; i++,j--)
    {
        if(a[i]!=a[j])
        {
             printf("No\n");
            return 0;
        }
    }
    for(i=x/2+1,j=x-1 ; i<=x-1,j>=x/2+1 ; i++,j--)
    {
        if(a[i]!=a[j])
        {
             printf("No\n");
            return 0;
        }
    }

     printf("Yes\n");
    return 0;
}



Measured memory_bytes: 128
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    ll n, m;
    cin >> n >> m;
    if (n == 1 || m == 1)
    {
        cout << "1";
        return 0;
    }
    if (n % 2 == 0 || m % 2 == 0)
        cout << n * m / 2;
    else
        cout << n * m / 2 + 1;
    return 0;
}


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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n; cin >> n;
  vector<ll> acca, accb;
  for(int i = 0; i < n; i++){
    ll a, b; cin >> a >> b;
    acca.push_back(a);
    accb.push_back(b);
  }
  sort(acca.begin(), acca.end());
  sort(accb.begin(), accb.end());

  if(n%2) cout << accb[n/2] - acca[n/2] + 1 << endl;
  else cout << ((accb[n/2-1]+accb[n/2]) - (acca[n/2-1]+acca[n/2])) + 1 << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


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

int main() {
    int n, m;
    cin >> n >> m;

    vector<pair<int, int>> a;
    rep(i, n){
        pair<int, int> p;
        cin >> p.first;
        p.second = 1;
        a.push_back(p);
    }
    rep(i, m){
        pair<int, int> p;
        cin >> p.second >> p.first;
        a.push_back(p);
    }

    sort(all(a), [](pair<int, int> l, pair<int, int> r){
        return l.first > r.first;
    });

    int64_t ans = 0;
    for(pair<int, int> p : a){
        ans += (int64_t)p.first * (p.second < n ? p.second : n);
        n -= p.second;
        if(n <= 0)break;
    }

    cout << ans;
}

Measured memory_bytes: 2420
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
 
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
   
using namespace std;
   
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
   
static const double EPS = 1e-8;
   
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

class Edge {
public:
  int to;
  int cost;
  Edge(int to, int cost) {
    this->to = to;
    this->cost = cost;
  }
};

int dfs(int pos, int cost, int cicadas[1001], vector<Edge> edges[1001]){
  int res = 0;
  if(cicadas[pos] > 0) return cost;

  for(int next_i = 0; next_i < edges[pos].size(); next_i++){
    int to = edges[pos][next_i].to;
    res += dfs(to,edges[pos][next_i].cost,cicadas,edges);
  }
  return min(res,cost);
}

int main(){
  int num_of_vertex;
  while(~scanf("%d",&num_of_vertex)){
    int cicadas[1001] = {};
    for(int vertex_i = 1; vertex_i < num_of_vertex; vertex_i++){
      int num_of_cicadas;
      scanf("%d",&num_of_cicadas);
      cicadas[vertex_i] = num_of_cicadas;
    }

    vector<Edge> edges[1001];
    for(int vertex_i = 0; vertex_i < num_of_vertex - 1; vertex_i++){
      int from,to,cost;
      cin >> from >> to >> cost;
      edges[from].push_back(Edge(to,cost));
    }
    
    printf("%d\n",dfs(0,INF,cicadas,edges));
  }
}

Measured memory_bytes: 1272
N,M,*P = $<.read.split.map &:to_i
A = (0..N).map {[]}
P.each_slice(2) {|a,b|  A[a] << b; A[b] << a }
1.upto(N) {|i|
  next  if (a=A[i]).frozen?
  A[i] = i
  while j = a.pop
    next  if (b=A[j]).frozen?
    a.concat b
    A[j] = i
  end
}
p A.tally.values.max

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

using namespace std;

const long long MOD = 1e9 + 7;

int fac[100500];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  fac[0] = fac[1] = 1;
  for(int i=2; i<=100000; i++) fac[i] = 1ll * fac[i-1] * i % MOD;
  int n, m;
  cin >> n >> m;
  if(abs(n - m) > 1){
    cout << "0" << endl;
    return 0;
  }
  if(n == m){
    cout << 1ll * fac[n] * fac[m] * 2 % MOD << endl;
  }else{
    cout << 1ll * fac[n] * fac[m] % MOD << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;
int main(void){
    int A,B,C;
    cin >> A >> B >> C;
    int ary[3] = {A,B,C};    // 配列を用意する。
    sort(ary, ary + 3);
    int result =0;
    // Aが小さい
    A=ary[0];
    B=ary[1];
    C=ary[2];
    result+=floor((C-B)/2);
    result+=floor((C-A)/2);
    if(A%2==B%2 && B%2==C%2){
    }else if(A%2==B%2 && B%2==(C+1)%2){
        result++;
    }else{
        result+=2;
    }
    cout << result << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp112 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());
            var a = new int[N];
            var b = new int[N];
            var c = new int[N];
            
            for (int i = 0; i < N; i++) {
                var x = Console.ReadLine().Split().Select(int.Parse).ToArray();

                a[i] = x[0];
                b[i] = x[1];
                c[i] = x[2];
            }

            var dp = new int[N + 2, 3];
            dp[0, 0] = a[0];
            dp[0, 1] = b[0];
            dp[0, 2] = c[0];

            for (int i = 1; i < N; i++) {
                dp[i, 0] = Math.Max(dp[i - 1, 1] + a[i], dp[i - 1, 2] + a[i]);
                dp[i, 1] = Math.Max(dp[i - 1, 0] + b[i], dp[i - 1, 2] + b[i]);
                dp[i, 2] = Math.Max(dp[i - 1, 0] + c[i], dp[i - 1, 1] + c[i]);

            }

            int ans = Math.Max(Math.Max(dp[N - 1, 0], dp[N - 1, 1]), dp[N - 1, 2]);

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 17464
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


void solve() {
    int N, D, A; cin >> N >> D >> A;
    vector<pair<int, int>> monster(N);
    vector<int> pos(N);
    for (int i = 0; i < N; i++) {
        int X, H; cin >> X >> H;
        pos[i] = X;
        monster[i] = make_pair(X, H);
    }

    sort(pos.begin(), pos.end());
    sort(monster.begin(), monster.end());

    vector<int> attack(N);

    long long ans = 0;

    attack[0] = (monster[0].second + A - 1) / A;
    auto it = upper_bound(pos.begin(), pos.end(), pos[0] + 2 * D);
    if (it != pos.end()) attack[it - pos.begin()] -= (monster[0].second + A - 1) / A;

    ans += (monster[0].second + A - 1) / A;


    for (int i = 1; i < N; i++) {

        attack[i] += attack[i-1];
        monster[i].second -= attack[i] * A;

        if (monster[i].second <= 0) continue;

        attack[i] += (monster[i].second + A - 1) / A;
        auto itr = upper_bound(pos.begin(), pos.end(), pos[i] + 2 * D);
        if (itr != pos.end()) attack[itr - pos.begin()] -= (monster[i].second + A - 1) / A;

        ans += (monster[i].second + A - 1) / A;
    }

    cout << ans << endl;
}


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

Measured memory_bytes: 6332
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }

void dfs(int n, char mx, string S){
    if(n == S.length()){
        cout << S << "\n";
        return;
    }
    for(char c = 'a'; c <= mx + 1;c++) dfs(n,max(mx,c),S + c);
}

//ミョ(-ω- ?)
int main() {
    int n;
    cin >> n;
    dfs(n,'a'-1,"");
    return 0;
}

Measured memory_bytes: 3600