akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int h[100010];
int main()
{
	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> h[i];
	sort(h, h + N);
	int ans = mod;
	for (int i = 0; i < N - K + 1; i++) {
		ans = min(ans, h[i + K - 1] - h[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();
		int M=sc.nextInt();
		int X=sc.nextInt();
		int Y=sc.nextInt();
		int x_max=-1001;
		int y_max=1001;
		for(int i=0; i<N; i++) {
			x_max=Math.max(x_max, sc.nextInt());
		}
		for(int i=0; i<M; i++) {
			y_max=Math.min(y_max, sc.nextInt());
		}


		for(int i=X+1; i<=Y; i++) {
			if(x_max<i && y_max>=i) {
				System.out.println("No War");
				System.exit(0);
			}
		}

		System.out.println("War");

	}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
bool is_prime(long n) {
    if(n < 2) return false;
    if(n == 2) return true;
    if(n % 2 == 0) return false;
    for(int i = 3;i * i < n;i += 2) {
        if(n % i == 0) return false;
    }
    return true;
}
int main() {
    int x;
    cin >> x;
    while(true) {
        if(is_prime(x)) {
            cout << x << endl;
            return 0;
        }
        else {
            x++;
        }
    }
}

Measured memory_bytes: 256
// Problem : C - management
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n;
	cin >> n;
	map<int, int> mp;
	for(int i = 1, x; i < n; i++) {
		cin >> x;
		mp[x]++;
	}
	for(int i = 1; i <= n; i++) {
		cout << mp[i] << '\n';
	}
				
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

#define ll long long

#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define debug(x) cout<<#x<<": "<<x<<endl

#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;

#define INF 1000000000000000000
#define PI 3.14159265358979323846L

bool mat[101][101];

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

    ll n;
    cin >> n;

    ll k;
    cin >> k;

    ll ans = 0;
    ll kit = 0;

    ll last = n+1;

    fr(i,2,n)
    {
    	if(ans>=k)
    	{
    		ll now = i-2;
    		last = i-1;
    		while(ans!=k)
    		{
    			mat[i-1][now] = 1;
    			mat[now][i-1] = 1;
    			now--;
    			ans--;
    		}
    		break;
    	}

    	mat[1][i] = 1;
    	mat[i][1] = 1;
    	ans = ans + kit;
    	kit++;

    	if(ans>=k)
    	{
    		ll now = i-1;
    		last = i;
    		while(ans!=k)
    		{
    			mat[i][now] = 1;
    			mat[now][i] = 1;
    			now--;
    			ans--;
    		}
    		break;
    	}
    }

    if(ans<k)
    {
    	cout << "-1" << endl;
    	return 0;
    }

    for(ll i=last+1; i<=n; i++)
    {
    	fr(j,1,n)
    	{
    		mat[i][j] = 1;
    		mat[j][i] = 1;
    	}
    }

    ll m = 0;
    fr(i,1,n)
    {
    	fr(j,i,n)
    	{
    		if(i==j)
    			continue;
    		if(mat[i][j])
    			m++;
    	}
    }

    cout << m << endl;

    fr(i,1,n)
    {
    	fr(j,i,n)
    	{
    		if(i==j)
    			continue;
    		if(mat[i][j])
    		{
    			cout << i << " " << j << endl;
    		}
    	}
    }
}


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

int main() {
    string s, s1="", s2="";
    int q;
    cin >> s >> q;
    bool flag = false;
    int count = 0;
    rep(i, q)  {
        int t;
        cin >> t;
        if (t==1) {
            flag=!flag;
            // reverse(all(s));
        }else {
            int f;
            char c;
            cin >> f >> c;
            if(flag==false){
                if (f==1) {
                    s1.insert(s1.begin(), c);
                }else {
                    s2.push_back(c);
                }
            }else {
                if (f==2) {
                    s1.insert(s1.begin(), c);
                }else {
                    s2.push_back(c);
                }
            }
        }
    }
    string ans = s1+s+s2;
    if (flag) {
        reverse(all(ans));
        // reverse(all(s1));
        // reverse(all(s2));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1436
# ABC146B
n = int(input())
s = input()
ss = ""
A = str("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
for i in range(len(s)):
    A_index = A.find(s[i])
    new_index = A_index + n
    ss = ss + str(A[new_index % 26])
print(str(ss))

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i = 0; i < n; i++){
        cin >> vec.at(i);
    }
    int ans = 0;
    for(int i = 0; i < n - 1; i++){
        for(int j = i + 1; j < n; j++){
            ans += vec.at(i) * vec.at(j);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# coding:utf-8
import itertools
n = int(input())
l = list(map(int, input().split()))
# print(l)
seq = list(itertools.combinations(l, 3))
# print(seq)
ans = 0

for item in seq:
    if item[0] == item[1] or item[1] == item[2] or item[2] == item[0]:
        continue
    if (item[0] + item[1] > item[2]) and (item[1] + item[2] > item[0]) and (item[2] + item[0] > item[1]):
        ans += 1
print(ans)


Measured memory_bytes: 20624
N = int(input())
S = []
ans = 0
for i in range(N):
    tmp = list(input())
    tmp.sort()
    tmp = "".join(tmp)
    S.append(tmp)

S.sort()

cnt = 0
ans = 0

for i in range(N):
    if i == 0 or S[i] == S[i-1]:
        cnt += 1
    else:
        ans += cnt*(cnt-1)//2
        cnt = 1
ans += cnt*(cnt-1)//2
    
print(ans)

Measured memory_bytes: 10616
N=int(input())
from math import gcd
from functools import reduce
l=list(map(int,input().split()))
sw=0
c=[0]*1000001
for i in l:
   c[i]+=1
if all(sum(c[i::i])<=1 for i in range(2,1000001)):
   print("pairwise coprime")
elif reduce(gcd,l)==1:
   print("setwise coprime")
else:
   print("not coprime")

Measured memory_bytes: 127664
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
//cout << fixed << setprecision(0)
int main() { 
  int r,g;cin >> r >> g;
  if(r%500<=g){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
 
      int N = sc.nextInt();
      long D = sc.nextInt();
      int C = 0;
      long DD = D*D;
      for(int i=0;i<N;i++){
      	long X = sc.nextInt();
        long XX = X*X;
        long Y = sc.nextInt();
        long YY = Y*Y;
        
        if((XX+YY)<=(DD)){
        	C++;
        }
      }
      
	System.out.println(C);
      
    }
}

Measured memory_bytes: 48872
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int comp_char(const void*a,const void*b){
    char *aa=(char*)a;
    char *bb=(char*)b;
    return strcmp(aa,bb);
}

int main(int argc,char* argv[]){
    int n;
    int ans=1;
    static char s[200000][11];
    //vector<vector<char>> s(200000,vector<char>(11));

    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%s",s[i]);
    }
    qsort(s,n,sizeof(s[0]),comp_char);
    for(int i=1;i<n;i++){
        //printf("---%s\n",s[i-1]);
        if(!strcmp(s[i],s[i-1])){
            continue;
        }
        else{
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 7544
N = int(input())						# 5
A =        list( map(int, input().split()) )	# 1 2 3 4 5 ...

A.sort()
maxA = A[-1]
X = [0]*(maxA+1)


for a in A:
  for i in range(1,maxA+1):
    x = a*i
    if x > maxA: break
    X[x] += 1

ans = 0
for a in A:
  if X[a]==1: ans+=1

print(ans)
# print(A)
# print(X)



Measured memory_bytes: 121928
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque

H,W = map(int,readline().split())
A = [line.rstrip().decode('utf-8') for line in readlines()]

class Dinic:
    def __init__(self, N, source, sink):
        self.N = N
        self.G = [[] for _ in range(N)]
        self.source = source
        self.sink = sink

    def add_edge(self, fr, to, cap):
        n1 = len(self.G[fr])
        n2 = len(self.G[to])
        self.G[fr].append([to, cap, n2])
        self.G[to].append([fr, 0, n1]) # 逆辺を cap 0 で追加
        
    def add_edge_undirected(self, fr, to, cap):
        n1 = len(self.G[fr])
        n2 = len(self.G[to])
        self.G[fr].append([to, cap, n2])
        self.G[to].append([fr, cap, n1]) # 逆辺を cap 0 で追加
        
    def bfs(self):
        level = [0] * self.N
        G = self.G; source = self.source; sink = self.sink
        q = deque([source])
        level[source] = 1
        pop = q.popleft; append = q.append
        while q:
            v = pop()
            lv = level[v] + 1
            for to, cap, rev in G[v]:
                if not cap:
                    continue
                if level[to]:
                    continue
                level[to] = lv
                if to == sink:
                    self.level = level
                    return
                append(to)
        self.level = level
        
    def dfs(self,v,f):
        if v == self.sink:
            return f
        G = self.G
        prog = self.progress
        level = self.level
        lv = level[v]
        E = G[v]
        for i in range(prog[v],len(E)):
            to, cap, rev = E[i]
            prog[v] = i
            if not cap:
                continue
            if level[to] <= lv:
                continue
            x = f if f < cap else cap
            ff = self.dfs(to, x)
            if ff:
                E[i][1] -= ff
                G[to][rev][1] += ff
                return ff
        return 0
    
    def max_flow(self):
        INF = 10**18
        flow = 0
        while True:
            self.bfs()
            if not self.level[self.sink]:
                return flow
            self.progress = [0] * self.N
            while True:
                f = self.dfs(self.source, INF)
                if not f:
                    break
                flow += f
        return flow

source = 0
sink = H+W+1

dinic = Dinic(H+W+2, source, sink)
add = dinic.add_edge_undirected

INF = 10 ** 18
for h in range(1,H+1):
    for w,ox in enumerate(A[h-1],1):
        if ox == 'x':
            continue
        elif ox == 'o':
            add(h,H+w,1)
        elif ox == 'S':
            add(source,h,INF)
            add(source,H+w,INF)
        elif ox == 'T':
            add(sink,h,INF)
            add(sink,H+w,INF)

f = dinic.max_flow()
answer = f if f < INF else -1
print(answer)

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);
  ll k, a, b; cin >> k >> a >> b;
  if(b-a <= 2 || k <= a) {
    cout << k+1 << endl;
  } else {
    ll ans = a;
    k -= a-1;
    ans += (b-a) * (k/2);
    ans += k%2;
    cout << ans << endl;
  }
}


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

int main(){
	double x, y;
	double angle = 90;
	int a, b;
	while(1){
		scanf("%d,%d", &a, &b);
		if(a == 0 && b == 0) break;
		double rad = angle * M_PI / 180;
		x += a * cos(rad);
		y += a * sin(rad);
		angle -= b;
	}
	cout << (int)x << endl << (int)y << endl;
	return 0;
}

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

int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  int r = 0;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R')
      r++;
    else
      a[i] = 1;
  }
  cout << reduce(begin(a), next(begin(a), r)) << endl;
}


Measured memory_bytes: 4444
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define slice(l, r) substr(l, r-l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
  #define cerrendl 42
#endif
//}}}

signed main() {
  int n,r;cin>>n>>r;
  cout << (n>=10 ? r : r+100*(10-n)) << endl;
  return 0;
}


Measured memory_bytes: 764
#include<stdio.h>

#include<math.h>

struct Point{
	double x;
	double y;
};

void kock(int n, struct Point p1, struct Point p2){
	if( n==0 ){ return; }
	struct Point s, t, u;
	double rad = M_PI * 60.0 / 180.0;
	
	s.x = (2.0 * p1.x + 1.0 * p2.x) / 3.0;
	s.y = (2.0 * p1.y + 1.0 * p2.y) / 3.0;
	t.x = (1.0 * p1.x + 2.0 * p2.x) / 3.0;
	t.y = (1.0 * p1.y + 2.0 * p2.y) / 3.0;
	u.x = (t.x - s.x) * cos(rad) - (t.y - s.y) * sin(rad) + s.x;
	u.y = (t.x - s.x) * sin(rad) + (t.y - s.y) * cos(rad) + s.y;
	
	kock(n-1, p1, s);
	printf("%.8f %.8f\n", s.x, s.y);
	
	kock(n-1, s, u);
	printf("%.8f %.8f\n", u.x, u.y);
	
	kock(n-1, u, t);
	printf("%.8f %.8f\n", t.x, t.y);
	
	kock(n-1, t, p2);
}

int main(void){
	int n;
	struct Point p1, p2;
	scanf("%d", &n);
	
	p1.x = 0;
	p1.y = 0;
	p2.x = 100;
	p2.y = 0;
	
	printf("%.8f %0.8f\n", p1.x, p1.y);
	
	kock(n, p1, p2);
	
	printf("%.8f %0.8f\n", p2.x, p2.y);
	
	return 0;
}


Measured memory_bytes: 2108
strargs = input()

n, a, b = map(lambda x: int(x), strargs.split())

if (b - a) % 2 == 0:
  print((b - a)//2)
  
elif a - 1 < n - b:
  newB = b - a
  mid = (newB - 1)//2 + 1
  print(a + mid - 1)

else:
  newA = (a + (n - b + 1))
  mid = newA + (n - newA)//2
  print((n - b + 1) + (n - newA)//2)

Measured memory_bytes: 3316
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		String a[] = new String[H];

		for (int i = 0; i < H; i ++) {
			a[i] = sc.next();
		}

		boolean row[] = new boolean[H];
		boolean col[] = new boolean[W];

		Arrays.fill(row, false);
		Arrays.fill(col, false);


		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (a[i].charAt(j) == '#') {
					row[i] = true;
					col[j] = true;
				}
			}
		}

		for (int i = 0; i < H; i++) {
			if (row[i]) {
				for (int j = 0; j < W; j++) {
					if (col[j]) {
						System.out.print(a[i].charAt(j));
					}
				}
				System.out.println();
			}
		}

	}
}


Measured memory_bytes: 24916
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  int maxAll = 0, maxSugar = 0;
  double minDist = 2.0;
  double LIMIT = (double)e / (100 + e);
  for (int i = 0; 100 * a * i <= f; i++) {
    int massA = 100 * a * i;
    for (int j = 0; 100 * b * j <= f - massA; j++) {
      int massB = 100 * b * j;
      for (int k = 0; c * k <= f - massA - massB; k++) {
        int massC = c * k;
        for (int l = 0; d * l <= f - massA - massB - massC; l++) {
          int massD = d * l;
          if (massA + massB + massC + massD <= 0) break;
          double conce =
              (double)(massC + massD) / (massA + massB + massC + massD);
          double dist = LIMIT - conce;
          if (dist >= 0 && dist < minDist) {
            minDist = dist;
            maxAll = massA + massB + massC + massD;
            maxSugar = massC + massD;
          }
        }
      }
    }
  }
  cout << maxAll << " " << maxSugar << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lint long long int
#define REP(i,n) for(lint i = 0; i < n ;i++)
const int N= 123456*2+100;
bool isprime[N];

int main()
{
  lint n;
  lint a = 0;
 for(lint a = 2;a<N;a++){
    for(lint i = a*2;i < N;i+=a){
      isprime[i] = true;
    }
 }
  while(cin>>n,n){
    lint ans=0;
    for(lint i = n+1;i < 2*n+1;++i){
      if(!isprime[i])ans++;
    }
    cout << ans << endl;

  }
  

  
}

Measured memory_bytes: 3308
#include <stdio.h>

int main(void)
{
	int b1,b2,b3,b;
	scanf("%d %d %d",&b1,&b2,&b3);
	b=b1+b2;
	if (b==2 && b3==0 || b==0 && b3==1)printf("Open\n");
	else if(b+b3==0 || b==1 && b3==0)printf("Close\n");
		
	return 0;
}


Measured memory_bytes: 2104
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <cmath>
using namespace std;

typedef long long ll;
const ll inf = 1e18 + 1;



int main() {
    ll n,k; cin >> n >> k;
    ll res = n % k;
    if (res == 0) {
        cout << 0 << "\n";
        return 0;
    }
    ll ans = min(res,k - res);
    cout << ans << "\n";
}

Measured memory_bytes: 256
def codei
  return gets.split.map &:to_i
end
def j
  a,b,c = codei
  if a == 7
    if b == 5 && c == 5
      return true
    else
      return false
    end
  elsif a == 5
    if (b==5&&c==7) || (b==7&&c==5)
      return true
    else
      return false
    end
  else
    return false
  end
end
if j
  puts "YES"
else
  puts "NO"
end


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::vector<std::vector<int> > hen;
std::vector<int> visited;
std::vector<int> stack;

bool dfs(int i) {
	stack.push_back(i);
	visited[i] = 0;
	for (auto j : hen[i]) {
		if (visited[j] == 1) continue;
		if (visited[j] == 0) {
			stack.push_back(j);
			return true;
		}
		if (dfs(j)) return true;
	}
	stack.pop_back();
	visited[i] = 1;
	return false;
}

int main() {
	int n = ri(), m = ri();
	int a[m], b[m];
	std::vector<std::vector<bool> > ext(n, std::vector<bool>(n));
	hen.resize(n);
	for (int i = 0; i < m; i++) {
		a[i] = ri() - 1;
		b[i] = ri() - 1;
		ext[a[i]][b[i]] = true;
		hen[a[i]].push_back(b[i]);
	}
	visited.resize(n, -1);
	std::vector<int> cycle;
	for (int i = 0; i < n; i++) {
		if (visited[i] == -1) {
			stack.clear();
			stack.push_back(i);
			if (dfs(i)) {
				int back = stack.back();
				assert(stack.size() >= 3);
				int start = -1;
				for (int j = stack.size() - 2; j >= 0; j--) {
					if (stack[j] == back) {
						start = j;
						break;
					}
				}
				assert(start != -1);
				for (int j = start; j + 1 < (int) stack.size(); j++) cycle.push_back(stack[j]);
				break;
			}
		}
	}
	if (!cycle.size()) {
		std::cout << -1 << std::endl;
	} else {
		int next[cycle.size()];
		for (int i = 0; i < (int) cycle.size(); i++) next[i] = (i + 1) % cycle.size();
		int start = 0;
		for (int j = 0; next[j] > j; j = next[j]) {
			for (int k = next[j]; k != j; k = next[k]) {
				if (ext[cycle[j]][cycle[k]]) next[j] = k, start = k;
			}
		}
		std::vector<int> res;
		int cur = start;
		do {
			res.push_back(cycle[cur]);
			cur = next[cur];
		} while (cur != start);
		std::cout << res.size() << std::endl;
		for (auto j : res) std::cout << j + 1 << std::endl;
		std::cout << std::endl;
	}
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  string alphabet = "abcdefghijklmnopqrstuvwxyz";
  char A;
  cin >> A;
  
  for(int i; i < alphabet.size(); i++){
  if (alphabet.at(i) ==  A)
    cout << alphabet.at(i+1) << endl;
  }
}
  

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,k,N,D;
  string s;
  cin>>s>>D;
  N=s.size();
  vector<mat> dp(2,mat(N+1,vec(D,0)));
  dp[1][0][0]=1;
  rep(i,N){
    rep(j,D){
      dp[1][i+1][(j+s[i]-'0')%D]=dp[1][i][j];
      rep(k,10){
        if(k<s[i]-'0')(dp[0][i+1][(j+k)%D]+=dp[1][i][j])%=mod;
        (dp[0][i+1][(j+k)%D]+=dp[0][i][j])%=mod;
      }
    }
  }
  print((dp[1][N][0]+dp[0][N][0]+mod-1)%mod);
}

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


typedef double db;
typedef long long ll;
typedef long double ld;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main(){
	fast_io();
  ll n;
  cin>>n;
  map<string , ll> m;
  for(ll i=0;i<n;i++){
    string x;
    cin>>x;
    sort(x.begin() , x.end());
    m[x]++;

  }


  ll ans=0 , sum = 1;
  for(auto it: m){
    ans+=(it.second * (it.second - 1))/2;
  }


  cout<<ans;
  // for(ll i=0;i<n;i++){
  //   cout<<s[i]<<"\n";
  // }
	return 0;
}


Measured memory_bytes: 11264
program main
  implicit none
  integer :: N
  real(8),allocatable :: x(:)
  real(8) :: out
  character(len=3),allocatable :: u(:)

  integer :: i
  read(*,*) N
  allocate(x(N),u(N))
  do i = 1,N
     read(*,*) x(i),u(i)
  end do
  do i = 1,N
     if (u(i) =='BTC' ) then
        x(i) = x(i)*380000.0
     end if
  end do
  out=sum(x)
  write(*,'(f0.6)') out
  stop
end program main

Measured memory_bytes: 256
import std.stdio, std.string, std.range, std.algorithm, std.math, std.conv;

void main() {
  auto N = readln.chomp.to!int;
  auto T = readln.split.to!(int[]);
  auto M = readln.chomp.to!int;
  auto s = T.sum;
  foreach (i; 0..M) {
      auto inp = readln.split.to!(int[]);
      auto P = inp[0]-1, X = inp[1];
      writeln(s - T[P] + X);
  }
}


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

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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  int X,Y;
  cin>>X>>Y;
  if(Y%2==0&&Y>=X*2&&Y<=X*4) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3620
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 998244353
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n,k;cin>>n>>k;
    if(n%k==0)
        cout<<0<<endl;
    else
        cout<<1<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;



int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	uint32 n, y;
	std::cin >> n >> y;
	y /= 1000;
	uint32 a, b, c;
	uint32 t[3];
	bool f = 0;
	rep(i, 0, 2001) {
		if (i * 10 > y) break;
		if (i > n) break;
		a = n - i;
		b = y - i * 10;
		if (b > a * 5) continue;
		c = a * 5 - b;
		if (c % 4 != 0) continue;
		c >>= 2;
		if (c <= a) {
			f = 1;
			t[0] = i;
			t[1] = a - c;
			t[2] = c;
		}
	}
	if (f) {
		std::cout << t[0] << " " << t[1] << " " << t[2] << "\n";
	}
	else {
		std::cout << "-1 -1 -1\n";
	}
	return 0;
}

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

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
int ans;
int a[50][50];
void dfs(int x, int y, int step) {
	if(step >= ans) return;
	if(a[x][y] == 3) {
		if(step < ans) ans = step;
		return;
	}
	for(int i = 0; i < 4; i++) {
		int xx = x + dx[i], yy = y + dy[i];
		if(a[xx][yy] == 1) continue;
		//printf("%d %d %d\n", xx, yy, a[xx][yy]);
		while(a[xx][yy] != -1) {
			//printf("pp\n");
			if(a[xx][yy] == 0) {
				xx = xx + dx[i];
				yy = yy + dy[i];
				continue;
			}
			if(a[xx][yy] == 1) {
				a[xx][yy] = 0;
				dfs(xx - dx[i], yy - dy[i], step + 1);
				a[xx][yy] = 1;
			}
			if(a[xx][yy] == 3) 
				dfs(xx, yy, step + 1);
			break;
		}
	}
}
int main() {
	int n, m, posx, posy;
	while(scanf("%d%d", &m, &n) && n && m) {
		ans = 11;
		memset(a, -1, sizeof(a));
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= m; j++) {
				scanf("%d", &a[i][j]);
				if(a[i][j] == 2) {
					posx = i;
					posy = j;
					a[i][j] = 0;
				}
			}
		}
		dfs(posx, posy, 0);
		if(ans < 11) 
			printf("%d\n", ans);
		else 
			printf("-1\n");
	}
	return 0;
} 

