akhauriyash/Code-Regression huggingface dataset:
/***************************************************
 * Problem Name : A.cpp
 * Problem Link :
 * Contest Name :
 * OJ           :
 * Verdict      : Trying
 * Date         : 2018-10-27
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdlib>
#include<deque>
#include<stack>
#include<map>
#include<set>
#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define SET(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define pll pair <ll, ll>
#define debug cout <<"#########\n";
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define Pow2(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define Max3(a, b, c) max(a, max(b, c))
#define Min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define MAX 100005
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
std::string NumberToString ( T Number ) {
    std::ostringstream ss;
    ss << Number;
    return ss.str();
}
ll lcm(ll a, ll b) {
    return a * b / __gcd(a, b);
}
/************************************ Code Start Here ******************************************************/
int main () {
    //~ __FastIO;
    string str;
    cin >> str;
    if(str.size() == 2){
		cout << str << "\n";
	}
	else{
		reverse(all(str));
		cout << str << "\n";
	}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>


int main(void){
int N;
std::cin >> N;
std::vector<int> vec(N);
for(int i = 0; i < N; ++i){
std::cin >> vec[i];
}

int sum = std::accumulate(vec.begin(), vec.end(), 0);
if(sum % 10 == 0){
std::sort(vec.begin(), vec.end());
for(auto i : vec){
 if(i % 10 == 0){ continue; }
 else{ sum -= i; break; }
}
}
if(sum % 10 == 0){ sum = 0;}
std::cout << sum << std::endl;
return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    string s,t;
    i32 n,m,p,q,r;
    cin >> n;

    i32 cnt = 0;
    rep1(i,n) {
        if(i%3!=0) {
            if(i%5!=0) {
                cnt += i;
            }
        }
    }

    cout <<      cnt   << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 3676
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<tuple>
#include<stdio.h>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Q;
typedef pair<Q,ll> R;
ll longinf=1ll<<60;
int inf=1<<29;
//mleしなければぜんぶllでかく。

int main(){
	int n;
	cin>>n;
	vector<P> ans;
	if((n&1)==0){
		for(int i=1;i<n;i++){
			for(int j=i+1;j<=n;j++){
				if((i+j)!=(n+1)){
					ans.push_back(make_pair(i,j));
				}
			}
		}
	}
	else{
		for(int i=1;i<n-1;i++){
			for(int j=i+1;j<=n-1;j++){
				if((i+j)!=n){
					ans.push_back(make_pair(i,j));
				}
			}
		}
		for(int i=1;i<=n-1;i++){
			ans.push_back(make_pair(i,n));
		}
	}
	cout<<ans.size()<<endl;
	for(auto a:ans){
		cout<<a.first<<" "<<a.second<<endl;
	}
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, t=0, color[N], d[N], f[N], M[N][N]; 

void visit(int u){

  int i;
  
  color[u] = GRAY;
  d[u] = ++t;
  for(i=0; i<n; i++){
    if(M[u][i] == 0) continue;
    if(color[i] == WHITE){
       visit(i);
    }
  }
  color[u] = BLACK;
  f[u] = ++t;

}

void dfs(){

  int i;
  
  for(i=0; i<n; i++){
    color[i] = WHITE;
  }
  t = 0;
  for(i=0; i<n; i++){
    if(color[i] == WHITE){
      visit(i);
    }
  }
  
}

int main(){

  int i, j, u, k, v;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      M[i][j] = 0;
    }
  }

  for(i=0; i<n; i++){
    scanf("%d%d", &u, &k);
    u--;
    for(j=0; j<k; j++){
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }

  dfs();

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

  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 0 && b >= 0) {
		cout << "Zero" << endl;
		return 0;
	}
	if (a == 0 || b == 0) {
		cout << "Zero" << endl;
		return 0;
	}
	if (a > 0 && b > 0) {
		cout << "Positive" << endl;
		return 0;
	}
	if (a < 0) {
		if ((b - a) % 2 == 1) {
			cout << "Positive" << endl;
			return 0;
		} else {
			cout << "Negative" << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
class Dice:
    def __init__(self, top: str, front: str, right: str, left: str, back: str, bottom: str) -> None:
        self.top = top
        self.front = front
        self.right = right
        self.left = left
        self.back = back
        self.bottom = bottom

    def __eq__(self, other) -> bool:
        for directions in ['', 'N', 'SE', 'WW', 'ES', 'S']:
            for direction in directions:
                other.roll(direction)

            for _ in range(4):
                other.rotate_right()
                if (
                        self.top == other.top
                        and self.front == other.front
                        and self.back == other.back
                        and self.right == other.right
                        and self.left == other.left
                        and self.bottom == other.bottom
                ):
                    return True
        return False

    def print_top(self):
        print(self.top)

    def print_right(self):
        print(self.right)

    def roll(self, direction: str) -> None:
        if direction == 'S':
            self.south()
        elif direction == 'N':
            self.north()
        elif direction == 'E':
            self.east()
        elif direction == 'W':
            self.west()

    def north(self):
        [self.top, self.back, self.bottom, self.front] = [self.front, self.top, self.back, self.bottom]

    def south(self):
        [self.top, self.back, self.bottom, self.front] = [self.back, self.bottom, self.front, self.top]

    def east(self):
        [self.top, self.right, self.bottom, self.left] = [self.left, self.top, self.right, self.bottom]

    def west(self):
        [self.top, self.right, self.bottom, self.left] = [self.right, self.bottom, self.left, self.top]

    def rotate_right(self) -> None:
        for direction in 'SWN':
            self.roll(direction)


n = int(input())
dices = []
for _ in range(n):
    dices.append(Dice(*input().split()))

dice1 = dices[0]
all_different = all(map(lambda dice: dice != dice1, dices[1:]))
if all_different:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 5636
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {//239///F.Sugoroku
	string s;
	cin>>s;
	if(s=="Sunny")cout<<"Cloudy";
	else if(s=="Cloudy")cout<<"Rainy";
	else cout<<"Sunny";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3648
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int k;
  cin >> k;
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << a[k-1] << endl;
  return 0;
}


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

int main(){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x3, y3, x4, y4;
    int a = x2 - x1;
    int b = y2 - y1;
    x3 = x2-b; x4= x1 - b;
    y3 = y2+a; y4= y1+a;

    printf("%d %d %d %d\n", x3, y3, x4, y4);
    return 0;
}

Measured memory_bytes: 3732
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
typedef long long ll;
#define N 66
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;
}
int n;
map<pair<int,int>,int> cnt;
ll ans;
inline ll _gcd(ll a,ll b){
	if(b==0)return a;
	return _gcd(b,a%b);
}
int main(){
	n=read();
	for(int i=1;i<=n;++i){
		ll a=0,b=1;
		char c=getchar();
		while(c<'0'||c>'9')c=getchar();
		while(c>='0'&&c<='9'){
			a=a*10+c-'0';
			c=getchar();
		}
		if(c=='.'){
			c=getchar();
			while(c>='0'&&c<='9'){
				a=a*10+c-'0';
				b=b*10;
				c=getchar();
			}
		}
		ll g=_gcd(a,b);
		a/=g,b/=g;
		int A=0,B=0;
		while(a%2==0)++A,a>>=1;
		while(a%5==0)++B,a/=5;
		while(b%2==0)--A,b>>=1;
		while(b%5==0)--B,b/=5;
		for(auto x:cnt){
			if(A+x.first.first>=0&&B+x.first.second>=0)ans+=x.second;
		}
		++cnt[make_pair(A,B)];
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3596
#include <iostream>
using namespace std;
 
int main() {

  int a,b,i,x;
  cin >> a >> b;
  int k[5];

  int ans=0;

  for(i = a; i<=b;i++){
    x = i;
    for(int j = 0;j<5;j++){
      k[j] = x%10;
      x /=10;
    }

    if(k[0]==k[4] && k[1]==k[3]) {
      ans++;
      }
  }

  cout << ans;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n, jud = 0;
int main(void){
    // Your code here!
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a % 2 == 1) jud++;
    }
    if (jud % 2 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
/*
AizuOnline A2000
Title Misterious Gems
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
struct g_st
{ int x;
  int y;
  int flag;
} gem[20];

  int m,n;
int xpos,ypos;
//
main()
{
  int i,j,k,kosuu,d;
  char dir;
  int *ptr,delta;

  while(EOF!=scanf("%d ",&n) && n)
    {
      //printf("N=%d",n);
      for(i=0;i<n;i++)
	{
	  scanf("%d %d ",&(gem[i].x),&(gem[i].y));
	  //printf("xy=%d %d",gem[i].x,gem[i].y);
	  gem[i].flag=0;
	}
      xpos=10;ypos=10;kosuu=0;
      scanf("%d ",&m);
      //printf("M=%d",m);
      for(i=0;i<m;i++)
	{
	  scanf("%c %d ",&dir,&d);
	  switch(dir)
	    {
	    case 'N':
	      ptr = &ypos;
	      delta=1;
	      break;
	    case 'S':
	      ptr = &ypos;
	      delta=-1;
	      break;
	    case 'W':
	      ptr = &xpos;
	      delta=-1;
	      break;
	    case 'E':
	      ptr = &xpos;
	      delta=1;
	      break;
	    }
	  for(k=0;k<d;k++)
	    {
	      *ptr += delta;
	      //printf("XY=%d %d",xpos,ypos);
	      for(j=0;j<n;j++)
		if(gem[j].x==xpos && gem[j].y ==ypos && gem[j].flag==0)
		  {
		    //printf("*");
		    kosuu++;
		    gem[j].flag=1;
		  }
	    }
	}
      //printf("km %d %d",kosuu,n);
      if(kosuu==n)
	printf("Yes\n");
      else
	printf("No\n");
    }
return(0);
}

Measured memory_bytes: 588
import math

N, HP = map(int, input().split())

hit = 0
throw = []
for i in range(N):
    h, t = map(int, input().split())
    if h > hit:
        hit = h
    throw.append(t)

throw.sort()

ans = 0
for t in throw[::-1]:
    if t < hit:
        break
    else:
        ans += 1
        HP -= t
        if HP <= 0:
            break
if HP > 0:
    ans += HP // hit
    if HP % hit != 0:
        ans += 1

print(ans)

Measured memory_bytes: 7848
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		StringTokenizer st = new StringTokenizer(br.readLine());
		
		int N = Integer.parseInt(st.nextToken());
		int R = Integer.parseInt(st.nextToken());
		
		int ans = (N < 10) ? 100 * (10 - N) + R : R;
		
		System.out.println(ans);
	}

}

Measured memory_bytes: 32572
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
using Graph = vector<vector<int>>;

vector<int> path; //パス

int N, M;

void dfs(const Graph &G, int v, long long &ans){
	if(path.size() == N){
		ans++;
		return;
	}

	for(auto nv : G[v]){
		int found = 0;
		for(int i=0; i<path.size(); i++){
			if(path[i] == nv){
				found = 1;
				break;
			}
		}
		if(found == 1) continue;
		path.push_back(nv);
		dfs(G, nv, ans);
		path.pop_back();
	}
}

int main(int argc, char* argv[]){
	cin >> N >> M;
  
	Graph G(N+1);
	for(int i=1; i<=M; i++){
		int a, b;
		cin >> a >> b;
		G[a].push_back(b); G[b].push_back(a);
	}

	long long ans = 0;
	path.push_back(1);
	dfs(G, 1, ans);
	cout << ans << endl ;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repi(i, a, b) for (long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

int main()
{
    int a, b, x;
    cin >> a >> b >> x;
    if (a <= x && b  > x - a)
    {
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
while True:
    m,f,r=map(int,input().split())

    if m==-1 and f==-1 and r==-1:
        break
    
    if m ==-1 or f == -1:
        print('F')
        
    elif m + f >=80:
        print('A')
        
    elif 65<=m+f and m+f<80:
        print('B')
    
    elif 50<=m+f and m+f<65:
        print('C')
        
    elif 30<=m+f and m+f<50:    
        if r >=50:
            print('C')
        else:
            print('D')
    else:
        print('F')


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

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

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

int main(void) {
  int n;
  cin>>n;
  vector<int> v(n);
  for(int i=0; i<n; i++)
    cin>>v[i];
  int c=0;
  for(int i=1; i<n-1; i++) {
    if(v[i-1]<v[i] and v[i]<v[i+1]) {
      c++;
    } else if(v[i+1]<v[i] and v[i]<v[i-1]) {
      c++;
    }

  }
  std::cout << c << std::endl;
  
  return 0;
}



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

int main(){
    int H, W;
    while(true){
        cin >> H >> W;
        if (W == 0 && H == 0) break;
        for(int i = 0; i < H; i ++){
            for(int j = 0; j < W; j ++){
                if((i + j) & 1){
                    cout << '.';
                }else{
                    cout << '#';
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  int init_x_max, init_x_min, init_y_max, init_y_min;
  init_x_max = init_y_max = INT_MIN;
  init_x_min = init_y_min = INT_MAX;
  int h_y_min, h_y_max, v_x_min, v_x_max;
  h_y_min = v_x_min = INT_MAX;
  h_y_max = v_x_max = INT_MIN;
  int up_y_min, up_y_max, down_y_max, down_y_min, l_x_min, l_x_max, r_x_min, r_x_max;
  up_y_min = down_y_min = l_x_min = r_x_min = INT_MAX;
  up_y_max = down_y_max = l_x_max = r_x_max = INT_MIN;
  double ans;
  for (int i = 0; i < N; i++) {
    int x, y;
    char d;
    cin >> x >> y >>d;
    init_x_max = max(x, init_x_max);
    init_x_min = min(x, init_x_min);
    init_y_max = max(y, init_y_max);
    init_y_min = min(y, init_y_min);
    if (d == 'L') {
      l_x_max = max(x, l_x_max);
      l_x_min = min(x, l_x_min);
    } else if (d == 'R') {
      r_x_max = max(x, r_x_max);
      r_x_min = min(x, r_x_min);
    } else if (d == 'U') {
      up_y_min = min(up_y_min, y);
      up_y_max = max(up_y_max, y);
    } else if (d == 'D') {
      down_y_min = min(down_y_min, y);
      down_y_max = max(down_y_max, y);
    }
    if (d == 'L' || d == 'R') {
      h_y_max = max(h_y_max, y);
      h_y_min = min(h_y_min, y);
    } else {
      v_x_max = max(v_x_max, x);
      v_x_min = min(v_x_min, x);
    }
  }
  ans = (long long)(init_x_max - init_x_min) * (init_y_max - init_y_min);
  vector<double> candidate_time;
  // y_max
  if (up_y_max < h_y_max) {
    candidate_time.push_back(h_y_max - up_y_max);
  }
  if (down_y_max > max(h_y_max, up_y_max)) {
      candidate_time.push_back((down_y_max - up_y_max) / 2.);
      candidate_time.push_back(down_y_max - h_y_max);
  }
  // y_min
  if (down_y_min > h_y_min) {
    candidate_time.push_back(down_y_min - h_y_min);
  }
  if (up_y_min < min(down_y_min, h_y_min)) {
    candidate_time.push_back((down_y_min - up_y_min) / 2.);
    candidate_time.push_back(h_y_min - up_y_min);
  }
  // x_max
  if (r_x_max < v_x_max) {
    candidate_time.push_back(v_x_max - r_x_max);
  }
  if (l_x_max > max(v_x_max, r_x_max)) {
    candidate_time.push_back(l_x_max - v_x_max);
    candidate_time.push_back((l_x_max - r_x_max) / 2.);
  }
  // x_min
  if (l_x_min > v_x_min) {
    candidate_time.push_back(l_x_min - v_x_min);
  }
  if (r_x_min < min(l_x_min, v_x_min)) {
    candidate_time.push_back(v_x_min - r_x_min);
    candidate_time.push_back((l_x_min - r_x_min) / 2.);
  }
  auto calc =[&](double t) {
    double min_x = min({double(v_x_min), l_x_min - t, r_x_min + t});
    double min_y = min({double(h_y_min), up_y_min + t, down_y_min - t});
    double max_x = max({double(v_x_max), l_x_max - t, r_x_max + t});
    double max_y = max({double(h_y_max), up_y_max + t, down_y_max - t});
    ans = min(ans, (max_x - min_x) * (max_y - min_y));
  };
  for (auto t : candidate_time) {
    calc(t);
  }
  cout << fixed << setprecision(10) << ans << '\n';

  
}


Measured memory_bytes: 256
import numpy as np
def absnuke(a, b, n):
    sum = 0
    for i in range(n):
        sum += abs(a[i]-(b+i+1))
    return sum

n = int(input())
a = list(map(int, input().split()))

b = [a[i]-(i+1) for i in range(n)]
c = sorted(b)
x = int(np.median(c))
print(absnuke(a, x, n))


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int two(int n){
    int res = 0;
    while(n % 2 == 0){
        res++;
        n /= 2;        
    }

    return res;
}

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

    int a, b, c;
    cin >> a >> b >> c;

    if(a == b && b == c && a % 2 == 0){
        cout << -1 << endl;
        return 0;
    }
    int ans = 0;
    while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
        int A = b / 2 + c / 2;
        int B = a / 2 + c / 2;
        int C = b / 2 + a / 2;

        a = A;
        b = B;
        c = C;
        ans++;
    }


    cout << ans << endl;

    return 0;
}

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

int main() {
	// your code goes here
	int x,y;
	cin>>x>>y;
	int max=x*4;
	int min=x*2;
	bool flag=false;
	if(y>=min && y<=max){
	    if(y%2==0){
	        flag=true;
	    }
	}
	if(flag){
	    cout<<"Yes"<<endl;
	}else{
	    cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>

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

	for (int i = 1; i <= 1000; ++i) {
		if (static_cast<int>(i * 0.08) == a && static_cast<int>(i * 0.1) == b) {
			std::cout << i << std::endl;
			return 0;
		}
	}

	std::cout << -1 << std::endl;
}

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

ll X;

const int R = 120;

int main(){
	cin >> X;
	ll q[R*2+1];
	for ( ll i = -R; i <= R; i++ )
		q[R+i] = i*i*i*i*i;
	
	
	for ( int a = -R; a <= R; a++ ){
		for ( int b = -R; b <= R; b++ ){
			if ( q[R+a] - q[R+b] == X ){
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}
	
	return 0;
}



Measured memory_bytes: 3644
#include<stdio.h>
int main(void){
    int d,J,M,j,m,a,b,c,e,f;
    scanf("%d %d %d %d %d",&d,&J,&M,&j,&m);
    a=J/j;
    b=J%j;
    if(b!=0){
       a=a+1;
    }
    c=M/m;
    e=M%m;
    if(e!=0){
        c=c+1;
    }
    if(a<=c){
        f=d-c;
    }else{
    f=d-a;
    }
    printf("%d\n",f);
return 0;
}

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

int main()
{
   int n, i;
   cin >> n;
   int a[n];

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

   int m = a[0];
   int ans = 1;

   for(int i=1; i<n; i++)
   {
   		m = max(m,a[i]);
   		if(a[i]>=m)
   			ans++;
   }

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner io = new Scanner(System.in);
		String O = io.next();
		String E = io.next();
		StringBuffer buffer = new StringBuffer();
		int Oi=0,Ei=0;
		while(Oi<O.length()){
			buffer.append(O.charAt(Oi));
			Oi ++;
			if(Ei>=E.length()) break;
			buffer.append(E.charAt(Ei));
			Ei ++;
		};
		
		System.out.println(buffer.toString());
		
	}	
}	

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


int main(){
    
    int a,b;
    cin>>a>>b;
    int c=a*b;
    if(c%2!=0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define tt this->
#define ll long long
using namespace std;
int main ()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
while (-1)
{
    c=c-b;
    if (d<=0)break;
    a=a-d;
    if(a<=0)break;

}

if (c<=0)cout<<"Yes";
else
    cout<<"No";
    return 0;
}

/*
▀█████████▄     ▄████████    ▄████████    ▄████████
  ███    ███   ███    ███   ███    ███   ███    ███
  ███    ███   ███    ███   ███    ███   ███    ███
 ▄███▄▄▄██▀    ███    ███  ▄███▄▄▄▄██▀   ███    ███
▀▀███▀▀▀██▄  ▀███████████ ▀▀███▀▀▀▀▀   ▀███████████
  ███    ██▄   ███    ███ ▀███████████   ███    ███
  ███    ███   ███    ███   ███    ███   ███    ███
▄█████████▀    ███    █▀    ███    ███   ███    █▀
                            ███    ███

*/


Measured memory_bytes: 3516
#include<iostream>
#include<algorithm>
using namespace std;
int n, s, dp[10][1<<10][331]; //nの制約は自明だけど sはどれくら(ry ← 331か
int rec( int now, int used,int sum){
  if( sum < 0 ) return 0;
  if( now == n ) return sum == 0;
  if(~dp[now][used][sum]) return dp[now][used][sum];
  int ret = 0;
  for(int i = 0 ; i < 10 ; i++ ){
    if((used >> i) & 1)
      ret += rec( now + 1, used&~(1 << i), sum - i * (now + 1));
  }
  return dp[now][used][sum] = ret;
}
int main(){
  while(cin >> n >> s){
    fill_n( **dp, 10 * (1 << 10) * 331, -1);
    cout << rec( 0, (1 << 10) - 1, s) << endl;
  }
}

Measured memory_bytes: 14400
n=int(input())
xi,yi,hi=[],[],[]
for i in range(n):
    num=[int(j) for j in input().split()]
    xi+=[num[0]]
    yi+=[num[1]]
    hi+=[num[2]]
ans=[0,0,0]
for i in range(101):
    for j in range(101):
        hoge=10**9+10
        for k in range(n):
            hight=hi[k]+abs(xi[k]-i)+abs(yi[k]-j)
            if(hi[k]==0):
                continue
            if(i==xi[k] and j==yi[k]):
                hight=hi[k]
            if(hoge==10**9+10):
                hoge=hight
            elif(hoge!=hight):
                break
        else:
            flg=True
            for k in range(n):
                hight=max(hoge-abs(xi[k]-i)-abs(yi[k]-j),0)
                if(hi[k]!=hight):
                    flg=False
                    break
            if(flg):
                ans=[i,j,hoge]
print(*ans,sep=" ")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll N,K,ans=INF;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i,N) cin >> A.at(i);
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<15> s(tmp);
    if(s.count()!=K){
      continue;
    }
    ll m=0,n=0;
    rep(i,N){
      if(s.test(i)){
        if(m>=A.at(i)){
          n+=m-A.at(i)+1;
          m++;
        }
      }
      m=max(m,A.at(i));
    }
    ans=min(ans,n);
  }
  cout << ans << endl;
}

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

int main(){
    int m, d; cin >> m >> d;
    int ans = 0;
    for(int j = 1; j <= m; j++){
    for(int i = 1; i <= d; i++){
        int d1 = i % 10, d10 = i/10;
        if(d1 < 2 || d10 < 2) continue;
        else if(j == d1 * d10) ans++;
    }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
from collections import deque


def main():
    total = 0
    s1 = deque()
    s2 = deque()
    str = input()
    for i in range(len(str)):
        if str[i] == "\\":
            s1.append(i)
        elif len(s1) > 0 and str[i] == "/":
            old = s1.pop()
            tmp = 0
            while len(s2) > 0 and old < s2[-1][0]:
                tmp += s2.pop()[1]
            s2.append([old, tmp + i - old])

    for i in range(len(s2)):
        total += s2[i][1]
    print(total)
    if s2:
        print(len(s2), end="")
        for i in range(len(s2)):
            if i == len(s2) - 1:
               print(" {}".format(s2[i][1]))
            else:
               print(" {}".format(s2[i][1]), end="")
    else:
        print(len(s2))

if __name__ == '__main__':
    main()



Measured memory_bytes: 6764
import sys
input = sys.stdin.readline
import collections
def main():
    N = int(input())
    a = list(map(int,input().split()))
    l = collections.Counter(a)
    l = list(l.items())
    count = 0
    for i in range(len(l)):
        count += l[i][1]-1

    print(N-(-(-count//2)*2))

if __name__ == "__main__":
    main()

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

int N, A[3][3], b[10];
bool appear[3][3];

int main() {
   for(int i = 0; i < 3; i++) {
      for(int j = 0; j < 3; j++) 
	     cin >> A[i][j];
   }
   
   cin >> N;
   for(int i = 0; i < N; i++) 
      cin >> b[i];
   
   for(int i = 0; i < N; i++) { 
      for(int j = 0; j < N; j++) {
	     appear[i][j] = false;
		 for(int k = 0; k < N; k++) {
		    if(A[i][j] == b[k]) appear[i][j] = true;
		 }
	  }
   }
   
   string ANS = "No";
   for(int i = 0; i < 3; i++) {
      if(appear[i][0] && appear[i][1] && appear[i][2])
	     ANS = "Yes";
   }
   
   for(int i = 0; i < 3; i++) {
      if(appear[0][i] && appear[1][i] && appear[2][i]) 
	     ANS = "Yes";
   }
   
   if(appear[0][0] && appear[1][1] && appear[2][2]) 
      ANS = "Yes";
   
   if(appear[0][2] && appear[1][1] && appear[2][0]) 
      ANS = "Yes";
   
   cout << ANS << endl;
   return 0;
}


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

#define INF INT_MAX/2;
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long ;

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

   int N,Y;
   cin>>N>>Y;
   int x,y,z;
   bool flg = false;
   for(int i=0;i<=N;i++){
      for(int j=0;j<=N-i;j++){
         if(Y==10000*i+5000*j+1000*(N-i-j)){
            flg = true;
            x=i;
            y=j;
            z=N-i-j;
         }
      }
   }
   if(flg)cout<<x<<" "<<y<<" "<<z;
   else cout<<-1<<" "<<-1<<" "<<-1;
   return 0; 
}


Measured memory_bytes: 256
using System;
using System.Linq;

class P
{
  static void Main()
  {
    var a = Console.ReadLine()
            .Split(' ')
            .Select(x => int.Parse(x))
            .ToArray();
    var W = a[0];
    var H = a[1];
    var x_ = a[2];
    var y = a[3];
    var r = a[4];

    if(x_ - r < 0
      || x_ + r > W
      || y - r < 0
      || y + r > H)
      Console.WriteLine("No");
    else
      Console.WriteLine("Yes");
  }
}

Measured memory_bytes: 9376
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#define _USE_MATH_DEFINES

#include<math.h>
#include<unordered_map>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int main()
{
	int a[101][101] = { 0 };
	int r, c;

	scanf("%d %d", &r, &c);

	for (int i = 0; i < r; i++)for (int j = 0; j < c; j++)
	{
		scanf("%d", &a[i][j]);
	}

	for (int i = 0; i < r; i++)
	{
		for (int j = 0; j < c; j++)
		{
			a[i][c] += a[i][j];
		}
	}

	for (int i = 0; i <= c; i++)
	{
		for (int j = 0; j < r; j++)
		{
			a[r][i] += a[j][i];
		}
	}

	for (int i = 0; i < (r + 1); i++)
	{
		for (int j = 0; j < (c + 1); j++)
		{
			printf("%d", a[i][j]);
			if (j < c)
			{
				printf(" ");
			}
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 3236
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);



int main(){
	FAST_IO
	
	int N, a, b; cin >> N >> a >> b;
	cout << min(b, N * a) << "\n";
			
	return 0;
}


Measured memory_bytes: 256
s = str(input())
t = str(input())
ls = len(s) + 1
lt = len(t) + 1

dp = [[0] * ls for _ in range(lt)]
for i in range(1, ls):
    for j in range(1, lt):
        if s[i-1] == t[j-1]:
            dp[j][i] = dp[j-1][i-1] + 1
        else:
            dp[j][i] = max(dp[j][i-1],dp[j-1][i])

revlst = []

lt -= 1
ls -= 1
while dp[lt][ls] != 0:
    while dp[lt][ls] == dp[lt-1][ls]:
        lt -= 1
    while dp[lt][ls] == dp[lt][ls-1]:
        ls -= 1
    revlst.append(lt)
    lt -= 1
    ls -= 1

ans = ''.join([t[_-1] for _ in reversed(revlst)])
print(ans)

Measured memory_bytes: 112348
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
int ctoi(const char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return -1;
	}
}
int main() {
	int s;
	string a;
	cin >> a;
	int a1, a2, a3, a4;
	a1 = ctoi(a[0]);
	a2 = ctoi(a[1]);
	a3 = ctoi(a[2]);
	a4 = ctoi(a[3]);
	int s1 = a1 * 10 + a2;
	int s2 = a3 * 10 + a4;
	int c, d;
		c = 0;
		d = 0;
		if ((s1 > 0) && (s1 <= 12)) {
			c = 1;
		}
		if ((s2 > 0) && (s2 <= 12)) {
			d = 1;
		}
		if ((c == 1) && (d == 1)) {
			cout << "AMBIGUOUS";
		}
		else if (c == 1) {
			cout << "MMYY";
		}
		else if (d == 1) {
			cout << "YYMM";
		}
		else {
			cout << "NA";
		}
}

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

int a[7];
int b[7];
int m;
long long int dp[7][11][1001];
long long int check(int i,int cnt,int n)
{
  //  cout<<m<<endl;
  //  cout<<i<<" "<<cnt<<" "<<n<<endl;

  if(n==0)
    return 1;
  if(n<0 || i>=m)
    return 0;
  if(dp[i][cnt][n]!=-1)
    return dp[i][cnt][n];
		 
  long long int ans = 0;
  if(b[i]>cnt)
    ans+=check(i,cnt+1,n-a[i]);
  ans+=check(i+1,0,n);
  dp[i][cnt][n]=ans;
  return ans;
  
}

int main()
{
  for(;cin>>m,m;)
    {
      //      card.clear();
      for(int i=0;i<m;i++)
	{
	  cin>>a[i]>>b[i];
	}
      int g;
      cin>>g;
      for(;g--;)
	{
	  int n;
	  cin>>n;
	  memset(dp,-1,sizeof(dp));
	  cout<<check(0,0,n)<<endl;
	}
    }
}

Measured memory_bytes: 1764
#include<cstdio>
#include <vector>
#include <map>
#define int long long int
using namespace std;

typedef pair<int,int> P;
vector<P> G[200000];
int d[200000];

void dfs(int prev, int now, int cost) {
    d[now] = cost;
    for(P p : G[now]) {
        int next = p.first;
        int ncost = p.second;
        if(next == prev) continue;
        dfs(now, next, cost + ncost);
    }
}

 main(void) {
    int n;
    scanf("%lld",&n);

    for(int i=0; i<n-1; i++) {
        int a,b,c;
        scanf("%lld%lld%lld",&a,&b,&c);
        a--, b--;
        G[a].push_back(P(b,c));
        G[b].push_back(P(a,c));
    }

    int q,k;
    scanf("%lld%lld",&q,&k);
    k--;
    dfs(-1, k, 0);

    for(int i=0; i<q; i++) {
        int x,y;
        scanf("%lld%lld",&x,&y);
        x--, y--;
        printf("%lld\n", d[x] + d[y]);
    }
}

Measured memory_bytes: 16640
N, M = map(int,input().split())
A = sorted(list(map(int,input().split())))
D = [list(map(int,input().split())) for k in range(M)]
D = sorted(D, key = lambda x: -x[1])

now = 0
for d in D:
    for k in range(now,now+d[0]):
        if now == N:
            break
        if A[k] < d[1]:
            A[k] = d[1]
            now += 1
        else:
            now = k
            break

print(sum(A))

Measured memory_bytes: 83224
#include<bits/stdc++.h>
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 1e5 + 7;
const int maxm = 2e5 + 7;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-10;
int n, m;
long long fac[maxn];

int main(int argc, char const *argv[])
{
    fac[0] = 1;
    for (int i = 1; i < maxn; i++)
        fac[i] = (fac[i - 1] * i) % mod;
    scanf("%d%d", &n, &m);
    if (n < m)
        swap(n, m);
    if (n >= m + 2)
    {
        printf("0\n");
        return 0;
    }
    if (n > m)
    {
        long long ans = (fac[n] * fac[m]) % mod;
        printf("%lld\n", ans);
    }
    if (n == m)
    {
        long long ans = ((2 * fac[n]) % mod * fac[m]) % mod;
        printf("%lld\n", ans);
    }
    return 0;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> X;
  for(int i=0; i<N; i++){
    int x; cin >> x;
    X.push_back(x);
  }
  long dist=1e9;
  for(int i=0; i<N-K+1; i++){
    long ld = abs(X[i])+X[i+K-1]-X[i];
    long rd = abs(X[i+K-1])+X[i+K-1]-X[i];
    dist = min(min(ld, rd), dist);
  }
  cout << dist<< endl;
  return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#define long long ll
using namespace std;

int main()
{
	int n,m;
	while(~scanf("%x%x",&n,&m))
	{
		if(n>m)
		{
			cout<<">"<<endl;
		}
		else if(n<m)
		{
			cout<<"<"<<endl;
		}
		else
		{
			cout<<"="<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
use v5.10;

my $n = <>;
my @a = glob <>;
my %ans = ();
for (@a) {
    $ans{$_} = (exists $ans{$_}) ? $ans{$_} + 1 : 1;
}

for (1..$#a+2) {
    say((exists $ans{$_}) ? $ans{$_} : 0);
}

Measured memory_bytes: 133420
#include<bits/stdc++.h>
using namespace std;
long long INF = 1e18;

struct Edge{
    int to;
    int cost;
};
using P = pair<int,int>;
int main(){
    
    int v,e,r;
    cin>>v>>e>>r;
    vector<Edge>g[v+100];
    for(int i=0; i<e; i++){
        int s,t,b;
        cin>>s>>t>>b;
        g[s].push_back(Edge{t,b});
    }

    priority_queue<P,vector<P>,greater<P>>que;

    long long d[v+100];
    for(int i=0; i<v; i++){
        d[i]=INF;
    }
    
    d[r] = 0;
    que.push(P(0,r));
     while(que.size()) {

        P p = que.top(); que.pop();

        long long cost = p.first;
        long long v = p.second;

        if(d[v] < cost) continue;
        for(int i = 0; i < g[v].size(); i++) {

            Edge e = g[v][i];

            if(d[e.to] > d[v] + e.cost) {

                d[e.to] = d[v] + e.cost;

                que.push(P(d[e.to], e.to));

            }

        }
    }
    for(int i =0 ; i<v;i++ ){
        if(d[i] !=1e18){
        cout<<d[i]<<endl;
        }else{
            cout<<"INF"<<endl;
        }
    
    }

    return 0;
}


Measured memory_bytes: 13328
def solve(n, m, a, d):
    a.sort(reverse=True)
    d.sort(key = lambda x:(x[1]), reverse=True)
    list1 = []
    index = 0
    for i in range(m):
        list1 += [d[i][1] for _ in range(min(d[i][0], n-index))]
        index += d[i][0]
        if index >= n:
            break
    if len(list1) < n:
        list1 += [0 for _ in range(n-index)]
    for i in range(n):
        if a[i] > list1[n-1-i]:
            list1[n-1-i] = a[i]
        else:
            break
    return sum(list1)

n, m = map(int, input().split())
a = list(map(int, input().split()))
d = []
for _ in range(m):
    d += [list(map(int, input().split()))]
print(solve(n, m, a, d))

Measured memory_bytes: 87704
#pragma GCC optimize("Ofast")

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <random>
#include <iterator>
#include <cstring>
#include <deque>

//#include <bits/stdc++h>

#define ll long long

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n, x, y;
    cin >> n >> x >> y;
    vector <ll> ans(n + 1, 0);
    for (ll i = 1; i < x; i ++) {
        for (ll j = 1; j <= n - y + x - i + 1; j ++) {
            ans[j] ++;
        }
        ans[x - i + 1]--;
        for (ll j = (x - i + 1); j < x + (y - x) / 2 - i + 1; j ++) {
            ans[j] += 2;
        }
        if ((y - x) % 2 == 1) {
            ans[x - i + 1 + (y - x) / 2] ++;
        }
    }
    for (ll i = n; i > y; i --) {
        for (ll j = 1; j <= (i - y); j ++) {
            ans[j] ++;
        }
        for (ll j = i - y + 1; j <= (i - y) + (y - x) / 2; j ++) {
            ans[j] += 2;
        }
        if ((y - x) % 2 == 1) {
            ans[(i - y) + (y - x) / 2 + 1] ++;
        }
    }
    for (ll i = 1; i <= (y - x) / 2; i ++) {
        ans[i] += (y - x + 1);
    }
    if ((y - x) % 2 == 1) {
        ans[(y - x + 1) / 2] += (y - x + 1) / 2;
    }
    for (ll i = 1; i < n; i ++) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

template <int MOD=1000000007>
struct Modular {
  int value;
  static const int MOD_value = MOD;

  Modular(long long v = 0) { value = v % MOD; if (value < 0) value += MOD;}
  Modular(long long a, long long b) : value(0){ *this += a; *this /= b;}

  Modular& operator+=(Modular const& b) {value += b.value; if (value >= MOD) value -= MOD; return *this;}
  Modular& operator-=(Modular const& b) {value -= b.value; if (value < 0) value += MOD;return *this;}
  Modular& operator*=(Modular const& b) {value = (long long)value * b.value % MOD;return *this;}

  friend Modular mexp(Modular a, long long e) {
    Modular res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
    return res;
  }
  friend Modular inverse(Modular a) { return mexp(a, MOD - 2); }

  Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
  friend Modular operator+(Modular a, Modular const b) { return a += b; }
  friend Modular operator-(Modular a, Modular const b) { return a -= b; }
  friend Modular operator-(Modular const a) { return 0 - a; }
  friend Modular operator*(Modular a, Modular const b) { return a *= b; }
  friend Modular operator/(Modular a, Modular const b) { return a /= b; }
  friend std::ostream& operator<<(std::ostream& os, Modular const& a) {return os << a.value;}
  friend bool operator==(Modular const& a, Modular const& b) {return a.value == b.value;}
  friend bool operator!=(Modular const& a, Modular const& b) {return a.value != b.value;}
};

int main() {

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

  int n, k;
  cin >> n >> k;

  Modular<> cnt[k+1], ans;
  memset(cnt, 0, sizeof cnt);

  for (int i = k; i >= 1; --i) {
    int j = k/i;
    cnt[i] = j;
    cnt[i] = mexp(cnt[i], n);
    for (int l = 2*i; l <= k; l += i) {
      cnt[i] -= cnt[l];
    }
    ans += i * cnt[i];
  }

  cout << ans << '\n';
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

const ll maxn_warshall_floyd=505;
ll dist[maxn_warshall_floyd][maxn_warshall_floyd];
ll n;
void warshallfloyd(){
  for(ll k = 0; k < n; k++)
    for(ll i = 0; i < n; i ++)
      for(ll j = 0; j < n; j++)
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  n=10;
  ll h,w; cin>>h>>w;
  rep(i,10) rep(j,10) cin>>dist[i][j];
  warshallfloyd();
  vll a(10);
  rep(i,10) a[i]=dist[i][1];
  
  ll ans=0;
  rep(i,h) rep(j,w){
    ll b; cin>>b;
    if(b==-1) continue;
    ans+=a[b];
  }
  cout<<ans<<endl;
  
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll K;
int N;
ll V[51];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>K;
	
	N=50;
	FOR(i,50) V[i]=49+K/50;
	K%=50;
	
	FOR(i,K) {
		V[i]+=N+1;
		FOR(j,N) V[j]--;
	}
	
	cout<<N<<endl;
	FOR(i,N) _P("%lld%c",V[i],(i==N-1)?'\n':' ');
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<map>

using namespace std;

int main()
{
    int n;cin>>n;
    set<string>s_;
    for(int i=0;i<n;++i){
        string tmp;cin>>tmp;
        s_.insert(tmp);
    }
    cout<<s_.size()<<endl;
    
    return 0;
}


Measured memory_bytes: 19180
U = 2*10**6
MOD = 10**9+7
 
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
 
for i in range(1,U+1):
  fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U],MOD-2,MOD)
 
for i in range(U,0,-1):
  fact_inv[i-1] = (fact_inv[i]*i)%MOD
 
def comb(n,k):
  if k < 0 or k > n:
    return 0
  z = fact[n]
  z *= fact_inv[k]
  z %= MOD
  z *= fact_inv[n-k]
  z %= MOD
  return z

n, k = map(int, input().split())
for i in range(1, k+1):
  ans = comb(n-k+1, i) * comb(k-1, i-1)
  print(ans%MOD)

Measured memory_bytes: 161524