akhauriyash/Code-Regression huggingface dataset:
import bisect
import os

import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

# MOD = 998244353


N, M = list(map(int, sys.stdin.buffer.readline().split()))
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]
LR = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]

AB.sort()
odd = 0
# 偶奇が変わる値
nums = [(0, 0)] + AB + [(INF, 0)]
A = [a for a, b in nums]
B = [b for a, b in nums]

size = len(nums)
graph = [[] for _ in range(size)]
for i, (l, r) in enumerate(LR, start=1):
    # l 未満が全部変わる
    v = bisect.bisect_left(A, l) - 1
    # r 以下が全部変わる
    u = bisect.bisect_right(A, r) - 1

    graph[v].append((u, i))
    graph[u].append((v, i))

parity = [0] * size
for i, (b1, b2) in enumerate(zip(B, B[1:])):
    if b1 == 0 and b2 == 1:
        parity[i] = 1
    if b1 == 1 and b2 == 0:
        parity[i] = 1

# 適当に全域木を作って 1 を押し出していけばいい
seen = [False] * size
trees = []
for root in range(size):
    if seen[root] or not graph[root]:
        continue
    edges = []
    seen[root] = True
    stack = [root]
    while stack:
        v = stack.pop()
        for u, i in graph[v]:
            if seen[u]:
                continue
            seen[u] = True
            stack.append(u)
            edges.append((v, u, i))

    # 頂点が1つしかない
    if not edges and parity[root] == 1:
        print(-1)
        exit()
    trees.append(edges)

graph = [[] for _ in range(size)]
degrees = [0] * size
for edges in trees:
    for v, u, i in edges:
        graph[v].append((u, i))
        graph[u].append((v, i))
        degrees[v] += 1
        degrees[u] += 1

ans = []
seen = [False] * size
stack = []
for v, d in enumerate(degrees):
    if d == 1:
        stack.append(v)
while stack:
    v = stack.pop()
    if degrees[v] == 0:
        continue
    assert degrees[v] == 1
    if seen[v]:
        continue
    seen[v] = True
    degrees[v] = 0
    # 葉っぱから内側にずらしてく
    for u, i in graph[v]:
        if seen[u]:
            continue
        if parity[v] == parity[u] == 1:
            parity[u] = parity[v] = 0
            ans.append(i)
        elif parity[v] == 1 and parity[u] == 0:
            parity[u] = 1
            parity[v] = 0
            ans.append(i)
        degrees[u] -= 1
        if degrees[u] == 1:
            stack.append(u)

if 1 in parity:
    print(-1)
else:
    print(len(ans))
    print(*sorted(ans))


Measured memory_bytes: 129372
def get_cycle(pre, nxt, root):
    cycles, checked = [], set()

    # root?????£????????????????????????????????§?????????????????????
    checked |= {root}
    que = nxt[root][:]
    while que:
        root_linked = que.pop()
        checked |= {root_linked}
        if nxt[root_linked]:
            que.extend(nxt[root_linked])

    for i in range(len(pre)):
        if i in checked:
            continue

        # ?????°????????§???????????????????????????
        checking = set()
        while i not in checked:
            checked |= {i}
            checking |= {i}
            i = pre[i]
        if i not in checking: # ?????°????????????
            continue

        # ??????????????´???????????????????????°??¨????????¢???   
        checking.clear()
        while i not in checking:
            checking |= {i}
            i = pre[i]            
            
        cycles.append(checking)
    return cycles

def cycle_cost(cycles, m):
    return sum(m[ci] for cycle in cycles for ci in cycle)

from collections import defaultdict
from itertools import product
def chi_liu_edmonds(g, v, r):
    # ?°??????????????????????????±??????????
    m = [float('inf')] * v
    pre = [None] * v
    for s, t in product(range(v), repeat=2):
        if g[s][t] < m[t]:
            m[t] = g[s][t]
            pre[t] = s
    nxt = defaultdict(list)
    for t, s in enumerate(pre):
        if s is not None:
            nxt[s].append(t)

    cycles = get_cycle(pre, nxt, r)

    # ??¨??¨??£?????????????????´???
    if len(cycles) == 0:
        m[r] = 0
        return sum(m)
    
    not_cycle = set(range(v)).difference(*cycles)
    #????´????????????????
    abridger  = {ni:i for i, ni in enumerate(not_cycle)}
    abridger.update({ci:i + len(not_cycle) for i, cycle in enumerate(cycles) for ci in cycle})
    v_dash = len(not_cycle) + len(cycles)
    g_dash = [[float('inf')] * v_dash for _ in range(v_dash)]
    for s, t in product(range(v), repeat=2):
        s_dash, t_dash = abridger[s], abridger[t]
        if s_dash != t_dash:
            d = g[s][t] if t in not_cycle else g[s][t] - g[pre[t]][t]
            if g_dash[s_dash][t_dash] > d:
                g_dash[s_dash][t_dash] = d
    return chi_liu_edmonds(g_dash, v_dash, abridger[r]) + cycle_cost(cycles, m)

from sys import stdin
readline = stdin.readline

