akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;

using namespace std;

int main() 
{   
    v_string a(2);
    v2_string b(2, v_string(3));
    cin >> a[0] >> a[1];
    
    irep(i, 2) {
        irep(j, 3) {
            b[i][j] = a[i][j];
        }
    }

    irep(i, 2) { 
        irep(j, 3) {
            if(b[i][j] != b[1-i][2-j]) {
                //cout << b[1-i][2-j];
                cout << "NO" << endl; 
                return 0;
            }
        }
        //cout << endl;
    }

    cout << "YES" << endl;
    return 0;
}
    



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

typedef long long ll;

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

	string inp;
	cin >> inp;
	cout << inp;
	if (inp.back() == 's')
		cout << "es\n";
	else
		cout << "s\n";
	return 0;
}

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

public class Main {


    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt();
        long arr[] = new long[n];
        for(int i=0;i<n;i++)
        {
            arr[i]=sc.nextLong();
        }

        Arrays.sort(arr);
        long ans=1;
        if(arr[0]==0)
        {
            System.out.println(0);
        }
        else
        {
            boolean flag=false;
            for(int i=n-1;i>=0;i--)
            {

                if(arr[i]>1000000000000000000l/ans)
                {
                    System.out.println(-1);
                    flag=true;
                    break;
                }
                ans=ans*arr[i];
            }
                if(!flag)
                {
                    System.out.println(ans);
                }

        }
    }
}


Measured memory_bytes: 61640
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

n = gets.chomp

flag = false
n.length.times do |i|
  if n[i].to_i == 7
    flag = true
  end
end

puts flag ? "Yes" : "No"

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

int main()
{
	int N, visited[4] = { 0, };
	cin >> N;
	while (N--) {
		string s;
		cin >> s;
		if (s == "AC")visited[0]++;
		else if (s == "WA")visited[1]++;
		else if (s == "TLE")visited[2]++;
		else visited[3]++;
	}
	cout << "AC x " << visited[0] << "\n";
	cout << "WA x " << visited[1] << "\n";
	cout << "TLE x " << visited[2] << "\n";
	cout << "RE x " << visited[3] << "\n";
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  int p[N];
  for ( int i = 0; i < N; i++ ) {
    cin >> p[i];
  }
  sort(p,p+N);
  
  int sum = 0;
  for ( int i = 0; i < K; i++ ) {
    sum += p[i];
  }
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<map>
using namespace std;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n; scanf("%d",&n);
    map<string, int> mp;
    while(n--){
        string s; cin >> s;
        mp[s]++;
    }  
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d", mp["AC"], mp["WA"], mp["TLE"], mp["RE"]);
    return 0;
}

Measured memory_bytes: 3796
N = int(input())
A = list(map(int, input().split()))

r = 0
std_sum = 0 # standard summation
xor_sum = 0 # xor summation
count = 0

for l in range(N):
    while (r != N and std_sum + A[r] == xor_sum ^ A[r]):
        std_sum += A[r]
        xor_sum ^= A[r]
        r += 1
 
    count += r - l
    std_sum -= A[l]
    xor_sum ^= A[l]
 
print(count)

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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
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; }

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


int main() {
    cout<<fixed<<setprecision(10);

    vint x(5); rep(i,5) cin>>x[i];

    rep(i,5){
        if(x[i] == 0){
            cout<<i+1<<endl;
            return 0;
        }
    }

    return 0;

}

Measured memory_bytes: 3548
#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;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

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

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

