akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define deb(x) cout<<#x<<" "<<endl;
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
//-------------------------------------------------------------------------------





int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int n;
	cin>>n;
	int arr[n+1],dp[n+1]={0};
	for(int i=1;i<=n;++i){
		cin>>arr[i];
	}
	
	dp[2]=abs(arr[2]-arr[1]);
	for(int i=3;i<=n;++i){
		dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i]),dp[i-2]+abs(arr[i-2]-arr[i]));
		// cout<<i<< " "<<dp[i]<<endl;
	}		
	cout<<dp[n]<<endl;


}
 

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

using namespace std;

int main()
{
  long long n,a,b;
  cin>>n>>a>>b;
  
  long long result=0;
  if((n%(a+b)>=a))
  	result+=((n/(a+b))*a+a);
  else
    result+=((n/(a+b))*a+n%(a+b));
  cout<<result<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b;
    while(1){
        cin >> a >> b;
        if(a==0 && b==0)break;
        else{
            if(a<=b){
                cout << a << " " << b << endl;
            }else{
                cout << b << " " << a << endl;
            }
        }
    }return 0;
}


Measured memory_bytes: 3104
import sys
input = sys.stdin.readline

A,B,C,D,E,F = list(map(int, input().split()))

W = set()
for a in range(0, F+1, A*100):
  for b in range(0, F+1, B*100):
    w = a+b
    if w==0 or w>F: continue
    W.add(w)

S = set()
for c in range(0, F+1, C):
  for d in range(0, F+1, D):
    s = c+d
    if s>F: continue
    S.add(s)

d_max = -1
ans = None
for w in W:
  for s in S:
    if w*E//100<s or w+s>F: continue
    d = 100*s/(w+s)
    if d>d_max:
      d_max = d
      ans = (w+s, s)

print(*ans)

Measured memory_bytes: 3188
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readFloat64() float64 {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return float64(i)
}

const MOD = 1000000007

func main() {
	sc.Split(bufio.ScanWords)
	n, m := readInt(), readInt()

	fmt.Println(ModComb(n, 2, MOD) + (ModComb(m, 2, MOD)))

}

func ModComb(n, k, mod int) int {
	if n < 0 || k < 0 || k > n {
		return 0
	}
	if k > n-k {
		k = n - k
	}
	return ModFact(n, mod) * (ModInv(ModFact(k, mod), mod) * ModInv(ModFact(n-k, mod), mod) % mod) % mod
}

func ModFact(x, mod int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % mod
	}
	return fact
}

func ModInv(x, mod int) int {
	return ModPow(x, mod-2, mod)
}

func ModPow(a, n, mod int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % mod
		}
		a = a * a % mod
		n /= 2
	}
	return res
}

func pow(a, n int) int {
	if n == 0 {
		return 1
	}

	ans := 0
	if n%2 == 0 {
		ans = pow(a*a, n/2)
	} else {
		ans = a * pow(a*a, (n-1)/2)
	}
	return ans
}


Measured memory_bytes: 640
n=int(input())

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

li=make_divisors(n)

if len(li)%2==0:
    x=len(li)//2
    y=x-1
    ans=li[x]+li[y]-2
else:
    x=len(li)//2
    ans=li[x]*2-2
print(ans)


Measured memory_bytes: 3296
from itertools import permutations
from math import factorial
n = int(input())
p = tuple(map(int, input().split(' ')))
q = tuple(map(int, input().split(' ')))

l = [i for i in range(1, n+1)]
ls = list(permutations(l))

for i in range(factorial(n)):
    if p==ls[i]:
        a = i
    if q==ls[i]:
        b = i

print(abs(a-b))

