akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        boolean first=true;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            String[] x;
            while ((line = br.readLine()) != null) {
            	String[] str=br.readLine().split(" ");
            	
            	x=new String[str.length];

            	for(int i=x.length-1;i>=0;i--){
            		x[i]=str[x.length-1-i];
            	}
            	System.out.println(String.join(" ",x));
            	break;
            }
        }
    }

}

Measured memory_bytes: 24336
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	string n;
	cin >> n;
	
	int ans=0;
	REP(i,n.size()){
		ans+= (int)n[i]-(int)'0';
	}
	
	if(ans%9){
		cout << "No\n";
	}else{
		cout << "Yes\n";
	}
	
	return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
int N;
  ll count,countmae;
 cin >> N;
  count=0;
  vector<int> vec(N);
  for (int i = 0; i < N; ++i) cin >> vec[i];
  for (int j = 0; j < N-1; ++j){
  if(vec.at(j)>vec.at(j+1)){
    countmae =count;
    count=(vec.at(j)-vec.at(j+1))+countmae;
    vec.at(j+1)=vec.at(j);
    
  }
  }
  cout << count << endl;
}


Measured memory_bytes: 3976
s=[11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381]
for i in s[:int(input())]:
    print(i,end=" ")

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

using namespace std;

pair<int, int> FindEmptyPos(const vector<vector<int>> &mat)
{
  for (size_t i = 0; i < mat.size(); ++i) {
    for (size_t j = 0; j < mat[0].size(); ++j) {
      if (mat[i][j] == 0) {
        return {i, j};
      }
    }
  }
  return {-1, -1};
}

inline bool in_bounds(const vector<vector<int>> &mat, int x, int y)
{
  return (x >= 0 && x < static_cast<int>(mat.size())) &&
          (y >= 0 && y < static_cast<int>(mat[0].size()));
}

const int kDirX[] = {-1, 0, 1, 0};
const int kDirY[] = {0, 1, 0, -1};

int mod_x[] = {-1, 0, 1, 0};
int mod_y[] = {0, 1, 0, -1};

void Paint(vector<vector<int>> &mat, const pair<int, int> &pos, int &count, int col)
{
  if (count <= 0) {
    return;
  }

  mat[pos.first][pos.second] = col;
  --count;

  for (int i = 0; i < 4 && count > 0; ++i) {
    int x = pos.first + mod_x[i];
    int y = pos.second + mod_y[i];
    if (in_bounds(mat, x, y) && mat[x][y] == 0) {
      Paint(mat, {x, y}, count, col);
    }
  }
}

vector<vector<int>> Construct(int r, int c, const vector<pair<int, int>> &colours)
{
  vector<vector<int>> mat(r, vector<int>(c, 0));
  for (const auto &c : colours) {
    int size = c.first;
    int col = c.second;
    auto start = FindEmptyPos(mat);
    Paint(mat, start, size, col);
  }
  return mat;
}

bool Good(const vector<vector<int>> &mat)
{
  for (const auto &line : mat) {
    for (const auto &elem : line) {
      if (elem == 0) {
        return false;
      }
    }
  }
  return true;
}

void ChangeDirections()
{
  static int conf = 0;
  ++conf;

  int index = 0;
  for (int i = 0; i < 4; ++i) {
    if (conf & (1 << i)) {
      mod_x[index] = kDirX[i];
      mod_y[index] = kDirY[i];
      ++index;
    }
  }

  for (int i = 0; i < 4; ++i) {
    if (!(conf & (1 << i))) {
      mod_x[index] = kDirX[i];
      mod_y[index] = kDirY[i];
      ++index;
    }
  }
}

vector<vector<int>> FindRes(int r, int c, const vector<pair<int, int>> &colours)
{
  auto mat = Construct(r, c, colours);
  while (!Good(mat)) {
    ChangeDirections();
    mat = Construct(r, c, colours);
  }
  return mat;
}

int main()
{
  int rows, cols, colours;
  cin >> rows >> cols >> colours;

  vector<pair<int, int>> count(colours);

  for (int i = 0; i < colours; ++i) {
    cin >> count[i].first;
    count[i].second = i + 1;
  }
  sort(count.begin(), count.end());

  auto mat = FindRes(rows, cols, count);
  for (const auto &line : mat) {
    for (const auto &elem : line){
      cout << elem << " " ;
    }
    cout << "\n";
  }
  return 0;
}

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

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

using pii = pair<int, int>;

const int MAX_NM = 30;
int N, M, A, C, R = 0;
int B[MAX_NM];