Measured memory_bytes: 3144
// Gear4        
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define FOR0(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define FOR(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define FORD(i,l,r) for(int i=(r), _##i=(l); --i>=_##i; )
#define SZ(a) ((int)((a).size()))
#define printCase() "Case #" << caseNum << ": "
#define pb push_back
#define mp make_pair
#define SYNC std::ios::sync_with_stdio(false);  cin.tie(NULL);
#define ff first
#define ss second
template<typename T> using V = vector<T>;
template<typename T, typename U> using P = pair<T,U>;
using ld = long double;
using ll = long long;
#define endl '\n'
const int inf = 1e9, mod = 1e9 + 7;
const ll INF = 9e18;
const ld EPS = 1e-9, PI = acosl(-1.0);
ll pos(ll i, ll a, ll b, ll x) {
    if(i > b-1 || i < 1) return 1;
    return i * (a+x+1-i) < a*b;
}
ll bs(ll a, ll b) {
    ll ans=0, l = 1, r = b-1;
    while(l<=r) {
        ll x = (l + r) >> 1;
        ll i = (a + x + 1)/2;
        if(pos(i, a, b, x) && pos(i+1, a, b, x) && pos(i-1, a, b, x))
            ans = x, l = x + 1;
        else r = x - 1;
    }
    return ans;
}
int main() {
    SYNC
    int q;
    ll a, b;
    cin >> q;
    while(q--) {
        cin >> a >> b;
        // if(a == 1 || b == 1) {
        //     a==b ? 
        // }
        ll ans = 0;
        ll ar = bs(b, a);
        ll br = bs(a, b);
        ans += ar + br;
        ans += min(b-br-1, a-ar-1);
        cerr << ar << " " << br << endl;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

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

	vector<long> P( 101 );
	for( int i = 1; i <= 100; ++i ) {
		for( int j = 0; j < N; ++j ) {
			int t = X[j] - i;
			P[i] += t*t;
		}
	}

	long ans = LLONG_MAX;
	for( int i = 1; i <= 100; ++i ) {
		ans = min( ans, P[i] );
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
string x,y,z;
int main()
{
	cin>>x>>y;
	
	for(int i=0;i<x.size();i++)
	{
		z+=x[i];
		if(i<y.size())z+=y[i];
		
	}
	
	cout<<z<<endl;
	return 0;
}


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

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )

using namespace std;


int N;
int W[105];

int main(void) {

	scanf("%d", &N);

	REP(i, 0, N) scanf("%d", &W[i]);


	int S1 = W[0];
	int S2 = 0;
	REP(i, 1, N) S2 += W[i];

	int ans = min(100000, abs(S1 - S2));

	for (int T = 1; T < N - 1; T++ ) {
		S1 += W[T];
		S2 -= W[T];
		ans = min(ans, abs(S1 - S2));
	}

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

	return 0;
}


Measured memory_bytes: 256
N, M, C = gets.split.map(&:to_i)
B_m = gets.split.map(&:to_i)
A_nm = N.times.map{|_| gets.split.map(&:to_i)}

ans = 0
N.times do |i|
  ab = 0
  M.times do |j|
    ab += A_nm[i][j] * B_m[j]
  end
  if ab + C > 0
    ans +=1
  end
end
p ans

Measured memory_bytes: 14208
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int w,n;
        w=sc.nextInt();
        n=sc.nextInt();
        int output[] = new int[w];
        for(int i=0; i<w; i++) output[i]=i+1;

        for(int i=0; i<n; i++)
        {
            String input = sc.next();
            String[] suuji = input.split(",");
            //System.out.println(suuji[1]);

            int a,b;
            a=Integer.parseInt(suuji[0]);
            b=Integer.parseInt(suuji[1]);

            
            //swap
            int c;
            c = output[a-1];
            output[a-1] = output[b-1];
            output[b-1] = c;
        }

        for(int i=0; i<w; i++) System.out.println(output[i]);
        sc.close();
    }
}


Measured memory_bytes: 26096
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
using namespace std;

int main(void) {
	int n, k, q , b;
	cin >> n >> k >> q;
	vector<int> a(n);

	for (int i = 0; i < n; i++) {
		a[i] = 0;
	}
	for (int i = 0; i < q; i++) {
		cin >> b;
		a[b-1]++;
	}
	for (int i = 0; i < n; i++) {
		if (k-q+a[i] <= 0) {
			cout << "No"<<endl;
		}
		else {
			cout << "Yes"<<endl;
		}
	}
}

Measured memory_bytes: 1024
/*
ID: Barry Wang
LANG: C++11
TASK: 
*/
#include <bits/stdc++.h>
using namespace std;
/*---define tricks---*/
#define ALL(v) v.begin(),v.end()
#define UN(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
#define FILL(x,y) memset(x,y,sizeof(x))
#define EACH(v,it) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define FIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define revsort(b,e) sort(b,e),reverse(b,e)
#define X first
#define Y second
#define Chtolly return 0
/*---define types---*/
typedef long long ll;
typedef list<int> li;
typedef queue<int> qi;
typedef deque<int> dqi;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef unsigned int uint;
/*---define variables---*/
const int inf=(1<<29);
int n,lim;
ll h[100005][3],dp[100005][3];
/*---define function---*/

/*---main code---*/
int main(){
	cin>>n;
	for(int i=1;i<=n;++i){
		dp[i][0]=-2147483647;dp[i][2]=-2147483647;dp[i][2]=-2147483647;
		cin>>h[i][0]>>h[i][1]>>h[i][2];
	}
	for(int i=1;i<=n+1;++i){
		for(int j=0;j<3;++j){
			for(int k=0;k<3;++k){
				if(k==j){
					continue;
				}
				dp[i][j]=max(dp[i][j],dp[i-1][k]+h[i-1][k]);
			}
		}
	}
	cout<<max(dp[n+1][0],max(dp[n+1][1],dp[n+1][2]))<<'\n';
	return 0;
}



Measured memory_bytes: 4992
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,fractions
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
def inpl_str(): return list(sys.stdin.readline().split())
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

n = inp()
t = inpln(n)
tmp = t[0]
for i in range(n-1):
    tmp = lcm(tmp, t[i+1])
print(tmp)


Measured memory_bytes: 5264
#include<iostream>
 #include<algorithm>
 using namespace std;
 #define N 100010
 int main(){
 int n,m,h[N],ma[N];
 cin>>n>>m;
 for(int i=1;i<=n;i++){
 cin>>h[i];
 ma[i]=0;
 }
 for(int i=0;i<m;i++){
 int a,b;
 cin>>a>>b;
 ma[a]=max(ma[a],h[b]);
 ma[b]=max(ma[b],h[a]);
 }
 int ans=0;
 for(int i=1;i<=n;i++){
 ans+=h[i]>ma[i];
 }
 cout<<ans<<endl;
 }

Measured memory_bytes: 4408
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
int h[100010]={};
int main(){
    int N,K;
    cin >> N >> K;
    int cnt=0;
    rep(i,N){
        cin >> h[i];
        if(h[i] >= K){
            cnt++;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	//////input///////
	ll N, M;
	std::vector<ll> L;
	std::vector<ll> R;

	cin >> N >> M;
	
	for (int i = 0; i < M; ++i)
	{
		ll a, b;
		cin >> a >> b;
		
		L.push_back(a);
		R.push_back(b);
	}
	/////////compute///////
	std::vector<ll> Ans[N];

	sort(R.begin(), R.end());
	sort(L.begin(), L.end(), greater<ll>());
	ll R_ans = R[0];
	ll L_ans = L[0];

	ll ANS;


	if (R_ans >= L_ans)
	{ 
		ANS = R_ans - L_ans + 1;
	}else{
		ANS = 0;
	}

	cout << ANS << endl;


}

Measured memory_bytes: 4332
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int main() {
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if (s == u) --a;
    else --b;
    cout << a << ' ' << b << endl;
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << endl
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>=0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
#define maxemt(v) *max_element(v.begin(), v.end())
#define minemt(v) *min_element(v.begin(), v.end())
#define lb(v,x) v[lower_bound(v.begin(), v.end(), x) - v.begin()]
#define ub(v,x) v[upper_bound(v.begin(), v.end(), x) - v.begin()]
template<class T> inline bool print(T& x){ cout << x << endl; return true; }
template<class T> inline bool print_(T& x){ cout << x << " "; return true; }
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; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
ll lcm(ll x, ll y){
  return x / gcd(x,y) * y;
}
const int INF = 1e9;
const ll llINF = 1LL<<60;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main(){
  int h, w; cin >> h >> w;
  vector<vector<int>> g(h,vector<int>(w,0));
  rep(i,h){
    rep(j,w){
      char c; cin >> c;
      if(c=='#') g[i][j] = 1;
    }
  }
  rep(i,h){
    rep(j,w){
      if(g[i][j]!=0){
        if(i!=0 && g[i-1][j]!=0) g[i][j]++;  
        if(i!=h-1 && g[i+1][j]!=0) g[i][j]++;
        if(j!=0 && g[i][j-1]!=0) g[i][j]++;
        if(j!=w-1 && g[i][j+1]!=0) g[i][j]++;
      }
      if(g[i][j]==1){ cout << "No"; return 0; }
    }
  }
  cout << "Yes";
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MP make_pair
#define pb push_back
#define ff first
#define ss second
#define sz(x) x.size()
#define all(c) c.begin(),c.end()
#define int long long
#define fr(i,j,x) for(int i=j;i<x;i++)
#define rep(i,j,x) for(int i=j;i<=x;i++)
#define mem(x,val) memset(x,val,sizeof(x))
//#define endl '\n'
#define vi vector<int>
#define pii pair<int,int>
#define piii pair<int,pii>
 
const int mod=1e9+7;
const int N=1e5+10;
const int MAXN=2e6+10;
const int INF=1e18;

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int h[3*N],w[3*N];
map<int,int>col,row;
map<int,set<int>>r,l;
void solve(){
    int H,W,m;
    cin>>H>>W>>m;
    rep(i,1,m){
        cin>>h[i]>>w[i];
        row[h[i]]++;
        col[w[i]]++;
        r[h[i]].insert(w[i]);
        l[w[i]].insert(h[i]);
    }
    int mx=0;
    rep(i,1,W){
        if(col.find(i)!=col.end()){
            if(mx<col[i]){
                mx=col[i];
            }
        }
    }
    vi have;
    rep(i,1,W){
        if(col.find(i)!=col.end()){
            if(mx==col[i]){
                have.pb(i);
            }
        }
    }
    int ans=0;
    rep(i,1,H){
        if(row.find(i)!=row.end()){
            int tot=row[i]+mx;
            int f=0;
            for(auto v:have){
                if(l[v].find(i)==l[v].end()){
                    f=1;
                    break;
                }
            }
            if(f==0){
                tot-=1;
            }
            ans=max(ans,tot);
        }
    }
    cout<<ans<<endl;
}


int32_t main()
{
//     #ifndef ONLINE_JUDGE
//         freopen("inputf.in", "r", stdin);
//         //freopen("outputf.in", "w", stdout);
//     #endif
    SPEED;
    int T=1;
    //cin>>T;
    int t1=1;
    while(true)
    {  
        //cout<<"Case #"<<t1<<": ";
        solve();
        t1++;
        if(t1>T)
            break;
    }
}


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

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

    vector<vector<int>> edges(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        --a; --b; //index 0 start
        edges[a].push_back(b);
    }

    vector<int> ans(n);
    rep(i,n) ans[i] = 0;

    rep(i,q){
        int p,x;
        cin >> p >> x;
        --p; //index 0 start
        ans[p] += x;
    }

    rep(i,n){
        for (auto v: edges[i]){
            ans[v] += ans[i];
        }
    }

    rep(i,n) cout << ans[i] << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 14080
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n);
#define DEBUG printf("%s\n","debug")
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
struct Vertex {
	// edge information
	vector<int> edges_to; //to vertex number
	vector<int> edges_cost; // edge cost
	
	//for dijkstra
	bool done; //conform or not
	int cost; // now cost
	int from;
	
	bool operator<(const Vertex& another) const { // priority --> min
        return another.cost < cost; // order(cost)
    }
	
	bool operator==(const Vertex& another) const {
        return another.cost == cost; // order(cost)
    }
};

const int MAX = 100005;
ll dist[MAX];
struct Vertex v[MAX];

void dfs (int n,int p, ll d){
	dist[n] = d;
	REP(i,v[n].edges_to.size()){
		if (v[n].edges_to[i] == p) continue;
		dfs(v[n].edges_to[i],n,d+v[n].edges_cost[i]);
	}
	
}


int main() {
	int N;
	SCD(N);
	
	REP(i,N-1){
		int a,b,c;
		SCD3(a,b,c);
		v[a].edges_to.PB(b);
		v[a].edges_cost.PB(c);
		
		v[b].edges_to.PB(a);
		v[b].edges_cost.PB(c);
		
	}


	
	queue<PII> Que;
	
	int Q,K;
	SCD2(Q,K);
	
	dfs(K,100003,0);
		
	REP(i,Q){
		int x,y;
		SCD2(x,y);
		Que.push(MP(x,y));
	}
	
	while(!Que.empty()){
		PII now = Que.front(); Que.pop();
		
		PRINTLLD(dist[now.first] + dist[now.second]);
	}
	
	
	return 0;
}










Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

#define rep(i,n) for(int i=0;i<n;i++)

//桁数指定　cout << fixed << setprecision(2)
int main() {
        const double pi=3.1415926535;
  double r=0;
  cin>>r;
  cout<<fixed << setprecision(5)<<(r*2)*pi;
}


Measured memory_bytes: 3784
#include <cassert>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int l = 0;
  int r = 0;
  for (char c: s) {
    if (c == '(') { 
      ++l;
    }
    else {
      if (l > 0) {
        --l;
      }
      else {
        ++r;
      }
    }
  }
  for (int i = 0; i < r; ++i) {
    cout << "(";
  }
  cout << s;
  for (int i = 0; i < l; ++i) {
    cout << ")";
  }
  cout << endl;
}



Measured memory_bytes: 256