akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    long long int m=0;
    long long int a=0;
    long long int r=0;
    long long int c=0;
    long long int h=0;
    string s;
    for (int i=0;i<n;i++) {
        cin>>s;
        if (s.at(0)=='M') {
            m++;
        } else if (s.at(0)=='A') {
            a++;
        } else if (s.at(0)=='R') {
            r++;
        } else if (s.at(0)=='C') {
            c++;
        } else if (s.at(0)=='H') {
            h++;
        }
    }
    std::deque<long long int> deq{m,a,r,c,h};
    std::deque<int> num{0,1,2,3,4};
    long long int count=0;
    for (int j=0;j<3;j++) {
        for (int k=j+1;k<5;k++) {
            for (int l=k+1;l<5;l++) {
                if (deq[num[j]]!=0&&deq[num[k]]!=0&&deq[num[l]]!=0) {
                    count+=deq[num[j]]*deq[num[k]]*deq[num[l]];
                }
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
n = int(input())
ans = float('inf')
divisors = make_divisors(n)
for i in range(len(divisors)//2+1):
    d1 = divisors[i]
    d2 = n // d1
    d1,d2 = str(d1),str(d2)
    #print(d1,d2,max(len(d1),len(d2)))
    ans = min(ans,max(len(d1),len(d2)))
print(ans)

Measured memory_bytes: 3064
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) int __VA_ARGS__; in(__VA_ARGS__)
//オーバーフロー対策
#define INL(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using Bint = boost::multiprecision::checked_cpp_int;
Bint modpow(Bint a, Bint n, Bint mod)
{
    Bint res = 1;
    while (n > 0)
    {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int f(int n)
{
    if (n == 1) return 1;
    return n * f(n-1);
}

void solve()
{
    IN(n);
    double x[8], y[8];
    rep(i, n)
    {
        cin >> x[i] >> y[i];
    }
    double d = 0;
    rep(i, n)
    {
        rep(j, n)
        {
            d += sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        }
    }
    cout << d / (n) << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define INF (1<<29)

int dp[100][128];
int a[100],b[100];


int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)dp[i][j]=INF;
	for(int i=0;i<n;i++)dp[i][i]=0;
	for(int len=2;len<=n;len++){
		for(int i=0;i<=n-len;i++){
			int j=i+len-1;
			for(int k=i;k<j;k++){
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+a[i]*b[k]*a[k+1]*b[j]);
			}
		}
	}
	cout<<dp[0][n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1200
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace

solve :: Int -> Int -> [(Int,Int)] -> Int
solve bN bW wvs = (VU.length (VU.takeWhile (<= bW) vecFin)) - 1
  where
  vec0 = VU.cons 0 (VU.replicate (bN*1000) (bW+1))
  vecFin = foldl' op vec0 wvs
  op vec (w,v) =
    VU.zipWith min vec ((VU.replicate v w) VU.++ VU.map (+ w) vec)


readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_bN,bs_bW]:remLines1 = remLines0
      bN = readBInt bs_bN
      bW = readBInt bs_bW
      wvs = map (\[x1,x2] -> (readBInt x1,readBInt x2)) remLines1
  in solve bN bW wvs

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 2044
#include<stdio.h>
int main(void){
int x,y,z;
int tmp;
scanf("%d %d %d",&x,&y,&z);
if(y < x){
tmp = y;
y = x;
x = tmp;
}
if(z < x){
tmp = z;
z = x;
x = tmp;
}
if(z < y){
tmp = z;
z = y;
y = tmp;
}
printf("%d %d %d\n",x,y,z);
return 0;
}


Measured memory_bytes: 2108
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;

#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl

int main() {
    //freopen(".in", "r", stdin);
    int n;
    scanf("%d",&n);
    ll sum=0;
    for(int i=1;;i++)
    {
        sum+=i;
        if(sum>=n) return 0*printf("%d\n",i);
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
#define mod(int)(1000000007)
using namespace std;
const int INF = 1000000000000;
int pre[345678]; //最短路の直前の頂点
int cost[3456][3456]; //cost[u][v]は辺e=(u,v)のコスト(残りINF)
int d[345678]; //頂点sからの最短距離
bool used[345678]; //すでに使われたかのグラフ
void dijkstra(int V, int s) { //頂点数と始点
	fill(d, d + V + 1, INF);
	fill(used, used + V + 1, false);
	fill(pre, pre + V + 1, -1);
	d[s] = 0;
	while (true) {
		int v = -1;
		//まだ使われていない頂点のうちの最小距離を探す
		for (int u = 1; u <= V; u++) {
			if (!used[u] && (v == -1 || d[u] < d[v])) v = u;
		}
		if (v == -1) break;
		used[v] = true;
		for (int u = 1; u <= V; u++) {
			if (d[u] > d[v] + cost[v][u]) {
				d[u] = d[v] + cost[v][u];
				pre[u] = v;
			}
		}
	}
}
//頂点tへの最短路
vector<int> get_path(int t) {
	vector<int> path;
	for (; t != -1; t = pre[t]) path.push_back(t); //tがsになるまでpre[t]を追う
	//逆順に
	reverse(path.begin(), path.end());
	return path;
}
int cnt[3456][3456], test[345678][2];
signed main() {
	int n, m, a, b, c, ans = 0; cin >> n >> m;
	for (int h = 0; h < 3456; h++) {
		for (int i = 0; i < 3456; i++) {
			cost[h][i] = INF;
		}
	}
	for (int h = 0; h < m; h++) {
		cin >> a >> b >> c;
		test[h][0] = a; test[h][1] = b;
		cost[a][b] = c; cost[b][a] = c;
	}
	for (int h = 1; h < n; h++) {
		for (int i = h + 1; i <= n; i++) {
			dijkstra(n, h); get_path(i);
			for (int j = 0; j < get_path(i).size(); j++) {
				//cout << h << ' ' << i << ' ' << get_path(i)[j] << endl;
				if (j >= 1) {
					cnt[get_path(i)[j - 1]][get_path(i)[j]] = 1;
					cnt[get_path(i)[j]][get_path(i)[j - 1]] = 1;
				}
			}
		}
	}
	for (int h = 0; h < m; h++) {
		if (cnt[test[h][0]][test[h][1]] == 0) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 102784
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            int d = int.Parse(Console.ReadLine());
            if (d == 25) Console.WriteLine("Christmas");
            else if (d == 24) Console.WriteLine("Christmas Eve");
            else if (d == 23) Console.WriteLine("Christmas Eve Eve");
            else if (d == 22) Console.WriteLine("Christmas Eve Eve Eve");
        }
    }
}


Measured memory_bytes: 27212
#include <math.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  double a, b, c, C;
  double s, l, h;
  cin >> a >> b >> C;
  c = sqrt(a * a + b * b - 2 * a * b * cos(M_PI / 180.0 * C));
  l = a + b + c;
  h = b * sin(M_PI / 180.0 * C);
  s = a * h / 2.0;
  printf("%.5f\n", s);
  printf("%.5f\n", l);
  printf("%.5f\n", h);
  return 0;
}


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

int main(){
  int x1, x2, y1, y2, x3, x4, y3, y4;
  cin >> x1 >> y1 >> x2 >> y2;

  int t1 = x2-x1;
  int t2 = y2-y1;

  x3 = x2-t2;
  y3 = y2+t1;

  t1 = x3-x2;
  t2 = y3-y2;

  x4 = x3-t2;
  y4 = y3+t1;

  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

  return 0;
}






Measured memory_bytes: 256
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let mut x = 0;
    for _ in 0..n {
        let sum = sc.read();
        let k = sc.read();
        x ^= grundy(sum, k);
    }

    println!("{}", if x == 0 { "Aoki" } else { "Takahashi" });
}

fn grundy(sum: u64, k: u64) -> u64 {
    if k == 1 {
        return sum;
    }
    let mut a = sum / k;
    let mut b = sum % k;
    while b > 0 {
        if b >= a + 1 {
            b %= a + 1;
        } else {
            let next_sum = a * k + b - (a + 1);
            a = next_sum / k;
            b = next_sum % k;
        }

        if a == 0 {
            return 0;
        }
    }
    a
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String o = sc.next();
		String e = sc.next();
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < o.length(); i++){
			sb.append(o.charAt(i));
			if (i < e.length()){
				sb.append(e.charAt(i));
			}
		}
		System.out.println(sb.toString());
	}

}


Measured memory_bytes: 21844
#include <cstdio>
#include <algorithm>
using namespace std;

int gcd(int x, int y){
    int r;
    if (x < y) swap(x,y);

    while (y > 0){
        r = x%y;
        x = y;
        y = r;
    }
    return x;
}

int main(){
    int x,y;
    scanf("%d %d",&x,&y);
    printf("%d\n",gcd(x,y));
    return 0;
}


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

int main(){
  string s;
  cin>>s;
  int n=s.size();
  int count=0,odd=0,even=0,j=-1;
  int rl=-1;
  int ans[n]={0};
  
  for(int i=0;i<n;i++){
    count++;
    if(count%2==1){ odd++;}
    else{ even++;}
    
    if(s[i]=='R'&&s[i+1]=='L'){
      if(count%2==1) rl=1;
      else rl=0;
      j=i;
    }
    if(i!=n-1){ 
      if(s[i]=='L'&&s[i+1]=='R'){
        if(rl==-1){
          ans[0]=count;
        }
        else if(rl==0){
          ans[j]=even;
          ans[j+1]=odd;
        }
        else{
          ans[j]=odd;
          ans[j+1]=even;
        }
        count=0;
        even=0;
        odd=0;
        rl=-1;
      }
    }
    else{
     if(rl==-1) ans[n-1]=count;
     else if(rl==1){
       ans[j]=odd;
       ans[j+1]=even;
     }
     else{
       ans[j]=even;
       ans[j+1]=odd;
     }
   }
  }
 
  for(int i=0;i<n;i++) cout<<ans[i]<<" ";
  cout<<endl;
  
}

Measured memory_bytes: 1024
use std::io::{self, BufRead};
use std::collections::HashMap;
use std::cmp::min;

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let _: usize = lines.next().unwrap().unwrap().parse().unwrap();
  let vs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let mut xs: HashMap<usize, usize> = HashMap::new();
  let mut ys: HashMap<usize, usize> = HashMap::new();
  for i in 0..vs.len() {
    let k = vs[i];
    if i % 2 == 0 {
      let v = xs.get(&k).unwrap_or(&0).clone();
      xs.insert(k, v + 1);
    } else {
      let v = ys.get(&k).unwrap_or(&0).clone();
      ys.insert(k, v + 1);
    }
  }
  let (kx, vx) = xs.iter().max_by(|x, y| x.1.cmp(y.1)).unwrap();
  let (ky, vy) = ys.iter().max_by(|x, y| x.1.cmp(y.1)).unwrap();
  let nx = (vs.len() + 1) / 2 - vx;
  let ny = vs.len() / 2 - vy;
  let ans = if kx != ky {
    nx + ny
  } else {
    let zero = 0;
    let (_, vx2) = xs.iter().filter(|k| *k.0 != *kx).max_by(|x, y| x.1.cmp(y.1)).unwrap_or((&zero, &zero));
    let (_, vy2) = ys.iter().filter(|k| *k.0 != *ky).max_by(|x, y| x.1.cmp(y.1)).unwrap_or((&zero, &zero));
    let nx2 = (vs.len() + 1) / 2 - vx2;
    let ny2 = vs.len() / 2 - vy2;
    min(nx + ny2, nx2 + ny)
  };
  println!("{}", ans);
}

