akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using  namespace std;

#define endl '\n'
#define ll long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
const db pi = acos(-1);
const long long infl = LLONG_MAX;

#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

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

ll i,x,j,y,z,k,n;

string s[2],t;	ll a[2];
cin>>s[0]>>s[1];
cin>>a[0]>>a[1];
cin>>t;
if(t==s[0])	a[0]--;
else a[1]--;
ce(a[0]<<" "<<a[1])
}


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

vector<int> forintinput(int n) {
	vector<int> x(100000);
	for(int i = 0;i < n;i++) cin >> x[i];
	return x;
}
int main(){
	int a,b;
	cin >> a >> b;
	for(int i = 0;i < 100000;i++){
		if(i == 99998 && (int(i*0.08) != a || int(i*0.1) != b)){
			cout << -1 << endl;
			break;
		}
		if(int(i*0.08) == a && int(i*0.1) == b){
			cout << i << endl;
			break;
		}
	}
}

Measured memory_bytes: 3632
s = list(input())
n = len(s)

a = int((n-1)/2)
b = int((n+3)/2)

for i in range(a):
  if s[i] != s[n-1-i]:
    print("No")
    exit()
    
for i in range(a):
  if s[i] != s[a-1-i]:
    print("No")
    exit()
    
for i in range(a):
  if s[b+i-1] != s[n-1-i]:
    print("No")
    exit()
    
print("Yes")

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

const int MOD = static_cast<int>(1e9 + 7);

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

    string S;
    cin >> S;
    unsigned long n = S.size();
    long long dp[100001][4] = {};  // { all, A, AB, ABC }
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 4; ++j) {
            dp[i + 1][j] += dp[i][j] * (S[i] ==  '?' ? 3 : 1);
            if (j < 3 && (S[i] ==  '?' || S[i] == "ABC"[j] )) {
                dp[i + 1][j + 1] += dp[i][j];
                dp[i + 1][j + 1] %=  MOD;
            }
            dp[i + 1][j] %= MOD;
        }
    }

    cout << dp[n][3] % MOD << '\n';

    return 0;
}


Measured memory_bytes: 3664
h,w,k=map(int,input().split())
c=[list(input()) for i in range(h)]
ans=0
sou=0
for i in range(h):
  for j in range(w):
    if c[i][j]=="#":
      sou+=1
for i in range(2**h):
  count=0
  ss=set()
  for j in range(h):
    if (i >> j)&1:
      for l in range(w):
        if c[j][l]=="#":
          count+=1
          ss.add((j,l))
  for i2 in range(2**w):
    count2=0
    for j in range(w):
      if (i2 >> j)&1:
        for l in range(h):
          if c[l][j]=="#" and not((l,j) in ss):
            count2+=1
    if sou-(count+count2)==k:
      ans+=1
print(ans)
          
          

Measured memory_bytes: 9204
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <sstream>
#include <cstdlib>
using namespace std;
int main(){
    int n,m,l,i,j,a[101][101]={0},b[101][101]={0};
    long long c[101][101]={0};
    cin>>n>>m>>l;
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            cin>>a[i][j];
    
    for(i=0;i<m;i++)
        for(j=0;j<l;j++)
            cin>>b[i][j];
    
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            for(int k=0;k<m;k++){
                c[i][j]+=a[i][k]*b[k][j];
            }
        }
    }
    for(i=0;i<n;i++)
        for(j=0;j<l;j++){
            if(j==l-1)cout<<c[i][j]<<endl;
            else cout<<c[i][j]<<" ";
        }
    return 0;
}


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

int main() {
  int D, N;
  cin >> D >> N;
  
  if (D == 0) {
    if (N == 100)
      cout << 101 <<endl;
    else
      cout << N << endl;
  }
  else if (D == 1) {
    if (N == 100)
      cout << 10100 << endl;
    else
      cout << 100 * N << endl;
  }
  else {
    if (N == 100)
      cout << 1010000 << endl;
    else
      cout << 10000 * N << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;


int main() {
	int n;
	double ans=0;
	array <double, 15> x;
	array <string, 15> u;
	cin >> n;
	for (int i = 1; i <= n;i++) {
		cin >> x[i] >> u[i];
		if (u[i]=="JPY") {
			ans += x[i];
		}
		else {
			ans += x[i] * 380000.0;
		}
	}
	cout << ans;

}

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

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

  int m=0;
  int id=0;
  for(int i=0;i<n-1;i++){
    if(m<a[i]+a[i+1]){
      m=a[i]+a[i+1];
      id=i;
    }
  }
  //cout<<m<<endl;

  if(m<l){
    cout<<"Impossible"<<endl;
    return 0;
  }
  cout<<"Possible"<<endl;
  for(int i=0;i<id;i++)cout<<i+1<<endl;
  for(int i=n-1;i>id;i--)cout<<i<<endl;



}


Measured memory_bytes: 1152
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        mut a: [u64; n]
    }

    a.sort_by(|x, y| y.cmp(x));
    let mut res = 0;
    for i in 0..(a.len() - 1) {
        res += a[(i + 1) / 2];
    }
    println!("{}", res);
}


Measured memory_bytes: 6208
/*
I just got lost in thought. It was unfamiliar territory.
- Steven Wright
*/

#include <algorithm>
#include <bitset>
#include <complex>
#include <cstring>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <vector>
//#include <boost/math/common_factor.hpp>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define Pi 3.14159265358979
#define A first
#define B second

typedef long long ll;
typedef vector <int> vi;
typedef vector<ll> vl;
typedef pair <int, int> pi;
typedef pair <ll, int> pl;
typedef pair <double, double> pd;