inline void Main() {
  // code
  cin >> N >> M >> C;
  rep(i, M) cin >> B[i];

  rep(i, N) {
    int su = C;
    rep(j, M) {
      cin >> A;
      su += A*B[j];
    }
    if (su > 0) R++;
  }

  cout << R << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

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

	ll ans = 0;
	if (n == 1 && m == 1) {
		ans = 1;
	}
	else if (n == 1) {
		ans = m - 2;
	}
	else if (m == 1) {
		ans = n - 2;
	}
	else {
		ans = (n - 2)*(m - 2);
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
  int N, l, r;
  cin >> N;
  int sum = 0;
  
  for (int i=0; i<N; i++) {
    cin >> l >> r;
    sum += r-l+1;
  }
  
  cout << sum <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b,aa[110000],cnt=0;
double d;
string s,ss;
signed main()
{
	cin>>a;
	rep(i,a){
		cin>>aa[i];
	}
	sort(aa,aa+a);
	d=aa[0]*1.0;
	rep(i,a-1){
		d=(d+aa[i+1])*1.0/2;
	}
	printf("%.6f",d);
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;



void Main(){
    ll N, V, E, u, v;
    sll(N);
    V = 0, E=0;
    for(ll i=1;i<=N;i++) V += (i * (N-i+1));

    rep(i, N-1){
        sll(u);
        sll(v);
        if(u>v) swap(u, v);
        E += u * (N-v+1);
    }

    cout << V - E <<endl;
}

int main(){
    Main();
    // string S = "ksdfjl";
    // char v = S[3];
    // S[3] = 'a';
    // cout << S <<endl;
}

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

void fnInput(vector<int>& rvnBoss)
{
  int nBossSiz;
  cin >> nBossSiz;
  rvnBoss.resize(nBossSiz - 1);

  for (int& rnBoss : rvnBoss)
    cin >> rnBoss;
}
  
void fnStaffGet(const vector<int>& cnrvnBoss)
{
  vector<int> vnStaff(cnrvnBoss.size() + 1);

  for (int nBoss : cnrvnBoss)
    vnStaff[ nBoss - 1 ]++;

  for (int nStaff : vnStaff)
    cout << nStaff << endl;
}
  
int main()
{
  vector<int> vnBoss;

  fnInput(vnBoss);
  fnStaffGet(vnBoss);

  return 0;
}

Measured memory_bytes: 4760
#include<iostream>

using namespace std;

int data[10][10000];
int dp[1<<10][10000];

int main(){
	int c,r;
	while(cin>>r>>c && r &&c){
		fill((int*)data,(int*)data+10*10000,0);
		fill((int*)dp,(int*)dp+(1<<10)*10000,0);
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				cin>>data[i][j];
			}
		}
		
		for(int i=0;i<c;i++){
			if(i>0){
				for(int j=0;j<1<<(r);j++){
					int tmp1=0,tmp2=0;
					for(int k=0;k<r;k++){
						int t=data[k][i];
						if((j&(1<<k))!=0)t++;
						if((t+1)%2==0)tmp2++;
						if(t%2==0)tmp1++;
					}
					
					dp[j][i]=dp[j][i-1]+max(tmp1,tmp2);
				}
			}
			
			else {
				for(int j=0;j<1<<(r);j++){
					dp[j][i]=0;
					int tmp1=0,tmp2=0;
					for(int k=0;k<r;k++){
						int t=data[k][i];
						if((j&(1<<k))!=0)t++;
						if((t+1)%2==0)tmp2++;
						if(t%2==0)tmp1++;
					}
					dp[j][i]=max(tmp1,tmp2);
					
				}
			}
		}
		
		int ans=0;
		for(int i=0;i<1<<(r);i++){
			ans=max(ans,dp[i][c-1]);
		}

		cout<<ans<<endl;
	}
	
	
}

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

int H;
int F[11][6] = {};

void update(){
    for(int j=1;j<=5;j++){
        for(int i=1;i<=H;i++){
            if(F[i][j]==0) continue;
            int now = i;
            while(now!=1 && F[now-1][j]==0){
                swap(F[now][j],F[now-1][j]);
                now--;
            }
        }
    }
//    for(int i=H;i>=1;i--) for(int j=1;j<=5;j++) cerr << F[i][j] << (j!=5? " ":"\n");
}

int calc(){
    int sum = 0;
    for(int i=1;i<=H;i++){
        int num = 0,len = 0,id = 0;
        for(int j=1;j<=3;j++){
            if(F[i][j]!=0 && F[i][j]==F[i][j+1] && F[i][j+1]==F[i][j+2]){
                num = F[i][j];
                F[i][j] = 0; F[i][j+1] = 0;F[i][j+2] = 0;
                id = j;
                break;
            }
        }
        len = 3;
        if(num!=0){
            if(id==1){
                if(F[i][4]==num){
                    len++;
                    F[i][4] = 0;
                    if(F[i][5]==num){
                        len++;
                        F[i][5] = 0;
                    }
                }
            }else if(id==2){
                if(F[i][1]==num){
                    len++;
                    F[i][1] = 0;
                }
                if(F[i][5]==num){
                    len++;
                    F[i][5] = 0;
                }
            }else{
                if(F[i][2]==num){
                    len++;
                    F[i][2] = 0;
                    if(F[i][1]==num){
                        len++;
                        F[i][1] = 0;
                    }
                }
            }
        }
        sum += len*num;
    }
    return sum;
}

int main(){
    while(cin >> H && H){
        for(int i=1;i<=H;i++) for(int j=1;j<=5;j++){
            cin >> F[H-i+1][j];
        }
        int ans = 0;
        while(true){
            int s = calc();
            if(s==0) break;
            ans += s;
            update();
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3072
import sys
import os
import itertools
from collections import deque

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

    N=int(input())
    A=list(map(int, input().split()))

    A.sort()
    ans=0
    # print(A)

    T=[True]*A[-1]
    # T[0]=False

    for i,a in enumerate(A):
        if T[a-1]:
            j=2*a
            while j <= A[-1]:
                T[j-1]=False
                j+=a
            if not i+1==len(A):
                if A[i]==A[i+1]:
                    T[a-1]=False

    for a in A:
        if T[a-1]:
            ans+=1

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 34140
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n = I()
l = LI()

longest = max(l)
if sum(l) - longest > longest:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 9088
#include<cstdio>

inline char nc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}

inline double read(){
    char ch=nc();
    double sum=0;
    while(!(ch>='0'&&ch<='9')) ch=nc();
    while(ch>='0'&&ch<='9') sum=sum*10+ch-48,ch=nc();
    return sum;
}

int main(){
	double r1=read(),r2=read();
	printf("%.10lf",r1*r2/(double)(r1+r2));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> W;
    int right = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        W.push_back(a);
        right += W[i];
    }
 
    int left = 0;
    int dif = 99;
    int minP = 99;
    for (int j = 0; j < N; j++) {
        left += W[j];
        right -= W[j];
        dif = abs(right - left);
        minP = min(minP, dif);
    }
    cout << minP << endl;
}

Measured memory_bytes: 256
from collections import OrderedDict
N = int(input())
a = list(map(int, str(input()).split()))

box = OrderedDict(zip(range(N, 0, -1), [0] * N))
output = list()
count = 0
for i in box:
    mul = N // i
    total_ball = 0
    for m in range(1,mul+1):
        total_ball += box[m * i]
    if (a[i-1] == 1 and total_ball % 2 == 0) or (a[i-1] == 0 and total_ball % 2 == 1) :
        box[i] = 1
        count += 1
        output.append(str(i))
    else:
        pass

if len(output) != 0:
    print(count)
    print(' '.join(output))
else:
    print(0)


Measured memory_bytes: 76984
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DEBUG_OUTPUT_ENABLED 1
	#define DBG(X) dout << #X << "=" << (X) << '\n';
	#define SAY(X) dout << (X) << '\n';
#else
	#define DEBUG_OUTPUT_ENABLED 0
	#define DBG(X) 42;
	#define SAY(X) 42;
#endif

#define dout   debug::instance

using namespace std;

template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
namespace debug {
	struct DebugStream {
		private:
			bool is_first;
		public:
			DebugStream(bool _is_first): is_first(_is_first) {}
			template<typename T> DebugStream operator<<(const T& value) const {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				cout << value;
				return DebugStream(false);
			};

			template<typename T> DebugStream printArray(T* l, T* r) {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				while(l != r) {
					cout << (*l);
					++l;
					if(l == r) {
						cout << '\n';
					} else {
						cout << ' ';
					}
				}
				return DebugStream(false);
			}
	};
	DebugStream instance(true);
};

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }
const int MAXN = 3007;
const int MOD  = 998244353;
inline int add(int x, int y) {
	return (x + y >= MOD ? x + y - MOD : x + y);
}
inline int mult(int x, int y) {
	ll r = x * 1LL * y;
	if(r >= MOD) r %= MOD;
	return (int)r;
}
int dp[MAXN], pDP[MAXN];
int n, S, a[MAXN];
void solve() {
	cin >> n >> S;
	for(int i = 0; i < n; ++i) cin >> a[i];
	int answ = 0;
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < MAXN; ++j) pDP[j] = dp[j];
		for(int j = a[i]; j < MAXN; ++j) {
			dp[j] = add(dp[j], pDP[j - a[i]]);
		}
		dp[a[i]] = add(dp[a[i]], i + 1);
		answ = add(answ, dp[S]);
	}
	cout << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 384
