akhauriyash/Code-Regression huggingface dataset:
/*
        ***Fresher***
    Md Mahfujur Rahman Khan
    Dept. of CSE
    CSE-28 Batch
    JU-48 Batch
    Jahangirnagar University

*/
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>
using namespace std;
#define V_ vector
#define Q_ queue
#define S_ set
#define ST_ stack
#define M_ map
#define DQ_ deque

#define pii pair<ll,ll>
#define pci pair<char,ll>
#define psi pair<string, ll>
#define pis pair<ll,string>
#define pic pair<ll, char>

#define mii map<ll,ll>
#define msi map<string, ll>
#define mis map<ll, string>
#define mib map<ll,bool>
#define msb map<string,bool>

#define vi vector<ll>
#define vs vector<string>

#define ivi vector<ll> :: iterator
#define ivs vector<string> :: iterator
#define imii map<ll,ll> :: iterator
#define imsi map<string,ll> :: iterator
#define imis map<ll, string> :: iterator
#define imib map<ll, bool> :: iterator
#define imsb map<string, bool> :: iterator

#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define F first
#define S second
#define pi 2*acos(0.0)
#define PB(x) push_back(x)
#define PP(x) push(x)
#define RSZ(n) resize(n)
#define POB pop_back()
#define P_ pop()
#define CL_ clear()
#define LEN_ length()
#define SZ_ size()
#define CNT_ count()
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define B_ begin()
#define E_ end()
#define F_ front()
#define t_ top()
#define IN_ insert
#define ER_  erase
#define GT getline
#define NL_   "\n"
#define SP_ " "

#define fr(i, n) for( ll i = 0; i < n; i++)
#define fe(x, n) for( ll i = x; i <= n; i++)

#define ul unsigned long long int
#define ll long long int
#define  MAX 250000

ll i, T, N, tc =0, t;



int main()
{

 ll n;
 cin >> n;
 ll arr[n+1];
 fe(1,n) cin>> arr[i];
 ll j = 1;

 fe(0, n){

     if(arr[i]==j) j++;
     else arr[i] = 0;
 }
 j = 0;
  fe(0,n) if(arr[i]) j++;
  if(n -j < n ) cout << n-j;
  else cout <<-1;
return 0;

}


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

int dp[100005][3];

const int INF = 1e9;

struct State{
	int cur, cnt, dist;
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<vector<int>> G(n);
	rep(i,m){
		int u, v;
		cin >> u >> v;
		--u; --v;
		G[u].push_back(v);
	}
	int s, t;
	cin >> s >> t;
	--s; --t;
	rep(i,100005)rep(j,3) dp[i][j] = INF;
	dp[s][0] = 0;
	State v;
	v.cur = s;
	v.cnt = 0;
	v.dist = 0;
	queue<State> que;
	que.push(v);
	while(!que.empty()){
		v = que.front();
		que.pop();
		int nx_cnt = (v.cnt + 1) % 3;
		for(auto to : G[v.cur]){
			if(dp[to][nx_cnt] <= v.dist + 1) continue;
			dp[to][nx_cnt] = v.dist + 1;
			State nv;
			nv.cur = to;
			nv.cnt = nx_cnt;
			nv.dist = v.dist + 1;
			que.push(nv);
		}
	}
	int ans;
	if(dp[t][0] == INF || dp[t][0]%3 != 0) ans = -1;
	else ans = dp[t][0] / 3;
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9764
n = list(map(int, input().split()))
n.sort(reverse = True)

if (n[0]-n[1]) % 2 == 0 and (n[0]-n[2]) % 2 == 0:
    print(int((2*n[0] - n[1] - n[2]) / 2))
elif (n[0]-n[1]) % 2 == 1 and (n[0]-n[2]) % 2 == 1:
    print(int((2*n[0] - n[1] - n[2]) / 2))
else :
    temp1 = n[1] % 2
    temp2 = n[2] % 2
    if n[0] % 2 == temp1:
        print(int((2*(n[0]+1) - (n[1]+1) - n[2])/2)+1)
    else :
        print(int((2*(n[0]+1) - (n[2]+1) - n[1])/2)+1)

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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	double r;
	const double PI = 3.141592653589793;
	cin >> r;
	cout << 2 * PI * r << '\n';