int main() {
  ll N;
  cin>>N;
  multiset<ll,greater<ll>> all;
  rep(i,1LL<<N){
    ll t;
    cin>>t;
    all.insert(t);
  }
  multiset<ll,greater<ll>> now;
  now.insert(*all.begin());
  all.erase(all.begin());
  bool ok = true;
  while(now.size()!=1LL<<N){
    auto ite = all.begin();
    queue<ll> q;
    for(auto x:now){
      while(ite != all.end()&&x<=*ite){
        ite++;
      }
      if(ite==all.end()) {
        ok = false;
        break;
      }
      q.push(*ite);
      ite++;
    }
    if(!ok) break;
    while(!q.empty()){
      ll t = q.front();
      q.pop();
      all.erase(all.find(t));
      now.insert(t);
    }
  }
  if(ok) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 16692
seg = [[0, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 1, 1, 0], 
[1, 0, 1, 1, 0, 1, 1], 
[1, 0, 0, 1, 1, 1, 1],
[1, 1, 0, 0, 1, 1, 0], 
[1, 1, 0, 1, 1, 0, 1], 
[1, 1, 1, 1, 1, 0, 1], 
[0, 1, 0, 0, 1, 1, 1], 
[1, 1, 1, 1, 1, 1, 1], 
[1, 1, 0, 1, 1, 1, 1]]

while True :
    n = int(input())
    if n == -1 :
        break
    pre = [0]*7
    for i in range(n) :
        num = int(input())
        post = seg[num]
        for j in range(7) :
            if pre[j] == post[j] :
                print(0, end='')
            else :
                print(1, end='')
        print()
        pre = post


Measured memory_bytes: 5600
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <set>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> P;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const int inf = 1e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

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

vector<ll> fac,inv,finv;

void initcom(){
    fac=inv=finv=vector<ll>(1e6);
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(ll i=2;i<1e6;++i){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll com(int n,int k){
    if(n<0||k<0) return 0;
    if(n<k) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
ll mopow(ll a,ll x,ll mod){
    ll res=1;
    while(x>0){
        if(x&1) res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}
int main(){
    string s;cin>>s;
    int n=(int)s.size();
    int i=0,j=n-1;
    int cnt=0;
    while(i<j){
        while(i<j&&s[i]=='x'&&s[j]=='x'){
            i++;j--;
            if(i>=j) break;
        }
        while(i<j&&s[i]=='x'){
            i++;
            cnt++;
            if(i>=j) break;
        }
        while(i<j&&s[j]=='x'){
            j--;
            cnt++;
            if(i>=j) break;
        }
        if(i<j&&s[i]!=s[j]){
            cout<<-1<<endl;
            return 0;
        }
        i++;j--;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3748
fun main(args: Array<String>) {
    val s = readLine()!!
    var ans = ""

    s.forEach { c ->
        when(c) {
            '0' -> ans += '0'
            '1' -> ans += '1'
            'B' -> ans = ans.slice(0 until ans.length-1)
        }
    }

    println(ans)
}

Measured memory_bytes: 33788
import math

class Culuculation():
  H = 0
  N = 0
  A = []
  
  def __init__(self):
    self.H, self.N = (int(x) for x in input().split(' '))
    #self.A = [int(x) for x in input().split(' ')]
    for x in input().split(' '):
      self.A.append(int(x))
    
  def culuculation(self):
    print('Yes' if self.H <= sum(self.A) else 'No')
    
def main():
  tmp = Culuculation()
  tmp.culuculation()

if __name__=='__main__':
  main()

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

int main() {
  std::string b;
  std::cin >> b;
  if (b == "A") {
    std::cout << "T" << "\n";
  }
  if (b == "C") {
    std::cout << "G" << "\n";
  }
  if (b == "G") {
    std::cout << "C" << "\n";
  }
  if (b == "T") {
    std::cout << "A" << "\n";
  }
  return 0;
}

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

int main() {

    int a,b;
    
    scanf("%d %d" , &a ,&b);
    
    if(a>8 || b>8){
        puts(":(");
    }else{
        puts("Yay!");
    }

    return 0;

}


Measured memory_bytes: 128
import java.util.Scanner;
import java.util.Queue;
import java.util.LinkedList;

public class Main {
	static int[][] field;
	static String[] wall;
	static int[] dx = {1, 0, -1, 0};
	static int[] dy = {0, 1, 0, -1};
	static int w, h;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			w = sc.nextInt();
			h = sc.nextInt();
			if (w == 0) {
				break;
			}
			field = new int[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					field[i][j] = 0;
				}
			}
			field[0][0] = 1;
			
			wall = new String[2*h-1];
			sc.nextLine();
			for (int i = 0; i < 2 * h - 1; i++) {
				wall[i] = sc.nextLine();
			}
			//debug();
			solve();
		}
	}
	
	public static void debug() {
		for (int i = 0; i < wall.length; i++) {
			System.out.println(wall[i]);
		}
	}
	
	public static void solve() {
		Queue<Field> que = new LinkedList<Field>();
		que.offer(new Field(0, 0));
		while (que.peek() != null) {
			Field tmp = que.poll();
			if (tmp.x == w - 1 && tmp.y == h - 1) {
				break;
			}
			for (int i = 0; i < 4; i++) {
				int nx = tmp.x + dx[i];
				int ny = tmp.y + dy[i];
				//System.out.println(tmp.x + " " + tmp.y + " " + nx + " " + ny + ": ");
				if (0 <= nx && nx < w && 0 <= ny && ny < h && !isWall(tmp.x, tmp.y, nx, ny) && field[ny][nx] == 0) {
					que.offer(new Field(nx, ny));
					field[ny][nx] = field[tmp.y][tmp.x] + 1;
				}
			}
		}
		System.out.println(field[h-1][w-1]);
	}
	
	// 隣接する2マスに壁があればtrue，そうでなければfalseを返すメソッド
	public static boolean isWall(int x1, int y1, int x2, int y2) {
		if (y1 == y2) {
			// 横2マスの場合
			//System.out.println("'" + wall[2*y1].charAt(x1 + x2) + "'");
			if (wall[2*y1].charAt(x1 + x2) == '1') {
				return true;
			} else {
				return false;
			}
		} else {
			// 縦2マスの場合
			//System.out.println("'" + wall[y1+y2].charAt(2 * x1) + "'");
			if (wall[y1+y2].charAt(2 * x1) == '1') {
				return true;
			} else {
				return false;
			}
		}
	}
}

class Field {
	int x;
	int y;
	Field(int x, int y) {
		this.x = x;
		this.y = y;
	}
}

Measured memory_bytes: 38940
open Str

type btree = Node of node | Nil and
     node = {k : int; l : btree; r : btree}

let preorder f tr =
  let rec iter = function
      Nil -> ()
    | Node n -> f n.k; iter n.l; iter n.r
  in iter tr; print_newline ()
  
let inorder f tr =
  let rec iter = function
      Nil -> ()
    | Node n -> iter n.l; f n.k; iter n.r
  in iter tr; print_newline ()

let insert k tr =
  let rec iter = function
      Nil -> Node {k = k; l = Nil; r = Nil}
    | Node n -> if n.k = k then Node n
                else if n.k < k then Node {n with r = iter n.r}
                else Node {n with l = iter n.l}
  in iter tr

let find k tr =
  let rec iter = function
      Nil -> "no"
    | Node n -> if n.k = k then "yes"
                else if n.k < k then iter n.r
                else iter n.l
  in iter tr

let read_list () =
  split (regexp " +") (read_line ())

let () =
  let n = read_int () in
  let rec read tr x =
    if x = 0 then ()
    else match read_list () with
           "print" :: _ -> begin
             inorder (fun i -> print_string @@ " " ^ (string_of_int i)) tr;
             preorder (fun i -> print_string @@ " " ^ (string_of_int i)) tr;
             read tr (x-1)
           end
         | "insert" :: ns :: _ -> read (insert (int_of_string ns) tr) (x-1)
         | "find" :: ns :: _ -> begin
             find (int_of_string ns) tr |> print_endline;
             read tr (x-1)
           end
         | _ -> failwith "read"
  in
  read Nil n

Measured memory_bytes: 37336
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main()
{
    int N;
    cin >> N;
    vector<int> X(N), copyX(N);
    
    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }

    copyX = X;
    sort(copyX.begin(), copyX.end());

    for (int i = 0; i < N; i++) {
        cout << (X[i] <= copyX[N/2-1] ? copyX[N/2] : copyX[N/2-1]) << endl;
    }
}

Measured memory_bytes: 3840
use proconio::input;

const MOD : i64 = 998_244_353;

fn main() {
    input! {
        n : usize,
        s : usize,
        a : [usize; n]
    };
    let mut dp = vec![0; s+1];
    dp[0] = 1;
    for &t in &a {
        for j in (0..=s).rev() {
            if j + t <= s {
                dp[j+t] = (dp[j+t] + dp[j]) % MOD;
            }
            dp[j] = 2 * dp[j] % MOD;
        }
    }
    println!("{}", dp[s]);
}


Measured memory_bytes: 2260
n=int(input())
ki=[[] for _ in range(n)]

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

odd=[-1]*n
odd[0]=0
todo=[0]
while todo:
    v=todo.pop()
    for nv in ki[v]:
        if odd[nv]==-1:
            odd[nv]=abs(odd[v]-1)
            todo.append(nv)
from collections import Counter
co=Counter(odd)
ans=[0]*n
if co[1]<=n//3:
    cnt1=1
    cnt2=0
    cnt3=1
    for i in range(n):
        if odd[i]==1 and 3*cnt3<=n:
            ans[i]=3*cnt3
            cnt3+=1
        else:
            if cnt1%3==0:cnt1+=1
            if cnt1<=n:
                ans[i]=cnt1
                cnt1+=1
            else:
                ans[i]=n-n%3-cnt2*3
                cnt2+=1

elif co[0]<=n//3:
    cnt1=1
    cnt2=0
    cnt3=1
    for i in range(n):
        if odd[i]==0 and 3*cnt3<=n:
            ans[i]=3*cnt3
            cnt3+=1
        else:
            if cnt1%3==0:cnt1+=1
            if cnt1<=n:
                ans[i]=cnt1
                cnt1+=1
            else:
                ans[i]=n-n%3-cnt2*3
                cnt2+=1
else:
    cnt1=1
    cnt2=1
    cnt3=1
    for i in range(n):
        if odd[i]==1:
            if 3*cnt1-2<=n:
                ans[i]=3*cnt1-2
                cnt1+=1
            else:
                ans[i]=3*cnt3
                cnt3+=1
        else:
            if 3*cnt2-1<=n:
                ans[i]=3*cnt2-1
                cnt2+=1
            else:
                ans[i]=3*cnt3
                cnt3+=1
print(*ans,sep=' ')



Measured memory_bytes: 123544
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n;
	string res;
	cin>>n;
	while(n)
	{
		if(n%26==0)
		{
			res='z'+res;
			n=n-26;
		}
			
		else
			res=char('a'-1+n%26)+res;
		n=n/26;
	}
	cout<<res;
	return 0; 
 } 

Measured memory_bytes: 3628
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	ar := make([]int, n)
	br := make([]int, n)
	cr := make([]int, n)
	for i := range ar {
		ar[i] = nextInt()
	}
	sort.Ints(ar)
	for i := range br {
		br[i] = nextInt()
	}
	sort.Ints(br)
	for i := range cr {
		cr[i] = nextInt()
	}
	sort.Ints(cr)

	dr := make([]int, n)
	bi := n - 1
	for i := n - 1; i >= 0; i-- {
		for bi >= 0 {
			if ar[i] < br[bi] {
				dr[bi] = i + 1
				bi--
			} else {
				break
			}
		}
	}
	for i := 1; i < n; i++ {
		dr[i] += dr[i-1]
	}
	er := make([]int, n)
	ci := n - 1
	for i := n - 1; i >= 0; i-- {
		for ci >= 0 {
			if br[i] < cr[ci] {
				er[ci] += dr[i]
				ci--
			} else {
				break
			}
		}
	}
	ans := 0
	for _, v := range er {
		ans += v
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7552
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long n, m, tmp, ans;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    if (n >= 2) {
        ans += n * (n - 1) / 2;
    }
    if (m >= 2) {
        ans += m * (m - 1) / 2;
    }
    cout << ans << E;
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.reflect.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        StringBuilder ans = new StringBuilder("Christmas");
        for(int i = 25; i > n; --i){
            ans.append(" Eve");
        }
        System.out.println(ans);
    }
}

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


int main()
{
    int n;
    std::cin >> n;
    std::set<int> a;
    for (int i = 0; i < n; i++) {
        int tmp;
        std::cin >> tmp;
        a.insert(tmp);
    }

    while (a.size() > 1) {
        std::set<int> b;
        int d = *a.begin();
        b.insert(d);

        for (auto x : a) {
            int dx = x % d;
            if (dx)
                b.insert(dx);
        }
        a.swap(b);
    }

    std::cout << *a.begin() << std::endl;
    return 0;
}


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

int main(){
int a,b,c,d;
cin >> a >> b >> c >> d;
while(a>0 && c>0){
c-=b;
a-=d;
}
if (a<=0 && c<=0) cout << "Yes\n";
else if (a<=0) cout << "No\n";
else cout << "Yes\n";
}

Measured memory_bytes: 3620
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    const int INF = 1001001001;
    
    int n, m; cin >> n >> m;
    int L = -1, R = INF;

    rep(i, m){
        int l, r; cin >> l >> r;
        L = max(L, l);
        R = min(R, r);
    }
    if(L > R) cout << 0 << endl;
    else cout << R-L+1 << endl;
    
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

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

int main(){
  
  //入力
  int N; int Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  
  //ACを累積和で数える（ACnum[i]は0-indexedでi番目の文字の右側までのACの数）
  int ACnum[N+1];
  ACnum[0]=0;
  for(int i=0;i<N;i++){
    ACnum[i+1]=ACnum[i];
    if(S[i]=='A'&&S[i+1]=='C'){
      ACnum[i+1]++;
    }
  }
  
  //累積和を解凍する
  for(int i=0;i<Q;i++){
    int L; int R;
    cin >> L >> R;
    L--; R--;
    cout << ACnum[R]-ACnum[L] << endl;
  }
  
}

Measured memory_bytes: 1408
N = int(input())
l1 = [input().split() for i in range(N)]
for i in range(len(l1)):
    l1[i][1] = int(l1[i][1])
    l1[i].append(i+1)
l2 = l1
l2.sort(key=lambda x:(x[0],-x[1]))
for j in l2:
    print(j[2])

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

#include<vector>
#include<map>
#include<math.h>
#include<stack>
#include<unordered_map>

using namespace std;
const int N = 1e6;
int a[N], b[N], c[N];
int dp[N][3];
int main() {

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

    return 0;
}

Measured memory_bytes: 7552
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int a = sc.nextInt();
  int b = sc.nextInt();
  int c = sc.nextInt();
  boolean d = false;
  for(int i = 0;i < a*b;i += a){
    if(i%b == c){
      d = true;
      break;
    }
  }
  if(d)System.out.println("YES");
  else System.out.println("NO");
}}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<long long> vec1(n);
    long long tgt = 0;
    long long res = 0;
    for (int i = 0; i < n; i++) {
        cin >> vec1.at(i);
        if (tgt >= vec1.at(i)){
            res += tgt - vec1.at(i);
        } else {
            tgt = vec1.at(i);
        }
    }
    cout << res;
}


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