N=int(input())

for n in range(N):
    gx,gy=map(int,input().split())
    T=[[0 for j in range(gy+1)] for i in  range(gx+1)]
    under=[[0 for j in range(gy+1)] for i in range(gx+1)]
    left=[[0 for j in range(gy+1)] for i in range(gx+1)]
    
    p=int(input())
    
    for i in range(p):
        x1,y1,x2,y2=map(int,input().split())
        if x1==x2:
            under[x1][max(y1,y2)]=1
        if y1==y2:
            left[max(x1,x2)][y1]=1
            
    for j in range(gy+1):
        for i in range(gx+1):
            T[0][0]=1
            if i==0:
                T[i][j]=1
            if j==0:
                T[i][j]=1
            if under[i][j]==0 and left[i][j]==0:
                T[i][j]=T[i-1][j]+T[i][j-1] 
            if under[i][j]==1 and left[i][j]==1:
                T[i][j]=0 
            elif under[i][j]==1:
                T[i][j]=T[i-1][j]
            elif left[i][j]==1:
                T[i][j]=T[i][j-1]
    if T[gx][gy]==0:
        print("Miserable Hokusai!")
    else:
        print(T[gx][gy])


Measured memory_bytes: 5616
//Radhe Radhe
#include<bits/stdc++.h>//157B
#define ll long long
#define fixed cout.setf(ios::fixed);
#define rep1    for( i=0; i<n; i++)
#define Precise cout.precision(7);
using namespace std;