//change these according to prob constraints
const int INF = 1000000000;
const int MAX = 100005;
const int MAX1 = 2007;
const int MAX2 = 4007;
const int LEN = 21;
const int BASE = 1000000000;
const double EPS = 1e-7;
const int MOD = 1234567891;
//g++ -std=c++11 your_file.cpp -o your_program

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ifstream in("");
	ofstream out("");
	int n;
  cin >> n;
  REP(i, 9){
    string tmp = "";
    REP(j, 3){
      tmp += to_string(i + 1);
    }
    if (n <= stoi(tmp)){
      cout << tmp << endl;
      return 0;
    }
  }
    cout << 1111 << endl;
	return 0;
}

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

int main() {
  vector<int> vec = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  int N;
  cin >> N;
  int K;
  K=N-1;
  cout << vec.at(K) << endl;
  }


Measured memory_bytes: 256
#include<stdio.h>
#include <string.h>
int isPrime(int x){
	int i;
	if(x<2) return 0;
	else if(x==2) return 1;
	if(x%2==0) return 0;
	for(i=3;i*i<=x;i+=2){
		if(x%i==0) return 0;
	}
	return 1;
}
int p,cnt,cnt2,food;
int n,d=0,g,kakaku[31],flag,youso[1000001]={0};
int main()
{
	scanf("%d %d",&n,&p);
	while(1){
		memset(youso, 0, sizeof(youso));
		if(n==0&&p==0){
			break;
		}
		for(cnt=1;cnt<=n;cnt++){
			scanf("%d",&food);
			youso[food]=1;
			kakaku[cnt]=food;
		}
		for(cnt=0;cnt<=p;cnt++){
			if(youso[cnt]==1){
				for(cnt2=1;cnt2<=n;cnt2++){
					if(cnt+kakaku[cnt2]<=p){
						youso[cnt+kakaku[cnt2]]=1;
					}
				}
			}
		}
		flag=0;
		for(cnt=p;cnt>=0;cnt--){
			if(youso[cnt]==1){
				g=cnt;
				d=isPrime(g);
				if(d==1){
					flag=1;
					d=cnt;
					printf("%d\n",d);
					break;
				}
			}
		}
		if(flag==0){
			printf("NA\n");
		}
		d=0;
		flag=0;
		
		scanf("%d %d",&n,&p);
	}
	return 0;
}

Measured memory_bytes: 6588
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef pair<int,int> pii;

int main(){
  int H, W;
  cin >> H >> W;
  string F[H];
  for(int i = 0; i < H; ++i){
    cin >> F[i];
  }
  int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
  pair<pii,pii> e[4];
  e[0] = make_pair(pii(1,0),pii(1,1));
  e[1] = make_pair(pii(0,1),pii(1,1));
  e[2] = make_pair(pii(0,0),pii(0,1));
  e[3] = make_pair(pii(0,0),pii(1,0));
  vector< pair<double,int> > A;//"#"テ」ツ?ョテヲツ閉ーテ」ツつ誰テ」ツ?ィテ」ツ?凖」ツつ凝」ツ?ィ2*N+2テ」ツ?静」ツつ嘉」ツ??」ツ?ョティツヲツ?ァツエツ?ヲツ閉ー
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      if(F[i][j] == '#'){
	for(int k = 0; k < 4; ++k){
	  if(i+dx[k] < 0 || j+dy[k] < 0 || i+dx[k] > H-1 || j+dy[k] > W-1 || F[i+dx[k]][j+dy[k]] != '#'){
	    pii s = pii(H-i-e[k].first.first, j+e[k].first.second);
	    pii t = pii(H-i-e[k].second.first, j+e[k].second.second);
	    //printf("(%d, %d), (%d, %d)\n",s.first,s.second,t.first,t.second);
	    if(s.second && s.first)
	      A.push_back(make_pair((double)s.first/s.second, -1));
	    if(t.second && s.first)
	      A.push_back(make_pair((double)t.first/t.second, +1));
	  }
	}
      }
    }
  }
  sort(A.begin(),A.end());
  int ans = 0, t = 0;

  for(int i = 0; i < (int)A.size(); ++i){

    t += A[i].second;
    t = max(t,0);
    ans = max(t,ans);
  }

  cout << (ans+1)/2 + 1 << endl;
  return 0;
}

