akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 2147483647
typedef long long ll;
int n,q;
ll seg[1<<19],lazy[1<<19];
void rep(int k,int r,int l){
    if(lazy[k]!=-1){
        seg[k]=lazy[k];
        if(l-r>0){
            lazy[k*2+1]=lazy[k];
            lazy[k*2+2]=lazy[k];
        }
    }
    lazy[k]=-1;
}
void update(int a,int b,int r,int l,int k,ll x){
    rep(k,r,l);
    if(a<=r&&l<=b){
        lazy[k]=x;
        rep(k,r,l);
        return;
    }
    if(l<a||b<r)return;
    update(a,b,r,(r+l-1)/2,k*2+1,x);
    update(a,b,(r+l+1)/2,l,k*2+2,x);
    seg[k]=min(seg[k*2+1],seg[k*2+2]);
    
}
ll find(int a,int b,int r,int l,int k){
    rep(k,r,l);
    if(a<=r&&l<=b)return seg[k];
    if(l<a||b<r)return INF;
    return min(find(a,b,r,(r+l-1)/2,k*2+1),find(a,b,(r+l+1)/2,l,k*2+2));
}
int main(void){
    cin>>n>>q;
    for(int i=0;i<1<<19;i++){
        seg[i]=INF;
        lazy[i]=-1;
    }
    for(int i=0;i<q;i++){
        int a,s,t;
        cin>>a>>s>>t;
        if(a){
            cout<<find(s,t,0,(1<<18)-1,0)<<endl;
        }else{
            ll x;
            cin>>x;
            update(s,t,0,(1<<18)-1,0,x);
        }
    }
    
}

Measured memory_bytes: 11284
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define int long long
using namespace std;
int a,b,cnt,Prime[1000010],num,ans;
inline int read(){
	char ch=getchar();int o=0;
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') o=(o<<3)+(o<<1)+(ch^48),ch=getchar();
	return o;
}
inline bool check(int n){
    if(n<=1)return 0;
    if(n==2||n==3)return 1;
    if(n%6!=5&&n%6!=1)return 0;
    for(register int i=5;i<=(int)sqrt(n);i++)if(n%i==0||n%(i+2)==0)return 0;
    return 1;
}
set<int> s;
vector<int> v;
signed main(){
	cin>>a>>b;
	for(register int i=1;i<=(int)sqrt(a);i++){
		if(!(a%i)){
			s.insert(i);
			s.insert(a/i);
		}
	}
	for(register int i=1;i<=(int)sqrt(b);i++){
		if(!(b%i)){
			if(s.count(i)) v.push_back(i);
			if(s.count(b/i)) v.push_back(b/i);   
		}
	}
	num=v.size();
	for(register int i=0;i<num;i++){
		if(check(v[i])) ++ans;
	}
	cout<<ans+1<<endl;
}

Measured memory_bytes: 640
import math
import sys
import bisect
readline = sys.stdin.readline


def main():
    n, a, b = map(int, readline().rstrip().split())
    if n == 1:
        print(1 if a == b else 0)
        return
    if a > b:
        print(0)
        return

    print(1 + (b * (n - 1) + a) - (a * (n - 1) + b))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P(M);
  vector<string> S(M);
  set<int> ac;
  map<int, int> wa;
  int waCnt = 0;
  rep(i, M) {
    cin >> P[i] >> S[i];
    if(S[i] == "WA") {
      if(!ac.count(P[i])) {
        if(!wa.count(P[i])) wa[P[i]] = 0;
        wa[P[i]]++;
      }
    } else {
      if(wa.count(P[i])) {
        waCnt += wa[P[i]];
        wa.erase(P[i]);
      }
      ac.insert(P[i]);
    }
  }
  cout << ac.size() << ' ' << waCnt << endl;
  return 0;
}


Measured memory_bytes: 10752
N=int(input())
S=list(map(int,input().split()))
T = [[0 for j in range(2)] for i in range((10**5)+1)]
Q=int(input())

for i in range(10**5+1):
    T[i][0]=i
ans=0
for i in range(N):
    T[S[i]][1]+=1
    ans+=S[i]
   
 
#print(T)   
#print(ans)

for i in range(Q):
    A,B=map(int,input().split())
    tmp=T[A][1]
    T[A][1]=0
    T[B][1]+=tmp
    ans=ans+(B-A)*tmp
    print(ans)


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

int main(void){
  int n,a,b,c,d;
  cin >> n>>a>>b>>c>>d;
  int x_sum=0,y_sum=0,x_buy=0,y_buy=0;
  while(x_buy<n){
  	x_sum+=b;
    x_buy+=a;
  }
  while(y_buy<n){
  	y_sum+=d;
    y_buy+=c;
  }
  if(x_sum<y_sum)cout<<x_sum<<endl;
  else cout << y_sum << endl;
}


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

const ll MX = 1e18;
const long double PI = acos(-1);

int main()
{
    int n; cin >> n;
    vector<int> a(200005);
    int all = -1;
    rep(i,n)
    {
        cin >> a[i];
        if(all == -1)
            all = a[i];
        else
            all ^= a[i];
    }

    rep(i,n)
    {
        auto s = all^a[i];
        cout << s << " ";
    }
    pri("");
    return 0;
}

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

long long n, ans, mod=1e9+7;

