akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  ll n,p;
  cin>>n>>p;
  ll ans = 1;
  ll t = p;
  for(ll i = 2; i * i <= p; i++) {
    ll cnt = 0;
    while(t % i == 0) {
      t /= i;
      cnt++;
    }
    ans *= (ll)pow(i, cnt / n);
  }
  if(n == 1) {
    ans = p;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,ans=0,count=0;
  cin>>N;
  vector<int> H(N);
  for(int i=0;i<N;i++)
    cin>>H.at(i);
  for(int i=0;i<N-1;i++){
    if(H.at(i)>=H.at(i+1)){
      count++;

    }
    else{
      ans=max(ans,count);
      count=0;
    
      
    }
    
  }
  cout<<max(ans,count)<<endl;
}

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

int main() {
	long long N, M;
	cin >> N >> M;

	vector<long long> H(N);
	vector<vector<long long>> Matrix(N);

	for (long long i = 0; i < N; i++) {
		cin >> H.at(i);
	}

	long long A, B;

	for (long long i = 0; i < M; i++) {
		cin >> A >> B;
		Matrix.at(A - 1).push_back(B - 1);
		Matrix.at(B - 1).push_back(A - 1);

	}

	int count = 0;
	bool flag = 0;

	for (long long i = 0; i < N; i++) {
		flag = 0;
		if (Matrix.at(i).size() == 0) {
			count++;
			continue;
		}
		for (auto x : Matrix.at(i)) {
			if (H.at(i) <= H.at(x)) {
				flag = 1;
				break;
			}
		}
		if (!flag) count++;
	}

	cout << count << endl;
	return 0;
}


Measured memory_bytes: 9460
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, m ] <- readInts
	ps <- sort . map mp <$> replicateM ( fromIntegral n ) readInts
	print $ solve m ps

solve m ( ( a, b ) : ps )
	| m <= b = a * m
	| otherwise = a * b + solve ( m - b ) ps

Measured memory_bytes: 48508
using System;
using System.Collections.Generic;

namespace _1167
{
	class Program
	{
		static void Main(string[] args)
		{
			int max = 1000000;
			List<int> num = new List<int>();
			List<int> odd = new List<int>();
			for (int i = 1; ; i++)
			{
				int x = i * (i + 1) * (i + 2) / 6;
				if (x >= max * 2) break;
				num.Add(x);
				if (x % 2 == 1) odd.Add(x);
			}
			int[] count = new int[max];
			int[] oddcount = new int[max];
			for (int i = 1; i < max; i++)
			{
				int min = int.MaxValue;
				for (int j = 0; num[j] <= i; j++)
				{
					min = Math.Min(min, count[i - num[j]] + 1);
				}
				count[i] = min;
				int oddmin = int.MaxValue;
				for (int j = 0; odd[j] <= i; j++)
				{
					oddmin = Math.Min(oddmin, oddcount[i - odd[j]] + 1);
				}
				oddcount[i] = oddmin;
			}
			while (true)
			{
				int n = int.Parse(Console.ReadLine());
				if (n == 0) break;
				Console.WriteLine(count[n] + " " + oddcount[n]);
			}
		}
	}
}


Measured memory_bytes: 23260
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  int[] a; readA(n, a);

  auto c = new int[](4);
  foreach (ai; a) ++c[ai];

  auto dp = new double[][][](n+1, n+1, n+1);
  dp[0][0][0] = 0;
  foreach (i3; 0..n+1)
    foreach (i2; 0..n-i3+1)
      foreach (i1; 0..n-i3-i2+1)
        if (i1 > 0 || i2 > 0 || i3 > 0) {
          dp[i1][i2][i3] = 1;
          if (i1 > 0) dp[i1][i2][i3] += dp[i1-1][i2][i3] * i1/n;
          if (i2 > 0) dp[i1][i2][i3] += dp[i1+1][i2-1][i3] * i2/n;
          if (i3 > 0) dp[i1][i2][i3] += dp[i1][i2+1][i3-1] * i3/n;
          dp[i1][i2][i3] /= (1-(n-i1-i2-i3).to!double/n);
        }

  writefln("%.10f", dp[c[1]][c[2]][c[3]]);
}


Measured memory_bytes: 367484
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    use std::collections::BTreeSet;
    let n: u32 = read();
    let a: BTreeSet<u32> = (0..n).map(|_| read()).collect();

    println!("{}", a.len());
}


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

using namespace std;

typedef vector<long long> vi;
typedef pair<int, int> pi;


#define F first
#define S second
#define PB push_back
#define MP make_pair

int N, M, X;
vector<vi> books;
vi subset;
long long total_cost;
long long min_cost = 99999999;
vi stats;


