akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

#define r(i) for(int i=0; i<10; i++)

using namespace std;

int main(){
  int n;
  
  while(cin >> n){
	int a,b,c,d;
	int cnt = 0;

	r(a)r(b)r(c)r(d){
	  if(a+b+c+d == n) cnt++;
	}
	cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s,t;
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
int sy, sx;
char maze[1010][1010];
P nums[10];
ll bfs(ll goal) {
	queue<P> que;
	rep(i,h){
		rep(j, w) {
			dis[i][j] = -1;
		}
	}
	que.push(P(sy, sx));
	dis[sy][sx] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == nums[goal].first && p.second == nums[goal].second) break;
		for (int i = 0; i < 4; i++) {
			int ny = p.first + dy[i];
			int nx = p.second + dx[i];
			if (0 <= ny && ny < h && 0 <= nx && nx < w && maze[ny][nx] != 'X' && dis[ny][nx] == -1) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	sy = nums[goal].first;
	sx = nums[goal].second;
	return dis[nums[goal].first][nums[goal].second];
}

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
		cout << 0 << endl;
		return 0;
	}
	if (a == b && b == c) {
		cout << -1 << endl;
		return 0;
	}
	ll res = 0;
	while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
		ll acnt = b / 2 + c / 2;
		ll bcnt = a / 2 + c / 2;
		ll ccnt = b / 2 + a / 2;
		a = acnt;
		b = bcnt;
		c = ccnt;
		res++;
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){
  int N, ans=0, flg=0;
  string S;
  cin >> N >> S;

  int pos = 0;
  for (int i = 0; i < 10; i++){
    char c = '0' + i;

    pos = S.find(c);

    if (pos == string::npos) continue;
    int jpos = pos;

    for (int j = 0; j < 10; j++){
      char c = '0' + j;


      pos = S.substr(jpos+1).find(c);

      if (pos == string::npos) continue;

      int kpos = pos + jpos + 1;
      for (int k = 0; k < 10; k++){
        char c = '0' + k;

        pos = S.substr(kpos+1).find(c);

        if (pos == string::npos){
          continue;
        }else{
          ans++;
          continue;
        }
        
      }
    }
  }

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


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k,x,y;cin>>n>>k>>x>>y;
    int ans = 0;
    if(n<k){
        ans = n*x;
    }else{
        ans = k*x + (n-k)*y;
    }
    cout<<ans<<endl;
}

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

const int MOD = 1e9 + 7;
const int MAXN = 3*1e5;
const int MAXM = 1e5+1;

// BIT (Binary indexed tree)
int bit[MAXM];

int sum(int i) {
	int s = 0;
	while (i > 0) {
		s += bit[i];
		i -= i&-i; // i&-i => last bit which is 1.  0110&1010=0010
	}
	return s;
}

