akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

// ユークリッド互除法の最大公約数の実装コピペ
int gcd(int m, int n) {
  if ( ( 0 == m ) || ( 0 == n ) )
    return 0;

  while( m != n )
  {
    if ( m > n ) m = m - n;
    else         n = n - m;
  }
  return m;
}

int main() {
  int x, y;
  cin >> x >> y;
  // 考察より x + y - gcd(x, y) + 1
  cout << (x + y - gcd(x, y) + 1) << endl;
}




Measured memory_bytes: 3204
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

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

  int d;
  cin >> d;

  if(d == 25){
    cout << "Christmas" << endl;
  }
  else if(d == 24){
    cout << "Christmas Eve" << endl;
  }
  else if(d == 23){
    cout << "Christmas Eve Eve" << endl;
  }
  else if(d == 22){
    cout << "Christmas Eve Eve Eve" << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void){
	
	int h,w,i,j;
	while(1){
		scanf("%d %d",&h,&w);
		if(h==0 && w==0)break;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if(i==0 || j==0 || i==h-1 || j==w-1
				){
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  vector<int> va(n);
  for (int i = 0; i < n; i++) {
    cin >> va[i];
  }

  int ex_sum = accumulate(va.begin(), va.end(), 0, [](int a, int b) { return a ^ b; });
  if (ex_sum == 0) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int linearsearch(int[],int,int);
int main(){
  int i,j,n,x,key,count=0;
  int A[10000];
    scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&j);
  for(i=0;i<j;i++){
    scanf("%d",&key);
    x=linearsearch(A,n,key);
    if(x!=n+1)count++;
  }
  printf("%d\n",count);
  return 0;
}
int linearsearch(int A[],int n,int key){
  int i=0;
  A[n]=key;
  while(A[i]!=key)i++;
  if(i==n)return n+1;
  else return i;
}



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

int main()
{
	int n, s, c, t, p = 1001;
	cin >> n >> s;

	for (int i = 0; i < n; i++) {
		cin >> c >> t;
		if (t <= s && c < p)
			p = c;
	}

	if (p < 1001)
		cout << p << endl;
	else
		cout << "TLE" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = sc.nextInt()
    val b = sc.nextInt()
    val p = (1..n).map {
        val P = sc.nextInt()
        when {
            P <= a -> "A"
            P <= b -> "B"
            else -> "C"
        }
    }
    val countA = p.count{it == "A"}
    val countB = p.count{it == "B"}
    val countC = p.count{it == "C"}
    println(Math.min(countA, Math.min(countB, countC)))
}

Measured memory_bytes: 29476
a, b, c, x, y = map(int, input().split())
pay = 0
minxy = min(x, y)
if a + b > c * 2:
  pay += minxy * c * 2
else:
  pay += minxy * a + minxy * b
if x == minxy:
  pay += min((c * 2) * (y - minxy), b * (y - minxy))
else:
  pay += min((c * 2) * (x - minxy), a * (x - minxy))
print(pay)

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector<int> indices(n);
  iota(indices.begin(), indices.end(), 0);
  sort(indices.begin(), indices.end(), [&a](size_t i1, size_t i2) {
      return a[i1] < a[i2];
    });

  for (int i = 0; i < n; ++i) {
    cout << indices[i] + 1;
    if (i == n - 1) puts("");
    else cout << " ";
  }
  return 0;
}



Measured memory_bytes: 1536
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;
typedef vector<pi> vp;

int n,y[9],x[9],K,u[111],v[111],Y,X;
int b[111][111];

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

map<vp,int> M;
queue<vp> Q;

inline int majadist(const pair<int,int> &a, const pair<int,int> &b) {
	int dx = abs(a.first - b.first);
	int dy = abs(a.second - b.second);
	int dz = abs(a.first+a.second-b.first-b.second);
	return min(dx+dy, min(dx+dz, dy+dz));
}

int dist;
void f(int cur,vp v){
	if(cur>=n){
		int ok=1;
		rep(i,n)rep2(j,i+2,n){
			if(majadist(v[i],v[j])<=1){ok=0;break;}
		}
		if(ok && M.find(v)==M.end()){
			M[v] = dist+1;
			Q.push(v);
		}
		return;
	}
	f(cur+1,v);
	int y=v[cur].fir,x=v[cur].sec;
	rep(dir,6){
		int ny=y+dy[dir],nx=x+dx[dir];
		if(b[ny][nx])continue;
		if(cur==0 && majadist(mp(ny,nx),mp(50,50)) > 20-dist-1)continue;
		if(cur-1>=0 && majadist(mp(ny,nx),v[cur-1])!=1)continue;
		if(cur+1<n  && majadist(mp(ny,nx),v[cur+1])!=1)continue;
		vp w=v;
		w[cur].fir=ny;
		w[cur].sec=nx;
		f(cur+2,w);
	}
}

void main2(){
	M.clear();
	while(sz(Q))Q.pop();
	
	vp v;
	rep(i,n)v.pb(mp(y[i],x[i]));
	Q.push(v);
	M[v]=0;
	while(sz(Q)){
		vp v=Q.front();Q.pop();
		dist=M[v];
		if(v[0].fir==Y && v[0].sec==X){
			cout<<M[v]<<endl;
			break;
		}
		f(0,v);
	}
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>n && n){
		memset(b,0,sizeof(b));
		rep(i,n)cin>>y[i]>>x[i];
		cin>>K;
		rep(i,K)cin>>u[i]>>v[i];
		cin>>Y>>X;
		rep(i,n)y[i]-=Y-50,x[i]-=X-50;
		rep(i,K){
			u[i]-=Y-50,v[i]-=X-50;
			if(0<=u[i] && u[i]<=100 && 0<=v[i] && v[i]<=100){
				b[u[i]][v[i]]=1;
			}
		}
		Y-=Y-50,X-=X-50;
		main2();
	}
}

