akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int n, m, c[100001];
vector<int> v[100001];
map<int, string> mp;
string go(int i) {
        int cc  = 0;
        string s = "", s1 = to_string(i);
        while (i) { cc++; i /= 10; }
        while (cc < 6) { s += "0"; cc++; }
        s += s1;
        return s;
}
int main() {
        cin >> n>> m;
        for (int i = 0; i < m; i++) {
                int a, b;
                cin >> a>> b;
                c[i] = b;
                v[a].push_back(b);
        }
        for (int i = 1; i <= n; i++) {
                if (v[i].size()) {
                  		sort(v[i].begin(), v[i].end());
                        for (int j = 0; j < (int)v[i].size(); j++) {
                                string str = go(i);
                                str += go(j+1);
                                mp[v[i][j]] = str;
                        }
                }
        }
        for (int i =0; i < m; i++) {
                cout << mp[c[i]]<< endl;
        }
        return 0;
}


Measured memory_bytes: 18432
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

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

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct city_t
{
	ll x, y, p;

};


struct solve
{
	int n;
	vvll dx, dy;
	vll x, y, p;
	vll ans;

	void ready_calc(vll&dx, vll&x, vll&axis)
	{
		dx.resize(n, 30000);
		for(int i=0;i<n;i++)
		{
			auto it=upper_bound(axis.begin(), axis.end(), x[i]);
			int idx=it-axis.begin();
			if(it!=axis.end()) min_u(dx[i], axis[idx]-x[i]);
			if(idx>0) min_u(dx[i], x[i]-axis[idx-1]);
			dx[i]*=p[i];
		}
	}
	void ready(vvll&dx, vll&x)
	{
		dx.resize(1<<n);
		for(int i=0;i<(1<<n);i++)
		{
			vll axis={0};
			for(int j=0;j<n;j++)
			{
				if((i>>j)&1) axis.push_back(x[j]);
			}
			sort(axis.begin(), axis.end());
			ready_calc(dx[i], x, axis);
		}
	}
	solve(vll&x, vll&y, vll&p) : x(x), y(y), p(p) {
		n=x.size();
		ready(dx, x);
		ready(dy, y);
		ans.resize(n+1, 1LL<<60);
		ll m=1;
		for(int i=0;i<n;i++) m*=3;
		for(ll i=0;i<m;i++)
		{
			ll x=i;
			int x_idx=0;
			int y_idx=0;
			int k=0;
			for(int j=0;j<n;j++)
			{
				x_idx<<=1;
				y_idx<<=1;
				switch(x%3)
				{
					case 1: x_idx|=1; k++; break;
					case 2: y_idx|=1; k++; break;
				}
				x/=3;
			}
			ll t=0;
			for(int j=0;j<n;j++)
			{
				t+=min(dx[x_idx][j], dy[y_idx][j]);
			}
			if(min_u(ans[k], t))
			{
//				cout << "(x_idx,y_idx,k)=" << x_idx << "," << y_idx << "," << k << "  " << t << "\n";
			}
		}
	}
	ll operator()(int k)
	{
		return ans[k];
	}
};


int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	for(;;)
	{
		int n;
		cin >> n;
		if(cin.fail()) break;
		vll x(n), y(n), p(n);
		for(int i=0;i<n;i++)
		{
			cin >> x[i] >> y[i] >> p[i];
		}

		solve solver(x, y, p);
		for(int k=0;k<=n;k++)
		{
			cout << solver(k) << "\n";
		}
	}
	return 0;
}


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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  if(s == "RRR"){
    ANS(3);
  }else if(s == "RRS" || s == "SRR"){
    ANS(2);
  }else if(s == "SSS"){
    ANS(0);
  }else{
    ANS(1);
  }
  return 0;
}