int main()
{
    ll i,j,n,k,a[5];
    for(i=0;i<5;i++)
    cin>>a[i];
    cin>>k;
    for(i=0;i<4;i++)
    {
    for(j=i+1;j<5;j++)
        {
            if(abs(a[i]-a[j])>k)
    return cout<<":("<<endl,0;
        }
    }

    cout<<"Yay!"<<endl;



    return 0;
}





Measured memory_bytes: 3516
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
using namespace std;


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

	vector<int> a,b;
	const int num = (n-1)*(n-2)/2;
	if(k > num){
		cout << -1 << endl;
	}else{
		// star
		for(int i=2;i<=n;i++){
			a.push_back(1);
			b.push_back(i);
		}
		// connect
		int cnt = 0;
		for(int i=2;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				if(cnt >= num - k){
					continue;
				}else{
					a.push_back(i);
					b.push_back(j);
					cnt++;
				}
			}
		}
		cout << a.size() << endl;
		for(int i=0;i<a.size();i++){
			cout << a[i] << " " << b[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 384
n, m = list(map(int,input().split()))
h = list(map(int,input().split()))
a = []
b = []
for i in range(m):
  a0, b0 = list(map(int,input().split()))
  a.append(a0)
  b.append(b0)
  
count = [0] * n

for i in range(m):
  if h[a[i] - 1] <= h[b[i] - 1]:
    count[a[i] - 1] = 1
  if h[a[i] - 1] >= h[b[i] - 1]:
    count[b[i] - 1] = 1
      
print(count.count(0))

Measured memory_bytes: 22240
#include <iostream>
#include <math.h> 
#include <string> 
#include <algorithm>
using namespace std;

int main() {
	string res = "No";
	int N; cin >> N;
	string s; cin >> s;
	int count = 0;

	for (int i = 0; i <= N - 1; i++)  if (s[i] == 'R') count++;

	if (count > N - count) res = "Yes";

	cout << res << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
int N,M;
cin>>N>>M;
vector<ll>A(N),B(M),C(M);
vector<P> Q(M);
for(int s=0;s<N;s++){
        cin>>A.at(s);
}
for(int t=0;t<M;t++){
        cin>>B.at(t)>>C.at(t);
        Q.at(t)=P(C.at(t),B.at(t));
}
sort(Q.begin(),Q.end());
reverse(Q.begin(),Q.end());
sort(A.begin(),A.end());
ll sum=0,S=0,T=0;
int j=0;
for(int i=0;i<M;i++){
      S=Q.at(i).second;
      T=Q.at(i).first;
      if(j>=N)break;
      if(A.at(j)>T) break;
      while(S>0 &&j<N){
          if(A.at(j)<T && j<N){
              A.at(j)=T;
              S--;
          }
          else break;
          j++;
      }
}
for(int k=0;k<N;k++){
    sum+=A.at(k);
}
cout<<sum<<endl;
return 0;
}



Measured memory_bytes: 4224
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
                
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define max2(a,b) ((a)>(b) ? (a) : (b))   
#define min2(a,b) ((a)<(b) ? (a) : (b)) 
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i) 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lli long long int 
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000

using namespace std;
typedef vector<lli>   vll;
typedef vector<int>   vi;
typedef set<lli>      sll;
typedef set<int>      si;
typedef pair<lli,lli> pll;
typedef pair<int,int> pii;
clock_t clk=clock();       

lli i,j;
void solve(void);

int main()
{
  speedio;
   int t=1;  
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
//
void solve()
{
	lli n,m; cin>>n>>m;
	int a[n+2]={0};
	rep(i,1,m)
	{
	lli l,r; cin>>l>>r;
	 ++a[l]; --a[r+1];
	}
	rep(i,1,n)
	 a[i]+=a[i-1];


   int ct=0;
   rep(i,1,n)
    if(a[i]==m) ++ct;
    cout<<ct<<"\n";
}

Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  string t="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  rep(i,s.size()){
    rep(j,52){
      if(s[i]==t[j]){
        s[i]=t[j+n];
        break;
      }
    }
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
input()
v = lambda: map(int,input().split())
d = [abs(x-y) for x,y in zip(v(),v())]
print(
	sum(d),
	sum(a**2 for a in d)**(1/2),
	sum(a**3 for a in d)**(1/3),
	max(d),
	sep='\n')



Measured memory_bytes: 5648
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        a: [u32; n],
    }
    let mut ans = 0;
    let mut prev = a[0];
    for a in a[1..].iter() {
        if *a > prev {
            ans += 1;
        }
        prev = *a;
    }
    println!("{}", ans);
}