Measured memory_bytes: 19952
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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
















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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(void){
    int N,M,Q;
    cin >> N >> M >> Q;
    
    vector<vector<int>> MAP(N+1,vector<int>(N+1));
    vector<vector<int>> SUM(N+1,vector<int>(N+1));
    
    for(int i=0;i<M;i++){
        int L,R;
        cin >> L >> R;
        MAP.at(L).at(R)++;
    }
    
    for(int i=0;i<N+1;i++){
        SUM.at(0).at(i)=0;
        SUM.at(i).at(0)=0;
    }
    
    for(int i=1;i<N+1;i++){
        for(int j=1;j<N+1;j++){
            SUM.at(i).at(j)=SUM.at(i-1).at(j)+SUM.at(i).at(j-1)-SUM.at(i-1).at(j-1)+MAP.at(i).at(j);
        }
    }

    for(int i=0;i<Q;i++){
        int P,Q;
        cin >> P >> Q;
        int ANS=0;
        ANS=SUM.at(Q).at(Q)-SUM.at(P-1).at(Q)-SUM.at(Q).at(P-1)+SUM.at(P-1).at(P-1);
        cout << ANS  << endl;
    }
    
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a[200005];

int main()
{
	ios::sync_with_stdio(false);
	ll n;cin>>n;
	for (int i = 0; i < n; i++)
	{
		cin>>a[i];
	}
	ll tot=a[0];
	ll mai=1000/tot;
	ll shen=1000%a[0];
	ll t=0;
	ll ans=1000;
	for (int i = 1; i < n; i++)
	{
		if(a[i]<a[t])
		{
			ans=a[t]*mai+shen;
			mai=ans/a[i];
			shen=ans%a[i];
			t=i;
		}
		else
		{
			ans=a[i]*mai+shen;
			mai=ans/a[i];
			shen=ans%a[i];
			t=i;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int64_t dp[305][305][305];
static const int64_t mod=1000000007;
int main(){
  int64_t N,M;cin>>N>>M;
  dp[0][1][0]=1;
  for(int64_t i=1;i<=M;i++)
    for(int64_t j=1;j<=N;j++)
      for(int64_t k=0;k<=N-j;k++){
      if(k!=0)
        dp[i][j][k]=(dp[i-1][j][k]*k+dp[i-1][j][k-1]*(N-k+1-j))%mod;
        else{
        int64_t d=(dp[i-1][j][0]*j)%mod;
          for(int64_t l=1;l<=j-1;l++)
            d=(d+(j-l)*dp[i-1][j-l][l])%mod;
          dp[i][j][0]=d;
         }
       }cout<<dp[M][N][0]<<endl;
  return 0;
}

Measured memory_bytes: 218476
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) a.begin(),a.end()

int solve(string &s, int &i){
    vector<int> v;
    if(isdigit(s[i])){
        int num = 0;
        while(isdigit(s[i])){
            num = num*10 + s[i]-'0';
            i++;
        }
        return num+1;
    }
    while(s[i] == '['){
        i++;
        v.push_back(solve(s,i));
        assert(s[i] == ']');
        i++;
    }

    sort(all(v));
    int n = v.size(), sum = 0;
    rep(k,(n+1)/2){
        sum += v[k];
    }
    return sum;
}

int main(void){
    int T;
    cin>>T;
    rep(_,T){
        string s;
        cin>>s;
        int index = 0;
        cout<<(solve(s,index)+1)/2<<endl;
    }
    return 0;
}



Measured memory_bytes: 3212
#include <cstdio>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MAXN = 100010;
inline int read() {
    int n = 0, f = 1; char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -f;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        n = 10 * n + (c ^ '0');
        c = getchar();
    }
    return f * n;
}
int val[MAXN];
vector<int> edge[MAXN];
int main() {
    int n = read(), m = read();
    for (int i = 1; i <= n; i++) val[i] = read();
    for (int i = 1; i <= m; i++) {
        int u = read(), v = read();
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    int ans = 0;
    for (int u = 1; u <= n; u++) {
        bool ok = 1;
        for (int i = 0; i < edge[u].size(); i++) {
            int v = edge[u][i];
            if (val[v] >= val[u]) {
                ok = 0;
            }
        }
        ans += ok;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 8684
height, width = gets.split(" ").map(&:to_i)
boards = Array.new
height.times do
  boards << gets.chomp.to_s
end

# 上記操作後、boards 例
# .  .  .
# .  #  .
# .  .  .

# 数字バージョンの盤面を作成し、 # からの必要ステップ数を格納していく
# 初期値は -1 （未探索）とする
number_boards = Array.new(height) {Array.new(width, -1)}
queue = Array.new

# # の場所の必要ステップ数は 0 とする
# また、 queue に座標を格納する
boards.each_with_index do |board, h|
  board.length.times do |w|
    if board[w] == "#"
      number_boards[h][w] = 0
      queue << [h, w]
    end
  end
end

# 上記操作後、number_boards 例
# -1 -1 -1
# -1  0 -1
# -1 -1 -1
#
# queue 例
# [1, 1]

# queue が空になるまで、上下左右に必要ステップ数を格納していく
until queue.empty?
  current_h, current_w = queue.shift
  current_step = number_boards[current_h][current_w]

  # 上側が -1 の場合、現在地のステップ数 + 1 を格納する
  # queue に上側の座標を格納する
  if current_h > 0 && number_boards[current_h - 1][current_w] == -1
    number_boards[current_h - 1][current_w] = current_step + 1
    queue << [current_h - 1, current_w]
  end

  # 下側が -1 の場合、現在地のステップ数 + 1 を格納する
  # queue に下側の座標を格納する
  if current_h < height - 1 && number_boards[current_h + 1][current_w] == -1
    number_boards[current_h + 1][current_w] = current_step + 1
    queue << [current_h + 1, current_w]
  end

  # 左側が -1 の場合、現在地のステップ数 + 1 を格納する
  # queue に左側の座標を格納する
  if current_w > 0 && number_boards[current_h][current_w - 1] == -1
    number_boards[current_h][current_w - 1] = current_step + 1
    queue << [current_h, current_w - 1]
  end

  # 右側が -1 の場合、現在地のステップ数 + 1 を格納する
  # queue に右側の座標を格納する
  if current_w < width - 1 && number_boards[current_h][current_w + 1] == -1
    number_boards[current_h][current_w + 1] = current_step + 1
    queue << [current_h, current_w + 1]
  end
end

# number_boards 遷移イメージ
# -1 -1 -1
# -1  0 -1
# -1 -1 -1
#
# -1  1 -1
#  1  0  1
# -1  1 -1
# 中略
#  2  1  2
#  1  0  1
#  2  1  2
#
# よって最大ステップ数は 2

puts current_step

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

#define rep(i, N) for(int (i) = 0; (i) < (N); i++)
#define all(v) v.begin(), v.end()
using i64 = int_fast64_t;

int main(){
    int N;
    cin >> N;
    vector<vector<pair<int,int>>> a(N);
    vector<int> A(N);

    rep(i, N){
        cin >> A[i];
        rep(j, A[i]){
            int x, y;
            cin >> x >> y;
            x--;
            a[i].push_back({x, y});
        }
    }

    int ans = 0;
    for(int s = 0; s < (1 << N); s++){
        bool possible = true;
        int cnt = 0;
        for(int i = 0; i < N; i++){
            if(s & (1 << i)){
                cnt++;
                for(int j = 0; j < A[i]; j++){
                    auto p = a[i][j];
                    int x = p.first;
                    int y = p.second;

                    if(!!(s & (1 << x)) != y) possible = false;
                }
            }
        }
        if(possible) ans = max(ans, cnt);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
# 122a

b = input() # 塩基bを入力

if b == 'A':
    pair_base = 'T'
elif b == 'T':
    pair_base = 'A'
elif b == 'C':
    pair_base = 'G'
elif b == 'G':
    pair_base = 'C'

print(pair_base)


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

typedef long long int ll;
ll powk(ll a, ll n = 2){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}


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

    ll ans = 1;
    for(ll i = 0;i < n;i++){
        ans *= 10;
        ans %= 1000000000 + 7;
    }
    ll t1 = 1;
    for(ll i = 0;i < n;i++){
        t1 *= 9;
        t1 %= 1000000000 + 7;
    }
    ll t2 = 1;
    for(ll i = 0;i < n;i++){
        t2 *= 8;
        t2 %= 1000000000 + 7;
    }
    ans -= t1 * 2;
    ans += t2;
    ans %= 1000000000 + 7;
    ans = (ans + 1000000007) % 1000000007;
    cout << ans;

    return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, y;

int main(){
	cin >> n >> y;
	y /= 1000;
	
	bool etre = false;
	for(ll a = 0; a <= min(y/10, n); a++){
		ll b = (y-10*a)-(n-a);
		if(b >= 0 && b%4 == 0){
			b /= 4;
			ll c = n-a-b;
			if(c >= 0){
				cout << a << " " << b << " " << c << endl;
				etre = true;
			}
		}
		
		if(etre){break;}
	}
	if(!etre){cout << "-1 -1 -1" << endl;}
	return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

ll n, m;
ll a[500][500];
ll b[500];

signed main()
{
    cin >> n >> m;
    n *= 3;
    n += m;
    cout << n / 2;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n,n_ichinokurai;
  char buf[10];
  char yomikata[3][4] = {("hon"),("bon"),("pon")};
  fgets(buf, sizeof(buf), stdin);
  sscanf(buf, "%d\n", &n);
  n_ichinokurai = n % 10;
    
  if(n_ichinokurai==3){
    printf("%s\n",yomikata[1]);
  }
  else if(n_ichinokurai==0 || n_ichinokurai==1 ||n_ichinokurai==6 ||n_ichinokurai==8){
    printf("%s\n",yomikata[2]);
  }
  else if(n_ichinokurai==2 || n_ichinokurai==4 ||n_ichinokurai==5 ||n_ichinokurai==7||n_ichinokurai==9){
    printf("%s\n",yomikata[0]);
  }
}
    

Measured memory_bytes: 1616
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
int main () {

  int a, b, c; cin >> a >> b >> c;
  vi ans {a, b, c}; sort(ans.begin(), ans.end());
  cout << ans[0] + ans[1] << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const ll mod = 1e9+7;
const ll INF = ll(1e18)+1;
const ll MAXN = 1e6;

int main()
{
    int n,k;
    cin>>n>>k;
    double ans=0.0;
    rep(i,n)
    {
        int dice=i+1;
        double temp=1.00000000;
        while(dice<k)
        {
            dice*=2;
            temp/=2;
        }
        ans+=temp;
        
    }
    ans/=n;
    cout<<setprecision(10)<<ans;
    
}

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

int main() {
    ll n;
    std::cin >> n;
    string s;
    std::cin >> s;
    
    for (int i = 0; i < n; i++) {
        s[i] = (s[i] == 'o' ? '0' : '1');
    }
    
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            string ans ="";
            
            ans += to_string(i)+to_string(j);
            
            for (int k = 2; k <= n; k++) {
                if(s[k-1] == '0' && ans[k-1] == '0'){
                    ans += ans[k-2];
                }
                if(s[k-1] != '0' && ans[k-1] == '0'){
                    ans += to_string(((ans[k-2]-'0')+1)%2);
                }
                if(s[k-1] == '0' && ans[k-1] != '0'){
                    ans += to_string(((ans[k-2]-'0')+1)%2);
                }
                if(s[k-1] != '0' && ans[k-1] != '0'){
                    ans += ans[k-2];
                }
            }
            
            string required;
            
            if((ans[0] == '0' && s[0] == '0')||(ans[0] != '0' && s[0] != '0')){
                required = ans[1];
            }else{
                required = to_string(((ans[1]-'0')+1)%2);
            }
            
            if(ans[0] == ans[n] && ans[n-1] == required[0]){
                for (int i = 0; i < n; i++) {
                    ans[i] = ans[i] == '0' ? 'S' : 'W';
                }
                ans.erase(n);
                std::cout << ans << std::endl;
                return 0;   
            }
        }
    }
    std::cout << -1 << std::endl;
    
}


Measured memory_bytes: 776
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.SplitInt32().OrderByDescending(i=>i).ToArray();

            return line[0] * 10 + line[1] + line[2];
        }
        
        public const int mod = 1000000007;
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
    }

    public class ConsoleReader { public virtual string String() => Console.ReadLine(); public int Int32() => int.Parse(String()); public long Int64() => long.Parse(String()); public ulong UInt64() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt32() => String().Split().Select(int.Parse).ToArray(); public long[] SplitInt64() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitUInt64() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); } public IEnumerable<int> RepeatInt32(int count) { for (int i = 0; i < count; i++) yield return Int32(); } public IEnumerable<long> RepeatInt64(int count) { for (int i = 0; i < count; i++) yield return Int64(); } public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); } public IEnumerable<int[]> RepeatSplitInt32(int count) { for (int i = 0; i < count; i++) yield return SplitInt32(); } }
}