Measured memory_bytes: 11372
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

A,B,C=nm()
print(C-(A-B) if C-(A-B)>0 else 0) 

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
	int n,c=0;
  	cin >> n;
  	int a[50];
  	for(int i=0;i<n;i++){
    	cin >>a[i];
    }
  	for(int i=0;i<n-1;i++){
    	for(int j=i+1;j<n;j++){
        	c+=a[i]*a[j];
        }
    }
  	cout << c << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import heapq

N=int(input())
l=[]

for i in range(N):
    l.append(int(input()))

ll=sorted(l)

for i in range(N):
    if l[i]==ll[-1]:
        print(ll[-2])
    else:
        print(ll[-1])
    

Measured memory_bytes: 14176
#include<bits/stdc++.h>
using namespace std;
const int maxn=200005;

int h[maxn],mem;
struct
{
    int v,next;
}e[maxn<<1];
vector<int> g[maxn];
int fa[maxn],deep[maxn],dis[maxn];
bool vis[maxn],check[maxn];
void add(int u,int v)
{
    e[mem].v=v;
    e[mem].next=h[u];
    h[u]=mem++;
}
int findfa(int x)
{
    if(x==fa[x]) return fa[x];
    return fa[x]=findfa(fa[x]);
}
void init()
{
    memset(h,-1,sizeof(h));
    memset(vis,0,sizeof(vis));
    memset(dis,127,sizeof(dis));
    memset(check,0,sizeof(check));
    mem=0;
}

