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

#define MAXN 200010
#define mod 1000000007

int n,x,y,fac[MAXN],inv[MAXN];
vector<int> color[MAXN];

int qpow(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=(long long)res*a%mod;
		a=(long long)a*a%mod;
		b>>=1;
	}
	return res;
}

int main()
{
	scanf("%d%d%d",&n,&x,&y);
	fac[0]=1;
	for(int i=1;i<=n;++i)fac[i]=(long long)fac[i-1]*i%mod;
	inv[n]=qpow(fac[n],mod-2);
	for(int i=n-1;i>=0;--i)inv[i]=(long long)inv[i+1]*(i+1)%mod;
	for(int i=1;i<=n;++i)
	{
		int c,w;
		scanf("%d%d",&c,&w);
		color[c].push_back(w); 
	}
	int minn=2147483647,min2=2147483647;
	for(int i=1;i<=n;++i)
		if(!color[i].empty())
		{
			sort(color[i].begin(),color[i].end());
			if(color[i][0]<=minn)
			{
				min2=minn;
				minn=color[i][0];
			}
		}
	int ans=1,cnt=0;
	for(int i=1;i<=n;++i)
	{
		if(color[i].empty())continue;
		int global=minn,now=color[i].size()-1;
		if(color[i][0]==minn)global=min2;
		if(global+color[i][0]>y)continue;
		while(now>0 && color[i][now]+global>y && color[i][now]+color[i][0]>x)--now;
		ans=(long long)ans*inv[now+1]%mod;
		cnt+=now+1;
	}
	printf("%d\n",(long long)ans*fac[cnt]%mod);
}

Measured memory_bytes: 10880
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,n,m=1,q,k,i,p;
    // cin>>T;
    k = 1000000000000000000;
    while(T--)
    {
        cin>>n;
        ll a[n];
        q=1;
        FOR(i,0,n)  
        {
            cin>>a[i];
            if(a[i]==0)
                m=0;
        }
        if(m==0)
        {
            cout<<0<<endl;
            return 0;
        }
        FOR(i,0,n)
        {
            if(a[i]<=(k/q))
                q *= a[i];
            else
            {
                cout<<-1<<endl;
                return 0;
            }
        }
        cout<<q<<endl;
    }
}

Measured memory_bytes: 4416
/* ALDS1_10_A: Fibonacci Number */

#include <iostream>

const int MAX_N = 440;

long memo[MAX_N] = {};

long fibonacci(int n) {
    switch (n) {
        case 0:
        case 1:
            return 1;
        default:
            if (memo[n])
                return memo[n];
            else
                return memo[n] = fibonacci(n - 1) + fibonacci(n - 2);
    }
}

int main() {
    int n;
    std::cin >> n;
    std::cout << fibonacci(n) << std::endl;
    return 0;
}

Measured memory_bytes: 1164
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC043BUnhappyHackingABCEdit
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] input = Console.ReadLine().ToCharArray();

            List<string> output = new List<string>();

            foreach (char key in input)
            {
                switch (key.ToString())
                {
                    case "0":
                        output.Add("0");
                        break;
                    case "1":
                        output.Add("1");
                        break;
                    case "B":
                        if (output.Count > 0)
                        {
                            output.RemoveAt(output.Count() - 1);
                        }
                        break;


                }


            }
            string result = "";

            output.ForEach(x => result += x);

            Console.WriteLine(result);

        }
    }
}


Measured memory_bytes: 11220
#include<iostream>
#include<cmath>
#include <bits/stdc++.h>

const double PI=3.14159265358979323846;

using namespace std;

int main()
{
	int A,B,H,M;
	double c;

	cin >> A >> B >> H >> M;

	double h = H * 30.0 + M*0.5;
	double m = M * 6.0;

	double rad = h - m;

	rad = min(360.0 - rad,rad);

	rad = rad/180.0 * PI;

	c = A*A + B*B -2*A*B*cos(rad);

	printf("%.20f\n",sqrt(c));

	return 0;
}

Measured memory_bytes: 4160
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long ll;

int N;
ll cnt[100000 + 10];
const ll MOD = 998244353;

ll modpow(ll a, ll b) {
	ll ret = 1, kakeru = a;
	while (b) {
		if (b & 1)ret *= kakeru, ret %= MOD;
		kakeru *= kakeru, kakeru %= MOD;
		b >>= 1;
	}
	return ret;
}