void search(int k) {
	if (k == N+1) {
		for (int i = 0; i < subset.size(); i++) {
			//add cost of selected book in subset
			total_cost += books[subset[i]-1][0];
			for (int j = 1; j <= M; j++) {
				// add stats of selected book in subset
				stats[j-1] += books[subset[i]-1][j];
			}
			// check if stats enough
			int good = 1;
			for (int k = 0; k < M; k++) {
				if (stats[k] < X) {
					good = 0;
					break;
				}
			}
			// if stats good and total cost sufficiently small, then update min_cost
			if (good == 1 && total_cost < min_cost) {
				min_cost = total_cost;
			}
		}
		// reset stats
		for (int h = 0; h < M; h++) {
			stats[h] = 0;
		}
		// reset total cost
		total_cost = 0;

	} else {
		subset.push_back(k);
		search(k+1);
		subset.pop_back();
		search(k+1);
	}
}

int main() {
	cin >> N >> M >> X;
	vi book;
	long long num;
	stats.resize(M);
	for (int i = 0; i < M; i++) {
		stats.push_back(0);
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M + 1; j++) {
			cin >> num;
			book.push_back(num);
		}
		books.push_back(book);
		book.clear();
	}
	search(1);
	if (min_cost != 99999999) {
		cout << min_cost << endl;
	} else {
		cout << -1 << endl;
	}
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

template <typename T>
struct RAQ //calculateはadd(区間加算 not update)
{
    int n;
    const T ex = 0; //初期値
    vector<T> dat, lazy; //tree本体
    RAQ(vector<T> v){
        int x = 1;
        int i;
        n = v.size();
        while(x < n) x <<= 1;
        n = x; 
        dat.resize(2*n-1, ex);
        lazy.resize(2*n-1, ex);
        for(i = 0;i < v.size();++i){
            dat.at(i + n - 1) = v.at(i);
        }
        for(i = n-2;i >= 0;--i){
            dat.at(i) = calculate(dat.at(2*i+1), dat.at(2*i+2));
        }
    }
    
    T calculate(T a, T b){
        return a + b;
    }
    
    void eval(int now){
        if(lazy.at(now) == ex) return;
        if(now < n - 1){
            lazy.at(2*now + 1) += lazy.at(now)/2;
            lazy.at(2*now + 2) += lazy.at(now)/2;
        }
        dat.at(now) += lazy.at(now);
        lazy.at(now) = ex;
    }
    
    void update(int a, int b, T x, int now, int l, int r){
        eval(now);
        if(a <= l && r<= b){
            lazy.at(now) += (r - l)*x; //上から書き換える。
            eval(now);
        }else if(a < r && l < b){
            update(a, b, x, 2*now + 1, l, (l + r)/2);
            update(a, b, x, 2*now + 2, (l + r)/2, r);
            dat.at(now) = calculate(dat.at(2*now + 1), dat.at(2*now + 2));
        }
    }
    void update(int a, int b, T x){update(a, b, x, 0, 0, n);}
    
    T query(int a, int b){return query_sub(a, b, 0, 0, n);}
    T query_sub(int a, int b, int now, int l, int r){
        eval(now);
        if(r <= a || b <= l) return ex;
        else if(a <= l && r <= b) return dat.at(now);
        else{
            T vl = query_sub(a, b, 2*now + 1, l, (l + r)/2);
            T vr = query_sub(a, b, 2*now + 2, (l + r)/2, r);
            return calculate(vl, vr);
        }
    }
};

int main()
{
    ll i,j;
    ll n,q;
    cin >> n >> q;
    vector<ll> a(n, 0);
    RAQ<ll> raq(a);
    for(i = 0;i < q;++i){
        ll com;
        cin >> com;
        if(com == 0){
            ll s,t,x;
            cin >> s >> t >> x;
            raq.update(s-1, t, x);
        }else{
            ll ind;
            cin >> ind;
            cout << raq.query(ind-1, ind) << endl;
        }
    }

    return 0;
}


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

// template {{{
/* vim: set foldmethod=marker: */

// constant
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const double PI = acos(-1);
#define EPS 1e-14

// typedef
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;

// input
inline int inputi(){ int x; scanf("%d", &x); return x; }
inline double inputd(){ double x; scanf("%lf", &x); return x; }
inline string inputs(){ string x; cin >> x; return x; }

// short
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define REPit(type, i, obj) for (type::iterator i = (obj).begin(); i != (obj).end(); i++)
#define RREPit(type, i, obj) for (type::iterator i = (obj).rbegin(); i != (obj).rend(); i++)

// container util
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define sz(obj) ((int)(obj).size())
#define sort(obj) sort(all(obj))
#define exist(obj, key) ((obj).find(key) != (obj).end())
#define clear(array) memset((array), 0, sizeof(array))

// print util
#define print(x) cout << (x) << endl
template <class T> inline void printall(vector<T> v){ REP(i, sz(v)) cout << v[i] << "\n "[i < sz(v) - 1]; }
#define dump(x) cerr << #x << ": " << (x) << endl
#define debug(x) cerr << #x << ": " << (x) << " (" << __LINE__ << ")" << endl

//template }}}