	return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define FOR(i,s,e) for(int i=(s);i<(e);i++)
#define REP(i,n) FOR(i,0,n)
#define all(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

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

    int a, b;
    cin >> a >> b;
    cout << (a > b ? a-1 : a) << endl;

    return 0;
}


Measured memory_bytes: 764
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int N, M, L;
int d[500][500]; // d[u][v]は辺e=(u, v)のコスト（存在しない場合はINF、ただし[i][i]=0とする）
int d2[500][500]; // d[u][v]は辺e=(u, v)のコスト（存在しない場合はINF、ただし[i][i]=0とする）
int V;

void warshall_floyd(){

    for(int k=0; k<V; k++){
        for(int i=0; i<V; i++){
            for(int j=0; j<V; j++){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            } 
        }
    }
}

void warshall_floyd2(){
    for(int k=0; k<V; k++){
        for(int i=0; i<V; i++){
            for(int j=0; j<V; j++){
                d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
            } 
        }
    }
}


int main(int argc, const char * argv[]) {
  std::cout << std::fixed << std::setprecision(15);

  cin >> N >> M >> L;
  V = N;
  memset(d, 0, sizeof(d));
  memset(d2, 0, sizeof(d2));


  rep(i, V){
      rep(j, V){
          d[i][j] = INTINF;
      }
  }
  rep(i, V) d[i][i] = 0;

  rep(i, M){
    int a, b, c; cin >> a >> b >> c;
    a--; b--;
    d[a][b] = c;
    d[b][a] = c;
  }
  warshall_floyd();

  rep(i, V){
      rep(j, V){
          d2[i][j] = INTINF;
      }
  }
  rep(i, V) d2[i][i] = 0;

  rep(i, N){
    rep(j, N){
      if(i == j) continue;
      if(d[i][j] <= L) d2[i][j] = 1;
    }
  }
  warshall_floyd2();

  int Q; cin >> Q;
  rep(i, Q){
    int s, t; cin >> s >> t;
    s--; t--;
    if(d2[s][t] == INTINF){
      cout << -1 << endl;
    }
    else{
      cout << d2[s][t]-1 << endl;
    }
  }
}  


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

last = -1
tmp = N
ct = 0
while tmp > 0:
    if last == -1:
        if tmp&1:
            last = ct
    tmp = tmp>>1
    ct += 1

if 1 << last == N:
    print("No")
elif last == 0:
    print("Yes")
    for i in range(2, N+1):
        if i&1:
            print(1, i)
            print(i, N+i-1)
        else:
            print(1, i)
            print(i, N+i+1)
    print(N+3, N+1)
else:
    print("Yes")
    for i in range(2, N):
        if i&1:
            print(1, i)
            print(i, N+i-1)
        else:
            print(1, i)
            print(i, N+i+1)
    print(N+3, N+1)
    k = 1 << last
    l = N ^ (k+1)
    print(k, N)
    print(l, 2*N)

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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<double> p(N);
  for (int i = 0; i < N; ++i) cin >> p[i];
  vector<double> sum(N + 1);
  sum[0] = 0;
  for (int i = 0; i < N; ++i) {
    double e = (p[i] * (p[i] + 1)) / 2;
    e /= p[i];
    sum[i + 1] = sum[i] + e;
  }

  double ans = -1.;
  for (int i = 0; i < N - K + 1; ++i) {
    ans = max(ans, sum[i + K] - sum[i]);
  }

  printf("%.10lf\n", ans);
  return 0;
}



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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll a,b,n;

ll val(ll x)
{
  return ((a * x) / b) - a * (x / b);
}
  
