akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() { 
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, a[666];
	cin >> n;
	bool ok = true;
	for (int i=1; i<=n; i++) {
		cin >> a[i];
		if (a[i] % 2 == 0 && a[i] % 3 != 0 && a[i] % 5 != 0) ok = false;
	}
	if (ok) cout << "APPROVED"; else cout << "DENIED";
	return 0;
}

Measured memory_bytes: 3560
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(void) {
    string S;
    int res = 0;
    char tmp = '9';
    cin >> S;
    
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == tmp) {
            if (S[i] == '0') {
                S[i] = '1';
                res++;
            }
            else if (S[i] == '1') {
                S[i] = '0';
                res++;
            }
        }
        tmp = S[i];
    }
    cout << res << endl;
    
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int H, W;
char S[20][20];
int visited[20][20];

void bfs(int startH, int startW)
{
    visited[startH][startW] = 0;
    deque< pair<int, int> > dq;
    dq.push_back(make_pair(startH, startW));

    while (dq.size() != 0) {
        pair<int, int> p = dq.front();
        dq.pop_front();
        int curH = p.first;
        int curW = p.second;

        if (curH > 0) {
            if (S[curH - 1][curW] == '.' && visited[curH - 1][curW] == -1) {
                dq.push_back(make_pair(curH - 1, curW));
                visited[curH - 1][curW] = visited[curH][curW] + 1;
            }
        }
        if (curH < H - 1) {
            if (S[curH + 1][curW] == '.' && visited[curH + 1][curW] == -1) {
                dq.push_back(make_pair(curH + 1, curW));
                visited[curH + 1][curW] = visited[curH][curW] + 1;
            }
        }
        if (curW > 0) {
            if (S[curH][curW - 1] == '.' && visited[curH][curW - 1] == -1) {
                dq.push_back(make_pair(curH, curW - 1));
                visited[curH][curW - 1] = visited[curH][curW] + 1;
            }
        }
        if (curW < W - 1) {
            if (S[curH][curW + 1] == '.' && visited[curH][curW + 1] == -1) {
                dq.push_back(make_pair(curH, curW + 1));
                visited[curH][curW + 1] = visited[curH][curW] + 1;
            }
        }
    }
}