Measured memory_bytes: 13952
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
//const int PI = acos(-1);
int main(){
	string x;cin>>x;
	int s=0,t=0;
	bool f=true;
	if(x[0]=='T'){
		f=false;
		t++;
	}
	else s++;
	int ans =x.length();
	rep(i,x.length()){
		if(i==0)continue;
		if(f){
			if(x[i]=='T'){
				f=false;
				s--;
				ans-=2;
			}
			else s++;
		}
		else{
			if(x[i]=='S'){
				s++;
				f=true;
			}
			else{
				if(s!=0){
					s--;
					ans-=2;
				}
			}
		}
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 640
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}


int main(){
    int N;
    cin >> N;
    int pos=0;
    LL ans=0;
    while(pos<N){
        ans+=800;
        ++pos;
        if(pos%15==0){
            ans-=200;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int a, b, c, i, ans = 0;
    
    cin>> a >> b >> c;
    
    for(i = a ; i <= b ; i++){
        if(c % i == 0){
            ans = ans + 1;
        }
    }
    cout<< ans << endl;
    
}


Measured memory_bytes: 3112
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
const long long MOD = 1'000'000'007;  //'

int main() {
    size_t N;
    cin >> N;
    vector<long long> A(N);
    for (long long &Ai : A) cin >> Ai;

    vector<long long> A_partial(N);
    partial_sum(A.begin(), A.end(), A_partial.begin());

    long long sum = 0LL;
    for (size_t i = 0; i < N - 1UL; i++) {
        // A_{i+1} から A_N までの総和
        long long sum_Aj_N = A_partial.at(N - 1UL) - A_partial.at(i);
        sum_Aj_N %= MOD;

        sum += sum_Aj_N * A.at(i);
        sum %= MOD;
    }

    cout << sum << "\n";

    return 0;
}


Measured memory_bytes: 6428
package main

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

/*
ボーナスを取らないのなら純粋に配点の高い問題を解くのがよい
*/

var d, g int
var P, C []int
var answer int

var sc = bufio.NewScanner(os.Stdin)

// NextLine reads a line text from stdin, and then returns its string.
func NextLine() string {
	sc.Scan()
	return sc.Text()
}

// NextIntsLine reads a line text, that consists of only integers delimited by spaces, from stdin.
// And then returns intergers slice.
func NextIntsLine() []int {
	ints := []int{}
	intsStr := NextLine()
	tmp := strings.Split(intsStr, " ")
	for _, s := range tmp {
		integer, _ := strconv.Atoi(s)
		ints = append(ints, integer)
	}
	return ints
}

func main() {
	tmp := NextIntsLine()
	d, g = tmp[0], tmp[1]
	for i := 0; i < d; i++ {
		tmp = NextIntsLine()
		p, c := tmp[0], tmp[1]
		P = append(P, p)
		C = append(C, c)
	}

	answer = 1000000
	recursion(0, 0)
	fmt.Println(answer)
}

func recursion(i, bits int) {
	if i == d {
		tmp := solvedProbNum(bits)
		if tmp < answer {
			answer = tmp
		}
		return
	}

	recursion(i+1, bits|(1<<byte(i)))
	recursion(i+1, bits)
}

func solvedProbNum(bits int) int {
	score := 0
	probNum := 0
	for i := 0; i < d; i++ {
		bit := 1 & (bits >> byte(i))
		if bit == 1 {
			score += P[i]*(i+1)*100 + C[i]
			probNum += P[i]
		}
	}

	if score >= g {
		return probNum
	}

	residual := g - score
	maxId := -1
	for i := d - 1; i >= 0; i-- {
		bit := 1 & (bits >> byte(i))
		if bit == 0 {
			maxId = i
			break
		}
	}
	if maxId == -1 {
		return 1000001
	}

	q := residual / (100 * (maxId + 1))
	r := (residual / 100) % (maxId + 1)
	if r > 0 {
		q++
	}
	if q >= P[maxId] {
		return 1000001
	} else {
		return probNum + q
	}
}


Measured memory_bytes: 640
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
    line := readLine()
    flag := map[string]bool{"a":false, "b":false, "c":false}
    
    for i:=0; i<len(line); i++ {
        flag[line[i:i+1]] = true
    }
    
    if flag["a"] == true && flag["b"] == true && flag["c"] == true {
        fmt.Println("Yes")
    } else {
        fmt.Println("No")
    }
}

func readLine() string {
	sc.Scan()
	return sc.Text()
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    ll r,d,x;
    cin>>r>>d>>x;
    FOR(i,2001,2010+1){
        x = r*x - d;
        cout<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static Scanner s = new Scanner(System.in);

    public static void main(String[] args) {
        int[] num;
        int n;

        while ((n = s.nextInt()) != 0) {
            int limit = n * 2 + 1;

            num = new int[limit];
            num[2] = 1;

            for (int i = 3; i < limit; i += 2) {
                if (num[i] != 0) continue;
                num[i] = 1;
                for (int j = i * 2; j < limit; j += i)
                    num[j] = -1;
            }

            int ans=0;

            for(int i=n+1;i<limit;i++){
                if(num[i]==1) ans++;
            }
            System.out.println(ans);
        }

    }
}

Measured memory_bytes: 54444
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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 INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll a, b;
    cin>>a>>b; a--; b--;

    cout<<100<<" "<<100<<endl;

    vector<string> grid(100);
    rep(i, 100) rep(j, 100) {
        if (i < 50) grid[i].push_back('#');
        else grid[i].push_back('.');
    }
    rep(i, a) {
        grid[i / 50 * 2][2 * i % 100] = '.';
    }
    rep(i, b) {
        grid[99 - i / 50 * 2][2 * i % 100] = '#';
    }

    rep(i, 100) {
        rep(j, 100) cout<<grid[i][j];
        cout<<endl;
    }
}

Measured memory_bytes: 256
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(n: usize, vs: [i64; n], cs: [i64; n]);
    let mut ans = 0;

    use std::cmp::max;
    for i in 0..n {
        ans += max(0, vs[i] - cs[i]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var)\
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

int main() {
  int n;
  cin >> n;
  if (n == 0) return 0;
  vector<int> nums;
  int min_ = numeric_limits<int>::max();
  for (int i = 0; i < n ; ++i) {
    int t;
    cin >> t;
    nums.push_back(t);
    min_ = min(min_, t);
  }
  // set<int> sorted(nums.begin(), nums.end());
  vector<int> sorted(nums.begin(), nums.end());
  sort(sorted.begin(), sorted.end());
  unordered_map<int, size_t> indices;
  for (size_t i = 0; i < sorted.size(); ++i) {
    indices.insert(make_pair(sorted[i], i));
  }
  vector<bool> done(nums.size(), false);
  unordered_set<int> cycle;
  int cost = 0;
  for (size_t i = 0; i < nums.size(); ++i) {
    if (done[i]) continue;
    done[i] = true;
    cycle.clear();
    auto value = nums[i];
    int cycle_min = value;
    cycle.clear();
    while (cycle.insert(value).second) {
      cycle_min = min(cycle_min, value);
      auto index = indices[value];
      value = nums[index];
      done[index] = true;
    }

    if (cycle.size() > 1) {
      cycle.erase(cycle_min);
      auto sum_ = accumulate(cycle.begin(), cycle.end(), 0);
      auto v1 = sum_ + cycle_min * cycle.size();
      auto v2 = sum_ + (cycle_min + min_) * 2 + min_ * cycle.size();
      cost += min(v1, v2);
    }
  }

  cout << cost << endl;
}

Measured memory_bytes: 3240
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9+7;
//const ll MOD = 998244353;
//const ll MOD = 924844033;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
const double EPS = 1e-5;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

#ifdef DEBUG
#define OUTPUT(x) (output(x), outendl())
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}


int main(){
	set<int> s;
	int n;
	cin >> n;
	rep(i,n){
		int d;
		cin >> d;
		s.insert(d);
	}
	cout << s.size() << endl;
	return 0;
}



Measured memory_bytes: 7760
s = int(input())
a = [s]
i = 0
while True:
    if a[i] % 2 == 0:
        a.append(a[i] / 2)
    else:
        a.append(3 * a[i] + 1)
    i += 1
    if a[i] in a[:i]:
        print(int(i+1))
        exit()

Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

w,a,b=map(int,input().split())
if (a<=b<=a+w or b<=a<=b+w):
    print(0)
else:
    print(min(abs(a-(b+w)),abs(a+w-b)))

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;


signed main(){
    int N, p[10];
    cin >> N;
    REP(i, N) cin >> p[i];
    sort(p, p + N, greater<int>());
    int sum = p[0] / 2;
    FOR(i, 1, N) sum += p[i];
    PRINT(sum);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
using namespace std;

const long long mod = 1e9+7;

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

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

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

  vector<int> left(N+1, 0), right(N+1, 0);

  for(int i = 0; i < N; i++)      left[i+1] = gcd(A[i], left[i]);
  for(int i = N - 1; i >= 0; i--) right[i]  = gcd(A[i], right[i+1]);

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    ans = max(gcd(left[i],right[i+1]), ans);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4480
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

int main(){
	int x, a, b;

	std::cin>>x>>a>>b;

	int ad= std::abs(x-a);
	int bd= std::abs(x-b);

	if(ad<bd)
		std::cout<<"A"<<std::endl;
	else 
		std::cout<<"B"<<std::endl;

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 1200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int n;
int h[maxn], nxt[maxn];
int s[maxn];


inline void link(int f,int x) {
	nxt[x] = h[f], h[f] = x;
}
int dp[maxn];
inline void down(int & x,int y) { if(x > y) x = y; }
inline void dfs0(int x) {
	for(int i = h[x];i;i = nxt[i]) {
		dfs0(i);
	}
	static int g0[10100], g1[10010];
	rep(i, 1, s[x]) g0[i] = 1e9;
	g0[0] = 0;
	for(int i = h[x];i;i = nxt[i]) {
		rep(i, 0, s[x]) g1[i] = g0[i], g0[i] = 1e9;
		rep(j, 0, s[x]) {
			if(j + dp[i] <= s[x]) {
				down(g0[j + dp[i]], g1[j] + s[i]);
			}
			if(j + s[i] <= s[x]) {
				down(g0[j + s[i]], g1[j] + dp[i]);
			}
		}
	}
	dp[x] = 1e9;
	rep(i, 0, s[x]) down(dp[x], g0[i]);
	if(dp[x] > 1e8) {
		cout << "IMPOSSIBLE" << '\n';
		exit(0);
	}
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	rep(i, 2, n) {
		int f; cin >> f;
		link(f, i);
	}
	rep(i, 1, n) {
		cin >> s[i];
	}
	dfs0(1);
	cout << "POSSIBLE" << '\n';
}


Measured memory_bytes: 384
s=int(input())
z=[s]
x=[]
for _ in range(100000):
    x.append(z[-1])
    if z[-1]%2==0:
        z.append(z[-1]//2)
    else:
        z.append(3*z[-1]+1)
    if z[-1] in x:
        print(len(z))
        break

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll, ll>
#define SZ(x) ((int)(x).size())
// #define endl "\n"
#define vvi vector<vector<int> >
#define vvl vector<vector<long long> >
ll mod = 1e9 + 7;
//const double pi = acos(-1.0);
/*
ll kmp(string x)
{
    ll n= x.length();
    //cout<<x<<endl;
    vector<ll> lcp(x.length(), 0);
    for(ll i=1;i<n;i++)
    {
        ll j=lcp[i-1];
        while(j>0 && x[j]!=x[i])
            j=lcp[j-1];
        if(x[i]==x[j])
            j++;
        lcp[i]=j;
    }
    return lcp[n-1];
}

int N = 1000002;
int ar[100002];
void sieve()
{
    for(int i=1;i<=N;i++)
        ar[i] = 1;
    ar[0] = 0;
    for(int i=2;i*i<=N;i++)
    {
        if(ar[i] && i*i<=N)
        {
            for(int j = i*i; j<=N;j+=i)
                ar[j] = 0;
        }
    }
}

ll modex(ll a,ll b){
    if(b<=0){
        return 1;
    }
    if(b%2==0)
    {
        ll x = modex(a, b/2);
        return ((x*x)%mod);
    }
    else
        return ((a%mod * modex(a, b-1))%mod);
}

ll c[1010][1010];

ll combina(ll i, ll j){
        for (int i=0;i<=1005;i++)
        for (int j=0;j<=i;j++)
        {
            if (j==i||j==0)
                c[i][j]=1;
            else
            c[i][j]=c[i-1][j-1]+c[i-1][j];
            c[i][j]%=mod;
        }
        return c[i][j];
}
void find_fac(int x){
    vector<ll> di;
    for(ll i = 2; i*i <= x; i++)
    {
        if(x%i==0){
            di.push_back(i);
            while(x%i==0)
                x/=i;
        }
    }
    if(x > 1)
        di.push_back(x);
}
*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed;
    cout.precision(12);
    int x;
    cin>>x;
    if(x>=30)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3660
# -*- coding: utf-8 -*-
def main():
    s = input()
    t = input()
    len_s = len(s)
    len_t = len(t)
    dp = [[0] * len_t for i in range(len_s)]

    for j in range(len_t):
        if s[0] == t[j]:
            for k in range(j, len_t):
                dp[0][k] = 1
            break

    for i in range(len_s):
        if s[i] == t[0]:
            for k in range(i, len_s):
                dp[k][0] = 1
            break
    
    for i in range(1, len_s):
        for j in range(1, len_t):
            if s[i] == t[j]:
                dp[i][j]  = dp[i-1][j-1] + 1
            else:
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
    length = dp[-1][-1]
    i = len_s - 1
    j = len_t - 1
    ans = ''
    while (length > 0):
        if s[i] == t[j]:
            ans = s[i] + ans
            i -= 1
            j -= 1
            length -= 1
        elif (j > 0 and dp[i][j - 1] == dp[i][j]) or i == 0:
            j -= 1
        else:
            i -= 1
            
    # for d in dp:
    #     print(d)
    
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 138932
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		Long[] p = new Long[a];
		Long[] q = new Long[b];
		Long[] r = new Long[c];

		Long[] pq = new Long[x + y];

		for(int i = 0 ; i < a ; i++) {
			p[i] = sc.nextLong();
		}
		for(int i = 0 ; i < b ; i++) {
			q[i] = sc.nextLong();
		}
		for(int i = 0 ; i < c ; i++) {
			r[i] = sc.nextLong();
		}
		Arrays.sort(p, Comparator.reverseOrder());
		Arrays.sort(q, Comparator.reverseOrder());
		Arrays.sort(r, Comparator.reverseOrder());

		long sum = 0;

		for(int i = 0 ; i < x ; i++) {
			sum += p[i];
			pq[i] = p[i];
		}
		for(int i = 0 ; i < y ; i++) {
			sum += q[i];
			pq[i + x] = q[i];
		}
		Arrays.sort(pq);

		int change = 0;
		for(int i = 0 ; i < Math.min(x + y, c) ; i++) {
			if(r[i] > pq[change]) {
				sum += r[i] - pq[change];
				change++;
			}
		}

		System.out.println(sum);
		sc.close();

	}
}



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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

constexpr ll INF = TEN(18);

int main() {
    int N, K;
    cin >> N >> K;
    V<int> P(N), C(N);
    rep(i, N) cin >> P[i], --P[i];
    rep(i, N) cin >> C[i];

    ll ans = -INF;

    rep(i, N) {
        int v = i;
        ll cycle_sum = 0;
        int cycle_cnt = 0;

        while (true) {
            cycle_cnt++;
            cycle_sum += C[v];
            v = P[v];
            if (v == i) break;
        }

        ll path = 0;
        int cnt = 0;

        while (true) {
            cnt++;
            path += C[v];

            if (cnt > K) break;

            int num = (K - cnt) / cycle_cnt;
            ll score = path + max(0ll, cycle_sum) * num;
            chmax(ans, score);

            v = P[v];
            if (v == i) break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#include <set>
#include<math.h>
#include <typeinfo>
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double    ld;
typedef pair <ll,ll>  pll;
typedef pair <int,int> pii;
#define rep(h)    for (long long int e=0; e<h; e++)
#define srep(a,b) for (int e=a; e<b; e++)
#define rrep(a,b) for (int e=a; e>b; e--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

// int binsearch(int l,int r, int arr,int x)
// {  int m= (l+r)/2;
//  while (l<r)
//  {
//        if(x==arr[m]) return x;
//        else if (x<arr[m]) binsearch(l,m,arr,x);
//        else binsearch(m+1,r,arr,x);

//  }
// ll mod (string str, int k)
// { ll rem;
  




// 	return rem;
// }
// ll mod(string num, ll m) 
// { 
//     // Store the modulus of big number 
//     vector<int> vec; 
//     ll moda = 0; 
  
//     // Do step by step division 
//     for (int i = 0; i < num.size(); i++) { 
           
//         int digit = num[i] - '0'; 
  
//         // Update modulo by concatenating 
//         // current digit. 
//         moda = moda * 10 + digit; 
  
//         // Update quotient  
//         int quo = moda / m; 
//         vec.push_back(quo); 
  
//         // Update mod for next iteration. 
//         moda = moda % m;         
//     } 
//       return moda; 
// } 
//  while(t--)
//  {  cin >> n >> k;
//       vector <ll> val(n);
//       rep (n) cin >> val[e];
//       rep (n)
//       { 
//       	if (fl>0) {cout <<  "NO"; return 0;}
//         string str =to_string( val[e]);
// //        int l = str.size();

//          while (mod (str,k)!=0)
//          {      cout<<"F";
// //            //  if (mod (str,k)==1) 
// //             //  continue;      
//                   if (mod (str,k)<k) break;
//                     str = to_string(mod (str,k));
//          cout << mod(str,k)<<"  ";
//          }
//         if ( mod (str,k) >1) {cout <<  "NO"; return 0;} 
//             val[e]= mod (str,k);
//       }
//  //cout<<"DF";
//  rep (n) {if (val[e]<=1)  cout << val[e]<<")";}
//  cout<<endl;
 // }     

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
 float n; cin >> n;
 cout << fixed << setprecision(12)<< pow(n,3)/27;



    return 0;
}

Measured memory_bytes: 640
#pragma gcc optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i=(ll)(r);i<(ll)(n);++i)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define pb(n) push_back(n)
#define endl '\n'
#define debug(x) cout << #x << " = " << (x) << endl
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c
#define VIN(V) for(int ii = 0; ii < (V).size(); ii++) {cin >> (V).at(ii);}
#define OUT(n) cout << n << endl
#define OUT2(n1,n2) cout << n1 << " " << n2 << endl
#define OUT3(n1,n2,n3) cout << n1 << " " << n2 << " " << n3 << endl
#define VOUT(V) REP(ii,(V).size()){cout << (V)[ii] << " ";} cout<<endl;
#define VOUT2(V) REP(jj,(V).size()){VOUT(V[jj])}
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi > vvi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
ll n, m, k, ans, sum, cnt = 0; string s; char c; bool flg;

int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  ll h,a,b;
  IN2(h,n);

  vi dp(h+1,INF);
  dp[0] = 0;

  FOR(i,0,n) {
    IN2(a,b);
    FOR(j,0,h+1) {
      if (dp[j] != INF) {
        if (j+a >= h) {
          chmin(dp[h], dp[j] + b);
        } else {
          chmin(dp[j+a], dp[j] + b);
        }
      }
    }
  }
  // VOUT(dp);

  OUT(dp[h]);
}


Measured memory_bytes: 384
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)

void print1d(const vector<int>& vec) {for (auto val : vec) {cout << val << " ";} cout << endl;}

void print2d(const vector<vector<int>>& vec) {for (auto row : vec) {for (auto val : row) {cout << val << " ";} cout << endl;}}

signed main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// #endif
	crap;

	int n, a, b;
	cin>>n>>a>>b;

	int ans = 0;

	if(n % (a + b) == 0){
		ans = a * (n / (a+b));
	}else{
		int rem = n % (a + b);
		ans = a * (n / (a + b));
		if(rem <= a)
			ans += rem;
		else
			ans += a;
	}

	cout << ans << endl;

	return 0;
}






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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> okashi(N, 0);
    for (int i = 0; i < K; ++i) {
        int d;
        cin >> d;
        for (int j = 0; j < d; ++j) {
            int A;
            cin >> A;
            --A;
            okashi[A]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < N; ++i) if (okashi[i] == 0) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
using ll = long long;

/*
ある積XがK番目の値⇔「x未満の積がK個未満」であるxの最大値X

proof:
XがK番目の値のときx = X未満の積はK個未満である.
一方でx > Xの場合, K番目の値より大きく少なくともK個以上のx未満の積が存在
よってx = Xがその最大値となる.

次に「x未満の積がK個未満」であるxの最大値をXとしたとき,
x > Xではx未満の積がK個以上存在することになるからこれはK番目の値ではない.
逆にx < XではxはK番目の値ではない. なぜならもしこれがK番目の値であれば,
X未満の積がK個未満にはならないからである. よってx = XがK番目の値
(証明終)

つまり「x未満の積がK個未満である」というクエリに対してTrueを返すときからFalseを返すように
切り替わる瞬間のギリギリのTrueのときを二分探索で調べればよい.

このクエリを実行するにはx未満の積をいくつあるかを調べる必要がある.
例えば次の場合
数列：1 2 3 4
クエリ：x = 6
基本的には積の片方を固定していくつ他方が考えられるかというので数え上げる.
1...1, 2, 3, 4
2...1, 2
3...1
4...1
で8個ですね. ただしペアのうち掛け算として同じ(1, 2), (2, 1)などは重複しないように数え上げる必要がある.
そこで重複して数え上げた数mから(y, y)という同じ数n個を除外して(m - n)/2とすればよいのです.
上の例ならば(8 - 2) / 2= 3個となります. 実際(1, 1), (1, 2), (1, 3), (1, 4), (2, 2)です.


しかしここで注意点があります. それは今回の数列は負の値や0の値を含むということです.
例えば次の場合
数列：-4, -2, 3, 3
クエリ：x = -5
-4...3, 3
-2...3, 3
 3...-2, -4
 3...-2, -4
で8個ですね. 注意するべきことは負の場合は数列の小さい方からどれが満たすのかを探索するのではなく
数列の大きい値から順に探索しなければならないという点です. 
-4に対して3, 3, -2, -4と数字を舐めていかなければなりません. この点だけ注意です.
このときも重複に注意して実際は(8 - 0) / 2= 4個となります.


最後に今回はペアを求めるために数字を順に舐めていきましたが, これでは非常に遅いです.
おこでここでも二分探索を用いてlogNにしておく必要があります.
*/



// 注意------
// 1e18と単に書くとdoubleだと認識されてしまいオーバーフローする
// そのため最初からlong long型だと認識させるために
// ll(1e18)と書く必要がある
const ll INF = ll(1e18)+1; //積の絶対値の上限

int main(){
    ll N, K;
    std::cin >> N >> K;
    std::vector<ll> A(N);
    for(ll i = 0; i < N; i++) std::cin >> A[i];
    std::sort(A.begin(), A.end());

    ll l = -INF, r = INF; // 探索の開始に使用
    while(l + 1 < r){ // lとrが隣り合ったらダメ
        ll x =(l + r) / 2; // クエリ
        auto ok = [&]() -> bool{
            ll num = 0;
            for(ll i = 0; i < N; i++){
                // A[i]のペアを二分探索で調査する
                if(A[i] < 0){
                    // 負の数の場合
                    ll left = -1, right = N;
                    while(left + 1 < right){
                        ll c = (left + right) / 2;
                        if(A[c] * A[i] < x){
                            right = c;
                        }else{
                            left = c;
                        }
                    }
                    num += N - right; // 負の場合は右からの個数
                }else{
                    // 0以上の場合
                    ll left = -1, right = N;
                    while(left + 1 < right){
                        ll c = (left + right) / 2;
                        if(A[c] * A[i] < x){
                            left = c;
                        }else{
                            right = c;
                        }
                    }
                    num += right; // 正の場合は左からの個数
                }

                // 同じペアについての処理
                if(A[i] * A[i] < x) num--;
            }
            // 探索終了
            num /= 2;
            return num < K;
        };


        if(ok()){
            // まだxを上げられる
            l = x;
        }else{
            // もっとxを下げて
            r = x;
        }
    }

    std::cout << l << std::endl;

    return 0;
}

Measured memory_bytes: 1792
S = list(input())

if S.count(S[0]) == len(S):
    print("".join(S))

else:
    if S[0] < S[1]:
        ans = str((int(S[0]) + 1)) * 3
    elif S[0] > S[1]:
        ans = S[0] * 3
    else:
        if S[0] < S[2]:
            ans = str(int(S[0]) + 1) * 3
        else:
            ans = S[0] * 3
            
    print(ans)

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

int main() {
    int k, a, b;
    cin >> k >> a >> b;

    int p1 = (a / k) * k;
    int p2 = ((a / k) + 1) * k;

    cout << ((a <= p1 && p1 <= b) || (a <= p2 && p2 <= b) ? "OK" : "NG") << "\n";
}


Measured memory_bytes: 3624
N, M, X = map(int, input().split())
A = []
C = []
for _ in range(N):
    c, *a = list(map(int, input().split()))
    A.append(a)
    C.append(c)
ans = float("inf")
for b in range(2**N):
    param = [0]*M
    tmp = 0
    for i in range(N):
        if 1&(b>>i):
            tmp += C[i]
            param = list(map(lambda a,b: a+b, A[i], param))
    if all([x>=X for x in param]):
        ans = min(tmp, ans)
if ans==float("inf"):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9036
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using std::cin;
using std::cout;
typedef long long ll;
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 1e6 + 5;
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
struct str
{
	int cnt, *addr;
	bool operator<(str A) const { return cnt < A.cnt; }
} d[Maxn];
int Disc(int t)
{
	rg int tmp = 0;
	std::sort(d + 1, d + t + 1);
	for (int i = 1; i <= t; i++)
	{
		if (i == 1 || d[i].cnt != d[i - 1].cnt)
			d[++tmp] = d[i];
		*d[i].addr = tmp;
	}
	return tmp;
}
int prime[Maxn], cnt, ans;
bool P[Maxn];
ll A, B;
ll gcd(ll x, ll y)
{
	ll z = x % y;
	while (z)
	{
		x = y;
		y = z;
		z = x % y;
	}
	return y;
}
int main()
{
	for (int i = 2; i <= 1000000; i++)
	{
		if (!P[i])
			prime[++cnt] = i;
		for (int j = 1; j <= cnt && i * prime[j] <= 1000000; j++)
		{
			P[i * prime[j]] = true;
			if (i % prime[j] == 0)
				break;
		}
	}
	rg ll x;
	cin >> A >> B;
	x = gcd(A, B);
	for (int i = 1; i <= cnt && x != 1; i++)
		if (x % prime[i] == 0)
		{
			ans++;
			while (x % prime[i] == 0)
				x /= prime[i];
		}
	if (x != 1)
		ans++;
	cout << ans + 1 << '\n';
	return 0;
}
//D

Measured memory_bytes: 1536
#include<iostream>
using namespace std;
int main(){
string n;
int A,B,i,j=0;
cin>>A>>B;
for(i=A;i<=B;i++){
n=to_string(i);
if(n.substr(0,1)==n.substr(4,1)){
if(n.substr(1,1)==n.substr(3,1))j++;
}
}
cout<<j;
}

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

using ll = long long;
using pii = pair<int, int>;

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);

    ll n, k;
    cin >> n >> k;
    ll r = n % k;
    cout << min(r, k - r);
}


Measured memory_bytes: 3628
#!/usr/bin/ruby
n=gets.to_i
x=(n+1).to_s(2).size-1
q=[*1..x]
n-=(1<<x)-1
(x-1).downto(0){|i|
	next if n<1<<i
	x+=1
	q.insert(i,x)
	n-=1<<i
}
q+=[*1..q.size]
p q.size
puts q*' '

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b;
  string s;
  cin >> n >> a >> b >> s;
  bool tuuka[n]={false};
  int a2=0, b2=0;
  for(int i=0; i<n; i++) {
    if(s.at(i)=='a'&&a2+b2<a+b) {
      tuuka[i]=true;
      a2++;
    }
    else if(s.at(i)=='b'&&a2+b2<a+b&&b2<b) {
      tuuka[i]=true;
      b2++;
    }
  }
  for(int i=0; i<n; i++) {
    if(tuuka[i]==true) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
 // cout << a2 << ' ' << b2 << endl;
  return 0;
}

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

using namespace std;

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

	int front = stoi(S.substr(0, 2));
	int back = stoi(S.substr(2, 2));

	bool isFrontOk = 1 <= front && front <= 12;
	bool isBackOk = 1 <= back && back <= 12;

	if (isFrontOk && isBackOk) {
		cout << "AMBIGUOUS" << endl;
	} else if (isFrontOk) {
		cout << "MMYY" << endl;
	} else if (isBackOk) {
		cout << "YYMM" << endl;
	} else {
		cout << "NA" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 5e5+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
	ll x, k , d;
	cin >> x >> k >> d;
	x = abs(x);
	ll z = x / d;
	if(z >= k)
	{
		ll ans = x % d + d * (z - k);
		cout << ans << '\n';
	}
	else
	{
		k = k - z;
		x = x % d;
		ll xx = d - x;
		if(k % 2== 0)
			cout << x;
		else 
			cout << xx;
	}

}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

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

using namespace std;
typedef long long ll;


int main()
{
    int n, x, a;
    scanf("%d", &n);
    n--;
    scanf("%d", &a);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &x);
        a = __gcd(a, x);
    }
    printf("%d\n", a);

    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val inputs = readInputLine().split(" ").map { Integer.parseInt(it) }
    
    val R = inputs[0]
    val G = inputs[1]
    val B = inputs[2]
    val N = inputs[3]
    
    var ans = 0
    
    // 何も考えずにループを回す
    for (i in 0..(N / R)) {
        for (j in 0..((N - R * i) / G)) {
            if ((N - R * i - j * G) % B == 0) {
                ans++
            }
        }
    }
    
    println(ans)
}
 
fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 35992
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq

#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]


N = int(input())
ans = 0

for i in range(1, N+1):
  if(i%3==0):
    pass
  elif(i%5==0):
    pass
  else:
    ans += i


print(ans)


Measured memory_bytes: 75000
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**7)