Measured memory_bytes: 11348
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

struct Edge{
    // 始点, 終点, 重み, 最大量
    long long src, dst, weight, capacity;
    Edge(): src(0), dst(0), weight(0), capacity(0) {}
    Edge(long long s, long long d, long long w): src(s), dst(d), weight(w) {}
    Edge(long long s, long long d, long long w, long long c): src(s), dst(d), weight(w), capacity(c) {}
};

class Graph{
public:
    long long size;
    vector<vector<Edge>> node;
    Graph(long long n): size(n), node(n) {}
    // 無向辺の追加
    void addEdge(long long s, long long d, long long w = 1){
        node[s].emplace_back(s, d, w);
        node[d].emplace_back(d, s, w);
    }
    // 有向辺の追加
    void addArc(long long s, long long d, long long w = 1){
        node[s].emplace_back(s, d, w);
    }
    // ノードの追加
    void addNode(){
        size++;
        node.emplace_back();
    }
};

// TopologicalSort; トポロジカルソート
// ：有向非巡回グラフ（DAG）の全ての辺が右向きになるように整列する。[O(E+V)]
vector<long long> TopologicalSort(const Graph &g){
    vector<long long> indegree(g.size), sorted;
    for(long long v=0; v<g.size; v++) for(auto &edge: g.node[v]) indegree[edge.dst]++;
    queue<long long> que;
    for(long long i=0; i<g.size; i++) if(indegree[i] == 0) que.push(i);
    while(!que.empty()){
        long long v = que.front();
        que.pop();
        sorted.emplace_back(v);
        for(auto &edge: g.node[v]) if (--indegree[edge.dst] == 0) que.push(edge.dst);
    }
    return *max_element(indegree.begin(), indegree.end()) == 0LL ? sorted : vector<long long>();
}