int main()
{
  ios::sync_with_stdio(0);
  cin >> a >> b >> n;
  cout << val(min(b - 1, n)) << endl;
  return 0;
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int a,b;cin >> a >> b  ;
  int ans = a*b;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#define df 0
using namespace std;

int dfs(int v,int temp,int* color,vector<vector<int>> const& alist);

int main(){
  int n,m; cin >> n >> m;
  vector<vector<int>> alist(n);
  for(int i=0;i<m;i++){
    int a,b; cin >> a >> b;
    a--;b--;
    alist.at(a).push_back(b);
    alist.at(b).push_back(a);
  }
  int color[n]={};
  int s=dfs(0,1,color,alist);
  if(df)printf("%d\n",s);
  if(s==0){
    cout << (long int)n*(n-1)/2-m;
  }else{
    cout << (long int)s*(n-s)-m;
  }
}
int dfs(int v,int temp,int* color,vector<vector<int>> const& alist){
  if(df)printf("search %d\n",v);
  static int num1=0;
  static bool flag=true;
  if(!flag)return 0;
  temp*=-1;
  for(const int& u: alist.at(v)){
    if(color[u]==0){
      if(df)printf("%d colored by %d\n",u,temp);
      color[u]=temp;
      if(temp==1)num1++;
      dfs(u,temp,color,alist);
    }else if(color[u]!=temp){
      if(df)printf("NOT bipatite!!\n");
      flag=false;
      return 0;
    }
    if(!flag)return 0;
  }
  return num1;
}


Measured memory_bytes: 6528
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll H,W;
ll ans=INF;

ll mmax(ll a,ll b,ll c){
  ll mx=0;
  chmax(mx,abs(a-b));
  chmax(mx,abs(b-c));
  chmax(mx,abs(c-a));
  return mx;
}

void solve(ll h,ll w){
  ll cnt=INF,SA,SB,SC;
  for(int i=1; i<h; ++i){
    SA=i*w;
    if(i<H-1){
      SB=(h-i)/2*w;
      SC=(h-i-(h-i)/2)*w;
      chmin(cnt,mmax(SA,SB,SC));
    }
    
    SB=(h-i)*(w/2);
    SC=(h-i)*(w-w/2);
    chmin(cnt,mmax(SA,SB,SC));
  }
  chmin(ans,cnt);
}

int main(){
  cin>>H>>W;
  solve(H,W);
  solve(W,H);
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

int main() {

	int d,n;
	cin >> d >> n;
	if(n==100)
		n++;
	if(d==0){
		cout << n;
	}else if(d==1){
		cout << n*100 ; 
	}else{
		cout << n*100*100; 
	}

}

Measured memory_bytes: 256
import math
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

S=_S()

if S == 'ARC':
    print('ABC')
else:
    print('ARC')

Measured memory_bytes: 26936
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 10000000000000000
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
long long int MOD = 1000000007;
#define SIZE 1000000
int hoge[20][101010];//2^k
int n,l,q;
int x[101010];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",x+i);
	}
	scanf("%d%d",&l,&q);
	int now=0;
	for(int i=0;i<n;i++){
		while(x[i]-x[now]>l){
			now++;
		}
		hoge[0][i]=now;
	}
	for(int i=1;i<18;i++){
		for(int j=0;j<n;j++){
			hoge[i][j]=hoge[i-1][hoge[i-1][j]];
		}
	}
	
	for(;q--;){
		int a,b;
		scanf("%d %d",&a,&b);a--;b--;
		if(a>b)swap(a,b);
		int ans=1;
		for(int i=17;i>=0;i--){
			if(hoge[i][b]>a){
				ans+= 1<<i;
				b = hoge[i][b];
			}
		}
		printf("%d\n",ans);
	}
}
	