int main(int argc, char **argv)
{
    cin >> H >> W;
    REP(i, H) REP(j, W) cin >> S[i][j];

    int ans = 0;
    REP(is, H) {
        REP(js, W) {
            if (S[is][js] == '.') {
                REP(i, H) REP(j, W) visited[i][j] = -1;
                bfs(is, js);
                REP(ig, H) REP(jg, W)
                    if (visited[ig][jg] != -1)
                        ans = max(ans, visited[ig][jg]);
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#define CIN_ONLY 1
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
const int MOD = 1000000007;
const ld PI = acos(ld(-1));
int fix(ll n) { return (n % MOD + MOD) % MOD; }
int fix(ll n, int MOD) { return (n % MOD + MOD) % MOD; }

int a[101];

int main()
{
  if (CIN_ONLY) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
  int n, x;
  cin >> n >> x;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  int i = 0;
  while (i < n && x >= a[i]) {
    x -= a[i];
    ++i;
  }
  if (i == n && x) {
    cout << n - 1 << endl;
  } else {
    cout << i << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
void ABC130(void);
void ABC131(void);
void ABC132(void);
void ABC133(void);
void ABC134(void);
void ABC135(void);
void ABC136(void);
void ABC137(void);
void ABC138(void);
void ABC139(void);

int main(void){
    ABC135();
}

void ABC135(){
    int a,b;
    cin>>a>>b;
    if((a+b)%2==0)cout<<(a+b)/2<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    int a, b;
    cin >> a >> b;
    int t = min(a, b);
    int n = max(a, b);
    for (int i = 0; i < n; i++) cout << t;
    cout << 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();
        int[] a=new int[200010];

        int[] arr=new int[200010];
        for (int i = 2; i <=n; i++) {
            a[i]=sc.nextInt();
        }
        for(int i=2;i<=n;i++)arr[a[i]]++;
        for (int i = 1; i <=n ; i++) {
            System.out.println(arr[i]);

        }








    }
}





Measured memory_bytes: 62672
n = int(input())
s = list(input())
rignt = 0
left = 0
#rignt = 1

for i in range(n):
  if s[i] == "E":
    rignt += 1

if s[0] == "E":
  rignt -= 1

ans = rignt

for i in range(1,n):
  if s[i-1] == "E":
    left += 1
    
  if s[i] == "E":
    rignt -= 1
    
  temp = rignt + (i-left) 
  
  if temp < ans :
    ans = temp
    
print(ans)

Measured memory_bytes: 5920
import java.io.PrintWriter;
import java.util.*;

public class Main {

    private static long gcd(long a, long b) {
        if ( a== 0)return b;
        return gcd(b % a, a);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        //String s = in.next();


        int n = in.nextInt(), k = in.nextInt();
        long ans = 0;
        for (int i = 1; i < n; i++) {
            ans += ans / (k - 1);
            ans++;
        }
        out.println(ans);

        out.flush();
    }

}



Measured memory_bytes: 26404
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

struct node {
  int id;
  int weight;
  struct node *next;
};
struct node **list;
int *pass, *dist;

void Insert(int, int, int);
int Bellman(int, int, int);

int main(void)
{
  int i, v, e, r, s, t, d;
  scanf("%d %d %d", &v, &e, &r);
  pass = (int*)malloc(sizeof(int) * v);
  dist = (int*)malloc(sizeof(int) * v);
  list = (struct node**)malloc(sizeof(struct node*) * v);
  for (i = 0; i < v; i++) list[i] = NULL;
  for (i = 0; i < e; i++) {
    scanf("%d %d %d", &s, &t, &d);
    Insert(s,t,d);
  }
  if (Bellman(r, v, e) == 1) {
    for (i = 0; i < v; i++) {
      if (dist[i] == INT_MAX) printf("INF\n");
      else printf("%d\n", dist[i]);
      free(list[i]);
    }
  } else {
    printf("NEGATIVE CYCLE\n");
    for (i = 0; i < v; i++) {
      free(list[i]);
    }
  }
  free(pass);
  free(dist);
  free(list);
  return 0;
}

void Insert(int a, int b, int weight)
{
  struct node *p = (struct node*)malloc(sizeof(struct node));
  p->id = b;
  p->weight = weight;
  p->next = list[a];
  list[a] = p;
}

int Bellman(int p, int size, int esize)
{
  int i;
  for (i = 0; i < size; i++){
    dist[i] = INT_MAX;
    pass[i] = 0;
  }
  dist[p] = 0;
  while (1) {
    int flag = 0;
    for (i = 0; i < size; i++){
      struct node *n;
      if (dist[i] == INT_MAX) continue;
      for (n = list[i]; n != NULL; n = n->next) {
        int w = n->weight;
        if (w + dist[i] < dist[n->id]) {
          dist[n->id] = w + dist[i];
          pass[n->id]++;
          if (pass[n->id] >= esize) {
            return 0;
          }
          flag = 1;
        }
      }
    }
    if (!flag) break;
  }
  return 1;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int,int>;
const int INF=1001001001;
const int NMAX=8;
const int MOD=1000000007;
const int dbase=80*160;


int check (int x){
	int a=0;
	while(x%2==0){
		x/=2;
		a++;
	}
	return a;
}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main()
{
	ll n,m;
	cin>>n>>m;
	vector<int> a(n);
	ll ans=0;
	ll now;
	rep(i,n){
		cin>>a[i];
		int temp=check(a[i]);
	//	cout<<temp<<endl;
		if (i>0 and temp!=now){
			cout<<ans;
			return ans;
		}
		now=temp;
	}
	ll l=1;
	rep(i,n){
		l=lcm(l,a[i]/2);
	}
	//cout<<l<<endl;
	ans=m/l;
	if (ans%2==0)
	cout<<ans/2;
	else cout<<ans/2+1;

}


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

#define int long long

using namespace std;

const int N = 2e5 + 10;

int a[N], s;
bool vis[N];
vector<int> v;

void dfs(int x)
{
    if (vis[x]) 
    {
        s = x;
        return;
    }
    vis[x] = 1;
    v.push_back(x);
    dfs(a[x]);
}


int32_t main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);    
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    dfs(1);
    int l = 0;
    while (k && l < v.size() && v[l] != s)
    {
        --k;
        ++l;
    }
    if (!k)
    {
        if (l < v.size()) cout << v[l];
        else
        {
            cout << s;
        }
    }
    else
    {
        int z = v.size() - l;
        k %= z;
        l += k;
        cout << v[l];
    }
    return 0;
}


Measured memory_bytes: 12648
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair

using namespace std;

int main()
{
   FAST/**/
   ll n;cin>>n;
   string s;
   cin>>s;
   
   for(ll i=0;i<s.length();i++)
   {
       ll temp = s[i] - 'A';
       temp+=n;
       temp%=26;
       cout<<char(temp+'A');
   }
   
   return 0;
}  
   

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

ll MOD = (ll) (1e9 + 7);
const ll INF = (ll) 1e11;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);

    int n;
    cin >> n;
    bool appear[100010] = {};
    int remainder = 0;
    int cnt = 0;

    rep(i, n) {
        int a;
        cin >> a;
        if (appear[a]) {
            remainder++;
        } else {
            appear[a] = true;
            cnt++;
        }
    }

    if (remainder % 2 == 1) cnt--;
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main() {
  int A, B, C, ans;
  cin >> A >> B >> C;

  if (C <= A + B) {
    ans = B + C;
  } else {
    ans = A + 2 * B + 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,-1,0,1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const ll mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    int n,m; cin >> n >> m;
    vl b(n), p(m);
    rep(i,n) cin >> b[i];
    rep(i,m) cin >> p[i];
    vvl state(2);
    int now = 0;
    rep(i,m){
        int sw = i & 1;
        REP(j,now,now+p[i]){
            state[0].push_back(sw);
            state[1].push_back(1-sw);
        }
        now += p[i];
    }
    vl ans(2,0);
    rep(k,2){
        vl c = b;
        rep(i,n){
            if(c[i] != state[k][i]){
                int id = -1;
                REP(j,i+1,n){
                    if(state[k][i] == c[j]){
                        id = j;
                        break;
                    }
                }
                if(id == -1){
                    ans[k] = inf;
                    break;
                }
                for(int j=id-1; j>=i; j--) swap(c[j],c[j+1]), ans[k]++;
            }
        }
    }
    cout << min(ans[0], ans[1]) << "\n";
}


Measured memory_bytes: 3156
import java.util.Scanner;

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

        while (true) {
            int n = sc.nextInt();
            int r = sc.nextInt();
            if (n == 0 && r == 0)
                break;

            int[] card = new int[n];
            for(int i=0;i<n;i++){
                card[i] = i+1;
            }

            int[] temp = new int[n];

            for(int i=0;i<r;i++){
                int p = sc.nextInt();
                int c = sc.nextInt();
                
                for(int j=0;j<c;j++)
                    temp[c-1-j] = card[n-p-j];

                for(int j=n-p+1;j<n;j++)
                    card[j-c] = card[j];

                for(int j=0;j<c;j++)
                    card[n-c+j] = temp[j];
            }
            System.out.println(card[n-1]);
        }
    }
}



Measured memory_bytes: 37156
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,ans = 0;
  cin >> A >> B;
  
  for(int i=0;i<2;i++){
  	if(A >= B){
  		ans += A;
    	A--;
  	}else{
  		ans += B;
    	B--;
  	}
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  
  int a,b,i,d;
  
  while(1){
  scanf("%d %d",&a,&b);
if(a==0 && b==0)break;
  
  for(i=0;i<a;i++){
 
    for(d=0;d<b;d++)
{
    printf("#");
  } 
  printf("\n");
  
   
  }
  printf("\n");
  }
   
  
  return 0;

  }



Measured memory_bytes: 2608
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    int[] m = new int[n];

    for (int i = 0; i < n; i++) {
      m[i] = sc.nextInt();
      x -= m[i];
    }

    Arrays.sort(m);

    int count = 0;

    while (x >= m[0]) {
      x -= m[0];
      count++;
    }

    System.out.println(n+count);

  }

}