void add(int i, int x) {
	while(i <= MAXM) {
		bit[i] += x;
		i += i&-i; // i&-i => last bit which is 1.
	}
}
// BIT : end

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

	int N, M, L, R;
	vector<pair<int, int>> a[MAXM];
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> L >> R;
		a[R-L+1].push_back(make_pair(L, R));
	}
	for (int i = 1; i <= M; i++) {
		int ans = N;
		for (int j = i; j <= M; j += i) {
			ans += sum(j);
		}
		for (auto p : a[i]) {
			// 001100
			//   LR
			add(p.first, 1);
			add(p.second+1, -1);
			N--;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>
int main(void)
{
    int N,K,i,ai,bi;
    scanf("%d%d",&N,&K);
    if(N%2==0)
    {
        for(i=0;i<K;i++)
        {
            scanf("%d %d",&ai,&bi);
            if(ai>N/2&&bi<=N/2)
            {
                ai=N/2-(N/2-(N-ai)-1);
            }
            else if(ai<=N/2&&bi>N/2)
            {
                bi=N/2-(N/2-(N-bi)-1);
            }
            else if(ai>N/2&&bi>N/2)
            {
                ai=N/2-(N/2-(N-ai)-1);
                bi=N/2-(N/2-(N-bi)-1);
            }
            if(ai==bi)
            {
                ai+=3;ai=ai%3;if(ai==0)ai=3;
                printf("%d\n",ai);
            }
            else if(ai>bi)
            {
                bi+=3;bi=bi%3;if(bi==0)bi=3;
                printf("%d\n",bi);
            }
            else if(ai<bi)
            {
                ai+=3;ai=ai%3;if(ai==0)ai=3;
                printf("%d\n",ai);
            }
        }
    }
    else if(N%2==1)
    {
        for(i=0;i<K;i++)
        {
            scanf("%d %d",&ai,&bi);
            if(ai>N/2+1&&bi<=N/2+1)
            {
                ai=N/2-(ai-N/2-2);
            }
            else if(ai<=N/2+1&&bi>N/2+1)
            {
                bi=N/2-(bi-N/2-2);
            }
            else if(ai>N/2+1&&bi>N/2+1)
            {
                ai=N/2-(ai-N/2-2);
                bi=N/2-(bi-N/2-2);
            }
            if(ai==bi)
            {
                ai+=3;ai=ai%3;if(ai==0)ai=3;
                printf("%d\n",ai);
            }
            else if(ai>bi)
            {
                bi+=3;bi=bi%3;if(bi==0)bi=3;
                printf("%d\n",bi);
            }
            else if(ai<bi)
            {
                ai+=3;ai=ai%3;if(ai==0)ai=3;
                printf("%d\n",ai);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 596
/*input
6 15
6 5
5 6
6 4
6 6
3 5
7 2
*/
 
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define ld long double
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define se second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<long long int, long long int> mpi;
typedef set<long long int> seti;
typedef multiset<long long int> mseti;
typedef priority_queue<long long int> pq;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define PI 3.14159265
#define dbg(x) cerr << "\n" << (#x) << " = " << (x) << endl ;
//#define cerr if(false)cerr
  
struct node{
    ll val;
};
struct Interval {int start, end;};
bool compare(struct node n1, struct node n2) {
    return (n1.val < n2.val);
}
 
 
 ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 











int main() 
{
	ll N, W; cin>>N>>W;
	vector <ll> v(N+1), w(N+1);
	repA(i,1,N){cin>>w[i]>>v[i];}

	ll totval = 0;
	repA(i,1,N)totval+=v[i];
	//cout<<totval<<endl;
	vector <ll> dp(totval+1,1e14);

	dp[0]=0;

	repA(i,1,N){
		repD(j,dp.size()-1-v[i],0){
			dp[j+v[i]] = min(dp[j+v[i]], dp[j]+w[i]);
		}
	}
	
	repD(i,dp.size()-1,0){if(dp[i]<=W){cout<<i<<endl; break;}}
    return 0;  
}



















 

Measured memory_bytes: 3980
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
struct edge {
    int to, cost;
};
// other libs
int gcd(int a, int b) {
    if (a % b == 0)
        return b;
    else
        return gcd(b, a % b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}

class dijkstra {
  private:
    int V;
    int d[100002];
    priority_queue<P, vector<P>, greater<>> que;

  public:
    dijkstra(int v, int s, vector<edge> G[]) {
        V = v;
        update(s, G);
    }

    void update(int s, vector<edge> G[]) {
        fill(d, d + V + 1, 100000000000ll);
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first)
                continue;
            rep(i, G[v].size()) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }
    }

    int find(int e) {
        return d[e];
    }
};
template<typename T>
class Union_Find {
  private:
    vector<T> t, s;

  public:
    Union_Find(T max_length) {
        rep(i, max_length + 1) {
            t.push_back(i);
            s.push_back(1);
        }
    }

    void Union(T x, T y) {
        if (same(x, y))
            return;
        T tx = Find(x), ty = Find(y);
        if (s[tx] < s[ty]) {
            s[ty] += s[tx];
            t[tx] = ty;
        }
        else if (s[tx] > s[ty]) {
            s[tx] += s[ty];
            t[ty] = tx;
        }
        else if (tx > ty) {
            t[tx] = ty;
            s[ty] += s[tx];
        }
        else {
            t[ty] = tx;
            s[tx] += s[ty];
        }
    }
    T Find(T n) {
        if (t[n] == n)
            return n;
        else
            return t[n] = Find(t[n]);
    }

    bool same(T x, T y) {
        return Find(x) == Find(y);
    }

    T get_Size(size_t a) {
        return s[a];
    }
};
bool ifPrime(int n){
    if(n==1)
        return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0)
            return false;
    }
    return true;
}
vector<int> primeFactorization(int n) {
    vector<int> re;
    int cnt = 2;
    while (n != 1) {
        if (n % cnt != 0) {
            cnt++;
            continue;
        }
        n /= cnt;
        re.push_back(cnt);
    }
    return re;
}
signed main(signed argc, char* argv[]) {
    int n;
    cin>>n;
    cout<<n*n*n<<endl;
}

Measured memory_bytes: 256
n = int(input())
a = [int(an) for an in input().split()]

remaining_leafs = sum(a)

layer_count = 1
vertex_count = 0
for i in range(len(a)):
    vertex_count += layer_count
    layer_count -= a[i]
    remaining_leafs -= a[i]
    if layer_count < 0:
        vertex_count = -1
        break
    layer_count = min(layer_count*2, remaining_leafs)

print(vertex_count)

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

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        int[] a = in.ii(N);
        int sum = 0;
        for (int i = 0; i < N; i++) {
            sum += a[i];
        }

        int d = Integer.MAX_VALUE;
        int ans = 0;
        for (int i = 0; i < N; i++) {
            int t = Math.abs(N * a[i] - sum);
            if (t < d) {
                ans = i;
                d = t;
            }
        }
        System.out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    int i() {
        int k = next() - '0';
        boolean minus = k == -3;
        int n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        int k = next() - '0';
        boolean minus = k == -3;
        long n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    char[] s(final int N) {
        char[] s = new char[N];
        for (int i = 0; i < N; i++) {
            s[i] = next();
        }
        next();
        return s;
    }

    public int read(char[] cbuf) {
        int i;
        char c;
        for (i = 0; (c = next()) != ' ' && c != '\n'; i++) cbuf[i] = c;
        return i;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }
}


Measured memory_bytes: 32552
#include <iostream>
#include <stdlib.h>

using namespace std;

int n;
int w[105], s[105];

int main(void)
{	
	int ans = 1e9;
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> w[i], s[i] = s[i-1] + w[i];
	for(int i = 1; i <= n; i++){
		ans = min(ans, abs(s[i]-(s[n]-s[i])));
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;
using static System.Math;

class Program
{
    static void Main()
    {
        var S = ReadLine();

        var ans = new string(S.OrderBy(c => c).ToArray()) == "abc" ? "Yes" : "No";

        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 26668
import java.util.*

const val INF = 5000000

fun main(args: Array<String>) {
    val (h,w) = readLine()!!.split(" ").map { it.toInt() }
    val queue : Queue<Int> = ArrayDeque<Int>()
    val blackLen = Array(h){IntArray(w){ INF }}
    val a = (1..h).map { readLine()!! }
    for(i in a.indices) {
        for(j in a[i].indices) {
            if(a[i][j]=='#') {
                queue.offer(i*w+j)
                blackLen[i][j] = 0
            }
        }
    }
    
    while(!queue.isEmpty()){
        val p = queue.poll()!!
        val i = p/w
        val j = p%w

        if(i>0   && blackLen[i-1][j]==INF) queue.offer((i-1)*w+j)
        if(i<h-1 && blackLen[i+1][j]==INF) queue.offer((i+1)*w+j)
        if(j>0   && blackLen[i][j-1]==INF) queue.offer(i*w+(j-1))
        if(j<w-1 && blackLen[i][j+1]==INF) queue.offer(i*w+(j+1))

        if(i>0)   blackLen[i-1][j] = Math.min( blackLen[i-1][j] , blackLen[i][j]+1 )
        if(i<h-1) blackLen[i+1][j] = Math.min( blackLen[i+1][j] , blackLen[i][j]+1 )
        if(j>0)   blackLen[i][j-1] = Math.min( blackLen[i][j-1] , blackLen[i][j]+1 )
        if(j<w-1) blackLen[i][j+1] = Math.min( blackLen[i][j+1] , blackLen[i][j]+1 )
    }

    val ans = blackLen.map { it.max()!! }.max()!!
    println(ans)

}

Measured memory_bytes: 81708
#include <iostream> 
#include <cstdio> 
#include <fstream> 
#include <algorithm> 
#include <cmath> 
#include <deque> 
#include <vector> 
#include <queue> 
#include <string> 
#include <cstring> 
#include <map> 
#include <stack> 
#include <set> 
using namespace std;
typedef  long long ll;
const int maxn = 210000;
ll s,d,now,now1;
ll find(ll x)
{
	ll x1 = sqrt(x);
	while (x1 * x1 < x)
	{
		x1++;
	}
	return x1;
}
int main()
{
	cin >> s;
	d = find(s);
	now = d * d - s;
	now1=0;
	
	if (now != 0)
	{
		while (1)
		{
			now = d * d - s;
			now1 = 0;
			for (ll i = 1; i <= sqrt(now); i++)
			{
				if (now % i == 0)
				{
					if (now / i <= d)
					{
						now1 = now / i;
						break;
					}
				}
			}
			if (now1 == 0)
			{
				d++;
			}
			else break;
		}
		now = d * d - s;
		now1 = 0;
		for (ll i = 1; i <= sqrt(now); i++)
		{
			if (now % i == 0)
			{
				if (now / i <= d)
				{
					now1 = now / i;
					break;
				}
			}
		}
		printf("%lld %d %d %lld %lld %lld", d - now / now1, 0, 0, d - now1, d, d);
	}
	else
	{
		printf("%d %d %d %lld %lld %lld", 0, 0, 0, d ,d, d);
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int x[5];
    REP(i,5){
        cin >> x[i];
        if(x[i]==0){
            cout << i+1 << endl;
            return 0;
        }
    }
        
    return 0;
}

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

template <typename T> void chmin(T&x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long s64;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i)
#define gc (c=getchar())
int read()
{
	char c;
	while(gc<'-');
	if(c=='-')
	{
		int x=gc-'0';
		while(gc>='0')x=x*10+c-'0';
		return -x;
	}
	int x=c-'0';
	while(gc>='0')x=x*10+c-'0';
	return x;
}
#undef gc

const int N=1e5+5,D=1e3+5;
int cnt[D][D],s[D][D];
int d;

void add(int x1,int x2,int y1,int y2,int w)
{
	chmax(x1,0);chmin(x2,d-1);
	chmax(y1,0);chmin(y2,d-1);
	if(x1>x2||y1>y2)return ;
	s[x2][y2]+=w;
	if(x1)s[x1-1][y2]-=w;
	if(y1)s[x2][y1-1]-=w;
	if(x1&&y1)s[x1-1][y1-1]+=w;
}

int main()
{
#ifdef kcz
	freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
#endif
	int n=read();d=read();
	rep(i,1,n)
	{
		int x=read(),y=read();
		++cnt[x%d][y%d];
	}
	int l=-1,r=1e9;
	while(l+1!=r)
	{
		memset(s,0,sizeof(s));
		int mid=(l+r)/2;
		bool OK=0;
		s64 base=mid/d;int mo=mid%d;
		rep(x,0,d-1)
		rep(y,0,d-1)
		if(base*base>=cnt[x][y])add(0,d-1,0,d-1,1); else
		if(base*(base+1)>=cnt[x][y])
		{
			add(0,d-1,0,d-1,1);
			rep(i,0,1)
			rep(j,0,1)add(mo-x+1+d*i,d-x-1+d*i,mo-y+1+d*j,d-y-1+d*j,-1);
		}
		else
		if((base+1)*(base+1)>=cnt[x][y])
		{	
			rep(i,0,1)
			rep(j,0,1)add(-x+d*i,mo-x+d*i,-y+d*j,mo-y+d*j,1);
		}
		per(x,d-1,0)
		per(y,d-1,0)s[x][y]+=s[x][y+1];
		per(x,d-1,0)
		per(y,d-1,0)s[x][y]+=s[x+1][y];
		per(x,d-1,0)
		per(y,d-1,0)OK|=s[x][y]==d*d;
		if(OK)r=mid;
		else l=mid;
	}
	cout<<r;	
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

string S;
set<int> d;

const int N_MAX = 2000;
int N;
int Y;
int x, y, z;
int flg = 0;
int main()
{
    cin >> N >> Y;
    REP(i, N + 1)
    {
        REP(j, N + 1 - i)
        {
            if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y)
            {
                x = i;
                y = j;
                z = N - i - j;
                flg = 1;
                break;
            }
        }
        if (flg == 1)
        {
            break;
        }
    }
    if (flg == 0)
    {
        x = -1;
        y = -1;
        z = -1;
    }
    cout << x << ' ' << y << ' ' << z;
    return 0;
}

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

int main() {

	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	sort(A.rbegin(), A.rend());

	long long ans = A[0];
	for (int i = 1; i <= (N - 2) / 2; i++) ans += (long long)A[i] * 2;
	if (N % 2 == 1) ans += A[(N - 2) / 2 + 1];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4056
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;
const int maxn = 1010, mod = 1e9 + 7;
int n, m;
vi a, b;
struct dsu {
	int sz;
	vi r, p;
	dsu(int n) : r(n+1, 1), p(n+1), sz(n) {iota(all(p), 0);}
	int par(int v) {
		return v == p[v] ? v : p[v] = par(p[v]);
	}
	void unite(int i, int j) {
		i = par(i), j = par(j);
		if(i == j) return;
		if(r[i] < r[j]) swap(i, j);
		r[i] += r[j];
		p[j] = i;
		--sz;
	}
};
void check() {
	vi t;
	for(auto i : b) if(i >= 1) t.push_back(i);
	b = t;
	dsu d(n);
	int p = 1;
	for(auto &i : a) {
		for(int j = 0; j < i; j++) d.unite(p+j, p+i-1-j);
		p += i;
	}
	p = 1;
	for(auto &i : b) {
		for(int j = 0; j < i; j++) d.unite(p+j, p+i-1-j);
		p += i;
	}
	//for(int i = 1; i <= n; i++) cout << d.par(i) << " ";
	if(d.sz == 1) {
		for(auto i : a) cout << i << " ";cout << '\n';
		cout << b.size() << "\n";
		for(auto i : b) cout << i << " ";
		exit(0);
	}
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
	a = vi(m);
	for(auto &i : a) cin >> i;
	//m = 50;
	//a = vi(m);
	//for(auto &i : a) i = 2*(rng()%10000 + 1), n += i;
	//for(auto i : a) cout << i << " "; cout << '\n';
	for(int X = 0; X < 500; X++) {
	shuffle(all(a), rng);
	for(int i = 1; i + 1 < m; i++) {
		if(a[i]&1) {
			if(a[0]%2 == 0) swap(a[0], a[i]);
			else if(a.back()%2 == 0) swap(a.back(), a[i]);
			else return cout << "Impossible", 0;
		}
	}
	if(a.back()%2) swap(a.back(), a[0]);
	for(int i = 0; i < m; i++) b.push_back(a[i] + (i == 0) - (i+1 == m));check();
	b.clear();
	for(int i = 0; i < m; i++) b.push_back(a[i] - (i == 0) + (i+1 == m));check();
	b = {1, n-1}, check();
	b = {n}, check();
	cout << "Impossible";
	}
	//exit(-1);
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <string.h>

int main()
{
	int place[100];
	int n,m,t,max=0,i;
	while(1){
		scanf("%d%d",&n,&m);
		if(!n&&!m) break;
		memset(place,0,sizeof(place));
		while(n--){
			for(i=0;i<m;i++){
				scanf("%d",&t);
				if(t==1){
					place[i]++;
					if(max<place[i]) max=place[i];
				}
			}
		}
		i=0;
		while(place[i]!=max) i++;
		printf("%d",i+1);
		place[i]=-1;
		for(;max;max--){
			for(i=0;i<m;i++) if(max==place[i]) printf(" %d",i+1);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
	long long int R, D, X; 
	cin >> R >> D >> X; long long int A = X; 
	for(int i = 1; i <= 10; i++){
		A = R * A - D; 
		cout << A << endl; 
	}
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

struct UF
{
	vector<int> par; // 親のインデックスを記憶する配列
	vector<int> sz; // サイズを記憶する。
	vector<int> rank;
	// 初期化
	UF(int n):par(n),sz(n),rank(n){
		for(int i = 0; i < n; i++){
			par[i] = i;sz[i] = 1;rank[i] = 0;
		}
	}
	// 親を求める
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if(rank[x] < rank[y]){
			par[x] = y;
			sz[y] += sz[x];
		}
		else{
			par[y] = x;
			sz[x] += sz[y];
			if(rank[x] == rank[y])rank[x]++;
		}
	}
	// xとyが同じ集合ならtrue
	bool same(int x, int y) { return find(x) == find(y); }
	// 素の集合のサイズを求める
	int size(int n){return sz[find(n)];}
};

vector<vector<int>> x(111111);
vector<vector<int>> y(111111);
vector<vector<int>> box(111111);
bool used[111111];

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

	ll n;cin >> n;
	REP(i, n){
		int a, b;cin >> a >> b;
		x[a].PB(b);
		y[b].PB(a);
	}

	UF uf(111111);

	REP(i, 111111){
		REP(j, x[i].size()){
			uf.unite(x[i][0], x[i][j]);
		}
	}

	REP(i, 111111){
		REP(j, y[i].size()){
			box[uf.find(i)].PB(y[i][j]);
		}
	}

	ll sum = 0;
	REP(i, 111111){
		sort(ALL(box[i]));
		box[i].erase(unique(ALL(box[i])), box[i].end());
		sum += (ll)uf.size(i) * (ll)box[i].size();
	}

	cout << sum - n << endl;

	return 0;
}


Measured memory_bytes: 13184
if __name__ == '__main__':
    import time
    START = time.time()
    LIMIT = START + 1.9

    from sys import stdin
    # from collections import defaultdict
    # from collections import deque
    # from collections import Counter
    from copy import deepcopy
    # import numpy as np
    from numpy import random as np_random
    # import math
    import random
    input = stdin.readline

    CONTEST_NUM = 26
    INFTY = 10**9

    D = int(input())
    cc = [0]+list(map(int, input().split()))
    ss = [[0]*(CONTEST_NUM+1) for _ in range(D)]
    for i in range(D):
        ss[i] = [0]+list(map(int, input().split()))

    """D = 365
    cc = list(range(27))
    np_random.seed(1)
    random.seed(1)
    ss = [[random.randint(1, 5000) for _ in range(CONTEST_NUM+1)] for _ in range(D)]
    """
    last_day = [-1]*(CONTEST_NUM+1)
    content = 0

    def count_discontent(content, date):
        for contest in range(1, CONTEST_NUM+1):
            content -= cc[contest]*(date-last_day[contest])
        return content

    def greedy_decide_contest(date):
        point = -INFTY
        for contest in range(1, CONTEST_NUM+1):
            get_point = ss[date][contest]+cc[contest]*(date-last_day[contest])
            if get_point > point:
                point = get_point
                t = contest
        return t

    tt = [0]*D
    for date in range(D):
        # t = int(input())
        t = greedy_decide_contest(date)
        tt[date] = t
        content += ss[date][t]
        last_day[t] = date
        content = count_discontent(content, date)
        # print(t)

    best_content = content
    best_tt = deepcopy(tt)
    # print(best_content)

    P = 0.05

    while time.time() <= LIMIT:
        content = 0
        tt = [0]*D
        last_day = [-1]*(CONTEST_NUM+1)
        for date in range(D):
            if np_random.binomial(1, P):
                t = random.randint(1, CONTEST_NUM)
            else:
                t = best_tt[date]
                # t = greedy_decide_contest(date)
            tt[date] = t
            content += ss[date][t]
            last_day[t] = date
            content = count_discontent(content, date)
        if content > best_content:
            best_content = content
            best_tt = deepcopy(tt)
    
    # print(best_content)
    # print(best_tt)

    for t in best_tt:
        print(int(t))

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

using namespace std;

int main()
{
  int n,m;
  cin >> n >> m;
  long long ans = 0;
  for(int i = 0 ; i < m ; i++)
  {
   	int x;
    cin >> x;
    ans+=x;
  }
  if(ans > n)
    cout << "-1";
  else
    cout << n-ans;
 return 0; 
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<climits>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cstring>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>
#include <cstdio>
using namespace std;

#define pb          push_back
#define mp          make_pair
#define ll          long long int
#define hmap        unordered_map
#define pii         pair<int,int>
#define pdd         pair<double, double>
#define M           1000000007
#define MOD         998244353
#define fast        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test        ll t; cin>>t; while(t--)
#define inp(a,n)    int a[n]; for(int i=0;i<n;i++)  cin>>a[i];
#define inpl(a,n)   ll a[n];  for(ll i=0;i<n;i++)   cin>>a[i];
#define out(a,n)    for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define outl(a,n)   for(ll i=0;i<n;i++)  cout<<a[i]<<" "; cout<<endl;
#define outv(v)     for(int i=0;i<v.size();i++) cout<<v[i]<<" ";  cout<<endl;
#define all(s)      (s).begin(),(s).end()

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define FOR(i,j,n) for(int i=j; i < n; i++)
#define souatari(i,j,n) rep1(i,n-1)rep(j,i)
#define souatari1(i,j,n) for(int i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if
#define inpv(a,n)   vector<int>a(n);  for(ll i=0;i<n;i++)   cin>>a[i];



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

// int modd(int a, int b, int c)
// {
// 	if (b == 0) return 1;

// 	if (b % 2 == 0)
// 	{
// 		int x = modd(a, b / 2, c);
// 		return (x * x) % c;
// 	}
// 	else return (a % c * modd(a, b - 1, c)) % c;
// }

// ll recursive_mod(ll a , ll b , ll mod) {
// 	if (b == 0) return 1 ;
// 	if (b & 1) return (a % mod * recursive_mod(a, b - 1, mod)) % mod;
// 	ll x = (recursive_mod(a, b / 2, mod)) ;
// 	return ((x ) * (x )) % mod ;
// }

// ll leading_digit(ll a , ll b , ll k) {
// 	long long double  pro = b * log10(a) ;
// 	long long double deci = pro - floor(pro) ;
// 	int po = pow(10, k - 1);
// 	return (ll)(((long long double)pow(10, deci)) * po) ;
// }




int main() {
	fast ;
	int a; int five = 0 ; int sev = 0;
	for (int i = 0 ; i < 3; i++) {
		cin >> a;
		if (a == 5) five++ ;
		if (a == 7) sev++ ;
	}
	if (five == 2 && sev == 1) {
		cout << "YES" ;
		return 0 ;
	}
	cout << "NO"  ;
	return  0 ;


}



Measured memory_bytes: 3588
N, X = (int(i) for i in input().split())

def Pnum(N, X):
    if N == 0:
        return X
    else:
        if X == 1:
            return 0
        elif 2 <= X <= 2**(N+1) - 2:
            return Pnum(N-1, X-1)
        elif X == 2**(N+1) - 1:
            return Pnum(N-1, 2**(N+1) - 3) + 1
        elif 2**(N+1) <= X <= 2**(N+1) + 2**(N+1) - 4:
            return Pnum(N-1, 2**(N+1) - 3) + 1 + Pnum(N-1, X- (2**(N+1) - 1) )
        elif X == 2 ** (N+2) - 3:
            return 2 * Pnum(N-1, 2**(N+1) - 3) + 1

print(Pnum(N,X))

Measured memory_bytes: 3064
#include <stdio.h>
int three(int);
int baisu(int);
int main(void){
    int i, x;
    scanf("%d", &x);
    for(i = 3; i <= x; i++){
        if(three(i) || baisu(i)){
            printf(" %d", i);
        }
    }
    printf("\n");
    return 0;
}
int three(int n){
    do{
        if(n % 10 == 3){
            return 1;
        }else{
            n = n / 10;
            }
    }while(n >= 3);
    return 0;
}
int baisu(int n){
    if(n % 3 == 0){
        return 1;
    }
    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <cstdio>
#define N 200005
using namespace std;

typedef long long ll;
ll n, mn = 1e18, m, l, r, a[N];

ll Abs(ll p) {return p > 0 ? p : -p;}

int main()
{
	ll i;
	cin >> n;
	for (i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
		a[i] += a[i - 1];
	}
	r = 3;
	for (m = 2; m < n; m++) {
		while (Abs(a[l] - a[m] + a[l]) >= Abs(a[l + 1] - a[m] + a[l + 1])) l++;
		while (Abs(a[r] - a[m] - a[n] + a[r]) >= Abs(a[r + 1] - a[m] - a[n] + a[r + 1])) r++;
		mn = min(mn, max(max(a[l], a[m] - a[l]), max(a[r] - a[m], a[n] - a[r])) - min(min(a[l], a[m] - a[l]), min(a[r] - a[m], a[n] - a[r])));
	}
    cout << mn << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define d1(x) cout<<#x<<" "<<x<<endl;
#define d2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define d2i(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;

#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
#define  mat vector<vector<ll>>
#define pi 3.14159265358979323846
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve(){
  ll n,m;
  cin>>n>>m;
  ll sm=0,x;
  fr(i,0,m)
  cin>>x,sm+=x;
  n-=sm;
  if(n<0)
  cout<<-1;
  else cout<<n;
}





int main(){
    ll t=1;
//cin>>t;
    while(t--){
     solve();
   cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    int k,a,b;cin>>k>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%k==0) return cout<<"OK"<<endl,0;
    }

        cout<<"NG"<<endl;
}


Measured memory_bytes: 3604
k,n = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*(n-1)
p = a[-1]
for i in range(n-1):
    b[i] = a[i+1] - a[i]
b.append(k-p+a[0])
ans = k- max(b)
print(ans)

Measured memory_bytes: 80204
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

const vector<P> moves = { {-1,0},{1,0},{0,-1},{0,1} };

int main() {
  IOS;
  int h,w; cin>>h>>w;
  char s[h][w];
  int white=0;
  REP(i,h) REP(j,w) {
    cin>>s[i][j];
    if (s[i][j] == '.') white++;
  }

  int dist[h][w]; memset(dist, -1, sizeof(dist));
  dist[0][0] = 0;
  queue<P> q;
  q.push({0,0});

  while(!q.empty()) {
    auto v = q.front(); q.pop();
    int y = v.first, x = v.second;

    for(auto d: moves) {
      int ny = v.first+d.first, nx = v.second+d.second;

      if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
      if (s[ny][nx] == '#') continue;
      if (dist[ny][nx] != -1) continue;

      dist[ny][nx] = dist[y][x]+1;
      q.push({ny, nx});
    }
  }

  if (dist[h-1][w-1] == -1) { COUT(-1); return 0; }
  COUT(max(0, white - (dist[h-1][w-1] + 1)));
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

using f64 = double;
using i64 = long long;
using pii = pair<int, int>;

const int N = 1e5 + 5;

struct Q {
	int a, b, d; };

vector<pii> g[N];
bool f[N];
int p[N];

vector<Q> q;
int n, m;

static void dfs(int u) {
	f[u] = true;
	for (auto v: g[u]) if (!f[v.x]) {
		p[v.x] = p[u] + v.y;
		dfs(v.x); } }

int main() {
#ifdef HOME
	freopen("arc.in", "r", stdin);
	freopen("arc.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int a, b, d;
	bool flag = true;

	cin >> n >> m;
	q.resize(m);
	for (int i = 0; i < m; ++i) {
		cin >> a >> b >> d;
		g[a].emplace_back(b, d);
		g[b].emplace_back(a, -d);
		
		q[i] = {a, b, d}; }

	for (int i = 1; i <= n; ++i) if (!f[i])
		dfs(i);

	for (auto i: q)
		flag&= (p[i.b] - p[i.a] == i.d);

	cout << (flag ? "Yes" : "No") << endl;

	return 0; }


Measured memory_bytes: 13568
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 201
typedef pair<string,string> P;

int N,D,idx;
string s[MAX];
map<int,set<string> > mp;
vector<P> vec;

void dfs(string now,int step){
  if(step == 1){
    mp[idx].insert(now);
    return;
  }
  
  int len = now.size();
  // delete
  for(int i = 0 ; i < len ; i++){
    string tmp = now;
    tmp.erase(tmp.begin()+i);
    dfs(tmp,step+1);
  }
 
  // swap
  for(int i = 0 ; i < len-1 ; i++){
    swap(now[i],now[i+1]);
    dfs(now,step+1);
    swap(now[i],now[i+1]);
  }

  // insert
  for(char ch = 'a' ; ch <= 'z' ; ch++){
    for(int j = 0 ; j < len+1 ; j++){
      string tmp = now;
      tmp = tmp.substr(0,j) + ch + tmp.substr(j);
      dfs(tmp,step+1);
    }
  }
 
  // replace
  for(char ch = 'a' ; ch <= 'z' ; ch++){
    for(int j = 0 ; j < len ; j++){
      char c = now[j];
      now[j] = ch;
      dfs(now,step+1);
      now[j] = c;
    }
  }
}

void init(){
  mp.clear();
  vec.clear();
}

int main(){
  while(cin >> N, N){
    cin >> D;
    init();
    for(int i = 0 ; i < N ; i++){
      cin >> s[i];
    }
    for(int i = 0 ; i < N ; i++){
      idx = i;
      dfs(s[i],0);
    }

    vector<string> v[MAX];
    for(int i = 0 ; i < N ; i++){
      set<string> st = mp[i];
      set<string>::iterator it;
      for(it = st.begin() ; it != st.end() ; ++it){
        v[i].push_back(*it);
      }
    } 

    if(D == 1){
      for(int i = 0 ; i < N ; i++){
        unordered_map<string,bool> ump;
        for(int j = 0 ; j < (int)v[i].size() ; j++){
          ump[v[i][j]] = true;
        }
        for(int j = i+1 ; j < N ; j++){
          if(ump.find(s[j]) != ump.end()){
           vec.push_back(P(s[i],s[j]));
          }
        }
      }
    }else{
      for(int i = 0 ; i < N ; i++){
        unordered_map<string,bool> ump;
        for(int j = 0 ; j < (int)v[i].size() ; j++){
          ump[v[i][j]] = true;
        }
        for(int j = i+1 ; j < N ; j++){
          for(int k = 0 ; k < (int)v[j].size() ; k++){
            if(ump.find(v[j][k]) != ump.end()){
              vec.push_back(P(s[i],s[j]));
              break;
            }
          }
        }
      }
    }
    int len = vec.size();
    for(int i = 0 ; i < len ; i++){
      if(vec[i].first > vec[i].second){
        swap(vec[i].first,vec[i].second);
      }
    }
    sort(vec.begin(),vec.end());
    for(int i = 0 ; i < len ; i++){
      cout << vec[i].first << "," << vec[i].second << endl;
    }
    cout << len << endl;
  }
  return 0;
}

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

gate = [list(map(int, input().split())) for _ in range(M)]
pL = max(gate[0][0], 0)
pR = min(gate[0][1], N)
lst = range(pL, pR+1)

for i in range(1, M):
    L = max(gate[i][0], 0)
    R = min(gate[i][1], N)
    lst = range(max(L, pL), min(R, pR)+1)
    pL = max(L, pL)
    pR = min(R, pR)

print(len(list(lst)))

Measured memory_bytes: 28760
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n, q;
    ll k;
    cin >> n >> k >> q;

    int a[100001]; INITA(a, 1, 100000, q); // 失点記録、何もしないとq点失う
    int tmp;
    REP(i, q) {
        cin >> tmp;
        a[tmp]--;
    }

    FOR(i, 1, n) {
        if (k - a[i] > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


class Program {

	static long mod = 998244353;
	static void Main(string[] args) {

		char[] cs = new char[] { ' ' };
		//char[] cs = new char[] { ' ', ',' };

		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		//string res="";
		//int res = 0; ;
		//int t = int.Parse(Console.ReadLine());
		//string str = Console.ReadLine();
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//int n = int.Parse(Console.ReadLine());
		//string res="";

		long res = 0;
		int n = int.Parse(Console.ReadLine());

		long[] vals = parseAryL(Console.ReadLine().Split(cs));

		long[,,] dp = new long[2, 2, n-1];	//[前が*-1,自分を*-1,N]

		dp[0, 0, 0] = vals[0] + vals[1];
		dp[1, 0, 0] = vals[0] + vals[1];
		dp[0, 1, 0] = (vals[0] + vals[1])*-1;
		dp[1, 1, 0] = (vals[0] + vals[1])*-1;

		for ( int i = 1; i < n-1; i++ ) {
			dp[0, 0, i] = Math.Max(dp[0, 0, i - 1] + vals[i + 1], dp[1, 0, i - 1] + vals[i + 1]);
			dp[1, 0, i] = Math.Max(dp[0, 1, i - 1] + vals[i + 1], dp[1, 1, i - 1] + vals[i + 1]);
			dp[0, 1, i] = Math.Max(dp[0, 0, i - 1] - vals[i + 1] - ( vals[i] * 2 ), dp[1, 0, i - 1] - vals[i + 1] - ( vals[i] * 2 ));
			dp[1, 1, i] = Math.Max(dp[0, 1, i - 1] - vals[i + 1] + ( vals[i] * 2 ), dp[1, 1, i - 1] - vals[i + 1] + ( vals[i] * 2 ));
		}
		res = Math.Max(dp[0, 0, n - 2], dp[0, 1, n - 2]);
		res = Math.Max(dp[1, 0, n - 2], res);
		res = Math.Max(dp[1, 1, n - 2], res);
			Console.WriteLine(res);


		return;
	
	}



	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryL(string[] str) {
		long[] nums = new long[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = long.Parse(str[i]); }
		return nums;
	}

	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { re[i] = str[i].ToString(); }
		return re;
	}

}

Measured memory_bytes: 34268
from math import floor
a, b = map(int, input().split())

a_ = a // 0.08
b_ = b // 0.1

ans = min(floor(a_), floor(b_))

while floor(ans * 0.08) != a or floor(ans * 0.1) != b:
    ans += 1
    if floor(ans * 0.08) > a or floor(ans * 0.1) > b:
        print('-1')
        exit()
print(ans)


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int A[111111];

signed main(){
    cin>>N;
    rep(i,N)cin>>A[i];
    sort(A,A+N);

    vpint latte;
    rep(i,N-1){
        latte.pb({min(A[i],A[N-1]-A[i]),A[i]});
    }
    sort(all(latte));
    cout<<A[N-1]<<" "<<latte.back().se<<endl;
    return 0;
}


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

int main(){
	long long int n;
	cin>>n;
	vector<long long int> a(n+1);
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int broken=0;
	for(int i=1;i<=n;i++){
		if(i-broken==a[i])
			continue;
		else ++broken;
	}
	if(broken==n)
		cout<<"-1\n";
	else cout<<broken<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxN = 2e5+7;
const int maxV = 90010;
//const int INF = 1e9+9;
const ll INF = (1ll)<<60;
const int MOD = 1e9+7;

ll r,d,x;
int main()
{
	scanf("%lld%lld%lld",&r,&d,&x);
	for(int i=1;i<=10;i++)
	{
		ll y = r*x - d;
		cout<<y<<endl;
		x = y;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define STR(i,str) for(int i=0;(str)[i];i++)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX3(a,b,c) ((a)>(b)?(a)>(c)?(a):(c):(b)>(c)?(b):(c))
#define MIN3(a,b,c) ((a)<(b)?(a)<(c)?(a):(c):(b)<(c)?(b):(c))
#define RNG(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#define RNG3(a,b,c) ((a)>(b)?(b)>(c)?(a)-(c):(c)>(a)?(c)-(b):(a)-(b):(b)>(c)?(c)>(a)?(b)-(a):(b)-(c):(c)-(a))
#define MAXS(a,b) {if((a)<(b))(a)=(b);}
#define MINS(a,b) {if((a)>(b))(a)=(b);}

int main(){
	int n;
	scanf("%d", &n);
	puts(n%10 == 9 || 90 <= n && n <= 99 ? "Yes" : "No");
}

Measured memory_bytes: 128
#include <stdio.h>
#include <queue>
#include <algorithm>
#include <climits>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)
#define RREP(n, i, a) for (int i = n - 1; i >= a; --i)

int main() {
    int N;
    scanf("%d", &N);

    int _3N = 3 * N;
    int a[_3N];
    REP(0, i, _3N) {
        scanf("%d", &a[i]);
    }

    // Red
    priority_queue<int, vector<int>, greater<int> > red_q;
    long red_sum = 0;
    REP(0, i, N) {
        red_q.push(a[i]);
        red_sum += a[i];
    }
    long red_sum_v[_3N];
    red_sum_v[N - 1] = red_sum;

    int _2N = 2 * N;
    REP(N, i, _2N) {
        long ai = a[i];
        long red_t = red_q.top();
        if (ai > red_t) {
            red_q.pop();
            red_q.push(ai);
            red_sum += ai - red_t;
        }
        red_sum_v[i] = red_sum;
    }

    // Blue
    priority_queue<int> blue_q;
    long blue_sum = 0;
    REP(_2N, i, _3N) {
        blue_q.push(a[i]);
        blue_sum += a[i];
    }
    long blue_sum_v[_3N];
    blue_sum_v[_2N] = blue_sum;

    RREP(_2N, i, N) {
        long ai = a[i];
        long blue_t = blue_q.top();
        if (ai < blue_t) {
            blue_q.pop();
            blue_q.push(ai);
            blue_sum += ai - blue_t;
        }
        blue_sum_v[i] = blue_sum;
    }

    long ans = LONG_MIN;
    REP(N, i, _2N + 1) {
        // printf("%ld - %ld = %ld\n", red_sum_v[i - 1], blue_sum_v[i], red_sum_v[i - 1] - blue_sum_v[i]);
        ans = max(ans, red_sum_v[i - 1] - blue_sum_v[i]);
    }

    printf("%ld\n", ans);

    return 0;
}


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

int main() {
  int N; cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; ++i) cin >> a[i];
  int ans = 1, btn = a[0];
  while(1) {
    //printf("NextBtn: %d\n", btn);
    if(btn == -1) {
      ans = -1;
      break;
    }
    if(btn == 2) {
      break;
    }
    ans++;
    int tmp = a[btn-1];
    a[btn-1] = -1;
    btn = tmp;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640