int main(){
 int n;
 cin>>n;
 int W;
 cin>>W;
 int v[n];
 int w[n];
 for(int i=0;i<n;i++){
     cin>>v[i]>>w[i];
 }   

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

 for(int i=1;i<=n;i++){
     for(int j=0;j<=W;j++){
         if(j<w[i-1]) DP[i][j]=DP[i-1][j];
         else{
             if(DP[i-1][j]>DP[i][j-w[i-1]]+v[i-1]) DP[i][j]=DP[i-1][j];
             else DP[i][j]=DP[i][j-w[i-1]]+v[i-1];
         }
     }
 }
 cout<<DP[n][W]<<endl;

 return 0;
}


Measured memory_bytes: 7028
#include <stdio.h>
int n, a, b, x, y;
int z[600][600];
int w[600][600];
int dx[8];
int dy[8];
int main() {
	scanf("%d%d%d", &n, &a, &b);
	while (!(a % 2)) {
		x++;
		a /= 2;
	}
	while (!(b % 2)) {
		y++;
		b /= 2;
	}
	a = 1 << (x / 2);
	b = 1 << (y / 2);
	if (x % 2) {
		dx[0] = a; dy[0] = a;
		dx[1] = -a; dy[1] = a;
		dx[2] = a; dy[2] = -a;
		dx[3] = -a; dy[3] = -a;
	}
	else {
		dx[0] = a;
		dy[1] = a;
		dx[2] = -a;
		dy[3] = -a;
	}
	if (y % 2) {
		dx[4] = b; dy[4] = b;
		dx[5] = -b; dy[5] = b;
		dx[6] = b; dy[6] = -b;
		dx[7] = -b; dy[7] = -b;
	}
	else {
		dx[4] = b;
		dy[5] = b;
		dx[6] = -b;
		dy[7] = -b;
	}
	for (int i = 0; i < 2 * n; i++) {
		for (int j = 0; j < 2 * n; j++) {
			if (!z[i][j]) {
				for (int k = 0; k < 4; k++) {
					x = i + dx[k];
					y = j + dy[k];
					if (0 <= x && x < 2 * n && 0 <= y && y < 2 * n) {
						z[x][y] = 1;
					}
				}
			}
			if (!w[i][j]) {
				for (int k = 4; k < 8; k++) {
					x = i + dx[k];
					y = j + dy[k];
					if (0 <= x && x < 2 * n && 0 <= y && y < 2 * n) {
						w[x][y] = 1;
					}
				}
			}
		}
	}
	x = 0;
	for (int i = 0; i < 2 * n; i++) {
		for (int j = 0; j < 2 * n; j++) {
			if (!(z[i][j] | w[i][j])) {
				x++;
				printf("%d %d\n", i, j);
				if (x == n * n)return 0;
			}
		}
	}
}