T=int(input())



def saiki(n):

    if n in memo:
        return memo[n]
        
    if n==0:
        return 0
    elif n==1:
        return D
    else:
        value=min(
            D*n,
            saiki(n//2)    +A+ D *abs(n - n//2*2),
            saiki((n+1)//2)+A+ D *abs(n - (n+1)//2*2),
            saiki(n//3)    +B+ D *abs(n - n//3*3),
            saiki((n+2)//3)+B+ D *abs(n - (n+2)//3*3),
            saiki(n//5)    +C+ D *abs(n - n//5*5),
            saiki((n+4)//5)+C+ D *abs(n - (n+4)//5*5)
            )
        
    memo[n]=value
    return value

for _ in range(T):
    memo={}
    ans=[]
    N,A,B,C,D=map(int,input().split())
    print(saiki(N))

Measured memory_bytes: 10956
#include <stdio.h>
#include <stdlib.h>

int main() {
  int i,n;
  scanf("%d",&n);
  int d;
  int x[102];
  for(i=0;i<102;i++) {
    x[i]=0;
  }
  for(i=0;i<n;i++) {
    scanf("%d",&d);
    x[d]=1;
  }
  int ans = 0;
  for(i=0;i<102;i++) {
    ans += x[i];
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string S;
	cin >> S;
	int m(1000), t;
	for(int i(0);i<S.length()-2;++i){
		t = abs(atoi(S.substr(i,3).c_str()) - 753);
		if(t < m) m = t;
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
from heapq import heapify, heappop, heappush 
x, y, a, b, c = map(int, input().split())
p_List = list(map(int, input().split()))
q_List = list(map(int, input().split()))
r_List = list(map(int, input().split()))
p_List.sort()
q_List.sort()
r_List.sort()

ans = p_List[-x:] + q_List[-y:]
heapify(ans)
for i in r_List[::-1]:
    tmp = heappop(ans)
    if tmp < i:
        heappush(ans, i)
    else:
        heappush(ans, tmp)
        break
print(sum(ans))



Measured memory_bytes: 23456
#include <bits/stdc++.h>
//using namespace std;
int next[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
char mp[100][105];
int book[105][105];
int n,m;
bool fun(int x,int y)
{
    return x >= 0 && y >= 0 && x < n && y < m;
}
void dfs(int x,int y)
{
    book[x][y] = 1;
    for(int k = 0; k <= 3; k++)
    {
        int dx = x + next[k][0], dy = y + next[k][1];
        if(!fun(dx,dy) || mp[dx][dy] != mp[x][y] || book[dx][dy] == 1) continue;
        dfs(dx,dy);
    }
}
int main()
{
    while(scanf("%d %d",&n,&m) == 2 && n && m)
    {
        int cnt = 0;
        memset(book,0,sizeof(book));
        for(int i = 0; i < n; i++) scanf("%s",mp[i]);
        for(int i = 0; i < n; i++) for(int j = 0; j < m; j++)
            if(book[i][j] == 0)
            {
                dfs(i,j);
                cnt++;
            }
        printf("%d\n",cnt);

    }


    return 0;
}



Measured memory_bytes: 4000