Measured memory_bytes: 8320
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    double n, k, ans = 0;
    cin >> n >> k;
    REP(i, n){
        double j = i, now = 1;
        while(j < k){
            j *= 2;
            now *= 2;
        }
        ans += (1/now) * (1/n);
    }
    cout << setprecision(15) <<ans << endl;
}
    

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int main(){
  int A[32] = {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 K; cin >> K;
  cout << A[K - 1] << endl;
  return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;


public class Main{

	static int[] unionFindTree;
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int productCnt = Integer.parseInt(s.nextLine());
		String[][] productList = new String[productCnt][2];
		for(int i=0 ; i<productCnt ; i++) {
			String[] line = s.nextLine().split(" ");
			productList[i][0] = line[0];
			productList[i][1] = line[1];
		}

		int magicCnt = Integer.parseInt(s.nextLine());
		unionFindTree = new int[productCnt];
		for(int i=0 ; i<productCnt ; i++) {
			unionFindTree[i] = i;
		}

		for(int i=0 ; magicCnt > i ; i++) {
			String[] magic = s.nextLine().split(" ");
			int left=0,right=0,leftV=0,rightV=0;
			for(int j=0 ; j<productCnt ; j++) {
				if(magic[0].equals(productList[j][0])) {
					left = j;
					leftV = Integer.parseInt(productList[j][1]);
				}
				if(magic[1].equals(productList[j][0])) {
					right = j;
					rightV = Integer.parseInt(productList[j][1]);
				}
			}

			int leftP = getParent(left);
			int rightP = getParent(right);
			if(Integer.parseInt(productList[leftP][1]) > Integer.parseInt(productList[rightP][1])) {
				unionFindTree[leftP] = rightP;
			}
			if(Integer.parseInt(productList[leftP][1]) <= Integer.parseInt(productList[rightP][1])) {
				unionFindTree[rightP] = leftP;
			}
		}

		int result = 0;
		for(int i=0 ; i<productCnt ; i++) {
			int pa = getParent(i);
			result+=Integer.parseInt(productList[pa][1]);
		}
		System.out.println(result);
	}

	public static int getParent(int index) {
		if(unionFindTree[index]==index)
			return index;
		return getParent(unionFindTree[index]);
	}
}

Measured memory_bytes: 53560
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
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; }

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

  vector<int> s(M);
  vector<char> c(M);
  for (int i = 0; i < (int)(M); ++i) {
    cin >> s[i] >> c[i];
    --s[i];
  }

  int MAX = 1;
  for (int i = 0; i < (int)(N); ++i) MAX *= 10;

  auto ok = [&](int n) {
    string t = to_string(n);
    if (t.size() != N) return false;
    for (int i = 0; i < (int)(M); ++i) if (t[s[i]] != c[i]) return false;
    return true;
  };

  for (int i = 0; i < MAX; ++i) {
    if (ok(i)) {
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<cmath>

using namespace std;

int a, b, c, ans = 0x7fffffff;

int main(){
	scanf("%d%d%d", &a, &b, &c);
	ans = min(ans, abs(a-b)+abs(b-c));
	ans = min(ans, abs(a-b)+abs(a-c));
	ans = min(ans, abs(a-c)+abs(b-c));
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n; cin >> n;
    
    vector<int> te(n);
    vector<int> fu(n);
    
    for( int i = 0; i < n; i++ ){
        cin >> te[i];
    }
    
    for( int i = 0; i < n; i++ ){
        cin >> fu[i];
    }
    
    int left = 1001, right = 1001, lc = 0, rc = 0;
    for( int i = 0; i < n; i++ ){
        if( te[i] == 0 ){
            if( right > fu[i] ){
                right = fu[i];
                rc++;
            }
        }
        
        if( te[i] == 1 ){
            if( left > fu[i] ){
                left = fu[i];
                lc++;
            }
        }
    }
    
    if( lc == 0 || rc == 0 ){
        cout << 0 << endl;
    }else{
        cout << right + left << endl;
    }
}



Measured memory_bytes: 3116
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(X: int, Y: int, Z: int):
    print(Z, X, Y)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    solve(X, Y, Z)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <stdio.h>

int main(void){

	int ans = 0; 
	int a, b, c, d, n;
	
	while(scanf("%d", &n) != EOF){
		ans = 0;
		for(a = 0; a <= 9; a++){
			for(b = 0; b <= 9; b++){
				for(c = 0; c <= 9; c++){
					for(d = 0; d <= 9; d++){
						if(a + b + c + d == n){
							ans++;
						}
					}
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
int main() {
	int W, H, x, y, r;
	std::cin >> W >> H >> x >> y >> r;
	if (x + r <= W && x - r >= 0 && y + r <= H && y - r >= 0) {
		std::cout << "Yes\n";
	}
	else {
		std::cout << "No\n";
	}
	return 0;
}


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

int main() {

	ll s;
	ll oku = 1000000000;
	cin >> s;
	cout << "0 0 1000000000 1 " << (oku - (s % oku)) % oku << " " << (s + oku - 1) / oku << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

#define N 1500

static
int my[ N * N ];

using namespace std;

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    int px[ N + 1 ], py[ N + 1 ];
    /** Allocated in Heap Memory Area:
     * int my[ N * N ]; */
    int x1, x2, y1, y2;
    int res = 0;
    int n, m;

    scanf ( "%d%d", &n, &m );
    if ( !( n | m ) ) break ;

    px[ 0 ] = 0; py[ 0 ] = 0;
    for ( i = 1; i <= n; ++i )
    {
      scanf ( "%d", px + i );
      px[ i ] += px[ i - 1 ];
    }
    for ( i = 1; i <= m; ++i )
    {
      scanf ( "%d", py + i );
      py[ i ] += py[ i - 1 ];
    }

    i = 0;
    for ( y1 = 0;       y1 <= m; ++y1 )
    for ( y2 = y1 + 1;  y2 <= m; ++y2 )
    {
      my[ i++ ] = py[ y2 ] - py[ y1 ];
    }
    sort ( my, my + i );

    for ( x1 = 0;       x1 <= n; ++x1 )
    for ( x2 = x1 + 1;  x2 <= n; ++x2 )
    {
      const int dx = px[ x2 ] - px[ x1 ];

      res += upper_bound ( my, my + i, dx ) - lower_bound ( my, my + i, dx );
    }

    printf ( "%d\n", res );
  }

  return ( 0 );
}

Measured memory_bytes: 5172
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))

# 株は変えるだけ買うほうがよさそう
dp = defaultdict(int)
dp[0] = 1000
for a in A:
    key, val = zip(*dp.items())
    for k, v in zip(key, val):
        # 株売る
        dp[0] = max(dp[0], v + k * a)
        # 株買う
        buy = v // a
        dp[k + buy] = max(dp[k + buy], v - buy * a)

print(dp[0])

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

using namespace std;

#define int long long

const int MOD = 998244353;
const int N = 1e7 + 12;

long long ans;
long long deg2[N], fact[N], ufact[N], r[N];

long long cnk(long long n, long long k)
{
    return fact[n] * ufact[k] % MOD * ufact[n - k] % MOD;
}

signed main()
{
    int n;
    cin >> n;
    deg2[0] = 1, fact[0] = 1, ufact[0] = 1, r[1] = 1;
    for (int i = 2; i < N; i++) r[i] = MOD - (MOD / i) * r[MOD % i] % MOD;
    for (int i = 1; i < N; i++) deg2[i] = deg2[i - 1] * 2 % MOD, fact[i] = fact[i - 1] * i % MOD, ufact[i] = ufact[i - 1] * r[i] % MOD;
    ans = 1;
    for (int i = 0; i < n; i++) ans = ans * 3 % MOD;
    for (int c = n / 2 + 1; c <= n; c++)
    {
        ans = (ans - cnk(n, c) * deg2[n - c + 1] + MOD * MOD) % MOD;
    }
    cout << ans;
}


Measured memory_bytes: 312704
#include <bits/stdc++.h>
#define ll long long

using namespace std;

///Code starts from here
int main()
{
    int a[5],i;

    for(i=0;i<5;i++)
    {
        cin>>a[i];
        if(a[i]==0)
            cout<<i+1<<endl;
    }
    return 0;
}



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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  int K;
  cin >> K;
  
  bool T = false;
  //TがTrueになる組み合わせがあればOK
  
  while(A>=B && K>=0){
    B*=2;
    K--;
  }
  
  while(B>=C && K>=0){
    C*=2;
    K--;
  }
  
  if(A<B && B<C && K>=0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
      
}


Measured memory_bytes: 3632
//make sure to make new file!
import java.io.*;
import java.util.*;

public class Main{
   
   public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      double n = Double.parseDouble(f.readLine());
      
      out.println(n*2.0*Math.PI);
      
      
      
      
      
      
      
      
      out.close();
   }
   
      
}

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

int main() {
  int n; cin >> n;
  int c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  for(int i = 0; i < n; i++){
    string s; cin >> s;
    if(s == "AC") c0++;
    else if(s == "WA") c1++;
    else if(s == "TLE") c2++;
    else c3++;
  }
  cout << "AC x " << c0 << endl;
  cout << "WA x " << c1 << endl;
  cout << "TLE x " << c2 << endl;
  cout << "RE x " << c3 << endl;
}

Measured memory_bytes: 3628
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * 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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        static int[][] cost;

        static int getMinCost(int sum, int min, int n, ArrayList<Integer> rest) {
            if (n == 1) return sum;
            if (sum > min) return sum;
            ArrayList<Integer> next = new ArrayList<Integer>();
            for (Integer i : rest) {
                if (i == n) continue;
                next.add(i);
            }
            int cMin = min;
            for (Integer i : next) {
                int nextSum = sum + cost[n][i];
                int iMin = getMinCost(nextSum, min, i, next);
                if (iMin < cMin) cMin = iMin;
            }
            return cMin;
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int h = in.nextInt();
            int w = in.nextInt();
            // int[][] field = new int[h][w];

            cost = new int[10][10];
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    cost[i][j] = in.nextInt();
                }
            }
            int[] minCost = new int[10];

            for (int i = 0; i < 10; i++) {
                ArrayList<Integer> path = new ArrayList<Integer>();
                for (int j = 0; j < 10; j++) if (j != i) path.add(j);
                minCost[i] = getMinCost(0, Integer.MAX_VALUE, i, path);
            }

            int ans = 0;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    int c = in.nextInt();
                    if (c != 1 && c != -1) ans += minCost[c];
                }
            }
            out.println(ans);
        }

    }
}