Measured memory_bytes: 19512
#include <bits/stdc++.h>
using namespace std;
static const int MAX=(int) 2e5;

int N,P[MAX+1],Q[MAX+1];
int k=1; //Q[]の最長部分列のサイズ
int aa,max_k=1;
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin >> N;
    for(int i=1;i<=N;i++) cin >> P[i];
    for(int i=1;i<=N;i++) Q[P[i]] = i; 
    aa = Q[1];
    for(int i=2;i<=N;i++){
        if(aa<Q[i]) k++;
        else k=1;
        aa = Q[i];
        max_k = max(max_k,k);
    }
    cout << N - max_k <<"\n";
    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++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 comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    LL a, b, k;
    cin >> a >> b >> k;
    if( k >= a ) {
        k -= a;
        a = 0;

    } else {
        a -= k;
        k = 0;

    }
    cout << a << " " << max(b - k, 0ll) << endl;
    

    return 0;
}



Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(lambda x: int(x) * (int(x)+1) // 2 / int(x), input().split()))

prev = sum(p[0:k])
sum_max = prev
for i in range(n-k+1):
    if i == 0:
        tmp = prev
    else:
        tmp = prev - p[i-1] + p[i+k-1]

    sum_max = max(sum_max, tmp)
    prev = tmp

print(sum_max)


Measured memory_bytes: 23588
import java.util.*;
import java.io.*;
 
class Main{
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] ss = br.readLine().split(" ");
         
        int n = Integer.parseInt(ss[0]);
        int m = Integer.parseInt(ss[1]);
        int l = Integer.parseInt(ss[2]);
        int num1[][] = new int[n][m];
        int num2[][] = new int[m][l];
         
        for(int i=0; i<n; i++){
            String[] s = br.readLine().split(" ");
            for(int j=0; j<m; j++){
                num1[i][j] = Integer.parseInt(s[j]);
            }
        }
        for(int i=0; i<m; i++){
            String[] str = br.readLine().split(" ");
            for(int j=0; j<l; j++){
                num2[i][j] = Integer.parseInt(str[j]);
            }
        }
        for(int i=0; i<n; i++){
            for(int j=0; j<l; j++){
                long a=0;
                for(int k=0; k<m; k++){
                    a += num1[i][k] * num2[k][j];
                }
                System.out.print(a);
                if(j+1<l){
                    System.out.print(" ");
                }
                a=0;
            }
            System.out.println("");
        }
    }
}

Measured memory_bytes: 29060
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;

typedef int64_t i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
    i64 from, to, cost;
    edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
    edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

// 多重vectorを可変引数テンプレートで http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}
//

#pragma endregion