int main()
{
    int n;

    while (n = inputi(), n){
        int two = 0;
        int five = 0;
        FOR(i, 1, n + 1){
            int tmp = i;
            while (tmp % 2 == 0){
                two++;
                tmp /= 2;
            }
            while (tmp % 5 == 0){
                five++;
                tmp /= 5;
            }
        }
        print(min(two, five));
    }

    return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
    int i;
    bool can = false;
    for(i = 0;i <=10000;i++) {
        if(i*8/100==a && i*10/100 == b){
            can = true;
            break;
        }
    }
    if(can) cout << i << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
//#include <bits/stdc++.h>
using namespace std;
#define SpeeD ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
int main() {
	int a[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int k;
	cin >> k;
	cout << a[k - 1];
	
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[][] F = new int[N][10];
		int[][] P = new int[N][11];
		int ans = Integer.MIN_VALUE;
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < 10; j++)
				F[i][j] = sc.nextInt();
		}
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < 11; j++)
				P[i][j] = sc.nextInt();
		}

      for(int i = 1; i < 1 << 10; i++) {
			int sum = 0;
			for(int j = 0; j < N; j++) {
				int count = 0;
				for(int k = 0; k < 10; k++) {
					if((1 & (i >> k)) >= 1 && F[j][k] == 1)
						count++;
				}
				sum += P[j][count];
			}
			ans = Math.max(ans, sum);
		}
		System.out.println(ans);
	}

}


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

int main () {
    string s,t;
    cin>> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n,m = get_nums_l()

print((n-1)*n//2 + (m-1)*m//2)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s; cin >> s;
	int len = s.size();
	vector<int> f(len + 1); f[len] = 1;
	vector<string> chk = {"dream", "dreamer", "erase", "eraser"};
	for(int i = len - 1; i >= 0; i--){
		for(string c : chk){
			bool bad = false;
			for(int j = 0; j < c.size(); j++){
				if(i + j >= len) bad = true;
				else if(c[j] != s[i+j]) bad = true;
			}
			if(!bad) f[i] |= f[i + c.size()];
		}
	}
	if(f[0]) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> S(h);
    for (int i = 0; i < h; ++i)
    {
        cin >> S[i];
    }
    int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1};
    int dy[8] = {1, 0, -1, 1, -1, 1, 0, -1};
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            if (S[i][j] == '.')
            {
                int bomb = 0;
                for (int k = 0; k < 8; ++k)
                {
                    int ni = i + dx[k];
                    int nj = j + dy[k];
                    if (ni < 0 || ni > h - 1)
                    {
                        continue;
                    }
                    if (nj < 0 || nj > w - 1)
                    {
                        continue;
                    }
                    if (S[ni][nj] == '#')
                    {
                        ++bomb;
                    }
                }
                S[i].replace(j, 1, to_string(bomb));
            }
        }
    }
     for (int i = 0; i < h; ++i)
    {
        cout << S[i] << endl;
    }
}

Measured memory_bytes: 3704
n=int(input())
lista = [int(i) for i in input().split()]
listb = [int(i) for i in input().split()]
listc = [int(i) for i in input().split()]

ans = 0
bef = -1000
for i in range(n):
    bango = lista[i]
    ans+=listb[bango-1]
    
    if bango-bef == 1:
        ans+=listc[bango-2]
        
    bef = bango
    
print(ans)

Measured memory_bytes: 38384
#####segfunc#####
def segfunc(x, y):
    if y[0]>x[0]:
        return x
    else:
        return y
#################

#####ide_ele#####
ide_ele =(float("inf"),-1)
#################

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

import heapq

N=int(input())
p=list(map(int,input().split()))
n=N//2
op=[(p[2*i+1],2*i+1) for i in range(n)]
ep=[(p[2*i],2*i) for i in range(n)]

oseg=SegTree(op,segfunc,ide_ele)
eseg=SegTree(ep,segfunc,ide_ele)

