akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll N,M;cin>>N>>M;
    pl stu[N],info[M];
    rep(i,N)cin>>stu[i].fi>>stu[i].se;
    rep(i,M)cin>>info[i].fi>>info[i].se;
    ll ans=0;
    rep(i,N){
        ans=0;
        ll x=stu[i].fi,y=stu[i].se;
        rep(j,M){
            if(abs(x-info[j].fi)+abs(y-info[j].se)<abs(x-info[ans].fi)+abs(y-info[ans].se))ans=j;
        }
        cout<<ans+1<<endl;
    }
    return 0;
}

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

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

    int n, k;
    cin >> n >> k;
    
    int ans = 0;
    for(int i = 0; i < n; i++){
        int h;
        cin >> h;
        if(h >= k){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
int main() {
	int a, b, k;
	std::cin >> a >> b >> k;
	int Q = std::min((b - a + 1) * 2, 2 * k);
	std::vector<int> s(Q);
	for (int i = 0;i < k;++i) {
		if (a + i <= b) {
			s[i] = a + i;
		}
	}
	for (int i = 0;i < k;++i) {
		if (b - i >= a) {
			s[i + std::min(k, b - a + 1)] = b - i;
		}
	}
	std::sort(s.begin(), s.end());
	s.erase(std::unique(s.begin(), s.end()), s.end());
	for (int i = 0;i < s.size();++i) {
		std::cout << s[i] << std::endl;
	}

	return 0;

}


Measured memory_bytes: 256
#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 ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

bool unique(int a[], int n){
  for(int i = 0; i < n; i++){
    for(int j = i + 1; j < n; j++){
      if(a[i] == a[j]) return false;
    }
  }
  return true;
}

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

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

  if(!(unique(a, n) && unique(b, m))){
    cout << 0 << endl;
    return 0;
  }

  ll p[n * m + 1];
  fill(p, p + n * m + 1, -1);

  for(int i = 0; i < n; i++){
    bool c = false;
    int count = 0;
    for(int j = 0; j < m; j++){
      if(a[i] == b[j]){
        c = true;
        p[a[i]] = 1;
        break;
      }
      if(b[j] >= a[i]) ++count;
    }
    if(!c) p[a[i]] = count;
  }

  for(int j = 0; j < m; j++){
    bool c = false;
    int count = 0;
    for(int i = 0; i < n; i++){
      if(a[i] == b[j]){
        c = true;
        p[b[j]] = 1;
        break;
      }
      if(a[i] >= b[j]) ++count;
    }
    if(!c) p[b[j]] = count;
  }

  sort(a, a + n);
  sort(b, b + m);

  ll sum = 1;
  ll count = 0;
  for(int i = n * m; i >= 1; i--){
    if(p[i] >= 0) sum = (sum * p[i]) % MOD;
    else{
      ll tmp = n - distance(a, upper_bound(a, a + n, i));
      tmp = (tmp * (m - distance(b, upper_bound(b, b + m, i))));
      if(tmp - count <= 0){
        sum = 0;
        break;
      }
      sum = (sum * (tmp - count)) % MOD;
    }
    ++count;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 8064
/*
 ╔═══╦═══╦═══╗
 ║╔═╗║╔══╩╗╔╗║
 ║║░║║╚══╗║║║║
 ║║░║║╔══╝║║║║
 ║╚═╝║╚══╦╝╚╝║
 ╚══╗╠═══╩═══╝
 ░░░╚╝░░░░░░░░
 */

#include <bits/stdc++.h>
#define ll					long long
#define debug(x)			{ cerr << #x << " = " << x << endl; }
#define MOD					1000000007
#define MAX					1e9
#define MIN                 -1e9
#define vi					vector<int>
#define vii					vector<vi>
#define max(x,y)			(x>y)?x:y
#define mid(s,e)			(s+(e-s)/2)
#define MAXND				11
using namespace std;

int main() {
	ios::sync_with_stdio(false);
 	cin.tie(0);
	ll l,r;
	cin>>l>>r;
	int div1 = (l-1) / 2019;
	int div2 = (r) / 2019;
	if(div1 != div2) {
		cout<<"0";
		return 0;
	}
	ll ans = MAX;
	for(ll i=l; i<r; i++) {
		for(ll j=i+1; j<=r; j++) {
			ans = min(ans, (i*j) % 2019);
		}
	
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    int N;
    cin >> N;
    vector<int> v(N);
    rep(i, N) cin >> v[i];
    sort(v.begin(), v.end());
    if(v[N/2-1]==v[N/2]) cout << "0" << endl;
    else cout << v[N/2]-v[N/2-1] << endl;
    return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	int a[n], b[n];
	ll sa = 0, sb = 0;
	rep(i, n) {
		cin >> a[i];
		sa += a[i];
	}
	rep(i, n) {
		cin >> b[i];
		sb += b[i];
	}
	if (sa > sb) {
		cout << "No" << endl;
		return 0;
	}
	ll p = sb - sa, q = 0, r = 0;
	rep(i, n) {
		if (a[i] > b[i])
			q += a[i] - b[i];
		else if (a[i] < b[i])
			r += (b[i] - a[i] + 1) / 2;
	}
	if (q <= p and r <= p)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include <cstdio>
#include<vector>
#include<map>
#include<utility>
#include<list>
#include<algorithm>
#include <ctype.h>
#include<deque>
using namespace std;
using ll = long long int;

int n;


int main(void) {
	cin >> n;
	double ret=0.;
	for (int i = 0; i < n; i++) {
		double xi;
		string ui;
		cin >> xi >> ui;
		if (ui == "JPY") {
			ret += xi;
		}
		else {
			ret += xi * 380000.;
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
x = np.median(X)
index = N // 2
m1 = Y[index]
m2 = Y[index - 1]

for i in range(N):
    if X[i] < x:
        print(m1)
    else:
        print(m2)


Measured memory_bytes: 50020
#include<stdio.h>
#include<string.h>

int N,i,j,k,l,C[30][9],r,m[6][4]={{1,2,4,3},{5,2,0,3},{1,5,4,0},{1,0,4,5},{0,2,5,3},{1,3,4,2}};
char *S[6]={"Red","Yellow","Blue","Magenta","Green","Cyan"},I[99],*p;

int ch(int a[9],int b[9])
{
	int i,j,x,y,t1[4],t2[4];
	for(i=0;i<6;i++)
	{
		if(a[0]==b[i])
		{
			for(j=0;j<4;j++)
			{
				t1[j]=a[m[0][j]];
				t2[j]=b[m[i][j]];
			}
			for(j=0;j<4;j++)
			{
				for(x=0,y=j;x<4;x++,y=(y+1)%4)
					if(t1[x]!=t2[y])
						break;
				if(x==4)return 1;
			}
		}
	}
	return 0;
}

int main()
{
	for(;scanf("%d\n",&N),r=N;)
	{
		for(i=0;i<N;i++)
		{
			gets(I);
			for(j=0;(p=strtok(j==0?I:NULL," "))!=NULL;j++)
			{
				for(k=0;k<6;k++)
					if(strcmp(p,S[k])==0)
						C[i][j]=k;
			}
		}
		for(i=0;i<N;i++)
			for(j=0;j<i;j++)
			{
				if(ch(C[i],C[j]))
				{
					r--;
					break;
				}
			}
		printf("%d\n",N-r);
	}
	return 0;
}

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

int main(){
	int A, B, K, i;
	scanf("%d%d%d", &A, &B, &K);
	for(i = A; ; i--){
		if(A % i == 0 && B % i == 0){
			K--;
		}
		if(K == 0){
			printf("%d\n", i);
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

int main(){
   int n;
   cin>>n;
   vector<long long> a(n+2);
   for(int i=0;i<n;i++)cin>>a[i];
   vector<long long>sum(n+2);
   sum[0]=a[0];
   for(int i=1;i<n;i++){
      sum[i]=sum[i-1]+a[i];
   }
   long long ans=1000000000000000000;
   for(int i=0;i<n-1;i++){
      ans=min(ans,abs(sum[i]-(sum[n-1]-sum[i])));
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 3328
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            boolean[] a = new boolean[n];
            boolean[] b = new boolean[n];
            for (int i = 0; i < m; i++) {
                int x = in.nextInt() - 1;
                int y = in.nextInt() - 1;
                if (x == 0) a[y] = true;
                if (y == 0) a[x] = true;
                if (x == n - 1) b[y] = true;
                if (y == n - 1) b[x] = true;
            }
            for (int i = 0; i < n; i++) {
                if (a[i] && b[i]) {
                    out.println("POSSIBLE");
                    return;
                }
            }
            out.println("IMPOSSIBLE");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 45544
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    ll N,M;
    cin >> N >> M;
    ll num = M;
    vector<ll> div;
    
    for(ll i = 1;i * i <= M;i++){
        if(num % i == 0){
            div.push_back(i);
            div.push_back(M / i);
        }
    }
    ll ans = 1;
    for(auto num:div){
        if(num * N <= M)ans = max(ans, num);
        //if(M/num <= N)ans = max(ans, M/num);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()
    
void no_cost_graphmake(ll E,mat &G){
  rep(i,E){
    ll a,b;
    cin >> a >> b;
    G.at(a-1).push_back(b-1);
    G.at(b-1).push_back(a-1);
  }
}

int main(){
  ll N,M,Q;
  cin >> N >> M;
  mat G(N);
  no_cost_graphmake(M,G);
  cin >> Q;
  vec V(Q),D(Q),C(Q);
  rep(i,Q){
    cin >> V.at(i) >> D.at(i) >> C.at(i);
    V.at(i)--;
  }
  mat A(N,vec(11,0));
  rep(i,Q){
    if(A.at(V.at(Q-1-i)).at(D.at(Q-1-i))!=0){
      continue;
    }
    A.at(V.at(Q-1-i)).at(D.at(Q-1-i))=C.at(Q-1-i);
    queue<P> R;
    if(D.at(Q-1-i)!=0){
      R.push(P(V.at(Q-1-i),D.at(Q-1-i)));
    }
    while(!R.empty()){
      P a=R.front();
      R.pop();
      if(A.at(a.first).at(a.second-1)==0){
        A.at(a.first).at(a.second-1)=C.at(Q-1-i);
        if(a.second-1!=0){
          R.push(P(a.first,a.second-1));
        }
      }
      rep(j,(ll)G.at(a.first).size()){
        if(A.at(G.at(a.first).at(j)).at(a.second-1)==0){
          A.at(G.at(a.first).at(j)).at(a.second-1)=C.at(Q-1-i);
          if(a.second-1!=0){
            R.push(P(G.at(a.first).at(j),a.second-1));
          }
        }
      }
    }
  }
  rep(i,N){
    cout << A.at(i).at(0) << endl;
  }
}
          

Measured memory_bytes: 26708
#!/usr/bin/env python3
import sys
import collections as cl


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    items = [[0 for i in range(9)]for j in range(9)]

    for i in range(N+1):
        start = int(str(i)[0])
        end = int(str(i)[-1])
        if end == 0:
            continue
        items[start - 1][end - 1] += 1

    ans = 0
    for i in range(9):
        for j in range(9):
            ans += items[i][j] * items[j][i]

    print(ans)


main()


Measured memory_bytes: 73996
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;
using ll =long long;
const int MOD = 1000000007;

//////検証する数,超えられない数////
/*
long long cine(long long a, long long b) {
	if (a <= b) {
		return a;
	}
	else {
		return b;
	}
};*/
//vector型の初期化
/*
void vec_initialize(vector<ll>& a, const ll N) {
	ll c;

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

		cin >> c;
		a.push_back(c);

	}

};
void vec_pair_initialize(vector<pair<ll, ll>>& a, const ll N) {
	ll c, d;
	for (int i = 0; i < N; i++) {
		cin >> c >> d;
		a.push_back(make_pair(c, d));
	}
};
*/
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {

		if (s[i] == 'B') {
			s.erase(i,1);
			if (i - 1 >= 0) {


				s.erase(i - 1, 1);
				i--;
			}

			i--;
		}
		
	}
	cout << s;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int h, w; cin >> h >> w;

    string mat[h];
    rep(i, h){
        cin >> mat[i];
    }

    int cntvert[h][w] = {};
    int cnthrzn[h][w] = {};

    rep(i, h){
        rep(j, w){
            if(mat[i][j] == '#') continue;

            if(j == 0){
                cnthrzn[i][j] = 1;
            }
            else{
                cnthrzn[i][j] = cnthrzn[i][j-1] + 1;
            }
        }
    }

    rep(i, h){
        repr(j, w){
            if(j == w-1) continue;

            if(cnthrzn[i][j] != 0 && cnthrzn[i][j+1] != 0){
                cnthrzn[i][j] = cnthrzn[i][j+1];
            }
        }
    }

    rep(j, w){
        rep(i, h){
            if(mat[i][j] == '#') continue;

            if(i == 0){
                cntvert[i][j] = 1;
            }
            else{
                cntvert[i][j] = cntvert[i-1][j] + 1;
            }
        }
    }

    rep(j, w){
        repr(i, h){
            if(i == h-1) continue;

            if(cntvert[i][j] != 0 && cntvert[i+1][j] != 0){
                cntvert[i][j] = cntvert[i+1][j];
            }
        }
    }

    // rep(i, h){
    //     rep(j, w){
    //         cout << cntvert[i][j];
    //     }
    //     cout << endl;
    // }

    int ans = 0;

    rep(i, h){
        rep(j, w){
            ans = max(ans, cntvert[i][j] + cnthrzn[i][j] - 1);
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 35712
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <cstdio>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n;
vector<int>G[10010];
int a[10010];
int m,mx;
int b[10010];
bool vis[10010];
int pos;
void bfs(){
	queue<int>qq;
	qq.push(mx);
	vis[mx]=1;
	b[mx]=a[++pos];
	while(!qq.empty()){
		int x=qq.front();
		qq.pop();
		for(auto to:G[x])if(!vis[to])vis[to]=1,qq.push(to),b[to]=a[++pos],m+=min(b[x],b[to]);
	}
}
int main(){
	cin>>n;
	for(int i=1,x,y;i<n;i++){
		cin>>x>>y;
		G[x].pb(y);
		G[y].pb(x);
	}
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1,greater<int>());
	for(int i=1;i<=n;i++)if(G[i].size()>G[mx].size())mx=i;
	bfs();
	cout<<m<<endl;
	for(int i=1;i<=n;i++)cout<<b[i]<<' ';
	cout<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){

  int pmin,jmin,inp;

  cin>>pmin;
  cin>>inp;
  if(inp<pmin) pmin=inp;

  cin>>inp;
  if(inp<pmin) pmin=inp;

  cin>>jmin;
  cin>>inp;
  if(jmin>inp) jmin=inp;

  cout<<pmin+jmin-50<<endl;

}

Measured memory_bytes: 1160
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    long long x;
    cin >> x;
    long long n=100;
    long int i;
    for(i=0;x>n;i++){
        n += floor(n/100);
    }
    cout << i << '\n';
    return 0;
}

Measured memory_bytes: 3620
'use strict'
function Main(input) {
    input = input.split("\n");
    const text = input[0]
    const length = text.length
    for (let i = 0; i <= length / 2; i++) {
        const len = length / 2 - i
        const arr = text.slice(0, len)
        const searchTxt = text.slice(len)
        const reg = new RegExp(arr)
        if (searchTxt.search(reg) === 0 && arr.length * 2 !== length) {
            console.log(arr.length * 2)
            break
        }
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21320
A, B, C = sorted(map(int,input().split()))

if A % 2 != 0 and B % 2 != 0 and C % 2 != 0:
    
    tmp1 = A * B
    tmp2 = C // 2
    tmp3 = C - tmp2
    ans = tmp1 * tmp3 - tmp1 * tmp2
    print(ans)
else:
    print(0)

Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,l,r,ans=0;
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>l>>r;
        ans+=r-l+1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;



signed main(){

    int N; cin >> N;
    vec A(N); cin >> A;

    int n = 0;
    REP(i, N) if(A[i] > 1) n++;

    if(n <= 80000){
        bool f = true;
        v_bool used(1000001, false);
        REP(i, N) if(A[i] > 1){
            int a = A[i];
            FOR(k, 2, 1001){
                int c = 0;
                while(a % k == 0){
                    c++;
                    a /= k;
                }
                if(c){
                    if(used[k]){
                        f = false;
                        break;
                    }
                    used[k] = true;
                }
            }
            if(a > 1){
                if(used[a]){
                    f = false;
                    break;
                }
                used[a] = true;
            }
            if(!f) break;
        }
        if(f){
            Out("pairwise coprime");
            return 0;
        }
    }

    int g = A[0];
    FOR(i, 1, N) g = gcd(g, A[i]);
    chOut(g == 1, "setwise coprime", "not coprime");

    return 0;
}


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

using ll = long long;
#define int long long

// [a -> b-1]
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
// [0 -> a-1]
#define rep(i, a) reps(i, 0, (a))
// [a-1 -> b]
#define rreps(i, a, b) for (int i = (int)((a)-1); i >= (int)(b); i--)
// [a-1 -> 0]
#define rrep(i, a)a, rreps(i,  0)
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
 * (v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)\
	sort(all(v));\
	(v).erase(unique(all(v)), v.end())
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(15)
#define YES(f) cout << ((f) ? YES_STR : NO_STR) << endl;


void solve(std::string S) {
	vector<int> res(S.length(), 0);
	rep(i, S.size()) {
		int cnt = 0;
		while (S[i] == 'R') {
			cnt++;
			i++;
		}
		res[i] += cnt / 2;
		res[i-1] += cnt - cnt / 2 - 1;
		int p = i-1;
		cnt = 1;
		while (i < (int) S.size() && S[i] == 'L') {
			cnt++;
			i++;
		}
		res[p] += cnt - cnt / 2;
		res[p+1] += cnt / 2;
		i--;
	}
	rep(i, S.length()-1) {
		cout << res[i] << " ";
	}
	cout << res.back() << endl;
}

signed main() {
	std::string S;
	std::cin >> S;
	solve(S);
	return 0;
}


Measured memory_bytes: 1408
void main()
{
    int n = readln.chomp.to!int;
    int[] a = readln.split.to!(int[]);

    double m = a.sum / n.to!double;
    double diff = double.max;
    ulong frame;
    foreach (i, x; a)
    {
        if (abs(x.to!double - m) < diff)
        {
            frame = i;
            diff = abs(x.to!double - m);
        }
    }

    frame.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
//INF = 1 061 109 567 ; INF + INF = 2 122 219 134 ;
//LINF = 4 557 430 888 798 830 399 ; LINF + LINF = 9 114 861 777 597 660 798 ;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9+7;
const int N = (int)1e5+7;

//浮点型运算
const db eps = 1e-6;
bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }

//--------变量--------//

int n, c[N], s[N], f[N];

//--------函数--------//

void Init() {
}

int Solve() {
	rep(i, 1, n) {
		scanf("%d%d%d", &c[i], &s[i], &f[i]);
	}
	int res;
	rep(i, 1, n) {
		res = 0;
		rep(j, i, n) {
			if (res <= s[j]) res+=s[j]-res+c[j];
			else res += f[j]-((res-s[j])%f[j]==0?f[j]:(res-s[j])%f[j])+c[j];
		}
		printf("%d\n", res);
	}
	printf("0\n");
}

//--------main--------//

int main ()
{
	while (~scanf("%d", &n)) {
		Init();
		Solve();
	}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000011
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
 ll n;
  cin>>n;
  ll a[n+1];
  rep(i, n){
    cin>>a[i+1];}
  
  ll m=0;
  ll x[n];
  ll y[n];
  ll nval=0;
  
  if(a[1]>=0){
    for(int i=3;i<=n;i++){
      if(a[i]<=0){
        swap(a[2], a[i]);
        break;}
      }
      if(a[2]>0){
        int minv=10000000;
        int mind=2;
        for(int i=2;i<=n;i++){
          if(abs(a[i])<=minv&&a[i]!=0){
            minv=abs(a[i]);
            mind=i;}
        }
        swap(a[2], a[mind]);
      }
  }
        
    
    //
     if(a[1]<0){
    for(int i=3;i<=n;i++){
      if(a[i]>=0){
        swap(a[2], a[i]);
        break;}
      }
      if(a[2]<0){
        int minv=10000000;
        int mind=2;
        for(int i=2;i<=n;i++){
          if(abs(a[i])<=minv&&a[i]!=0){
            minv=abs(a[i]);
            mind=i;}
        }
        swap(a[2], a[mind]);
      }
     }
     
    
    //
         
           
    
    
    
             
  
  
  
  for(int i=1;i<=n-1;i++){
    ll p,q;
    
    if(i+1==n){
      p=max(a[i],a[i+1]);
      q=min(a[i],a[i+1]);
    }
    
    if(i+2<=n){    
      
  if(a[i+2]>0){
    p=min(a[i],a[i+1]);
      q=max(a[i],a[i+1]);}
      if(a[i+2]<0){
        p=max(a[i],a[i+1]);
      q=min(a[i],a[i+1]);}
      
      
      if(a[i+2]==0){
        bool tt=false;
        int k=3;
        while(i+k<=n){
        if(a[i+k]>0){
    p=min(a[i],a[i+1]);
      q=max(a[i],a[i+1]);
          tt=true;
        break;}
      if(a[i+k]<0){
        p=max(a[i],a[i+1]);
      q=min(a[i],a[i+1]);
        tt=true;
      break;}
          k++;
        }
        if(!tt){
          p=max(a[i],a[i+1]);
      q=min(a[i],a[i+1]);
        }
      }
      
      
    }
          
       
    
    x[i]=p;
    y[i]=q;
    nval=p-q;
    a[i+1]=p-q;
    a[i]=0;
  }
    
  m=nval;
  cout<<m<<endl;
  for(int i=1;i<=n-1;i++){
  cout<<x[i]<<" "<<y[i]<<endl;}
  return 0;
  
 
}

Measured memory_bytes: 4224
i = {}
i[0] = int(input())
i[1] = int(i[0] / 10)
i[2] = int(i[1] / 10)
i[1] = i[1] - i[2] * 10
i[0] = i[0] - i[1] * 10 - i[2] * 100
s = i[0] + i[1] + i[2]
print(s)

Measured memory_bytes: 3060
from math import gcd

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

if N==2:
    print(max(A))
else:
    L=[0 for _ in range(N)]
    R=[0 for _ in range(N)]
    L[0]=A[0]
    R[-1]=A[-1]
    for i in range(1,N):
        L[i]=gcd(A[i-1],L[i-1])
        R[N-1-i]=gcd(A[N-i],R[N-i])
    ans=max(L[-1],R[0])
    for j in range(1,N-1):
        ans=max(ans,gcd(L[j],R[j]))
    print(ans)

Measured memory_bytes: 21036
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;
#define PI 3.14159265359
 
int main() {
  ll N, A;
  cin >> N;
  vector<ll> vec;
  vec.reserve(N);
  for (auto i = 0;i < N;i ++) {
    cin >> A;
    if (A == 0) {
      cout << 0 << endl;
      return 0;
    }
    vec.push_back(A);
  }
  ll ret = 1;
  bool flag = true;
  ll LIMIT = 1000000000000000000;
  for (auto i = 0;i < N;i ++) {
    if (vec[i] > LIMIT/ret) {
      cout << -1 << endl;
      return 0;
    }
    ret *= vec[i];
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 3992
a=input().strip().split(" ")
a=[int(i) for i in a]

b=[]
c=[]

b.append(a[0])
b.append(a[2])

c.append(a[1])
c.append(a[3])

b.sort()
c.sort()

Sum=c[0]-b[1]

if(Sum<=0):
    print("0")
else:
    print(Sum)


Measured memory_bytes: 3060
#include<iostream>
#include<float.h>
#include<cfloat>
#include<string>
#include<ctype.h>
#include<algorithm>
#include<errno.h>
#include<cerrno>
#include<assert.h>
#include<cassert> 
#include<map>
#include<memory.h>
#include<cctype>
#include<ctype.h>
#include<math.h>
#include<vector> 
#include<cstdio> 
#include<set>
#include<string.h>
#include<stdio.h>
#include<new>
#include<memory>
#include<cmath>
#include<queue>
#include<cstring>
#define ll long long
#define fo(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define br break
#define ct continue
#define pb push_back
#define pi 3.141592653589793238462643383279502884197169
#define F first
#define S second
#define em empty()
#define vei vector<int>
#define ves vector<string>
#define qui queue<int> 
#define qu queue
using namespace std;
int main()
{int a;
 cin>>a;
 cout<<"ABC"<<a;
 return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e18+7;

int32_t main(){
	int a;
	cin>>a;
	for(int i=a;;i++){
		int flag=0;
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0){
				flag=1;
				break;
			}
		}
		if(flag==0){cout<<i<<endl;break;}
	}
}

Measured memory_bytes: 256
n, m = input().split()
n = int(n)
m = int(m)

# 正解した問題を入れるlist

correct = 0
pn = 0
done_list = [0] * n
pn_list = [0] * n

for i in range(m):
    a,b=input().split()
    
    if done_list[int(a)-1] == 0 and b == "AC":
        done_list[int(a)-1] += 1
        correct += 1
        pn += pn_list[int(a) - 1]
    elif b == "WA":
        pn_list[int(a) - 1] += 1

print(correct, pn)

Measured memory_bytes: 4596
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n,m;
Vi s,c;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n>>m;
    s.resize(m);
    c.resize(m);
    rep(i,m){
        cin>>s[i]>>c[i];
    }
    Vi v(n,-1);
    bool flg = true;
    rep(i,m){
        if(v[s[i]-1]==-1 || v[s[i]-1]==c[i]){
            v[s[i]-1] = c[i];
        }else{
            flg = false;
            break;
        }
    }
    if(flg){
        rep(i,n){
            if(i==0){
                if(v[i]==-1){
                    if(n==1)v[i]=0;
                    else v[i]=1;
                }
            }else{
                if(v[i]==-1)v[i]=0;
            }
        }
    }
    if(flg){
        string s;
        rep(i,n){
            s+=to_string(v[i]);
        }
        if(v[0]==0 && v.size()>1)print(-1);
        else print(s);

    }else{
        print(-1);
    }
    return 0;
}

Measured memory_bytes: 256
MOD = 1000000007


def powmod(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        x = powmod(n, p // 2) % MOD
        return (x * x) % MOD
    x = powmod(n, p - 1) % MOD
    return (n * x) % MOD


def main():
    n=int(input())
    ans = powmod(10, n) - powmod(9, n) - powmod(9, n) + powmod(8, n)
    ans %= MOD
    ans = (ans + MOD) % MOD
    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 9216
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0
for a in A:
    if a % 2 == 0:
        if a % 3 != 0 and a % 5 != 0:
            ans += 1
if ans == 0:
    print('APPROVED') 
else:
    print('DENIED')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main() {

	int N;
	cin>>N;
	ll ans=0;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		ans+=a-1;
	}
	cout<<ans<<endl;

	return 0;
}

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

int main() {
  int n;
  ll m;
  cin>>n>>m;
  ll a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n);
  ll l=2;
  ll r=2e5+1;
  while(l<r){
    int x=(l+r)/2;
    int b=0;
    ll c=0;
    rep(i,0,n){
      while(b<n && a[i]+a[n-1-b]>=x) b++;
      c+=b;
    }
    if(c>m) l=x+1;
    else r=x;
  } 
  int d=0;
  ll e=0;
  ll cur=0;
  ll ans=0;
  rep(i,0,n){
    while(d<n && a[i]+a[n-1-d]>=r){
      cur+=a[n-1-d];
      d++;
    }
    e+=d;
    ans+=a[i]*d+cur;
  }
  cout<<ans+(r-1)*(m-e)<<endl;
}

Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
    val input = readLine()!!.split(" ")
    val stack = ArrayDeque<Int>()
    for (s in input) {
        when(s) {
            "+" -> {
                val temp = stack.pop() + stack.pop()
                stack.push(temp)
            }
            "-" -> {
                val temp = - stack.pop() + stack.pop()
                stack.push(temp)
            }
            "*" -> {
                val temp = stack.pop() * stack.pop()
                stack.push(temp)
            }
            "/" -> {
                val temp = stack.pop() / stack.pop()
                stack.push(temp)
            }
            else -> stack.push(s.toInt())
        }
    }

    println(stack.pop())
}


Measured memory_bytes: 32000
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
//#include "Bignum/bignum.h"
//#define big bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j); i <= (int) (k); ++i)
#define Rep(i, j, k) for(R int i = (j); i >= (int) (k); --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 100011;
const ll INF = 5e16;
const double eps = 1e-9;

namespace IO {

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

	#define dd ch = getchar()
	inline ll read() {
		R ll x = 0; R int f = 0; R char dd;
		for (; !isdigit(ch); dd) f ^= (ch == '-');
		for (; isdigit(ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) x = -x, putchar('-');
		if (x > 9) write(x / 10); putchar(x % 10 | 48);
	}

	inline void wrn ( ll x ) { write(x), putchar(' '); }

	inline void wln ( ll x ) { write(x), putchar('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x), wln(y); }

}

using IO::wln;
using IO::read;

namespace Cesare {
	
	/*
		b * a * mid = x
		a * a * l + a * a * (b - l) / 2 = x
	*/
	
	double a, b, x, Ans;
	
	const double PI = 3.14159265358979343846264338327950288;
	
	int main() {
		cin >> a >> b >> x;
		
		if (x > a * a * b / 2.0) {
			double l = 0, r = b;
			while (r - l > eps) {
				double Mid = (l + r) / 2.0;
				double len = a * a * Mid + a * a * (b - Mid) / 2.0;
				(len - x > eps)? r = Mid: l = Mid;
			}
			Ans = atan((b - l) / a) * 180.0 / PI;
			printf("%.9lf\n", Ans);
		} else {
			double l = 0, r = a;
			while (r - l > eps) {
				double Mid = (l + r) / 2.0;
				double len = a * b * Mid / 2.0;
				(len - x > eps)? r = Mid: l = Mid;
			} 
			Ans = atan(b / l) * 180.0 / PI;
			printf("%.9lf\n", Ans);
		} return 0;
	}
	
}

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);

	return Cesare :: main();
}

/*

*/






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	priority_queue<pi>p;
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		ll x;
		cin >> x;
		p.push({x, 1});
	}
	for (int i = 0; i < m; i++) {
		ll how, by;
		cin >> how >> by;
		p.push({by, how});
	}
	ll have = n;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		pi v = p.top();
		ll taken = min(have, p.top().se);
		ans += (taken * p.top().fi);
		have -= taken;
		p.pop();
		if (have == 0)break;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6384
package main

import "fmt"

func main() {
	// Code for A - Irreversible operation
	var S string
	fmt.Scan(&S)

	var count int
	var w int
	for i := 0; i < len(S); i++ {
		if S[i] == 'W' {
			count += i - w
			w++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 3192
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    int a[n][3];
	long long int dp[n][3];
    long long int ans = 0;

    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<3;j++)
    	{
    		cin>>a[i][j];
    		if(i==0)
				dp[i][j]=a[i][j];
			else
				dp[i][j] =0;
 			ans = max(ans,dp[i][j]);

    	}
    }
 	for(int i=1;i<n;i++)
 	{
 		for(int j=0;j<3;j++)
 		{
 			for(int k=0;k<3;k++)
 			{	
 				if(k!=j)
 				{	
					dp[i][j] = max(dp[i][j],dp[i-1][k]);
 					
 				}
 			}
 			dp[i][j] = dp[i][j] + a[i][j];
 			ans = max(ans,dp[i][j]);
 		}
 	}
    cout<<ans;

	return 0;
}

Measured memory_bytes: 3840
nk = list(map(int, input().split()))
n = nk[0]
k = nk[1]
x = list(map(int, input().split()))
min_d = 10 ** 9
for i in range(n - k + 1):
    max_i = x[i + k - 1]
    min_i = x[i]
    if max_i <= 0:
        min_d_i = - min_i
    elif min_i >= 0:
        min_d_i = max_i
    else:
        min_d_i = min(- min_i + 2 * max_i, -2 * min_i + max_i)
    if min_d_i < min_d:
            min_d = min_d_i
print(min_d)


Measured memory_bytes: 14384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,k;
    cin>>a>>b>>k;
    int cnt=0;
    int ans=0;
    for(int i=min(a,b);i>=1;i--){
        if(a%i==0&&b%i==0)
            cnt++;
        if(cnt==k){
            ans=i;
            break;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#define rep(i,j,k) for (i=j;i<=k;i++)
using namespace std;
const int N=1e5+5,H=405;
int n,i,u,v,I[H],O[H],fa[H],ok[H],a[N],b[N],c[N],d[N],h;
int find(int x) {return fa[x]==x?x:fa[x]=find(fa[x]); }
void link(int u,int v) {
	int fx=find(u),fy=find(v);
	if (fx==fy) return;
	fa[fy]=fx;
}
int main()
{
//	freopen("jigsaw.in","r",stdin);
//	freopen("jigsaw.out","w",stdout);
	scanf("%d%d",&n,&h);
	rep(i,1,n) scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
	rep(i,1,h+h) fa[i]=i;
	rep(i,1,n)
	{
		if (!c[i]) u=a[i];
		else u=c[i]+h;
		if (!d[i]) v=b[i]+h;
		else v=d[i];
		O[u]++; I[v]++;
		link(u,v);
	}
	rep(i,1,h)
		if (O[i]<I[i]) { printf("NO\n"); return 0; }
	rep(i,h+1,h+h)
		if (O[i]>I[i]) { printf("NO\n"); return 0; }
	rep(i,1,h+h) if (O[i]!=I[i]) ok[find(i)]=1;
	rep(i,1,h+h)
		if (I[i] && !ok[find(i)]) { printf("NO\n"); return 0; }
	printf("YES\n");
	return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    for(int i=0; i<S.size(); i++){
        int a = S[i] - 'A';
        a = (a+N) % 26;
        S[i] = 'A' + a;
    }
    cout << S << endl;
    return 0;
}

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

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//省略
using vi  = vector<int>;
using vii = vector<vector<int>>;
using vl  = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
    ll N;
    cin>>N;
    vl A(N+1);
    A[0]=0;
    REP(i,N) cin>>A[i+1];
    ll k=0;
    ll flag=true;
    ll ans=0;
    REP2(i,1,N+1){
        if(A[i]==k+1){
            k=k+1;
        }else{
            ll tmp=A[i]-k-2;
            if(tmp>=0){
                tmp/=(k+1);
                tmp++;
                ans+=tmp;
            }
            A[i]=1;
            k=max(k,1LL);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4048
N = int(input())
A = [list(map(int, input().split())) for _ in range(2)]
total = 0
ans = 0
for i in range(N):
    total = 0
    for j in range(i+1):
        total += A[0][j]
    for j in range(i, N):
        total += A[1][j]
    if total > ans:
        ans = total
print(ans)


Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int M = sc.nextInt();
        int N = sc.nextInt();
        sc.close();

        int mCount = 0;
        int nCount = 0;
        if (M < 2) {
            mCount = 0;
        }
        if (nCount < 2) {
            nCount = 0;
        }

        mCount = M * (M - 1) / 2;
        nCount = N * (N - 1) / 2;

        System.out.println(mCount + nCount);
    }

}


Measured memory_bytes: 21844
import java.util.Scanner;
import java.util.ArrayList;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    //input
    int x = sc.nextInt();
    int n = sc.nextInt();
    ArrayList<Integer> intArray = new ArrayList<Integer>();
    for(int i = 0; i < n; i++){
      intArray.add(sc.nextInt());
    }

    //output
    if( n == 0 ){
      System.out.println(x);
    }else{

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

        if( i == 0 ){
          boolean found = false;
          for(int j = 0; j < intArray.size(); j++){
            if( intArray.get(j) == x ){
              intArray.remove(j);
              found = true;
              break;
            }
          }
          if( !found ){
            System.out.println(x);
            break;
          }
        }else{
          boolean highExist = false;
          boolean lowExist = false;
          for(int j = 0; j < intArray.size(); j++){

            if( intArray.get(j) == x+i ){
              highExist = true;
              intArray.remove(j);
              j--;
            }else if( intArray.get(j) == x-i ){
              lowExist = true;
              intArray.remove(j);
              j--;
            }

            if( highExist && lowExist ){
              break;
            }

          }
          if( !(highExist && lowExist) ){
            if( highExist ){
              System.out.println(x-i);
              break;
            }else if( lowExist ){
              System.out.println(x+i);
              break;
            }else{
              System.out.println(x-i);
              break;
            }
          }
        }

      }

    }

  }
}


Measured memory_bytes: 27156
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,M=0;
vi a;

int main(){
	cin>>n;
	a=vi(n);
	for(auto &i:a) cin>>i;
	int res=0;
	a.push_back(0);
	for(int i=1;i<=100;i++){
		int B=0;
		for(int j=0;j<=n;j++){
			if(a[j]<i) res+=B,B=0;
			else B=1;
		}
	}
	cout<<res<<endl;
}

Measured memory_bytes: 384