Measured memory_bytes: 89500
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        ++$this->pointer;

        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int) $this->next();
    }

    public function nextDouble()
    {
        return (float) $this->next();
    }
}

$sc = new Scanner();
$n = $sc->nextInt();
$array = [];
$sum = 0;

for($i=1;$i<$n+1;$i++){
    $array[$i] = $sc->nextInt();
}

for($i=floor($n/2);$i>0;$i--){
    for($j=$i;$j<$n+1;$j=$j+$i){
        $sum = $sum + $array[$j];
    }
    if($sum%2 == 0){
        $array[$i] = 0;
    } else {
        $array[$i] = 1;
    }
    $sum = 0;
}

if(max($array) == 0){
    echo "0".PHP_EOL;
} else {
    echo array_sum($array).PHP_EOL;
    $flag = false;
    for($i=1;$i<$n+1;$i++){
        if($array[$i] == 1){
           if($flag){
             echo " ";
           }
           echo $i;
           $flag = true;
        }
    }
}

Measured memory_bytes: 29800
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

class UnionFindTree {
public:
    explicit UnionFindTree(size_t size = 0) {
        reset(size);
    }

    void reset(size_t size) {
        group.resize(size);
        rep(i, size) group[i] = i;
    }
 
    int getGroupId(int i) {
        int g = group[i];
        if (i != g) {
            group[i] = getGroupId(g);
        }
        return group[i]; 
    }