def first(l,r):
    if l>=r:
        return (-1,-1,-1,-1)
    if l%2==0:
        val,index=eseg.query(l//2,r//2)
        val2,index2=oseg.query(index//2,r//2)
        return (val,val2,index,index2)
    else:
        val,index=oseg.query(l//2,r//2)
        val2,index2=eseg.query(index//2+1,r//2+1)
        return (val,val2,index,index2)

val,val2,index,index2=first(0,N)
que=[((val,val2),0,N)]
heapq.heapify(que)
ans=[]
while que:
    tuple,l,r=heapq.heappop(que)
    ans.append(tuple[0])
    ans.append(tuple[1])
    val,val2,index,index2=first(l,r)
    val,val2,l1,r1=first(l,index)
    if val!=-1:
        heapq.heappush(que,((val,val2),l,index))
    val,val2,l2,r2=first(index+1,index2)
    if val!=-1:
        heapq.heappush(que,((val,val2),index+1,index2))
    val,val2,l3,r3=first(index2+1,r)
    if val!=-1:
        heapq.heappush(que,((val,val2),index2+1,r))

print(*ans)

Measured memory_bytes: 151980
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>

typedef long long ll;
using namespace std;

int main()
{
    int n,x, cnt=0;
    ll a[100];

    cin >> n >> x;

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

    sort(a, a+n);

    for(int i=0; i<n; i++){
        x-=a[i];
        if(x<0)break;
        cnt++;
    }

    if(cnt==n && x!=0)cnt--;

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	ll n;
	cin >> n;

	vector<ll> a(9);
	for (ll i = 0; i < n; i++)
	{
		ll r;
		cin >> r;

		bool b = false;
		for (ll j = 1; j <= 8; j++)
		{
			if (r < 400 * j)
			{
				a[j - 1]++;
				b = true;
				break;
			}
		}

		if (!b)
		{
			a[8]++;
		}
	}


	ll cnt = 0;
	for (ll i : a)
	{
		if (i > 0)
		{
			cnt++;
		}
	}
	if (a.back() == 0)
	{
		println(cnt << " " << (cnt + a.back()));
	}
	else
	{
		if (cnt == 1)
		{
			println(1 << " " << a.back());
		}
		else
		{
			println(cnt - 1 << " " << (cnt + a.back() - 1));
		}
	}
 }


Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
using namespace std;

const int NN=2e5;
int arr[NN];
int n;

int main()
{
    scanf("%d",&n);
    int Max=0;
    scanf("%d",&arr[0]);
    Max=0;
    for(int i=1;i<n;i++){
        scanf("%d",&arr[i]);
        if(arr[i]>arr[Max]){
            Max=i;
        }
    }
    int nMax=-1;
    for(int i=0;i<n;i++){
        if(i!=Max){
            if(nMax==-1){
                nMax=i;
            }
            else if(arr[nMax]<arr[i]){
                nMax=i;
            }
        }
    }
    for(int i=0;i<n;i++){
        if(Max==i){
            printf("%d\n",arr[nMax]);
        }
        else{
            printf("%d\n",arr[Max]);
        }
    }
}



Measured memory_bytes: 2432
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		int q = sc.nextInt();

		LinkedList lh = new LinkedList();
		LinkedList lt = new LinkedList();
		boolean rev = false;  // reverse

		for ( int i=0; i<q; i++ ) {
			int qr = sc.nextInt();
			if ( qr == 1 ) {
				rev = !rev;
			} else {
				int f = sc.nextInt();
				String c = sc.next();
				if ( (!rev && f==1) || (rev && f==2) ) {
					lh.addFirst(c);
				} else {
					lt.addLast(c);
				}
			}
		}

		StringBuffer sb = new StringBuffer(String.join("",lh)+s+String.join("",lt));
		if ( rev ) {
			System.out.println(sb.reverse());
		} else {
			System.out.println(sb);
		}
	}
}

Measured memory_bytes: 169284
n,k = map(int,input().split())

k_lst = []
a_lst = []

for _ in range(k):
    k_lst.append(int(input()))
    a_lst.extend(list(map(int,input().split())))

ans = 0

for i in range(n):
    if (i+1) in a_lst:
        continue
    else:
        ans += 1 

print(ans)

Measured memory_bytes: 9184
a, b, h, m = map(int, input().split())

import math

kakua = (h/12+m/60/12)*2*math.pi
kakub = m/60 * 2*math.pi


c = (a**2.0+b**2.0 - 2.0*a*b*math.cos(kakua-kakub)) ** 0.5
print(c)

Measured memory_bytes: 9500
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>>v;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        v.push_back({a,b});
    }
    sort(v.begin(),v.end());
    int req=m;
    int ans=0;
    for(int i=0;i<v.size();i++){
        if(v[i].second>req){
            ans+=req*v[i].first;
            break;
        }else{
            ans+=v[i].second*v[i].first;
            req=req-v[i].second;
            if(req==0){
                break;
            }
        }
    }
    cout<<ans<<endl;
    
    return 0;
    
}



Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

template <class T>
vector< vector<T> > CS;

template <class T>
void sum_2(const std::vector<std::vector<T>>& a) {
    int h = a.size(), w = a[0].size();
    
    CS<T>.resize(h+1);
    for ( int i = 0; i < h+1; i++ ) {
        CS<T>[i].resize(w+1,0);
    }
    
    for ( int i = 0; i < h; i++ ) {
    for ( int j = 0; j < w; j++ ) {
        CS<T>[i + 1][j + 1] = a[i][j];
    }
    }
    for ( int i = 0; i < h+1; i++ ) {
    for ( int j = 0; j < w; j++ ) {
        CS<T>[i][j + 1] += CS<T>[i][j];
    }
    }
    for ( int i = 0; i < h; i++ ) {
    for ( int j = 0; j < w+1; j++ ) {
        CS<T>[i + 1][j] += CS<T>[i][j];
    }
    }
    
}

// template <class T>
// int calc_2(const std::vector<std::vector<T>>& s, int i, int j, int h, int w) {
    // return s[i + h][j + w] - s[i][j + w] + s[i][j] - s[i + h][j];
// }


template <class T>
int calc_2( int x1, int y1, int x2, int y2) {
    return CS<T>[x2][y2] - CS<T>[x1][y2] - CS<T>[x2][y1] + CS<T>[x1][y1];
}