v, e, r = map(int, readline().split())
g = [[float('inf')] * v for _ in range(v)]

for _ in range(e):
    s, t, d = map(int, readline().split())
    if t == r:
        continue
    g[s][t] = d
print(chi_liu_edmonds(g, v, r))

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

int main(){

    int a,b,c;
    cin >> a >> b >> c;
    if(a==b&&b==c) cout << "1";
    else if(a!=b&&b!=c&&c!=a) cout << "3";
    else cout << "2" << endl;

    return 0;
}

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

const int MAXN = 105;
const int MAXK = 52;
const int MAXM = 12;
const int INF = 1<<28;
int M, C, N;
int K[MAXN];
int B[MAXN][MAXK];
vector<int> D[MAXM];
int size[MAXM];
int pos[MAXN];

int tottekuru(int req) {
  int res = 0;
  for(int i = 0; i < M; ++i) {
    vector<int>::iterator it
      = find(D[i].begin(), D[i].end(), req);
    if(it != D[i].end()) {
      D[i].erase(it);
      res += i+1;
      break;
    }
  }

  if(D[0].size() < size[0]) {
    D[0].push_back(req);
    res += 1;
    return res;
  }

  int i, j;
  for(i = 1; i < M; ++i) {
    if(D[i].size() < size[i]) {
      break;
    }
  }
  for(j = i; j < M; ++j) {
    if(D[j].size() + (i == j) < size[j]) {
      break;
    }
  }
  int tmp = *D[0].begin();
  D[0].erase(D[0].begin());
  D[j].push_back(tmp);
  D[0].push_back(req);
  res += i+1 + 1 + j+1 + i+1 + 1;
  return res;
}