int main() {
    i64 h, w, n;
    cin >> h >> w >> n;
    i64 x, y;
    cin >> x >> y;
    string s, t;
    cin >> s >> t;
    char cs[4] = {'L', 'R', 'U', 'D'};
    vector<int> pos(4);
    pos[0] = pos[1] = y;
    pos[2] = pos[3] = x;
    for (int i = 0; i < n; ++i) {
        if(s[i] == 'L') pos[0]--;
        if(s[i] == 'R') pos[1]++;
        if(s[i] == 'U') pos[2]--;
        if(s[i] == 'D') pos[3]++;
        if (pos[0] <= 0 || pos[2] <= 0 || pos[1] > w || pos[3] > h) {
            cout << "NO" << endl;
            return 0;
        }
        if (t[i] == 'L' && pos[1] >= 2) pos[1]--;
        if (t[i] == 'R' && pos[0] < w) pos[0]++;
        if (t[i] == 'U' && pos[3] >= 2) pos[3]--;
        if (t[i] == 'D' && pos[2] < h) pos[2]++;
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
typedef long long int  ll;
const int mod=1e9+7;
const int N=2e5+5;


int main()
{
   ll l,r,ans=1e9;
   cin>>l>>r;
   if(r-l>=2019)return cout<<0,0;
   for(ll i=l;i<=r;i++){ 
       for(ll j=i+1;j<=r;j++){ 
           ll r=(i*j)%2019;
//cout<<i<<"  "<<j<<"  "<<r<<endl;
           ans=min(ans,r);
       }
   }
   cout<<ans<<'\n';
   
 

     
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

const int MAX = 200000;
int a[MAX], b[MAX], c[MAX];
signed main(){
  int n, m, q;
  cin >> n >> m >> q;
  rep(i,n)cin >> a[i];
  rep(i,m)cin >> b[i];
  rep(i,q)cin >> c[i];
  rep(i,q){
    int x = c[i];
    int idx1 = lower_bound(a, a+n, x)-a;
    int idx2 = lower_bound(b, b+m, x)-b;
    int ans = INF;
    int d1[2], d2[2];
    d1[0] = (idx1 == 0 ? -INF : a[idx1-1]);
    d2[0] = (idx2 == 0 ? -INF : b[idx2-1]);
    d1[1] = (idx1 == n ? INF : a[idx1]);
    d2[1] = (idx2 == m ? INF : b[idx2]);
    chmin(ans, max(d1[1], d2[1]) - x);
    chmin(ans, x - min(d1[0], d2[0]));
    chmin(ans, 2*(x-d1[0]) + (d2[1]-x));
    chmin(ans, 2*(x-d2[0]) + (d1[1]-x));
    chmin(ans, 2*(d2[1]-x) + (x-d1[0]));
    chmin(ans, 2*(d1[1]-x) + (x-d2[0]));
    // if(ans < 0)cout << "no" << endl;
    printf("%lld\n", ans);
  }
  return 0;
}






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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,n;
    cin >> h >> n;

    vector<int> a(n);
    vector<int> b(n);
    int mx=0;
    for(int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        mx=max(mx,a[i]);
    }

    vector<int> dp(h+mx,1e9);
    dp[0]=0;

    for(int i = 1; i < h+mx; i++) {
        for(int j = 0; j < n; j++) {
            if(a[j]<=i) dp[i] = min(dp[i],dp[i-a[j]]+b[j]);
        }
    }
    int ans=dp[h];
    for(int i = 0; i < mx; i++) {
        ans=min(ans,dp[h+i]);
    }
    cout << ans << "\n";

    return 0;
}

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

struct Card
{
	char suit;
	char value;
};

bool bubbleSort(Card C[], int N)
{
	bool isStable = true;

	for (int i = 0; i < (N - 1); i++)
	{
		for (int j = N - 1; j > i; j--)
		{
			if (C[j - 1].value > C[j].value)
			{
				swap(C[j - 1], C[j]);
			}
		}
	}
	return isStable;
}

void selectionSort(Card C[], int N)
{

	for (int i = 0; i < N - 1; i++)
	{
		int minPos = i;
		for (int j = i + 1; j < N; j++)
		{
			if (C[minPos].value > C[j].value)
			{
				minPos = j;
			}
		}
		if (i != minPos) {
			swap(C[i], C[minPos]);
		}
	}
}

void traceData(Card C[], int N)
{
	int i;
	for (i = 0; i < N - 1; i++)
	{
		cout << C[i].suit << C[i].value << " ";
	}
	cout << C[i].suit << C[i].value << endl;
}

bool isStable(Card C1[], Card C2[], int N)
{
	for (int i = 0; i < N; i++)
	{
		if (C1[i].suit != C2[i].suit) return false;
	}
	return true;
}

int main()
{
	Card C1[36], C2[36];
	int N;

	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> C1[i].suit >> C1[i].value;
		C2[i] = C1[i];
	}

	bubbleSort(C1, N);
	traceData(C1, N);
	cout << "Stable" << endl;

	selectionSort(C2, N);
	traceData(C2, N);
	if (isStable(C2, C1, N) == true)
	{
		cout << "Stable" << endl;
	}
	else
	{
		cout << "Not stable" << endl;
	}

	return 0;
}

Measured memory_bytes: 3112
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = 1e9 + 7;


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

const ll MOD = 1e9 + 7;



int main() {


	ll n, m;
	cin >> n >> m;
	
	priority_queue<ll, vector<ll>, greater<ll> > que;

	for (int i = 0; i < n; i++)
	{
		ll tmp;
		cin >> tmp;
		que.push(tmp);
	}

	vector<pll> query(m);
	for (int i = 0; i < m; i++)
	{
		cin >> query[i].first >> query[i].second;
	}
	sort(query.begin(), query.end(), greater<pll>());


	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < query[i].first; j++)
		{
			ll tmp = que.top();
			if (tmp < query[i].second)
			{
				que.pop();
				que.push(query[i].second);
			}
			else
			{
				break;
			}
		}
	}

	ll ans = 0;
	while (!que.empty())
	{
		ans += que.top();
		que.pop();
	}
	cout << ans << endl;

	return 0;
}


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