int main() {
    
    int N,K;
    cin >> N >> K;
    
    vector< vector<int> > B( K*2, vector<int>( K*2, 0 ) );
    
    long long x,y;
    char c;
    for ( int i = 0; i < N; i++ ) {
        cin >> x >> y >> c;
        
        if ( c == 'W' ) { y += K; }
        
        B[x%(K*2)][y%(K*2)]++;
    }
    
    // for ( int x = 0; x < K*2; x++ ) {
    // for ( int y = 0; y < K*2; y++ ) {
        // cout << B[x][y];
    // }
    // cout << endl;
    // }
    
    sum_2<int>(B);
    
    int ans = 0;
    for ( int x = 0; x < K; x++ ) {
        
        for ( int y = 0; y < K; y++ ) {
            
            int x1 = x, x2 = x+K;
            int y1 = y, y2 = y+K;
            
            int a = calc_2<int>( 0, 0, x1, y1 ) + calc_2<int>( x2, 0, K*2, y1 ) + calc_2<int>( x1, y1, x2, y2 ) + 
            calc_2<int>( 0, y2, x1, K*2 ) + calc_2<int>( x2, y2, K*2, K*2 );
            
            // cout << a << " " << b << endl;
            
            ans = max( ans, a );
            ans = max( ans, N-a );
        }       
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 31744
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

#define MOD_BIG 1000000007
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using std::vector;

template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) {
    vec.resize(len);
    for (auto &v : vec) ndarray(v, args...);
}

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

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

int main() {
    
    double a, b, x;
    
    cin >> a >> b >> x;
    
    double th, y1, y2;

    y1 = 2*(a*a*b - x)/(a*a*a);
    y2 = a*b*b*0.5/x;
    //cerr << y1 << ", " << y2 << endl;
    double y = y1;
    if (y2 > b/a) {
        y = y2;
    }
    th = std::atan(y);
    double ans = th * 360 / (2*M_PI);
    printf("%.16f \n", ans);
    
    return 0;
}


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

using namespace std;


#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 1e6 + 1, MOD = 1e9 + 7, mod = 998244353, INF = 3e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;


signed main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);
   int n;
   cin >> n;
   vi a(n);
   for (int i = 0; i < n; i++) {
      cin >> a[i];
   }
   int i = 0, ans = 0;
   while (i < n) {
      int i1 = i, i2 = i;
      int start = a[i1], kol = 0, kol1 =  0;
      while (start <= a[i1] && i1 < n) start = a[i1], i1++, kol++;
      start = a[i2];
      while (start >= a[i2] && i2 < n) start = a[i2], i2++, kol1++;

      if (kol1 > kol) swap(i1, i2);
      i = i1;
      ans++;
   }
   cout << ans;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int inf=0x3fffffff;
int main(void)
{
    int n,a[105],s1=0,s2=0,Min=inf;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    //sort(a,a+n);
    for(int i=1;i<n;i++)
    {
        s1=0,s2=0;
        for(int j=0;j<=i;j++)
        {
            s1+=a[j];
        }
        for(int j=i+1;j<n;j++)
            s2+=a[j];
        Min=min(Min,abs(s1-s2));
    }
    cout<<Min<<endl;
    return 0;
}


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

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> sp(N, vector<int>(M));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            cin >> sp[i][j];
        }
    }
    int ans = N;
    vector<bool> use(M+1, true);
    for (int i = 0; i < M-1; i++) {
        vector<int> cnt(M+1, 0);
        for (int j = 0; j < N; j++) {
            int pos = 0;
            while (!use[sp[j][pos]]) pos++;
            cnt[sp[j][pos]]++;
            //cout << sp[j][pos];
        }
        cout << endl;
        int m = 0;
        int m_sp;
        for (int j = 1; j <= M; j++) {
            if (m < cnt[j]) {
                m = cnt[j];
                m_sp = j;
            }
        }
        ans = min(ans, m);
        //cout << m_sp << endl;
        use[m_sp] = false;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

const string YES = "Yes";
const string NO = "No";

int main()
{
  long long N;
  scanf("%lld", &N);
  std::vector<long long> a(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &a[i]);
  }
  std::vector<long long> b(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &b[i]);
  }
  ll cnt = 0;
  for (int i = 0; i < N; ++i)
  {
    if (a[i] < b[i])
    {
      cnt += (b[i] - a[i]) / 2;
    }
    else
    {
      cnt -= a[i] - b[i];
    }
  }
  cout << (cnt >= 0 ? YES : NO) << endl;

  return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#define MIN(x,y) ((x>y)? y:x)

using namespace std;

int numbe[10]={0};

bool C(int number[10])
{
	for(int i=1;i<10;i++)
	{
		//printf("%d ",number[i]);
	}
	//printf("\n");
	int ans=0;
	int min=10;
	for(int i=1;i<10;i++)
	{
		ans+=number[i];
		if(number[i]!=0)min=MIN(min,i);
	}
	if(ans==0)return true;
	if(number[min]>=3)
	{
		number[min]-=3;
		if(C(number))return true;
		number[min]+=3;
	}
	if(min<8&&number[min+1]!=0&&number[min+2]!=0)
	{
		number[min]--;
		number[min+1]--;
		number[min+2]--;
		if(C(number))return true;
		number[min]++;
		number[min+1]++;
		number[min+2]++;
	}
	return false;
}