long long p(long long x, long long y){
	if(y==1) return (x+mod)%mod;
	if(y%2) return (x*p(x, y-1)+mod)%mod;
	long long res=p(x, y/2)%mod;
	return (res*res+mod)%mod;
}

int main(){
	cin>>n;
	
	ans=p(10, n)-2*p(9, n);
	ans%=mod;
	ans+=p(8, n);
	ans%=mod;
	cout<<(ans+mod)%mod<<endl;
}


Measured memory_bytes: 3632
using System;
public class Hello{
    static int func(int x){
        int sum = 0;
        while(x != 0){
            sum += x % 10;
            x /= 10;
        }
        return sum;
    }
    public static void Main(){
        int N = int.Parse(Console.ReadLine());
        int X = func(N);
        Console.WriteLine((N % X == 0) ? "Yes" : "No");
        
    }
}

Measured memory_bytes: 13140
#!/usr/bin/perl
use Data::Dumper;
my ($n) = map {$_ - 0} split(/\s+/o,<STDIN>);
my @x = map {$_ - 0} split(/\s+/o,<STDIN>);

my @xx = ();
for(my $i=0;$i<$n;$i++){
  push(@xx,+[$x[$i],$i]);
}
@x = sort { $a->[0] <=> $b->[0] } @xx;
my @w;
for(my $i=0;$i<$n;$i++){
  $w[$x[$i]->[1]] = $i;
}

#print Dumper(\@x,\@w);

my $n_2 = $n / 2;
for(my $i=0;$i<$n;$i++){
  if( $w[$i] < $n_2 ){
    print "$x[$n_2]->[0]\n";
  } else {
    print "$x[$n_2-1]->[0]\n";
  }
}

exit(0);



Measured memory_bytes: 66084
from operator import itemgetter
N = int(input())
arms = []
finishtime = float('-inf')
ans=[]
for i in range(N):
    x,l = map(int,input().split())
    arms.append((x-l,x+l))
arms.sort(key=itemgetter(1))
for i in range(N):
    if arms[i][0]>=finishtime:
        ans.append(i)
        finishtime = arms[i][1]
print(len(ans))

Measured memory_bytes: 20444
import java.util.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;//答え
        int temp = 0;
        long p = 0;
        for (int i=0;i<N;i++){
            long h = sc.nextLong();
            if (p >= h){
                temp++;
                
            }else{
                if (ans<temp){
                    ans = temp;
                }
                temp = 0;
            }
            p = h;
        }
        if (ans<temp){
                ans = temp;
            }
        System.out.printf("%d\n",ans);
    }
}


Measured memory_bytes: 47860
use proconio::input;

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

    let mut ans = 0i64;
    let mut v = vec![0; n];

    for i in 0..n {
        let idx = i as i32 - a[i] as i32;
        if idx > 0 {
            ans += v[idx as usize];
        }

        if i + a[i] >= n {
            continue;
        }

        v[(i + a[i]) as usize] += 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 6596
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1e18;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rnr(i,a,b) for(int i=int(a);i>=int(b);i--)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int n, x, t; cin >> n >> x >> t;
    cout << ((n + (x - (n % x)) % x) / x) * t << endl;
}


Measured memory_bytes: 3564
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int l = scn.nextInt();
		float temp = (float) l / 3;
		BigDecimal b1 = new BigDecimal(temp);
		b1 = b1.multiply(new BigDecimal(temp));
		b1 = b1.multiply(new BigDecimal(temp));
		System.out.println(b1);
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N, X; cin >> N >> X;
    vector<int> l(N);
    for(int i=0; i<N; i++) cin >> l[i];

    int d = 0;
    int ans = 1;
    for(int i=0; i<N; i++){
        d += l[i];
        if(d <= X) ans++;
    }

    cout << ans << endl;
}

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

long LucasNum_i(long f1, long f2, int cnt){
  if(cnt==2){
   return f1+f2;
  }
  
  return LucasNum_i(f2, f1+f2, cnt-1);
}

long LucasNum(int cnt){
  
  if(cnt==0){
    return 2;
  }
  
  if(cnt==1){
    return 1;
  }
  
  //int ans = LucasNum(num, cnt-2) + LucasNum(num, cnt-1);
  long ans = LucasNum_i(2, 1, cnt);
  return ans;
  
}

int main() {
  int N;
  cin >> N;
  
  cout << LucasNum(N) << endl;
  
  /*
  vector<int> L(N+1);
  L.at(0) = 2;
  L.at(1) = 1;
  L.at(2) = L.at(0) + L.at(1);  //:3
  L.at(3) = L.at(1) + L.at(2);  //:4
  L.at(4) = L.at(2) + L.at(3);  //:7
  L.at(5) = L.at(3) + L.at(4);  //:11
  cout << L.at(5) << endl;
  */
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    float t, d, s;
    cin >> d >> t >> s;
    if (s >= (d / t))
    {
        cout << "Yes";
    }
    else
        cout << "No";

    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>                          
using namespace std;
long long h,x=1,num=1;
int main(){
    cin>>h;
    while(h!=1)
    {
    	h/=2;
    	x*=2;
    	num+=x;
	}
	cout<<num;
	return 0;
}

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

using namespace std;
#define endl "\n"

const int MOD = 1000000007;
int main()
{
	string a, b, x;
	int m, n;
	cin >> a >> b >> m >> n >> x;
	if(x == a) cout << m - 1 << " " << n << endl;
	else if(x == b) cout  << m << " " << n -1 << endl ;	
	return 0;
}


Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int month = scan.nextInt(), day = scan.nextInt();
		int count = 0;
		for (int k = 4; k < month+1; k++)
			for (int i = 2; i < 10; i++)
				for (int j = 2; j < 10; j++) {
					if (i * j == k && 10 * i + j <= day) {
						count++;
					}
				}
		System.out.println(count);
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define forx(i, n) for(int i = 1 ; (i) <= (n) ; ++i)
#define ll long long
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x) * (x)
#define debug(x) cout << #x <<" = " << x << endl
#define printvpair(v) for(auto x : v) cout << x.first  <<" " << x.second << endl;
#define printv(v) for(auto x : v) cout << x << " "; cout << endl;