    bool inSameGroup(int i, int j) {
        return (getGroupId(i) == getGroupId(j));
    }

    void merge(int i, int j) {
        i = getGroupId(i);
        j = getGroupId(j);
        if (i != j) {
            group[i] = j;
        }
    }

private:
    vector<int> group;
};

int groupSize[100005];

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

    int N, M, K;
    cin >> N >> M >> K;

    UnionFindTree uft(N);
    vector<set<int>> blocked(N);
    vector<int> friends(N);

    rep(i, M) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        uft.merge(a, b);
        ++friends[a];
        ++friends[b];
    }

    rep(i, K) {
        int c, d;
        cin >> c >> d;
        --c; --d;
        blocked[c].insert(d);
        blocked[d].insert(c);
    }

    rep(i, N) {
        ++groupSize[uft.getGroupId(i)];
    }

    rep(i, N) {
        int gs = groupSize[uft.getGroupId(i)];
        --gs; // exclude self
        gs -= friends[i]; //! exclude friends
        for (int b: blocked[i]) {
            if (uft.inSameGroup(i, b)) {
                --gs;
            }
        }
        cout << gs << ' ';
    }
    cout << endl;


    return 0;
}


Measured memory_bytes: 16640
#include <iostream>

int cards[3];
int k;

bool isPossible(int remaining)
{
    if (cards[0] < cards[1] && cards[1] < cards[2])
        return true;
    
    if (remaining <= 0)
        return false;
    
    for (int i = 0; i < 3; ++i)
    {
        cards[i] *= 2;
        if (isPossible(remaining - 1))
            return true;
        cards[i] /= 2;
    }
    return false;
}