bool check(int number[])
{
	for(int i=1;i<10;i++)
	{
		if(number[i]>=2)
		{
			number[i]-=2;
			if(C(number))return true;
			number[i]+=2;
		}
	}
	return false;
}

int main()
{
	int n[10];
	char c[15];
	while(scanf("%s",c)!=EOF)
	{
		fill(numbe,numbe+10,0);
		for(int i=0;i<13;i++)
		{
			numbe[c[i]-'0']++;
		}
		for(int i=0;i<10;i++)
		{
			n[i]=numbe[i];
		}
		bool flag=true;
		for(int i=1;i<10;i++)
		{
			for(int j=0;j<10;j++)
			{
				numbe[j]=n[j];
			}
			numbe[i]++;
			if(numbe[i]!=5&&check(numbe))
			{
				if(!flag)printf(" ");
				printf("%d",i);
				if(flag)flag=false;
			}
		}
		if(flag)printf("0");
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 0
from collections import deque
import copy

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

sortedP = sorted(P)

if sortedP == P:
    print("YES")
    exit(0)

diff_count = 0
for p, sp in zip(P, sortedP):
    if p != sp:
        diff_count += 1


print("YES") if diff_count == 2 else print("NO")

Measured memory_bytes: 3444
s = input()
s = " " + s + " "
n = len(s) - 1
r = True
if s != s[::-1]:
    r = False
if s[1 : (n - 1) // 2 + 1] != s[(n - 1) // 2 : 0 : -1]:
    r = False
if s[(n + 3) // 2 : -1] != s[n - 1 : (n + 3) // 2 - 1 : -1]:
    r = False
print("Yes") if r else print("No")


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;



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

	ll H, W, h, w;
	cin >> H >> W >> h >> w;

	cout << H * W - H * w - h * W + h * w << endl;

	//system("pause");
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }

int main(){
    int d; cin >> d;
    if(d == 25) cout << "Christmas" << endl;
    else if(d == 24) cout << "Christmas Eve" << endl;
    else if(d == 23) cout << "Christmas Eve Eve" << endl;
    else if(d == 22) cout << "Christmas Eve Eve Eve" << endl;
    return 0;
}


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

using namespace std;

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

	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	for(int & i : a) cin >> i;
	sort(a.begin(), a.end());
	int ans = 0;
	for(int i =0; i<m; ++i) ans += a[i];
	cout << ans;
}

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

typedef struct {
    int     num;
    int     t_f = 0;
}           bingo;

void    set_tf(bingo in[3][3], int num)
{
    for (int    i = 0; i < 3; i++)
    {
        for (int    j = 0; j < 3; j++)
            if (in[i][j].num == num) in[i][j].t_f = 1;
    }
}

void    write_bingo(bingo in[3][3])
{
    for (int    i = 0; i < 3; i++)
    {
        for (int    j = 0; j < 3; j++)
            cout << in[i][j].t_f << " ";
        cout << endl;
    }
}

int    search_ans(bingo in[3][3])
{
    int     flag;
    for (int    i = 0; i < 3; i++)
    {
        flag = 1;
        for (int    j = 0; j < 3; j++)
            if (in[i][j].t_f == 0) flag = 0;
        if (flag == 1) return (1);
    }
    for (int    i = 0; i < 3; i++)
    {
        flag = 1;
        for (int    j = 0; j < 3; j++)
            if (in[j][i].t_f == 0) flag = 0;
        if (flag == 1) return (1);
    }
    flag = 1;
    int     i = -1;
    int     j;
    while (++i < 3)
        if (in[i][i].t_f == 0) flag = 0;
    if (flag == 1) return (1);
    flag    =   1;
        i   =   0;
        j   =   2;
    while (i < 3)
        if (in[i++][j--].t_f == 0) flag = 0;
    if (flag == 1) return (1);
    return (0);
}

int main(void){
    // Your code here!
    bingo   in[3][3];
    int     count;
    int     buf;
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
            cin >> in[i][j].num;
    }
    std::cin >> count;
    while (count-- > 0)
    {
        cin >> buf;
        set_tf(in, buf);
    }
    if (search_ans(in) == 1)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return (0);
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

set<ll> factorize(ll x) {
    set<ll> primes;
    primes.insert(1);

    for (ll i = 2; i * i <= x; ++i) {
        while (x % i == 0) {
            primes.insert(i);
            x /= i;
        }
    }
    if (x != 1) { primes.insert(x); }
    return primes;
}

ll solve(ll a, ll b) {
    set<ll> pa = factorize(a), pb = factorize(b);

    ll ans = 0;
    for (ll p : pa) { ans += pb.count(p); }
    return ans;
}

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

    ll a, b;
    cin >> a >> b;
    cout << solve(a, b) << endl;

    return 0;
}

Measured memory_bytes: 256
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	double x, a, b; cin >> a >> b >> x;

	if(x <= a * a * b / 2)
	{
		double d = 2 * x / a / b;
		cout << 180 * (1 / (M_PI / atan(b / (d)))) << endl;
	}
	else{
		double c = x / (a * a);
		cout << 180 * (1 / (M_PI / atan((b-c) / (a/2)))) << endl;
	}
	return 0;
}