fn main() {
    run();
}



Measured memory_bytes: 5032
import java.util.*;
import java.util.function.Consumer;

class Node {
    int pattern;
    int notZero;
    boolean max;

    Node apply(Consumer<Node> lambda) {
        lambda.accept(this);
        return this;
    }
}

class Main {
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        String n = s.next();
        int k = s.nextInt();

        int length = n.length();


        int[][] dp0 = {};
        int[][] dp1 = {};

        List<Node> state = Collections.emptyList();
        for (int i = 0; i < length; i++) {
            final int digit = n.charAt(i) - '0';
            if (i == 0) {
                state = new ArrayList<>();
                // 最大値君
                state.add(new Node().apply(self -> {
                    self.max = true;
                    self.notZero = 1;
                    self.pattern = 1;
                }));
                // 真中らぁら
                if(digit>1) {
                    state.add(new Node().apply(self -> {
                        self.max = false;
                        self.notZero = 1;
                        self.pattern = digit - 1;
                    }));
                }
                // わがなはぜろ
                state.add(new Node().apply(self -> {
                    self.max = false;
                    self.notZero = 0;
                    self.pattern = 1;
                }));

            } else {
                List<Node> next = new ArrayList<>();
                int[] tmp=new int[1000];
                for (Node node : state) {
                    if (node.max) {
                        // up
                        next.add(new Node().apply(self -> {
                            self.max = true;
                            self.pattern = node.pattern;
                            self.notZero = node.notZero+((digit==0)?0:1);
                        }));
                        // まなか
                        if(digit>1){
                            tmp[node.notZero+1]+=(node.pattern * (digit - 1));
                        }
                        if(digit>0){
                            //zero
                            tmp[node.notZero]+=(node.pattern );

                        }
                    } else {
                        //1-9
                        tmp[node.notZero+1]+=(node.pattern * 9);
                        // 0
                        tmp[node.notZero]+=(node.pattern );
                    }
                }
                for (int j = 0; j <tmp.length ; j++) {
                    final int jj=j;
                    if(tmp[j]<1)continue;
                    next.add(new Node().apply(self -> {
                        self.max = false;
                        self.pattern = tmp[jj];
                        self.notZero = jj;
                    }));
                }
                state = next;
            }
        }
        int ans= state.stream().filter(self -> self.notZero == k).map(self -> self.pattern).reduce(0, (p, q) -> p + q);
        System.out.println(ans);

    }
}

Measured memory_bytes: 29136
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

long long a[55];

int main()
{
    long long k;

    scanf("%lld",&k);

    for (int i = 0;i < 50;i++)
        a[i] = i;

    for (int i = 0;i < 50;i++)
    {
        a[i] += k / 50;
    }

    for (int i = 0;i < k % 50;i++)
    {
        sort(a,a+50);

        a[0] += 50;

        for (int i = 1;i < 50;i++)
            a[i]--;
    }
    
    printf("50\n");
    
    for (int i = 0;i < 49;i++) printf("%lld ",a[i]);
    printf("%lld",a[49]);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int h[n],cnt=0;
	for(int i=0;i<n;i++) {
		cin>>h[i];
		if(h[i]>=k){
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();

		long result = 0;
		long num = sc.nextLong();

		for (int i = 1; i < n; i++) {
			long a = sc.nextInt();
			if (a >= num) {
				num = a;
			} else {
				result = result + num - a;
			}
		}

		System.out.println(result);

	}

}


Measured memory_bytes: 58852
object Main extends App {
  def crossProduct(p1: (Double, Double, Double),
                   p2: (Double, Double, Double)): (Double, Double, Double) = {
    (
      p1._3 * p2._2 - p1._2 * p2._3,
      p1._1 * p2._3 - p1._3 * p2._1,
      p1._2 * p2._1 - p1._1 * p2._2
    )
  }

  Stream
    .continually(readLine)
    .takeWhile(_ != null)
    .map(_.split(" ").map(_.toDouble) match {
      case Array(x1, y1, x2, y2, x3, y3, xp, yp) =>
        val (ab, ap, bc, bp, ca, cp) = (
          (x2 - x1, y2 - y1, 0.0),
          (xp - x1, yp - y1, 0.0),
          (x3 - x2, y3 - y2, 0.0),
          (xp - x2, yp - y2, 0.0),
          (x1 - x3, y1 - y3, 0.0),
          (xp - x3, yp - y3, 0.0)
        )
        Seq((ab, ap), (bc, bp), (ca, cp)).map { case (p1, p2) => crossProduct(p1, p2) }
    })
    .map(_.map(_._3 > 0))
    .map(zIsPositives => zIsPositives.forall(_ == zIsPositives.head))
    .foreach(isInner => println(if (isInner) "YES" else "NO"))
}



Measured memory_bytes: 44704
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, j) for (long long i = 0; i < j; i++)
#define int long long

