akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-9;

typedef long long ll;

#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

int N;
int a[101];

int main(int argc, char * argv[])
{
    ios::sync_with_stdio(false);
	cin >> N;
	rep(i,N) cin >> a[i];

	int mn = INF;
	for (int x = -100; x <= 100; x++){
		int ret = 0;
		rep(i,N){
			ret += (x-a[i])*(x-a[i]);
		}
		mn = min(mn,ret);
	}
	cout << mn << endl;



    return 0;
}



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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}

void solve(){


}
const ll mod = 998244353;
ll dp[2][309][309];
ll sum[2][309][609];
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	string s;int k;
	cin>>s>>k;
	k=min(k,300);
	vi v;
	int cnt = 0;
	trav(i,s){
		if(i=='1') cnt++;
		else v.pb(cnt),cnt=0;
	}
	v.pb(cnt);
	if(sz(v)==1){
		cout<<1;
		return 0;
	}
	dp[0][0][0] = 1;
	int cur = 0;
	trav(i,v){
		fill(dp[1-cur]);
		repA(j,0,k) repA(x,0,k){
			if(x&&j) sum[0][j][x] = (sum[0][j-1][x-1]+dp[cur][j][x])%mod;
			else sum[0][j][x] = dp[cur][j][x];
		}
		repD(j,k,0) repD(x,k,0) {
			sum[1][j][x] = (sum[1][j][x+1]+dp[cur][j][x])%mod;
		}
		repA(j,0,k) repA(x,0,k){
			dp[1-cur][j][x] = (sum[0][j][x]+sum[1][j][x]-dp[cur][j][x]-sum[1][j][x+i+1]+2*mod)%mod;
		}
		cur=1-cur;
	}
	ll fns = 0;
	repA(j,0,k) {
		fns+=dp[cur][j][0];
	}
	cout<<fns%mod;
	return 0;
}



Measured memory_bytes: 7976
a,b,c,d = map(int, input().split())
if b<=c or d <=a:
  print(0)
  exit()
if a<=c and d<=b:
  print(d-c)
elif a<=c and b<=d:
  print(b-c)
elif c<=a and d<=b:
  print(d-a)
elif c<=a and b<=d:
  print(b-a)

Measured memory_bytes: 3060
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M = list(map(int,input().split()))
Network = UnionFind(N+M)
for i in range(N):
    tmp = list(map(int,input().split()))
    for j in range(tmp[0]):
        Network.union(i, tmp[j+1]+N-1)
cnt = 0
for k in Network.parents:
    if k<0 and k!= -1:
        cnt += 1
if cnt>=2:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 82608
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
 
int main() {
    ll ans = 0;
    ll h, w, n;
 
    cin >> h >> w >> n;
 
    if (h > w) (n % h == 0) ? (ans = n / h) : (ans = n / h + 1);
    else (n % w == 0) ? (ans = n / w) : (ans = n / w + 1);
 
    cout << ans << endl;
 
 
    return 0;
}

Measured memory_bytes: 256
N = int(input())
SP = [["", 0, 0] for _ in range(N)]
for i in range(N):
  line = [el for el in input().strip().split()]
  SP[i][0], SP[i][1] = line[0], int(line[1])
  SP[i][2] = i + 1
SP.sort(key=lambda x: x[1], reverse=True)
SP.sort(key=lambda x: x[0])
for i in range(N):
  print(SP[i][2])


Measured memory_bytes: 3064
/*********************************************************************************\
*  _________  _      _  ________  _       _       __       ________               *
* |___   ___|| |    | ||  ______|| |     | |     /  \     |  ____  |              *
*     | |    | |    | || |______ | |_____| |    / /\ \    | |____| |              *
*     | |    | |    | ||______  ||  _____  |   / /__\ \   |  __  __|              *
*     | |    | |____| | ______| || |     | |  / ______ \  | |  \ \                *
*     |_|    |________||________||_|     |_| /_/      \_\ |_|   \_\               *
*  ________       __      ________  _    __       __       ________               *
* |  ______|     /  \    |  ____  || |  / /      /  \     |  ____  |              *
* | |______     / /\ \   | |____| || |_/ /      / /\ \    | |____| |              *
* |______  |   / /__\ \  |  __  __||  __ \     / /__\ \   |  __  __|              *
*  ______| |  / ______ \ | |  \ \  | |  \ \   / ______ \  | |  \ \                *
* |________| /_/      \_\|_|   \_\ |_|   \_\ /_/      \_\ |_|   \_\               *
*                                                                                 *
*                                                                                 *
*   Department of Computer Science & Engineering                                  *
*   Student ID : 18CSE035                                                         *
*   Bangabnadhu Sheikh Mujibur Rahman Science & Technology University,Gopalgonj.  *
*                                                                                 *
\*********************************************************************************/
 
//Now Write to Code ___________________________
#include<bits/stdc++.h>
using namespace std;