int main() {
	cin >> N;
	int x;
	cin >> x;
	if (x != 0) {
		for (int i = 0; i < N - 1; i++) {
			int a;
			cin >> a;
		}
		cout << 0 << endl;
		return 0;
	}
	ll M = 0;
	bool f = false;
	for (int i = 0; i < N - 1; i++) {
		ll a;
		cin >> a;
		if (a == 0)f = true;
		else {
			cnt[a]++;
			M = max(M, a);
		}
	}
	if (f) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1;
	cnt[0] = 1;
	for (int i = 1; i <= M; i++) {
		ans *= modpow(cnt[i - 1], cnt[i]);
		ans %= MOD;
	}
	cout << ans << endl;
	//逃げるな！力を尽くせ！
	return 0;
}

Measured memory_bytes: 1024
n, m = gets.split.map(&:to_i)
c = n.times.map{gets.split.map(&:to_f)}
d = Array.new(n).map{Array.new(n)}
n.times do |i|
    n.times do |j|
        d[i][j] = (0..2).map{|k| (c[i][k] - c[j][k])**2}.inject(:+)
    end
end
puts (0...n).to_a.combination(m).map{|c| c.combination(2).map{|p,q| d[p][q]}.inject(:+)}.max || 0

Measured memory_bytes: 7752
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (a,b,c) = get!(usize, usize, usize);
    if a % 2 == 1 || b % 2 == 1 || c % 2==1 {
        println!("0");
        return;
    }
    if a == b && b == c{
        println!("-1");
        return;
    }
    let vec = vec![a+b,b+c,c+a];
    let mut tmp = 2;
    for i in 0..32 {
        if vec.iter().any(|&e| e % tmp != 0) {
            println!("{}", i);
            return;
        }
        tmp *= 2;
    }
}



