akhauriyash/Code-Regression huggingface dataset:
/*
....................../´¯/)
....................,/¯../
.................../..../
............./´¯/'...'/´¯¯`·¸
........../'/.../..../......./¨¯\
........('(...´...´.... ¯~/'...')
.........\.................'...../
..........''...\.......... _.·´
............\..............(
..............\.............\...
*/


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define ye cout<<"YES";
#define no cout<<"NO";
#define ln cout<<"\n";
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define pi 3.14159265358979323846
// cout<<"Case #"<<ts<<": “;
//priority_queue < pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;


using namespace std;

ll mod(ll x, ll m) {
	return (x % m + m) % m;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll t = 1, r, n, a, d, c, b, x, y, sum, cnt, i, j, k, m, l, q, maxx, minn, temp, ans, flag, g, ts;
	ll mod = 1000000007;
	char ch, chh;
	double dans;
	string str, ttr;

	//cin >> t;


	for (ts = 1; ts <= t; ts++)
	{
		flag = 0; sum = 0; cnt = 0; ans = 0; k = 0; maxx = 0; minn = 0; a = 0; b = 0; temp = 0;

		cin >> n;

		ll arr[n];

		for (i = 0; i < n; i++)
			cin >> arr[i];

		sort(arr, arr + n);

		for (i = 0; i < n; i++)
		{
			for (j = i + 1; j < n; j++)
			{
				for (k = j + 1; k < n; k++)
				{
					a = arr[i];
					b = arr[j];
					c = arr[k];

					if (a != b && a != c && b != c)
					{
						if (a + b > c)
							ans++;
					}

				}
			}
		}

		cout << ans;



		ln
	}
	return 0;
}


Measured memory_bytes: 3648
void main() {
    int[] abc = readln.split.to!(int[]);
    writeln(abc.sum - abc.reduce!max);
}

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

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

int main() {
    long long int N, Sum;
    cin >> N;

    Sum = 0;
    for(int i=0; i <= N; i++){
        if ((i % 3 != 0) && (i % 5 != 0)){
            Sum += i;
        }
    }
    cout << Sum << endl;
    return 0;
}

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

using namespace std;
struct UnionFind{
      vector<int> par;
      
      UnionFind(int N):par(N){
            for(int i = 0;i < N;i++){
                  par[i] = i;
            }
      }
      int root(int x){
            if(x == par[x]){
                  return x;
            }
            return par[x] = root(par[x]);
      }
      
      void unite(int x,int y){
            int rx = root(x);
            int ry = root(y);
            if(rx == ry)return;
            par[rx] = ry;
      }
      bool same(int x,int y){
            return root(x) == root(y);
      }
};

int main(void){
    int n,m;
    cin >> n >> m;
    UnionFind UT(n);
    for(int i = 0;i < m;i++){
          int a,b;
          cin >> a >> b;
          a--;b--;
          UT.unite(a,b);
    }
    int ans = 0;
    for(int i = 0;i < n;i++){
          if(!UT.same(0,i)){
                ans++;
                UT.unite(0,i);
          }
    }
    cout << ans << endl;
}


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

int main() {
    int N; 
    cin >> N;
    int d[110];
    for (int i = 0; i < N; ++i) cin >> d[i];
    set<int> a; 
    for (int i = 0; i < N; ++i) {
        a.insert(d[i]); 
    }
    cout << a.size() << endl;
}           