Measured memory_bytes: 512
#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>;
int main(){
    int n, r=0;
    cin >> n;
    vector<int> a(n);
    for (int& i : a) cin >> i;
    for (int i = 0; i < n;++i){
        if (i % 2 == 0 && a[i] % 2 == 1) ++r;
    }
    cout << r;
}

Measured memory_bytes: 3620
from collections import deque

N = int(input())
tree = [[] for _ in range(N + 1)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    tree[u].append((v, w))
    tree[v].append((u, w))

ans = [-1] * (N + 1)
q = deque()
q.append((1, 0, None))
while len(q):
    u, d, prev = q.pop()
    ans[u] = d % 2
    for v, w in tree[u]:
        if v != prev:
            q.append((v, d + w, u))

for v in ans[1:]:
    print(v)


Measured memory_bytes: 39948
#include<stdio.h>

#define MAX 100000

int parent(int);
int left(int);
int right(int);

int main(){
  int H,i,A[MAX+1];

  scanf("%d",&H);
  for(i=1;i<=H;i++)scanf("%d",&A[i]);

  for(i=1;i<=H;i++){
    printf("node %d: ",i);
    printf("key = %d, ",A[i]);
    if(parent(i)>=1)printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=H)printf("left key = %d, ",A[left(i)]);
    if(right(i)<=H)printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}
int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}


Measured memory_bytes: 2732
def divisors(n):
    i = 1
    table = set()
    while i * i <= n:
        if not n % i:
            table.add(i)
            table.add(n//i)
        i += 1
    table = list(table)
    return table

def binary_search_int(ok, ng, test):
    """
    :param ok: solve(x) = True を必ず満たす点
    :param ng: solve(x) = False を必ず満たす点
    """
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if test(mid):
            ok = mid
        else:
            ng = mid
    return ok

import numpy as np
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
S = sum(A)
D = divisors(S)
D.sort()

def test(x):
    k = D[x]
    B = A%k
    B.sort()
    cnt = sum(B)//k
    return k*cnt - sum(B[-cnt:]) <= K

p = binary_search_int(0,len(D),test)
q = binary_search_int(p+1,len(D),test)
print(max(D[p],D[q]) if q != p+1 else D[p])

Measured memory_bytes: 27212
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#define il inline
#define re register
#define fo(i,j,k) for(register int i=j;i<=k;i++)
#define inf 0x7fffffff
typedef long long ll;
using namespace std;
il ll read()
{
	re ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return f*x;	
}
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<" "<<b<<" "<<c<<endl; 
	return 0; 
}


Measured memory_bytes: 256
N = gets.to_i
A = gets.split.map(&:to_i)

left = [A[0]]
right = [A[N-1]]

for i in 1..N-1 do
  left[i] = left[i-1].gcd(A[i])
  right[i] = right[i-1].gcd(A[N-1-i])
end
max = 1

for i in 0..N-1 do
  tmp =
  if i == 0
    right[N-2]
  elsif i == N-1
    left[N-2]
  else
    left[i-1].gcd(right[N-i-2])
  end
  max = tmp if max < tmp
end

puts max


Measured memory_bytes: 10272
class UnionFind:
    __slots__ = ["_data_size", "_roots"]

    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size

    def __getitem__(self, x: int) -> int:
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def is_connected(self, x: int, y: int) -> bool:
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x


def main():
    import sys

    readline = sys.stdin.buffer.readline

    N, Q = map(int, readline().split())
    tree = UnionFind(N)
    res = []
    for _ in range(Q):
        t, u, v = map(int, readline().split())
        if t:
            res.append(int(tree.is_connected(u, v)))
        else:
            tree.unite(u, v)
    print("\n".join(map(str, res)))


if __name__ == "__main__":
    main()


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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            var array = new bool[nk[0]];

            for (var i = 0; i < nk[1]; i++)
            {
                Console.ReadLine();
                foreach (var numStr in Console.ReadLine().Split(' '))
                {
                    array[int.Parse(numStr) - 1] = true;
                };
            }

            Console.WriteLine(array.Where(b => !b).Count());

        }
    }
}