const int N = 1e5 + 7;
int a,b;

int main() {
    cin >> a >> b;

    cout << a * b - a - b + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<sstream>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pa;
const int inf=0x3f3f3f3f;
struct qaq{
    int to,cost,lenth;
    qaq(int a,int b,int c):to(a),cost(c),lenth(b){};
};
vector<qaq> G[10005];
int dis[10005],cost[10005];
void dijkstra(int n){
    fill(dis,dis+n+1,inf);
    fill(cost,cost+n+1,inf);
    dis[1]=cost[1]=0;
    priority_queue<pa,vector<pa>,greater<pa> > que;
    que.push(pa(dis[1],1));
    while(!que.empty()){
        pa q=que.top();
        que.pop();
        if(dis[q.second]<q.first) continue;
        for(int i=0;i<G[q.second].size();i++){
            qaq e=G[q.second][i];
            if(dis[e.to]>dis[q.second]+e.lenth){
                dis[e.to]=dis[q.second]+e.lenth;
                cost[e.to]=e.cost;
                que.push(pa(dis[e.to],e.to));
            }else if(dis[e.to]==dis[q.second]+e.lenth){
                cost[e.to]=min(cost[e.to],e.cost);
            }
        }
    }
}
int main(){
    int n,m;
    while(scanf("%d%d",&n,&m)&&n){
        for(int i=0;i<=n;i++) G[i].clear();
        for(int i=0;i<m;i++){
            int a,b,c,d;
            scanf("%d%d%d%d",&a,&b,&c,&d);
            G[a].push_back(qaq(b,c,d));
            G[b].push_back(qaq(a,c,d));
        }
        dijkstra(n);
        ll ans=0;
        dis[0]=0;
        for(int i=1;i<=n;i++){
            ans+=cost[i];
        }
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 5164
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	int c;

	scanf("%d %d %d", &a, &b, &c);

	if (a>b)
	{
		if (b>c)
		{
			printf("%d %d %d\n", c, b, a);
		}

		else if (c>b)
		{
			if (a>c)
			{
				printf("%d %d %d\n", b, c, a);
			}

			else 

				printf("%d %d %d\n", b, a, c);

			return 0;
		}


	}

	if (a<b)
	{
		if (b<c)
		{
			printf("%d %d %d\n", a, b, c);
		}

		else if (b>c)
		{
			if (a<c)
			{
				printf("%d %d %d\n", a, c, b);
			}

			else

				printf("%d %d %d\n", c, a, b);
		}

		return 0;
	}

	if (a==b)
	{
		if (a<c)
		{
			printf("%d %d %d\n", a, b, c);
		}

		else if (a>c)
		{
			printf("%d %d %d\n", c, b, a);
		}

		return 0;
	}

	if (a==c)
	{
		if (a<b)
		{
			printf("%d %d %d\n", a, c, b);
		}

		else if (a>b)
		{
			printf("%d %d %d\n", b, c, a);
		}

		return 0;
	}

	if (c==b)
	{
		if (a<c)
		{
			printf("%d %d %d\n", a, b, c);
		}

		else if (a>c)
		{
			printf("%d %d %d\n", c, b, a);
		}

		return 0;
	}

	


	return 0;
}

Measured memory_bytes: 596
import math
import re
import copy

n,m = map(int,input().split())
to = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

q = [0]
dist = [None] * n
dist[0] = 0
pre = [None] * n
pre[0] = 0

while len(q) != 0:
    for x in to[q[0]]:
        if dist[x] == None:
            dist[x] = dist[q[0]] + 1
            pre[x] = q[0]
            q.append(x)
    q.pop(0)

if all(z != None for z in pre):
    print("Yes")
    for i in range(1,n):
        print(pre[i] + 1)
else:
    ("No")

Measured memory_bytes: 35596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,ll> pll;
typedef pair<pll,int> tri;

int h[100100];
list<pll> g[100100];
bool vis[100100];

ll solve(void){
  int n,m,x,a,b,l;
  scanf("%d%d%d",&n,&m,&x);
  for(int i=0;i<n;i++)scanf("%d",&h[i]);

  for(int i=0;i<m;i++){
    scanf("%d%d%d",&a,&b,&l);
    a--; b--;
    g[a].push_back(pll(b,l));
    g[b].push_back(pll(a,l));
  }

  priority_queue<tri> q;
  q.push(tri(pll(x,0),0));

  while(q.size()){
    tri p = q.top(); q.pop();
    int hight = p.first.first, tree = p.second;
    ll cost = -p.first.second;

    if(vis[tree])continue;
    vis[tree] = 1;

    if(tree == n-1)return cost + h[n-1]-hight;

    for(pll e : g[tree]){
      int nxt = e.first,  t = e.second, nxth = hight;
      ll nxtc = cost;
      if(h[tree]<t)continue;

      if(hight<t){
	nxtc += 2*t-hight;
	nxth = 0;
      }else if(h[nxt]<hight-t){
	nxtc += hight-h[nxt];
	nxth = h[nxt];
      }else{
	nxtc += t;
	nxth -= t;
      }
      q.push(tri(pll(nxth,-nxtc),nxt));
    }
  }
  return -1;
}

int main(){
  printf("%lld\n",solve());
}

Measured memory_bytes: 44532
#include<bits/stdc++.h>
using namespace std;
#define MAXN	100005
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
map <int, int> cnt, num;
vector <int> g[MAXN];
int ans, s, n, tot;
int a[MAXN], b[MAXN];
bool visited[MAXN];
void dfs(int x) {
	visited[x] = true;
	ans += g[x].size();
	for (unsigned i = 0; i < g[x].size(); i++)
		if (!visited[g[x][i]]) dfs(g[x][i]);
}
int main() {
	read(n); s = 0;
	for (int i = 1; i <= n; i++) {
		read(a[i]);
		s ^= a[i];
		cnt[a[i]]++;
	}
	cnt[s]++;
	for (int i = 1; i <= n; i++) {
		read(b[i]);
		if (--cnt[b[i]] < 0) {
			printf("-1");
			return 0;
		}
	}
	num[s] = tot = 1;
	for (int i = 1; i <= n; i++)
		if (num[a[i]] == 0) num[a[i]] = ++tot;
	for (int i = 1; i <= n; i++)
		if (num[b[i]] != num[a[i]]) g[num[b[i]]].push_back(num[a[i]]);
	dfs(num[s]);
	for (int i = 1; i <= n; i++) {
		int tmp = num[a[i]];
		if (!visited[tmp] && g[tmp].size()) {
			dfs(tmp);
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 19072
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, k;
    cin >> n >> k;
    int num = (n - 1) * (n - 2) / 2;
    if (num < k)
    {
        cout << -1 << endl;
        return 0;
    }
    vector<P> e;
    for (int i = 1; i < n; i++)
        e.push_back(P(1, i + 1));
    for (int i = 1; i < n; i++)
    {
        bool f = false;
        for (int j = i + 1; j < n; j++)
        {
            if (num == k)
            {
                f = true;
                break;
            }
            num--;
            e.push_back(P(i + 1, j + 1));
        }
        if (f)
            break;
    }
    cout << e.size() << endl;
    rep(i, e.size())
    {
        cout << e[i].first << " " << e[i].second << endl;
    }
}

Measured memory_bytes: 512
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

n = int(input())
s = input()

ans = 0
for i in range(n-1):
    cnt = 0
    f = set(s[:i+1])
    b = set(s[i+1:])
    tmp = []
    if (len(f) >= len(b)):
        tmp = list(set(s[:i+1]))
        tmp2 = list(s[i+1:])
    else:
        tmp = list(set(s[i+1:]))
        tmp2 = list(s[:i+1])
    for i in range(len(tmp)):
        if tmp[i] in tmp2:
            cnt += 1
    ans = max(ans, cnt)
print(ans)






Measured memory_bytes: 9196
//code by 27.
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
using namespace std;
vector<int>vt[100001];
int f[100001];
queue<int>que;
int n;
int main()
{
	int g1=0,g2=0;
	cin>>n;
	int x,y;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		vt[x].push_back(y);
		vt[y].push_back(x);
	}
	que.push(1);
	g1++;
	g2++;
	que.push(n);
	f[1]=1;
	f[n]=-1;
	while(!que.empty())
	{
		if(f[que.front()]>0)
		{
			for(int i=0;i<vt[que.front()].size();i++)
			{
				if(f[vt[que.front()][i]]==0)
				{
					f[vt[que.front()][i]]=f[que.front()]+1;
					que.push(vt[que.front()][i]);
					g1++;
				}
			}
		}
		if(f[que.front()]<0)
		{
			for(int i=0;i<vt[que.front()].size();i++)
			{
				if(f[vt[que.front()][i]]==0)
				{
					f[vt[que.front()][i]]=f[que.front()]-1;
					que.push(vt[que.front()][i]);
					g2++;
				}
			}
		}
		que.pop();
	}
	if(g1>g2)cout<<"Fennec";
	else cout<<"Snuke";
    return 0;
}

Measured memory_bytes: 6272
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,h=LI()
  l=[]

  for _ in range(n):
    a,b=LI()
    l.append([a,-1])
    l.append([b,1])

  l=sorted(l,key=lambda x:x[0],reverse=True)
  # print(l)

  ans=0
  for i,x in enumerate(l):
    if x[1]==1:
      ans+=1
      h-=x[0]
    else:
      ans+=-(-h//x[0])
      return ans

    if h<=0:
      return ans

  return ans

# main()
print(main())


Measured memory_bytes: 37052
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,a[100005],b[100005],f[100005],cnt,ans,s[100005];
map<int,int> m;
bool ok=1;
int get(int x){return x==f[x]?x:f[x]=get(f[x]);}
int main(){
    scanf("%d",&n);
    ++n;
    for(int i=1;i<n;++i)scanf("%d",a+i),a[n]^=a[i];
    for(int i=1;i<n;++i)scanf("%d",b+i),b[n]^=b[i];
    for(int i=1;i<=n;++i)++m[a[i]];
    for(int i=1;i<=n;++i){
        --m[b[i]];
        if(m[b[i]]<0)ok=0;
    }
    if(!ok){
        puts("-1");
        return 0;
    }
    for(int i=1;i<=n;++i)if(a[i]!=b[i])ok=0;
    if(ok){
        puts("0");
        return 0;
    }
    for(int i=1;i<=n;++i){
        if(m[a[i]])a[i]=m[a[i]];
        else a[i]=m[a[i]]=++cnt;
    }
    for(int i=1;i<=n;++i)b[i]=m[b[i]];
    for(int i=1;i<=cnt;++i)f[i]=i;
    for(int i=1;i<=n;++i){
        if(a[i]==b[i]) continue;
        ++ans;
        if(get(a[i])!=get(b[i]))f[f[a[i]]]=b[i];
    }
    for(int i=1;i<=n;++i)if(a[i]!=b[i])++s[get(a[i])];
    for(int i=1;i<=cnt;++i)if(get(i)==i&&s[i]>1)++ans;
    if(a[n]!=b[n])--ans;
    if(s[get(a[n])]>1)--ans;
    printf("%d\n",ans);
    //system("pause");
    return 0;
}


Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;



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

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

    int sx,sy,gx,gy;
    cin >> sy >> sx >> gy >> gx;
    sx--;sy--;gx--;gy--;

    pair<int,int> s = make_pair(sx,sy), g = make_pair(gx,gy); 
    string sur[h];

    for(int i = 0; i < h; i++) cin >> sur[i];

    queue<pair<int,int>> p,q;

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

    p.push(s);

    int can = 0;

    while(!p.empty()){
        while(!p.empty()){
            pair<int,int> now = p.front();
            p.pop();
            q.push(now);
            for(int i = 0; i < 4; i++){
                pair<int,int> nxt = make_pair(now.first+dx[i],now.second+dy[i]);
                if(0 <= nxt.first && nxt.first < w && 0 <= nxt.second && nxt.second < h){
                    if(sur[nxt.second][nxt.first] == '.'){
                        if(nxt == g){
                            cout << can << endl;
                            return 0;
                        }
                        p.push(nxt);
                        sur[nxt.second][nxt.first] = '#';
                    }
                }
            }
        }
        can++;
        while(!q.empty()){
            pair<int,int> now = q.front();
            q.pop();
            for(int i = -2; i < 3; i++){
                for(int j = -2; j < 3; j++){
                    pair<int,int> nxt = make_pair(now.first+i,now.second+j);
                    if(0 <= nxt.first && nxt.first < w && 0 <= nxt.second && nxt.second < h){
                        if(sur[nxt.second][nxt.first] == '.'){
                            p.push(nxt);
                            sur[nxt.second][nxt.first] = '#';
                            if(nxt == g){
                                cout << can << endl;
                                return 0;
                            }
                        }
                    }
                }
            }
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 4696
def main():
	s = list(str(input()))
	# half = int(len(s)) // 2
	# print(s[0:half])
	ans = 0
	if len(s) % 2 == 0:
		half = int(len(s)) // 2
		sf = s[0:half]
		sl = s[half:int(len(s))]
		sl.reverse()
		# print(len(sf))
		# print(sf,sl)
		for i in range(len(sf)):
			if sf[i] == sl[i]:
				ans += 0
			else:
				ans += 1
	else:
		half = int(len(s)) // 2 + 1
		sf = s[0:half-1]
		sl = s[half:]
		sl.reverse()

		# print(sf,sl)
		for i in range(len(sf)):
			if sf[i] == sl[i]:
				ans += 0
			else:
				ans += 1

	print(ans)

if __name__ == "__main__":
	main()

Measured memory_bytes: 38448
/*

@author hasankamal

*/

#include <iostream>
#include <climits>
using namespace std;

int f(int v){
	int sum = 0;
	while(v){
		sum += (v % 10);
		v /= 10;
	}
	return sum;
}

int main(){

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

	int n;
	cin >> n;

	int best = INT_MAX;
	for(int a = 1; n - a >= 1; a++){
		int b = n - a;

		int s = f(a) + f(b);
		if(s < best)
			best = s;
	}

	cout << best;
	
	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define rep(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define irep(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define rrep(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

const int MOD = 1e9 + 7;

int main() {
    long long q, h, s, d;
    cin >> q >> h >> s >> d;
    long long n;
    cin >> n;

    if (2 * q < h)
        h = 2 * q;
    if (4 * q < s)
        s = 4 * q;
    if (2 * h < s)
        s = 2 * h;
    if (8 * q < d)
        d = 8 * q;
    if (4 * h < d)
        d = 4 * h;
    if (2 * s < d)
        d = 2 * s;

    cout << (n / 2)*d + (n % 2) * s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <bitset>
#include <time.h>
#include <set>
#include <algorithm>
#define ll long long
#define Inf 123372036854775806ll
using namespace std;


ll A[111111];


int GetMaxInRange(int en) {
    int pos=-1;
    int maxx=-1;
    for(int i=0;i<=en;i++) {
        if (A[i] > maxx) {
            pos=i;
            maxx=A[i];
        }
    }
    return pos;
}

ll ans[111111];

int main() {


    int N;
    cin>>N;
    A[0]=0;
    ll reqd_summ = 0;
    for(int i=1;i<=N;i++) {
        cin>>A[i];
        //A[i]=rand()%100+1;
        //printf("%lld ",A[i]);
        reqd_summ += A[i];
        ans[i]=0;
    }
    
    
    map<int,pair<int,int> > val_to_id_counts;
    
    for(int i=1;i<=N;i++) {
        
        int x = A[i];
        
        map<int,pair<int,int> >::iterator it = val_to_id_counts.find(-x);
        
        if (it == val_to_id_counts.end()) {
            val_to_id_counts[-x]=make_pair(i,1);
        } else {
            (it->second).second++;
        }
    }
    
    
    
    
    
    while(1) {
        
        /*if (val_to_id_counts.size() == 1) {
            break;
        }*/
        
        map<int,pair<int,int> >::iterator rit = val_to_id_counts.begin();
        
        ll curr_val = -rit->first;
        int pos = (rit->second).first;
        if (pos==1) {
            ans[1] += (val_to_id_counts.begin()->second).second;
            break;
        }
        
        ll counts = (rit->second).second;
        val_to_id_counts.erase(val_to_id_counts.begin());
        
        
        rit = val_to_id_counts.begin();
        ll prev_val = -rit->first;
        int prev_pos = (rit->second).first;
        
        ans[pos] += counts*(curr_val-prev_val);
        //printf("Adding %lld to %d %lld\n",counts*(curr_val-prev_val),pos,ans[pos]);
        
        (rit->second).second += counts;
        
        if ((rit->second).first > pos) {
            (rit->second).first = pos;
        }
        
        
    }
    
    ll summ = 0;
    for(int i=2;i<=N;i++)
        summ += ans[i];
    
    ans[1]=reqd_summ-summ;
    
    for(int i=1;i<=N;i++)
        printf("%lld ",ans[i]);
    printf("\n");
    
    
    
    return 0;
    
    
    for(int i=1;i<=N;i++)
        ans[i]=0;
   
    int pos = GetMaxInRange(N);
    
    
    while(pos > 0) {
        
        int prev_pos = GetMaxInRange(pos-1);
        
        // reduce A[pos] to A[N] to A[prev_pos]
        
        
        
        
        for(int j=pos;j<=N;j++)
        {
            if (A[j] > A[prev_pos]) {
                ans[pos] += A[j]-A[prev_pos];
                A[j]=A[prev_pos];
            }
        }
        
        
        pos=prev_pos;
        
    }
    
    for(int i=1;i<=N;i++)
        printf("%lld ",ans[i]);
    printf("\n");
    
    
    

}

Measured memory_bytes: 8832
#include<stdio.h>
#include<stdlib.h>
int main(void){
long long X,K,D,st;//環境でlongでみ32バイトまでしか表現できない long型で書いて出しといたらいいやん
	scanf("%lld %lld %lld",&X,&K,&D);
    
	if(X<0) X*=-1;
	/*X=abs(X); absの返り値はintがたであるのでおかしくなっている
	*/
	if(K>X/D) st=X/D;
	else st=K;

	K-=st;
	X-=st*D;

	if(K%2==0)printf("%lld\n",X);
	else printf("%lld\n",D-X);
	return 0;
}

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

using namespace std;

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

    int N;
    cin >> N;
    vector<double> vec(N);

    for (int i=0; i<N; i++){
      cin >> vec.at(i);
    }
     
    double bunbo = 0;
    for (int i=0; i<N; i++){
        bunbo += 1/vec.at(i);
    }
  
    cout << 1/bunbo << endl;

    return 0;
}


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

const int N = 500009;
const int mod = 1000000007;

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define int long long int
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()

int n;
double ans = 0;
vector<pair<double, double>> v;

double dis(pair<double, double> a, pair<double, double> b)
{
	return sqrt((a.first - b.first) * (a.first - b.first) + ((a.second - b.second) * (a.second - b.second)));
}

void pre()
{
}

int32_t main()
{
	IOS;
	pre();
	cin >> n;
	v.resize(n);
	int see = 1;
	vector<int> dekh;
	for (int i = 0; i < n; i++)
	{
		cin >> v[i].first >> v[i].second;
		see = (see * (i + 1));
		dekh.push_back(i);
	}
	while (1)
	{
		for (int i = 1; i < n; i++)
		{
			ans += (dis(v[dekh[i]], v[dekh[i - 1]]) / (see));
		}
		if (!next_permutation(all(dekh)))
			break;
	}
	cout << setprecision(20) << ans << endl;
}

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;

const int mod = 1000000007;

// dp[i][j] : 先頭からi桁目まで見たときの組み合わせ数。
//            j = 0 : i桁目まで一致
//            j = 1 : s未満であることが確定している
ll dp[100100][2]; 
int main() 
{
    string s;
    cin >> s;
    int n = s.size();

    rep(i,100100)rep(j,2) dp[i][j] = 0;
    dp[0][0] = 1;

    for (int i=1; i<=n; i++) {
        // 合計が0
        if (s[i-1] == '0') {
            (dp[i][0] += dp[i-1][0]) %= mod;
            (dp[i][1] += dp[i-1][1]) %= mod;
        } else {
            (dp[i][1] += (dp[i-1][0] + dp[i-1][1])%mod) %= mod;
        }

        // 合計が1
        if (s[i-1] == '0') {
            (dp[i][1] += dp[i-1][1] *2 %mod) %= mod;
        } else {
            (dp[i][0] += dp[i-1][0] *2 %mod) %= mod;
            (dp[i][1] += dp[i-1][1] *2 %mod) %= mod;
        }
    }

    ll ans = dp[n][0] + dp[n][1];
    ans %= mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2048
import math

def is_prime(n):
    if n == 1: return False
    
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    
    return True

n = int(input())
ans = 0

for i in range(n):
    x = int(input())
    if is_prime(x):
        ans += 1
        
print(ans)


Measured memory_bytes: 5676
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

#define MOD 1e9+7
#define INF 2123123123


int n, m;
char grid[1002][1002];
int fil[1002][1002];
int dirx[4] = {0,1,0,-1};
int diry[4] = {1,0,-1,0};
queue<pair<int, pair<int,int> > >q;
int checkdir(int x, int y){
	if (x < 0 || x >= n || y < 0 || y >= m ) return 0;
	return 1;
}
int main(){
	memset(fil, -1, sizeof(fil));
	scanf("%d %d", &n, &m);
	for (int i=0;i<n;i++){
		scanf("%s", grid[i]);
		for (int j=0;j<m;j++){
			if (grid[i][j] == '#'){
				q.push(make_pair(0, make_pair(i,j)));
				fil[i][j] = 0;
			}
		}
	}
	int maxi = 0;
	while(!q.empty()){
		pair<int, pair<int,int> > temp = q.front();
		maxi = temp.first;
		q.pop();
		for (int i=0;i<4;i++){
			int tempx = temp.second.first + dirx[i];
			int tempy = temp.second.second + diry[i];
			if (checkdir(tempx,tempy)){
				if (fil[tempx][tempy]==-1){
					fil[tempx][tempy] = temp.first+1;
					pair<int,pair<int,int> > now = make_pair(fil[tempx][tempy], make_pair(tempx,tempy));
					q.push(now);
				}
			}
		}
	}
	printf("%d\n", maxi);
	return 0;
}

Measured memory_bytes: 17296
a,b=map(int,input().split())
ans=0
for i in range(40):
  p1=2**i
  p2=2**(i+1)
  c=a//p2*p1+max(a%p2-p1,0)
  d=(b+1)//p2*p1+max((b+1)%p2-p1,0)
  ans+=(d-c)%2*p1
print(ans)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
for(int x,y,i=0;  ; i++){
cin >> x >> y;
if(x==0 && y==0)break;
if(x>y) cout << y << " " << x <<endl;
else cout << x << " " << y <<endl;
}
return 0;
}



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

using namespace std;

int main() {
    int x,y,i=0;
    int result[6000];

    while(true){
      scanf("%d %d", &x,&y);
      if(x==0&&y==0){break;
      }else if(x < y){
        result[i] = x;
        result[i+1] = y;
	i += 2;
      }else{
        result[i] = y;
        result[i+1] = x;
        i += 2;
      }
    }

    for(int j=0; j<i; j+=2){
        printf("%d %d\n",result[j] ,result[j+1]);
        //if(j+2<i){printf("\n");}
    }
    return 0;
}



Measured memory_bytes: 3140
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    	int D = sc.nextInt();
    	int T = sc.nextInt();
    	int S = sc.nextInt();
        double DIS = T*S;
      if(DIS>=D){
      	System.out.println("Yes");
      }else{
		System.out.println("No");
      }
      
    }
}

Measured memory_bytes: 35844
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string tostring(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

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

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int h, w;
	cin >> h >> w;
	
	string s;
	getline(cin, s);
	rep(i, h) {
		getline(cin, s);
		stringstream ss(s);

		char c = 'A';
		string t;
		while (ss >> t) {
			if (t == "snuke") {
				cout << c << i + 1 << endl;
				return 0;
			}
			c++;
		}
	}


	return 0;
}

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

int main(){
  ll N, A, B;
  cin >> A >> B >> N;
  int ans;
  if(N<B) {
    ans = A * N / B;
    cout << ans;
    return 0;
  }
  int max = 0;
  if(B<=N) {
    ans = A * (2*B-1) / B - (2*B-1) / B * A;
  }
  cout << ans;
}


Measured memory_bytes: 3596
# coding: utf-8
import heapq as hq
n,m=map(int,input().split())
x=sorted(list(map(int,input().split())))
a=[]
ans=x[-1]-x[0]
if n>=m:
    print(0)
    exit()
for i in range(m-1):
    hq.heappush(a,x[i]-x[i+1])
for i in range(n-1):
    ans+=hq.heappop(a)
print(ans)


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

class union_find {
    private:
        vector<int> par;
        vector<int> ran;
        vector<ll> size;
    public:
        union_find(int n);
        int find(int x);
        void unite(int x, int y);
        bool same(int x, int y);
        ll show_size(int x);
};

union_find::union_find(int n){
    par.resize(n);
    ran.resize(n);
    size.resize(n);
    rep(i,n) par[i] = i;
    rep(i,n) ran[i] = 0;
    rep(i,n) size[i] = 1;
};

int union_find::find(int x) {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    ll t = show_size(x)+show_size(y);
    size[x] = size[y] = t;
    if(ran[x] < ran[y]){
        par[x] = y;
        //size[y] += size[x];
    }
    else{
        par[y] = x;
        //size[x] += size[y];
        if(ran[x] == ran[y]) ran[x]++;
    }
};

ll union_find::show_size(int x) {
    if(par[x] == x) return size[x];
    return show_size(par[x] = find(par[x]));
}

bool union_find::same(int x, int y) {
    return (find(x) == find(y));
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	union_find uf(n);
	rep(i,m){
		int a, b;
		cin >> a >> b;
		--a; --b;
		uf.unite(a, b);
	}
	int ans = 0;
	rep(i,n){
		chmax(ans, (int)uf.show_size(i));
	}
	cout << ans << endl;
	return 0;
}


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

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

  // ここにプログラムを追記
  int t = N;
  int c = 0;
  
  while (t > 0) {
  	c += t % 10;
  	t /= 10;
  }
  
  if (N % c == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))

int H,W;
int A[82][82];
int B[82][82];
int C[82][82];// +C or -C
bool D[82][82][6402*2]={};// p

int main(){
	cin >> H >> W;
	FOR(i,0,H)FOR(j,0,W){
		cin >> A[i][j];
	}
	FOR(i,0,H)FOR(j,0,W){
		cin >> B[i][j];
		C[i][j] = abs(A[i][j]-B[i][j]);
	}
	D[0][0][C[0][0]]=1;
	vector<int> X[82][82];
	X[0][0].push_back(C[0][0]);

	FOR(i,0,H){
		FOR(j,0,W){// 確定していく
			if(i>0){
				for(auto x:X[i-1][j]){
					int a[4];
					a[0] = x - C[i][j];
					a[1] = x + C[i][j];
					a[2] = C[i][j] - x;
					a[3] = C[i][j] + x;
					FOR(k,0,4){
						if( a[k]>=0 && not D[i][j][abs(a[k])]){
							D[i][j][a[k]]=true;
							X[i][j].push_back(a[k]);
						}
					}
				}
			}
			if(j>0){
				for(auto x:X[i][j-1]){
					int a[4];
					a[0] = x - C[i][j];
					a[1] = x + C[i][j];
					a[2] = C[i][j] - x;
					a[3] = C[i][j] + x;
					FOR(k,0,4){
						if( a[k]>=0 && not D[i][j][abs(a[k])]){
							D[i][j][a[k]]=true;
							X[i][j].push_back(a[k]);
						}
					}
				}
			}
		}
	}
	int ans = X[H-1][W-1][0];
	for(auto x:X[H-1][W-1]){
		ans = min(ans,x);
	}
	cout << ans << endl;
}


Measured memory_bytes: 178048
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define mod 1000000007
#define fr(i,l,r) for(int i=l;i<=r;i++)
signed main()
{   //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin>>h>>w;
    string s[h];

    for(int i=0;i<h;i++)cin>>s[i];

     int dp[h][w];
     
     for(int i=0;i<h;i++)
     {
      for(int j=0;j<w;j++)
      {
        if(i==0 || j==0)
          {dp[i][j]=1;
            if(s[i][j]=='#')dp[i][j]=0;
            if(j==0 && i>0 && dp[i-1][j]==0)dp[i][j]=0;
            if(i==0 && j>0 && dp[i][j-1]==0)dp[i][j]=0;
            }
        else     
        dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;

        if(s[i][j]=='#')dp[i][j]=0;
      }
     } 
  cout<<dp[h-1][w-1]%mod<<endl;
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
//	std::cout<<std::fixed<<std::setprecision(10);


int main() {
	int h, w, n;
	cin >> h >> w >> n;
	int ans = dup(n, max(h, w));

	cout << ans << endl;

	return 0;
}



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

int main()
{
    int A,B,X;
    while(~scanf("%d %d %d",&A,&B,&X))
    {
        if(A+B>=X&&A<=X)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

int main() {
    int N, K, H[100001], ans=1e+9;

    cin >> N >> K;
    for (int i=0; i<N; i++) scanf("%d", &H[i]);

    sort(H, H+N);
    for (int i=0; i<N-(K-1); i++) ans = min(ans, H[i+K-1] - H[i]);

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <cmath>
#include <cstring>
#include <stack>
using namespace std;

int main(){
    char a, b, c;
    cin >> a >> b >> c;
    cout << (a == b && b == c ? "No" : "Yes") << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s;
  string n;
  cin>>s>>n;
  int v=0;
  for(int i=0; i<3; i++){
    if(s[i]==n[i]){
      v++;
    }
  }
  cout<<v<<'\n';
 }


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);

#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second 

#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)

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

ll gcd(ll a, ll b) 
{ 
    if (a == 0) return b; 
    return gcd(b % a, a); 
} 

ll exp(ll x, ll y, ll p)
{
    ll res = 1;   
    x = x % p;  
    while (y > 0)
    {
        if (y & 1) res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
}
ll mulmod(ll a, ll b, ll mod) 
{ 
    ll res = 0; 
    a = a % mod; 
    while (b > 0) 
    { 
        if (b % 2 == 1) res = (res + a) % mod; 
        a = (a * 2) % mod; 
        b /= 2; 
    }  
    return res % mod; 
} 

int main(){
    ayush();
    fastio;

    ll t; t=1;
    while(t--){
        ll n,k; cin>>n>>k;
        ll a[n];
        rep(i,n){
            cin>>a[i];
        }
        ll ans=0;
        sort(a,a+n);
        rep(i,k){
            ans+=a[i];
        }
        cout<<ans;
    }
    return 0;
}


Measured memory_bytes: 3628