Measured memory_bytes: 256
#include <stdio.h>
int n,k,q;
int a[100010];
int main(){
	scanf("%d %d %d",&n,&k,&q);
	for(int i=1;i<=q;i++){
		int x;
		scanf("%d",&x);
		a[x]++;
	}
	for(int i=1;i<=n;i++){
		if(k-q+a[i]>0) printf("Yes\n");
		else printf("No\n");
	}
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1000005;

int A,B,m,a[N],b[N],c[N],ans=1e18;

signed main() {
    ios::sync_with_stdio(false);
    cin>>A>>B>>m;
    for(int i=1;i<=A;i++) cin>>a[i];
    for(int i=1;i<=B;i++) cin>>b[i];
    for(int i=1;i<=m;i++) {
        int t1,t2,t3;
        cin>>t1>>t2>>t3;
        ans=min(ans,a[t1]+b[t2]-t3);
    }
    ans=min(ans,*min_element(a+1,a+A+1)+*min_element(b+1,b+B+1));
    cout<<ans;
}


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

int gcd(int a, int b, int c){
    int r, temp;
    if(a<b){
        temp = a;
        a = b;
        b = temp;
    }

    // Euclidean Algorithm 
    r = a%b;
    while(r != 0){
        a = b;
        b = r;
        r = a%b;
    }

	if(c<b){
        temp = c;
        c = b;
        b = temp;
    }

    // Euclidean Algorithm 
    r = c%b;
    while(r != 0){
        c = b;
        b = r;
        r = c%b;
    }
    return b;
}


int main(void){
	int n;
	scanf("%d",&n);
	long long sigma=0;
	int i, j, k;
	int a;
	for(i=1;i<=n;i++){
		for(j=i;j<=n;j++){
			for(k=j;k<=n;k++){
				if(i==j&&j==k){
					a = 1;
				}
				else if(i!=j && j!=k && k!=i){
					a = 6;
				}
				else{
					a = 3;
				}
				sigma += a*gcd(i,j,k);
//				printf("%lld\n",sigma);
			}
		}
	} 
	printf("%lld\n",sigma);
    return 0; 
}


Measured memory_bytes: 1736
#include<iostream>
#include<algorithm> 
#include<cmath>
#include<vector>
#include<string>
using namespace std;

int main() {
    int a,b,c;
    int x,y;
    cin>>a>>b>>c;
    cin>>x>>y;
    int n=min(x,y);
    int sum=0;
    if(c*2<=a+b) sum+=n*2*c;
    else sum+=n*(a+b);
    if(x-n){
    	n=x-n;
    	if(c*2<a) sum+=n*c*2;
    	else sum+=n*a;
	}
	else{
		n=y-n;
		if(c*2<b) sum+=n*c*2;
		else sum+=n*b;
	}
	cout<<sum;
	
	return 0;
}

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

int main(){
  int q,i,j,a;
  int l[100004],r[100004];
  int ll,rr;
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d %d",&l[i],&r[i]);
  }
  int x[300004];
  x[0]=1;
  x[1]=1;
  for(i=2;i<=300002;i++){
    if(x[i]==0){
      for(j=2*i;i<=300002-j;j+=i){
        x[j]=1;
      }
    }
  }
  int y[100004];
  y[0]=0;
  for(i=1;i<100004;i++){
    if((x[2*i-1]==0)&&(x[i]==0)){
      y[i]=1;
    }
  }
  for(i=1;i<100004;i++){
    y[i]+=y[i-1];
  }
  for(i=0;i<q;i++){
    ll=(l[i]+1)/2-1;
    rr=(r[i]+1)/2;
    a=y[rr]-y[ll];
    printf("%d\n",a);
  }
  return 0;
}