using namespace std;

signed main()
{
    int N, K, x;
    int answer = 0;
    cin >> N >> K;
    rep(i, N)
    {
        cin >> x;
        if (x >= K)
            answer++;
    }
    cout << answer << endl;
}


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

namespace output{
    void __(short x){cout<<x;}
    void __(unsigned x){cout<<x;}
    void __(int x){cout<<x;}
    void __(long long x){cout<<x;}
    void __(unsigned long long x){cout<<x;}
    void __(double x){cout<<x;}
    void __(long double x){cout<<x;}
    void __(char x){cout<<x;}
    void __(const char*x){cout<<x;}
    void __(const string&x){cout<<x;}
    void __(bool x){cout<<(x?"true":"false");}
    template<class S,class T>
    void __(const pair<S,T>&x){__(DEBUG?"(":""),__(x.first),__(DEBUG?", ":" "),__(x.second),__(DEBUG?")":"");}
    template<class T>
    void __(const vector<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class T>
    void __(const set<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class T>
    void __(const multiset<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class S,class T>
    void __(const map<S,T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    void pr(){cout<<"\n";}
    template<class S,class... T>
    void pr(const S&a,const T&...b){__(a);if(sizeof...(b))__(' ');pr(b...);}
}

using namespace output;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,char> pic;
typedef pair<double,double> pdd;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vl;

#define pb push_back
#define fox(i,x,y) for(int i=(x);i<=(y);i++)
#define foxr(i,x,y) for(int i=(y);i>=(x);i--)

const ll MN = 1e5+5;
ll N, M, V, P, i, j, arr[MN], ps[MN], lim, cnt, lo, hi;

int main(){
    scanf("%lld%lld%lld%lld",&N,&M,&V,&P);
    for(i=1;i<=N;i++) scanf("%lld",&arr[i]);
    sort(arr+1,arr+N+1,[](ll i,ll j){return i>j;});
    for(i=1;i<=N;i++) ps[i]=ps[i-1]+arr[i];
    lim = arr[P];
    for(i=1;i<=N;i++){
        if(arr[i]>=lim) cnt++;
        else{
            ll rem = (V-(N-i))*M;
            lo=1, hi=i;
            while(lo<hi){
                ll m=(lo+hi)>>1;
                if(arr[m]<=arr[i]+M) hi=m;
                else lo=m+1;
            }
            if(lo<=P){
                if((P-1)*M+(i-P+1)*(arr[i]+M)-(ps[i]-ps[P-1])>=rem) cnt++;
            }
        }
    }
    printf("%lld\n",cnt);
    return 0;
}


Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))

cnt = {}
for ai in a:
    if ai in cnt:
        cnt[ai] += 1
    else:
        cnt[ai] = 1
s = sum([v * (v - 1) // 2 for _, v in cnt.items()])
dic = { k: s - (v - 1) for k, v in cnt.items() }
ans = "\n".join(map(lambda ai: str(dic[ai]), a))
print(ans)

Measured memory_bytes: 127180
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

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

    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    sort(all(a));
    cout << a[n-1] - a[0] << endl;
}

Measured memory_bytes: 256
// RAKSHIT KADAM
 
//  -- Declare array globally...
 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
// find_by_order returns iterator to  element present at that index...
// order_of_key returns no. of elements having value stricktly less than that given in the order_of_key();
#warning !!!check the size of arrayss!!!
 
// NUMERIC DEFINITIONS :
    #define INF 1000000000000000005
    #define inf 1000000003
    #define MOD  1000000007
    #define newMOD  998244353
    #define MAX 200006
    #define pi 3.1415926535897932384626433832795
#define ld long double
 #define ll long long
 #define int long long
 
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>
 
 #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
 #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m;}
ll modInverse(int a, int m){{ return power(a, m-2, m);}}
const int maxn = 500066;



void solve()
{
    ll n;cin>>n;
    ll ans= 0;
    for(ll i=1;i<=n;i++)
    {
        ll x;cin>>x;
        if(i&1 && x&1)ans++;
        
    }
    cout<<ans<<endl;
   
}
 
signed main()
{
   Need_for_speed(activated);
 
//satisfy
//    {
//  solve();
//   }
 
    solve();
    return 0;
}


Measured memory_bytes: 3664
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn rec(n:usize,m:usize,buff:&mut Vec<i64>,mut ans:u32) -> u32{

    //再帰終了条件
    let mut buff_num = 0;
    for (i,b) in buff.iter().enumerate(){
        buff_num += b * 10i64.pow((buff.len()-1-i) as u32);
    }
    if (buff_num as usize) > n {
        return ans;
    }

    //753数の判定
    if buff.contains(&3) && buff.contains(&5) && buff.contains(&7){
        ans += 1;
    }

    //再帰全探索
    let v = vec![3,5,7];
    for num in v.into_iter(){
        buff.push(num);
        ans = rec(n,m,buff,ans);
        buff.pop();
    }

    ans
}
  
fn main() {
    let n: usize = read();
    let mut m = n;
    let mut keta = 0;
    while m!=0 {
        m /= 10;
        keta += 1;
    }
    let mut buff = Vec::new();
    let ans = rec(n,keta,&mut buff,0);
    print!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
int n,m,x,y;
int main(){
	cin>>n>>m>>x>>y;
	cout<<n*m-(x*m+y*n-x*y);
	return 0;
}

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

int main()
{
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    int move = 'A' - 'a';
    putchar(s1[0] + move);
    putchar(s2[0] + move);
    putchar(s3[0] + move);
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import math


ND= list(map(int, input().split()))
X = [list(map(int, input().split())) for i in range(ND[0])]


count = 0

for j in range(ND[0]):

    for u in range(ND[0]):
        if j == u:
            continue
        else:
            SUM = 0

            for b in range(ND[1]):
                SUM += pow(X[j][b] - X[u][b],2)

            SQ = math.sqrt(SUM)

            if SQ.is_integer():
                count+=1
            else:
                continue

print(int(count/2))





Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#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()
const int mod=(int)1e9+7;
const int MAXN=(int)2e5+10;
const int INF=(int)2e9+7;
const ll LINF=(1ll<<62);
int n;ll a[MAXN];bool u[MAXN];ll all;

ll solve(ll ckr[],int n)
{
    int idx=0;
    for (int i=60; i>=0;i--)
    {
        int maxidx=idx;
        ll maxEle=-LINF;
        rep(j,idx,n)
        {
            if((ckr[j] & (1ll<<i))!=0
                     && ckr[j] > maxEle )
                maxEle = ckr[j], maxidx = j;
        }
        if (maxEle==-LINF)
        continue;
        swap(ckr[idx],ckr[maxidx]);
        maxidx = idx;
        for (int j=0;j<n;j++)
        {
            if (j != maxidx &&
               (ckr[j]&(1ll<<i))!=0)
                ckr[j] = ckr[j]^ckr[maxidx];
        }
        idx++;
    }
    ll res=0;
    for (int i = 0; i < n; i++)
        res^=ckr[i];
    return res;
}

ll f(ll x){
    return x+(all^x);
}
int main(){
    cin>>n;
    rep(i,n){
        cin>>a[i];
        all^=a[i];
    }
    sort(a,a+n);
    for(int i=60; i>=0; i--){
        rep(j,n){
            if((all>>i)%2&&(a[j]>>i)%2) {
                a[j]-=(1ll<<i);
            }
        }
    }
    ll mn=solve(a,n);
    cout<<f(mn)<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#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 itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;



int main(){
    int n;
    cin >> n;
    cout << n*(n+1)/2 << endl;
}

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

int main(){
    int N;
    cin >> N;

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

    const int n = N/2;

    for(int i = N-1; i >= n; --i){
        if(a[i] == 1) b[i] = a[i];
    }

    for(int i = n-1; i >= 0; --i){
        b[i] ^= a[i];
        for(int j = 2*i+1; j < N; j += i+1){
            b[i] ^= b[j];
        }
    }

    const int M = count(begin(b), end(b), 1);
    cout << M << endl;
    if(M != 0){
        for(int i = 0; i < N; ++i){
            if(b[i] == 1) cout << i+1 << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 2432
import java.util.Scanner;
class Main{
    public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
       
       int n = sc.nextInt();
       int m = sc.nextInt();
       int[][] a = new int[n][m];
       int[] b = new int[m];
       for(int i=0; i<n; i++){
           for(int j=0; j<m; j++){
               int oa = sc.nextInt();
               a[i][j] = oa; 
           }
       }
       for(int j=0; j<m; j++){
           int ob = sc.nextInt();
           b[j] = ob;
       }
       int sum = 0;
       for(int i=0; i<n; i++){
           for(int j=0; j<m; j++){
            sum += a[i][j]*b[j];
           }
           System.out.println(sum);
           sum = 0;
       }
    }
}


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

int main(){
  
  int n,T,A;
  cin >>n>>T>>A;
  int H[n];
  for(int i=0; i<n; i++) cin >> H[i];
  
  double minn=abs(A-(T-H[0]*0.006));
  int ans=0;
  for(int i=1; i<n; i++){
  	if(minn>abs(A-(T-H[i]*0.006))){ minn=abs(A-(T-H[i]*0.006)); ans=i;}
  }
  
  cout << ans+1 << endl;
}

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

int main(){
  string N;
  cin>>N;
  if (N[0] == N[1]&&N[1] == N[2]){
    cout<<"Yes"<<endl;
  }
  else if (N[1] == N[2]&&N[2] == N[3]){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
}
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Tue Sep  8 16:23:28 2020

@author: liang
"""

N, M = map(int, input().split())
AC_list = [0]*N
WA_list = [0]*N

for i in range(M):
    p, j = input().split()
    p = int(p)
    if j == 'AC':
        AC_list[p-1] += 1
    else:
        if AC_list[p-1] == 0:
            WA_list[p-1] += 1

AC = 0
WA = 0
for i in range(N):
    if AC_list[i] >= 1:
        AC += 1
        WA += WA_list[i]
    
print(AC, WA)

Measured memory_bytes: 10364
# include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007



int main()
{
    int N;
    vec(V)
        vec(C)
           cin >> N;
    vec(M)
    fx(N){
        vecp(V)
    }
    fx(N){
        vecp(C)
            pb(M,V.at(x)-C.at(x))
    }
    int ans = 0;
    sorts(M)
        reverses(M)
        int i = 0;
    while (i<N&&M.at(i)>0) {
        ans += M.at(i);
        i++;
 
    }
    ce(ans)
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <math.h>
#include <stdbool.h>

int ASC( void *a,  void *b) {
	return strcmp(*(const char **)a, *(const char **)b);//降順
}
int GCD(int a, int b) {	//最大公約数
	if (b == 0) return a;
	else return GCD(b, a % b);
}
int min(int a, int b ) {
	if (a < b) {
		return a;
	}
	else
		return b;
}
int max(int a, int b) {
	if (a < b)
		return b;
	else
		return a;
}
int main(void)
{
	int a, b, c, x, time = 0;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	while (a >= b) {
		if (time >= x) {
			printf("No");
			return 0;
		}
		b = b * 2;
		//printf("%d",b);
		time++;
	}
	while (b >= c) {
		if (time >= x) {
			printf("No");
			return 0;
		}
		c = c * 2;
		time++;
		//printf("%d", c);
	}
	printf("Yes");
	
	return 0;
}//pd pdp

Measured memory_bytes: 1728
S = input()

idx = len(S)
while True:
    if S[idx-5:idx] == 'dream':
        idx -= 5
    elif S[idx-6:idx] == 'eraser':
        idx -= 6
    elif S[idx-5:idx] == 'erase':
        idx -= 5
    elif S[idx-7:idx] == 'dreamer':
        idx -= 7
    else:
        print('NO')
        break

    if idx == 0:
        print('YES')
        break


Measured memory_bytes: 9080
#include<bits/stdc++.h>
#define ll long long
#define db double
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl "\n"
#define pb push_back
#define mp make_pair
#define inf LONG_LONG_MAX
#define inf1 INT_MAX
using namespace std;
/*
ll mpow(ll a, ll b){
    if(!b)
        return 1;
    ll temp=mpow(a,b/2);
    temp=(temp*temp)%mod;
    if(b%2)
        return (a*temp)%mod;
    return temp;
}

ll _pow(ll a, ll b){
    if(!b)
        return 1;
    ll temp=_pow(a,b/2);
    temp=(temp*temp);
    if(b%2)
        return (a*temp);
    return temp;
}

ll mod_in(ll n){
    return mpow(n,mod-2);
}
*/
int main()
{
    fastio
    ll n;
    cin>>n;
    ll a[n], b[n], c[n];
    ll i;
    for(i=0; i<n; i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    ll dp[n][3];
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(i=1; i<n; i++)
    {
        dp[i][0]=a[i]+max(dp[i-1][1], dp[i-1][2]);
        dp[i][1]=b[i]+max(dp[i-1][0], dp[i-1][2]);
        dp[i][2]=c[i]+max(dp[i-1][0], dp[i-1][1]);
    }
    cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
    return 0;
}

Measured memory_bytes: 4992