int main(){
  int x;
  cin>>x;
  if(x==5||x==7||x==3) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>

using namespace std; 
int main(){
    int i=0,j=0;
    int m=1,h=1;
    do{
        cin >> m >> h;
        if(m !=0 && h != 0){
            for ( i = 0; i < m; i++){
                for ( j = 0; j < h; j++){
                    if((i+j)%2 == 0){
                        cout << "#";
                    }else {
                        cout << ".";
                    }
                }
                cout << "\n";
            }
            cout << "\n";
        }
    }while(m !=0 && h != 0);
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
LL mod = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(x); sll(y);
	pll(x+y/2); nl;
}

Measured memory_bytes: 256
class Dice():
	def __init__(self, label):
		self.d = label
	
	def roll(self, drt):
		if drt == 'N':
			self.d[1], self.d[2], self.d[6], self.d[5] = self.d[2], self.d[6], self.d[5], self.d[1]
		elif drt == 'E':
			self.d[1], self.d[3], self.d[6], self.d[4] = self.d[4], self.d[1], self.d[3], self.d[6]
		elif drt == 'S':
			self.d[2], self.d[6], self.d[5], self.d[1] = self.d[1], self.d[2], self.d[6], self.d[5]
		elif drt == 'W':
			self.d[4], self.d[1], self.d[3], self.d[6] = self.d[1], self.d[3], self.d[6], self.d[4]
	def printl(self, lct):
		print(self.d[lct])
		
label = [0]	
label.extend(list(map(int, input().split())))
dice1 = Dice(label)
direction = input()
leng = len(direction)

for i in range(leng):
	dice1.roll(direction[i])

dice1.printl(1)

Measured memory_bytes: 7812
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = s.charAt(i) - '0';
		}
		long ans = 0;
		for(int i=0;i<1<<(n-1);i++) {
			long sum = 0;
			long now = 0;
			for(int j=0;j<n;j++) {
				now = now * 10 + a[j];
				if ((i >> j & 1) == 1) {
					sum += now;
					now = 0;
				}
			}
			sum += now;
			ans += sum;
		}
		System.out.println(ans);
	}
 
}

Measured memory_bytes: 21588
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> values(n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &values[i]);

  vector<array<lint, 3>> dp_right(n + 1), dp_left(n + 1);

  for (int i = n - 1; i >= 0; --i) {
    for (int j = 0; j < 3; ++j) {
      dp_right[i][j] = LLONG_MAX;
      if (j - 1 >= 0) dp_right[i][j] = min(dp_right[i][j], dp_right[i][j - 1]);
      if (j == 2) {
        dp_right[i][j] = min(dp_right[i][j], dp_right[i + 1][j] + (values[i] % 2 != 1));
      } else if (j == 1) {
        dp_right[i][j] = min(dp_right[i][j], dp_right[i + 1][j] + (values[i] == 0 ? 2 : (values[i] % 2 != 0)));
      } else {
        dp_right[i][j] = min(dp_right[i][j], dp_right[i + 1][j] + values[i]);
      }
    }
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 3; ++j) {
      dp_left[i + 1][j] = LLONG_MAX;
      if (j - 1 >= 0)
        dp_left[i + 1][j] = min(dp_left[i + 1][j], dp_left[i + 1][j - 1]);
      if (j == 2) {
        dp_left[i + 1][j] = min(dp_left[i + 1][j], dp_left[i][j] + (values[i] % 2 != 1));
      } else if (j == 1) {
        dp_left[i + 1][j] = min(dp_left[i + 1][j], dp_left[i][j] + (values[i] == 0 ? 2 : (values[i] % 2 != 0)));
      } else {
        dp_left[i + 1][j] = min(dp_left[i + 1][j], dp_left[i][j] + values[i]);
      }
    }
  }

  lint result = LLONG_MAX;
  for (int i = 0; i < n; ++i)
    result = min(result, dp_right[i][2] + dp_left[i][2]);
  printf("%lld\n", result);

  return 0;
}


Measured memory_bytes: 10368
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define SIZE 2000000

int A[SIZE];
int H;

void insert(int x)
{
  int tmp;
  A[H] = x;
  H++;
  int i=H-1;
  int parent = (i-1)/2;
  if (H<1) return;
  while (A[parent]<A[i]) {
    tmp = A[parent];
    A[parent] = A[i];
    A[i] = tmp;
    if (i==0) break;
    tmp = i;
    i = parent;
    parent = (i-1)/2;
  }
}