void dfs(int u,int f)
{
    fa[u]=u;deep[u]=deep[f]+1;
    for(int i=h[u];i+1;i=e[i].next)
    {
        int v=e[i].v;
        if(v==f) continue;
        dfs(v,u);
    }
    for(int i=0;i<g[u].size();i++)
    {
        int v=g[u][i];
        if(vis[v]){
            int t=findfa(v);
            int len=deep[v]+deep[u]-deep[t]*2;
            if(len>2){
                check[u]=check[v]=1;
               // printf("%d k %dsss\n",u,v);
            }
        }

    }
    fa[u]=f;
    vis[u]=1;
}
int q[maxn];
int bfs(int x)
{
    dis[x]=0;
    int head,tail;
    head=tail=0;
    q[tail++]=x;
    int ans=2*deep[x];
    while(head<tail)
    {
        int u=q[head++];
        if(check[u]) {
            //printf("%dss %d %d\n",u,head,tail);
            return -1;
        }
        for(int i=0;i<g[u].size();i++)
        {
            int v=g[u][i];
            if(dis[v]>dis[u]+1){
                if(deep[v]>dis[u]+1){
                    dis[v]=dis[u]+1;
                    q[tail++]=v;
                    ans=max(ans,2*deep[v]);
                }
            }
        }
    }
    return ans;
}
int main()
{
    int y,x,n;
    scanf("%d%d%d",&n,&x,&y);
    for(int i=1;i<n;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    init();
    for(int i=1;i<n;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        add(u,v);
        add(v,u);
    }
    deep[y]=-1;
    dfs(y,y);
    printf("%d\n",bfs(x));
    return 0;
}


Measured memory_bytes: 26748
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,m,n,a[200040];
double s;
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout<<fixed<<setprecision(12);
	cin>>n>>s;
	s=s*100+0.01;
	m=(int)s;
	cout<<n*m/100;
}

Measured memory_bytes: 3744
#include<stdio.h>
#include<math.h>

int main(void){
    double a, b, c;
    scanf("%lf%lf%lf", &a, &b, &c);
    printf("%lf\n", a*b*sin(c*M_PI/180.0)/2.0);
    printf("%lf\n", a+b+sqrt(b*b+a*a-2.0*a*b*cos(c*M_PI/180.0)));
    printf("%lf\n", b*sin(c*M_PI/180.0));
    return 0;
}


Measured memory_bytes: 2076
iN = int(input())
aA = [int(x) for x in input().split()]

i2M = (min(aA) + max(aA)) // 2
iMM = sum(aA) // len(aA)

if i2M < iMM :
    iLM = i2M
    iUM = iMM + 1
else:
    iLM = iMM
    iUM = i2M + 1

aR = []
for iM in range(iLM,iUM+1):
    aR.append(0)
    for iA in aA:
        aR[-1] += (iA - iM) ** 2
print(min(aR))


Measured memory_bytes: 3060
# C - Product and GCD
def factorization(n):
    """
    引数の値を素因数分解したリストを返す

    Parameters
    ----------
    n : int
        素因数分解したい自然数

    Returns
    -------
    retlist : list
        2以上の整数n => [[素因数, 指数], ...]の2次元リスト
    """
    retlist = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            retlist.append([i, cnt])

    if temp!=1:
        retlist.append([temp, 1])

    if retlist==[]:
        retlist.append([n, 1])

    return retlist