int main()
{
    scanf("%d %d %d", &cards[0], &cards[1], &cards[2]);
    scanf("%d", &k);
    
    printf("%s", isPossible(k) ? "Yes" : "No");

    return 0;
}

Measured memory_bytes: 3820
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
#include <sstream>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
const long long INF = 1LL << 60;
typedef unsigned long long ll;
template<class T> inline bool chmin(T& a, T 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 ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}


int main(){ 
int N; cin >> N;
vector<long long> h(N);
rep(i,N) cin >> h[i];
vector<long long> dp(N);
rep(i,N) dp[i] = INF;
dp[0] = 0;
for(int i = 1; i < N; i++){
	chmin(dp[i],dp[i-1] + abs(h[i] - h[i-1]));
	if(i > 1)
	chmin(dp[i],dp[i-2] + abs(h[i] - h[i-2]));

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


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,m,n) for(ll i=m;i<(ll)(n);i++)
typedef pair<int,long long> pint;
typedef long long ll;
const ll mod= 1e9+7;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

ll dp[1010][1010],fact[1010],invfact[1010],inv[1010];
int a,b,c,d;

ll comb(int n,int k){
  ll ret=fact[n]*invfact[k]%mod;
  return ret*invfact[n-k]%mod;
  }

ll rec(int k,int m){
  if(m<0)return 0;
  if(dp[k][m]!=-1)return dp[k][m];
  if(k==a-1)return m==0;
  ll ret=rec(k-1,m);
  int cnt=1,res=1;
  int mm=m;
  while(m>=k&&cnt<=d){
    res=res*comb(m,k)%mod;
    res=res*inv[cnt] %mod;
    if(cnt>=c)ret+=res*rec(k-1,m-k);
    ret%=mod;
    m-=k;
    cnt++;
    }
  return dp[k][mm]=ret;
  }

ll f(ll n){
  ll ret=1,k=mod-2;
  while(k>0){
    if(k%2)ret=ret*n %mod;
    n=n*n %mod;
    k/=2;
    }
  return ret;
  }

int main(){
  fact[0]=invfact[0]=inv[0]=1;
  rep(i,1010)inv[i+1]=f(i+1);
  rep(i,1010){
    fact[i+1]=fact[i]*(i+1) %mod;
    invfact[i+1]=invfact[i]*inv[i+1] %mod;
    }
  int n;
  cin>>n>>a>>b>>c>>d;
  rep(i,1010)rep(j,1010)dp[i][j]=-1;
  cout<<rec(b,n)<<endl;
  return 0;
  }

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

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

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

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

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

    int N, M;
    cin >> N >> M;
    vector<int> S(N), T(M);
    REP(i, N) cin >> S[i];
    REP(i, M) cin >> T[i];
    
    vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 1));
    RREP(i, N) RREP(j, M) {
        if (S[i] == T[j]) {
            dp[i][j] = (dp[i + 1][j] + dp[i][j + 1]) % MOD;
        } else {
            dp[i][j] = (dp[i + 1][j] + dp[i][j + 1] + (MOD - dp[i + 1][j + 1])) % MOD;
        }
        //printf("dp[%d][%d] = %lld\n", i, j, dp[i][j]);
    }
    cout << dp[0][0] << endl;
    return 0;
}



Measured memory_bytes: 31616
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = list(STR())
for i in range(len(s)):
    s = s[:len(s) - 1]
    if len(s) % 2 == 0 and s[:len(s) // 2] == s[len(s) // 2:]:
        print(len(s))
        exit()


Measured memory_bytes: 5180
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

map<ll,ll> ma;

int main(void) {

    ll n,m;
    cin>>n>>m;
    vll v(n);
    rep(i,n)cin>>v[i];
    rep(i,m){
        int a,b;
        cin>>a>>b;
        ma[b]+=a;
    }
    rep(i,n){
        ma[v[i]]++;
    }
    vector<pair<ll,ll>> p;
    for(auto it=ma.begin();it!=ma.end();it++){
        p.push_back(mp(it->first,it->second));
    }
    Rort(p);
    ll ans=0;
    int pos=0;
    // rep(i,p.size())cout<<p[i].first<<" "<<p[i].second<<endl;
    while(n>0){
        if(n>=p[pos].second){
            // cout<<"AAA:"<<p[pos].first*p[pos].second<<endl;
            ans+=p[pos].first*p[pos].second;
            n-=p[pos].second;
            pos++;
            // cout<<"n"<<n<<endl;
        } else {
            // cout<<"BBB:"<<p[pos].first*n<<endl;
            ans+=p[pos].first*n;
            break;
        }
    }
    fin(ans);
}


Measured memory_bytes: 19696
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans=min(b,d)-max(a,c);
    cout<<max(ans,0)<<endl;
    return 0;
}