void maxHeapify(int i) {
  int largest, tmp;
  int l = (i+1)*2-1;
  int r = (i+1)*2;

  if (l<H && A[l]>A[i])      largest = l;
  else                       largest = i;
  if (r<H && A[r]>A[largest])  largest = r;

  if (largest != i) {
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest);
  }
}
int extract()
{
  if (H<0) return -1;
  int val = A[0];
  A[0]=A[H-1];
  maxHeapify(0);
  H--;
  return val;
}


void print()
{
  int i, n=1;
  printf("[ ");
  while (1) {
    for (i=n-1; i<=(n-1)*2; i++) {
      if (i>=H) goto END;
      printf("%d ",A[i]);
    }
    printf("\n");
    n*=2;
  }
 END:
  printf("] H==%d\n", H);
}

int main() {
  int key;
  char com[20];
  while (1) {
    scanf("%s", com);
    if (com[2] == 'd')   break;
    if (com[0] == 'i') {
      scanf("%u", &key);
      insert(key);
    } else { // extract
      int e = extract();
      if (e<0) break;
      printf("%d\n", e);
    }
  }
  return 0;
}


Measured memory_bytes: 5768
import java.util.*;
class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int N = sc.nextInt(),A[] = new int[N],C[] = new int[N],i;
		for(i=0;i<N;i++) {
			A[i]=sc.nextInt();
			C[i]=A[i];
		}
		Arrays.sort(C);
		for(i=0;i<N;i++) System.out.println(A[i]==C[N-1]?C[N-2]:C[N-1]);
	}
}

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

int N, Q, A[1 << 18], B[1 << 18], P[1 << 18], G[1 << 18], S[1 << 18];
vector<int> X[1 << 18];
bool used[1 << 18];

void dfs(int pos) {
	used[pos] = true;
	for (int i = 0; i < X[pos].size(); i++) {
		int to = X[pos][i];
		if (used[to] == true) continue;
		S[to] += S[pos];
		dfs(to);
	}
}

int main() {
	cin >> N >> Q;
	for (int i = 1; i <= N - 1; i++) {
		cin >> A[i] >> B[i];
		X[A[i]].push_back(B[i]);
		X[B[i]].push_back(A[i]);
	}
	for (int i = 1; i <= Q; i++) { cin >> P[i] >> G[i]; S[P[i]] += G[i]; }
	dfs(1);
	for (int i = 1; i <= N; i++) { if (i >= 2) cout << " "; cout << S[i]; } cout << endl;
	return 0;
}

Measured memory_bytes: 29056
#include<bits/stdc++.h>
using namespace std;
main(){
  int N;
  string S;
  cin>>N>>S;
  int x=0,x_max=0;
  for(char c:S){
    x+=c=='I'?1:-1;
    x_max=max(x_max,x);
  }
  cout<<x_max<<endl;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int Q=in();
	multimap<string,int> M;
	REP(i,Q){
		int q=in();
		if(q==1){
			string key=in<string>();
			auto res = M.equal_range(key);
			while(res.first!=res.second){
				out(res.first->second);
				res.first++;
			}
		}
		else if(q==2){
			M.erase(in<string>());
		}
		else if(q==3){
			auto start = M.lower_bound(in<string>());
			auto end = M.upper_bound(in<string>());
			while(start!=end){
				out(start->first,start->second);
				++start;
			}
		}
		else{
			string key=in<string>();
			M.emplace(key,in());
		}
	}
	return 0;
}


Measured memory_bytes: 24904
/*
 *Author - Abhas Jain
 */
 
#include <bits/stdc++.h>
 
#define F first
#define S second
#define all(c) c.begin(), c.end()
#define endl '\n'
#define pb push_back
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
 
typedef long long ll;
typedef long double ld;
 
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
 
const ld PI = 3.141592653589793;
const ll INF = 9223372036854775807ll;
const ll mod = 1e9 + 7;
 
void solve() 
{
	string s;
	cin >> s;
	if (s.length() == 1) {
		cout << 1 << endl;
		return;
	}
	vector<string> v;
	string cur = "";
	for (int i = 0; i < s.length(); ++i) {
		cur += s[i];
		if (i == 0 || v[v.size() - 1] != cur) {
			v.pb(cur);
			cur = "";
		}
	}
	cout << v.size() << endl;
}
 
int main( )
{   
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    solve();
    return 0;
}

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

#define ll long long
#define pb push_back
#define ins insert
#define mp make_pair
#define pii pair<int, int>
#define pil pair<int, ll>
#define pib pair<int, bool>
#define SET(a, c) memset(a, c, sizeof(a))
#define MOD 1000000007
#define enld endl
#define endl "\n"
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define FOUND(u, val) u.find(val) != u.end()
#define max_self(a, b) a = max(a, b);