Measured memory_bytes: 4508
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	ll ans1= 0, ans2 = 0;
	for(int i = 0; i<=30; i++)
		for(int j = 0; j<=30; j++)
		{
			ll y = 100*(i)*a+j*100*b;
			for(int k = 0; k<=100; k++)
				for(int h = 0; h<=100; h++)
				{
					ll sugar = c*k+d*h;
					if(y+sugar<=f && (e*y/100)>=sugar)
					{
						if(ans1>0 && (double(sugar)/(y+sugar))>(double(ans2)/ans1))
						{
							ans1 = y+sugar; ans2 = sugar;
						}
						else if(ans1==0)
						{
							ans1 = y+sugar; ans2 = sugar;
						}
					}
				}
		}

	cout<<ans1<<" "<<ans2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };

int main() {
	IN(LL, h, w);
	OUT(min(h, w) == 1 ? 1 : ce(h * w, 2));
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    long long int A;
    cin>>A;
    int minians=100;
    for(long long int i=1;i<=100000;i++){
        if(A%i!=0)continue;
        long long int kari=max(i,A/i);
        if(kari<10)minians=1;
        else if(kari<100)minians=min(minians,2);
        else if(kari<1000)minians=min(minians,3);
        else if(kari<10000)minians=min(minians,4);
        else if(kari<100000)minians=min(minians,5);
        else if(kari<1000000)minians=min(minians,6);
        else if(kari<10000000)minians=min(minians,7);
        else if(kari<100000000)minians=min(minians,8);
        else if(kari<1000000000)minians=min(minians,9);
        else if(kari<10000000000)minians=min(minians,10);
    }
    cout<<minians<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define ull unsigned long long

int main() {
	ull n, m, ans;
	cin >> n >> m;
	if (n > m / 2) {
		ans = m / 2;
	} else {
		n *= 2;
		ans = (n + m) / 4;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r",stdin);
	freopen("output.txt", "w",stdout);
	#endif


	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin>>n;
	int dp[1000000][3];
	int x,y,z;
	cin>>x>>y>>z;
	dp[0][0]=x;
	dp[0][1]=y;
	dp[0][2]=z;
	for(int i=1;i<n;i++){
		int a,b,c;
		cin>>a>>b>>c;
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a;
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b;
		dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c;
	}
	cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
	return 0;

}
	/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/
	

Measured memory_bytes: 4832
#include<stdio.h>
#include<string.h>
int main()
{
   char S[101];
   scanf("%s",S);
   int l,i,a,b=0;
   l=strlen(S);
  if(l%2==0)
  {
    for(i=0;i<l/2;i++)
    {
      if(S[i]!=S[l-i-1])
       b++;
    }
    printf("%d",b);
  }
  else 
  { a=l-1;
    for(i=0;i<a/2;i++)
      {
      if(S[i]!=S[l-i-1])
      b++;
      }
    printf("%d",b);
  }
  return 0;
}
      


Measured memory_bytes: 1732
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
num = [0] * 100010
b = [0] * q
c = [0] * q
for i in range(q):
    b[i], c[i] = map(int, input().split())

for i in a:
    num[i] += 1

s = sum(a)

for i in range(q):
    s += (c[i]-b[i])*num[b[i]]
    num[c[i]] += num[b[i]]
    num[b[i]] = 0
    print(s)


Measured memory_bytes: 22216
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
ll mod = 1000000007LL;
ll dp[100100];
int main() {
  int n,m;
  cin >> n >> m;
  vi a(n+1,0);
  rep(i,m){
    int x;
    cin >> x;
    a[x] = 1;
  };
  dp[0] = 1;
  rep(i,n){
    if(!a[i+1])dp[i+1]+=dp[i];
    dp[i+1]%=mod;
    if(!a[i+2])dp[i+2]+=dp[i];
    dp[i+2]%=mod;
  }
  cout<<dp[n]<<endl;
  return 0;
}

Measured memory_bytes: 4424
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;

class Dice {
    public:
        int s[6], tmp;
        Dice(int nums[6]){
            s[0] = nums[0];
            s[1] = nums[1];
            s[2] = nums[2];
            s[3] = nums[3];
            s[4] = nums[4];
            s[5] = nums[5];
        }
        
        void N(){
            tmp = s[0];
            s[0] = s[1];
            s[1] = s[5];
            s[5] = s[4];
            s[4] = tmp;
        }   
        void E(){
            tmp = s[0];
            s[0] = s[3];
            s[3] = s[5];
            s[5] = s[2];
            s[2] = tmp;
        }
        void W(){
            tmp = s[0];
            s[0] = s[2];
            s[2] = s[5];
            s[5] = s[3];
            s[3] = tmp;
        }
        void S(){
            tmp = s[0];
            s[0] = s[4];
            s[4] = s[5];
            s[5] = s[1];
            s[1] = tmp;
        }
        int show_top(){
            return s[0];
        }
        
        int show_right(int num1, int num2){
            if(s[5] == num1) {
                N();
                N();
            }
            else if(s[1] == num1) N();
            else if(s[2] == num1) W();
            else if(s[3] == num1) E();
            else if(s[4] == num1) S();
            if(s[1] == num2) return s[2];
            else if(s[2] == num2) return s[4];
            else if(s[4] == num2) return s[3];
            else if(s[3] == num2) return s[1];
        }
        
};



int main(void){
   int nums1[6], nums2[6];
   int i, j;
   for(i=0; i<6; i++){
       cin >> nums1[i];
   }
   for(i=0; i<6; i++){
       cin >> nums2[i];
   }
   Dice dice1(nums1);
   Dice dice2(nums2);
   bool judge = true;
   
    for(i=0; i<6; i++){
        for(j=0; j<6; j++){
            if(i == j || i + j == 5) continue;
            if(dice1.show_right(nums1[i], nums1[j]) != dice2.show_right(nums1[i], nums1[j])) {
                judge = false;
                break;
            }
        }
    }
    if(judge) cout << "Yes" << endl;
    else cout << "No" <<endl;
    return 0;
}


Measured memory_bytes: 3104
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>

using std::cin;
template <typename T>
using vec = std::vector<T>;
template <typename T>
using min_heap = std::priority_queue<T, vec<T>, std::greater<T>>;

typedef long long lld;
const int MAXC = 3000;
const int MAXN = 55;
const lld MAXT = 1e18; // 3e12;
int C[MAXN];
int D[MAXN];
int M, N, S;

struct Edge {
  int v;
  int a, b;
};
vec<Edge> G[MAXN];
bool seen[MAXN];
int visited;

lld T[MAXN][MAXC+5];
// T[i][j] = min time to arrive at city i with j silver coins.

struct State {
  lld time;
  int u, s;

  bool operator > (const State& o) const {
    return time > o.time;
  }
};

void dijkstra(int src) {
  min_heap<State> pq;

  pq.push({0, src, S});
  T[src][S] = 0;
  seen[src] = true;
  ++visited;

  while (!pq.empty()) {
    State cur = pq.top();
    pq.pop();

    if (T[cur.u][cur.s] < cur.time) {
      continue;
    }

/*
printf("cur[t,u,s]=[%lld, %d, %d]\n",
cur.time, cur.u, cur.s
);
*/

    if (!seen[cur.u]) {
      seen[cur.u] = true;
      if (++visited == N) {
        break;
      }
    }

    for (auto& nxt: G[cur.u]) {
      lld time = cur.time;
      int silver = cur.s;
      if (silver < nxt.a) {
        int xchg = (nxt.a - silver + C[cur.u] - 1) / C[cur.u];
        silver = std::min(xchg * C[cur.u] + silver, MAXC);
        time += 1LL * xchg * D[cur.u];
      }

      auto transit = [&time, &silver, &nxt, &pq](){
        lld nt = time + nxt.b;
        int ns = silver - nxt.a; 
        if (nt < T[nxt.v][ns]) {
          pq.push({nt, nxt.v, ns});
          T[nxt.v][ns] = nt;
        }
      };
      transit();

      while (silver < MAXC) {
        silver = std::min(silver + C[cur.u], MAXC);
        time += D[cur.u];
        transit();
      }
    }    
  }
}

void output() {
  for (int t = 2; t <= N; ++t) {
    lld ans = *std::min_element(T[t], T[t]+MAXC+1);
    printf("%lld\n", ans);
  }
}

void fastio() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
}

void init() {
  for (int i = 1; i <= N; ++i) {
    G[i].clear();
    seen[i] = false;
  }
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j <= MAXC; ++j) {
      T[i][j] = MAXT;
    }
  }
  S = std::min(MAXC, S);
  visited = 0;
}