int main()
{
	int N,R,result;

	cin >> N >> R;
	if(N <= 10)
	{
		result = R + 100*(10-N);
		cout << result << endl;
	}
	else
	{
		cout << R << endl;
	}

	return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())

a = []
for i in range(h):
    tmp = list(map(int, input().split()))
    a.append(tmp)

ans = []
for y in range(h):
    for x in range(w):
        if y == h-1 and x == w-1:
            continue
        if a[y][x] % 2 == 1:
            if x == w-1:
                a[y+1][x] += 1
                tmp = [y+1, x+1, y+2, x+1]
            else:
                a[y][x+1] += 1
                tmp = [y+1, x+1, y+1, x+2]
            ans.append(tmp)
print(len(ans))
for x in ans:
    print(*x)

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

class DSU{
    public:
        int n;
        vector<int> parent, rank, size;

        DSU(int x){
            n = x;
            parent.assign(n+1,0);
            rank.assign(n+1,0);
            size.assign(n+1,1);
            for(int i=0;i<=n;i++){
                parent[i] = i;
            }
        }

        int find(int x){
            return (parent[x]==x) ? x : parent[x] = find(parent[x]);
        }

        void _union(int x, int y){
            x = find(x);
            y = find(y);
            if(x!=y){
                if(rank[x]>rank[y]){
                    parent[y] = x;
                    size[x]+=size[y];
                }
                else{
                    parent[x] = y;
                    size[y]+=size[x];
                    rank[y] += (rank[x]==rank[y]);
                }
            }
    }

    int mx(){
        int answ=0;
        for(auto p:size){
            answ = max(answ,p);
        }
        return answ;
    }
};

int main(){
    int n, m, a, b;

    cin >> n >> m;
    DSU alg(n);
    for(int i=0;i<m;i++){
        cin >> a >> b;
        alg._union(a,b);
    }

    cout << alg.mx() << '\n';

    return 0;
}


Measured memory_bytes: 5640
N, M = map(int,input().split())

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)
      
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

uf = UnionFind(N)
for _ in range(M):
  a, b = map(int,input().split())
  uf.union(a-1, b-1)
#print(uf.parents)  
print(uf.group_count() - 1)

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

int main(){
    int n;
    std::cin >> n;
    std::vector<double> a(n);
    double product = 1.0;
    for(int i = 0; i < n; i++){
        std::cin >> a[i];
        product *= a[i];
    }

    double denominator = 0.0;
    for(int i = 0; i < n; i++){
        denominator += product / a[i];
    }
    double res = product / denominator;
    printf("%.6f\n", res);
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1e+9
#define MAX_V 200002

struct edge {
    int to;
};

int V;
vector<edge> G[MAX_V];
int d[MAX_V];
int mark[MAX_V];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        rep(i,G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + 1) {
                d[e.to] = d[v] + 1;
                mark[e.to] = v; 
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    cin >> V;
    int E; cin >> E;
    rep(i,E) {
        int a,b; cin >> a >> b; a--; b--;
        edge ea = {a};
        edge eb = {b};
        G[a].push_back(eb);
        G[b].push_back(ea);
    }
    dijkstra(0);
    rep(i,V) {
        if(d[i] == INF) {
            cout << "No" << endl;
            exit(0);
        }
    }
    cout << "Yes" << endl;
    for(int i = 1; i < V; i++) {
        cout << mark[i]+1 << endl;
    }
}

Measured memory_bytes: 13556
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};

// 二分探索
// llrep(i,N){
//     b = B[i];
//     auto cntA = lower_bound(A.begin(), A.end(), b);//イテレータなのでそのままllに変換とかはできない
//     auto cntC = upper_bound(C.begin(), C.end(), b);
//     ll cntA_ll = distance(A.begin(), cntA);
//     ll cntC_ll = C.size() - distance(C.begin(), cntC);
//     cnt += (cntA_ll * cntC_ll);
// }

bool pairCompare(pair<int, pair<string, int> > a, pair<int, pair<string, int> > b) {
    if (a.second.first != b.second.first){
        return a.second.first < b.second.first;
    }else{
        return a.second.second > b.second.second;
    }
}

vector< pair<int, pair<string, int> > > restaurant;