Measured memory_bytes: 28380
program tiling
  implicit none
  integer :: n, m, a, b, x(1000,1000) = 0, i, j
  character(1) :: s(0:4) = (/".","<",">","^","v"/)
  read(*,*) n, m, a, b
  if (mod(n,2) == 0 .and. mod(m,2) == 0) then
    call fill_sq(x,n,m,a,b)
  else if (mod(n,2) == 0) then
    call fill_rc(x(:,m),n,b,3,4)
    call fill_sq(x,n,m-1,a,b)
  else if (mod(m,2) == 0) then
    call fill_rc(x(n,:),m,a,1,2)
    call fill_sq(x,n-1,m,a,b)
  else if (2*(a+b) /= n*m-1 .or. mod(b,2) == mod((n-1)*m/2,2)) then
    call fill_rc(x(:,m),n-1,b,3,4)
    call fill_rc(x(n,:),m-1,a,1,2)
    call fill_sq(x,n-1,m-1,a,b)
  else
    x(n,m-1:m) = (/1,2/)
    x(n-2,m-2:m-1) = (/1,2/)
    x(n-2:n-1,m) = (/3,4/)
    x(n-1:n,m-2) = (/3,4/)
    a = a-2
    b = b-2
    call fill_rc(x(:,m),n-3,b,3,4)
    call fill_rc(x(n,:),m-3,a,1,2)
    call fill_sq(x,n-3,m-3,a,b)
    call fill_sq(x(n-2:n-1,:),2,m-3,a,b)
    call fill_sq(x(:,m-2:m-1),n-3,2,a,b)
  end if
  if (a > 0 .or. b > 0) then
    write(*,'(a)') "NO"
    stop
  end if
  write(*,'(a)') "YES"
  do i = 1, n
    do j = 1, m
      write(*,'(a)',advance='no') s(x(i,j))
    end do
    write(*,*)
  end do
contains
  subroutine fill_rc(x,n,a,p,q)
    integer, intent(out) :: x(:)
    integer, intent(in) :: n, p, q
    integer, intent(inout) :: a
    integer :: i
    do i = 1, n, 2
      if (a > 0) then
        x(i:i+1) = (/p,q/)
        a = a-1
        cycle
      end if
      exit
    end do
  end
  subroutine fill_sq(x,n,m,a,b)
    integer, intent(out) :: x(:,:)
    integer, intent(in) :: n, m
    integer, intent(inout) :: a, b
    integer :: i, j
    do i = 1, n, 2
      do j = 1, m, 2
        if (a > 0) then
          x(i,j:j+1) = (/1,2/)
          a = a-1
          if (a == 0) cycle
          x(i+1,j:j+1) = (/1,2/)
          a = a-1
          cycle
        end if
        if (b > 0) then
          x(i:i+1,j) = (/3,4/)
          b = b-1
          if (b == 0) cycle
          x(i:i+1,j+1) = (/3,4/)
          b = b-1
          cycle
        end if
        exit
      end do
    end do
  end
end program tiling

Measured memory_bytes: 5120
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 18;
char C[CM + CL], * ci = C + CL, * owa = C + CM, c;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;

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


	fread(ci, 1, CM, stdin);
	int N = 0;
	while ((c = *ci++) >= '0') N = N * 10 + c - '0';
	int D[10];
	int d = 1;
	rep(i, 10) {
		D[i] = d;
		d *= 10;
	}

	ll p[20][20] = {};
	rep(i, N) {
		if (ci - owa > 0) {
			memcpy(C, owa, CL);
			ci -= CM;
			fread(C + CL, 1, CM, stdin);
		}

		ll kari = 0;
		while ((c = *ci++) >= '0') kari = kari * 10 + c - '0';
		int d = 9;
		if (*(ci - 1) == '.') {
			ll tmp = *(ll*)ci;
			if ((tmp & ma0) ^ ma0) {
				int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
				tmp = tmp << dig & ma1;
				tmp = tmp * 10 + (tmp >> 8) & ma2;
				tmp = tmp * 100 + (tmp >> 16) & ma3;
				tmp = tmp * 10000 + (tmp >> 32) & ma4;
				ci += (72 - dig >> 3);
				d -= (64 - dig >> 3);
				kari = kari * D[(64 - dig >> 3)] + tmp;
			}
			else {
				tmp = tmp & ma1;
				tmp = tmp * 10 + (tmp >> 8) & ma2;
				tmp = tmp * 100 + (tmp >> 16) & ma3;
				tmp = tmp * 10000 + (tmp >> 32) & ma4;
				ci += 8;
				d -= 8;
				kari = kari * 100000000 + tmp;
				if (*ci >= '0') {
					kari = kari * 10 + *ci++ - '0';
					d--;
				}
				ci++;
			}
		}
		int a = __builtin_ctzll(kari) + d;
		if (a > 18) a = 18;
		int b = d;
		while (kari % 5 == 0) {
			b++;
			kari /= 5;
		}
		p[a][b]++;
	}
	ll kotae = 0;
	rep(a, 19) rep(b, 19) if (p[a][b]) {
		ll P = p[a][b];
		for (int x = 18 - a; x <= 18; x++) {
			for (int y = 18 - b; y <= 18; y++) {
				kotae += P * p[x][y];
			}
		}
	}
	for (int a = 9; a <= 18; a++) {
		for (int b = 9; b <= 18; b++) {
			kotae -= p[a][b];
		}
	}

	printf("%lld\n", kotae / 2);

	Would you please return 0;
}

Measured memory_bytes: 1704