int main() {
  while(cin >> M >> C >> N && (M|C|N)) {
    set<int> s;
    for(int i = 0; i < N; ++i) {
      cin >> K[i];
      for(int j = 0; j < K[i]; ++j) {
        cin >> B[i][j];
        s.insert(B[i][j]);
      }
    }
    ++M;
    for(int i = 0; i < M; ++i) {
      if(i+1 == M) size[i] = INF;
      else size[i] = C;
    }
    for(int i = 0; i < MAXM; ++i) D[i].clear();
    D[M-1] = vector<int>(s.begin(), s.end());

    fill(pos, pos+MAXN, 0);
    int res = 0;
    while(1) {
      bool flag = false;
      for(int i = 0; i < N; ++i) {
        if(pos[i] == K[i]) continue;
        flag = true;
        int req = B[i][pos[i]++];
        res += tottekuru(req);
      }
      if(!flag) break;
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1252
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

const double PI=(acos(-1));

ll mygcd(ll a,ll b){
    while(0<b){
        ll r=a%b;
        a=b;
        b=r;
    }
    return a;
}
int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    ll ans=10000000000;
    rep(i,n-1){
        ans=min(ans,mygcd(a[i],a[i+1]));
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 4028
#include <iostream>

using namespace std;

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

if (S.at(0) != S.at(1) && S.at(0)==S.at(2) && S.at(1)==S.at(3))
                cout << "Yes";
else if (S.at(0) != S.at(1) && S.at(1)==S.at(2) && S.at(0)==S.at(3))
                cout << "Yes";
 else if (S.at(0)!= S.at(3)&& S.at(0) == S.at(1)  &&( S.at(2)==S.at(3) ))
            cout << "Yes";
else if (S.at(0)!= S.at(3)&& S.at(0) == S.at(2)  &&( S.at(3)==S.at(1) ))
            cout << "Yes";
else if (S.at(1)!= S.at(2)&& S.at(1) == S.at(0)  &&( S.at(2)==S.at(3) ))
            cout << "Yes";
else if (S.at(1)!= S.at(2)&& S.at(1) == S.at(3)  &&( S.at(0)==S.at(2) ))
            cout << "Yes";
else if (S.at(3)!= S.at(2)&& S.at(2) == S.at(0)  &&( S.at(3)==S.at(1) ))
            cout << "Yes";
else if (S.at(3)!= S.at(2)&& S.at(2) == S.at(1)  &&( S.at(3)==S.at(0) ))
            cout << "Yes";
            else
                cout << "No" ;




    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// created by himo;
/*まず、問題文を確認すると、正答数＝ 一度でもACした問題。　ペナルティ数＝「その問題でACするまでにWAした数」の総和と読み取れる。
このことがわかれば　あとは実装する。
*/
int  main(){
int n,m;
cin >> n >> m;
vector<bool>ac_check(n,false);//その問題でACしたかを判断
vector<int>wa_n(n,0);//その問題を何回WAしたか
int ac=0,wa=0;//この変数が答えになる。
for(int i=0;i<m;i++){
	int z;
	string t;
	cin >> z >> t;
	z--;
	if(t=="WA"){//WAした問題を＋１する。
		wa_n.at(z)++;
	}
	if(!ac_check.at(z)&&t=="AC"){//その問題に初めてACしたとき
		ac++;//ACした問題なので＋１する。
		ac_check.at(z)=true;//ACした問題なのでtrueにする。
		wa+=wa_n.at(z);//ACしたため、これまでのWAした回数分足す。もし、同じ問題でACしたとしても、初めてACしたか判断しているためこのifは偽になる。
	}
}
cout << ac <<" "<<wa<<endl;//正答数　ペナルティー数の順に出力する。
}





Measured memory_bytes: 768
#include<bits/stdc++.h>
	using namespace std; 
	#define max(a, b) (a < b ? b : a) 
	#define min(a, b) ((a > b) ? b : a) 
	#define mod 1e9 + 7 
	#define FOR(a, c) for (int(a) = 0; (a) < (c); (a)++) 
	#define FORL(a, b, c) for (int(a) = (b); (a) < (c); (a)++) 
	#define FORR(a, b, c) for (int(a) = (b); (a) > (c); (a)--) 
	#define INF 1000000000000000003 
	typedef long long int ll; 
	typedef vector<int> vi; 
	typedef vector<long long int> vl; 
	typedef pair<int, int> pi; 
	typedef pair<long long int, long long int> pl; 
	#define F first 
	#define S second 
	#define pb push_back 
	#define POB pop_back 
	#define mp make_pair 
	

	int main()
	 {ios_base::sync_with_stdio(false);
	    cin.tie(NULL);
		ll n,x,y;
		//vector<pl>a(n);
		cin>>n;
		int m=0,c=0;
		FOR(i,n)
		{
			cin>>x>>y;
			if(x==y)
			c++;
			else
			{
				m=max(m,c);
				c=0;
		}}
		m=max(m,c);
			if(m>=3)
			cout<<"Yes"<<endl;
			else
			{
				cout<<"No"<<endl;
			}
		
		
	

		
	return 0;
	}






Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159
int main()
{
	long long int n,m;
	cin>>n>>m;
	long long int arr[m],sum=0;
	for(int i=0;i<m;i++)
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	if(n>=sum)
	{
		cout<<n-sum<<endl;
		return 0;
	}
	else
	{
		cout<<"-1"<<endl;
	}
	
}


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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

////////////////////////////////////////////////////////////////////

const int N = 2e5 + 5;

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	ll n, p; cin >> n >> p;
	ll ans = 1;
	for (int i = 2; 1LL * i * i <= p; i++) {
		int c = 0;
		while (p % i == 0) {
			p /= i;
			if (++c == n) ans *= i, c = 0;
		}
	}
	if (p != 1 && n == 1) ans *= p;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	a, b := nextFloat64(), nextFloat64()
	ans := int(math.Ceil((b - 1) / (a - 1)))
	fmt.Fprintln(out, ans)
}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}


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

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

int main() {
	cout << fixed << setprecision(9);
	ios :: sync_with_stdio(0);

	for(int n; cin >> n; ) {
		cout << n * (n + 1) / 2 + 1 << '\n';
	}

	return 0;
}

Measured memory_bytes: 3124
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
	int n;
	char s[500000];
	cin >> n >> s;
	vector<int> Lvec(n+1,0),Rvec(n+1,0),ans(n,0);
	
	if(s[0]=='#')Lvec[1]++;
	for(int i=1;i<n;i++){
		if(s[i]=='#')Lvec[i+1]++;
		Lvec[i+1]+=Lvec[i];
	}
	
	if(s[n-1]=='.')Rvec[n-1]++;
	for(int i=1;i<n;i++){
		if(s[n-1-i]=='.')Rvec[n-1-i]++;
		Rvec[n-1-i]+=Rvec[n-i];
	}
	
	for(int i=0;i<n;i++)ans[i]=Rvec[i+1]+Lvec[i];
	
	sort(ans.begin(),ans.end());
	
	cout << ans[0];
	return 0;
}

Measured memory_bytes: 2816
n = int(input())
s = input()

ans = 0
for i in range(1000):
  pin = '{:03d}'.format(i)
  p1 = s.find(pin[0])
  if p1>=0:    
    p2 = s.find(pin[1],p1+1)     
    if p2>=0:
      p3 = s.find(pin[2],p2+1)      
      if p3>=0:
        ans+=1        
    
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define erep(i, a, b) for (int i = a; i <= (int)(b); i++)
#define per(i, a, b) for (int i = (b)-1; i > (a); i--)
#define eper(i, a, b) for (int i = ((int)(a)); i >= b; i--)
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
const int INF = (1 << 30) - 1;
const int MOD = 1000000007;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

ll n, zero, one, four;
bool flag = false;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  rep(i, 0, n) {
    int x;
    cin >> x;
    if (x % 4 == 0)
      four++;
    else if (x % 2 == 0)
      one++;
    else
      zero++;
    // cout << zero << " " << one << " " << four << endl;
  }
  if (one > 0) {
    if (four >= zero)
      flag = true;
    else
      flag = false;
  } else {
    if (four + 1 >= zero)
      flag = true;
    else
      flag = false;
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

struct STAMP {
    int H, W;
}

int N;
STAMP[] S;
string[] F;
int[] masks;

void input() {
    scanf("%d\n", &N);
    S = new STAMP[N];
    foreach (i; 0 .. N) {
        int h, w; scanf("%d %d\n", &h, &w);
        S[i] = STAMP(h, w);
    }
    F = new string[4];
    foreach (i; 0 .. 4) {
        F[i] = readln.chomp;
    }

    masks.destroy;
    foreach (s; S) {
        for (int y = -3; y < 4; y++) {
            for (int x = -3; x < 4; x++) {
                int sy = max(0, y),
                    gy = min(y + s.H, 4);
                int sx = max(0, x),
                    gx = min(x + s.W, 4);
                int mask = 0;
                for (int i = sy; i < gy; i++) {
                    for (int j = sx; j < gx; j++) {
                        mask |= 1 << (i * 4 + j);
                    }
                }
                masks ~= mask;
            }
        }
    }
    masks = masks.sort.uniq.array;
}

void solve() {
    int init = 0;
    bool[int] used;
    used[init] = true;
    struct P {
        int state, dist;
        string toString() const {
            return format("P(%016b, %d)", state, dist);
        }
    }
    DList!P Q;
    Q.insert(P(init, 0));
    while (!Q.empty) {
        auto cur = Q.front; Q.removeFront;
        //writeln(cur);
        foreach (c; "RGB") {
            foreach (mask; masks) {
                int next = cur.state;
                foreach (int i; 0 .. 16) {
                    if (!(mask & (1 << i))) continue;
                    int y = i / 4,
                        x = i % 4;
                    if (c == F[y][x]) {
                        next |= (1 << i);
                    } else {
                        next &= ~(1 << i);
                    }
                }
                if (next == (1 << 16) - 1) {
                    writeln(cur.dist + 1);
                    return;
                }
                if (next in used) continue;
                Q.insert(P(next, cur.dist + 1));
                used[next] = true;
            }
        }
    }
    assert(false);
}

void main() {
    input;
    solve;
}

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


int gcd(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int x1, y1;
    int d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

bool find_any_solution(int a, int b, int c, int &x0, int &y0, int &g) {
    g = gcd(abs(a), abs(b), x0, y0);
    if (c % g) {
        return false;
    }

    x0 *= c / g;
    y0 *= c / g;
    if (a < 0) x0 = -x0;
    if (b < 0) y0 = -y0;
    return true;
}


int main(){
    
    int a, b, c;
    cin >> a >> b >> c;
    
    int k1 = -1, k2 = -1, g = -1;
    bool check = find_any_solution(a, b, c, k1, k2, g);
    //cout << k1 << " " << k2 << endl;
    if(check){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
    
}


Measured memory_bytes: 3608
MAXN = 10**5+10
sieve = [0,0] + [1]*MAXN
m = 2
while m*m <= MAXN:
    if sieve[m]:
        for n in range(2*m,MAXN,m):
            sieve[n] = 0
    m += 1

ok = [0]*MAXN
cums = [0]
for n in range(MAXN):
    if sieve[n] and sieve[(n+1)//2]:
        ok[n] = 1
    cums.append(cums[-1] + ok[n])

Q = int(input())
for i in range(Q):
    l,r = map(int,input().split())
    print(cums[r+1] - cums[l])


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

int H, W, M;

int main() {
  cin >> H >> W >> M;
  vector<int> h(H), w(W);
  set<pair<int, int> > st;
  int maxH = 0, maxW = 0;
  
  for (int i = 0; i < M; i++) {
    int ih, iw;
    cin >> ih >> iw;
    --ih; --iw;
    st.insert({ih, iw});
    h[ih]++; w[iw]++;
    maxH = max(maxH, h[ih]);
    maxW = max(maxW, w[iw]);
  }
  
  // 最大値のリストを抽出
  vector<int> mhl, mwl;
  for (int i = 0; i < H; i++) {
    if (maxH == h[i]) mhl.push_back(i);
  }
  for (int i = 0; i < W; i++) {
    if (maxW == w[i]) mwl.push_back(i);
  }
  
  int ans = maxH + maxW - 1;
  // 交点に無いパターンがあればそれが答え
  for (int i = 0; i < mhl.size(); i++) {
    for (int j = 0; j < mwl.size(); j++) {
      if (st.find({mhl[i], mwl[j]}) == st.end()) {
        ans++;
        cout << ans;
        return 0;
      }
    } 
  }
  cout << ans;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

bool isPrime(int a) {
    if (a == 1) return false;
    for (int i = 2; i * i <= a; i++) {
        if(a % i == 0) return false;
    }
    return true;
}

void solve()
{
  int n;
  cin >> n;

  vector<int> ans{2, 11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361};
  for(int i = 0; i < n; ++i)
  {
    cout << ans[i] << " ";
  }
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	string s1,s2;
	cin>>s1>>s2;
	int zh(string x);
	int s;
	s1+=s2;
	s=zh(s1);
	
	if(int(sqrt(s))==sqrt(s))
		cout<<"Yes";
	else
		cout<<"No";
}
int zh(string x)
{
	int s=0, i;
	for(i=0; i<x.size(); i++) 
	   s=s*10+(x[i]-'0');
	return s;
}


Measured memory_bytes: 256
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 4003
#define mod 1000000007
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) cout<<"Case #"<<i<<": "
#define pf(a) printf("%lld\n",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define pfff(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pffff(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp1,mp;
vector<pair<ll,pair<ll,ll> > >vpp,vpp1;
vector<pair<ll,ll> >vp,fin;
vector<ll>v1,v2,dummy;
map<pair<ll,ll>,bool>mbb;
map<ll,bool>mb;
ll n,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,maxi;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
vector<ll>power;
int main()
{
    cin>>n>>k;
    if(n<10 and k<10) cout<<n*k<<endl;
    else cout<<-1<<endl;
    return 0;
}
/*
5
4
3
2
3
4
4
3
3
4
2
3
*/


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

#define int long long

auto main() -> signed {
    int n;
    cin >> n;
    deque<int> b;
    for(int i=0; i<n; ++i) {
        int a;
        cin >> a;
        if(i%2==0) {
            if(n%2==0) b.push_back(a);
            else b.push_front(a);
        }
        else {
            if(n%2==0) b.push_front(a);
            else b.push_back(a);
        }
    }
    for_each(b.begin(), b.end(), [](int a){
        cout << a << endl;
    });
    return 0;
}



Measured memory_bytes: 3840
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int yoko = sc.nextInt();
		int katen = sc.nextInt();
		if(!(0 > yoko-katen*2)){
      System.out.printf("%d",yoko-katen*2);
    }else{
      System.out.println("0");
    }
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using G = vector<vector<int>>;
vector<int> coun(1e5+1, 0);
vector<ll> ans;
    
int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    ll total = 0;
    rep(i,n) {
        cin >> a[i];
        total += a[i];
        coun[a[i]]++;
    }
    int q;
    cin >> q;
    rep(i,q){
        int b, c;
        cin >> b >> c;
        if(coun[b]==0){
            ans.push_back(total);
            continue;
        }
        total += (c-b) * coun[b];
        coun[c] += coun[b];
        coun[b] = 0;
        ans.push_back(total);
    }

    rep(i,ans.size()) cout << ans[i] << endl; 
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    int X[N];
    for(int i=0; i<N; i++){
        cin >> X[i];
    }
    int totStam[100]={};
    int j=0;
    while(j<101){
        for(int u=0; u<N; u++){
            totStam[j] += pow(X[u]-j, 2);
        }
        j++;
    }
    sort(totStam, totStam + sizeof(totStam)/sizeof(totStam[0]));
    cout << totStam[0];
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()



int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	vll am(b, 0);
	rep(i, b) {
		ll tmp = i * a % b;
		if (am[tmp] != 0) break;
		else am[tmp] = 1;
	}
	cout << (am[c] == 1 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;

  vector<vector<int>> count(10, vector<int>(10, 0));
  for (int n = 1; n <= N; ++n) {
    string s = to_string(n);
    count[s[0] - '0'][s.back() - '0']++;
  }

  int64_t answer = 0;
  rep(i, 10) {
    rep(j, 10) {
      int cntA = count[i][j];
      int cntB = count[j][i];
      answer += cntA * cntB;
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
#define MAX_N 40
int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> A(N), sum(N+1);
  rep(i, N) {
    cin >> A[i];
    sum[i+1] = sum[i] + A[i];
  }
  vector<ll> B;
  rep(l, N+1) REP(r, l+1, N+1) B.push_back(sum[r]-sum[l]);
  int M = B.size();
  vector<vector<int>> D(M, vector<int>(MAX_N));
  rep(k, MAX_N) {
    rep(i, M) {
      D[i][MAX_N-1-k] = (B[i]>>k)&1;
    }
  }
  vector<set<int>> vse(2);
  rep(i, M) vse[0].insert(i);
  ll ans = 0;
  ll pw = pow(2, MAX_N-1);
  int id = 1;
  rep(k, MAX_N) {
    vse[id].clear();
    for(int i: vse[1-id]) {
      if(D[i][k]) vse[id].insert(i);
    }
    if(vse[id].size() >= K) {
      ans += pw;
    } else {
      vse[id].clear();
      for(int i: vse[1-id]) vse[id].insert(i);
    }
    pw >>= 1;
    id = 1-id;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 148848
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
using namespace std;

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


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,t,a;
struct edge
{
	int v;
	edge *next;
}*h[233333],pool[233333];
int top;
inline void addedge(int u,int v)
{
	edge *tmp=&pool[top++];tmp->v=v;tmp->next=h[u];h[u]=tmp;
	edge *pmt=&pool[top++];pmt->v=u;pmt->next=h[v];h[v]=pmt;
}
int vis[233333],pa[233333],dep[233333],maxdep[233333];
void dfs(int u)
{
	vis[u]=1;
	for(edge *tmp=h[u];tmp;tmp=tmp->next)
	{
		if(!vis[tmp->v])
		{
			pa[tmp->v]=u;
			dep[tmp->v]=dep[u]+1;
			dfs(tmp->v);
			maxdep[u]=max(maxdep[tmp->v]+1,maxdep[u]);
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	int u,v;
	cin>>n>>t>>a;
	for(int i=1;i<n;i++)cin>>u>>v,addedge(u,v);
	dfs(a);
//	for(int i=1;i<=n;i++)cerr<<i<<' '<<pa[i]<<' '<<dep[i]<<' '<<maxdep[i]<<endl;
	int cur=t;
	while((dep[cur]-1)*2>dep[t])cur=pa[cur];
	cout<<dep[cur]+maxdep[cur]-1<<endl;
	return 0;
}

Measured memory_bytes: 9984
# -*- coding: utf-8 -*-
import sys

def main():
	A, B, K = map(int, input().split(" "))
	
	tmp = []
	counts = 0
	for i in range(1, 101):
		if A % i == 0 and B % i == 0:
			tmp.append(i)
			counts += 1
	
	print(tmp[counts - K])
	
	
if __name__ == "__main__":
	main()
	

Measured memory_bytes: 2940
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

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

		int[] range = { 1, n }; // 全部のゲートを通過できるカードの範囲
		for (int i = 0; i < m; i++) {
			int l = getInt(sc);
			int r = getInt(sc);
			updateRange(range, l, r);
		}

		int cardsNum = range[1] - range[0];
		if (cardsNum < 0) {
			System.out.println(0);
		} else {
			System.out.println(cardsNum + 1);
		}
	}

	private static void updateRange(int[] range, int l, int r) {
		range[0] = Math.max(range[0], l);
		range[1] = Math.min(range[1], r);
	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}

class Status {
	int row = 0;
	int col = 0;
	int candies = 0;

	public Status(int row, int col, int candies) {
		this.row = row;
		this.col = col;
		this.candies = candies;
	}
}


Measured memory_bytes: 47296
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;



const ll mod=1e9+7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(ll n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (ll i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (ll i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(ll n, ll k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(ll n, ll k) {
    return fact[n]*ifact[n-k];
  }
} c(1000005);

int main(){
    ll s;
    cin >> s;
    vector<mint> dp(s+1),nxt(s+1);
    mint ans=0;
    dp[0]=1;
    rep(i,s/3){
        for(ll j=3;j<=s-3*i;j++){
            for(ll k=3*i;k<=s;k++){
                if(j+k>s) break;
                nxt[j+k]+=dp[k];
            }
            
        }
        rep(j,s+1){
            //cout << j  << " " << nxt[j]<< endl;
        }
        dp=nxt;
        nxt=vector<mint>(s+1);
        ans+=dp[s];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 18636
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const auto mod=1e9+7;

 ll a,b,c,d;

 ll func(ll v){
 	return v-v/c-v/d+v/(c/__gcd(c,d)*d); 
 }

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
 
  cin >> a >> b >> c >> d;
  cout << func(b)-func(a-1) << endl;
   
 }

Measured memory_bytes: 256
<?php
/*
    Problem URL : http://abc049.contest.atcoder.jp/tasks/abc049_b

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */
// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%d %d", $H, $W);

for ($i = 0; $i < $H; $i++) {
    $s = trim(fgets(STDIN));
    echo $s . PHP_EOL;
    echo $s . PHP_EOL;
}

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

const int mod = 1e9 + 7;
int sz[5010],fac[5010],pre[5010];
vector<int> e[5010];
bool ok;
void dfs(int x,int p){
	sz[x]=1;
	for(int it:e[x]){
		if(it==p)	continue;
		if(sz[it]!=0){
			ok=false;
			continue;
		}
		dfs(it,x);
		sz[x]+=sz[it];
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	fac[0]=pre[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=1LL*fac[i-1]*i%mod,pre[i]=1LL*pre[i-1]*(n-1)%mod;
	int k=0;
	for(int i=1,p;i<=n;i++){
		cin>>p;
		if(p==-1)	k++;
		else	e[i].emplace_back(p),e[p].emplace_back(i);
	}
	vector<int> v;
	int ans=1LL*pre[k]*n%mod;
	for(int i=1;i<=n;i++)
		if(sz[i]==0){
			ok=true;
			dfs(i,0);
			if(ok)
				v.emplace_back(sz[i]);
			else
				ans=(ans-pre[k])%mod;
		}
	vector<int> f(1,1);
	for(int it:v){
		f.emplace_back(0);
		for(int i=f.size()-2;i>=0;i--)
			f[i+1]=(f[i+1]+1LL*f[i]*it)%mod;
	}
	for(int i=2;i<f.size();i++)
		ans=(ans-1LL*fac[i-1]*f[i]%mod*pre[k-i])%mod;
	if(f.size()>1)
		ans=(ans-1LL*(f[1]-k)*pre[k-1])%mod;
	cout<<(ans+mod)%mod<<endl;
}


Measured memory_bytes: 3988
A=[[int(x) for x in input().split()]for i in range(3)]
N = int(input())
b = []
for i in range(N):
    b.append(int(input()))
 
for i in range(3):
    if A[i][0] in b and A[i][1] in b and A[i][2] in b:
        print('Yes')
        exit()
for i in range(3):
    if A[0][i] in b and A[1][i] in b and A[2][i] in b:
        print('Yes')
        exit()
if A[0][0] in b and A[1][1] in b and A[2][2] in b:
    print('Yes')
    exit()
if A[2][0] in b and A[1][1] in b and A[0][2] in b:
    print('Yes')
    exit() 
print('No')

Measured memory_bytes: 3064
import math
a, b, c = map(int, input().split())

print(a*b*math.sin(math.radians(c))/2)
print(math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(c)))+a+b)
print(b*math.sin(math.radians(c)))


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

int main(){
  int n;
  cin >> n;
  int min=100000000, cnt=0, p;
  for(int i=0; i<n; i++){
    cin >> p;
    if(min>=p){
      cnt++;
      min = p;
    }
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 256
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

# from itertools import accumulate
# from collections import deque
import random


def main():
    l = input()
    l1=int(l[0:2])
    l2=int(l[2:4])
    eprint(l1)
    eprint(l2)
    if 1<=l1<=12 and 1<=l2<=12:
        print("AMBIGUOUS")
    elif 1<=l1<=12:
        print("MMYY")
    elif 1<=l2<=12:
        print("YYMM")
    else:
        print("NA")

if __name__ == '__main__':
    main()


Measured memory_bytes: 65260
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = sc.ReadInt()
	}

	buyMode := true
	money := 1000
	paper := 0
	for i := 0; i < n-1; i++ {
		if buyMode {
			if a[i+1]-a[i] > 0 {
				paper += money / a[i]
				money %= a[i]
				buyMode = false
			}
		} else {
			if a[i+1]-a[i] < 0 {
				money += a[i] * paper
				paper = 0
				buyMode = true
			}
		}
	}
	if !buyMode {
		money += a[n-1] * paper
		paper = 0
		buyMode = true
	}

	fmt.Println(money)
}

// from [my library](https://github.com/ikngtty/go-contestlib)
// -   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base, exponent int) int {
	if exponent < 0 {
		panic(fmt.Sprintf("exponent (%d) should not be a minus", exponent))
	}

	answer := 1
	for i := 0; i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Ceil(divident, dividor int) int {
	if dividor == 0 {
		panic("dividor should not be 0")
	}

	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// -   sortutil

func ReverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func ReverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// -   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1780
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll H, W;
string s[444];
ll dx[]={-1, 0, 1, 0};
ll dy[]={0, -1, 0, 1};

P dfs(ll x, ll y, ll** used) {
    used[x][y]=1;
    
    P p=mkp(0, 0);
    if(s[x][y]=='#') p.fi++;
    else p.se++;
    
    for(ll i=0; i<4; i++) {
        ll tx=x+dx[i];
        ll ty=y+dy[i];
        
        if(tx<0 || ty<0 || tx>=H || ty>=W) continue;
        if((s[x][y]=='#' && s[tx][ty]=='#') || (s[x][y]=='.' && s[tx][ty]=='.')) continue;
        if(used[tx][ty]!=-1) continue;
        
        P t=dfs(tx, ty, used);
        p.fi+=t.fi;
        p.se+=t.se;
    }
    
    return p;
}

int main(void) {
    ll ans=0;
    ll **used;
    ll i, j;
    cin >> H >> W;
    
    used=(ll**)malloc(H*sizeof(ll*));
    for(i=0; i<H; i++)
        used[i]=(ll*)malloc(W*sizeof(ll));
    
    for(i=0; i<H; i++)
        cin >> s[i];

    for(i=0; i<H; i++)
        for(j=0; j<W; j++)
            used[i][j]=-1;
    
    for(i=0; i<H; i++)
        for(j=0; j<W; j++)
            if(s[i][j]=='#') {
                P t=dfs(i, j, used);
                ans+=t.fi*t.se;
            }
    
    pr(ans);
}


Measured memory_bytes: 16768
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

class BIT
{
public:
    vector<int> bit;
    int M;

    BIT(int M):
        bit(vector<int>(M+1, 0)), M(M) {}

    int sum(int i) {
        if (!i) return 0;
        return bit[i] + sum(i-(i&-i));
    }

    void add(int i, int x) {
        if (i > M) return;
        bit[i] += x;
        add(i+(i&-i), x);
    }
};

signed main(){

    
    string S;
    cin >> S;
    int N = S.size();

    vector< vector<int> > pos(26, vector<int>(0));
    REP(i, N){
        int a = (int)(S[i] - 'a');
        pos[a].push_back(i);
    }

    vector<int> alfnum(26, 0);

    int odd = 0;
    REP(i, 26){
        if(pos[i].size() % 2 == 1) odd++;
    }
    if(odd > 1){
        cout << -1;
        return 0;
    }

    BIT b(N);
    int ans = 0;
    vector<int> used(26, 0);
    while(N > 1){
        int minv = 10000000000;
        int alf;
        REP(i, 26){
            if(pos[i].size() - 2 * used[i] >= 2){
                int n = pos[i].size();
                int v = (pos[i][used[i]] - b.sum(pos[i][used[i]] + 1)) + (N - 1 - pos[i][n - 1 - used[i]] + b.sum(pos[i][n - 1 - used[i]] + 1));
                if(v < minv){
                    minv = v;
                    alf = i;
                }
            }
        }
        b.add(pos[alf][used[alf]] + 1, 1);
        b.add(pos[alf][pos[alf].size() - 1 - used[alf]] + 1, 1);
        //pos[alf].erase(pos[alf].begin() + pos[alf].size() - 1);
        //pos[alf].erase(pos[alf].begin());
        used[alf]++;
        ans += minv;
        N -= 2;
    }
    
    cout << ans;

    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fr(i,a,n) for(ll i=a;i<n;i++)
int main()
{
	ll n,k;
	cin>>n>>k;
	double a=0.0,ans=0.0;
	fr(i,1,n+1)
	{
		ll t=i;
		a=(double)1/n;
		while(t<k)
		{
			t*=2;
			a*=0.5;
		}
		ans+=a;
	}
	printf("%.12f\n",ans);
}			

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main ()
{
    ll n;
    cin>>n;
    vector <ll> a,b,c;
    for (ll i = 0; i < n; i++)
    {
       ll a1,b1,c1;
       cin>>a1>>b1>>c1;
       a.push_back(a1);
       b.push_back(b1);
       c.push_back(c1);
    }
    ll x[n][3];
    for (int i = 0; i < n; i++)
    {
       for (int j = 0; i < 3; i++)
       {
           x[i][j]=0;
       }
      
    }
    x[0][0]=a[0];
    x[0][1]=b[0];
    x[0][2]=c[0];
    for(ll i=1;i<n;i++)
    {
        x[i][0]=max(x[i-1][1],x[i-1][2])+a[i];
        x[i][1]=max(x[i-1][0],x[i-1][2])+b[i];
        x[i][2]=max(x[i-1][1],x[i-1][0])+c[i];
    }
    
    
    ll z=max(x[n-1][1],x[n-1][2]);
    z=max(z,x[n-1][0]);
    cout<<z<<endl;
}


Measured memory_bytes: 5216
import java.util.*;

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

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

        int[] left = new int[n];
        int[] right = new int[n];

        for (int i = 1; i < n; i++) {
            left[i] = gcd(left[i - 1], nums[i - 1]);
        }
        for (int i = n - 2; i >= 0; i--) {
            right[i] = gcd(right[i + 1], nums[i + 1]);
        }

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

        System.out.println(ans);
    }

    static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a%b);
    }
}

Measured memory_bytes: 49932
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
typedef pair<int, int> P;
const int INF = 1 << 30;
vector<long long int> baum;
long long int n, ans, minma = INF;
long long int Baum = 0, Baum3 = 0;

void cut(long long int f) {
	long long int s = f + Baum3, t = s + Baum3;
	long long int p;
	long long int sp[3] = {}, tp[3] = {};
	p = lower_bound(baum.begin(), baum.end(), s) - baum.begin();
	if (s == baum[p]) {
		sp[0] = baum[p + 1];
		sp[1] = baum[p - 1];
		sp[2] = baum[p];
	}
	else {
		sp[0] = baum[p];
		sp[1] = baum[p - 1];
		sp[2] = INF;
	}
	p = lower_bound(baum.begin(), baum.end(), t) - baum.begin();
	if (t == baum[p]) {
		tp[0] = baum[p + 1];
		tp[1] = baum[p - 1];
		tp[2] = baum[p];
	}
	else {
		tp[0] = baum[p];
		tp[1] = baum[p - 1];
		tp[2] = INF;
	}
	for (int i = 0; i <= 2; i++) {
		if (sp[i] == INF) break;
		minma = sp[i] - f;
		for (int j = 0; j <= 2;j ++){
			if (tp[j] == INF) break;
			minma = min( minma, min( tp[j] - sp[i], Baum - tp[j] + f ));
			ans = max(ans, minma);
			minma = sp[i]-f;
		}
	}
}

int main() {
	cin >> n;
	baum.push_back(0);
	for (int i = 0; i < n; i++) {
		int in;
		scanf("%d", &in);
		Baum += in;
		baum.push_back(in);
	}
	Baum3 = Baum / 3;

	for (int i = 2; i <= n+1; i++) {
		baum[i] += baum[i - 1];
	}
	for (int i = 0; i < n + 1; i++) {
		if (baum[i] >= Baum3) break;
		cut(baum[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 2120
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <functional>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;

    vector<int> a(m), b(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }

    vector<bool> v(n);
    long count = 0;
    function<void(int)> iter = [&](int node){
        v[node] = true;
        bool deadend = true;
        for (int i = 0; i < m; i++) {
            if (a[i] == node && !v[b[i]]) {
                iter(b[i]);
                deadend = false;
            } else if (b[i] == node && !v[a[i]]) {
                iter(a[i]);
                deadend = false;
            }
        }
        if (deadend) {
            if (all_of(v.begin(),
                       v.end(),
                       [](bool b){return b;})) {
                count += 1;
            }
        }
        v[node] = false;
    };
    iter(0);

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256