akhauriyash/Code-Regression huggingface dataset:
import math
import copy
import bisect








def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input().split())

def func():
    if n[1]==1:
        return "YES"
    if n[0]%2!=0:
        n[0]=n[0]+1
    if n[1]*2<=n[0]:
        return "YES"
    else:
        return "NO"
    
print(func()) 




Measured memory_bytes: 3572
#include<cstdio>
#include<vector>
using namespace std;
struct edge{int to, index;};
static const int MAX_V = 100000;
static const int MAX_E = 100000;

int V, E;
vector<edge> G[MAX_V];
bool visited[MAX_V], passed[MAX_E];
int ord[MAX_V], low[MAX_V];

void dfs(int u, int k){
	visited[u] = true;
	ord[u] = k;
	k++;
	low[u] = ord[u];
	for(int i = 0; i < G[u].size(); i++){
		if(!visited[G[u][i].to]){
			passed[G[u][i].index] = true;
			dfs(G[u][i].to, k);
			low[u] = min(low[u], low[G[u][i].to]);
		}else if(!passed[G[u][i].index]){
			low[u] = min(low[u], ord[G[u][i].to]);
		}
	}
}

int main(){
	scanf("%d %d", &V, &E);
	for(int i = 0; i < E; i++){
		int s, t;
		scanf("%d %d", &s, &t);
		G[s].push_back((edge){t, i});
		G[t].push_back((edge){s, i});
	}
	fill(visited, visited + V, false);
	fill(passed, passed + E, false);
	dfs(0, 0);
	for(int i = 0; i < V; i++){
		if(i == 0){
			int cnt = 0;
			for(int j = 0; j < G[i].size(); j++){
				if(passed[G[i][j].index]) cnt++;
			}
			if(cnt > 1) printf("%d\n", i);
		}else{
			for(int j = 0; j < G[i].size(); j++){
				if(!passed[G[i][j].index]) continue;
				if(ord[G[i][j].to] < ord[i]) continue;
				if(ord[i] <= low[G[i][j].to]){
					printf("%d\n", i);
					break;
				}
			}
		}
	}
	return 0;
}



Measured memory_bytes: 6800
# AOJ 0093 Leap Year

leap_year = Array.new(3001, false)
3001.times do |i|
  leap_year[i] = true if i % 4 == 0 && (i % 400 == 0 || i % 100 != 0)
end

leap_years = []
while line = gets
  a, b = line.split.map {|v| v.to_i}
  break if a.zero? && b.zero?

  y = (a..b).to_a.select {|i| leap_year[i]}
  if y.empty?
    leap_years << "NA"
  else
    leap_years << y.join("\n")
  end
end

puts leap_years.join("\n\n")

Measured memory_bytes: 6228
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	string s, t;
	cin >> n >> s >> t;
	mint ans = 1;
	rep(i,n){
		if(i == 0){
			if(s[i] == t[i]) ans *= 3;
			else{
				ans *= 6;
				++i;
			}
		}
		else{
			if(s[i] == t[i]){
				if(s[i-1] == t[i-1]){
					ans *= 2;
				}
				else{
					ans *= 1;
				}
			}
			else{
				if(s[i-1] == t[i-1]){
					ans *= 2;
					++i;
				}
				else{
					ans *= 3;
					++i;
				}
			}
		}
	}
	cout << ans.x << endl;
	return 0;
}