Measured memory_bytes: 2944
function Main(x) {
    if (x >99 || x <1000) {
        let _n = [];
let n = x.toString();
        _n[0] = n.charAt(0);
        _n[1] = n.charAt(1);
        _n[2] = n.charAt(2);
        const a = _n.filter(_a => _a === '7');
        if(a.length < 1){
            console.log('No');
        } else {
            console.log('Yes');
        }
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;


string S,T;

bool ok[2000020];
int num[2000020];

int m;

int dfs(int now,int d){
    if(num[now]>0) return num[now];
    if(d>m){
        cout<<-1<<endl;
        exit(0);
    }
    if(ok[now]==false) return 0;

    int nex=(now+T.size())%m;
    int res=dfs(nex,d+1)+1;
    return num[now]=res;
}

//size of longest common prefix between s and s[i,n-1]
vector<int> Zalgorithm(const string &s){
    int n=s.size();
    vector<int> z(n,0);
    int L=0,R=0;
    for(int i=1;i<n;i++){
        if(R<i){
            L=i;R=i;
            while(R<n&&s[R-L]==s[R]) R++;
            R--;
            z[i]=R-L+1;
        }else{
            int k=i-L;
            if(z[k]<R-i+1) z[i]=z[k];
            else{
                L=i;
                while(R<n&&s[R-L]==s[R]) R++;
                R--;
                z[i]=R-L+1;
            }
        }
    }

    z[0]=0;
    return z;
}

int main(){
  cin>>S;
  cin>>T;

  string A=S;
  while(A.size()<T.size()) A+=S;


  m=A.size();
  A+=A;

  string X=T+"#"+A;
  vector<int> z=Zalgorithm(X);

  int t=T.size();
  for(int i=0;i<m;i++){
      if(z[t+i+1]==t){
          ok[i]=true;
      }
  }

  int ans=0;

  for(int i=0;i<m;i++){
      ans=max(ans,dfs(i,1));
  }

  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 34228
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main() {
    int x, y;
    cin >> x >> y;
    vector<int> group1 = {1, 3, 5, 7, 8, 10, 12};
    vector<int> group2 = {4, 6, 9, 11};
    vector<int> group3 = {2};
    int label1, label2;
    for(int a : group1){
        if(x == a) label1=1;
        if(y == a) label2=1;
    }
    for(int a : group2){
        if(x == a) label1=2;
        if(y == a) label2=2;
    }
    for(int a : group3){
        if(x == a) label1=3;
        if(y == a) label2=3;
    }
    if(label1 == label2) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
 
#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<(b))
using namespace std;
int t, h, w, n;
char town[32][32], cmd[128];
 
void shot(int y, int x){
   int dx[] = {0,0,-1,1}, dy[] = {-1,1,0,0}; // U D L R
  int d;
  switch(town[y][x]){
  case '^': d = 0; break;
  case 'v': d = 1; break;
  case '<': d = 2; break;
  case '>': d = 3; break;
  }
  //  printf("%d\n", d);
  while(true){
    if(between(0,y+dy[d], h) && between(0, x+dx[d], w)){
      y+=dy[d]; x+=dx[d];
      if(town[y][x] == '*'){
    town[y][x] = '.';
    break;
      }else if(town[y][x] == '#'){
    break;
      }
    }else break;
  }
  return;
}
 
int main(){
  scanf("%d", &t);
  bool f = false;
  while(t--){
    scanf("%d%d", &h, &w);
    rep(i, h) scanf("%s", town[i]);
  
    scanf("%d", &n);
    scanf("%s", cmd);
    int x, y;
    rep(i, h) rep(j, w) 
      if(town[i][j]=='^' || town[i][j]=='v' || town[i][j]=='<' || town[i][j]=='>')x=j,y=i;
    rep(i, n){
      //      printf("%d %d\n", y, x);
      switch(cmd[i]){
      case 'U':
    if(y-1 >= 0 && town[y-1][x] == '.'){ town[y][x] = '.'; town[--y][x] = '^';}
    else town[y][x] = '^';
    break;
       case 'D':
    if(y+1 < h && town[y+1][x] == '.'){ town[y][x] = '.'; town[++y][x] = 'v';}
    else town[y][x] = 'v';
    break;
      case 'L':
    if(x-1 >= 0 && town[y][x-1] == '.'){ town[y][x] = '.'; town[y][--x] = '<';}
    else town[y][x] = '<';
    break;
      case 'R':
    if(x+1 < w && town[y][x+1] == '.'){ town[y][x] = '.'; town[y][++x] = '>';}
    else town[y][x] = '>';
    break;
      case 'S':
    shot(y, x);
    break;
      }
    }      
    if(f) puts("");
    rep(i, h){
      rep(j, w) printf("%c", town[i][j]);
      puts("");
    }
     
    f = 1;
  }
  return 0;
}


Measured memory_bytes: 3124
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()

q = deque(list(range(1, 10)))

for i in range(K):
	n = q.popleft()
	r = n%10
	if r != 0:
		q.append(10*n+(r-1))
	q.append(10*n+r)
	if r != 9:
		q.append(10*n+(r+1))

print(n)

Measured memory_bytes: 20956
// C - Traveling Plan
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

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

	vi A(N+2);
	vi dist(N+2);
	int all_dist = 0;
	rp(i,1,N+1){
		cin>>A[i];
		dist[i] = abs(A[i-1]-A[i]);
		all_dist += abs(A[i-1]-A[i]);
	}
	dist[N+1] = abs(A[N]-A[0]);
	all_dist += abs(A[N]-A[0]);

	vi ans(N+2);
	rp(i,1,N+1) ans[i] = all_dist - (dist[i]+dist[i+1]) + abs(A[i+1]-A[i-1]);
	rp(i,1,N+1) cout<< ans[i] <<endl;
}

Measured memory_bytes: 2432
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define   ull unsigned long long 
const int MAX=1e6+9;
const int mod=1e9+7;
using namespace std;
int cnt[MAX];

int main(){
	int n,m,c;
	cin>>n>>m>>c;
	int mat[n+1][m+1];
	int b[m+3];
	for(int i=0;i<m;i++)
		cin>>b[i];
	int cnt=0;
	for(int i=0;i<n;i++){
		int tot=0;
		for(int j=0;j<m;j++){
			int x;
			cin>>x;
			tot=tot+x*b[j];

		}
		if(tot+c>0)
			cnt++;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<int> v = {1,1,1};
signed main()
{
    int n, m;
    cin>>n>>m;
    vector<int> a(n), b(n), c(n);
    for(int i = 0; i<n; i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    vector<int> ve(n,0);
    int maxa = 0;
    int tot = 0;
    v = {1,1,1};
    for(int i = 0; i<n; i++){
        ve[i] = a[i]*v[0]+b[i]*v[1]+c[i]*v[2];
    }
    tot = 0;
    sort(ve.begin(), ve.end());
    for(int i = n-1; i>=n-m; i--){
        tot+=ve[i];
    }
    maxa = max(maxa, tot);
    v = {1,1,-1};
    for(int i = 0; i<n; i++){
        ve[i] = a[i]*v[0]+b[i]*v[1]+c[i]*v[2];
    }
    tot = 0;
    sort(ve.begin(), ve.end());
    for(int i = n-1; i>=n-m; i--){
        tot+=ve[i];
    }
    maxa = max(maxa, tot);
    v = {1,-1,1};
    for(int i = 0; i<n; i++){
        ve[i] = a[i]*v[0]+b[i]*v[1]+c[i]*v[2];
    }
    tot = 0;
    sort(ve.begin(), ve.end());
    for(int i = n-1; i>=n-m; i--){
        tot+=ve[i];
    }
    maxa = max(maxa, tot);
    v = {1,-1,-1};
    for(int i = 0; i<n; i++){
        ve[i] = a[i]*v[0]+b[i]*v[1]+c[i]*v[2];
    }

    v = {-1,1,1};
    for(int i = 0; i<n; i++){
        ve[i] = a[i]*v[0]+b[i]*v[1]+c[i]*v[2];
    }
    tot = 0;
    sort(ve.begin(), ve.end());
    for(int i = n-1; i>=n-m; i--){
        tot+=ve[i];
    }
    maxa = max(maxa, tot);
    v = {-1,1,-1};
    for(int i = 0; i<n; i++){
        ve[i] = a[i]*v[0]+b[i]*v[1]+c[i]*v[2];
    }
    tot = 0;
    sort(ve.begin(), ve.end());
    for(int i = n-1; i>=n-m; i--){
        tot+=ve[i];
    }
    maxa = max(maxa, tot);
    v = {-1,-1,1};
    for(int i = 0; i<n; i++){
        ve[i] = a[i]*v[0]+b[i]*v[1]+c[i]*v[2];
    }
    tot = 0;
    sort(ve.begin(), ve.end());
    for(int i = n-1; i>=n-m; i--){
        tot+=ve[i];
    }
    maxa = max(maxa, tot);
    v = {-1,-1,-1};
    for(int i = 0; i<n; i++){
        ve[i] = a[i]*v[0]+b[i]*v[1]+c[i]*v[2];
    }
    tot = 0;
    sort(ve.begin(), ve.end());
    for(int i = n-1; i>=n-m; i--){
        tot+=ve[i];
    }
    maxa = max(maxa, tot);
    cout<<maxa;
    return 0;
}


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

int main() {
	// your code goes here
	int n,y,b[100],r,t;
	double money[100];
	while(cin >> n >> y){
	if(n==0)
	break;

	int maxim=0;
	for(int i=0;i<n;i++){
		cin >> b[i] >> r >> t;
		if(t==1)
		money[i]=1+r*y/100.0;
		else
		money[i]=pow((100+r)/100.0,y);
	}
	for(int i=0;i<n;i++)
		if(money[maxim]<money[i])
		maxim=i;
		cout << b[maxim] << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, mm, pp, sumac = 0, sumwa = 0;
	string ss;
	cin >> nn >> mm;
	vector<bool> ac(nn, false);
	vector<int64> wa(nn, 0);
	for(int64 ii = 0;ii < mm;ii++)
	{
		cin >> pp >> ss;
		pp--;
		if(ss[0] == 'A')
		{
			if(!ac[pp])
			{
				ac[pp] = true;
				sumac++;
			}
		}
		else
		{
			if(!ac[pp])
			{
				wa[pp]++;
			}
		}
	}
	for(int64 ii = 0;ii < nn;ii++)
	{
		if(ac[ii])
		{
			sumwa += wa[ii];
		}
	}
	cout << sumac << ' ' << sumwa << endl;
	return 0;
}


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

#define INF INT_MAX
typedef long long ll;

using namespace std;

int main(void){
	int N,A,B;
	cin >> N >> A >> B;

	if(B < A*N){
		cout << B << endl;
	}else{
		cout << A*N << endl;
	}
	return 0;
}

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)
int n1000,n100,n10,n1,n10000;
long sum=0;

int main(void){
  int m;
  cin>>m;
  cout<<24-m+24<<endl;


return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin >> a >> b;
	if(b>0){
		c=a+b;
	}
	else{
		c=a-b;
	}
	if(c>a*b){
		cout << c << endl;
	}
	else{
		cout << a*b << endl;
 	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair <int,int> PII;
typedef pair <ll, ll> PLL;
typedef pair <int,string> PIS;
typedef vector <int> vec;
typedef priority_queue<int> PQ;
#define endl '\n'
#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fori(z,n)  for(int i=z;i<n;i++)
#define fork(z,n)  for(int k=z;k<n;k++)
#define forii(z,n) for(int i=z;i<=n;i++)
#define forkk(z,n) for(int k=z;k<=n;k++)
int maxElement(int arr[],int n)
{
    int maxi=arr[0];
    for(int i=1;i<n;i++)
    {
        if(arr[i]>maxi)
            maxi=arr[i];
    }
    return maxi;
}
int minElement(int arr[],int n)
{
    int mini=arr[0];
    for(int i=1;i<n;i++)
    {
        if(arr[i]<mini)
            mini=arr[i];
    }
    return mini;
}
string trim(const string& str)
{
    size_t first = str.find_first_not_of(' ');
    if (string::npos == first)
    {
        return str;
    }
    int last = str.find_last_not_of(' ');
    return str.substr(first, (last - first + 1));
}
int main() 
{ 
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x;cin>>x;
    int t=1;
    int ans;
    while(true) {
        ans = (360 * t)/x;
        double ans1 = (360 * t*1.0)/x;
        double diff = ans1-ans;
        if(diff<0.000000000001) {
            cout<<ans<<endl;
            break;
        }
        t++;
    }
    cerr<<"Time elapsed"<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
    return 0;
}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, long long K){
  if(K>(N-1)*(N-2)/2){
    cout<<-1<<endl;
    return;
  }
  vector<pll> edges;
  REP(N-1)edges.push_back({0,i+1});
  ll sum=(N-1)*(N-2)/2;
  ll i=1,j=2;
  while(sum>K){
    if(i==N-1)assert(false);
    --sum;
    edges.push_back({i,j});
    ++j;
    if(j==N){
      ++i;
      j=i+1;
    }
  }
  cout<<edges.size()<<endl;
  for (auto &&i : edges)
  {
    cout<<i.first+1<<" "<<i.second+1<<endl;
  }
  
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 512
//
import java.math.*;
import java.util.*;
import java.io.*;
  
public class Main { 
  
    static BufferedReader in;
    static PrintWriter out = new PrintWriter(System.out);
    static String file = "../in";
    static int test = 10; // 0 for local testing, 1 for std input
    static int inf = 1_000_000, mod = 1_000_000_007;

    void swap(int[]ary, int i, int j)
    {
        int t = ary[i];
        ary[i] = ary[j];
        ary[j] = t;
    }
    
    String[] split() throws Exception
    {
        return in.readLine().split(" ");
    }

    int readInt() throws Exception
    {
        return Integer.valueOf(in.readLine());
    }

    int[] toIntArray() throws Exception
    {
        String[] sp = split();
        int n = sp.length;
        int[] ary = new int[n];
        for(int i = 0; i < n; i++) ary[i] = Integer.valueOf(sp[i]);
        return ary;
    }

    String reverse(String str)
    {
        return new StringBuilder(str).reverse().toString();
    }


    long pow(long a, int pow)
    {
        long res = 1;
        while(pow > 0)
        {
            if(pow % 2 != 0) {
                res *= a;
                res %= mod;
            }
            a = a * a;
            a %= mod;
            pow /= 2;
        }

        return res;
    }

    public static void main(String[] args) throws Exception
    {
        int _k = Integer.valueOf("1");
        if(test > 0) in = new BufferedReader(new InputStreamReader(System.in));
        else in = new BufferedReader(new FileReader(file));
        if(test < 0) {String[] str = in.readLine().split(" ");}
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
        // System.out.println((-100 + 0) / 2);

        new Main().a();
        out.flush();
    }


    void a() throws Exception
    {
        String str = in.readLine();
        int a = 0, b = 0;
        for(char c : str.toCharArray())
        {
            if(c == 'A') a++;
            else b++;
        }
        if(a > 0 && b > 0) out.println("Yes");
        else out.println("No");
    }
}

Measured memory_bytes: 21204
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
const int MOD = 1000000007;

#define v_exists(elem, v) find(v.begin(),v.end(),elem)!=v.end()
#define s_exists(elem, s) s.find(elem)!=s.end()
#define mod_mul(x, y) x*y%MOD
#define mod_add(x, y) (x+y)%MOD
#define mod_sub(x, y) (x-y)%MOD
#define INF_INT 2147483647

typedef std::vector<std::vector<int>> Matrix;

long gcd(long a, long b) {
    return b == 0 ? a : gcd(b, a % b);
}

long lcm( long m, long n ){
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m / gcd(m, n)) * n);
}


long nCr(long n, long r){
    if(n==r || r==0){
        return 1;
    } else {
        return mod_add(nCr(n-1,r),nCr(n-1,r-1));
    }
}


Matrix dist;
std::vector<int> r;
int N,M,R;
int ans = INF_INT;

void warshall_floyd(int n){
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for (int k = 0; k < n; k++) {
                dist[j][k] = min(dist[j][k], dist[j][i]+dist[i][k]);
            }
        }
    }
}




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

    r = std::vector<int>(R, 0);
    for (int i = 0; i < R; i++) {
        int temp; cin >> temp;
        r[i] = temp-1;
    }

    dist = Matrix(N, std::vector<int>(N, 200000000));
    for(int i = 0; i < N; i++) dist[i][i] = 0;

    for (int i = 0; i < M; i++) {
        int A,B,C; cin >> A >> B >> C;
        dist[A-1][B-1] = C;
        dist[B-1][A-1] = C;
    }

    warshall_floyd(N);
    sort(r.begin(), r.end());

    do{
        int l = 0;
        for(int i=1; i<R; i++){
            l += dist[r[i-1]][r[i]];
        }
        ans = min(ans, l);
    }while(next_permutation(r.begin(), r.end()) );

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  cin >> N;
  va.resize(N);
  rep(i, 0, N - 1) { cin >> va[i]; };
}
void solve() {
  int ans = 0;
  rep(i, 0, 59) {
    int odd = 0;
    int even = 0;
    for (auto k : va) {
      if ((k >> i) & 1)
        odd++;
      else
        even++;
    }
    int t = 1LL << i;
    t %= MOD;
    t *= (even * odd) % MOD;
    ans += t;
    ans %= MOD;
  }
  cout << ans << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int i, v; string s;
int P() {
  i++;
  if(s[i]=='T') return 1;
  if(s[i]=='F') return 0;
  if(isalpha(s[i])) return v>>(s[i]-'a')&1;
  if(s[i]=='-') return !P();
  int l=P();
  i++;char o=s[i];if(o=='-')i++;
  int r=P();i++;
  if(o=='*') return l&r;
  if(o=='+') return l|r;
  if(o=='-') return l<=r;
}
 
int main() {
  while(cin>>s) {
    if(s=="#") break;
    bool k=true;
    for(v=0;v<(1<<11);v++) {
      i=-1; int l=P();
      i++;
      if(l!=P()) { k=false; break; }
    }
    cout<<(k ? "YES\n":"NO\n");
  }
  return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>

int main(void)
{
	int j,i,k,H[100],W[100];

	for(j=0;j<100;j++){	
		scanf("%d %d",&H[j],&W[j]);
		if(H[j]==0&&W[j]==0) break;
	}
		
	for(j=0;j<100;j++){
		if(H[j]==0&&W[j]==0) break;
		
		for(i=1;i<=H[j];i++){
			for(k=1;k<=W[j];k++){
				if(i%2==1){
					if(k%2==0) printf(".");
					else printf("#");
				}else{
					if(k%2==1) printf(".");
					else printf("#");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}


Measured memory_bytes: 2668
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

#define MAX_N 10000

int dp[4][10000], cnt, cnt2;
int v[3] = { 2,3,5 }, w[3] = { 380,550,850 }, x[3] = { 5,4,3 }, y[3] = { 20,15,12 };

int main() {
	memset(dp, 127, sizeof(dp));
	dp[0][0] = 0;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < MAX_N; j++) {
			cnt = 0; cnt2 = 0;
			for (int k = j; k < MAX_N; k += v[i]) {
				dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + cnt);
				cnt += w[i];
				cnt2++;
				if (cnt2%x[i] == 0) {
					cnt -= (w[i] * x[i])*y[i] / 100;
				}
			}
		}
	}
	while (true) {
		int n;
		cin >> n;
		if (n == 0) { break; }
		cout << dp[3][n / 100] << endl;
	}
	return 0;
}

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

int main(){
int n; cin >> n;
string s; cin >> s;
while(n>0){
    rep(i,s.length())
    if(s[i]=='Z') s[i] = 'A';
    else s[i]++;
    n--;
}
   
cout << s << endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
 
typedef long long LL;
typedef pair<int, int> PII;
 
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = (LL)INF * INF;

const int MAX = 1 << 12;

bool can[2][MAX];

void calcCan(int idx, int a, int b)
{
	can[idx][0] = true;
	FOR(i, 1, MAX)
		can[idx][i] = (i >= a && can[idx][i - a]) || (i >= b && can[idx][i - b]);
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	calcCan(0, a, b);
	calcCan(1, c, d);
	int s = 0, w = a;
	FOR(x, 1, f / 100 + 1)
	{
		if(can[0][x])
		{
			FOR(y, 0, f - 100 * x + 1)
				if(can[1][y] && y <= e * x && y * w > s * x)
				{
					s = y;
					w = x;
				}
		}
	}
	cout << s + 100 * w << " " << s << "\n";
	return 0;
}

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

using namespace std;
int main(int argc, char **argv)
{
    int n,x;
    cin>>n;
    vector<int> vec;
    int counter = 0 , sum = 0;
    for(int i = 0; i <  n;i++){
        cin>>x;
        vec.push_back(x);
    }
    
    for(int i = 0 ; i <  n-1 ;i++){
        if(vec[i] < vec[i+1]){
            // update counter
           if(counter < sum) counter = sum; 
           sum = 0;
        }
        else{
            sum++;
        }
        
        if(i == n-2)
            if(counter < sum) counter = sum; 
    }
    
    cout<<counter<<endl;

	return 0;
}


Measured memory_bytes: 892
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	int A[200001];
	ll num[200001]={};
	scan(N);
	rep(i,N){
		scan(A[i]);
		A[i]--;
		num[A[i]]++;
	}
	ll sum=0;
	rep(n,N){
		sum+=num[n]*(num[n]-1)/2;
	}
	rep(i,N){
		prin(sum-num[A[i]]+1);
	}
	return 0;
}


Measured memory_bytes: 4864
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,C = LI()
    d = LIR(C)
    c = LIR(n)
    ans = 0
    s = [[0]*C for i in range(3)]
    for i in range(n):
        for j in range(n):
            s[(i+j)%3][c[i][j]-1] += 1
    ans = float("inf")
    for x in range(C):
        bx = 1<<x
        for y in range(C):
            if x == y:
                continue
            by = 1<<y
            for z in range(C):
                if z == x or z == y:
                    continue
                cost = 0
                for j in range(C):
                    cost += s[0][j]*d[j][x]
                    cost += s[1][j]*d[j][y]
                    cost += s[2][j]*d[j][z]
                if cost < ans:
                    ans = cost
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 43996
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll binpowmod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return binpowmod(n, p-2, p);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,t,m,i,f=0,j,k,x,r;
    ll ans=0;
    cin >> n ;
    ll cnt[n+1]={0};
    
    rep(i,n-1)
    {
        cin >> t;
        cnt[t]++;
    }
    for(i=1;i<=n;++i)
    {
        cout << cnt[i] << endl ;
    }
    return 0;
}

Measured memory_bytes: 5260
#include <stdio.h>

int main(void)
{
	int x, y;
	int i;
	int n, k;
	int color;
	
	scanf("%d", &n);
	scanf("%d", &k);
	for (i = 0; i < k; i++){
		scanf("%d %d", &x, &y);
		
		if (x * 2 > n){
			x = n + 1 - x;
		}
		if (y * 2 > n){
			y = n + 1 - y;
		}
		
		if (x <= y){
			color = x % 3;
		}
		else if (x > y){
			color = y % 3;
		}
		
		switch (color){
		  case 0:
		  	printf("3\n");
			break;
			
		  case 1:
		  	printf("1\n");
			break;
			
		  case 2:
		  	printf("2\n");
		}
	}
	
	return (0);
}

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

#define read(num) scanf("%d", &num)
#define readll(num) scanf("%lld", &num)
#define read2(num1, num2) scanf("%d%d", &num1, &num2)
#define read3(num1, num2, num3) scanf("%d%d%d", &num1, &num2, &num3)
#define reads(str) scanf("%s", str)
#define readc(ch) scanf("%c", &ch)

#define M 1000000007
#define pb push_back
#define mp make_pair

#define pii pair<int, int>
#define vi vector<int>
#define ll long long

int main()
{
	
    int n;cin>>n;
    ll a[n+1],sum=0,m=1000000000,neg=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum+=abs(a[i]);
        m=min(m,abs(a[i]));
        if(a[i]<0)
        {
            neg++;
        }
    }
    if(neg%2==0)
    {
        cout<<sum;
    }
    else
    
    {
        //cout<<m;
        cout<<sum-2*m;
    }
    
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, k;std::cin >> n >> k;
  ll ans = 0, t;
  re(i, n){
    std::cin >> t;
    ans += min(2*t, 2*abs(k-t));
  }
  std::cout << ans << '\n';
  return 0;
}


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

int main(void)
{
    double ans = 0;
    int n, k;
    int i;

    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++)
    {
        double p = 1;
        int tmp = i;
        while (tmp < k)
        {
            p *= 0.5;
            tmp *= 2;
        }
        ans += p / (double)n;
    }

    printf("%.12f\n", ans);

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

/*bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p % i == 0) return false;
	}
	return true;
}*/
/*ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/
/*ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}*/
/*ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}
ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}*/
//printf("%.10f\n", n);

ll dp[2001];
signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	
	ll n; cin >> n;
	for (int h = 3; h <= n; h++) {
		ll cnt = 1;
		for (int i = 3; i <= h - 3; i++) {
			cnt += dp[h - i]; cnt %= mod;
		}
		dp[h] = cnt;
		//cout << dp[h] << endl;
	}
	cout << dp[n] << endl;
	return 0;
}

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

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

int main(void)
{
    ll n;
    cin >> n;
    ll l[n],count=0;
    for(int i=0;i<n;i++)
    {
        cin >> l[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if(l[i]+l[j]>l[k] && l[k]+l[j]>l[i] && l[i]+l[k]>l[j] && l[i]!=l[k] && l[k]!=l[j] && l[i]!=l[j])
                {
                    count++;
                }
            }
        }
    }
    cout << count << endl;
    return 0;
}


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

typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int def[10] = {-100000, 2, 5, 5, 4, 5, 6, 3, 7, 6};

    int n, m; cin >> n >> m;
    int a[m];
    vector<pair<int, int>> hand(m); // num, cost
    for (int i = 0; i < m; i++) {
        cin >> a[i];
        hand[i] = {a[i], def[a[i]]};
    }
    sort(hand.begin(), hand.end(), greater<>());
    int mnv = hand[0].first, mnc = hand[0].second;
    for (int i = 1; i < m; i++) {
        int cost = hand[i].second;
        int val = hand[i].first;
        if (mnc > cost) {
            mnc = cost;
            mnv = val;
        }
    }
    int order = n/mnc;

    vector<string> s;
    for (int ord = order; ord >= 1; ord--) {
        string ans = "";
        for (int i = 0; i < ord; i++) {
            ans += to_string(mnv);
        }
        int left = n - mnc * ord;
        queue<pair<int, string>> q;
        q.push({left, ans});
        bool flag = false;
        while (!q.empty()) {
            int fl = q.front().first;
            string fs = q.front().second;
            q.pop();
            if (fl == 0) {
                flag = true;
                s.push_back(fs);
            }
            // find included unique number
            set<char> uniH;
            for (auto &c : fs) {
                uniH.insert(c);
            }
            for (auto it = uniH.begin(); it != uniH.end(); it++) {
                for (int i = 0; i < m; i++) {
                    string ns(fs);
                    ns[ns.find(*it)] = to_string(hand[i].first)[0];
                    int diff = hand[i].second - def[*it - '0'];
                    if (diff > 0 && fl - diff >= 0) {
                        sort(ns.begin(), ns.end(), greater<>());
                        q.push({fl - diff, ns});
                    }
                }
            }
        }
        if (flag) break;
    }
    sort(s.begin(), s.end());
    cout << s.back() << endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>

using namespace std;

#define ll long long

void solve()
{
    ll N;
    cin >> N;
    vector<ll> A(N + 1);
    vector<ll> B(N);

    for (ll i = 0; i < N + 1; i++)
    {
        cin >> A.at(i);
    }
    for (ll i = 0; i < N; i++)
    {
        cin >> B.at(i);
    }

    ll count = 0;
    for (ll i = N - 1; i >= 0; i--)
    {
        // i+1の処理
        ll ma1 = min(A.at(i + 1), B.at(i));
        A.at(i + 1) -= ma1;
        B.at(i) -= ma1;
        count += ma1;

        // iの処理
        ll ma2 = min(A.at(i), B.at(i));
        A.at(i) -= ma2;
        B.at(i) -= ma2;
        count += ma2;
    }

    cout << count << endl;

    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 1792
def main():
    N = int(input())
    A = list(map(int, input().split()))

    D = [0] * (10**5 + 1)

    for a in A:
        D[a] += 1
        D[a+1] += 1
        if a-1 >= 0:
            D[a-1] += 1

    print(max(D))

        
if __name__ == "__main__":
    main()



Measured memory_bytes: 13964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long INF = 1LL << 60; 

int main()
{
  ll n, a, b;
  cin >> n >> a >> b;
  ll res = 0;
  res += n/(a+b)*a + min(a, n%(a+b));
  cout << res << endl;
}

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

int main(void) {
	int N;
	scanf("%d", &N);
	string c;
	cin >> c;
	int Rnum = 0;
	for (int i = 0; i < N; i++) {
		if (c[i] == 'R') Rnum++;
	}
	// cout << Rnum << "\n";
	int ans = 0;
	for (int i = Rnum; i < N; i++) {
		if (c[i] == 'R') ans++;
	}

	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3908
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char c1 = s.charAt(0);
		char c2 = s.charAt(1);
		char c3 = s.charAt(2);
		if (c1 == c2 && c2 == c3) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}

		sc.close();
	}

}


Measured memory_bytes: 21712
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int max = 0;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int p = sc.nextInt();
            sum += p;
            if (p > max) {
                max = p;
            }
        }
        sum -= max / 2;
        System.out.println(sum);
    }
}


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