Measured memory_bytes: 21844
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)

ll a[300001] = {};
int main() {
	ll n; cin >> n;
	rep(i, 0, 3 * n)cin >> a[i];
	sort(a, a + 3 * n);
	reverse(a, a + 3 * n);
	ll ans = 0;
	rep(i, 0, n) {
		ans += a[i * 2 + 1];
	}

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

Measured memory_bytes: 2560
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;

long n;

void solve();

int main() {
  cin >> n;
  solve();
}

void solve() {
  long ans = 0;
  if (n % 2 == 0) {
    ans += n / 2;
    ans *= (n - 1);
  } else {
    ans += (n - 1) / 2;
    ans *= n;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"math/rand"
	"os"
	"strconv"
	"sync"
)

func main() {
	n := ScanInt()
	s := ScanStringSlice(n)
	m := make(map[string]int)

	max := math.MinInt32
	for i := range s {
		m[s[i]]++
		if m[s[i]] > max {
			max = m[s[i]]
		}
	}
	r := []string{}

	for k, v := range m {
		if v == max {
			r = append(r, k)
		}
	}
	quicksort(r)
	for i := range r {
		P(r[i])
	}

	close(O)
	oWg.Wait()
}

func quicksort(a []string) []string {
	if len(a) < 2 {
		return a
	}

	left, right := 0, len(a)-1

	pivot := rand.Int() % len(a)

	a[pivot], a[right] = a[right], a[pivot]

	for i, _ := range a {
		if a[i] < a[right] {
			a[left], a[i] = a[i], a[left]
			left++
		}
	}

	a[left], a[right] = a[right], a[left]

	quicksort(a[:left])
	quicksort(a[left+1:])

	return a
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}


Measured memory_bytes: 35072
N, Q = list(map(int, input().split()))
S = input()

start_position = []
prev = ""
counter = 0
for s in S:
    if s == "C" and prev == "A":
        counter += 1
        start_position.append(counter)
    else:
        start_position.append(counter)
    prev = s

for _ in range(Q):
    l, r = list(map(int, input().split()))
    print(start_position[r-1] - start_position[l-1])


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

int main() {
  int a,b,x,y;
  
  cin>>a>>b;
  
  x=a*b;
  y=x%2;
  
  if(y==0){
    cout<<"Even"<<endl;
  }
  else{
    cout<<"Odd"<<endl;
  }
}

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

const int bB = 10;
const int B = 1 << bB;

int up(int x) {
	return (x + (1 << bB) - 1) >> bB;
}

int down(int x) {
	return x >> bB;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q;
	cin >> n >> q;
	const int H = up(n);
	vector<int> bv(H, 0), v(n, 0);
	while (q--) {
		int com, x, y;
		cin >> com >> x >> y; x--;
		if (com == 0) {
			v[x] += y;
			bv[down(x)] += y;
		}
		else {
			int res = 0;
			for (int i = x; i < y && i < (up(x) << bB); i++) {
				res += v[i];
			}
			if (up(x) <= down(y)) {
				for (int i = up(x); i < down(y); i++) {
					res += bv[i];
				}
				for (int i = down(y) << bB; i < y; i++) {
					res += v[i];
				}
			}
			printf("%d\n", res);
		}
	}
	return 0;
}



Measured memory_bytes: 3252
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		int[]A = new int[N];
		for(var i=0;i<N;i++){
			A[i] = int.Parse(str[i]);
		}
		Array.Sort(A,(x,y)=>y-x);
		int sum = 0;
		for(var i=1;i<N;i++){
			sum += A[i];
		}
		string ans = "No";
		if(sum > A[0]){
			ans = "Yes";
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


const int MOD=1000000007;
int INF=100100100100100;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
string s[450];
bool used[450][450];
int h,w;

P dfs(int x,int y,char c){
  used[x][y]=true;
  P p=P(0,0);
  if((x+y)%2)p.S=1;
  else p.F=1;
  rep(i,4){
    int nx=x+dx[i],ny=y+dy[i];
    if(0<=nx && nx<h && 0<=ny && ny<w && !used[nx][ny] && s[nx][ny]==c){
      P q=dfs(nx,ny,c);
      p.F+=q.F,p.S+=q.S;
    }
  }
  return p;
}
signed main(){
  cin>>h>>w;
  rep(i,h)cin>>s[i];
  rep(i,h){
    rep(j,w){
      if((i+j)%2){
        if(s[i][j]=='.')s[i][j]='#';
        else s[i][j]='.';
      }
      used[i][j]=false;
    }
  }
  //rep(i,h)cout<<s[i]<<endl;
  
  int ans=0;
  rep(i,h){
    rep(j,w){
      if(!used[i][j]){
        P p=dfs(i,j,s[i][j]);
        ans+=p.F*p.S;
        //cout<<i<<" "<<j<<" "<<p.F*p.S<<endl;
      }
    }
  }
  cout<<ans<<endl;
      
  return 0;
}

Measured memory_bytes: 16444
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main()
{

    int n,i;
    cin>>n;
    int d=(n/2);
    int a[n];
    for(i=0;i<n;i++)
    {

        cin>>a[i];

    }
      sort(a,a+n);
      cout<<a[d]-a[d-1];
}


Measured memory_bytes: 640
import math
import copy
import sys
import fractions
# import numpy as np
# import statistics
import decimal
import heapq
import collections
import itertools
import bisect

# from operator import mul

sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===


n = int(input())


ans = 0
dic = {}

for i in range(1, n+1):
    for j in range(1, n+1):
        tmp = math.gcd(i,j)
        if tmp in dic:
            dic[tmp] += 1
        else:
            dic[tmp] = 1

for key in dic:
    for i in range(1, n+1):
        ans += math.gcd(key, i) * dic[key]

print(ans)

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

#define LL long long
#define VI vector<int>
#define VB vector<bool>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14
#define MINUS(a) memset(a,0xff,sizeof(a))

const std::string YES = "YES";
const std::string Yes = "Yes";
const std::string NO = "NO";
const std::string No = "No";

using namespace std;


int did[101010];
vector<int> E[301010];
int id=100001;


void dfs(int cur,int x, vector<vector<int>> &station_graph) {
    if(did[cur]==x) return;
    did[cur]=x;
    E[id].push_back(cur);
    E[cur].push_back(id);
    FOE(&r,station_graph[cur]) {
        dfs(r, x, station_graph);
    }
}

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

    vector<vector<pair<int,int>>> company_station(1010101);
    FOR(i, 0, M) {
        int p, q, c;
        cin >> p >> q >> c;
        company_station[c].emplace_back(make_pair(p, q));
    }

    MINUS(did);
    vector<vector<int>> station_graph(N + 1);
    FOR(company, 0, 1010100) {
        if(company_station[company].size()) {
            vector<int> station_list;
            FOE(&e, company_station[company]) {
                station_graph[e.first].push_back(e.second);
                station_graph[e.second].push_back(e.first);

                station_list.push_back(e.first);
                station_list.push_back(e.second);
            }

            FOE(&r, station_list) if(did[r]!=company) {
                    dfs(r, company, station_graph);
                    id++;
                }
            FOE(&e,company_station[company]) {
                station_graph[e.first].clear();
                station_graph[e.second].clear();
            }
        }
    }

    vector<int> dist(303030, INT_MAX);
    dist[1] = 0;
    queue<int> que;
    que.push(1);
    while (not que.empty()) {
        int x = que.front();que.pop();
        FOE(&e, E[x]) {
            if(dist[e]>dist[x]+1) {
                dist[e]=dist[x]+1;
                que.push(e);
            }
        }
    }

    if(dist[N]>0x3f0000) dist[N]=-1;
    else dist[N]/=2;
    cout<<dist[N]<<endl;

    return 0;
}

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


int main()
{
	int n,m,dx[8]={0,0,1,1,1,-1,-1,-1},dy[8]={1,-1,1,0,-1,1,0,-1};
	char a[55][55]={};
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(a[i][j]=='#')cout<<a[i][j];
			else
			{
				int sum=0;
				for(int k=0;k<8;k++)
				{
					if(a[i+dx[k]][j+dy[k]]=='#')sum++;
				}
				cout<<sum;
			}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
std::string s;
int main() {
	std::cin >> s;
	long long ans = 0;
	for (int bit = 0; bit < (1 << ((int)s.size() - 1)); bit++) {
		long long num = s[0] - '0';
		long long sum = 0;
		for (int i = 0; i < (int)s.size() - 1; i++) {
			if (bit & (1 << i)) {
				sum += num;
				num = 0;
			}
			num = num * 10 + s[i + 1] - '0';
		}
		sum += num;
		ans += sum;
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
// In the name of God
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <iomanip>
#include <ctime>
#include <queue>
using namespace std;
 
template <typename T>
T next_int() {  
    T x = 0, p = 1;
    char ch;
    do { ch = getchar(); } while(ch <= ' ');
    if (ch == '-') {
        p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * p;
}
 
const int max_n = (int)2e5 + 227 + 1;
const int max_int = (int)1e9 + 227 + 1;
const int mod = (int)1e9 + 7;
 
bool used[10];
 
inline bool f(int n) {
    while(n) {
        if(used[n % 10]) return 0;
        n /= 10;
    }
    return 1;
}
 
int main() {
//    freopen(".in", "r", stdin);
 
    int n = next_int<int>();
 
    int m = next_int<int>();
 
    for(int i = 0; i < m; i++) used[next_int<int>()] = 1;
 
    while(!f(n)) n++;
 
    cout << n << "\n";
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
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 ll MOD = 1e9+7;

vector<int> G[200100];
int d[200100];
bool isvisit[200100];

void dfs(int v, int c){
    isvisit[v] = true;
    d[v] = c;
    for(int i = 0; i < G[v].size(); i++){
        int next = G[v][i];
        if(isvisit[next]) continue;
        dfs(next, c+1);
    }
}

int main(){
    int N;
    cin >> N;
    REP(i,N-1){
        int a,b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dfs(0, 0);
    int ma = -1;
    int idx;
    REP(i,N){
        int x = d[i];
        if(x > ma){
            ma = x;
            idx = i;
        }
    }

    fill(isvisit, isvisit+N, false);

    dfs(idx, 0);

    sort(d, d+N);

    int step = d[N-1] + 1;

    //cout << step << endl;
    int num = (step+1)%3;

    bool win;
    //cout << step << endl;
    if(step == 0){
        win = false;
    }
    else if(step == 1){
        win = true;
    }
    else if(num == 0){
        win = false;
    }
    else if(num == 1){
        win = true;
    }
    else if(num == 2){
        win = true;
    }


    if(win){
        cout << "First" << endl;
    }
    else{
        cout << "Second" << endl;
    }
    return 0;
}


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

int main() {
    int N; cin >> N;
    double ans = 0.;
    for (int i = 0; i < N; i++)
    {
        double x; string s; cin >> x >> s;
        if(s=="BTC") x = x * 380000.0;
        ans += x;
    }
    cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <deque>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

int main()
{
    deque <long> dq;
    int n,i;
    long a;
    cin>>n;
    for(i=0; i<n; ++i)
    {
        cin>>a;
        if(i%2==0)
        {
            dq.push_back(a);
        }
        else
        {
            dq.push_front(a);
        }
    }
    deque <long>::iterator ator;
    if(i%2==0)
    {
        for(ator=dq.begin(); ator!=dq.end(); ++ator)
        {
            a=*ator;
            cout<<*ator;
            cout<<" ";
        }
    }
    else
    {
        for(ator=dq.end()-1; ator!=dq.begin()-1; --ator)
        {
             a=*ator;
            cout<<*ator;
            cout<<" ";
        }
    }
    dq.clear();
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define mkp make_pair
#define pii pair<int,int>
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=1e2+5;
int dis[maxn*maxn*3];
char mp[maxn][maxn];
int n,m;
vector<pair<int,int> >v[maxn*maxn*3];
void dji(){
	priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
	for(int i=0;i<=n*m+1;i++)dis[i]=inf;
	q.push(mkp(0,0));
	dis[0]=0;
	while(!q.empty()){
		auto tmp=q.top();q.pop();
		int x=tmp.second;
		//cout<<x<<" fuck "<<dis[x]<<endl;
		for(auto p:v[x]){
			int y=p.first;
			//cout<<y<<" "<<p.second<<" "<<dis[y]<<endl;
			if(dis[x]+p.second<dis[y]){
				dis[y]=dis[x]+p.second;
			
				q.push(mkp(dis[y],y));
			}
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%s",mp[i]+1);
	if(mp[1][1]=='#')
	v[0].push_back(mkp(1,1));
	else 	v[0].push_back(mkp(1,0));
	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(i+1<=n){
				if(mp[i][j]=='.'&&mp[i][j]!=mp[i+1][j])v[j+(i-1)*m].push_back(mkp(j+i*m,1));
				else v[j+(i-1)*m].push_back(mkp(j+i*m,0));
			}
			if(j+1<=m){
				if(mp[i][j]=='.'&&mp[i][j]!=mp[i][j+1])
				v[j+(i-1)*m].push_back(mkp(j+1+(i-1)*m,1));
				else v[j+(i-1)*m].push_back(mkp(j+1+(i-1)*m,0));
			}
		}
	}
	dji();
	/*for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cout<<dis[(i-1)*m+j]<<" ";
		}
		cout<<endl;
	}*/

	cout<<dis[n*m];
	return 0;
}

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

using namespace std;

#define pq priority_queue
#define MZ 1000000007

int num[300005];

int main()
{
    int n,a,b,x,y=0,m;
    scanf("%d%d%d",&n,&a,&b);
    if(a+b-1>n || 1LL*a*b<1LL*n)
        printf("-1\n");
    else
    {
        m=n;
        for(int i=1;i<=b;i++)
            num[i]=b-i+1;
        y=b;
        a--;
        n-=b;
        while(a)
        {
            x=n/a;
            for(int i=1;i<=x;i++)
                num[y+i]=y+x-i+1;
            n-=x;
            a--;
            y+=x;
        }
        for(int i=1;i<=m;i++)
            printf("%d ",num[i]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3328
# C
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
#print(N)#
#print(A)#
#print(B)#

def zeros(n): return [0 for i in range(n)]

m = 0
count = 0
for i in range(N):
    if A[i]<B[i]: 
        count += 1
        m += A[i] - B[i]
#print(m, count)#
D = zeros(N)
for i in range(N): D[i] = [max(A[i] - B[i], 0), i]
D.sort()
D.reverse()
# mの分だけDの大きいものから移動
#print(D)#
for i in range(N):
    if m>=0: break
    m += D[i][0]
    count += 1
else: count = -1
print(count)

Measured memory_bytes: 26208
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdint>
using namespace std;

int main()
{
  string s;

  cin >> s;
  if (s[0] == s[1] && s[0] == s[2] && s[0] == s[3]) {
    cout << "No";
  } else if (s[0] == s[1] && s[2] == s[3]) {
    cout << "Yes";
  } else if (s[0] == s[2] && s[1] == s[3]) {
    cout << "Yes";
  } else if (s[0] == s[3] && s[1] == s[2]) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define mkpr(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()

typedef long long int ll;

ll general,total;
ll num[ten5];
ll num2[ten5];
//char cmap[10][10];
//priority_queue<ll> pqll;   //decrease
//priority_queue<double> pqd;
//stack<int> stk;
//vector<pair<ll,ll>> vpll;
//vector<pair<double,double>> vpdd;
//vector<ll> vll[ten52];
//vector<double> vd;
//deque<ll> deq[55];
//list<int> li;
//set<int> sint;
//set<ll> sll;
//map<ll,ll> mp;

/*ll cmp(pair<ll,ll> a,pair<ll,ll> b)
{
    return a.first<b.first;
    //arrising
}*/


int main()
{
    double ans=0.0,half,d,d1,d2;
    //float f,g,h;
    string s,s1;
    //char now,pre,c1,c2;
    long long int sum,sum2,n1,n2,n3;
    long long int m,n,o,i,j,k=1;
    long long int a,a1,a2,a3,a4,a5,a6;
    sum=sum2=n1=n2=n3=0;
    a=a1=a2=a3=a4=a5=a6=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>m;
        num[i]=m;
        sum+=m;
    }
    for(i=0;i<n;i++)
    {
        cin>>m;
        num2[i]=m;
        sum2+=m;
    }
    if(sum>sum2)
    {
        cout<<"No";
        return 0;
    }
    sum=sum2=0;
    for(i=0;i<n;i++)
    {
        if(num[i]!=num2[i] && k==1) k=0;
        a=num[i]-num2[i];
        if(a>0) sum2+=a;
        else
        {
            a=abs(a);
            if(a&1==1)
            {
                sum+=(a+1)/2;
                sum2++;
            }
            else sum+=a/2;
        }
    }
    if(k==1) cout<<"Yes";
    else
    {
        if(sum2>sum) cout<<"No";
        else cout<<"Yes";
    }
    return 0;
}





Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int64_t N, A, B;
    cin >> N >> A >> B;
    if(N < A+B-1 || A*B < N){
        cout << -1 << endl;
        return 0;
    }

    vector<int> num(B, 1);
    num[B-1] = A;
    int rest = N-(A+B-1);
    while(rest) for(int i=0; i<B-1; i++) if(rest) num[i]++, rest--;

    vector<vector<int>> ans(B);
    int pt = 1;
    for(int i=B-1; i>=0; i--) for(int j=0; j<num[i]; j++) ans[i].push_back(pt++);
    for(int i=0; i<B; i++) for(int a : ans[i]) cout << a << " ";
    cout << endl;
}

Measured memory_bytes: 13568
#include <stdio.h>

int main(void){
    int p,q,r;
    int sum[3];
    scanf("%d %d %d", &p, &q, &r);
    
    sum[0] = p + q;
    sum[1] = q + r;
    sum[2] = r + p;
    
    if(sum[1] > sum[0] && sum[2] > sum[0]){
        printf("%d\n", sum[0]);
    }else if(sum[2] > sum[1]){
        printf("%d\n", sum[1]);
    }else{
        printf("%d\n", sum[2]);
    }
     
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	int a[100001];
	int b[100001];
	for(int i = 0; i < n + 1; i++){
		cin >> a[i];
	}
	for(int i = 0; i < n; i++){
		cin >> b[i];
	}
	long long int ans = 0;
	for(int i = 0; i < n; i++){
		if(a[i] + a[i + 1] <= b[i]){
			ans += a[i] + a[i + 1];
			a[i + 1] = 0;
		}else if(a[i] < b[i]){
			ans += b[i];
			a[i + 1] -= b[i] - a[i];
		} else {
			ans += b[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	x := sc.NextIntArray()

	mn := -1
	for i := 0; i+K-1 < N; i++ {
		j := i + K - 1
		A := 0
		if x[i] < 0 && x[j] > 0 {
			A = abs(x[i])*2 + abs(x[j])
		} else {
			A = max(abs(x[i]), abs(x[j]))
		}

		B := 0
		if x[i] < 0 && x[j] > 0 {
			B = abs(x[i]) + abs(x[j])*2
		} else {
			B = max(abs(x[i]), abs(x[j]))
		}

		C := min(A, B)

		if mn == -1 || mn > C {
			mn = C
		}
	}

	fmt.Println(mn)

}
func max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

int main(){
    int n,m;
    cin >>n>>m;
    int Lmax = 1;
    int Rmin = pow(10,5);
    for(int i=0; i<m; ++i){
        int l,r; cin >> l >> r;
        Lmax = max(Lmax,l);
        Rmin = min (Rmin,r);    
    }
    int ans = Lmax<=Rmin ? Rmin-Lmax+1 : 0;
    cout << ans << endl;
}

Measured memory_bytes: 384
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/

const int MAX_N = 1000005;

/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i] >> b[i] >> c[i];
    int dp[MAX_N][3];

    for(int i = 1; i <= n; ++i){
        dp[i][0] = max(dp[i - 1][1] + b[i - 1], dp[i - 1][2] + c[i - 1]);
        dp[i][1] = max(dp[i - 1][0] + a[i - 1], dp[i - 1][2] + c[i - 1]);
        dp[i][2] = max(dp[i - 1][0] + a[i - 1], dp[i - 1][1] + b[i - 1]);
    }

    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;

return 0;
}

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

#define fast ios_base:: sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long

int32_t main(){
	fast;
	int x,a;
	cin >> x >> a;
	if(x < a)	cout << 0;
	else		cout << "10";
}

Measured memory_bytes: 256
//Md Fahad
// CSE 18

#include<bits/stdc++.h>


using  namespace  std;

#define PI              acos(-1.0)
#define lcm(a,b)        (a * (b / __gcd(a,b)))
#define en '\n'

#define READ_IN freopen("Input.txt","r",stdin);
#define READ_OUT freopen("Output.txt","w",stdout);
#define Infi                0x3f3f3f3f

const int fx[] = {+1,-1,+0,+0};                         // 4 X directions
const int fy[] = {+0,+0,+1,-1};                         // 4 Y directions
const int fx8[] = {+0,+0,+1,-1,-1,+1,-1,+1};            // King X Moves
const int fy8[] = {-1,+1,+0,+0,+1,+1,-1,-1};            // King Y Moves
const int kx[] = {-2, -2, -1, -1,  1,  1,  2,  2};      // Knight X Moves
const int ky[] = {-1,  1, -2,  2, -2,  2, -1,  1};      // Knight Y Moves



int  Set    (int N,int pos) {return N=N | (1<<pos);}    /// turn a bit on
int  reset  (int N,int pos) {return N= N & ~(1<<pos);}  /// turn a bit off
bool check  (int N,int pos) {return (bool)(N & (1<<pos));} /// check, if a bit is on or not

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

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


typedef long long int           ll;
typedef unsigned long long int  llu;

int main(void)
{
    //READ_IN;



   long double a,b,c;

    cin >> a >> b >> c;

    long double eps = 1.0E-14;

    if((sqrt(a)+sqrt(b)+eps)<sqrt(c)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}



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

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define F0R(i, n) for (int i = 0; i < (n); i++)
#define print(x) cout << x << '\n'
#define watch(x) cout << (#x) << " is " << (x) << endl

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

const int INF = 1e9 + 5;
const int MAX_N = 1e5 + 5;
int dp[MAX_N][3];

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> days(n, vector<int> (3,0));
  for (vector<int>& i : days){
      for (int& j : i){
          cin >> j;
      }
  }
  for (int i = 0; i < 3; i++){
      dp[0][i] = days[0][i];
  }

  for (int i = 1; i < n; i++){
      for (int a : {0,1,2}){
        int newMax = 0;
          for (int b: {0,1,2}){
              if (a != b){
                  newMax = max(newMax, dp[i-1][b]);
              }
          }    
        dp[i][a] = days[i][a] + newMax;
        } 
    }
    
  cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
  return 0;
}

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

int main(void){
  int n;
  cin >> n;
  int s[n];
  for(int i = 0; i < n; i++) cin >> s[i];
  sort(s, s + n);
  int ans = 0;
  for(int i = 0; i < n; i++) ans += s[i];
  if(ans % 10 != 0) {
    cout << ans << endl;
    return 0;
  }
  int temp = -1;
  for(int i = 0; i < n; i++){
    if(s[i] % 10 != 0){
      temp = s[i];
      break;
    }
  }
  if(temp != -1) {
    cout << ans - temp << endl;
    return 0;
  }
  cout << "0" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip> 
using namespace std; 
#define rep(i,a,b)		for(long int i=a;i<=b;i++)
#define MOD 1e9+7

string a,b;
bool flag = false;
int main() 
{ 
	ios::sync_with_stdio(false);
    cin.tie(NULL);  
    
    
	cin>>a>>b;
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	reverse(b.begin(),b.end());
	if(a<b)
		cout<<"Yes";
	else
		cout<<"No";
}
	

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

int n, a;
int cnt[100];

int main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) { cin >> a; cnt[a]++; }
	
	for (i = n - 1; i >= 0; i--) { if (cnt[i]) break; }
	int tyo = i;
	
	//直径を作る
	for (i = 0; i < tyo + 1; i++) {
		int dist = tyo - (i / 2);
		if (cnt[dist] <= 0) { cout << "Impossible" << endl; return 0; }
		else { cnt[dist]--; }
	}
	
	//他の部分を作る
	for (i = 0; i < (tyo + 1) / 2 + 1; i++) if (cnt[i]) { cout << "Impossible" << endl; return 0; }
	cout << "Possible" << endl;
	return 0;
}

Measured memory_bytes: 256