int main(){
    int N,p;
    string S;
    cin >> N;
    rep(i,N){
        cin >> S >> p;
        restaurant.push_back( make_pair(i, make_pair(S,p) ) );
    }
    sort(restaurant.begin(), restaurant.end(), pairCompare);

    rep(i,N){
        cout << restaurant[i].first + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

using namespace std;

long solve(long N) {
    if (5 > N) return 0;
    else return N / 5 + solve(N / 5);
}

int main() {
    long N; cin >> N;
    if (N % 2 == 1) {
        cout << 0 << endl;
    } else {
        cout << solve(N / 2) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M, V, P = mapint()
As = list(mapint())
As.sort(reverse=True)

threshold = As[P-1]
l, r = P-1, N
while l+1<r:
    half = (l+r)//2
    a = As[half]+M
    if a<threshold:
        r = half
    else:
        rest_sum = 0
        for i in range(P-1, N):
            if As[i]>=a:
                continue
            if i==half:
                continue
            rest_sum += min(M, a-As[i])
        if M*V > rest_sum+P*M:
            r = half
        else:
            l = half
print(l+1)

Measured memory_bytes: 85748
N, Q = map(int, input().split(" "))
points = [0 for _ in range(N+1)]
g = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split(" "))
    g[a].append(b)
for _ in range(Q):
    p, x = map(int, input().split(" "))
    points[p] += x

q = [1]
while q:
    node = q.pop()
    for child in g[node]:
        points[child] += points[node]
        q.append(child)

print(*points[1:])

Measured memory_bytes: 47868
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

#define maxn 100+5

using namespace std;

int mt[maxn][maxn];
int a, b;

int main() {
	scanf("%d%d", &a, &b);
	for (int i = 1; i <= 100; i++) {
		for (int j = 1; j <= 50; j++) mt[i][j] = 1;
		for (int j = 51; j <= 100; j++) mt[i][j] = 2;
	}
	int nowa = 1, nowb = 1;
	int ax = 1, ay = 100;
	int bx = 1, by = 1;
	while (nowa < a) {
		mt[ax][ay] = 1; nowa++;
		ay -= 2;
		if (ay <= 50) ax += 2, ay = 100;
	}
	while (nowb < b) {
		mt[bx][by] = 2; nowb++;
		by += 2;
		if (by > 50) bx += 2, by = 1;
	}
	puts("100 100");
	for (int i = 1; i <= 100; i++,puts(""))
		for (int j = 1; j <= 100; j++) {
			if (mt[i][j] == 1) printf(".");
			else printf("#");
		}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
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; }
const long long INF = 1LL << 60;
const int inf = 1001001001;

int main() {
    ll n,l,sayuri=INF,sum=0;
    cin >> n >> l;
    vector<ll> data(n);
    rep(i,n){
        data.at(i)=l+i;
        sayuri=min(sayuri,abs(data.at(i)));
        sum+=data.at(i);
    }
    rep(i,n){
        if(sayuri==data.at(i)){
            sum-=data.at(i);
            break;
        }
        else if(sayuri==-data.at(i)){
            sum-=data.at(i);
            break;
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;
    
    public static void main(String[] args) {
        int a = ni();
        int p = ni();
        so.println((a*3+p)/2);
    }

    
    private static int ni() {
        return sc.nextInt();
    }

    private static long nl() {
        return sc.nextLong();
    }

    private static String ns() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0);
    }

    private static long[] nlongs(int n, int padding) {
        long[] a = new long[padding + n];
        for (int i = 0; i < n; i++)
            a[padding + i] = ni();
        return a;
    }
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1'000'000'000'000'007ll;
const llong mod = 1e9+7;

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

	cout << N*(N-1)/2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    double d, t, s, dis;
    scanf("%lf%lf%lf",&d,&t,&s);
    dis=s*t;
    if(dis<d)
    {
        printf("No\n");
    }
    else {
        printf("Yes\n");
    }

}

Measured memory_bytes: 1696
n,a,b,c = map(int,input().split())
nu = [a,b,c]
ans = [[[0,0],[0,0],[0,0],[0,0]] for i in range(4 ** n)]
lis = [int(input()) for i in range(n)]
def to4(n):
    if int(n//4):
        return to4(n//4) + str(n%4)
    return str(n%4)
for i in range(4 ** n):
    s = to4(i).zfill(n)
    for j in range(n):
        ans[i][int(s[j])][0] += lis[j]
        ans[i][int(s[j])][1] += 1
an = 10 ** 18
for i in range(4 ** n):
    if ans[i][0][1] != 0 and ans[i][1][1] != 0 and ans[i][2][1] != 0:
        a = 0
        for num in range(3):
            a += abs(ans[i][num][0] -nu[num])
            a += max(0,ans[i][num][1]-1) * 10
        an = min(an,a)
print(an)

Measured memory_bytes: 43000
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std ;
using namespace __gnu_pbds;

#define ll long long
#define ull unsigned long long
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define rep(i , a , b) for(int i = (a) ; i < (b) ; ++i)
#define repp(i , a , b) for(int i = (a) ; i >= b ; --i)
#define each(x , a) for(auto &x : a)
#define len(x)  (int)x.size()
#define all(x)  (x).begin() ,(x).end()
#define mem(x , a) memset(x , a , sizeof(x))
#define vi vector<int>
#define vl vector<LL>
#define pii pair<int,int>
#define Pll pair<LL,LL>
#define io ios::sync_with_stdio(0) ; cin.tie(0);

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

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds ;

string to_string(string s) {
	return '"' + s + '"';
}
string to_string(const char *s) {
	return to_string((string)s);
}
string to_string(bool b) {
	return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(x...) ;
#endif

const int N = 1000010 ;
vi div_cnt(N) ;

void solve() {
	int n ;
	cin >> n ;
	vi arr(n) ;
	rep(i , 0,  n)
	cin >> arr[i] ;
	bool ok = true ;
	each(x , arr) {
		for (int i = 1 ; i * i < x ; ++i ) {
			if (x % i == 0) {
				div_cnt[i]++ ;
				if (i * i != x) {
					div_cnt[x / i]++;
				}
				if (i != 1 && div_cnt[i] > 1) {
					ok = false;
					break ;
				} else if ((x / i) != 1 && div_cnt[x / i] > 1) {
					ok = false;
					break ;
				}
			}
			if (!ok)
				break ;
		}
	}
	if (ok) {
		cout << "pairwise coprime" << "\n" ;
		return ;
	}
	int g = 0 ;
	rep(i , 0 , n)
	g = __gcd(arr[i] , g) ;
	if (g == 1) {
		cout << "setwise coprime" << "\n" ;
		return ;
	}
	cout << "not coprime" << "\n" ;

}
int main() {
	io;
	//freopen("in.txt" ,"r" , stdin) ;
	solve() ;
}

Measured memory_bytes: 11064
#include<iostream>
using namespace std;
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<utility>

typedef pair<double, double> point;
typedef point* data;

double dist(const point &p1, const point &p2)
{
    double dx = p1.first - p2.first;
    double dy = p1.second - p2.second;
    return sqrt(dx * dx + dy * dy);
}

bool sort_y(const point &p1, const point &p2){ return p1.second < p2.second; }

double closest(data X, data Y, int n)
{
    if(n <= 3){
        double d = dist(X[0], X[1]);
        for(int i = 0; i < n; i++){ Y[i] = X[i]; }
        sort(Y, Y + n, sort_y);  // sort. (n <= 3)
 
        if(n < 3){ return d; }
        return min(d, min(dist(X[0], X[2]), dist(X[1], X[2])));
    }
    int m = (n >> 1);
    double median = X[m].first;
    double d = min(closest(X, Y, m), closest(X + m, Y + m, n - m));
 
    data Z; int size = 0;
    Z = new point [n]; // merge_sort. (n > 3)
    int i = 0, j = m;
    while(1){
        if(i < m && j < n){
            if(Y[i].second < Y[j].second){
                Z[size] = Y[i]; size++; i++;
            }else{
                Z[size] = Y[j]; size++; j++;
            }
        }
        if(i == m){ while(j < n){ Z[size] = Y[j]; size++; j++; }; break; }
        if(j == n){ while(i < m){ Z[size] = Y[i]; size++; i++; }; break; }
    };

    for(i = 0; i < n; i++){ Y[i] = Z[i]; } // merge.

    int resize = 0;
    for(i = 0; i < size; i++){
        if(fabs(Z[i].first - median) <= d){ Z[resize] = Z[i]; resize++; }
    }

    int a = 0;
    for(i = 1; i < resize; i++){
        for(j = a; j < i; j++){
            if(Z[i].second - Z[j].second > d){ a++; }
            else{
                d = min(d, dist(Z[i], Z[j]));
            }
        }
    }
    delete [] Z;
    return d;
}

int main()
{
    data X, Y;
    int i, n;
    scanf("%d", &n);
    X = new point [n];
    Y = new point [n];

    double co_x, co_y;
    for(i = 0; i < n; i++){
        scanf("%lf %lf", &co_x, &co_y);
        X[i] = make_pair(co_x, co_y);
    }
    sort(X, X + n);

    printf("%.12f\n", closest(X, Y, n));

    delete [] X;
    delete [] Y;

    return 0;
}

Measured memory_bytes: 6524
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  ll sum = 0;
  rep(i,N+1)
  {
    if(i%3==0||i%5==0)
    {
      continue;
    }
    sum += i;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3556
# abc163_b.py
# https://atcoder.jp/contests/abc163/tasks/abc163_b

# B - Homework /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# 高橋君の夏休みは N日間です。
# 夏休みの宿題が M個出されており、i 番目の宿題をやるには Ai日間かかります。
# 複数の宿題を同じ日にやることはできず、また、宿題をやる日には遊ぶことができません。
# 夏休み中に全ての宿題を終わらせるとき、最大何日間遊ぶことができますか？
# ただし、夏休み中に全ての宿題を終わらせることができないときは、かわりに -1 を出力してください。

# 制約
#     1≤N≤106
#     1≤M≤104
#     1≤Ai≤104

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N M
# A1 ... AM

# 出力
# 高橋君が遊ぶことのできる日数、または、-1 を出力せよ。

# 入力例 1
# 41 2
# 5 6

# 出力例 1
# 30

# 例えば、最初の 5日間で 1 番目の宿題をやり、その後 30 日間遊んで、最後の 6 日間で 2 番目の宿題をやることで、30日間遊ぶことができます。

# 入力例 2
# 10 2
# 5 6

# 出力例 2
# -1

# 宿題を終わらせることができません。

# 入力例 3
# 11 2
# 5 6

# 出力例 3
# 0

# 宿題を終わらせることはできますが、遊ぶことはできません。

# 入力例 4
# 314 15
# 9 26 5 35 8 9 79 3 23 8 46 2 6 43 3

# 出力例 4
# 9


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    N, M = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = max(N - sum(values), -1)

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['41 2', '5 6']
        lines_export = [30]
    if pattern == 2:
        lines_input = ['10 2', '5 6']
        lines_export = [-1]
    if pattern == 3:
        lines_input = ['11 2', '5 6']
        lines_export = [0]
    if pattern == 4:
        lines_input = ['314 15', '9 26 5 35 8 9 79 3 23 8 46 2 6 43 3']
        lines_export = [9]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


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

int h, w;
vector<string> ma; //二次元配列ではなく文字列のベクトル


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

int main() {
    cin >> h >> w;
    ma.resize(h); //ベクトルのサイズを変更
    rep(i,h) cin >> ma[i];

    // 多点をスタートとして扱う
    vector<vector<int> > dist(h, vector<int>(w, -1)); //一番近い黒からの距離,-1で初期化
    queue<P> que;
    rep(i,h){
        rep(j,w){
            if (ma[i][j] == '#') {
                dist[i][j] = 0; 
                que.push(P(i, j)); //まずすべての黒の位置をキューに入れておく。これで多点スタート
            }
        }
    }

    while (!que.empty()) {
        auto cur = que.front(); //別にintでもよい
        que.pop();
        for (int i = 0; i < 4; i++) {
            int ny = cur.first + dy[i];
            int nx = cur.second + dx[i];
            if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
            if (dist[ny][nx] == -1) {
                dist[ny][nx] = dist[cur.first][cur.second] + 1;
                que.push(P(ny, nx));
            }
        }
    }
    int res = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            res = max(res, dist[i][j]);
        }
    }
    cout << res << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int mod = 1000000007;
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
        sum %= mod;
    }

    long ans = 0;

    //i について全探索する
    for (int i = 0; i < N; i++)
    {
        //A[i+1] ... A[N] の値を更新する
        sum -= A[i];
        if (sum < 0) sum += mod;

        ans += A[i] * sum;
        ans %= mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
 
/// Typedef
typedef long long           ll;
typedef unsigned long       ul;
typedef unsigned long long  ull;
typedef vector<int>         vi;
typedef vector<vi>          vvi;
typedef vector<ll>          vll;
typedef pair<int,int>       pii;
typedef pair<ll,ll>         pll;
 
#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define SQR(x)              ((x)*(x))
#define loop(i, y)          for(int i=0; i<int(y); i++)
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x); i>=int(y); i--)
#define all(c)              c.begin(), c.end()
#define sz(c)               int(c.size())
#define clr(x, y)           memset(x, y, sizeof(x))
#define si(x)               scanf("%d", &x)
#define sii(x, y)           scanf("%d %d", &x, &y)
#define siii(x, y, z)       scanf("%d %d %d", &x, &y, &z)
#define sl(x)               scanf("%lld", &x)
#define sll(x, y)           scanf("%lld %lld", &x, &y)
#define slll(x, y, z)       scanf("%lld %lld %lld", &x, &y, &z)
#ifdef VAMP
     #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define dbg(...)
#endif
/// Constants
#define N                   111
#define MOD                 1000000007
#define base                1000000007
#define eps                 1e-9
#define INF                 1llu<<61    // 2,305,843,009,213,693,952
#define inf                 (ll)1e18     // 536,870,912
#define PI                  acos(-1.0)  // 3.1415926535897932
// #define INF              0x3f3f3f3f3f3f3f3f
// #define inf              0x3f3f3f3f
#define U  0
#define L  1
#define D  2
#define R  3

int main(){
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("C:\\Users\\raiha.DESKTOP-5M3GJRN\\Videos\\Raihan\\input.txt", "r", stdin);
        freopen("C:\\Users\\raiha.DESKTOP-5M3GJRN\\Videos\\Raihan\\output.txt", "w", stdout);
    #endif
    int n;
    si(n);string str;
    cin>>str; 
    if(n&1)puts("No");
    else{
        string tmp  = str.substr(0,n/2);
        string tmp1 = str.substr(n/2,n);
        if(tmp==tmp1)puts("Yes");
        else puts("No"); 
    }
    #ifdef VAMP
       printf("\n>>Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
    return 0;
}

Measured memory_bytes: 384
H, W = map(int,input().split())
N = int(input())
A = list(map(int,input().split()))

MAP = [[0 for i in range(W)] for j in range(H)]

h = 0
w = 0
num = 1

for i in range(N):
    while A[i] > 0:
        MAP[h][w] = num
        A[i] -= 1
        if h % 2 == 0:
            if w == W - 1:
                h += 1
            else:
                w += 1
        else:
            if w == 0:
                h += 1
            else:
                w -= 1
    num += 1

for i in range(H):
    print(*MAP[i])

Measured memory_bytes: 9336
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<vector>
#include<algorithm>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i32 n;
cin >> n;
vector<P> a(n);
rep(i,n){
    i32 x,y;
    cin >> x >> y;
    a[i].first = x - y;
    a[i].second = x + y;
}
sort(all(a));
i64 ans;
ans = abs(a.back().first - a[0].first);
rep(i,n)swap(a[i].first,a[i].second);
sort(all(a));
ans = max(ans,abs(a.back().first - a.front().first));
cout << ans << endl;
}

Measured memory_bytes: 6328
S = input()
N = len(S) - 1
n = int(N / 2)

for i in range(0, n):
  if S[i] != S[N - i]:
    print('No')
    exit()
  if i < n // 2:
    if S[i] != S[int((N / 2) - 1) - i]:
      print('No')
      exit()
    if S[int((N + 4) / 2) - 1 + i] != S[N - i]:
      print('No')
      exit()
print('Yes')

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <iostream>
#include <string>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <queue>
#include <deque>
#include <math.h>
#include <cmath>
#include <stack>
#include <algorithm>
#include <list>
#include <array>
#include <valarray>
#include <unordered_map>
#include <cassert>
#include <random>
#include <cstring>
#include <bitset>

using namespace std;

typedef long double ld;
typedef long long li;
typedef vector<li> vec;
typedef vector<vector<li>> mt;
typedef pair<int, int> pii;

#define X first
#define Y second
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(a) int(a.size())

const double PI = 3.14159265358979323846;
const double EPS = 1e-15;
const int INF = 1e9 + 7;
const li LINF = 8e18 + 7;


int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);


	int n;
	cin >> n;

	int x;
	cin >> x;

	vector<int> a(n);
	forn(i, n) {
		cin >> a[i];
	}

	sort(all(a));

	int ans = 0;
	forn(i, n) {
		if (a[i] <= x) {
			x -= a[i];
			ans++;
		}
		else {
			x = 0;
			break;
		}
	}

	if (x) {
		ans--;
	}

	cout << ans << endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
using namespace std;

int main() {
    int n, k, tmp;
    scan2Int(n, k);
    vector<int> ps(n);
    rep(i, n) {
        scanInt(tmp);
        ps[i] = tmp;
    }
    sort(ps.begin(), ps.end());
    int ans = 0;
    rep(i, k) ans += ps[i];
    printInt(ans);
    return 0;
}


Measured memory_bytes: 3728
#include<stdio.h>
#define MAX_N 200000
int par[MAX_N];
int original_par[MAX_N];
int rank[MAX_N];
int query_list[MAX_N][2];

void init(int n){
  int i;
  for(i=0;i<n;i++){
    par[i] = i;
    rank[i] = 0;
  }
}
int find(int x){
  if(par[x]==x){
    return x;
  }else {
    return par[x] = find(par[x]);
  }
}
void unite(int x,int y){
 // x =find(x);
//  y =find(y);
  if(x==y){
    return ;
  }
  par[y] = x;
  /*
  if(rank[x] < rank[y]){
    par[x] = y;
  }else {
    par[y] = x;
    if(rank[x] == rank[y])rank[x]++;
  }
  */
}
int same(int x,int y){
  return find(x)==find(y);
}
int main(){
  int N,Q;
  long long int ans;
  int i,j,k;
  int marked_list[MAX_N];
//??¨??¨????????§?????????????????§1?????¬???
  while(1){
    scanf("%d %d",&N,&Q);
    if(N==0&&Q==0)break;
    for(i=0;i<N;i++){
      marked_list[i]=0;
    }marked_list[0]=1;
    original_par[0]=0;
    ans=0;

    for(i=1;i<N;i++){
      scanf("%d\n",&original_par[i]);
      original_par[i]--;
    }
    for(i=0;i<Q;i++){
      char bc;
      scanf("%c %d\n",&bc,&query_list[i][1]);
      query_list[i][0] = bc;
      query_list[i][1]--;
    }

    init(N);
    for(i=0;i<Q;i++){
      if(query_list[i][0]=='M'){
				if(marked_list[query_list[i][1]]==1){
					query_list[i][0]='N';
				}
        marked_list[query_list[i][1]]=1;
      }
    }
    for(i=0;i<N;i++){
      if(0==marked_list[i]){
        unite(original_par[i],i);
      }
    }
    for(i=Q-1;i>=0;i--){
      if(query_list[i][0]=='Q'){
        int q_a = find(query_list[i][1])+1;
        ans += q_a;
      //  printf(":%d\n",ans);
      }else if(query_list[i][0]=='M'){
        int m = query_list[i][1];
        unite(original_par[m],m);
      }
    }
    printf("%lld\n",ans);
  }
  return 0;

}

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

links = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    links[u - 1].append((v - 1, w))
    links[v - 1].append((u - 1, w))

distance = [-1] * N
distance[0] = 0
q = [0]
while q:
    p = q.pop()
    for n, w in links[p]:
        if distance[n] == -1:
            distance[n] = distance[p] + w
            q.append(n)

for i in distance:
    print(i % 2)


Measured memory_bytes: 70816
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<climits>
#include<bitset>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long long
#define mod 1000000007
using namespace std;
inline int read(){
    int f=1,ans=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
    return f*ans;
}
const int MAXN=1e6+11;
int f[MAXN],N;
signed main(){
    N=read();f[N]=N,f[N-1]=N*N,f[N-1]%=mod;int s=0;
    for(int i=N-2;i>=1;i--){
        s+=f[i+3];s%=mod;
        f[i]+=f[i+1],f[i]%=mod;
        f[i]+=s+(N-1)*(N-1)+i+1,f[i]%=mod;
    }printf("%lld\n",f[1]);return 0;
}


Measured memory_bytes: 10944
/** "Ever tried.
         Ever failed.
               No matter.
                   Try Again.
                        Fail again.
                             Fail better.**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define bp  __builtin_popcount
#define endl "\n"
#define oo 0x3f3f3f3f3f3f3f3fLL
#define pb push_back
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define sz(s) (int)(s.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define setdp memset(dp,-1,sizeof(dp))
#define db(x) cout<<" LOOK "<<(#x)<<" = "<<x <<'\n'
#define NumofDigits(n)   ((long long)log10(n)+1)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e5+5;
const  double EPS = 1e-9;
const int MOD = 1e9+7;
/*
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll fastpow(ll b, ll p)
{if(!p)return 1;ll ret = fastpow(b, p >> 1);ret *= ret;if(p&1)ret*= b;return ret;}
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};*/
inline void File()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}
int dp[maxn];
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    //File();
    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    dp[0]=0;
    for(int i=1; i<n; i++)
    {
        if(s[i-1] == 'A' and s[i] == 'C')
            dp[i] = dp[i-1] + 1;
        else
            dp[i] = dp[i-1];
    }
    while(q--)
    {
        int x,y;
        cin>>x>>y;
        x--,y--;
        cout<<dp[y]-dp[x]<<endl;
    }
}


Measured memory_bytes: 4168
(N, Q) = map(int, input().split())
s = input()

from_first = [0 for _ in range(N)]


def count_from_first(l, r):
    return from_first[r] - from_first[l]


for i in range(1, N):
    if s[i-1] == "A" and s[i] == "C":
        from_first[i] = (1 + from_first[i - 1])
    else:
        from_first[i] = from_first[i-1]

for i in range(Q):
    l, r = list(map(int, input().split()))
    print(count_from_first(l-1, r-1))


Measured memory_bytes: 6196
import heapq

N, M = map(int,input().split())
ab_list = [list(map(int,input().split())) for _ in range(N)]

d = {}
for a,b in ab_list:
    if a in d:
        d[a].append(-b)
    else:
        d[a] = [-b]

b_list = []
heapq.heapify(b_list)
reward = 0
for i in range(1,M+1):
    if i in d:
        for b in d[i]:
            heapq.heappush(b_list,b)
    if len(b_list) > 0:
        reward += -(heapq.heappop(b_list))

print(reward)

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

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for i, a in enumerate(A):
    ans += B[a-1]
    if i != 0 and a == A[i-1] +1:
        ans += C[a-2]

print(ans)


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

string gsub(string str, const string& pat, const string& sub)
{
  for (string::size_type i = 0; i < str.size();) {
    const string::size_type p = str.find(pat, i);
    if (p == string::npos) {
      break;
    }
    str.replace(p, pat.size(), sub);
    i = p + sub.size();
  }
  return str;
}

set<string> visited;
vector<pair<string,string> > subs;
string target;
int ans;
void dfs(const string& str, int depth)
{
  if (str == target) {
    ans = min(ans, depth);
    return;
  }
  if (str.size() >= target.size() || visited.count(str)) {
    return;
  }
  visited.insert(str);
  for (vector<pair<string,string> >::const_iterator it = subs.begin(); it != subs.end(); ++it) {
    dfs(gsub(str, it->first, it->second), depth+1);
  }
}

int main()
{
  int N;
  while (cin >> N && N != 0) {
    subs.resize(N);
    for (int i = 0; i < N; i++) {
      cin >> subs[i].first >> subs[i].second;
    }
    string str;
    cin >> str >> target;

    static const int INF = 10000;
    visited.clear();
    ans = INF;
    dfs(str, 0);
    cout << (ans == INF ? -1 : ans) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int ArrayA[80][80];
int ArrayB[80][80];
bool table[81][81][12800];
int main(){
    int h,w;
    cin >> h >> w;
    rep(i,81){
        rep(j,81){
            rep(k,12800){
                table[i][j][k] = false;
            }
        }
    }
    rep(i,h){
        rep(j,w){
            cin >> ArrayA[i][j];
        }
    }
    rep(i,h){
        rep(j,w){
            cin >> ArrayB[i][j];
        }
    }

    table[0][0][abs(ArrayA[0][0]-ArrayB[0][0])] = true;
    table[0][0][abs(ArrayB[0][0]-ArrayA[0][0])] = true;

    rep(i,h){
        rep(j,w){
            rep(k,12800){
                if(table[i][j][k]){
                    table[i+1][j][k + abs(ArrayA[i+1][j] - ArrayB[i+1][j])] = true;
                    table[i+1][j][abs(k - abs(ArrayA[i+1][j] - ArrayB[i+1][j]))] = true;

                    table[i][j+1][k + abs(ArrayA[i][j+1] - ArrayB[i][j+1])] = true;
                    table[i][j+1][abs(k - abs(ArrayA[i][j+1] - ArrayB[i][j+1]))] = true;
                }
            }
        }
    }

    rep(k,12800){
        if(table[h-1][w-1][k]){
            cout << k << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 82304
N=int(input())
points1=0
points2=0
for i in range(N):
    card1,card2=input().split()
    if card1==card2:
        points1+=1
        points2+=1
        continue
    M=min(len(card1),len(card2))
    c=""
    d=""
    for j in range(M):
        c+=card1[j]
        d+=card2[j]
    if c==d and len(card1)>len(card2):
        points1+=3
        continue
    elif c==d and len(card1)<len(card2):
        points2+=3
        continue
    for j in range(M):
        a=card1[j]
        b=card2[j]
        if a>b:
            points1+=3
            break
        elif a<b:
            points2+=3
            break
        elif a==b:
            continue
print(points1,points2)



Measured memory_bytes: 5604
#include<cstdio>
using namespace std;

int n,x,a[200005];

int main()
{
	scanf("%d",&n);
	for (int i=1 ; i<n ; i++)
	{
		scanf("%d",&x);
		a[x]++;
	}
	for (int i=1 ; i<=n ; i++)
	{
		printf("%d\n",a[i]);
	}
	
	return 0;
}

Measured memory_bytes: 2488
package main

import "fmt"

func main() {
	var h, w, a, b int
	fmt.Scan(&h, &w, &a, &b)

	for i := 0; i < h; i++ {
		for j := 0; j < a; j++ {
			if i < b {
				fmt.Print(0)
			} else {
				fmt.Print(1)
			}
		}
		for j := a; j < w; j++ {
			if i < b {
				fmt.Print(1)
			} else {
				fmt.Print(0)
			}
		}
		fmt.Println()
	}
}


Measured memory_bytes: 6528
N, A, B = list(map(int, input().split()))

def findSum(n):
    sum_total = 0
    while n > 0:
        sum_total += int(n % 10)
        n = int(n /10)
    return int(sum_total)

total = 0
for i in range(1, N + 1):
    sum_total = findSum(i)
    if sum_total >= A and sum_total <= B:
        total += i

print(total)

Measured memory_bytes: 40304
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string s;
	cin >> s;
	int l = s.size();
	int cnt = 0, res = 0;
	for (int i = 0; i < l; i++) {
		if (s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G') {
			cnt++;
			res = max(cnt, res);
		}
		else cnt = 0;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
        public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
          
          int N =sc.nextInt();
          long sum=0;
            
          for(int i=1; i<=N; i++){        
             if(i%3!=0&&i%5!=0){   
               sum+=i;
             }
          }
             System.out.println(sum);
          
        }
}
        

Measured memory_bytes: 35592
#include<stdio.h>
long long d[100010][2];
int ta[100010],to[200010],nt[200010],M=1e9+7,u[100010];
void f(int s){
  d[s][0]=d[s][1]=1;
  u[s]=1;
  int i;
  for(i=ta[s];i+1;i=nt[i]){
    if(u[to[i]])continue;
    f(to[i]);
    d[s][0]=(d[s][0]*(d[to[i]][0]+d[to[i]][1])%M)%M;
    d[s][1]=(d[s][1]* d[to[i]][0]               )%M;
  }//printf("%d %lld %lld\n",s,d[s][0],d[s][1]);
  return ;
}
int main(){
  int n,a,b,i;
  scanf("%d",&n);
  for(i=0;i<n;i++)ta[i+1]=-1;
  for(i=0;i<n-1;i++){
    scanf("%d %d",&a,&b);
    nt[i]=ta[to[i+n-1]=a];
    ta[a]=i;
    nt[i+n-1]=ta[to[i]=b];
    ta[b]=i+n-1;
  }
  f(1);
  printf("%lld\n",(d[1][0]+d[1][1])%M);
  return 0;
}


Measured memory_bytes: 6784