listA = [list(map(int, input().split())) for j in range(n)]

ans = 0


for a in range(1, m+1):
    ok = True
    for i in range(n):
        if a not in listA[i][1:]:
            ok = False
    if ok:
        ans += 1



print(ans)

Measured memory_bytes: 3060
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print((a-1)*(b-1))
    return

#B
def B():
    def est(n):
        res = 0
        for i in range(1, int(n ** 0.5) + 1):
            if not n % i:
                res += 2
        res -= float.is_integer(n ** 0.5)
        return res == 8
    n = II()
    ans = 0
    for i in range(1, n + 1, 2):
        ans += est(i)
    print(ans)
    return

#C
def C():
    s = S()
    k = II()
    for i in range(k):
        if s[i] != "1":
            print(s[i])
            return
    print(s[k-1])
    return

# D
# 解説AC
# 始点と終点を2次元座標に落とし込むことで解ける
# 難しい
def D():
    n, m, q = LI()
    c = [[0] * n for i in range(n)]
    for _ in range(m):
        l, r = LI_()
        c[r][l] += 1
    for y in range(n):
        for x in range(1, n):
            c[y][x] += c[y][x - 1]
    for _ in range(q):
        p, q = LI_()
        ans = 0
        for qi in range(p, q + 1):
            ans += c[qi][q] - (c[qi][p - 1] if p != 0 else 0)
        print(ans)
    return

#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 57692
import java.util.*;
import java.io.*;

class Main {

    public static void main(String[] args) {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        Solver s = new Solver();
        int test = 1;
        for (int i = 1; i <= test; i++) {
            s.solve(i, in, out);
        }
        out.close();
    }

    static class Solver {
        void solve(int test_case, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            out.println((long) Math.sqrt(n) * (long) Math.sqrt(n));
        }
    }

    static class InputReader {

        BufferedReader br;
        StringTokenizer st;

        public InputReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 22996