Measured memory_bytes: 256
def examA():
    N = I()
    A = LI()
    if A[-1]!=2:
        print(-1)
        return
    l = 2; r = 2
    for a in A[::-1]:
        ner = (r//a+1)*a-1
        nel = ((l-1)//a+1)*a
        r = ner; l = nel
        if r<l:
            print(-1)
            return
    print(l,r)
    return

def examB():
    N, M = LI()

    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examA()

"""

"""

Measured memory_bytes: 15016
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
#define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    int n,m;
    cin>>n;
    vpii v(n);
    rep(i,n){
        int a,b;
        cin>>a>>b;
        v[i]=mp(a,b);
    }
    Sort(v);
    
    rep(i,v.size()){
       cout<<v[i].first<<" "<<v[i].second<<endl;
    }
}




Measured memory_bytes: 3596
using System;
using System.Linq;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class program{
  static void Main(string[] args){
    program p = new program();
    p.Run();
  }
  void Run(){
	int[] inp =  Readint();
    int N = inp[0];
    int K = inp[1];
    string S = ReadLine();
    string s =S.Substring(K-1,1);
    if(s=="A")
      s="a";
    else if(s=="B")
      s="b";
    else{
      s="c";
    }
	S=S.Substring(0,K-1)+s+S.Substring(K,N-K);
    WriteLine(S);
  }

  int[] Readint(){
    string[] s = ReadLine().Split();
    int[] res=new int[s.Length];
    Parallel.For(0,s.Length,i=>{
      res[i]=int.Parse(s[i]);
    });
    return res;
  }
}

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

#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(int i=a ; i<=b ; i++)
#define FORD(i,a,b) for(int i=a ; i>=b ; i--)
#define INF 1000000000
#define ll long long int
#define eps (1e-8)
#define sq(x) ( (x)*(x) )
#define all(x) x.begin(),x.end()
#define flog2(n) 64 - __builtin_clzll(n) - 1
#define popcnt(n) __builtin_popcountll(n)

using namespace std;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

ll cost[(1 << 16)];
ll d[1 << 16];

ll a[17][17];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
	
	int n;
	cin >> n;
	FOR (i, 0, n - 1) {
		FOR (j, 0, n - 1) {
			cin >> a[i][j];
		}
	}

	FOR (i, 1, (1 << n) - 1) {
		vector<int> bits;
		FOR (j, 0, n - 1) {
			if ((1 << j) & i) {
				bits.pb(j);
			}
		}
		cost[i] = cost[i - (1 << (bits[0]))];
		
		for (int j = 1; j < bits.size(); j++) {
			cost[i] += a[bits[0]][bits[j]];
		}
	}

	FOR (i, 0, (1 << n) - 1) {
		d[i] = cost[i];
		for (int j = i; j; j = (j - 1) & i) {
			if (j) d[i] = max(d[i], cost[j] + d[i ^ j]);
		}
	}

	cout << d[(1 << n) - 1] << endl;







	
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200, MAXINT=2147483647;
ll b[N], t, n, mi=MAXINT;
string s;
int main() {
    cin >> s;
    for (int i=0; i<3; i++) {
        s[i]=='1' ? cout << '9' : cout << '1';
    }
}

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

int main(){
  string s;
  cin >> s;
  bool judge = true;
  
  if(s.size() < 5){
    judge = false;
  }
  
  while(s.size() > 7){
    if(s.substr(s.size()-5) == "dream" || s.substr(s.size()-5) == "erase"){
      s = s.erase(s.size()-5);
      //cout << s << endl;
      //cout << s.size() << endl;
    }
    else if(s.substr(s.size()-6) == "eraser"){
      s = s.erase(s.size()-6);
      //cout << s << endl;
      //cout << s.size() << endl;
    }
    else if(s.substr(s.size()-7) == "dreamer"){
      s = s.erase(s.size()-7);
    }
    else{
      judge = false;
      break;
    }
  }
  
  if(judge){
    if(s.size() == 5){
      if(s == "dream" || s == "erase"){
        cout << "YES" << endl;
      }
      else{
        cout << "NO" << endl;
      }
    }
    if(s.size() == 6){
      if(s == "eraser"){
        cout << "YES" << endl;
      }
      else{
        cout << "NO" << endl;
      }
    }
    if(s.size() == 7){
      if(s == "dreamer"){
        cout << "YES" << endl;
      }
      else{
        cout << "NO" << endl;
      }
    }
  }
  else{
    cout << "NO" << endl;
  }
}
    

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

int main() {
    int N;
    float number = 0, mix;
    std::cin >> N;
    std::vector<int> numbers(N);
    for(auto& x: numbers)
    {
        std::cin >> x;
    }

    std::sort(numbers.begin(), numbers.end());
     
    mix = numbers[0];
    for (const auto& number: numbers) {
        mix = (mix + number)/2;
    }
    std::cout << mix;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int ans = 0;
    REP(i, 3001) REP(j, 3001) {
        int rest = N - R * i - G * j;
        if (rest >= 0 && rest % B == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string>
#include <sstream>
#define ll long long
#define F first
#define S second
#define pb push_back
#define ld long double
#define pll pair<long long,long long>
#define pld pair<long double,long double>
#define ios     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll mod=1000000007;
ll gcd (ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll fastexp(ll x ,ll n)
{
    ll result =1;
    while(n>0)
    {
        if(n%2==1)
            result*=x;
        x*=x;
        n=n/2;
    }
    return result;
}

ll modularExp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%mod;
        x=((x%mod)*(x%mod))%mod;
        n=n/2;
    }
    return (result)%mod;
}
bool isPrime(ll n)
{
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
            return false;
    return true;
}
bool mycomp(pll &a,pll &b)
{
    if(a.F!=b.F)
        return a.F < b.F;
    else
        return a.S < b.S;
}

void solve()
{
     ll n;
     cin>>n;
     vector<ll> v(n+1);
     ll i;
     for(i=1;i<=n;i++)
          cin>>v[i];
     vector<ll> dp(n+1);
     dp[1]=0;
     dp[2]=abs(v[1]-v[2]);
     for(i=3;i<=n;i++)
     {
          dp[i]=min(dp[i-2]+abs(v[i]-v[i-2]),dp[i-1]+abs(v[i]-v[i-1]));
     }
     cout<<dp[n]<<" ";
}

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

Measured memory_bytes: 1792
/**
 *   author: AK Tiwari
 *   created: 30 January 2019  12:02:38
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
struct vars { ll a,b; };
ll i,j,k;
vector<ll> cost(100005,1e6);
vector<ll> a(100005);

void solve(){
	ll n;cin>>n;
	rep(i,0,n-1)cin>>a[i];
	rrep(i,n-1,0){
		if((i+1)<n && (i+2)<n)
			cost[i] = min(cost[i+1]+abs(a[i]-a[i+1]), cost[i+2]+abs(a[i]-a[i+2]));
		else if((i+1)<n)
			cost[i] = abs(a[i]-a[i+1]);
		else
			cost[i] = 0;
	}
	cout<<cost[0];
}

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    // ll t;cin>>t;
    // while(t--)
    	solve();
return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

const int mod = 1000000007;

vector <int> mp[1100010];
int sum[500010];
int all[500010];

long long power(long long a, long long b){
	if (!b) return 1;
	long long t = power(a, b >> 1);
	return b & 1 ? t * t % mod * a % mod : t * t % mod;
}

int main(){
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++){
		int x; scanf("%d", &x);
		sum[i] = sum[i - 1] ^ x;
		mp[sum[i]].push_back(i);
		if (sum[i] == 0) all[i] = all[i - 1] + 1;
		else all[i] = all[i - 1];
	}
	if (sum[n] != 0){
		vector <int> a = mp[0], b = mp[sum[n]];
		int m = b.size() * 2;
		b.push_back(n);
		vector <long long> sum1(m + 1, 0), sum2(m + 1, 0), dp(m + 1, 0);
		dp[0] = 1, sum2[0] = 1;
		long long res = 0;
		for (int i = 1; i <= m - 1; i++){
			int cnt;
			if (i & 1) cnt = 1;
			else cnt = all[b[i + 1 >> 1]] - all[b[i - 1 >> 1] - 1];
			if (i & 1){
				dp[i] = sum2[i - 1] * cnt % mod;
				sum2[i] = sum2[i - 1];
				sum1[i] = (sum1[i - 1] + dp[i]) % mod;
			} else {
				dp[i] = sum1[i - 1] * cnt % mod;
				sum1[i] = sum1[i - 1];
				sum2[i] = (sum2[i - 1] + dp[i]) % mod;
			}
			if (i == m - 1) res = sum2[i - 1];
		}
		printf("%lld\n", res);
		return 0;
	}
	long long ans = 0;
	vector <int> a = mp[0];
	for (int i = 0; i < (1 << 20); i++){
		if (i == 0){
			ans = (ans + power(2, mp[i].size() - 1)) % mod;
			continue;
		}
		if (mp[i].size() == 0) continue;
		vector <int> b = mp[i];
		int m = b.size() * 2;
		b.push_back(n);
		vector <long long> sum1(m + 1, 0), sum2(m + 1, 0), dp(m + 1, 0);
		dp[0] = 1, sum2[0] = 1;
		long long res = 0;
		for (int i = 1; i <= m; i++){
			int cnt;
			if (i & 1) cnt = 1;
			else cnt = all[b[i + 1 >> 1]] - all[b[i - 1 >> 1] - 1];
			if (i & 1){
				dp[i] = sum2[i - 1] * cnt % mod;
				sum2[i] = sum2[i - 1];
				sum1[i] = (sum1[i - 1] + dp[i]) % mod;
			} else {
				dp[i] = sum1[i - 1] * cnt % mod;
				sum1[i] = sum1[i - 1];
				sum2[i] = (sum2[i - 1] + dp[i]) % mod;
			}
			if (i == m) res = sum1[i - 1];
		}
		ans = (ans + res) % mod;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 47840
#include<iostream>
#include<vector>

using std::cout;
using std::cin;
using std::endl;
using std::vector;

void printVector(vector<vector<int> > v) {
    for (int i = 0; i < v.size(); i++) {
        if (i % 3 == 0 && i != 0) {
            cout << "####################" << endl; 
        }
        for (int j = 0; j < v.front().size(); j++) {
            cout << " " << v[i][j];
        }
        cout << endl;
    }
}

int main(void) {
    vector<vector<int> > house(3*4, vector<int>(10, 0));
    int times;
    int v;
    int f;
    int r;
    int b;
    cin >> times;
    for (int i= 0; i < times; i++) {
       cin >> v >> f >> r >> b; 
       house[3 * (v - 1) + f - 1][r - 1] += b;
    }
    printVector(house); 
    return 0;
}

Measured memory_bytes: 3132
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main(){    
  int H,W,h,w;
  cin >> H >> W >> h >> w;

  int ans = H*W - (h*W + (H*w-h*w));

  if(ans < 0){
  cout << "0" << endl;
  }
  else{
    cout << ans << endl;
  }
  
}


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

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

int INF = 10000000;

int main() {
  int H, W, white_tile = 0;
  char field[55][55];
  int dist[55][55];
  for(int i = 0; i < 55; i++) {
    for(int j = 0; j < 55; j++) {
      dist[i][j] = INF;
    }
  }
  cin >> H >> W;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> field[i][j];
      if(field[i][j] == '.') white_tile++;
    }
  }
  
  queue<int> que;
  dist[0][0] = 1;
  que.push(0); que.push(0);
  while(que.size()) {
    int x = que.front(); que.pop();
    int y = que.front(); que.pop();
    for(int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if(0 <= nx && nx < W && 0 <= ny && ny < H && field[ny][nx] == '.' && dist[ny][nx] == INF) {
	dist[ny][nx] = dist[y][x] + 1;
	que.push(nx); que.push(ny);
      }
    }
  }
  if(dist[H - 1][W - 1] == INF) {
    cout << -1 << endl;
  } else {
    cout << white_tile - dist[H - 1][W - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    bool card[4][13] = {};
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        char x;
        int num;
        cin >> x >> num;
        if(x == 'S'){
            card[0][num-1] = true;
        }else if (x == 'H'){
            card[1][num-1] = true;
        }else if (x == 'C'){
            card[2][num-1] = true;
        }else if (x == 'D'){
            card[3][num-1] = true;
        }
    }
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 13; j++){
            if(i == 0 && card[i][j] == 0){
                cout << "S" << " " << j+1 << endl;
            }else if (i == 1 && card[i][j] == 0){
                cout << "H" << " " << j+1 << endl;
            }else if (i == 2 && card[i][j] == 0){
                cout << "C" << " " << j+1 << endl;
            }else if (i == 3 && card[i][j] == 0){
                cout << "D" << " " << j+1 << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};
void primeFactors(int n,set <ll> &s1)  
{  
    while (n % 2 == 0)  
    {  
        s1.insert(2);
        n = n/2;  
    }  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        while (n % i == 0)  
        {  
            s1.insert(i);
            n = n/i;  
        }  
    }  
    if (n > 2)  
        s1.insert(n);
}  
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    ve <ll> arr(n);
    rep (i,0,n)
    {
        cin>>arr[i];
    }
    //pairwise coprime
    ve <set <ll>> pfac(n);
    map <ll,ll> m1;
    rep (i,0,n)
    {
        primeFactors(arr[i],pfac[i]);
        for (auto x: pfac[i])
        {
            m1[x]++;
        }
    }
    bool flag=true;
    rep (i,0,n)
    {
        for (auto x: pfac[i])
        {
            m1[x]--;
        }
        for (auto x: pfac[i])
        {
            if (m1[x]>0)
            {
                flag=false;
                goto zee;
            }
        }
    }
    zee:;
    if (flag)
    {
        cout<<"pairwise coprime\n";
        return 0;
    }
    //setwise coprime
    ll fgcd=arr[0];
    for (int i=0;i<n;i++)
    {
        fgcd=__gcd(fgcd,arr[i]);
    }
    if (fgcd==1)
    {
        cout<<"setwise coprime\n";
        return 0;
    }
    //neither
    cout<<"not coprime\n";
}


Measured memory_bytes: 294720
#include<iostream>
#include<cassert>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


struct mint {
	int x;
	mint(int x = 0) :x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= MOD)x -= MOD;
		return *this;
	}
	mint & operator-=(const mint a) {
		if ((x += MOD - a.x) >= MOD)x -= MOD;
		return *this;
	}
	mint & operator*=(const mint a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint a)const {
		return mint(*this) += a;
	}
	mint operator-(const mint a)const {
		return mint(*this) -= a;
	}
	mint operator*(const mint a)const {
		return mint(*this) *= a;
	}
	mint pow(int t)const {
		if (!t)return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1)a *= *this;
		return a;
	}

	//for prime mod
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a)const {
		mint res(*this);
		return res /= a;
	}
};
ostream& operator<<(ostream & os, const mint & m) {
	os << m.x;
	return os;
}

struct combination {
	vector<mint>fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; i++)fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; i--)ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n)return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
};

signed main() {
	int N, K;
	cin >> N >> K;
	combination a(N - K + 1);
	for (int i = 1; i <= K; i++) {
		mint ans = a(N - K + 1, i);
		combination b(K - 1);
		ans *= b(K - 1, i - 1);
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#define INF 1000000000
using namespace std;
int n, m;
int X1[105], Y1[105], X2[105], Z2[105];
double width(int* X, int* Y, int n, double xx) {
    double lb = INF, ub = -INF;
    for (int i = 0; i < n; ++i) {
        double x1 = X[i], y1 = Y[i], x2 = X[(i + 1) % n], y2 = Y[(i + 1) % n];
        if ((x1 - xx) * (x2 - xx) <= 0 && x1 != x2) {
            double y = y1 + (y2 - y1) * (xx - x1) / (x2 - x1);
            lb = min(lb, y);
            ub = max(ub, y);
        }
    }
    return max(0.0, ub - lb);
}
int main() {
    while(scanf("%d %d", &m, &n) && m && n) {
        vector<int> xs;
        int min1 = INF, max1 = -INF, min2 = INF, max2 = -INF;
        for (int i = 0; i < m; ++i) {
            scanf("%d %d", X1 + i, Y1 + i);
            min1 = min(min1, X1[i]);
            max1 = max(max1, X1[i]);
            xs.push_back(X1[i]);
        }
        for (int i = 0; i < n; ++i) {
            scanf("%d %d", X2 + i, Z2 + i);
            min2 = min(min2, X2[i]);
            max2 = max(max2, X2[i]);
            xs.push_back(X2[i]);
        }
        sort(xs.begin(), xs.end());
        double ans = 0;
        for (int i = 0; i + 1 < xs.size(); ++i) {
            double a = xs[i], b = xs[i + 1];
            double c = (a + b) / 2;
            if (min1 <= c && c <= max1 && min2 <= c && c <= max2) {
                double fa = width(X1, Y1, m, a) * width(X2, Z2, n, a);
                double fb = width(X1, Y1, m, b) * width(X2, Z2, n, b);
                double fc = width(X1, Y1, m, c) * width(X2, Z2, n, c);
                ans += (b - a) / 6 * (fa + 4 * fc + fb);
            }
        }
        printf("%.10f\n", ans);
    }
    return 0;
}



Measured memory_bytes: 2796
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner scan = new Scanner(System.in);
		
      	String S = scan.next();
		char[] cArray = S.toCharArray();

      	int yesCnt = 0;
      	for(int i = 0; i < S.length(); i++){
      		if((i + 1) % 2 == 0){
            	// 偶数
              	if('L' == cArray[i] || 'U' == cArray[i] || 'D' == cArray[i]) {
                	yesCnt++;
                }
            } else {
            	// 奇数
              	if('R' == cArray[i] || 'U' == cArray[i] || 'D' == cArray[i]) {
                	yesCnt++;
                }
            }
        }
      	if(yesCnt == S.length()){
          	System.out.println("Yes");
        } else {
        	System.out.println("No");  
        }
    }
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  map<ll, string> mp;
  mp[0] = "pon";
  mp[1] = "pon";
  mp[2] = "hon";
  mp[3] = "bon";
  mp[4] = "hon";
  mp[5] = "hon";
  mp[6] = "pon";
  mp[7] = "hon";
  mp[8] = "pon";
  mp[9] = "hon";

  ll N;
  IN(N);
  OUT(mp[N%10]);

  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

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

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    
    int x, y;
    cin >> x >> y;

    for(int i = 0; i <= x; i++)
    {
        if(2 * i + (x - i) * 4 == y)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

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

int main() {
	int r,g,b;
  	cin >> r >> g >> b;
  
  	int bottom2 = g * 10 + b;
  
  	if(bottom2 % 4 == 0) {
    	cout << "YES" << endl;
    }else {
    	cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#pragma warning disable
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
using System.Collections;
using static System.Math;
using static System.Console;
class E { static void Main() => new J(); }
class J
{
	const int Mod = 1000000007;
	int F() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	public J()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var a = G();
		WriteLine(a[0] % 3 == 0 || a[1] % 3 == 0 || a.Sum() % 3 == 0 ? "Possible" : "Impossible");
	}
	long GCD(long a, long b)
	{
		var n = (ulong)Abs(a); var m = (ulong)Abs(b);
		if (n == 0) return (long)m; if (m == 0) return (long)n;
		int zm = 0, zn = 0;
		while ((n & 1) == 0) { n >>= 1; zn++; }
		while ((m & 1) == 0) { m >>= 1; zm++; }
		while (m != n)
		{
			if (m > n) { m -= n; while ((m & 1) == 0) m >>= 1; }
			else { n -= m; while ((n & 1) == 0) n >>= 1; }
		}
		return (long)n << Min(zm, zn);
	}
}

Measured memory_bytes: 11348
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <typeinfo>
#include <math.h>
#include <iomanip>
#include <limits>

using namespace std;
using ll = long long;
const ll res = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
	int x,y,z;
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y << endl;
}

Measured memory_bytes: 256
from sys import stdin

N, x = [int(x) for x in stdin.readline().rstrip().split()]
candys = [int(x) for x in stdin.readline().rstrip().split()]

count = 0

# xより多く入っている箱のキャンディは必ず食べる必要がある。
for i in range(N):
    if candys[i] > x:
        num = candys[i] - x
        candys[i] = x
        count += num
        # print(candys)

# print('count = ', count)
# print('---------------------------')

# 隣り合った箱を見て、xを越えていれば食べる
for i in range(N-1):
    if candys[i] + candys[i+1] > x:
        num = candys[i] + candys[i+1] - x
        count += num
        candys[i+1] = candys[i+1] - num
        # print(candys)
# 結果
print(count)


Measured memory_bytes: 14548
void main() {
	auto X = ri;
	ulong res;
	if(X == 1) res = 1;
	foreach(i; 1..X) {
		debug iota(1, i+1).sum.writeln;
		// アホ
		// if(iota(i).sum < X) res++;
		if((i-1)*i/2 < X) res++;
		else break;
	}
	if(X == 2) res = 2;
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

T[] deepcopy(T)(T[] a) {
	static if(isArray!T) {
		T[] res;
		foreach(i; a) {
			res ~= deepcopy(i);
		}
		return res;
	} else {
		return a.dup;
	}
}

ulong[] generate_prime_list(T)(T N) if(isIntegral!T) {
	ulong[] prime_list = [2];
	bool not_prime = false;
	foreach(i; 3..N.to!ulong+1) {
		foreach(j; prime_list) {
			if(i % j == 0) {
				not_prime = true;
				break;
			}
		}
		if(!not_prime) prime_list ~= i;
		not_prime = false;
	}
	return prime_list;
}

bool isPrime(ulong n) {
	if(n <= 1) return false;
	else if(n == 2) return true;
	else if(n % 2 == 0) return false;

	foreach(i; iota(3, n.to!double.sqrt.ceil+1, 2)) {
		if(n % i == 0) return false;
	}
	return true;
}

class UnionFind(T) {
	T[] arr;
	this(ulong n) {
		arr.length = n+1;
		arr[] = -1;
	}
	T root(T x) {
		return arr[x] < 0 ? x : root(arr[x]);
	}
	bool same(T x, T y) {
		return root(x) == root(y);
	}
	bool unite(T x, T y) {
		x = root(x);
		y = root(y);
		if(x == y) return false;
		if(arr[x] > arr[y]) swap(x, y);
		arr[x] += arr[y];
		arr[y] = x;
		return true;
	}
	T size(T a) {
		return -arr[root(a)];
	}
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

using namespace std;

int main()
{
    int A, B;
    if (scanf("%d%d", &A, &B) < 2) return 0;

    char S[12];
    if (scanf("%s", S) < 1) return 0;

    bool flg = true;
    if (S[A] == '-')
    {
        for (int i = 0; i < A; i++)
        {
            if (S[i] < '0' || '9' < S[i])
            {
                flg = false;
                break;
            }
        }

        for (int i = A+1; i < A + B + 1; i++)
        {
            if (S[i] < '0' || '9' < S[i])
            {
                flg = false;
                break;
            }
        }
    }
    else
    {
        flg = false;
    }

    printf("%s\n", flg ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main(void){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	int left = a+b, right = c+d;
	if(left>right){
		printf("%s\n","Left");
	}else if(left==right){
		printf("%s\n","Balanced");
	}else{
		printf("%s\n","Right");
	}
	return 0;
}

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

#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

inline void Main() {
  // code
  int N;
  int H[30];

  cin >> N;
  rep(i, N) cin >> H[i];

  int res = 1;
  int curMax = H[0];
  repi(i, 1, N) {
    if(curMax <= H[i]) {
      res++;
      curMax = max(curMax, H[i]);
    }
  }

  cout << res << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
const int mod= 1e9 + 7;

int r[3005];
int n, l;
char str[3005];
int ps[3005];
int sum(int s, int e){
	return ps[e] - ps[s-1];
}

int dp[3005][3005];

lint f(int x, int y){
	if(y < 0 || y > r[x] - x + 1) return 0;
	if(x == n+1) return y == 0;
	if(~dp[x][y]) return dp[x][y];
	int ret = 0;
	if(y < r[x] - x + 1) ret += f(x+1, y + sum(r[x]+1, r[x+1]));
	if(y) ret += f(x+1, y-1 + sum(r[x]+1, r[x+1]));
	return dp[x][y] = ret % mod;
}

int main(){
	memset(dp, -1, sizeof(dp));
	cin >> n >> l >> (str + 1);
	for(int i=1; i<=n; i++) r[i] = i, ps[i] = (str[i] == '1');
	for(int i=0; i<l; i++){
		int s, e;
		cin >> s >> e;
		r[s] = max(r[s], e);
	}
	r[n+1] = n;
	for(int i=2; i<=n; i++){
		r[i] = max(r[i], r[i-1]);
		ps[i] += ps[i-1];
	}
	cout << f(1, sum(1, r[1])) << endl;
}


Measured memory_bytes: 35840
#define _GLIBCXX_DEBUG    //空コンテナ操作禁止　Clang環境では#define _LIBCPP_DEBUG 0
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
  int A, B;
  cin >> A >> B;
  
  if( (A+B)%2 == 1 ){
    cout << "IMPOSSIBLE";
  }else{
    cout << (A+B)/2;
  }
  return 0;
}

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

using namespace std;
int a, b, c, k;

void pre(){
int sum = 0;
  for (int i = 0; i < k; ++i) {
    if (a > 0) {
      ++sum;
      --a;
    } else if (b > 0) {
      --b;
    } else {
      --sum;
    }
  }
  cout << sum << '\n';
    
}

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

  cin >> a >> b >> c >> k;
  {
    pre();

}
  return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct CHT{
    deque<pair<int,int>>ls;
    inline bool check(const pair<int,int>&a,const pair<int,int>&b,const pair<int,int>&c){
        return (b.fi-a.fi)*(c.se-b.se)>=(b.se-a.se)*(c.fi-b.fi);
    }
    void add(int a,int b){
        pair<int,int>l(a,b);
        while(ls.size()>=2&&check(ls[ls.size()-2],ls[ls.size()-1],l))ls.pop_back();
        ls.push_back(l);
    }
    int query(int x){
        assert(ls.size());
        while(ls.size()>1&&ls[0].fi*x+ls[0].se>=ls[1].fi*x+ls[1].se)ls.pop_front();
        return ls[0].fi*x+ls[0].se;
    }
};

const int INF=1001001001;
int S,N,M;
int X[2222];
int A[2222];
int sum[2222];
int dp[2222][2222];
signed main(){
    cin>>S>>N>>M;
    rep(i,S)cin>>X[i];
    rep(i,N){
        int t,p;
        cin>>t>>p;
        A[i]=t-X[p-1];
    }
    sort(A,A+N);
    for(int i=0;i<N;i++)sum[i+1]=sum[i]+A[i];
    chmin(M,N);
    for(int k=0;k<M;k++){
        CHT cht;
        cht.add(-k,dp[k][k]+sum[k]);
        for(int j=k+1;j<=N;j++){
            dp[k+1][j]=cht.query(A[j-1])+j*A[j-1]-sum[j];
            if(k)cht.add(-j,dp[k][j]+sum[j]);
        }
    }
    cout<<dp[M][N]<<endl;
    return 0;
}

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

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

            Console.WriteLine(N % 500 <= A ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void){
    int n;
    char s[105];
    cin >> n;
    cin >> s;
    int k = 0, l = 0;
    int mx_f = 0, mx_l = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == ')') {
            k++;  mx_f = max(mx_f, k);
        }
        else k--;
        
        if (s[n - 1 - i] == '(') {
            l++;  mx_l = max(mx_l, l);
        }
        else l--;
    }
    
    for (int i = 0; i < mx_f; i++) cout << '(';
    for (int i = 0; i < n; i++) cout << s[i];
    for (int i = 0; i < mx_l; i++) cout << ')';
    cout << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

template<typename Type>
struct SegmentTree {
        vector<Type> data;
        int n;
        SegmentTree(int x) {
                n = pow(2, ceil(log2(x)));
                data.resize(2 * n - 1);
                for (int i = 0; i < 2 * n - 1; i ++) {
                        data[i] = make_pair(0, -1);
                }
        }
        Type merge(Type x, Type y) { //merge function (val, idx) maximum value and minimum idx
                if (x.first > y.first) {     
                        return x;
                } else if (x.first < y.first) {
                        return y;
                } else {
                        return make_pair(x.first, min(x.second, y.second));
                }
        }
        void update(int k, Type p) { //update k-th value to p
                k += n - 1;
                data[k] = p;
                while (k > 0) {
                        k = (k - 1) / 2;
                        data[k] = merge(data[k * 2 + 1], data[k * 2 + 2]);
                }
        }
        // [l, r)
        Type query(int a, int b) { return query(a, b, 0, 0, n); }
        Type query(int a, int b, int k, int l, int r) {
                if (r <= a || b <= l) return make_pair(0, -1); //initial value
                if (a <= l && r <= b) return data[k];
                int m = (l + r) / 2;
                return merge(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
        }
};

int main() {
        int n;
        scanf("%d", &n);
        vector<int> a(n);
        for (int i = 0; i < n; i ++) {
                scanf("%d", &a[i]);
        }
        SegmentTree<pair<int, int>> seg(n);
        for (int i = 0; i < n; i ++) {
                seg.update(i, make_pair(a[i], i));
        }
        for (int i = 0; i < a.size(); i ++) cerr << a[i] << ' '; cerr << endl;
        map<int, int> cnt;
        for (int i = 0; i < n; i ++) {
                cnt[a[i]] ++;
        }
        sort(a.rbegin(), a.rend());
        a.erase(unique(a.begin(), a.end()), a.end());
        vector<long long> ans(n);
        int idx = n;
        int cur = 0;
        long long total = 0;
        for (;;) {
                pair<int, int> ma = seg.query(0, idx);
                total += cnt[a[cur]];
                if (cur + 1 < a.size()) ans[ma.second] += (long long) (a[cur] - a[cur + 1]) * total;
                else ans[ma.second] += (long long) a[cur] * total;
                cur ++;
                if (cur == a.size()) break;
                if (seg.query(0, ma.second).first == a[cur]) {
                        idx = ma.second;
                }
        }
        for (int i = 0; i < n; i ++) {
                printf("%lld\n", ans[i]);
        }
        return 0;
}



Measured memory_bytes: 10240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    ll n;cin>>n;
    vl a(n);rep(i,n)cin>>a[i];

    ll mi=INF,ma=-INF,sum=0;
    rep(i,n){
        chmin(mi,a[i]);
        chmax(ma,a[i]);
        sum+=a[i];
    }
    cout<<mi<<" "<<ma<<" "<<sum<<endl;
}

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



Measured memory_bytes: 3252
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

using pil = pair<int, ll>;
void bfs(int s, vector<ll> &d, vector<vector<ll>> &G) {
    queue<pil> que;
    fill(All(d), INF);
    d[s] = 0;
    que.push(make_pair(0, s));

    while(!que.empty()) {
        pil p = que.front();
        que.pop();
        int v = p.second;
        for(auto nv : G[v]) {
            if(d[nv] == INF) {
                d[nv] = p.first + 1;
                que.push(MP(p.first + 1, nv));
            }
        }
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<ll>> G(N, vector<ll>());
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<ll> dist(N);
    bfs(0, dist, G);
    vector<int> res(N - 1);
    for(int i = 1; i < N; i++) {
        int next = INF;
        for(auto x : G[i]) {
            if(dist[x] < dist[i]) {
                next = x + 1;
                break;
            }
        }
        if(next == INF) {
            cout << "No" << endl;
            return 0;
        }

        res[i - 1] = next;
    }
    cout << "Yes" << endl;
    rep(i, N - 1) cout << res[i] << endl;
    return 0;
}

Measured memory_bytes: 13560