Measured memory_bytes: 256
// Last Change: 05/16/2019 18:21:16.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  ll a, b, c;
  cin >> a >> b >> c;

  if (b - a == c - b)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __ <<' '<<
#define ___ <<' '
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {IoSetup() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout <<fixed<<setprecision(12);
    cerr <<fixed<<setprecision(12);
}}IoSetup;

using ll = long long;
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int SMOD = 1000000007;
constexpr int NMOD = 998244353;
constexpr int dx[]={1,0,-1,0,1,1,-1,-1};
constexpr int dy[]={0,1,0,-1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a<b?a=b,true:false);}
template<class T>bool chmin(T &a, const T &b){return(a>b?a=b,true:false);}
inline int qp(int a,ll b,int mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}



signed main() {

    ll x;

    cin >> x;

    ll ans = 100, c = 0;

    while(ans < x) {
        ans += ans/100;
        c++;
    }

    cout << c << endl;
    
    return 0;
}



Measured memory_bytes: 3612
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    X,t=map(int,input().split())
    ans=X-t
    print(ans if ans>=0 else 0)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int ans = 700;
  for ( int i = 0; i<3; i++){
    if ( S.at(i) == 'o' ){
      ans += 100;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3552
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int A, B;
  cin >> A >> B;
  int sum = A + B;
  if (sum >= 10) {
    cout << "error" << endl;
  } else {
    cout << sum << endl;
  }
}


Measured memory_bytes: 256
use std::io;


fn main() {
    let s = read_one::<String>().chars()
        .map(|c| (c as u8 - b'0') as usize).collect::<Vec<usize>>();
    let k = read_one::<usize>();
    let mut ans = 0;
    let mut cnt = 0;
    for i in s {
        if i == 1 { cnt += 1;}
        if k <= cnt { ans = i; break; }
        if i != 1 { ans = i; break; }
    }
    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define f(i,x,n) for(ll i=x;i<n;i++)
#define fl(i,x,n) for(ll i=n;i>=x;i--)
#define mod (ll)1e9+7
#define print(x) cout<<x<<endl
#define vec vector<ll>
#define pai pair<ll, ll>
#define itr(it) :: iterator it
#define MAX (ll)1e16
#define MIN (ll)-1e16
#define X first
#define Y second
#define up upper_bound
#define lo lower_bound
using namespace std;
       ///////////   ///     ///   ///      ///   ////////////  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///////////   ///      ///   ////////////  ////////////
               ///   ///     ///   ///      ///   ///      ///  ///      ///
               ///   ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///     ///   ////////////   ////////////  ///      ///
ll minn( ll a , ll b) 
{
    if(a>b)
        return b;
    return a;
}
ll maxx2( ll a , ll b)
{
    if(a>b)
        return a;
    return b;
}
ll maxx(ll a,ll b,ll c)
{
  return maxx2(a,maxx2(b,c));
}
ll gcdd(ll a, ll b)
{
    if(b==0)
        return a;
    else
        return gcdd(b,a%b);
}
ll dsum(ll n)
{
    ll sum=0;
    while(n>0)
    {
        sum+=n%10;
        n/=10;
    }
    return sum;
}
ll poww(ll a,ll b)
{
    if(b<=0)
        return 1;
    if(b==1)
        return a;
    if(b==2)
        return (a*a);
    else
        return poww(poww(a,b/2),2)*(poww(a,b%2));
}
ll sumsq(ll x,ll y,ll z)
{
    return (x-y)*(x-y)+(y-z)*(y-z)+(z-x)*(z-x);
} 
signed main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    IOS;
    ll a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
    return 0;
}

Measured memory_bytes: 3616