int main() {
  fastio();
  cin >> N >> M >> S;
  init();
  for (int i = 0; i < M; ++i) {
    int a, b, u, v;
    cin >> u >> v >> a >> b;
    G[u].push_back({v, a, b});
    G[v].push_back({u, a, b});
  }
  for (int i = 1; i <= N; ++i) {
    cin >> C[i] >> D[i];
  }
  dijkstra(1);
  output();
  return 0;
}

Measured memory_bytes: 36896
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

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

int main() {
	int n;
	vector<int> data; // count
	
	
	cin >> n;
	vector<int> in(n);
	REP(i, n) scanf("%d", &in[i]);
	
	data.push_back(0);
	
	int cnt = 1;
	FOR(i, 1, n) {
		if (in[i - 1] == in[i]) {
			data.push_back(cnt);
			cnt = 0;
		}
		cnt++;
	}
	data.push_back(cnt);
	data.push_back(0);
	
	int ans = 0;
	FOR(i, 2, data.size()) ans = max(ans, data[i - 2] + data[i - 1] + data[i]);
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
string l;
vector<string> vec;
int N;
int main() {
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> l;
    vec.push_back(l);
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  cout << vec.size() << endl;
  return 0;
}


Measured memory_bytes: 11604
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;

#define printLn(X) cout << X << endl
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

int main(){
	int N, Y;
	cin >> N >> Y;
	rep(i, N + 1){
		rep(j, N - i + 1){
			int k = N - i - j;
			if(i * 10000 + j * 5000 + k * 1000 == Y){
				printLn(i << " " << j << " " << k);
				return 0;
			}
		}
	}
	printLn("-1 -1 -1");
	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
x = gets.split.map(&:to_f)
y = gets.split.map(&:to_f)

d = []
d1, d2, d3 = 0, 0, 0

n.times{ |i|
  d[i] = (x[i] - y[i]).abs
  d1 += d[i]
  d2 += d[i]**2
  d3 += d[i]**3
}

puts d1
puts d2**(1/2.0)
puts d3**(1/3.0)
puts d.max

Measured memory_bytes: 8816
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
 
struct S{
  P p,q;
  S(P p,P q): p(p),q(q) {}
};
 
P calc(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}
 
P calc( S a, S b){
  return calc( a.p , a.q , b.p , b.q );
}
 
double cross(P a,P b){
  return imag( b * conj(a) );
}
 
double calcArea(P a,P b,P c,P d){
  b-=a;c-=a;d-=a;
  double res=0;
  res+= abs( cross(b,c) )*0.5;
  res+= abs( cross(c,d) )*0.5;
  return res;
}
 
int main(){
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    vector< P > top,right,left,bottom;
    for(int i=0;i<n;i++){
      double k;
      cin>>k;
      bottom.push_back( P(k,0) );
    }
    for(int i=0;i<n;i++){
      double k;
      cin>>k;
      top.push_back( P(k,1) );
    }
    for(int i=0;i<n;i++){
      double k;
      cin>>k;
      left.push_back( P(0,k) );
    }
    for(int i=0;i<n;i++){
      double k;
      cin>>k;
      right.push_back( P(1,k) );
    }
     
    vector< S > sh,sw;
    sh.push_back( S( P(0,0) , P(0,1) ) );
    for(int i=0;i<n;i++){
      sh.push_back( S( bottom[i],top[i] ) );
    }
    sh.push_back( S( P(1,0) , P(1,1) ) );
     
    sw.push_back( S( P(0,0) , P(1,0) ) );
    for(int i=0;i<n;i++){
      sw.push_back( S( left[i],right[i] ) );
    }
    sw.push_back( S( P(0,1) , P(1,1) ) );
 
    double ans=-1;
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
        P ld = calc( sh[i], sw[j] );
        P lu = calc( sh[i+1], sw[j] );
        P rd = calc( sh[i], sw[j+1] );
        P ru = calc( sh[i+1], sw[j+1] );
        ans=max(ans, calcArea(ld,rd,ru,lu) );
      }
    }
 
    printf("%.6f\n",ans);
  }
  return 0;
}