Measured memory_bytes: 3604
#include <cstdio>
#define MAXN 2005
#define LL unsigned long long
const int mod = 1e9 + 7;
int n;
int a[MAXN];
int b[MAXN], c[MAXN];
LL k, result;
int main() {
	scanf ( "%d %lld", &n, &k );
	for ( int i = 1;i <= n;i ++ )
		scanf ( "%d", &a[i] );
	for ( int i = 1;i <= n;i ++ )
		for ( int j = i + 1;j <= n;j ++ )
			if ( a[i] > a[j] ) {
				b[i] ++;
				b[i] %= mod;
			}
	for ( int i = 1;i <= n;i ++ )
		for ( int j = 1;j <= n;j ++ )
			if ( a[i] > a[j] ) {
				c[i] ++;
				c[i] %= mod;
			}
	LL tmp = ( k * ( k - 1 ) / 2 ) % mod;
	for ( int i = 1;i <= n;i ++ )
		result = ( result + ( b[i] * k % mod ) + ( c[i] * tmp % mod ) ) % mod;
	printf ( "%lld", result );
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdlib>

using namespace std;

int main(){

    ios::sync_with_stdio(false);

    int n,*v,*c;
    int x=0,y=0;

    cin>>n;

    v = (int*) malloc(n*sizeof(int));
    c = (int*) malloc(n*sizeof(int));

    for(int i=0;i<n;i++)cin>>v[i];
    for(int i=0;i<n;i++){
        cin>>c[i];
        if(c[i]<v[i]){
            x+=v[i];
            y+=c[i];
        }
    }

    cout<<x-y<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int flip(int n){
  int ret = 0;
  while(n > 0){
    ret *= 10;
    ret += n % 10;
    n /= 10;
  }
  return ret;
}

int main(void){
  int A, B;
  cin >> A >> B;
  int ans = 0;
  for(int n = A; n <= B; n++){
    if(n == flip(n)) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#define ll long long
#define mod 998244353
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static int buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10;
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
int a[maxn],cnt[maxn];
int n;
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	if(a[1]){
		puts("0"); return 0;
	}
	std::sort(a+1,a+n+1);
	// for(int i=1;i<=n;i++)
	// 	writesp(a[i]);
	// putchar('\n');
	ll ans=1;
	cnt[0]=1;
	for(int i=2;i<=n;i++)
		if(!a[i])ans=0;
		else ++cnt[a[i]],ans=ans*cnt[a[i]-1]%mod;
	writeln(ans);
	return 0;
}

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

using namespace std;

void West(int surface[]);
void East(int surface[]);
void North(int surface[]);
void South(int surface[]);
void Swing(int surface[]);

typedef struct dice {

	int surface[6];
	string str;

} Dice;

Dice memory;
bool change = false;

int main() {

	Dice dice;
	int n = 0;
	int q[2][100] = { 0 };

	for (int i = 0; i < 6; i++) {

		cin >> dice.surface[i];

	}

	cin >> n;
	memory = dice;

	for (int i = 0; i < n; i++) {

		cin >> q[0][i] >> q[1][i];

	}
	
	for (int i = 0; i < n; i++) {

		change = true;

		for (int u = 0; u < 4; u++) {

			if (dice.surface[0] == q[0][i]) {

				change = false;
				break;

			}

			West(dice.surface);
			dice = memory;

		}

		if (change) {

			for (int u = 0; u < 4; u++) {

				if (dice.surface[0] == q[0][i]) {

					break;

				}

				North(dice.surface);
				dice = memory;

			}

		}

		for (int u = 0; u < 4; u++) {

			if (dice.surface[1] == q[1][i]) {

				break;

			}

			Swing(dice.surface);
			dice = memory;


		}

		cout << dice.surface[2] << endl;

	}

}

void West(int surface[]) {

	memory.surface[0] = surface[2];
	memory.surface[2] = surface[5];
	memory.surface[5] = surface[3];
	memory.surface[3] = surface[0];

	return;

}

void East(int surface[]) {

	memory.surface[0] = surface[3];
	memory.surface[3] = surface[5];
	memory.surface[5] = surface[2];
	memory.surface[2] = surface[0];

	return;

}

void North(int surface[]) {

	memory.surface[0] = surface[1];
	memory.surface[1] = surface[5];
	memory.surface[5] = surface[4];
	memory.surface[4] = surface[0];

	return;

}

void South(int surface[]) {

	memory.surface[0] = surface[4];
	memory.surface[4] = surface[5];
	memory.surface[5] = surface[1];
	memory.surface[1] = surface[0];

	return;

}

void Swing(int surface[]){

	memory.surface[2] = surface[1];
	memory.surface[1] = surface[3];
	memory.surface[3] = surface[4];
	memory.surface[4] = surface[2];

	return;

}




Measured memory_bytes: 3148
// ヘッダファイルのインクルード
#include<stdio.h>
#include<math.h>

// マクロ定義
#define X 0
#define Y 1
#define X_AND_Y 2
#define NORTH 90 //度表現

#define compile 0 //デバッグ用,0:実装版,1:デバッグ版

// 関数のプロトタイプ宣言
double func_cal_rad(double angle); //度からラジアンへ変換する関数
double func_cal_x(double edge, double angle_r, double x); //x座標を計算する関数
double func_cal_y(double edge, double angle_r, double y); //y座標を計算する関数
void func_output(double array[], int n); //結果の出力を行う関数

main()
{
	double input_l = 0, input_t = 0; //入力代入用の変数,input_l:進む距離,input_t:回転する角度
	double turn = 0; //回転角代入用の変数,turn:現在の回転角
	double t_rad = 0; //回転角代入用の変数,t_rad:回転角を[rad]に変換
	double point[X_AND_Y] = {0, 0}; //座標代入用の変数
	
	turn = NORTH; //問題の仕様では最初の角度はx軸に対して垂直(角度は90°)になる
	
	scanf("%lf,%lf", &input_l, &input_t); //入力の取得
	
#if compile == 1 //デバッグ用
	puts("");
#endif
	
	while((0 != input_l) || (0 != input_t)) //input_l,input_tの2値が0でないとき
	{
		t_rad = func_cal_rad(turn); //度表記をラジアン表記に変換
		point[X] = func_cal_x(input_l, t_rad, point[X]); //x座標の計算
		point[Y] = func_cal_y(input_l, t_rad, point[Y]); //y座標の計算
		
#if compile == 1 //デバッグ用
		printf("point[X] = %lf point[Y] = %lf\n", point[X], point[Y]);
#endif
		
		turn -= input_t; //現在の角度の値input_tをturnに代入
		input_l = 0, input_t = 0; //入力前に一度初期化する
		scanf("%lf,%lf", &input_l, &input_t); //入力の取得
	}
	func_output(point, X_AND_Y); //結果の出力
	
	return 0;
}
double func_cal_rad(double angle_d) //度からラジアンへ変換する関数
{
	double rad = 0;
	rad = (angle_d * M_PI) / 180; //角の変換公式を使用,要インクルードmath.h
	return rad;
}
double func_cal_x(double edge, double angle_r, double x) //x座標を計算する関数
{
	double p_x = 0;
	p_x = (double)(edge * cos(angle_r)) + x; //移動先の座標から移動元の座標を引いた長さが移動先のx座標,要インクルードmath.h
	return p_x;
}
double func_cal_y(double edge, double angle_r, double y) //y座標を計算する関数
{
	double p_y = 0;
	p_y = (double)(edge * sin(angle_r)) + y; //移動先の座標から移動元の座標を引いた長さが移動先のy座標,要インクルードmath.h
	return p_y;
}
void func_output(double array[], int n) //結果の出力を行う関数
{
	int i = 0;
	for(i = 0; i < n; i++) //出力をループさせる
	{
		
#if compile == 0 //実装版
		if(0 > array[i]) //array[i]のi番目の要素が0未満の実数の場合
		{
			array[i] = ceil(array[i]); //小数点以下切り上げを行う,要インクルードmath.h
		}
		else //array[i]のi番目の要素が0より大きい実数の場合
		{
			array[i] = floor(array[i]); //小数点以下切り捨てを行う,要インクルードmath.h
		}
#endif
		
#if compile == 0 //実装版
		printf("%.0lf\n", array[i]); //1回目のループでx座標,2回目のループでy座標をそれぞれ表示
#elif compile == 1 //デバッグ版
		printf("%lf\n", array[i]); //1回目のループでx座標,2回目のループでy座標をそれぞれ表示
#endif
	}
}

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

struct e_drink {
  int64_t a, b;
};

int main()
{
  int64_t n, m;
  cin >> n >> m;
  vector<e_drink> drink(n);
  for (int i = 0; i < n; i++) {
    cin >> drink[i].a >> drink[i].b;
  }
  sort(begin(drink), end(drink), [](auto&& d1, auto&& d2){return d1.a < d2.a;});
  int64_t ans = 0;
  for (int i = 0; i < n; i++) {
    if (m <= 0) break;
    int64_t p = drink[i].a;
    int64_t h = drink[i].b;
    if (m >= h) {
      ans += p * h;
      m -= h;
    } else {
      ans += p * m;
      m = 0;
    }
  }
  cout << ans << endl;
}


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

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    set<int> v;

    for (int i = a; i < a + k; i++) {
        if (i <= b) v.insert(i);
    }
    for (int i = b; i > b - k; i--) {
        if (i >= a) v.insert(i);
    }

    for (auto x : v) cout << x << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reg(i,a,b) for(int i=(a);i<=(b);i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=(b);i>=(a);i--)
typedef long long int lli;
typedef pair<int,int> mp;
typedef pair<int,mp> mmp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX

int n,m,fn,qn;

set<int> sets[100005];

struct unifo{
	int uni[100010];
	void init(int n){
		rep(i,n)uni[i]=i;
	}
	int find(int p){
		if(uni[p]==p)return p;
		else return (uni[p]=find(uni[p]));
	}
	void mer(int p,int q){
		if(!same(p,q))uni[find(p)]=find(q);
	}
	bool same(int p,int q){
		return find(p)==find(q);
	}
};

unifo uni;

vector<mp> vs[100005];
mmp es[200005];
int dist[100005];

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

void dijkstra(){
	reg(i,1,n)dist[i] = IINF;
	
	while(!que.empty()){
		mp pa = que.top();
		que.pop();
		int no = pa.sec,
			co = pa.fir;
		if(dist[no]<=co)continue;
		dist[no] = co;
		rep(i,vs[no].size()){
			mp pb = vs[no][i];
			int to = pb.fir,
				tc = co + pb.sec;
				if(dist[to]<=tc)continue;
			que.push(mp(tc,to));
		}
	}
}

int anss[100005];

int main(void){

	scanf("%d%d%d%d",&n,&m,&fn,&qn);
	uni.init(n+3);
	
	rep(i,m){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		vs[a].push_back(mp(b,c));
		vs[b].push_back(mp(a,c));
		es[i] = mmp(-1,mp(a,b));
	}
	
	rep(i,fn){
		int a;
		scanf("%d",&a);
		que.push(mp(0,a));
	}
	
	rep(i,qn){
		int a,b;
		scanf("%d%d",&a,&b);
		sets[a].insert(i);
		sets[b].insert(i);
	}
	
	dijkstra();
	
	/*
	reg(i,1,n){
		printf("dist .. %d\n",dist[i]);
	}*/
	
	rep(i,m){
		mmp& pa = es[i];
		pa.fir = min(dist[pa.sec.fir],dist[pa.sec.sec]);
		//printf("edgs .. %d %d %d\n",pa.sec.fir,pa.sec.sec,pa.fir);
	}
	
	sort(es,es+m,greater<mmp>());
	
	
	rep(i,m){
		mmp pa = es[i];
		int a = es[i].sec.fir,
			b = es[i].sec.sec,
			d = es[i].fir;
		//printf("edg .. %d %d %d\n",a,b,d);
		a = uni.find(a);
		b = uni.find(b);
		if(uni.same(a,b))continue;
		
		set<int> sa,sb;
		swap(sa,sets[a]);
		swap(sb,sets[b]);
		
		if(sa.size()>sb.size())swap(sa,sb);
		
		set<int>::iterator ite;
		
		for(ite = sa.begin(); ite != sa.end(); ite++){
			int no = *ite;
			//printf("set .. %d no .. %d\n",a,no);
			if(sb.find(no)!=sb.end()){
				//printf("merge %d %d %d\n",a,b,no);
				sb.erase(no);
				anss[no] = d;
			}
			else sb.insert(no);
		}
		
		uni.mer(a,b);
		swap(sb,sets[uni.find(a)]);
	}
	
	rep(i,qn){
		printf("%d\n",anss[i]);
	}
	
	return 0;
}

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

using namespace std;
void solve(){
	int k;
	cin>>k;
	string s;
	cin>>s;
	if(s.length()<=k)
		cout<<s<<"\n";
	else
		cout<<s.substr(0,k)<<"...\n";
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	
	solve();

	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<ll,ll>
using namespace std;
#define N 100007
#define pb push_back;
vector<ll> g[N];
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
ll countDiv(ll l,ll r,ll k)
{
    if(l%k==0)
    {
        return r/k-l/k+1;
    }
    return r/k-l/k;
}
int main()
{
    ll l,r,k;
    cin>>l>>r>>k;
    cout<<countDiv(l,r,k);
}

Measured memory_bytes: 5932
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;

int main(){
   int n,m;
   cin >> n >> m;
   vector<int> a(m);
   vector<int> b(m);
   vector<long long> h(n);
   vector<int> ans(n,0);
   vector<int> cou(n,0);
   for(int i=0; i<n; i++) cin >> h[i];
   for(int i=0; i<m; i++){
     cin >> a[i] >> b[i];
     cou[a[i]-1]++;
     cou[b[i]-1]++;
     if(h[a[i]-1]>h[b[i]-1]) ans[a[i]-1]++;
     else if(h[a[i]-1]<h[b[i]-1]) ans[b[i]-1]++;
   }
   int sum =0;
   for(int i=0; i<n; i++){
     if(cou[i]==0) sum++;
     else if(ans[i]==cou[i]) sum++;
   }
   cout << sum << endl;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define MAX(a, b) (((a) > (b)) ? a : b)
#define mod 1000000007
LL ways[1001][1001];

LL cal(LL i, LL j)
{
    //cout<<"LOOP ENTERED\n";
    if (ways[i][j] == -1)
    {
        if (i == 1 && j == 1)
        {
            return 1;
        }
        else if (i == 1 && j != 1)
        {
            if(ways[i][j-1]==-1)
            {
                ways[i][j-1]=cal(i,j-1)%mod;
            }
            ways[i][j]=ways[i][j-1];
        }
        else if (i !=1 && j == 1)
        {
            if(ways[i-1][j]==-1)
            {
                ways[i-1][j]=cal(i-1,j)%mod;
                
            }
            ways[i][j]=ways[i-1][j];
        }
        else
        {
            if(ways[i][j-1]==-1)
            {
                ways[i][j-1]=cal(i,j-1)%mod;
            }
            if(ways[i-1][j]==-1)
            {
                ways[i-1][j]=cal(i-1,j)%mod;
                
            }

            ways[i][j]=(ways[i-1][j]+ways[i][j-1])%mod;
        }      
        
    }
    return ways[i][j];
}

int main()
{
    LL h, w, i, j, k;
    char a;
    for (i = 0; i < 1001; i++)
    {
        for (j = 0; j < 1001; j++)
        {
            ways[i][j] = -1;
        }
    }
    cin >> h >> w;
    for (i = 1; i <= h; i++)
    {
        for (j = 1; j <= w; j++)
        {
            cin >> a;
            if (a == '#')
            {
                ways[i][j] = 0;
            }
        }
    }

    LL ans = cal(h, w) % mod;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

int main() {
	int n; std::cin >> n;
	std::vector<int> b_numbers(n - 1); for (auto& b : b_numbers) std::cin >> b;
	int result = b_numbers.front() + b_numbers.back();
	for (auto i = 1; i < n - 1; ++i) {
		result += std::min(b_numbers[i - 1], b_numbers[i]);
	}
	std::cout << result << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}

//INSERT ABOVE HERE
signed main(){
  int n,m;
  cin>>n>>m;
  string s;
  cin>>s;
  vector<int> ls(m),rs(m);
  for(int i=0;i<m;i++) cin>>ls[i]>>rs[i],ls[i]--;

  vector<int> mv(n);
  iota(mv.begin(),mv.end(),1);
  for(int i=0;i<m;i++)
    chmax(mv[ls[i]],rs[i]);

  for(int i=1;i<n;i++)
    chmax(mv[i],mv[i-1]);

  vector<int> os(n+1,0),zs(n+1,0);
  for(int i=0;i<n;i++){
    os[i+1]=os[i]+(s[i]=='1');
    zs[i+1]=zs[i]+(s[i]=='0');
  }

  using M = Mint<int>;
  vector<M> dp(n+1,0);
  dp[0]=M(1);
  for(int p=0;p<n;p++){
    vector<M> nx(n+1,0);
    for(int i=0;i<=p;i++){
      // put one
      if(i+1<=os[mv[p]])
        nx[i+1]+=dp[i];
      // put zero
      if((p-i)+1<=zs[mv[p]])
        nx[i]+=dp[i];
    }
    swap(dp,nx);
  }

  M ans{0};
  for(auto v:dp) ans+=v;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
#define dec(i,j,k) for(re int i=j;i>=k;i--) 
#define ll long long
using namespace std;
const int N=1e5+5;
int n,m,v,p,a[N],num[N],ans;
bool cmp(int a,int b){return a>b;}
inline int read(){
	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while('0'<=ch&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x; 
}
bool check(int x){
	if(a[x]+m<a[p]) return false;
	int tot=x-p,tmp=v-(n-tot);
	ll res=0;
	inc(i,p,x-1) res+=min(m,a[x]+m-a[i]);
	return res>=1LL*m*tmp;
}
int main(){
	n=read(),m=read(),v=read(),p=read();
	inc(i,1,n) a[i]=read();
	sort(a+1,a+1+n,cmp);
	int L=1,R=n;
	while(L<=R){
		int mid=(L+R)>>1;
		if(check(mid)) ans=mid,L=mid+1;
		else R=mid-1;
	}
	printf("%d",ans);
}


Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
using namespace std;
#define INF 999999999
#define lint long long
#define rep(i, n) for(int i = 1; i <= (int)(n); i++)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define P pair<int, int>

void printP(P p1, P p2){
    cout << p1.first << " " << p2.first << endl;
    cout << p1.first << " " << p2.second << endl;
    cout << p1.second << " " << p2.first << endl;
    cout << p1.second << " " << p2.second << endl;
}

void solve(int N){// N is even
    vector<P> vec;
    if(N == 2) return;
    rep(i, N){
        vec.push_back(P(i, N-i+1));
    }
    for(int i=0; i<N/2-1; ++i){
        for(int j=i+1; j<N/2; ++j){
            printP(vec[i], vec[j]);
        }
    }
}

int main(){
    int N;
    cin >> N;
    if(N%2==0){
        cout << N*(N/2-1) << endl;
        solve(N);
    }
    else{
        cout << (N-1)*((N-1)/2-1)+(N-1) << endl;
        rep(i, N-1){
            cout << N << " " << i << endl;
        }
        solve(N-1);
    }
    return 0;
}

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



int main()
{
    int n,k; cin>>n>>k;
    int * a = new int [n];
    for(int i=0;i<n;i++) cin>>a[i];
    vector<bool> dp(k+1,0);
    dp[0]=false;
    for(int i=1;i<=k;i++)
    {
        dp[i]=false;
        for(int j=0;j<n;j++)
        {
            if(i-a[j]>=0)
            {
                if(dp[i-a[j]]==false) dp[i]=true;
            }
        }
    }
    if(dp[k]==true) cout<<"First";
    else cout<<"Second";


    return 0;
}


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

using namespace std;

int main() {
  int N, M, sum = 0, p, x;
  cin >> N;
  vector<int> T(N);  
  for (int i = 0; i < N; ++i) {
    cin >> T[i];
    sum += T[i];
  }

  cin >> M;
  vector<int> ans(M);
  for (int i = 0; i < M; ++i) {
    cin >> p >> x;
    ans[i] = sum - (T[p - 1] - x);
  }

  for (int i = 0; i < M; ++i) {
    cout << ans[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main(){
  i64 N,K;
  cin >> N >> K;
  
  i64 cnt = 0;
  {
    i64 a = N / K;
    i64 b = N / K;
    cnt += a * a * b;
  }
  for(i64 m = 1;m < K;m++){
    if((2 * m) % K == 0){
      i64 a = (N + K - m) / K;
      i64 b = (N + m) / K;
      cnt += a * a * b;
    }
  }

  cout << max(cnt,0LL) << endl;
}


Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
  var x = Number(input[0].split(" ")[0]);
  var y = Number(input[0].split(" ")[1]);
  var z = Number(input[0].split(" ")[2]);

  console.log(z,x,y);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

#define debug(var)  do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef vector<v2> v3;

typedef unordered_map<ll, unordered_map<ll, ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

ll n,m;
unordered_set<ll> s;

ll min_dist(ll x, ll y){
    if(x > y) swap(x, y);
    return min(y-x, x+n-y);
}

int main(){
    cin >> n >> m;
    ll j = 1;
    ll k = n;
    if(n%2 == 0) s.insert(n/2);
    for(ll i = 0;i < m;i++){
        ll d = min_dist(j, k);
        if(s.count(d)) j++;
        d = min_dist(j, k);
        // debug(d);
        s.insert(d);
        cout << j << " " << k << endl;
        j++;
        k--;
    }
}


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

int main(){

    ll n;
    cin >> n;
    ll k;
    cin >> k;
    ll a[n+1];
    for(ll i = 1;  i <= n ; i++)
    cin >> a[i];

    bool dp[k+1];
    memset(dp , false , sizeof(dp));

    for(ll i  =1 ; i <= k ; i++)
    {
        for(ll j = 1 ; j <= n  ; j++)
        {
            if(a[j] <= i && dp[i-a[j]] == false)
            {
                //cout << i << " " << a[j] << endl;
                dp[i] = true;
            }
        }
    }

    if(dp[k] == true)
    cout << "First" ;
    else
    cout << "Second" ;


}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int N=405;
int a[N];
ll dp[N][N];
bool was[N][N];
ll DP(int l, int r)
{
if(l==r || was[l][r])
return dp[l][r];
was[l][r]=1;
dp[l][r]=1e18;
ll sum=a[l];
for(int i=l+1;i<=r;i++)
dp[l][r]=min(dp[l][r],DP(l,i-1)+DP(i,r)),
sum+=a[i];
dp[l][r]+=sum;
return dp[l][r];
}
int main()
{
int n;
scanf("%i",&n);
for(int i=1;i<=n;i++)
scanf("%i",&a[i]);
printf("%lld",DP(1,n));
return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;

ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll com(ll n,ll k){
    ll res = 1;
    rep(i,k){
        res *= n-i;
        res %= MOD;
        res *= inv[i+1];
        res %= MOD;
    }
    return res;
}
ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    COMinit();
    ll n,a,b;
    cin >> n >> a >> b;
    PRINT((RepeatSquaring(2,n,MOD)+MOD+MOD-com(n,a)-com(n,b)-1)%MOD);
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define maxn 233
using namespace std;
long long a[maxn];
int main() {
	int n, ans = 0;
	cin >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i];
	for(int i = 1; i <= n; ++i) {
		for(int j = i + 1; j <= n; ++j) {
			for(int k = j + 1; k <= n; ++k) {
				int x = a[i], y = a[j], z = a[k];
				if(x != y && y != z && z != x) {
					if(x + y > z && y + z > x && z + x > y) ++ans;
				}
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3588
N, M = map(int, input().split())

K = []
S = []

for m in range(M):
    X = list(map(int, input().split()))
    K.append(X[0])
    tmp = list(map(lambda x: x-1, X[1:]))
    S.append(tmp)

P = list(map(int, input().split()))

#print(N, M)
#print(K)
#print(S)
#print(P)


def strings2list(strings):
    l =  [int(c) for c in strings]
    size = len(l)
    return [0]*(N-size)+l

L = []
for i in range(2**N):
    bi = bin(i)[2:]
    l = strings2list(bi)
        
    flag = [0]*M
    
    
    
    for m in range(M):
        p = P[m]
        s = S[m]
        counter = 0
        for index in s:
            counter += l[index]
        if counter%2!=p:
            flag[m]=1
        
        
    if sum(flag) == 0:
        L.append(l)

print(len(L))    

"""
2 2
2 1 2
1 2
0 1
"""

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MOD = 1000000007;

int main()
{
    string s;
    cin >> s;
    int n = s.size();

    vector<int> dp(13, 0);
    dp[0] = 1;
    for(int i=0; i<n; ++i){
        vector<int> nextDp(13, 0);
        for(int a=0; a<=9; ++a){
            if(s[i] != '?' && s[i] != '0' + a)
                continue;
            for(int x=0; x<13; ++x){
                int y = (x * 10 + a) % 13;
                nextDp[y] += dp[x];
                nextDp[y] %= MOD;
            }
        }
        dp = move(nextDp);
    }
    cout << dp[5] << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ll long long
int main(){
    int n,m; cin >> n >> m;
    ll x[n], y[n], z[n];
    REP(i,n){
        cin >> x[i] >> y[i] >> z[i] ;
    }
    vector<ll> cal[8];
    REP(i,2){
        REP(j,2){
            REP(k,2){
                REP(l,n){
                    cal[i*4+j*2+k].push_back((i*2-1)* x[l] + (j*2-1) * y[l] +(k*2-1) * z[l]);
                }

            }
        }
    }
    ll ans = 0;
    REP(i,2){
        REP(j,2){
            REP(k,2){
                    sort(cal[i*4+j*2+k].begin(),cal[i*4+j*2+k].end(), greater<ll>());
                    ans = max(ans, accumulate(cal[i*4+j*2+k].begin(),cal[i*4+j*2+k].begin()+m, 0LL));
                    
            }
        }
    }
    cout << ans << endl;


}

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

using namespace std;

const int INF = 1e9 + 5;

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

	int N;
	cin >> N;

	vector<int> h(N);
	for (int i = 0; i < N; i++)
		cin >> h[i];
	
	vector<int> dp(N, INF);
	
	dp[0] = 0;

	for (int i = 0; i < N; i++) {
		int sum1 = INF, sum2 = INF;
		for (int j = i + 1; j <= i + 2; j++) {
			if (j < N)
				dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]));
		}
	}

	cout << dp[N-1] << endl;
    return 0;
}


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

using namespace std;


long long H, N;
vector<long long> A;



int main()
{


	cin >> H;
	cin >> N;

	A = vector<long long>(N);

	long long h = H;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		h -= A[i];
	}

	
	cout << ((h<=0)?"Yes":"No") << endl;

	return 0;
}




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

int main()
{
    int A;
    int N[4];
    cin >> A;
    int n1 = A /100;
    int n2 = A %100;
    if ((n1<=12 && n1>0) && (n2<=12 && n2>0))
        cout<<"AMBIGUOUS"<<endl;
    else if ((n1<=12 && n1>0))
        cout<<"MMYY"<<endl;
    else if((n2<=12 && n2>0))
        cout<<"YYMM"<<endl;
    else
        cout<<"NA"<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

map<vi,int> ma;
map<vi,int> rotar;
vi A[1111];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++)
	{
		vi V; 
		for(int j=0;j<4;j++){int x; cin>>x; V.pb(x);} 
		A[i]=V;
		for(int j=0;j<4;j++)
		{
			ma[V]++;
			V.pb(*V.begin()); V.erase(V.begin());
		}
	}
	for(auto X:ma)
	{
		vi v=X.fi; vi ori=v; int cnt=0;
		for(int i=0;i<4;i++)
		{
			v.pb(*v.begin()); v.erase(v.begin());
			if(v==ori) cnt++;
		}
		rotar[v]=cnt;
	}
	ll ans = 0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			vi a = A[i];
			vi b = A[j];
			for(int k=0;k<4;k++)
			{
				ma[a]--; ma[b]--;
				a.pb(*a.begin()); a.erase(a.begin());
				b.pb(*b.begin()); b.erase(b.begin());
			}
			for(int k=0;k<4;k++)
			{
				vi F[4];
				F[0] = {a[0],b[1],b[0],a[1]};
				F[1] = {a[3],a[2],b[3],b[2]};
				F[2] = {b[1],a[0],a[3],b[2]};
				F[3] = {a[1],b[0],b[3],a[2]};
				if(!ma[F[0]]||!ma[F[1]]||!ma[F[2]]||!ma[F[3]]) {b.pb(*b.begin()); b.erase(b.begin()); continue;}
				ll res = 1;
				for(int z=0;z<4;z++)
				{
					res*=ma[F[z]];
					for(int dir=0;dir<4;dir++)
					{
						ma[F[z]]--;
						F[z].pb(*F[z].begin()); F[z].erase(F[z].begin());
					}
				}
				for(int z=0;z<4;z++)
				{
					for(int dir=0;dir<4;dir++)
					{
						ma[F[z]]++;
						F[z].pb(*F[z].begin()); F[z].erase(F[z].begin());
					}
				}
				ans += res;
				b.pb(*b.begin()); b.erase(b.begin());
			}
			for(int k=0;k<4;k++)
			{
				ma[a]++; ma[b]++;
				a.pb(*a.begin()); a.erase(a.begin());
				b.pb(*b.begin()); b.erase(b.begin());
			}
		}
	}
	cout<<ans/3<<'\n';
}


Measured memory_bytes: 35584
# -*- Coding: utf-8 -*-
#import numpy as np

def count(s):
	i = 0
	a_cnt = 0
	cnt = 0
	while i < len(s):
		if s[i] == 'A':
			a_cnt += 1
		if s[i] =='D':
			cnt += a_cnt

		i += 1

	return cnt



originalS = raw_input()
originalS = originalS.replace('BC', 'D')
originalS = 'B'+originalS+'B'	


idx = []
i = 0

while i < len(originalS):
	if (originalS[i] == 'B')|(originalS[i] == 'C'):
		idx.append(i)
	i += 1


Substr = []

i = 0
while i < len(idx)-1:
	if idx[i+1]-idx[i]!=1:
		Substr.append(originalS[idx[i]+1:idx[i+1]])

	i += 1

ans = 0
for c in Substr:
	ans += count(c)

print ans


Measured memory_bytes: 9256
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import Data.Char

main = do
  s <- getLine
  let n = length s
      state = foldl (\(a, b) i -> if i >= 2 && i <= n - 2
        then if s !! i == 'C' then (a + 1, b) else if isUpper (s !! i) then (a, b + 1) else (a, b)
        else if isUpper (s !! i) then (a, b + 1) else (a, b)
        ) (0, 0) [1..(n - 1)]
  putStrLn $ if s !! 0 == 'A' && state == (1, 0) then "AC" else "WA"


Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    int H[N];
    for(int i = 0; i < N; i++) cin >> H[i];
    bool good[N];
    for(int i = 0; i < N; i++) good[i] = true;
    for(int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        if(H[A] > H[B])
            good[B] = false;
        else if(H[A] < H[B])
            good[A] = false;
        else
            good[A] = good[B] = false;
    }
    int ans = 0;
    for(int i = 0; i < N; i++)
        if(good[i]) ans++;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4120
n, k = map(int, input().split())
ar = {}
for i in range(n):
    a, b = map(int, input().split())
    if (a in ar) == True:
        ar[a] += b
    else:
        ar[a] = b

for i in sorted(ar.keys()):
    k -= ar[i]
    if k <= 0:
        print(i)
        break


Measured memory_bytes: 16080
D = {}
N = int(input())
for i in range(N):
  A = int(input())
  if A in D:
    if D[A] == 1:
      D[A] -= 1
    else:
      D[A] += 1
  else:
    D[A] = 1
print(sum(D[i] for i in D))

Measured memory_bytes: 15072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int maxn = 1e6 + 7;
int n, m, k;


int main() 
{
    ios::sync_with_stdio(0); cin.tie(0); //C++关同步
    ll n, k;
    cin >> n >> k;
    ll ans = n;
    n = abs(n - k);
    ans = min(ans, n);
    n = n % k;
    ans = min(ans, n);
    n = abs(n - k);
    ans = min(ans, n);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 1000000000000000000

int main(void)
{
    string A, B, C;
    cin >> A >> B >> C;
    if( A[A.length()-1] == B[0] && B[B.length()-1] == C[0] ){
        cout << "YES" << endl;
    }else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {
	
	char str[100];
	scanf("%s", str);
	string s = str;
	printf("%c%d%c\n", s.front(), s.length() - 2, s.back());

	return 0;
}


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

int main()
{
    int n,m;
    cin>>n>>m;
    int a[m];
    int sum=0;
    for(int i=0;i<m;i++)cin>>a[i],sum+=a[i];
    //cout<<sum<<endl;
    if(sum<=n)cout<<n-sum<<endl;
    else cout<<-1;
    return 0;
}


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

set<int> dcare;

int solve(){
  int n,target,up,down,temp;
  cin>>target>>n;
  for(int i=0;i<n;i++){
    cin>>temp;
    dcare.insert(temp);
  }
  up=target;down=target;
  if(dcare.count(target)==0) return(target);
  while(1){
    up++;down--;
    if(dcare.count(down)==0) return(down);
    if(dcare.count(up)==0) return(up);
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int t=1;
  //cin>>t;
  while(t--) cout<<solve()<<'\n';
}

Measured memory_bytes: 3656
#include <stdio.h>

int main(){
    //読み取り
    int a;
    int ans;
    scanf("%d",&a);
    if(a%2==0){
        ans = (a/2)*(a/2);
        printf("%d",ans);
    }else{
        ans = ((a+1)/2) * ((a-1)/2);
        printf("%d",ans);
    }
    return 0;
}

Measured memory_bytes: 128
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e17+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
//  17:50-
//A 17:54 AC
//B 17:58 AC
//C 18:05 AC
bool solve(void){
	int n,m,i,j,k;cin>>n;
	if(n==0){return false;}
	vector<int>w(n);
	static bool can[300][300];
	for(i=0;i<n;i++){cin>>w[i];}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){can[i][j]=false;}
		if(i>0){can[i][i-1]=true;}
	}
	for(i=2;i<=n;i++){
		for(j=0;j<=n-i;j++){
			int L=j,R=j+i-1;
			for(k=2;k<i;k+=2){
				int Lm=j+k-1,Rm=j+k;
				if(can[L][Lm]&&can[Rm][R]){can[L][R]=true;break;}
			}
			if(can[L+1][R-1]&&abs(w[L]-w[R])<=1){can[L][R]=true;}
		}
	}
	vector<int>dp(n+1,0);
	dp[0]=0;
	for(i=0;i<n;i++){
		maxeq(dp[i+1],dp[i]);
		for(j=i+1;j<n;j+=2){
			if(can[i][j]){maxeq(dp[j+1],dp[i]+j-i+1);}
		}
	}
	cout<<dp[n]<<endl;
	return true;
}
int main(void){
	while(solve()){}
	return 0;
}


Measured memory_bytes: 3184
#include <iostream>
#include <stack>
#include <string>
#include <sstream>
using namespace std;
int main(){
    string instr; getline(cin,instr);
    stringstream ss; ss.str(instr);
    stack<int> st;
    while(!ss.eof()){
        string s; ss >> s;
        if(s[0] == '+'){
            int a = st.top(); st.pop();
            int b = st.top(); st.pop();
            st.push(a+b);
        }
        else if(s[0] == '-'){
            int a = st.top(); st.pop();
            int b = st.top(); st.pop();
            st.push(b-a);
        }
        else if(s[0] == '*'){
            int a = st.top(); st.pop();
            int b = st.top(); st.pop();
            st.push(a*b);
        }
        else{
            st.push(stoi(s));
        }
    }
    cout << st.top() << endl;
    return 0;
}


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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
int main() {
  int a,b,c,d;cin>>a>>b>>c>>d;
  bool ans=false;
  if(abs(c-a)<=d){
    ans=true;
  }else if((abs(b-a)<=d)&&(abs(c-b)<=d)){
    ans=true;
  }
  cout << (ans?"Yes":"No") << endl;
}

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

int loop;
int runner,OUT,point;
string stait;

int main(){
  scanf("%d",&loop);
  for(int i=0;i<loop;i++){
    point = 0;
    OUT=0;
    runner=0;
      while(OUT<3){
	cin>>stait;
	if(stait=="HOMERUN"){
	  point += runner + 1;
	  runner = 0;
	}
	if(stait=="OUT"){
	  OUT++;
	}
	if(stait=="HIT"){
	  if(runner==3){
	    point++;
	  }else{
	    runner++;
   	  }
	}
      }
      printf("%d\n",point);
  }
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
typedef pair<double, double> P;
typedef pair<P, int> P2;

#define INF 100000000

int n;
double s[55] = {0}, v[55] = {0}, d[55] = {0};
P2 dp[1 << 16][16];
vector<int>e;

void dfs(int now, int nowb){
	e.push_back(s[now]);
	if(dp[nowb][now].second == -1) return;
	dfs(dp[nowb][now].second, nowb & ~(1 << now));
}

int main(){
	cin >> n;
	for(int i = 0; i < n; i++) cin >> s[i] >> d[i] >> v[i];
	for(int i = 0; i < (1 << n); i++){
		for(int j = 0; j < n; j++){
			dp[i][j].first.second = INF;
		}
	}
	for(int i = 0; i < (1 << n); i++){
		for(int j = 0; j < n; j++){
			if(i == 0){
				dp[(1 << j) | i][j].first.first = v[j]*20.0;
				dp[(1 << j) | i][j].first.second = 0;
				dp[(1 << j) | i][j].second = -1;
 			}
			else{
				if(i & (1 << j)) continue;
				for(int k = 0; k < n; k++){
					if(!(i & (1 << k))) continue;
					int pv = dp[i][k].first.first;
					int pd = dp[i][k].first.second;
					if((2000.0 / (70.0 + pv)) <= 0) continue;
					if(dp[i | (1 << j)][j].first.second > pd + (abs(d[j] - d[k]) / (2000.0 / (70.0 + pv)))){
						dp[i | (1 << j)][j].first.first = pv + v[j]*20.0;
						dp[i | (1 << j)][j].first.second = pd + (abs(d[j] - d[k]) / (2000.0 / (70.0 + pv)));
						dp[(1 << j) | i][j].second = k;
					}
				}
			}
		}
	}
	int st = -1;
	int ma = INF;
	for(int i = 0; i < n; i++){
		if(ma > dp[(1 << n) - 1][i].first.second){
			ma = dp[(1 << n) - 1][i].first.second;
			//cout << ma << endl;
			st = i;
		}
		//out << dp[(1 << n) - 1][i].first.second << endl;
	}
	dfs(st, (1 << n)-1);
	//cout << endl;
	for(int i = n-1; i >= 0; i--){
		if(i == 0) cout << e[i] << endl;
		else cout << e[i] << " ";
	}
	return 0;
}



Measured memory_bytes: 27752
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    for(int i=1;i<=n;i++){
        if(i%3 != 0 && i%5 != 0){
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3672
N,M = [int(i) for i in input().split()]

items = [int(i) for i in input().split()]
items.sort(reverse=True)
total = sum(items)

flag = 1
for i in range(M):
  if total / (4 * M) <= items[i]:
    pass
  else:
    flag = 0
if flag:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064