long long encode(long long i, long long j){
    if(i<j) swap(i, j);
    return i*(i-1)/2+j+1;
}


vi d(1000*999/2+1);
vi seen(1000*999/2+1);
long long dfs(Graph &g, ll now){
    if(seen[now] == 2) return d[now];
    seen[now] = 1;
    for(auto &edge: g.node[now]){
        chmax(d[now], dfs(g, edge.dst)+1);
    }
    seen[now] = 2;
    return d[now];
}



int main(){
    Init();
    ll n; cin >> n;
    Graph g(n*(n-1)/2+1);
    vi d(n*(n-1)/2+1, 0);
    rep(i, n){
        ll now = 0;
        rep(j, n-1){
            ll num;
            cin >> num;
            num--;
            ll next = encode(i, num);
            g.addArc(now, next);
            now = next;
        }
    }
    auto p = TopologicalSort(g);
    ll cnt = 0;
    if(!p.size()) cnt = -1;
    else cnt = dfs(g, 0);
    
    cout << cnt << endl;
}

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

typedef long long ll;

ll gcd(ll C, ll D) {
    if (C % D == 0) {
        return D;
    } else {
        return gcd(D, C % D);
    }
}

ll lcm(ll C, ll D) {
    return C / gcd(C, D) * D;
}

ll count(ll A, ll B, ll div) {
    return B / div - (A - 1) / div;
}
 