Measured memory_bytes: 8572
/*
author : seryu
title : AGC034A_"Kenken Race"
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    string s;
    a--;b--;c--;d--;
    cin >> s;
    for (int pos = a; pos + 2< c; pos++)
    {
        if(s[pos+1] == '#' && s[pos+2] == '#')
        {
            cout << "No" << endl;
            return;
        }
    }
    for (int pos = b; pos + 2 < d; pos++)
    {
        if(s[pos+1] == '#' && s[pos+2] == '#')
        {
            cout << "No" << endl;
            return;
        }
    }
    
    bool ok = false;
    if(c < d)
    {
        ok = true;
    }
    else if(c > d)
    {
        for(int pos = b; pos <= d ; pos++)
        {
            if(s[pos-1] == '.' && s[pos] == '.' && s[pos+1] == '.')
            {
                ok = true;
                break;
            }
        }
    }
    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
    return;	
}

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


Measured memory_bytes: 3756
#include<bits/stdc++.h>
#define itn int 
#define ri int 
#define ll long long 
using namespace std;
string a,b;
int main(){
	cin>>a;
	b=a;
	int len=a.size();
	reverse(a.begin(),a.end());
	for(int i=0;i<len;i++){
		if(a[i]=='b')
		a[i]='d';
		else if(a[i]=='d')
		a[i]='b';
		else if(a[i]=='p')
		a[i]='q';
		else 
		a[i]='p';
	}
	if(a==b)
	cout<<"Yes";
	else 
	cout<<"No";
	
	
	
	return 0;
} 

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int used[10];
 
void solve() {
    int n, k, v;
    cin >> n >> k;
    for (int i = 0; i < k; i++) {
        cin >> v;
        used[v] = 1;
    }
    for (; ; n++) {
        int isok = 1;
        int nn = n;
        while (nn > 0) {
            if (used[nn % 10] == 1) {
                isok = 0;
                break;
            } else {
                nn /= 10;
            }
        }
        if (isok) {
            cout << n;
            return;
        }
    }
}
 
int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private Scanner sc;
	
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
 
		int num = Integer.parseInt(sc.nextLine());
		int ans = 1;
		while (ans <= num) {
			ans = ans * 2;
		}
		System.out.println(ans / 2);
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((ll)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
typedef long long ll;
ll INF = 1e18;
using namespace std;

int dp[333333];
int main(){
  int N;
  cin >> N;
  rep(i,333333){
    dp[i] = N;
  }
  dp[0] = 0;
  rep(n,N){
    for(int pow6 = 1; n+pow6 <= N; pow6 *= 6){
      dp[n+pow6] = min(dp[n+pow6], dp[n]+1);
    }
    for(int pow9 = 1; n+pow9 <= N; pow9 *= 9){
      dp[n+pow9] = min(dp[n+pow9], dp[n]+1);
    }
  }
  
  cout << dp[N] << endl;




  return 0;
}


Measured memory_bytes: 1536
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

enum class Op(val i: Int, val op: String) {
    Plus(1, "+"),
    Minus(-1, "-")
}

fun solve() {
    val abcd = br.readLine()!!.map { it - '0' }

    for (i in Op.values()) {
        for (j in Op.values()) {
            for (k in Op.values()) {
                val tmp = abcd[0] + i.i * abcd[1] + j.i * abcd[2] + k.i * abcd[3]
                if (tmp == 7) {
                    out.println("${abcd[0]}${i.op}${abcd[1]}${j.op}${abcd[2]}${k.op}${abcd[3]}=7")
                    return
                }
            }
        }
    }
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 34296
H, W = map(int,input().split())
A = [list(input()) for _ in range(H)]
first = 0
a = A[0]
a = list(reversed(a))
last = W - a.index('#') -1
if A[0][first:last+1] == ['#'] * len(A[0][first:last+1]):
    pass
else:
    print('Impossible')
    exit()

for i in range(1, H):
    a = A[i]
    if last == a.index('#'):
        first = last
    else:
        print('Impossible')
        exit()
    a = list(reversed(a))
    last = W - a.index('#') - 1
    if A[i][first:last+1] == ['#'] * len(A[i][first:last+1]):
        pass
    else:
        print('Impossible')
        exit()
print('Possible')


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int N;
int A[100005];
long long res;
long long X, Y;
void Read()
{
    cin >> N;
    for(int i = 1; i <= N; i++)
        cin >> A[i];
}

void Solve()
{
    long long res = 2;
    X = Y = 2;
    for(int i = N; i >= 1; i--)
    {
        long long aux = X - X % A[i];
        if(X % A[i] != 0)
        aux += A[i];
        long long aux2 = Y - Y % A[i];
        if(aux > aux2)
        {
            cout << "-1\n";
            return;
        }
        X = aux;
        Y = aux2 + A[i] - 1;
    }
    cout << X << " " << Y << "\n";
}
int main()
{
    Read();
    Solve();
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

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

    int st=A/0.08;
    int ed=(A+1)/0.08;

    int ans=-1;
    for(int i=st;i<=ed;i++){
        if((int)(i*0.08)==A&&i/10==B){
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3640
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <string>
#include <cctype>
#include <vector>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 100007;
const int INF = 0x3f3f3f3f;

char str[N];

bool ok(int l, int r)
{
    int a = l % 3;
    int b = r % 3;
    if (a == 0)
    {
        a = 3;
    }
    if (b == 0)
    {
        b = 3;
    }
    return a <= b;
}

int main()
{
    while (scanf("%s", str))
    {
        if (str[0] == '#')
        {
            break;
        }
        int ans = INF;
        for (int l = 1; l <= 9; l++)
        {
            if (l == 5)
            {
                continue;
            }
            for (int r=1;r<=9;r++)
            {
                if (r ==5||l==r|| !ok(l, r) || l == str[0] - '0' || r == str[0] - '0')
                {
                    continue;
                }
                for (int d = 0; d < 2; d++)
                {
                    int nowl = l;
                    int nowr = r;
                    int nowd = d;
                    int nowans = 0;
                    for (int i = 0; str[i]; i++)
                    {
                        int di = str[i] - '0';
                        if (nowd == 0)
                        {
                            if (ok(di, nowr))
                            {
                                nowd = 1;
                                nowl = di;
                            }
                            else
                            {
                                nowr = di;
                                nowans++;
                            }
                        }
                        else
                        {
                            if (ok(nowl, di))
                            {
                                nowd = 0;
                                nowr = di;
                            }
                            else
                            {
                                nowl = di;
                                nowans++;
                            }
                        }
                    }
                    ans = min(ans, nowans);
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1236
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

map<string, int> rest;

int getRest(const string& s)
{
    int n = s.size();
    int i = 0;
    int t = 0;
    while(i < n){
        int j = i+1;
        while(j < n && s[j] != 'R')
            ++ j;
        t += rest[s.substr(i, j-i)];
        i = j;
    }
    return t;
}

int main()
{
    for(int i=1; i<=64; i*=2){
        int len = 64 / i;
        string s = "R";
        if(i >= 10)
            s += i / 10 + '0';
        s += i % 10 + '0';
        rest[s] = len;

        for(int j=i*2; j<=64; j*=2){
            len += 64 / j;
            s += '.';
            rest[s] = len;
        }
    }

    vector<string> dp(2001, "");
    for(int i=0; i<=2000; ++i){
        for(map<string, int>::iterator it=rest.begin(); it!=rest.end(); ++it){
            int j = i + it->second;
            if(j > 2000)
                continue;

            string s = dp[i] + it->first;
            if(dp[j] == "" || s.size() < dp[j].size() || (s.size() == dp[j].size() && s < dp[j]))
                dp[j] = s;
        }
    }

    int d;
    cin >> d;

    while(--d >= 0){
        string s;
        cin >> s;

        int t = getRest(s);
        if(t <= 2000){
            cout << dp[t] << endl;
            continue;
        }

        string ret = dp[1952+t%32].substr(0, 20);
        while(ret[ret.size()-1] != 'R')
            ret = ret.substr(0, ret.size()-1);
        ret = ret.substr(0, ret.size()-1);

        t -= getRest(ret);
        while(t > 2000){
            ret += "R1.";
            t -= 64 + 32;
        }
        ret += dp[t];
        cout << ret << endl;
    }

    return 0;
}

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

int main() {
  int N, M;
  string s, t;
  map<string, int> mp;
  cin >> N;
  for(int i=0; i<N; i++) cin>>s, mp[s]++;
  cin>>M;
  for(int i=0; i<M; i++) cin>>t, mp[t]--;

  int max=0;
  for(auto itr=mp.begin(); itr!=mp.end(); ++itr)
    if(max<itr->second) max=itr->second;
  cout<<max<<endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# -*- coding: utf-8 -*-


from sys import stdin
import itertools



############################################

# read data for n sequences.
temp = stdin.readline().split()
N = int(temp[0])
M = int(temp[1])

data = []
for i in range(M):
    write = stdin.readline().split()
    data.append(write)

mina = 0
maxa = 10e7
for num in data:
    if int(num[0]) > mina:
        mina = int(num[0])
    if int(num[1]) < maxa:
        maxa = int(num[1]) 

count = maxa-mina+1

if count < 0:
    print(0)
else:
    print(count)


Measured memory_bytes: 32244
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;

int n, k;
int a[N];
int main()
{
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++)  scanf("%d", &a[i]);
	printf("%d\n", (n - 1 + k - 2) / (k - 1));
	return 0;
} 

Measured memory_bytes: 4104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
const int M = 3;
ll dp[N][M];
int a[N], b[N], c[N];
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    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] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
    }
    ll res = max(dp[n - 1][0], dp[n - 1][1]);
    cout << max(res, dp[n - 1][2]);
    return 0;
}


Measured memory_bytes: 3840
from numpy import *
from scipy import *
from sys import *

w, h = map(int, input().split())
p = array([int(input()) for i in range(w)])
q = array([int(input()) for i in range(h)])
p = append(p, maxsize)
q = append(q, maxsize)

p, q = sort(p), sort(q)

ans = 0

i, j = 0, 0
w_, h_ = w+1, h+1
while i < w or j < h:
    if p[i] < q[j]:
        ans += p[i]*h_
        w_ -= 1
        i += 1
    else:
        ans += q[j]*w_
        h_ -= 1
        j += 1

print(ans)


Measured memory_bytes: 17692
a=int(input())
b=[a]

for i in range(1,1000000):
  c=b[i-1]
  if c%2==0:
    d=int(c/2)
  else:
    d=c*3+1
  if d in b:
    print(i+1)
    break
  b.append(d)

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

int main() {
  int n;
  cin >> n;
  set<int> s;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    if (s.count(temp))
      s.erase(temp);
    else
      s.insert(temp);
  }
  cout << s.size() << endl;
}

Measured memory_bytes: 4864
//保留所有权利。
#include<iostream>
#include<stdio.h>//printするよ
#include<vector>
#include<algorithm>//辞書順はnext_permutationだよ
#include<set>
#include<string>
#include<sstream>
#include<string.h>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<utility>//swapで数値交換するよ
//END OF LIBRARIES.
#define rt "\n"//改行を最速化させるよ
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(v) for (int i = 0; i < (v).size(); i++) { cin >> (v)[i]; }
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define cncn int cnt=0
#define smsm int sum=0
#define str srting
#define v vector
#define please return
#define AC 0//おまじないだよ
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
//END OF DEFINE.
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
//printf("%02d:%02d:%02d\n", h, m, s);・・・2文字は埋める・h、m、ｓ
//END OF TYPEDEF.

//最大公約数（GCD）を求めるよ
//最小公倍数（LCM）は＜＜　A × B ÷ GCD　 ＞＞で求まるよ

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

//for A以上B未満でI探索 for (int I = A; i <= B; i++)
//string s = to_string(i);
int a = 0, b = 0, x = 0, y = 0, z = 0, n = 0;
string s = ""; asas; cncn;

int main(void) {
	cin >> n;
	x = n / 2;
	for (int i = 1; i <= x; i++) {
		if (i != n - i)cnt++;
	}
	cout << cnt << rt;
	please AC;
}

Measured memory_bytes: 256
/* tempate
 *
 *
 */

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i, n){
        cin >> a[i];
        b[i] = a[i];
    }
    ll mx = *max_element(all(a));
    sort(all(a));
    rep(i, n){
        if(b[i] == mx){
            cout << a[n - 2] << endl;
        }
        else{
            cout << a[n - 1] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4736
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
    int elements[MAX], n;

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

    int maxv = -2000000000;
    int minv = elements[0];

    for (int i = 1; i < n; i++) {
        maxv = max(maxv, elements[i] - minv);
        minv = min(minv, elements[i]);
    }

    cout << maxv << endl;

    return 0;
}



Measured memory_bytes: 3888
#include <iostream>
#include <algorithm>


#define MAX 200001 //2 * 10^6 ここを最低限にしておかないと絶対にいらない計算をやっちゃう
#define MOD 1000000007

using namespace std;

long fac[MAX];
long finv[MAX];

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

void fac_table(){
    fac[0] = 1;
    for(int i=1; i<MAX; i++){
        fac[i] = fac[i-1] * i;
        fac[i] %= MOD;
    }
}

/*
O(n)で計算n<10^6程度なら使える。
最初にfac_table()で初期化
*/
long comb(int n, int k){
    long c = fac[n];
    c *= modinv(fac[k], MOD); c %= MOD;
    c *= modinv(fac[n-k], MOD); c %= MOD;
    return c;
}

int main(){
    long N, K;
    cin >> N >> K;    
    long ans = 0;
    for(long i=K; i<=N+1; i++){
        long upper = (2 * N - i + 1) * i / 2;
        long lower = i * (i - 1) / 2;
        ans += (upper - lower + 1);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<climits>
using namespace std;
void File(){
	freopen("B.in","r",stdin);
	freopen("B.out","w",stdout);
}
#define REP(i,a,b) for(register int i=a;i<=b;++i)
#define DREP(i,a,b) for(register int i=a;i>=b;--i)
#define MREP(i,x) for(register int i=beg[x];i;i=E[i].last)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define inf INT_MAX
const int maxn=2e5+10;
int n,a[maxn],b[maxn];
int main(){
	//File();
	scanf("%d",&n);
	REP(i,1,n)scanf("%d",&a[i]);
	REP(i,1,n)b[a[i]]=b[a[i]-1]+1;
	int Max=0;
	REP(i,1,n)Max=max(Max,b[i]);
	cout<<n-Max<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  ll ans = 1;
  while(ans <= n) ans *= 2;
  cout << ans / 2 << endl;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C: Strange Bank
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

int dsum(int n, int e) {
  int sum = 0;
  while (n) sum += n % e, n /= e;
  return sum;
}

/* subroutines */

/* main */

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

  int minc = n;
  for (int i = 0; i <= n; i++) {
    int c = dsum(i, 6) + dsum(n - i, 9);
    if (minc > c) minc = c;
  }
  printf("%d\n", minc);
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	char s[101];
	int i,len,flg;
	scanf("%s",s);
	len=strlen(s);
	flg=1;
	for(i=0;i<len;i++)	{
		if(i%2==0)	{
			if(s[i]=='L')	{
				flg=0;	break;
			}
		}
		else {
			if(s[i]=='R')	{
				flg=0;	break;
			}
		}
	}
	if(flg==1)	printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
import bisect

def solve(s: str, t: str):
    LENS = len(s)
    dict_s = {} ##{'c': [0], 'o': [1], 'n': [2], 't': [3, 6], 'e': [4], 's': [5]}
    index = [] ##[[5], [4], [2], [3, 6], [4], [2], [0], [4]]

    ## create dict
    for i in range(LENS):
        if dict_s.get(s[i]) != None:
            dict_s[s[i]].append(i)
        else:
            dict_s[s[i]]= [i]
    
    ## そもそもtが作れるかの判定
    for tt in t:
        if dict_s.get(tt) == None:
            print(-1)
            return
        else:
            index.append(dict_s[tt])
    
    answer = 0
    for i in range(len(index)):
        cur = index[i]

        if i == 0:
            answer += cur[0]
            index[i]=[cur[0]]
            continue

        prev = index[i-1]

        if len(cur)==1:
            if cur[0]>prev[0]:
                answer += cur[0]-prev[0]
            else:
                answer += cur[0]+LENS-prev[0] ##一周追加
        else: ##複数
            next_index = bisect.bisect_left(cur,prev[0])

            if next_index<len(cur)-1: ## prevより大きいindexがある時
                next_index += 1 if cur[next_index] == prev[0] else 0
                
                answer += cur[next_index]-prev[0]
                index[i]= [cur[next_index]]
            elif next_index==len(cur)-1:
                if prev[0]<cur[next_index]:
                    answer += cur[next_index]-prev[0]
                    index[i] =[cur[next_index]]
                elif prev[0]==cur[next_index]:
                    answer += cur[0]+LENS-prev[0]
                    index[i] =[cur[0]]
            else: ##next_index==len(cur):
                answer += cur[0]+LENS-prev[0]
                index[i] = [cur[0]]
       

    print(answer+1)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    t = next(tokens)  # type: str
    solve(s, t)

if __name__ == '__main__':
    main()


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll x;
    cin >> x;
    ll sum = 0;

    if (x % 11 <= 6)
    {
        if (x % 11 == 0)
            sum = 0;
        else
            sum += 1;
    }
    else
    {
        sum += 2;
    }

    sum += (x / 11) * 2;
    OP(sum);

    return 0;
}

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

Measured memory_bytes: 1720
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

int main()
{
    string s;
    vector<char> ch;
    while(cin>>s)
    {
        int len1=s.size();
        for(int i=0;i<len1;i++)
        {
            if(s[i]=='0')
            {
                ch.push_back('0');
            }
            else if(s[i]=='1')
            {
                ch.push_back('1');
            }
            else if(!ch.empty())
            {
                ch.pop_back();
            }
        }
        int len2=ch.size();
        for(int i=0;i<len2;i++)
        {
            cout<<ch[i];
        }
        cout<<endl;
    }
    return 0;
}


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

int main()
{
    int N, max = 0, sum = 0;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++)
    {
        cin >> p[i];
    }
    for (int i = 0; i < N; i++)
    {
        if (max < p[i])
        {
            max = p[i];
        }
    }
    for (int i = 0; i < N; i++)
    {
        sum += p[i];
    }
    cout << (sum - max) + max / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a[200005];
long long s[200005]={0};
int main()
{
	int i,j,next=2,k;
	long long now=0,co=0,n,nn;
	cin>>n;
  	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		s[i]=s[i-1]+a[i];
	}
	for(i=1;i<=n;i++)
	{
	    now=a[i];
	    for(j=max(next,i+1);j<=n;j++)
		{
	      	if(j==max(next,i+1)&&j!=i+1) now=nn^a[i-1];
	      	else now ^=a[j];
	      	if(now==s[j]-s[i-1]) co+=j-i;
	      	else 
		  	{	
			  	next = j;
				nn = now;
				break;
	      	}
	    	if(j==n)i=n;
		}
	}
	cout <<co+n<<endl;
  	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    cin >> S;
    int ans = S.size();
    for (int i = 0; i < 2; i++)
    {
        int cnt = 0;
        for (int j = 0; j < S.size(); j++)
        {
            if (j % 2 == 0 && S[j] != char(i + '0'))
                cnt++;
            if (j % 2 == 1 && S[j] == char(i + '0'))
                cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
int n;
cin >> n;
vector<pair<ll,ll>>a(n);
for(int i=0;i<n;i++){
	ll aa,bb;
	cin >> aa >>bb;
	a.at(i)=make_pair(aa,bb);
}
ll ans = 0;
reverse(a.begin(),a.end());
for(int i=0;i<n;i++){
	if((ans+a.at(i).first)%a.at(i).second==0)continue;
	ll che = (ans+a.at(i).first)%a.at(i).second;
	ans += a.at(i).second-che;
}
cout << ans << endl;
}





Measured memory_bytes: 2300
n = int(input())
s = str(input())
t = str(input())
s_rev = s[::-1]
count = 0

for i in range(1, n+1):
    sub_str = (s_rev[0:i])[::-1]
    if t[0:i] == sub_str and t[0:i][0] == sub_str[0]:
        count = max(count, len(sub_str))
print((2*n) - count)

# for i in range(n):
#     if list(s_rev)[i] == list(t)[i]:
#         count += 1
# if s == t:
#     print(n)
# else:
#     print((2 * n)-count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long int
#define PI 3.14159265359
using namespace std;

int main()
{
    ll ans = LLONG_MAX;
    ll a, b, m;
    cin >> a >> b >> m;
    vector<ll> reizoko(a + 1), renzi(b + 1);
    vector<tuple<ll, ll, ll>> waribiki(m);
    for(ll i = 0; i < a; i++) cin >> reizoko[i + 1];
    for(ll i = 0; i < b; i++) cin >> renzi[i + 1];
    for(ll i = 0; i < m; i++){
        cin >> get<0>(waribiki[i]) >> get<1>(waribiki[i]) >> get<2>(waribiki[i]);
    } 

    for(ll i = 0; i < m; i++){
        ans = min(ans, reizoko[get<0>(waribiki[i])] + renzi[get<1>(waribiki[i])] - get<2>(waribiki[i]));
    }
    auto itr1 = reizoko.begin();
    itr1++;
    auto itr2 = renzi.begin();
    itr2++;


    ans = min(ans, *min_element(itr1, reizoko.end()) + *min_element(itr2, renzi.end()));

    cout << ans << endl;

    


    return 0;
}

Measured memory_bytes: 4096
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
				
		while(true){
			String tmpStr = br.readLine();
			
			if(tmpStr == null){
				break;
			}

			int answer = Integer.parseInt(tmpStr);
			int count = 0;
			for(int i = 0; i <= 9999; i++){
				int tmp = i/1000+(i%1000)/100+(i%100)/10+i%10;
				if(tmp == answer){
					count++;
				}
			}
			
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 24756
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace VirtualAtCorder
{
    class Program
    {



        static void Main(string[] args)
        {
            string inputs = Console.ReadLine();

            int cnt = 1, cnt_max = 0;

            char integer = ' ';

            string output = "";

            foreach (char c in inputs)
            {
                if (c == integer)
                {
                    cnt++;
                }
                else
                {
                    cnt = 1;
                }
                cnt_max = (cnt_max < cnt) ? cnt : cnt_max;

                integer = c;
            }

            output = (cnt_max >= 3) ? "Yes" : "No";

            Console.WriteLine(output);

            Console.ReadKey();
        }

    }
}


Measured memory_bytes: 11220
import java.util.*

var n = 0
var q = 0
var p = IntArray(0)
var x = LongArray(0)
var g = Array(0){ArrayList<Int>()}
var queries = LongArray(0)
var scores = LongArray(0)

fun main(args: Array<String>) = IO().exec {
    n = int()
    q = int()
    g = Array(n){ArrayList<Int>()}
    for (i in n-1) {
        val a = int()-1
        val b = int()-1
        g[a].add(b)
        g[b].add(a)
    }
    p = IntArray(q)
    x = LongArray(q)
    queries = LongArray(n)
    scores = LongArray(n)
    for (i in q) {
        p[i] = int()-1
        x[i] = long()
        queries[p[i]] += x[i]
    }
    rec(0, -1, 0)
    println(scores.joinToString(" "))
}

fun rec(cur: Int, pre: Int, delta: Long) {
    val d = delta + queries[cur]
    scores[cur] = d
    for (v in g[cur]) {
        if (v == pre) continue
        rec(v, cur, d)
    }
}

// region template
operator fun Int.iterator() = 0.until(this).iterator()

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = java.io.PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }

    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }

    fun string(): String {
        if (!hasNext()) throw java.util.NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun long(): Long {
        if (!hasNext()) throw java.util.NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}
// endregion


Measured memory_bytes: 103224
#include <iostream>
#include <cstring>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
	string a;
	cin >> a;
	int l = a.size();
	int i;
	int f = 0;
	for (i = 0 ; i < l ; i++){
		if (f == 0 && a[i] == 'C')
			f++;
		if (f == 1 && a[i] == 'F'){
			f++;
			break;
		}
	}
	if (f == 2)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
#define enl "\n";
using namespace std;
using ll=long long;
using ld=long double;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; }
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) for (auto vvv : vv) cout << vvv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class CPrison {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int n, m;
	    in >> n >> m;
	    int l, r;
	    int resl=1, resr=n;
	    for(int i=0; i<m; i++){
            in >> l >> r;
            chmax(resl, l);
            chmin(resr, r);
	    }

	    out << max(resr-resl+1, 0) << endl;
	}
};


int main() {
	CPrison solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

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

long long lcm(long long a, long long b){
	return a * b / gcd(a, b);
}

int n;
long long *d;
long long *v;
long long tg,tl;
long long ans;

int main(){
	while(true){
		cin >> n;
		if(!n)
			return 0;
		d = new long long[n];
		v = new long long[n];
		tl = 1;
		for(int i=0; i<n; i++){
			cin >> d[i] >> v[i];
			long long tmp = gcd(d[i], v[i]);
			d[i] /= tmp;
			v[i] /= tmp;
			tl = lcm(tl, d[i]);
			if(!i)
				tg = v[i];
			else
				tg = gcd(tg, v[i]);
		}
		for(int i=0; i<n; i++)
			cout << tl * v[i] / d[i] / tg << endl;
		delete[] d;
		delete[] v;
	}
}

Measured memory_bytes: 0
#include<stdio.h>
#include<algorithm>
using namespace std;
int prime[1100000];
int table[1200][1200];
pair<int,int> dp[1200][1200];
int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};
int main(){
	int a,b;
	prime[0]=prime[1]=-1;
	for(int i=2;i<1100000;i++){
		if(~prime[i]){
			prime[i]=1;
			for(int j=i+i;j<1100000;j+=i)prime[j]=-1;
		}
	}
	
	while(scanf("%d%d",&a,&b),a){
		int sr;
		int sc;
		int at=0;
		int dir=0;
		int row=600;
		int col=600;
		for(int i=0;i<1200;i++)
			for(int j=0;j<1200;j++){
				table[i][j]=0;
				dp[i][j]=make_pair(-99999,-99999);
			}
		for(int i=0;i<a;i++){
			table[row][col]=i+1;
			if(b==i+1){
				sr=row;
				sc=col;
			}
			row+=dx[dir%4];
			col+=dy[dir%4];
			at++;
			if(at==dir/2+1){
				dir++;
				at=0;
			}
		}
		dp[sr][sc]=make_pair(0,0);
		if(~prime[table[sr][sc]])dp[sr][sc]=make_pair(1,table[sr][sc]);
		pair<int,int>ret=dp[sr][sc];
		for(int i=1;i<1199;i++){
			for(int j=1;j<1199;j++){
				ret=max(ret,dp[i][j]);
				if(dp[i][j].first<0)continue;
				if(~prime[table[i+1][j-1]]){
					dp[i+1][j-1]=max(dp[i+1][j-1],make_pair(dp[i][j].first+1,table[i+1][j-1]));
				}else{
					dp[i+1][j-1]=max(dp[i+1][j-1],dp[i][j]);
				}
				if(~prime[table[i+1][j]]){
					dp[i+1][j]=max(dp[i+1][j],make_pair(dp[i][j].first+1,table[i+1][j]));
				}else{
					dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
				}
				if(~prime[table[i+1][j+1]]){
					dp[i+1][j+1]=max(dp[i+1][j+1],make_pair(dp[i][j].first+1,table[i+1][j+1]));
				}else{
					dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]);
				}
			}
		}
		printf("%d %d\n",ret.first,ret.second);
	}
}

Measured memory_bytes: 22200
#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979323846264338327950L

int main(void) {
  int a, b, h, m;
  scanf("%d%d%d%d", &a, &b, &h, &m); 
  long double rad = PI * 2 * ((long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long double)m / 60.0);
  long double rsq = (long double)(a * a + b * b) - (long double)(2 * a * b) * cosl(rad);
  printf("%20.20Lf\n", sqrtl(rsq));
  return 0;
 }


Measured memory_bytes: 2584