Measured memory_bytes: 3196
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int n;
ll k;
vector<ll> a;

bool check(ll x) {
  ll cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (x < a[i]) {
      cnt += a[i] / x;
    }
  }
  return cnt <= k;
}

int main() {
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  ll ok = a[n - 1], ng = 0;
  while (1 < abs(ok - ng)) {
    ll mid = (ok + ng) / 2;
    if (check(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok << endl;
  return 0;
}

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

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

  int ans = 0;
  for (int i = 1; i <= N; i += 2) {
    int count = 0;
    for (int j = 1; j <= N; j++) {
      if (i % j == 0) {
        count += 1;
      }
    }
    if (count == 8) {
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace AtCorder1
{
    class AtCorder163A
    {
        static void Main(string[] args)
        {
            long r = long.Parse(Console.ReadLine());
            double circle = 2 * 3.14 *r;

            
                Console.WriteLine(circle);
            }
        }
    }


Measured memory_bytes: 27456
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

LL n, z, w;
LL a[101010];

int main() {
	cin >> n >> z >> w;
	REP(i, n)cin >> a[i];
	LL cz = z, cw = w;
	if (n == 1) {
		cout << abs(a[0] - w) << endl;
		return 0;
	}
	cout << max((abs(a[n - 2] - a[n - 1])), abs(a[n - 1] - w)) << endl;

}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){ 
    string s; cin >> s;
    int len = s.size(); s += "DD";
    ll res = 0, cnt; bool mode = false;
    rep(i, len){
        if(!mode){
            if(s[i] == 'A'){
                mode = true;
                cnt = 1;
                }
        }else{
            if(s[i] == 'B' && s[i+1] == 'C'){
                res += cnt;
                i++;
            }else if(s[i] == 'A') cnt++;
            else mode = false;
        }  
    }
    cout << res << ln;
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  // vector<vector<int>> v(n, vector<int> (n-1));
  int v[1010][1010];
  rep(i, n) rep(j, n-1){
    cin >> v[i][j];
    v[i][j]--;
  }
  vector<int> index(n, 0);
  // int index[1010];

  for (int i = 1; i <= ((n-1) * n) / 2; i++) {
    vector<bool> battled(n, false);
    // bool battled[1010];
    // rep(j, 1010) battled[j] = false;
    // cout << "===" << endl;
    // cout << i << endl;
    bool flag = true;
    for (int j = 0; j < n; j++) {
      if(index[j] >= n-1) continue;
      int enemy = v[j][index[j]];
      if(index[j] >= n-1 || index[enemy] >= n-1) continue;
      if(v[enemy][index[enemy]] == j && !battled[j] && !battled[enemy]){
        flag = false;
        battled[j] = true;
        battled[enemy] = true;
        index[enemy]++;
        index[j]++;
      }
    }
    if(flag) break;

    flag = true;
    rep(j, n){
      if(index[j] < n-1) {
        flag = false;
        break;
      }
    }
    if(flag){
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;

}


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

#define int long long

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

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

int N;
vector<string>W;

signed main(){
    cin>>N;
    W=vector<string>(N);
    rep(i,N)cin>>W[i];
    bool ok=true;
    rep(i,N-1){
        if(W[i].back()!=W[i+1].front()){
            ok=false;
        }
    }
    sort(all(W));
    if(unique(all(W))!=W.end()){
        ok=false;
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
s = input()
mod = 2019
mod_lst = [0]*mod
mod_lst[0] =1
x = 0
t = 1
for i in reversed(s):
    x += int(i) * t
    y = x % mod
    t *= 10
    t %= mod
    mod_lst[y] += 1


count = 0
for j in mod_lst:
    a = j*(j-1)//2
    count += a
print(count)

Measured memory_bytes: 9324