#include <string>
#include <vector>
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
//#include <algorithm>
//#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//#include <cmath>
//#include <cstring>
//#include <sstream>
//#include <stack>
//#include <queue>
int n, m;

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

    cin >> n >> m;
    char grid[n][m];
    for (int tr = 0; tr < n; tr++) {
        for (int j = 0; j < m; j++) {
            cin >> grid[tr][j];
        }
    }

    ll dp[n + 1][m + 1];
    if (grid[n - 1][m - 1] == '#') {
        cout << 0;
        return 0;
    }
    for (int i = 0; i <= n; i++) dp[i][m] = 0;
    for (int j = 0; j <= m; j++) dp[n][j] = 0;

    dp[n - 1][m - 1] = 1;
    for (int i = n - 1; i >= 0; i--) {
        for (int j = m - 1; j >= 0; j--) {
            if (j == m - 1 && i == n - 1) continue;
            if (grid[i][j] == '#') {
                dp[i][j] = 0;
                continue;
            }
            dp[i][j] = (dp[i + 1][j] + dp[i][j + 1]) % MOD;
        }
    }

    cout << dp[0][0];
}

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

int main(){
  long int N,A,B,C,D,E,pmin;
  cin >> N >>A >> B >> C >> D >> E;
  pmin=min(A,min(B,min(C,min(D,E))));
  if(N%pmin==0)cout << N/pmin+4 << endl;
  else cout << N/pmin+5 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, a, b) for (int64_t i = (a); i < (b); ++i)
typedef long long ll;
const long long INF = 1LL << 60;

int N;
int ans = 0;
  
// 3, 5, 7を組み合わせて作れる数値を全探索
void dfs(ll x, bool s3, bool s5, bool s7) {
  if (x > N) return;
  // 3, 5, 7をすべて含むならansに+1
  if (s3 && s5 && s7) ans++;
  
  dfs(10 * x + 3, true, s5, s7);
  dfs(10 * x + 5, s3, true, s7);
  dfs(10 * x + 7, s3, s5, true);
}
  