int main() {
ll A, B, C, D;
cin >> A >> B >> C >> D;
ll N = B - A + 1;
ll E = lcm(C, D);

cout << N - count(A, B, C) - count(A, B, D) + count(A, B, E) << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
#include <iomanip>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;

#define ll long long
#define pii pair<int,int>
/**==Info==
*Program:2
*Problem:Symmetric Grid
*Date:2018-4-21
*Algorithm:latte's Solution
*Stats:Unknown*/

bool debug=false;

int n,m;
string s[15];
string t[15];

void func(){
	map<string,int> cnt;
	for(int i=0;i<m;i++){
		string s="";
		for(int j=0;j<n;j++){
			if(t[j][i]=='*'){
				s+=t[n-1-j][i];
			}else{
				s+=t[j][i];
			}
		}
		
		string ano=s;
		reverse(ano.begin(),ano.end());
		if(ano>=s){
			cnt[s]++;
		}else{
			cnt[ano]--;
		}
	}
	
	bool odd=false;
	for(map<string,int>::iterator it=cnt.begin();it!=cnt.end();it++){
		if(it->second==0) continue;
		string a=it->first;
		string b=a;
		reverse(b.begin(),b.end());
		
		if(a!=b) return;
		if(it->second%2==0) continue;
		if(odd) return;
		odd=true;
	}
	
	puts("YES");
	exit(0);
}
void dfs(int mask,int pos){
	if(mask==0){
		func();
		return;
	}
	
	int p=0;
	while(~mask>>p&1){
		p++;
	}
	
	t[pos]=s[p];
	for(int i=p+1;i<n;i++){
		if((mask>>i)&1){
			t[n-1-pos]=s[i];
			
			dfs(mask^(1<<p)^(1<<i),pos+1);
		}	
	}
}
int main(int argc,char* argv[]){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	
	if(n%2==1){
		s[n]=string(m,'*');
		n++;
	}
	
	dfs((1<<n)-1,0);
	
	puts("NO");
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int h,w;
  cin >> h >> w;
  vector<int> ans(h*w);
  char kari;
  for(int i = 0;i< h ; i++){
    for(int j = 0 ;j<w;j++){
      cin >> kari;

      if(kari == '#'){
        ans.at(i*w + j) += 9;
        if( j != 0){
          ans.at(i*w + j-1) += 1;
        }
        if( j != w-1){
          ans.at(i*w + j+1) += 1;
        }
        if( i != 0 ){
          ans.at((i-1)*w + j) +=1;
          if( j !=0){
            ans.at((i-1)*w + j -1) +=1;
          }
          if(j != w-1){
            ans.at((i-1)*w + j +1) +=1;
          }
        }
        if( i != h-1){
          ans.at((i+1)*w + j) +=1;
          if( j != 0){
            ans.at((i+1)*w + j-1) += 1;
          }
          if( j != w-1){
            ans.at((i+1)*w + j+1) += 1;
          }
        }
      }
    }
  }
  for(int i = 0;i<h;i++){
    for(int j = 0;j<w;j++){
      if(ans.at(i*w +j)<9){
        cout << ans.at(i*w + j)  ;
      }
      else{
        cout << '#' ;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
	static final int MAX = 2_147_483_646; // intMax 
	static final int INF = 1_000_000_000; // 10^9  
	public static void main(String[] args) throws Exception{
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int r = saori.saori_hayami();
		int d = saori.saori_hayami();
		int ans = 0;
		for(int i = n;i <= r;i++){
			if(i %d == 0)ans++;
		}
		System.out.println(ans);
		saori.close();
	}
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}


Measured memory_bytes: 32196
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <queue>


using namespace std;

template<class T> inline bool chmin(T& a, T b) {
  //aの方が大きければbに値を更新、そうでなければ何もしない
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}



int main(){
  int n;
  cin >> n;
  int h[n];
  int i;
  for(i=0;i<n;i++) cin >> h[i];

  int dp[n];
  int INF = 1e9;
  for(i=0;i<n;i++) dp[i] = INF;

  dp[0] = 0;
  dp[1] = abs(h[0]-h[1]);
  for(i=2;i<n;i++){
    chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
  }

  cout << dp[n-1] << endl;




}

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

int main(void)
{
	int a, b, c, d, e, f;
	while(cin >> a >> b >> c >> d >> e >> f){
		double y = (double)(f*a-c*d)/(a*e-b*d);
		double x = (double)(c-b*y)/a;
		printf("%.3f %.3f\n", x, y);
	}
	return(0);
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
//typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1; //llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll modpow(ll a, ll n, ll p)
{ //(a^n)mod p
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % p;
    a = a * a % p;
    n >>= 1;
  }
  return res;
}

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

  ll N,M;
  string S;
  cin >> M>>N;

  cout << modpow(M, N, MOD) << endl;



}



Measured memory_bytes: 3216
#include<unordered_set>
#include<unordered_map>
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<stack>
#include<map>
#include<algorithm>
using namespace std;
 
const static string ASCII("abcdefghijklmnopqrstuvwxyz");
size_t N;
 
string canonical(const string& s) {
    char m[26]; 
    fill(m, m+26, '!');
    int i = 0;
    string r;
    for (char c : s) {
        if (m[c-'a'] == '!') {
            m[c-'a'] = ASCII[i++];
        }
        r += m[c-'a'];
    }
    return r;
}

int main() {    
    cin>>N;
    unordered_set<string> ans;
    stack<string> stk;
    stk.push("");
    while(stk.size()) {
        string s = stk.top(); stk.pop();
        if (s.size()==N)
            ans.insert(canonical(s));
        else
            for (char c='a'; c <= ASCII[s.size()]; c++)
                stk.push(s + c);                                        
    }
    set<string> ss(ans.begin(), ans.end());
    for(auto& s : ss)
        printf("%s\n", s.c_str());
}

Measured memory_bytes: 18724
A, B, C = map(int, input().split())
m = max(A, B, C)
s = A + B + C
if s % 2 == 3 * m % 2:
    ans = (3 * m - s) // 2
else:
    ans = (3 * (m + 1) - s) // 2
print(ans)


Measured memory_bytes: 61892
#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<utility>
#include<sstream>
#define mem0(x) memset(x,0,sizeof x)
#define mem1(x) memset(x,-1,sizeof x)
#define dbug cout<<"here"<<endl;
//#define LOCAL

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e6+10;
const int MOD = 1000000007;
const double EPS = 1e-10;
const double g = 9.8;

int N, V, X, Y;
int L[MAXN], B[MAXN], R[MAXN], T[MAXN];

double calc(double vy, double t){		//?算以vy的速度?直向上射出t秒后的位置
	return vy*t-g*t*t/2;
}

int cmp(double lb, double ub, double a){		//a相?lb和ub的位置
	return a<lb+EPS ? -1 : a>ub-EPS?1:0;
}

bool check(double qx, double qy){				//判断当射出路径??点(qx, qy)?， 卵是否能?中猪
	//?初速度在x方向和y方向的分量分??vx和vy，?通?(qx,qy)的???t
	//求解?立方程式vx?+vy?=V?， vx*t = qx， vy*t-?gt?=qy
	double a = g*g/4;
	double b = g*qy - V*V;
	double c = qx*qx + qy*qy;
	double D = b*b - 4*a*c;
	if(D<0 && D>-EPS)
		D = 0;
	if(D < 0)
		return false;
	for(int d = -1; d <= 1; d += 2){			//???立方程式的?个解的循?
		double t2 = (-b + d*sqrt(D)) / (2*a);
		if(t2 <= 0)
			continue;
		double t = sqrt(t2);
		double vx = qx/t;
		double vy = (qy+g*t*t/2) / t;
		//判断是否通?猪的正上方
		double yt = calc(vy, X/vx);
		if(yt < Y-EPS)
			continue;
		bool ok = true;
		for(int i = 0; i < N; ++i){
			if(L[i] >= X)					//判断在猪正上方的?和猪之?是否有障碍物
				continue;
			if(R[i]==X && Y<=T[i] && B[i]<=yt)		//判断在?到猪正上方之前是否会撞到障碍物
				ok = false;
			int yL = cmp(B[i], T[i], calc(vy, L[i]/vx));	//左?的相?位置
			int yR = cmp(B[i], T[i], calc(vy, R[i]/vx));	//右?的相?位置
			int xH = cmp(L[i], R[i], vx*(vy/g));			//最高点的相?位置
			int yH = cmp(B[i], T[i], calc(vy, vy/g));
			if(xH==0 && yH>=0 && yL<0)
				ok = false;
			if(yL*yR <= 0)
				ok = false;
		}
		if(ok)
			return true;
	}
	return false;
}

void solve(){					//截掉猪以右的障碍物
	for(int i = 0; i < N; ++i){
		R[i] = min(R[i], X);
	}
	bool ok = check(X, Y);			//直接撞上猪的情况
	for(int i = 0; i < N; ++i){
		ok |= check(L[i], T[i]);		//??左上角的情况
		ok |= check(R[i], T[i]);		//??右上角的情况
	}
	printf("%s\n", ok? "Yes":"No");
}

int main(){
	#ifdef LOCAL
		freopen("C:\\Users\\asus-z\\Desktop\\input.txt","r",stdin);
		freopen("C:\\Users\\asus-z\\Desktop\\output.txt","w",stdout);
	#endif
	while(scanf("%d%d%d%d", &N, &V, &X, &Y) != EOF){
		mem0(L);
		mem0(B);
		mem0(R);
		mem0(T);
		for(int i = 0; i < N; ++i){
			scanf("%d%d%d%d", &L[i], &B[i], &R[i], &T[i]);
		}
		solve();
	}
	return 0;
}

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

using namespace std;
#define fi first
#define se second

const int maxn = 123456;

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

ll a[maxn];
map<ll, int>mp;
std::map<ll, int>::iterator it;
int main(){
    // freopen("input.txt", "r", stdin);
    int N, M;
    mp.clear();
    cin>>N>>M;
    for (int i = 0; i < N; ++i)
    {
        cin>>a[i];
    }
    sort(a, a+N);
    ll c;
    int b;
    for (int i = 0; i < M; ++i)
    {
        cin>>b>>c;
        mp[c] += b;
    }
    int cur = 0;
    ll res = 0;
    for(; cur < N; ){
        if(!mp.size())break;
        it = mp.end();
        it--;
        if(it->first > a[cur]){
            res += it->first;
            it->second--;
            if(!it->second)mp.erase(it);
            cur ++;
        }
        else break;
    }
    while(cur < N){
        res += a[cur++];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#define LEN 10000

using namespace std;
int prime_pair(int N);
int is_prime(int p);
int prime_list(int MAX);
int prime[LEN];

int main(void){
	int input;
    int j = 0;
    prime_list(LEN);
    while(cin >> input){
        cout << prime_pair(input) << endl;
	}
	return 0;
}

int prime_list(int MAX){
    int i = 0;
    int j = 0;
    int flag = 1;
    prime[0] = 2;
    for(i = 2; i < MAX; i++){
        while(prime[j] != 0){
            if(i % prime[j] == 0){
                flag = 0;
            }
            j++;
        }
        if(flag){
            prime[j] = i;
        }
        flag = 1;
        j=0;
    }
    return 0;
}

int prime_pair(int N){
    int count = 0;
    int i = 0;
    while((prime[i] < N) && (prime[i] != 0)){
        if(is_prime(N-prime[i]+1))count++;
        i++;
    }
    return count;
}

int is_prime(int p){
    int flag = 0;
    int i = 0;
    while((prime[i] != 0) && (i < p)){
        if(p == prime[i]){
            flag = 1;
            break;
        }
        i++;
    }
    return flag;
}

Measured memory_bytes: 1168
N,W=map(int,input().split())
w=[]
v=[]
for i in range(N):
    w_,v_=map(int,input().split())
    w.append(w_)
    v.append(v_)
INF=10**9+1
dp=[[INF]*(10**5+1) for i in range(N+1)]#dp[i+1][j] i個目までで価値jのときの最小の価値
#dp[i+1][v]:=min(dp[i][v-vi]+wi,dp[i][v])加えるか加えないか
dp[0][0]=0
for i in range(N):
    for j in range(10**5+1):
        if j-v[i]>=0:
            dp[i+1][j]=min(dp[i][j-v[i]]+w[i],dp[i+1][j])
        dp[i+1][j]=min(dp[i+1][j],dp[i][j])
for j in range(10**5,-1,-1):
    if dp[N][j]<=W:
        ans=j
        break
print(ans)


Measured memory_bytes: 121068
#include<bits/stdc++.h>
using namespace std;
int x[128], y[128], h[128];
int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> x[i] >> y[i] >> h[i];
	int pos = 0;
	for(; h[pos] == 0; pos++);

	for(int i = 0; i <= 100; i++)
		for(int j = 0; j <= 100; j++){
			int H = abs(i - x[pos]) + abs(j - y[pos]) + h[pos];
			bool flag = 1;
			for(int k = 0; k < n; k++){
				if( max(H - abs(x[k] - i) - abs(y[k] - j), 0) != h[k]){
					flag = 0;
					break;
				}
			}
			if(flag)
				return cout << i << " " << j << " " << H, 0;
		}
}

Measured memory_bytes: 256
W, H, N = map(int,input().split())
l = 0
r = W
u = H
d = 0
for i in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        l = max(x,l)
    elif a == 2:
        r = min(x,r)
    elif a == 3:
        d = max(y,d)
    else:
        u = min(y,u)
print(max((r-l),0)*max((u-d),0))


Measured memory_bytes: 3064
import heapq

K, T = map(int, input().split())

hp = []
heapq.heapify(hp)
for i in input().split():
    heapq.heappush(hp, -int(i))

pre = -heapq.heappop(hp) - 1  
while hp:
    q = -heapq.heappop(hp)
    if pre > 0:
        heapq.heappush(hp, -pre)
    pre = q - 1
print(pre)


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

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

  int i;
  int now;
  vector<int> a(N);
  vector<bool> b(N, false);

  for (i=0;i<N;i++){
    cin >> a.at(i);
  }

  b.at(0) = true;
  now = 1;
  for (i=0;i<N;i++){
    if (a.at(now-1) == 2){
      cout << i + 1 << endl;
      break;
    } else {
      now = a.at(now-1);
      if (b.at(a.at(now-1)- 1) == true){
        cout << -1 << endl;
        break;
      } else {
        b.at(a.at(now-1)-1) = true;
      }
    }
  }
}

Measured memory_bytes: 768
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 100000
using namespace std;
int cnt[MAXN+5];
int main()
{
	int N,M;
	scanf("%d %d",&N,&M);
	int a,b;
	for(int i=1;i<=M;i++)
	{
		scanf("%d %d",&a,&b);
		cnt[a]++,cnt[b]++;
	}
	for(int i=1;i<=N;i++)
		if(cnt[i]%2==1)
		{
			printf("NO\n");
			return 0;
		}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>

using namespace std;

int main(){
	char a[110],b[110];
	cin >> a;
	cin >> b;
	int len = strlen(a);
	bool flag = true;
	for (int i = 0; i < len; i++){
		if (b[i] != a[i]){ 
			cout << "No";
			flag = false;
			break;
		}
	}
	if (flag) cout << "Yes";
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define int long long
using namespace std;
string s, t;
map<char, char>st, ts;
map<char, bool>stbool, tsbool;
signed main() {
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) {
		if (st[s[i]] != t[i] && stbool[s[i]]) {
			puts("No");
			return 0;
		}
		if (ts[t[i]] != s[i] && tsbool[t[i]]) {
			puts("No");
			return 0;
		}
		st[s[i]] = t[i];
		stbool[s[i]] = true;
		ts[t[i]] = s[i];
		tsbool[t[i]] = true;
	}
	puts("Yes");
	return 0;
}



Measured memory_bytes: 776
import java.util.*;
 
public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        long x = stdIn.nextLong();
        //int x = stdIn.nextInt();
        //boolean flag = true;
        
        // for(int i = 0; i < s.length(); i++){
        //     a[i] = c[i] - 48;
        //     System.out.println(a[i]);
        // }
        //int sum = 0;
        //boolean flag = true;
        //for(int i = 0; i < s.length(); i++){
        //}
        
        System.out.println((x / 500 * 1000) + (x % 500 / 5 * 5));
 
        //System.out.println();
        //System.out.print();
 
        stdIn.close();
    }
}


Measured memory_bytes: 21844
package main

// Solution for https://atcoder.jp/contests/abc075/tasks/abc075_b

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var h, w int
	con.Scan(&h, &w)
	s := make([]string, h)
	for i := 0; i < h; i++ {
		con.Scan(&s[i])
	}
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if s[i][j] == '#' {
				con.Print("#")
				continue
			}
			c := 0
			if i > 0 && s[i-1][j] == '#' {
				c++
			}
			if i < h-1 && s[i+1][j] == '#' {
				c++
			}
			if j > 0 && s[i][j-1] == '#' {
				c++
			}
			if j < w-1 && s[i][j+1] == '#' {
				c++
			}
			if i > 0 && j > 0 && s[i-1][j-1] == '#' {
				c++
			}
			if i > 0 && j < w-1 && s[i-1][j+1] == '#' {
				c++
			}
			if i < h-1 && j > 0 && s[i+1][j-1] == '#' {
				c++
			}
			if i < h-1 && j < w-1 && s[i+1][j+1] == '#' {
				c++
			}
			con.Print(c)
		}
		con.Println()
	}
	return nil
}


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

int main() {
  long long N,T=1000000,T2;
  cin >> N;
  vector<long long> X(N);
  for (int i=0;i<N;i++) cin >> X[i];
  for (int i=1;i<101;i++) {
    T2=0;
    for (int j=0;j<N;j++) T2+=(i-X[j])*(i-X[j]);
	T=min(T,T2);
  }
  cout << T << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b,c,d;
int i[1000000];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,w;
  cin >>s>>w;
  cout <<w<<s<<'\n';
  return (0);
}


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

using namespace std;

vector<int> vv;

long double sq(long double a) {
	return a * a;
}

int main() {
	cout.precision(100);
	int n;
	cin >> n;
	int x[10], y[10];
	for(int i = 1; i <= n; i++)
		vv.push_back(i);
	for(int i = 1; i <= n; i++) {
		cin >> x[i] >> y[i];
	}
	long double ans = 0;
	long double fact = 0;
	do {
		fact++;
		long double temp = 0;
		for(int i = 0; i < n-1; i++) 
			temp += sqrt(sq(x[vv[i]] - x[vv[i+1]]) + sq(y[vv[i]] - y[vv[i+1]]));
		ans += temp;	
	} while(next_permutation(vv.begin(), vv.end()));
	ans /= fact;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256