n,p=map(int,input().split())
l=[]
ans=1
l=factorization(p)
for ll in l:
    if ll[1]>=n:
        ans*=ll[0]**(ll[1]//n)
print(ans)


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;



int main(){
  ll n, m;
  cin >> n >> m;
  vector<ll> l(m);
  vector<ll> r(m);
  rep(i, m) cin >> l[i] >> r[i];
  rep(i, m) l[i]--, r[i]--;


  vector<bool> memo(n, true);
  ll ld = 0;
  ll rd = n-1;
  rep(i, m){
    ld = max(ld, l[i]);
    rd = min(rd, r[i]);
  }

  cout << max(0ll, rd-ld+1) << endl;



  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N,M,P;
  cin>>N>>M>>P;
  // vector<pair<int,int> > c[N];
  // REP(i,M){
  //   int A,B,C;
  //   cin>>A>>B>>C;
  //   A--;
  //   B--;
  //   C-=P;
  //   c[A].push_back(make_pair(B,C));
  // }
  int A[M],B[M],C[M];
  REP(i,M){
    cin>>A[i]>>B[i]>>C[i];
    A[i]--;
    B[i]--;
    C[i]-=P;
  }
  lint d[N];
  REP(i,N)d[i]=-1e12;
  d[0]=0;
  REP(i,N+1){
    REP(m,M){
      if(d[A[m]]==-1e12)continue;
      if(d[B[m]]<d[A[m]]+C[m]){
        d[B[m]]=d[A[m]]+C[m];
      }
    }
  }
  lint temp=d[N-1];
  REP(i,N+1){
    REP(m,M){
      if(d[A[m]]==-1e12)continue;
      if(d[B[m]]<d[A[m]]+C[m]){
        d[B[m]]=1e12;
      }
    }
  }
  if(d[N-1]==1e12){
    cout<<-1<<endl;
    return 0;
  }
  cout<<max((lint)0,temp)<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

#define N 100


int main() {
  int n, i, j, l, key, data[N];

  scanf("%d", &n);
  
  for (i = 0; i < n; i++) {
    scanf("%d", &data[i]);
  }

  for (i = 1; i < n; i++) {
    for (l = 0; l < n; l++) {
      printf("%d", data[l]);
      if (l != n-1) printf(" ");
    }
    printf("\n");
    key = data[i];
    j = i-1;
    while(j >= 0 && data[j] > key) {
      data[j+1] = data[j]; 
      j--;
    }
    data[j+1] = key;
    
  }

  for (l = 0; l < n; l++) {
      printf("%d", data[l]);
      if (l != n-1) printf(" ");
    }
  printf("\n");

  return 0;
}



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

int n,m;
int ans;
int ee,h[100005],nex[100005],to[100005];
int rdu[100005];
int f[100005];
int q[100005],head=1,tail=0;
bool vis[100005];

void addedge(int x,int y)
{
	nex[++ee] = h[x];
	to[ee] = y;
	h[x] = ee;
}

void topo()
{
	for(int i=1;i<=n;i++)
		if(rdu[i]==0)
			q[++tail] = i;
	while(head<=tail)
	{
		int x=q[head];
		head++;
		for(int i=h[x];i;i=nex[i])
			if((--rdu[to[i]])==0)
				q[++tail] = to[i];
	}
}

int main()
{
	cin>>n>>m;
	for(int i=1,x,y;i<=m&&cin>>x>>y;i++)
	{
		addedge(x,y);
		rdu[y]++;
	}
	topo();
	for(head=1;head<=tail;head++)
	{
		int x=q[head];
		for(int i=h[x];i;i=nex[i])
			f[to[i]] = max(f[to[i]],f[x]+1);
	}
	for(int i=1;i<=n;i++)
		ans = max(ans,f[i]);
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 2560
def main():

    N = int(input())
    A = list(map(int, input().split()))

    A = sorted(A)
    Amax = A[-1]
    count = [0 for _ in range(Amax+1)]

    for a in A:
        for i in range(1, Amax//a+1):
            count[i*a] += 1

    ans = 0
    for i in range(N):
        a = A[i]
        if count[a] == 1:
#            print(i)                                                                                                                                            
            ans += 1

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 32232
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long int
#define ld long double
#define ff first
#define ss second  
#define endl '\n'
#define pb push_back
#define t_case ll tt; cin>>tt; while (tt--)
#define all(v) v.begin(),v.end()
#define ub(a,x) upper_bound(all(a),x)-a.begin()
#define lb(a,x) lower_bound(all(a),x)-a.begin()
#define fr(a,b,c) for (ll a=b;a<c;a++)
#define take(xx,n) for (int i=0;i<n;i++) cin>>xx[i];
#define take1(xx,n) for (int i=1;i<=n;i++) cin>>xx[i];
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
const auto inf=LLONG_MAX; 

int main() 
{
	fastio
	//t_case
	{
		ll sum=0,f=1,ans=0,n,m=1,mx=-inf,mn=inf,x,y,k  ; cin>>n; 
		
		for(int i=1;i<n;i++){
			ans=ans+((n-1)/i);
		}	
		cout<<ans;
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3572
import math
import numpy as np
op = list(map(int,input().split()))
a = op[0]
b = op[1]
h = op[2]
m = op[3]
hs = h*30
d = abs(hs-5.5*m)
d = np.radians(d)
cd = np.cos(d)
x = math.sqrt(a**2+b**2-2*a*b*cd)
print(x)

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

int main(){
    int x, t;
    cin >> x >> t;
    if(t <= x){
        cout << x-t << endl;
    }else{
        cout << 0 << endl;
    }
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) ((v).begin(),(v).end())
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int d,g;cin >> d >> g;
    typedef pair<int,int>pair;
    vector<pair>vec;
    int a,b;
    REP(i,d){
        cin >> a >> b;
        vec.push_back(pair(a,b));
    }
    bool flag = true;
    int ans = INF;
    for(int bit=0;bit<(1<<d);bit++){
        int count=0,score=0,num1;
        for(int i=0;i<d;i++){
            flag = true;
            if(bit&(1<<i)){
                count+=vec[i].first;
                score+=(100*(i+1)*vec[i].first);
                score+=vec[i].second;
                flag = false;
            }
            if(flag)num1=i+1;
        }
        if(score<g){
            int num3 = 0;
            while(score<g){
                score += 100*num1;
                count++;
                num3++;
                if(num3==vec[num1-1].first)break;
            }
        }
        if(score<g)continue;
        ans = min(ans,count);
    }
    COUT(ans);
    return 0;
}

Measured memory_bytes: 256
#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 rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.20f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;

	int cntw = 0;
	rep (i, n) if (s[i] == 'R') cntw++;

	int ans = 0;
	rep (i, cntw) if (s[i] == 'W') ans++; 

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


Measured memory_bytes: 3748
n,m = gets.split.map(&:to_i)
arr = []
n.times do
  arr << gets.split.map(&:to_i)
end

ans = Array.new(m){|i| i + 1}
ans1 = Array.new(m){|i| i + 1}

ans.each do |b|
  arr.each do |a|
    c = a[1..-1]
    unless c.include?(b)
      ans1.delete(b)
    end
  end
end

p ans1.size

Measured memory_bytes: 3836
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
	int r,g,b,n;
	cin >> r >> g >> b >> n;
	int ans = 0;
	for(int i=0; i<=n; i++){
		for(int j=0; j<=n; j++){
			int rem = n-i*r-j*g;
			if(rem>=0 and rem%b==0) ans++;
		}

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

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

using namespace std;

int main()
{
  string S, T;
  cin >> S >> T;

  int count = 0;
  for (int i = 0; i < (int)S.size(); ++i)
  {
    if (S[i] == T[i]) ++count;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as C
import           Data.Maybe ( fromJust, isNothing )

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  [n,y] <- readInts
  putStrLn $ f n y

type Mai = Int
type Yen = Int
type Pochi = (Int,Int,Int) -- #s of 10000,5000,1000 bills

minPochi :: Yen -> Pochi
minPochi y = (a,b,c)
  where
    (a,r) = y `quotRem` 10000
    (b,s) = r `quotRem` 5000
    c     = s `quot` 1000

canPay :: Mai -> Yen -> Maybe Pochi
canPay n y = h i
  where
    i@(a,b,c) = minPochi y

    h :: Pochi -> Maybe Pochi
    h p@(a,b,c)
      | n == m = Just p
      | n - m > 3 && b > 0 = h (a, b-1, c+5)
      | n - m > 0 && a > 0 = h (a-1,b+2,c)
      | otherwise = Nothing
      where
        m = a+b+c

f :: Mai -> Yen -> String
f n y
  | isNothing p = "-1 -1 -1"
  | otherwise   = show a ++ " " ++ show b ++ " " ++ show c
  where
    p = canPay n y
    (a,b,c) = fromJust p

otsdm' :: Mai -> Yen -> [Pochi]
otsdm' n y
  = [(a,b,n-a-b) -- double loop
      | let a0 = y `quot` 10000
      , a <- [0 .. a0]
      , let b0 = (y - 10000*a) `quot` 5000
      , b <- [0 .. b0]]

gok :: Pochi -> Yen
gok (a,b,c) = 10000*a +5000*b + 1000*c 

otsdm :: Mai -> Yen -> String
otsdm n y
  | null os   = "-1 -1 -1"
  | otherwise = show a ++ " " ++ show b ++ " " ++ show c
  where
    os = filter (\o -> y == gok o) $ otsdm' n y
    (a,b,c) = head os

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

using namespace std;

const int inf = 1e9;

struct Dinic {
   int n, s, t;
   struct Edge {
      int to, cap, flow, rev;
      Edge(int to = 0, int cap = 0, int flow = 0, int rev = 0) :
         to(to), cap(cap), flow(flow), rev(rev) {}
   };
   vector<int> d;
   vector<int> ptr;
   vector<vector<Edge>> g;
   Dinic(int n = 0, int s = 0, int t = 0) :
      n(n), s(s), t(t), d(n), ptr(n), g(n) {}
   void addEdge(int u, int v, int cap) {
      g[u].emplace_back(v, cap, 0, g[v].size());
      g[v].emplace_back(u, 0, 0, g[u].size() - 1);
   }
   bool bfs() {
      fill(d.begin(), d.end(), -1);
      fill(ptr.begin(), ptr.end(), 0);
      queue<int> q;
      d[s] = 0;
      q.push(s);
      while (!q.empty()) {
         int u = q.front();
         q.pop();
         for (auto e : g[u]) {
            if (d[e.to] == -1 && e.cap > e.flow) {
               d[e.to] = d[u] + 1;
               q.push(e.to);
            }
         }
      }
      return d[t] != -1;
   }
   int dfs(int u, int flow) {
      if (u == t) {
         return flow;
      }
      for (int &i = ptr[u]; i < g[u].size(); ++i) {
         auto &e = g[u][i];
         if (e.cap <= e.flow || d[e.to] != d[u] + 1) continue;
         int nxt = dfs(e.to, min(flow, e.cap - e.flow));
         if (nxt) {
            e.flow += nxt;
            g[e.to][e.rev].flow -= nxt;
            return nxt;
         }
      }
      return 0;
   }
   int maxFlow() {
      int ans = 0;
      while (bfs()) {
         while (true) {
            int now = dfs(s, inf);
            if (now) ans += now;
            else break;
         }
      }
      return ans;
   }
   vector<int> path;
   void trace(int v) {
      path.emplace_back(v);
      for (auto &e : g[v]) {
         if (e.flow > 0) {
            e.flow--;
            return trace(e.to);
         }
      }
   }
   vector<int> getPath() {
      path.clear();
      trace(s);
      return path;
   }
};

int main() {
   ios_base::sync_with_stdio(false);
   int N, M; cin >> N >> M;
   vector<string> A(N);
   Dinic dn(N + M + 2, N + M, N + M + 1);
   for (int i = 0; i < N; ++i) {
      cin >> A[i];
      for (int j = 0; j < M; ++j) {
         if (A[i][j] == 'S') {
            dn.addEdge(N + M, i, inf);
            dn.addEdge(N + M, j + N, inf);
         } else if (A[i][j] == 'T') {
            dn.addEdge(i, N + M + 1, inf);
            dn.addEdge(j + N, N + M + 1, inf);
         } else if (A[i][j] == 'o') {
            dn.addEdge(i, j + N, 1);
            dn.addEdge(j + N, i, 1);
         }
      }
   }
   int ans = dn.maxFlow();
   if (ans >= inf) ans = -1;
   cout << ans << "\n";
   return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N+1);
  for(int i=0; i<N; i++) cin >> A.at(i);
  A.at(N)=1000000001;
  sort(A.begin(), A.end());
  int cnt=1;
  int ans=0;
  for(int i=0; i<N; i++){
    if(A.at(i)==A.at(i+1)) cnt++;
    else{
      if(cnt%2!=0) ans++;
      cnt=1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

man = 0
euc = 0
euc3 = 0
che = 0
for i in range(n):
    man += abs(x[i]-y[i])
    euc += abs(x[i]-y[i])**2
    euc3 += abs(x[i]-y[i])**3
    che = max(che, abs(x[i]-y[i]))

print(man)
print(euc**0.5)
print(euc3**(1/3))
print(che)


Measured memory_bytes: 5640
/**********************
    Vikas Kumar Jha
    vkjha1010
**********************/
#include<bits/stdc++.h>
using namespace std;

#define ll          long long int 
#define ld          long double
#define mod         1000000007
#define fi          first
#define se          second
#define pb          push_back
#define mp          make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vb          vector<bool>
#define mii         map<ll,ll>
#define pqb         priority_queue<ll>
#define pqs         priority_queue<ll, vi, greater<ll> >
#define ps(x,y)     fixed << setprecision(y) << x
#define fast        ios_base::sync_with_stdio(0);   cin.tie(0); cout.tie(0);
#define w(t)        ll t; cin >> t; for(ll zx=1;zx<=t;++zx)  
#define fr(be,en)   for(ll i = be; i < en; i++)
ll pow(ll x,ll y){ if(y==0) return 1; if(y%2==1) return (((pow(x,y/2)*pow(x,y/2)%mod)*x)%mod); else return (pow(x,y/2)*pow(x,y/2))%mod;}
vb prime;   vi spf; 
void sieve(ll n) 
{   prime.resize(n+1,true); prime[0]=prime[1]=false;
    spf.resize(n+1,1);  spf[2]=2;
    for(ll i=4;i<=n;i+=2){ prime[i]=false; spf[i]=2; } 
    for (ll p=3; p*p<=n; p+=2) 
    {   if (prime[p] == true) 
        {   spf[p]=p;
            for (ll i=p*p; i<=n; i += p) 
            {   if(prime[i]==true)
                {   spf[i]=p;
                    prime[i] = false;
                }
            } 
        } 
    } 
} 
vector<vector<ll> > g;
vector<ll> vis;
vector<ll> dp;
ll ans=0;
ll dfs(ll u,ll p)
{   vis[u]=1;
    ll m1=0;
    for(auto x : g[u])
    {
        if(x!=p && vis[x]!=1)
        {
            ll a=dfs(x,u);
            m1=max(a,m1);
            // if(a>m1)
            // {
            //     m2=m1;
            //     m1=a;
            // }
            // else
            // {
            //     if(a>m2) m2=a;
            // }
        }
        else if(vis[x]==1)
            m1=max(m1,dp[x]);
    }
    ans=max(ans,m1+1);
    return dp[u]=m1+1;

}
int main() {
    
    fast;
    ll n,m,x,y;
    cin >> n >> m;
    g.resize(n+1);
    vis.resize(n+1);
    dp.resize(n+1);
    fr(0,m)
    {
        cin >> x >> y;
        g[x].push_back(y);
    }
    for(ll i=1;i<=n;++i)
        if(vis[i]==0)
            dfs(i,0);
    cout << ans-1 ;
    return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;
int n;
int main()
{
    string s;
    cin >> s;
    if (s.size() == 2)
    {
        if (s[0] != s[1])
        {
            cout << -1 << " " << -1 << endl;
        }
        else
        {
            cout << 1 << " " << 2 << endl;
        }
        return 0;
    }
    else
    {
        rep(i, s.size() - 2)
        {
            if (s[i] == s[i + 1] || s[i] == s[i + 2] || s[i + 1] == s[i + 2])
            {
                cout << i + 1 << " " << i + 3 << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
void visit(int);
int d(void);
void e(int);
 
int map[101][101];
int Q[101],n,head=0,tail=0,color[101],G[101];
int main()
{
  int i,j,v,vv,m,u,k;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    color[i]=0;
    for(j=0;j<n;j++){
      map[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&m);
    for(j=0;j<m;j++){
      scanf("%d",&vv);
      map[v-1][vv-1]=1;
    }
  }
 
  for(j=0;j<n;j++){
    if(map[0][j]==1){
      color[j]=0;
    }
  }
  color[0]=1;
  G[0]=0;
  e(0);
  while(head!=tail){
    u=d();
    for(k=0;k<n;k++){
      if(map[u][k]==1 && color[k]==0){
	color[k]=1;
	G[k]=G[u]+1;
	e(k);
      }
      color[u]=2;
    }
  }
   
 
   
  for(i=0;i<n;i++){
    if(color[i]==2){
      printf("%d %d\n",i+1,G[i]);
    }
    else printf("%d -1\n",i+1);
  }
  return 0;
}
 
int d()
{
  int x;
  x=Q[head];
  if(head+1==100){
    head=0;
  }
  else head=head+1;
  return x;
}
 
void e(int x)
{
  Q[tail]=x;
  if(tail+1==100){
    tail=0;
  }
  else tail=tail+1;
}

Measured memory_bytes: 636
#!/usr/bin/env python3
# ALDS_10_D: Dynamic Programming - Optimal Binary Search Tree


def optimal_cost(n, kp, dp):
    sums = [sum(kp[0:i]) + sum(dp[0:i+1]) for i in range(n+1)]
    expects = [[kp[i] + (dp[i] + dp[i+1])*2 for i in range(n)]]

    for w in range(2, n+1):
        exps = []
        for i in range(n-w+1):
            j = i + w
            exp = min(dp[i] + expects[j-i-2][i+1], expects[j-i-2][i] + dp[j])
            for k in range(i+1, j-1):
                _exp = expects[k-i-1][i] + expects[j-k-2][k+1]
                if exp > _exp:
                    exp = _exp
            exps.append(exp + sums[j] - sums[i] + dp[i])
        expects.append(exps)

    return expects[-1][0]


def run():
    n = int(input())
    ps = [float(x) for x in input().split()]
    qs = [float(x) for x in input().split()]

    print("{:.8f}".format(optimal_cost(n, ps, qs)))


if __name__ == '__main__':
    run()



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

int n, W, w[100], v[100];
vector<int> mono[4];

int dfs(int a, int wsum, int sum) {
	if (a == 4)return sum;

	int vsum = 0, res = sum;
	for (int i = 0; i <= mono[a].size(); i++) {
		if(i > 0)vsum += mono[a][i-1];
		//cout << "a:" << a << " i:" << i << endl;
		//cout << "wsum+(w[0]+a)*i:" << wsum + (w[0] + a)*i << endl;
		if (wsum + (w[0]+a)*i <= W) {
			res = max(res, dfs(a + 1, wsum+(w[0]+a)*i, sum + vsum));
		}
		else {
			break;
		}
	}

	return res;
}

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

	for (int i = 0; i < n; i++) {
		mono[w[i] - w[0]].push_back(v[i]);
	}
	//cout << endl;
	for (int i = 0; i < 4; i++) {
		sort(mono[i].begin(), mono[i].end(), greater<int>());
		/*for (int j = 0; j < mono[i].size(); j++) {
			cout << mono[i][j] << " ";
		}
		cout << endl;*/
	}

	cout << dfs(0, 0, 0) << endl;
}

Measured memory_bytes: 256
def printBorad():
    for i in range(8):
        s = ['.'] * 8
        s[row[i]] = 'Q'
        print(''.join(s))

def putQueen(i, j):
    row[i] = j
    col[j] = True
    left[i+j] = True
    right[7+i-j] = True

def removeQueen(i, j):
    row[i] = False
    col[j] = False
    left[i+j] = False
    right[7+i-j] = False
    


def recursive(i):
    if i == 8:
        printBorad()
        return
    
    if row[i] is not False:
        putQueen(i, row[i])
        recursive(i + 1)
    else:
        for j in range(8):        
            if col[j] or left[i+j] or right[7+i-j]:
                continue
            putQueen(i, j)
            recursive(i + 1)
            removeQueen(i, j)


if __name__ == "__main__":
    row = [False for i in range(8)]
    col = [False for i in range(8)]
    left = [False for i in range(15)]
    right = [False for i in range(15)]
    n = int(input())
    for _ in range(n):
        i, j = map(int, input().split())
        putQueen(i, j)
    
    recursive(0)


Measured memory_bytes: 5612
#include <stdio.h>
int isRight(int x,int y,int z){
  if(x*x==(y*y+z*z))return -1;
  return 0;
} 
int main(){
  int a,b,c,d,e;
  scanf("%d",&a);
  for(b=1;b<=a;b++){
    scanf("%d %d %d",&c,&d,&e);
    if(isRight(c,d,e) || isRight(d,c,e) || isRight(e,c,d)) printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
const ll MOD=1e9+7;
using namespace std;

int main() {
  ll N,K;
  cin >> N >> K;
  ll num[100005]={};
  rep(i,N){
    ll a,b;
    cin >> a >> b;
    num[a]+=b;
  }
  ll count=0;
  for(ll i=1;i<=100000;i++){
    count+=num[i];
    if(count>=K){
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 1024
X, K, D = map(int, input().split())

mod = abs(X) % D
ura = D - mod
if mod <= ura:
  if abs(X)-D*K > mod:
    ans = abs(X)-D*K
  else:
    n = (abs(X)-mod) // D
    if (K-n) % 2 == 0:
      ans = mod
    else:
      ans = ura
else:
  if D*K-abs(X) < ura:
    ans = abs(X)-D*K
  else:
    n = (abs(X)+ura) // D
    if (K-n) % 2 == 0:
      ans = ura
    else:
      ans = mod
print(ans)

Measured memory_bytes: 9200
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main()
{
  string S,T;
  string x;

  cin >> S >> T;

  int size = S.size()-1;

  if(S==T)
    {
      cout << "Yes";
      return 0;
    }
  
  
  for(int i = 0; i < size;i++)
  {
    x = S.at(size);
    S.erase(size,1);
    S.insert(0,x);

    if(S==T)
      {
        cout << "Yes";
        return 0;
      }
  }

  cout << "No";
  return 0;
  
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function dfs(depth, last, used, r, d) {
    if (depth > r.length) {
        return 0;
    }
    var minDist = Number.MAX_VALUE;
    var dist = 0;
    for (var i = 0; i < r.length; i++) {
        if (used[i]) {
            continue;
        }
        used[i] = true;
        if (last >= 0) {
            dist = d[r[last] - 1][r[i] - 1];
        }
        minDist = Math.min(minDist, dfs(depth + 1, i, used, r, d) + dist);
        used[i] = false;
    }

    return minDist;
}

function Main(input) {
    var values = input[0].split(' ');
    var n = parseInt(values[0], 10);
    var m = parseInt(values[1], 10);
    var rNum = parseInt(values[2], 10);
    var r = new Array(rNum);
    var rStr = input[1].split(' ');
    for (var i = 0; i < rNum; i++) {
        r[i] = parseInt(rStr[i], 10);
    }
    var d = new Array(n);
    for (var i = 0; i < n; i++) {
        d[i] = new Array(n);
    }
    for (var i = 0; i < n; i++) {
        for (var j = 0; j < n; j++) {
            if (i == j) {
                d[i][j] = 0;
            }
            else {
                d[i][j] = Number.MAX_VALUE;
            }
        }
    }
    for (var i = 0; i < m; i++) {
        var distValues = input[i + 2].split(' ');
        var a = parseInt(distValues[0], 10);
        var b = parseInt(distValues[1], 10);
        var c = parseInt(distValues[2], 10);
        d[a - 1][b - 1] = c;
        d[b - 1][a - 1] = c;
    }
   
    for (var k = 0; k < n; k++) {
        for (var i = 0; i < n; i++) {
            for (var j = 0; j < n; j++) {
                if (d[i][j] > d[i][k] + d[k][j]) {
                    d[i][j] = d[i][k] + d[k][j];
                }
            }
        }
    }
    var used = new Array(rNum);
    for (var i = 0; i < rNum; i++) {
        used[i] = false;
    }
    var ans = dfs(1, -1, used, r, d);

    console.log(ans);

    return 0;
}



Measured memory_bytes: 16680
#include <iostream>
using namespace std;
long long int INF = 999999999;
int main() {
	long long int n;
	cin >> n;
	for (int i = 1; i <= INF; ++i) {
		if ((i*i + i) / 2 >= n) {
			cout << i << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	deque<int>q;
	bool r = true;
	if (n % 2 == 1)r = false;
	for (int i = 0; i < n; i++) {
		if (r) {
			q.push_back(a.at(i));
			r = false;
		}
		else {
			q.push_front(a.at(i));
			r = true;
		}
	}
	cout << q.front();
	q.pop_front();
	while (q.size() > 0) {
		cout << " " << q.front();
		q.pop_front();
	}
	cout << endl;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
#define rep(i, n) for(int i = 0; i < n; i++)
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main(){
    ll n; cin >> n;
    char t[5] = {'M','A','R','C','H'};
    string s[n];
    map<char,ll> mp;
    rep(i,n){
        cin >> s[i];
        mp[s[i][0]]++;
    }
    ll cnt = 0;
    for(ll i = 0; i < 5; i++){
        for(ll j = i+1; j < 5; j++){
            for(ll k = j+1; k < 5; k++){
                cnt += mp[t[i]]*mp[t[j]]*mp[t[k]];
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 6144
#include <stdio.h>
int main(){
  int n,i,flag=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    if((i%4==0 && (n-i)%7==0)||(i%7==0 && (n-i)%4==0)){
      flag=1;
      break;
    }
    if(i==n-1){
      flag=0;
    }
  }
  if(flag){
    puts("Yes");
  }else{
    puts("No");
  }
  return 0;
}


Measured memory_bytes: 128
N = int(input())
a = list(map(int,input().split(" ")))

N += 1
a.append(0)
s = 0
m = a[0]
n = 1
for i in range(1,N):
    if m == a[i]:
        n += 1
    else:
        s += (n//2)
        n = 1
    m = a[i]

print(s)

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

int n;
int a[101];

void solve() {
    int tot = 0;
    for (int i=0;i<n;i++) {
      tot += a[i];
    }
    int avg = round((double)tot / n);
    int cost = 0;
    for (int i=0;i<n;i++) {
      cost += (a[i] - avg) * (a[i] - avg);
    }
    cout << cost << endl;
}

int main () {
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> a[i];
  }
  solve();
}


Measured memory_bytes: 256
n,m=map(int,input().split())
l=1;ma=n
te=set(range(1,n+1))
for i in range(m):
    x,y=map(int,input().split())
    l=max(x,l)
    ma=min(ma,y)
print(abs(l-ma)+1 if l<=ma else 0)


Measured memory_bytes: 50660
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
int main()
{
    string str;
    cin>>str;
    set<char> s;
    for(int i=0;i<4;i++)
        s.insert(str[i]);
    if(s.size() == 2)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std ;
int main()
{
	int A[4][3][10]={} , n=0 , b=0 , f=0 , r=0 , v=0 , i=0 , a=0;
	cin >> n ;
	for(i=0;i<n;i++)
	{
		cin >> b >> f >> r >> v ;
		a=A[b-1][f-1][r-1] ;
		A[b-1][f-1][r-1]= a + v ;
	}

	for(int ia=0;ia<4;ia++)
	{
		for(int ib=0;ib<3;ib++)
		{
			for(int ic=0;ic<10;ic++)
			{
				cout << " " << A[ia][ib][ic] ;
			}
			cout << endl ;
		}
		if(ia!=3)
		{
			for(int id=0;id<20;id++)
			{
				cout << "#" ;
			}
		}
		if(ia!=3)
		{
			cout << endl ;
		}
	}
	return 0 ;
}



Measured memory_bytes: 3100
fn main() {
    let v = read_vec::<usize>();
    let (a, b, c) = (v[0], v[1], v[2]);
    let mut ans = a * b * (c - c / 2 - c / 2);
    ans = std::cmp::min(ans, a * c * (b - b / 2 - b / 2));
    ans = std::cmp::min(ans, b * c * (a - a / 2 - a / 2));
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> x(n),y(n);
    for(int i = 0; i < n;i++)
        cin >> x[i] >> y[i];
    long long mn = x[0]+y[0], mx = x[0]+y[0];
    for(int i = 1; i < n;i++)
    {
        mn = min(x[i]+0ll+y[i],mn);
        mx = max(x[i]+0ll+y[i],mx);
    }
    long long a1 = mx - mn;

    mn = x[0] - y[0]; mx = x[0]-y[0];
    for(int i = 1; i < n; i++)
    {
        mn = min(x[i]-0ll-y[i],mn);
        mx = max(x[i]-0ll-y[i],mx);
    }

    long long a2 = abs(mx-mn);
    cout << max(a1,a2) << endl;
}


Measured memory_bytes: 4820