int main() {
  // 入力
  cin >> N;
  
  // 深さ優先探索
  dfs(0, 0, 0, 0);
  
  // 出力
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
    int k, i, j, count[30]={0}, n=0,x=0;
    char static str[1200];
    char alpha[26] = "abcdefghijklmnopqrstuvwxyz";
    char alpha1[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    while((str[x]=getchar()) != EOF){
        x++;
    }
    for(i=0; i<x; i++){
        for(k=0; k<26; k++){
            if(str[i] == alpha[k] || str[i] == alpha1[k]){
                count[k]++;
            }
        }
    }
    for(j=0; j<26; j++){
        printf("%c : %d\n", alpha[j], count[j]);
        }
    return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
int a[N];
int main() {
    int n;
    cin >> n;
    for(int i = 0, x; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int R = 2002;
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        int s[2002] = {0};
        for(int j = i + 1; j < n; j++) s[a[j]]++;
        for(int j = 1; j < R; j++) s[j] += s[j - 1]; 
        for(int j = i + 1; j < n; j++) {
            ans += s[a[j] + a[i] - 1] - s[a[j]];
            int t = s[a[j]] - (j-i);
            ans += t;
            // printf("%d,%d: %d %d\n", i, j, s[a[j] + a[i] - 1] - s[a[j]], s[a[j]]-s[a[j]-1] - 1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <stack>
 
using namespace std;
 
#define f(i,a,b) for(int i=a;i<b;i++)
#define fll(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define vvi vector<vector<int>>
#define ss second
#define ff first
#define ll long long
#define lld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pq priority_queue< int >
#define pqll priority_queue< ll >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define INF 1000000000
#define NINF -1000000000
 
ll maxll(ll a , ll b ){
    return a > b ? a : b;
}
 
ll minll(ll a , ll b){
    return a > b ? b : a;
}

// bool check(ll z){
//     ll temp = k;
//     // cout << z << endl;
//     f(i , 0 , n){
//         ll sub = (ll)z * a[i];
//         if (sub > b[i])
//         temp -= (sub -b[i]);
//         if (temp < 0){
//             return 0;
//         }
//     }
//         // cout << z << endl;
//     sol = z;
//         return 1;
// }


// To count Number of ones in a binary number
// int count_one(int x){
//     x = (x & (0x55555555)) + ((x >> 1) & (0x55555555));
//     x = (x & (0x33333333)) + ((x >> 2) & (0x33333333));
//     x = (x & (0x0f0f0f0f)) + ((x >> 4) & (0x0f0f0f0f));
//     x = (x & (0x00ff00ff)) + ((x >> 8) & (0x00ff00ff));
//     x = (x & (0x0000ffff)) + ((x >> 16) & (0x0000ffff));
//     // cout << x << endl;
//     return x;
// }


void solve(){

    int n;
    cin >> n;
    vi h(n);
    f( i , 0 , n){
        cin >> h[i];
    }
    vi dp(n+1 , 0);
    f( i , 1 , n+1){
        dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
        if ( i >=2 ){
            dp[i] = min(dp[i] , dp[i-2] + abs(h[i]-h[i-2]));
        }
    }
    cout << dp[n-1] << endl;
	return ;
    
}

 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
 
 
    // int t;
    // cin >> t;
    int t = 1;
    
    while(t--){
        
        solve();
    }
}

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

#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define MOD 1000000007

using namespace std;

using ll = long long;

ll solve() {

    int H, W;
    cin >> H >> W;
    vector<int> A(H), B(W);
    set<int> As, Bs;
    REP(i, H) {
        cin >> A[i];
        --A[i];
        As.insert(A[i]);
    }
    REP(i, W) {
        cin >> B[i];
        --B[i];
        Bs.insert(B[i]);
    }

    if (As.size() < H || Bs.size() < W) {
        return 0;
    }

    int n_used_rows = 0;
    int n_used_cols = 0;
    ll result = 1;
    RREP(x, H * W) {
        int n_filled = H * W - 1 - x;
        bool inA = As.count(x) > 0;
        bool inB = Bs.count(x) > 0;
        int n_ways;
        if (inA && inB) {
            n_ways = 1;
            ++n_used_rows;
            ++n_used_cols;
        } else if (inA && !inB) {
            n_ways = n_used_cols;
            ++n_used_rows;
        } else if (!inA && inB) {
            n_ways = n_used_rows;
            ++n_used_cols;
        } else {
            n_ways = n_used_rows * n_used_cols - n_filled;
            if (n_ways <= 0) return 0;
        }
        result = (result * n_ways) % MOD;
    }
    return result;
}

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

    cout << solve() << endl;

    return 0;
}


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

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

using namespace std;

int A[2 * 100000];

int main() {
  int K, N;
  cin >> K >> N;
  REP(i, N) cin >> A[i];
  int maximum = 0;
  REP(i, N - 1) maximum = max(maximum, A[i + 1] - A[i]);
  cout << K - max(maximum, K - A[N - 1] + A[0]) << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++)
        cin>>a[i]>>b[i];
    int cnt=0;
    int flg=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]==b[i])
            cnt++;
        else
            cnt=0;
        if(cnt==3)
        {
            flg=1;
            break;
        }
    }
    if(flg==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
ll llabs(ll x) {
  return x > 0 ? x : - x;
}
int main()
{
  ll X, Y;
  cin >> X >> Y;
  if(llabs(X-Y)<=1) {
    cout << "Brown" << endl;
  } else {
    cout << "Alice" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n, k, q = list(map(int, input().rstrip('\n').split()))
    a = [int(input().rstrip('\n')) for _ in range(q)]
    ac = collections.Counter(a)
    l = [q] * n
    ll = [k] * n
    for k, v in ac.items():
        l[k-1] -= v
    for i in range(n):
        if ll[i] - l[i] <= 0:
            print("No")
        else:
            print("Yes")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 56284
use proconio::input;
use std::collections::BTreeMap;

const M: u64 = 1_000_000_007;

fn main() {
    input! {
        n: usize,
        d: [(i64, i64); n],
    }

    let mut z = 0;
    let mut t = BTreeMap::new();
    for e in d {
        if e.0 == 0 && e.1 == 0 {
            z += 1;
        } else {
            fn grouping(e: &(i64, i64)) -> (i64, i64) {
                let e = if e.0 < 0 { (-e.0, -e.1) } else { *e };
                let g = num::integer::gcd(e.0, e.1);
                (e.0 / g, e.1 / g)
            }
            let e = match e {
                _ if e.0 == 0 => (0, 1),
                _ if e.1 == 0 => (1, 0),
                _ => grouping(&e),
            };
            *t.entry(e).or_insert(0) += 1;
        }
    }
    z %= M;

    let mut ans = 1;
    while let Some((&k, &c)) = t.iter().next() {
        t.remove(&k);

        let c2 = modpow(2, c);
        let inv = if k.1 < 0 { (-k.1, k.0) } else { (k.1, -k.0) };
        ans *= if let Some(c) = t.remove(&inv) { c2 + modpow(2, c) - 1 } else { c2 };
        ans %= M;
    }
    ans += z + M - 1;
    ans %= M;
    println!("{}", ans);
}

fn modpow(x: u64, y: u64) -> u64 {
    let mut result = 1;
    let mut a = x;
    let mut b = y;
    while b > 0 {
        if b % 2 == 1 {
            result = result * a % M;
        }
        a = a * a % M;
        b /= 2;
    }
    result
}


Measured memory_bytes: 20524
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int q = sc.nextInt();
		int[][] matrix = new int[n + 1][n + 1];
		for (int i = 0; i < m; i++) {
		    matrix[sc.nextInt()][sc.nextInt()]++;
		}
		for (int i = 1; i <= n; i++) {
		    for (int j = 1; j <= n; j++) {
		        matrix[i][j] += matrix[i - 1][j] + matrix[i][j - 1] - matrix[i - 1][j - 1];
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int left = sc.nextInt();
		    int right = sc.nextInt();
		    int ans = matrix[right][right] - matrix[left - 1][right] - matrix[right][left - 1] + matrix[left - 1][left - 1];
		    sb.append(ans).append("\n");
		}
		System.out.print(sb);
    }
}



Measured memory_bytes: 155300
#include <stdio.h>
using namespace std;
int main() {
	int r, g, b;
	scanf("%d%d%d", &r, &g, &b);
	int num = 100 * r + 10 * g + b;
	if (num % 4 == 0) {
		printf("YES");
	}
	else {
		printf("NO");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
template<class t>
t read_template(){
t res;
cin >> res;
return res;
}
template<class t>
void print_template(t x){
cout << x;
}
int main(){long long N = read_template<long long>();
;
long long M = read_template<long long>();
;
function<long long(long long)> READS = [&](long long X){
return (X <= 0?0:(read_template<long long>() + READS ((X - 1))));
};
;
long long ANS = (N - READS (M));
;
(ANS < 0?print_template<long long>(-1):print_template<long long>(ANS));
return 0;
}

Measured memory_bytes: 4148
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long
using namespace std;

int main() {
    string s;
    string t;
    cin >> s >> t;
    if (s.compare(t.substr(0, t.size() - 1)) == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

struct data{
    unsigned long long v,w;
};

int main(){

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr); std::cout.tie(nullptr);

    int c,n;
    while(std::cin >> n >> c){
        std::vector<data> v(n);
        for(data& d : v){
            std::cin >> d.w >> d.v;
        }
        std::vector<std::vector<unsigned long long>> dp(n + 1, std::vector<unsigned long long>(c + 1, 0));        
        for(int i = 1 ; i <= n ; ++i){
            for(int j = 1 ; j <= c ; ++j){
                unsigned long long no_change = dp[i - 1][j];
                unsigned long long change =  dp[i - 1][j - v[i - 1].w] + v[i - 1].v;
                if(j < v[i - 1].w){
                    dp[i][j] = no_change;
                }else{
                    dp[i][j] = std::max(no_change, change);                    
                }
            }            
        }    
        std::vector<int> sol;
        int row = n,col = c;
        while(dp[row][col] != 0){
            if(dp[row][col] == dp[row - 1][col]){
                row -= 1;
            }else{
                col -= v[row - 1].w;
                sol.push_back(row - 1);
            }
        }
        std::cout << dp[n][c] << '\n';  
        //for(int val : sol){
        //    std::cout << val << ' ';
        //}         
        //std::cout << '\n'; 
    }

}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    string s;
    cin >> s;
    int ans = 0;
    bool is_streak = false;
    int streak = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T'){
            is_streak = true;
            streak++;
        }else{
            is_streak = false;
        }
        if(!is_streak){
            streak = 0;
        }
        ans = max(ans, streak);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 100001
#define MOD 1000000007
#define INF 1000000001

typedef long long int lli;

int main(void)
{
  int n, a[MAX];
  scanf("%d", &n);

  rep(ai, n)
  {
    scanf("%d", &a[ai]);
  }
  int ai;
  int num_minus = 0;
  long long int sum = 0;
  int min = INF;
  rep(ai, n)
  {
    if (a[ai] < 0)
      num_minus++;
    min = min(min, abs(a[ai]));
    sum += abs(a[ai]);
  }
  long long int ans = (num_minus % 2 == 0) ? sum : sum - 2 * min;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 512
import sys
input=sys.stdin.readline

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

dp=[[[0]*(n+1) for i in range(2501)] for j in range(n+1)]

dp[0][0][0]=1

for i in range(n):
    for j in range(2501):
        for k in range(n+1):
            dp[i+1][j][k]+=dp[i][j][k]
            if j+x[i]<=2500 and k+1<=n:
                dp[i+1][j+x[i]][k+1]+=dp[i][j][k]

ans=0
for j in range(1,2501):
    for k in range(1,n+1):
        if a*k==j:
            ans+=dp[n][j][k]

print(ans)

Measured memory_bytes: 135884