akhauriyash/Code-Regression huggingface dataset:
import fractions
A,B = map(int,input().split())
m = fractions.gcd(A,B)
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

l_m = prime_factorize(m)
if len(l_m) >= 1:
    ans = 2
else:
    print("1")
    exit()
for i in range(1,len(l_m)):
    if not l_m[i] == l_m[i-1]:
        ans += 1
print(ans)

Measured memory_bytes: 5180
#ITP1_11_A

def west(d):
	tmp=d[4]
	d[4]=d[1]
	d[1]=d[3]
	d[3]=d[6]
	d[6]=tmp

def east(d):
	tmp=d[4]
	d[4]=d[6]
	d[6]=d[3]
	d[3]=d[1]
	d[1]=tmp

def north(d):
	tmp=d[1]
	d[1]=d[2]
	d[2]=d[6]
	d[6]=d[5]
	d[5]=tmp

def south(d):
	tmp=d[1]
	d[1]=d[5]
	d[5]=d[6]
	d[6]=d[2]
	d[2]=tmp

def spin(d):
	tmp=d[2]
	d[2]=d[3]
	d[3]=d[5]
	d[5]=d[4]
	d[4]=tmp

def kaiten(d, op):
	if   op == "W": west(d)
	elif op == "E": east(d)
	elif op == "N": north(d)
	elif op == "S": south(d)

def inputDice():
	return list(map(int,("-1 "+input()).split()))

def solveB(d,d1,d2):
	for op in list("NWWWN-"):
		for i in range(4):
			if(d[1]==d1 and d[2]==d2):
				return d[3]
			spin(d)
		kaiten(d,op)
	return None

d=inputDice()
solveB(d,1,2)

for i in range(int(input())):
	d1,d2=map(int,input().split())
	print(solveB(d,d1,d2))


Measured memory_bytes: 5608
#include <iostream>
using namespace std;
int R[200000];
int num;
int main()
{
	//cout << "????????\???????????¶??´??????" << endl;
	cin >> num;
	for (int i = 0; i < num; i++)
	{
		cin >> R[i];
	}
	int maxv =R[1]-R[0];
	int minv = R[0];
	for (int j = 1; j < num; j++)
	{
		if (maxv < R[j] - minv)
		{
			maxv = R[j] - minv;
		}
		if (minv > R[j])
		{
			minv = R[j];
		}
	/*	for (int i = 0; i < j; i++)
		{
			if (maxv < R[j] - R[i])
			{
				maxv = R[j] - R[i];
			}
		}*/
	}
	cout << maxv << endl;
	return 0;
}

Measured memory_bytes: 3856
N = int(input())
A = [int(input()) for _ in range(N)]

A_max = max(A)
A_max_ind = A.index(max(A))

for i in range(N):
    if i==A_max_ind:
        print(max(A[:i]+A[i+1:]))
    else:
        print(A_max)

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

namespace MyProgram
{
    public class Program
    {	
        public static void Main(string[] args)
        {
            int[] n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int x1 = n[0];
            int y1 = n[1];
            int x2 = n[2];
            int y2 = n[3];
            
            int xc = x2 - x1;
            int yc = y2 - y1;

            Console.WriteLine("{0} {1} {2} {3}", x2 - yc , y2 + xc , x1 - yc , y1 + xc );
        }
    }
}

Measured memory_bytes: 13396
import Data.List
main=do
 getLine
 x<-map(f.read).words<$>getLine
 let b=length$filter((>0).length)[filter(==i)x|i<-[0..7]]
 let c=length$filter(==8)x
 print$if b==0 then 1 else b
 print$b+c
f n
 |n<3200=div n 400
 |otherwise=8

Measured memory_bytes: 1020
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys


n = int(input())
An = [[0 for j in range(n+1)] for i in range(2)]
for i in range(2):
  An[i] = [0] + list(map(int, sys.stdin.readline().rstrip().split()))

for j in range(n):
  An[0][j+1] = An[0][j] + An[0][j+1]
  An[1][j+1] = max(An[0][j+1], An[1][j]) + An[1][j+1]

print(An[1][n])

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

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

	if(n==3) return puts("2 3 25"),0;

	vector<int> ans={2,3,4,9};

	vector<int> A0={6},A2={8},A3,A4;
	for(int i=10;i<=30000;i++){
		if(i%6==0) A0.emplace_back(i);
		if(i%6==2) A2.emplace_back(i);
		if(i%6==3) A3.emplace_back(i);
		if(i%6==4) A4.emplace_back(i);
	}

	while(n-ans.size()>=2 && A2.size()>0 && A4.size()>0){
		ans.emplace_back(A2.back()); A2.pop_back();
		ans.emplace_back(A4.back()); A4.pop_back();
	}
	while(n-ans.size()>=2 && A3.size()>=2){
		ans.emplace_back(A3.back()); A3.pop_back();
		ans.emplace_back(A3.back()); A3.pop_back();
	}
	while(n-ans.size()>0){
		ans.emplace_back(A0.back()); A0.pop_back();
	}

	rep(i,n) printf("%d%c",ans[i],i<n-1?' ':'\n');

	return 0;
}


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

using namespace std;

int n,k;

bool d[10];


bool ok(int x)
{
  while (x > 0) {
    int v = x % 10;
    x /= 10;
    if (d[v]) return false;
  }
  return true;
}

int main()
{
  fill_n(d, 10, false);

  cin >> n >> k;

  for (int i = 0; i < k; i++) {
    int x;
    cin >> x;
    d[x] = true;
  }

  while (!ok(n)) n++;

  cout << n << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 100000000;
const int MOD = 1000000007;

int main(){
  int a,b,c,d;
  std::cin >> a>>b>>c>>d;
  std::cout << c-d+b<<' '<<d+c-a<<' '<<a-d+b<<' '<<b+c-a << std::endl;
}


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

const int mod = 1000000007;
string k;
int dp[10005][100][2] , d , ans;

int add(int a , int b)
{
	return ( (a%mod) + (b%mod) ) % mod;
}

int go(int pos , int sum , int pref)
{
	if(pos == (int)k.size() )return sum == 0;
		
	int &res = dp[pos][sum][pref];
	if(res != -1)
	{
		return res;
	}
	res = 0;	
	
	if(pref)
	{
		for(int i = 0; i <= (k[pos] - '0'); i++)
		{
			res = add(res , go(pos + 1 , (sum+i) % d , (i == k[pos] - '0')));
		}
	}
	else 
	{
		for(int i = 0; i <= 9; i++)
		{
			res = add(res , go(pos + 1 , (sum+i) % d , 0));
		}
	}
	return res;
}


main()
{
	memset(dp , -1 , sizeof dp);
	
	cin >> k >> d;
	
	
	for(int i = 1; i <= k.size(); i++)
	{
		if(i == 1)
		{
			for(int j = 1; j <= k[i - 1] - '0'; j++)
			{
				ans = add(ans , go(i , j % d , (j == k[i-1] - '0')));
			}
		}
		else
		{
			for(int j = 1; j <= 9; j++)
			{
				ans = add(ans , go(i , j % d , 0));
			}
		}
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 8832
#include<iostream>

using namespace std;
 
int main() 
{
    int A,B;
    cin >> A;
    cin >> B;

    if(A<=9 && B<=9)
    {
        cout << A*B << endl;
    }
    else
    {
        cout << "-1" <<endl;
    }
    return 0;
    
}

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


int main()
{
	int a, b, c;
	vector<int> v;
	char op;
	do
	{
		cin >> a >> op >> b;
		if (op == '?')
			break;
		switch (op)
		{
			case '+' : c = a + b;
					   break;
			case '-' : c = a - b;
					   break;
			case '*' : c = a * b;
					   break;
			case '/' : c = a / b;
					   break;
		}
		v.push_back(c);
	} while (true);
	
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << endl;
	return 0;
}




Measured memory_bytes: 3144
n = int(input())
l = [int(input()) for x in range(n)]

dp = [[None for x in range(200 * 100)] for x in range(n)]

def search(i, score):
    if i >= n:
        return score
    
    if dp[i][score] != None:
        return dp[i][score]

    d = max(search(i + 1, score), search(i + 1, score + l[i]))
    dp[i][score] = d
    return d

search(0, 0)
print((list(filter(lambda x: x != None and x % 10, dp[-1])) or [0])[-1])


Measured memory_bytes: 19308
n = int(input())
mod = n % 4
if mod == 0:
    print('Yes')
elif mod == 1:
    if n >= 21:
        print('Yes')
    else:
        print('No')
elif mod == 2:
    if n >= 14:
        print('Yes')
    else:
        print('No')
else:
    if n >= 7:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3060
N = int(input())
nums = [int(i) for i in input().split()]
nums_sorted = sorted(list((set(nums))), reverse=True)
def compute_divs(n):
    divs = []
    if n == 1: return [1]
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            divs.append(i)
            if i != n // i:
                divs.append(n//i)
    divs.append(n)
    return divs
ans = 1
if len(nums_sorted) == 1: ans = nums[0]
else:
    divs1 = compute_divs(nums_sorted[0])
    divs2 = compute_divs(nums_sorted[1])
    divs = sorted(list(set(divs1+divs2)))
    for i in reversed(divs):
        c= 0
        for j in nums:
            if j % i != 0:
                c += 1
                if c == 2:
                    break
        if c <= 1:
            ans = i
            break
print(ans)

Measured memory_bytes: 14052
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, K := sc.nextInt(), sc.nextInt()
	ans := 0
	for b := K + 1; b <= N; b++ {
		rests := b - K
		d := N / b
		ans += d * rests
		ans += max(0, N%b-K+1)
		if K == 0 {
			ans--
		}
	}

	fmt.Fprintln(wtr, ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
        #define endl '\n'
        #define modulo 1000000007
        #define int long long
        //#define __int128 long long
        #pragma GCC optimize("-Ofast")
        #define float double
        #define PI 3.141592653589793238462643383279502884
        #define sinDegrees(x) sin((x) * PI / 180.0)
        #define tanDegrees(x) tan((x) * PI / 180.0)
        #define atanDegrees(x) atan(x)* 180.0 / PI
        #define f first
       // #define s second
        using namespace std;
        int power(int x,int y,int m)
        {
        int temp;
        if(y == 0)
        return 1;
        temp = (power(x, y/2,m))%m;
        if (y%2 == 0)
        return ((temp%m)*temp);
        else
        return ((x*temp%m)*temp%m)%m;
        }
        int inv(int x)
        {
        return (power(x,modulo-2,modulo))%modulo;
        }
        bool comp(pair<int,int>a,pair<int,int>b)
        {
            if(a.second==b.second)
            return a.first<b.first;
            return a.second<b.second;
        }
        set<vector<int>>total;
        int maxer;
        void calculate(vector<int>n){
        set<int>buff;
        if(n.size()==maxer){
        total.insert(n);
        return;
        }
        for(int i=0;i<n.size();i++)
        buff.insert(n[i]);
        for(int i=0;i<maxer;i++)
        if(buff.find(i)==buff.end()){
        n.push_back(i);
        calculate(n);
        n.pop_back();
        }
        }
        ///Solution created by:Ahmadsm2005
        int32_t main()
        {
            //freopen("output.txt","w", stdout);
            //freopen("input0.txt","r", stdin);
            iostream::sync_with_stdio(0);
            cin.tie(0);
            cout.tie(0);
            vector<int>lolz;
            int buff;
            cin>>maxer;
            vector<int>empt;
            calculate(empt);
            vector<int>a;
            vector<int>b;
            for(int i=0;i<maxer;i++){
            cin>>buff;
            a.push_back(buff-1);
            }
            for(int i=0;i<maxer;i++){
            cin>>buff;
            b.push_back(buff-1);
            }
            auto itr=total.lower_bound(a);
            int dis=distance(total.begin(),itr);
            auto itr2=total.lower_bound(b);
            int dis2=distance(total.begin(),itr2);
            cout<<abs(dis-dis2);
            return 0;
        }


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

using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,k,h) for(int i = k; i < h; ++i)
#define rep3(i,k,h) for(int i = k; i <= h; ++i)
#define INF LLong_MAX // long long INF
#define inf INT_MAX // int inf

typedef pair<int,int> int_pair;
typedef pair<string,string> string_pair;



int main() {
    int n, ans = 0;
    string x;
    cin >> n;
    vector<pair<string,int>> data(n);
    rep(i,n) {
        cin >> data.at(i).first >> data.at(i).second;
    }
    cin >> x;
    bool bo = false;
    rep(i,n-1) {
        if(data[i].first == x || bo) {
            bo = true;
            ans += data.at(i+1).second;
        }
    }
    cout << ans << endl;
    return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    string S; cin >> S;
    int ans = S.size();
    REP(i,S.size()){
        if(S[i]=='S'){
            int s = 1, t = 0;
            while(i<S.size()-1 && t <= s){
                i++;
                if(S[i] == 'S') s++;
                else t++;
            }
            if(i == S.size()-1) ans -= 2*t;
            else ans -= s+t-1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

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

inline int in(int& a) {return scanf("%d", &a);}
inline void out(int n) {printf("%d\n", n);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


const int MOD = (int)(1e9 + 7);
int N, K;
vector<int> adj[100000];
ll pattern[100000];

void dfs(int index, int color){
    pattern[index] = (ll)max(0, color);
    color = (index == 0) ? K - 1 : K - 2;
    for(auto next : adj[index]){
        if(pattern[next] == -1){
            dfs(next, color);
            color--;
        }
    }
}

signed main(){
    cin >> N >> K;
    int a, b;
    REP(i, N - 1){
        cin >> a >> b;
        adj[a - 1].push_back(b - 1);
        adj[b - 1].push_back(a - 1);
    }
    REP(i, N) pattern[i] = -1;
    dfs(0, K);
    ll ans = 1;
    REP(i, N){
        //cerr << pattern[i] << ENDL;
        ans = (ans * pattern[i]) % MOD;
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15

const int N = 1e5 + 14;
vector<int> cnt(N, 0);

 
int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
		cnt[a[i]]++;
	}
	int mx = 0;
	for(int i = 0; i < n; i++){
		if(a[i] != 0)
			mx = max(mx, cnt[a[i]] + cnt[a[i]+1] + cnt[a[i]-1]);
		else
			mx = max(mx, cnt[a[i]] + cnt[a[i]+1]);
	}
	cout << mx << endl;
	return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;
const int MAX_N = 101;
const int MAX_L = 101;

class C{
    public:
        int p, dis, cost;
        C(int _p, int _dis, int _cost);
};

C::C(int _p, int _dis, int _cost){
    p = _p;
    dis = _dis;
    cost = _cost;
}

int main(){
    int n, m, l;
    while(cin >>n >>m >>l && (n || m || l)){
        vector< vector<C> > v(n, vector<C>());
        REP(i, m){
            int a, b, c, d;
            cin >>a >>b >>c >>d;
            a--;
            b--;
            v[a].push_back( C(b, c, d) );
            v[b].push_back( C(a, c, d) );
        }
        int closed[MAX_N][MAX_L];
        REP(i, MAX_N){
            REP(j, MAX_L){
                closed[i][j] = INF;
            }
        }
        queue<C> open;
        open.push( C(0, l, 0) );

        while(!open.empty()){
            C now = open.front();
            open.pop();

            if(now.cost >= closed[now.p][now.dis]) continue;

            closed[now.p][now.dis] = now.cost;
            REP(i, v[now.p].size()){
                C next = v[now.p][i];
                if(now.dis >= next.dis){
                    open.push( C(next.p, now.dis - next.dis, now.cost) );
                }
                open.push( C(next.p, now.dis, now.cost + next.cost) );
            }
        }

        int ans = INF;
        REP(i, MAX_L){
            ans = min(ans, closed[n - 1][i]);
        }
        cout <<ans <<endl;
    }
    return 0;
}

Measured memory_bytes: 19768
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long 
#define pb push_back
#define fo(i,N) for(int i = 0 ; i < N ; i++)
#define foo(i,x,N) for (int i = x; i < N ; i++)
#define fill(a,val) memset(a,val,sizeof(a))
#define fastio()  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define ff first
#define ss second
#define MAX 1234567
#define pii pair<int,int> 
#define pll pair<ll,ll> 
#define inf 1e14+1
#define all(a) a.begin(),a.end()
int n;
int  arr[17][17];
ll dp[1ll<<16];
ll sum[1ll<<16];


ll calc(int idx)
{
  ll ans = 0;

  fo(i,17)
  { if ( (idx & (1<<i)) == 0)
    continue;
    for(int j = i+1; j < 17 ; j++)
     {
          if ( idx & (1<<j))
            ans += arr[i][j];
     }
  }
  return ans;
}

void pre()
{
   foo(i,1,1<<n)
   {
    dp[i] = inf;
    sum[i] = calc(i);
   }
}

ll solve(int i)
{ 
   if ( i == 0)
    return 0;

    if ( dp[i] != inf)
      return dp[i];
    
    ll ans = 0;
    for(int m = i ; m != 0 ; m = (m-1)&i)
    {
      ans = max(ans,sum[m]+solve(i^m));

    }
    return dp[i] = ans;
}


int main()
{ 
  cin >> n;
  fo(i,n)
  {
    fo(j,n)
    cin >> arr[i][j];
  }
  pre();



  cout << solve((1<<n)-1) << endl;


 

}

Measured memory_bytes: 1408
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
int mul[214514];
int divi[214514];
#define inf 1000000007
int bit[114514],n;
struct edge{int u,v,cost;};
edge es[214514];
int zero=0;
int dp[55][55][3000];
string alph("abcdefghijklmnopqrstuvwxyz");
signed main(){
    int n;cin>>n;
    string s=to_string(n);
    int count=0;
    rep(i,0,1<<(s.size()-1)){
        int num=0;
        string str=s;
        rep(j,0,s.size()-1){
            if(i>>j&1){
                count+=num*10+(s[j]-'0');
                num=0;
            }
            else num=num*10+(s[j]-'0');
        }
        count+=num*10+(s[s.size()-1]-'0');
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 998244353;
pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}};

vector<ll> V, C;


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

	else {

		return gcd(b, a % b);
	}

}


vector<ll> A;
ll dp1[100005], dp2[100005];

int main() {
	ll N;


	cin >> N;

	A.resize(N);
	rep(i, N) {

		cin >> A[i];
		
	}


	dp1[0] = A[0];
	dp2[N-1] = A[N - 1];

	for(int i = 1; i < N; i++) {
		dp1[i] = gcd(dp1[i - 1], A[i]);
		dp2[N-i-1] = gcd(dp2[N - i], A[N-i-1]);
	}

	ll ans = 0;
	for (int i = 0; i < N; i++) {

		if (i != 0 && i != N - 1)
			ans = max(ans, gcd(dp1[i-1], dp2[i+1]));

		else if (i == 0) 
			ans = max(ans, dp2[1]);



		else if (i == N - 1)
			ans = max(ans, dp1[N - 2]);
		

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
#define f first
#define s second
using namespace std;
const int INF=(int)0x3f3f3f3f;
const int MOD=(int)1e9+7;
const double eps=1e-9;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    if(s.back()!='s')
        s+='s';
    else
        s+="es";
    cout<<s;
    return 0;
}



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

int n, m;
string a[55], b[55];

bool f(int p, int q) {
	int i, j;
	for (i = 0; i < m; i++) {
		for (j = 0; j < m; j++) {
			if (a[p + i][q + j] != b[i][j]) return 0;
		}
	}
	return 1;
}

int main()
{
	int i, j;
	cin >> n >> m;
	for (i = 0; i < n; i++) cin >> a[i];
	for (i = 0; i < m; i++) cin >> b[i];
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (f(i, j)) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
    cout << "No" << endl;
    return 0;
}

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

void solve(){
  int n, a; cin >> n >> a;
  if(n % 500 <= a) cout << "Yes\n";
  else cout << "No\n";
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        int first = -1;
        int second = -2;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
            
            if (array[i] > first) {
                second = first;
                first = array[i];
            } else if (array[i] > second) {
                second = array[i];
            }
        }
        
        for (int i = 0; i < n; i++) {
            if (array[i] == first) {
                System.out.println(second);
            } else {
                System.out.println(first);
            }
        }
    }
}


Measured memory_bytes: 94044
import numpy as np

mod = 998244353


def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def lcm(a, b):
    """
    最小公倍数
    """
    return a * b / gcd(a,b)


# def main_old():
#     N, A, B, K = lii()
#     dp = np.zeros([N+1, K+1])
#     dp[:, 0] = 1
#     for n in range(1, N+1):
#         for k in range(K+1):
#             c = dp[n-1][k]
#             if k - A >= 0: c += dp[n-1][k-A]
#             if k - B >= 0: c += dp[n-1][k-B]
#             if k - (A+B) >= 0: c += dp[n-1][k-(A+B)]
#             dp[n][k] = c
#
#     print(int(dp[N][K]) % mod)


def solve_eucl(A, B, K, N):
    for _x in range(N):
        if (K - A * _x) % B == 0:
            x = _x
            y = (K - A * _x) // B
            return x, y


def modinv(a, m):
    orgm = m
    x, lastx, y, lasty = 0, 1, 1, 0
    while m:
        a, (quotient, m) = m, divmod(a, m)
        x, lastx = lastx - quotient * x, x
        y, lasty = lasty - quotient * y, y
    if a != 1:
        raise ValueError
    return lastx % orgm


def fastcombmod(m, n):
    nn = min(n, m - n)
    num = 1
    div = 1
    for i in range(nn):
        num *= m - i
        if num > mod:
            num %= mod
        div *= i + 1
        if div > mod:
            div %= mod
    return (num * modinv(div, mod)) % mod


def combmod_table(m):
    num = 1
    div = 1
    t = [1]
    for i in range(m // 2 ):
        num *= m - i
        if num > mod:
            num %= mod
        div *= i + 1
        if div > mod:
            div %= mod

        t.append((num * modinv(div, mod)) % mod)

    return t


def main():
    N, A, B, K = lii()
    if K == 0: return 1

    d = gcd(gcd(A, B), K)
    if d > 1:
        A = A // d
        B = B // d
        K = K // d

    # x, y = solve_eucl(A, B, K, N)
    #
    # C = int(lcm(A, B))
    # ans = 0
    # p = x
    # while True:
    #     q = (K - A * p) // B
    #     if q <= 0:
    #         break
    #
    #     ans = (ans + fastcombmod(N, p) * fastcombmod(N, q)) % mod
    #     p += C // A
    #     if p > N:
    #         break
    #
    # return ans
    ans = 0
    ct = combmod_table(N)
    for x in range(N+1):
        y, m = divmod(K - A * x, B)
        if m == 0 and 0 <= y <= N:
            ans = ans + ct[min(x, N-x)] * ct[min(y, N-y)]
            ans = ans % mod
    return ans

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 18352
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define ALLOC(size,type) ((type*) calloc ((size), sizeof (type)))

typedef struct potential_union_find {
  i32 *parent;
  i32 *weight;
  i32 size;
} union_find;

union_find* new_union_find (i32 n) {
  union_find *u = ALLOC (1, union_find);
  u->parent = ALLOC (n, i32);
  u->weight = ALLOC (n, i32);
  for (i32 i = 0; i < n; ++i) {
    u->parent[i] = -1;
    u->weight[i] = 0;
  }
  return u;
}

i32 root (union_find *u, i32 x) {
  while (u->parent[x] >= 0) {
    x = u->parent[x];
  }
  return x;
}

int same (union_find *u, i32 x, i32 y) {
  return root (u, x) == root (u, y);
}

i32 get_weight (union_find *u, i32 x) {
  i32 sum = 0;
  while (u->parent[x] >= 0) {
    sum += u->weight[x];
    x = u->parent[x];
  }
  return sum;
}

int unite (union_find *u, i32 x, i32 y, i32 z) {
  z += get_weight (u, x);
  z -= get_weight (u, y);
  x = root (u, x);
  y = root (u, y);
  if (x == y) {
    return z == 0;
  }
  if (u->parent[x] > u->parent[y]) {
    i32 swap = x;
    x = y;
    y = swap;
    z = -z;
  }
  u->parent[x] += u->parent[y];
  u->parent[y] = x;
  u->weight[y] = z;
  return 1;
}

void run (void) {
  i32 n, q;
  scanf ("%" SCNi32 "%" SCNi32, &n, &q);
  union_find *u = new_union_find (n);
  while (q--) {
    i32 op, x, y;
    scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &op, &x, &y);
    if (op == 0) {
      i32 z;
      scanf ("%" SCNi32, &z);
      if (!unite (u, x, y, z)) {
        puts ("Contradiction");
        exit (1);
      }
    } else if (!same (u, x, y)) {
      puts ("?");
    } else {
      printf ("%" PRIi32 "\n", get_weight (u, y) - get_weight (u, x));
    }
  }
}

int main (void) {
  run();
  return 0;
}



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

int main(){
    int r,c;
    cin>>r>>c;
    char A[r][c];
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            cin>>A[i][j];
        }
    }
    long long int dp[r][c];
    int insert=1;
    for(int i=0;i<c;i++){
        if(A[0][i]=='.'){
            dp[0][i]=insert;
        }
        else{
            dp[0][i]=0;
            insert=0;
        }
    }
    insert=1;
    for(int i=0;i<r;i++){
        if(A[i][0]=='.'){
            dp[i][0]=insert;
        }
        else{
            dp[i][0]=0;
            insert=0;
        }
    }
   
    for(int i=1;i<r;i++){
        for(int j=1;j<c;j++){
            
                if(A[i][j]=='.'){
                    dp[i][j]=(dp[i-1][j]%1000000007+dp[i][j-1]%1000000007)%1000000007;
                }
                else{
                    dp[i][j]=0;
                }
            
        }
    }
    
    cout<<dp[r-1][c-1]%1000000007<<endl;
}


Measured memory_bytes: 9088
#include<iostream>
using namespace std;
#define WHITE 0
#define BLACK 1
#define MAXN 100
#define MAXH 100
#define MAXW 100

int W,H,N;
int field[MAXH][MAXW];
int x,y,a;

int main(){
  cin>>W>>H>>N;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      field[i][j]=WHITE;
    }
  }
  for(int i=0;i<N;i++){
    cin>>x>>y>>a;
    switch(a){
      case 1:
        for(int i=0;i<H;i++){
          for(int j=0;j<x;j++){
            field[i][j]=BLACK;
          }
        }
        break;
      case 2:
        for(int i=0;i<H;i++){
          for(int j=x;j<W;j++){
            field[i][j]=BLACK;
          }
        }
        break;
      case 3:
        for(int i=0;i<y;i++){
          for(int j=0;j<W;j++){
            field[i][j]=BLACK;
          }
        }
        break;
      case 4:
        for(int i=y;i<H;i++){
          for(int j=0;j<W;j++){
            field[i][j]=BLACK;
          }
        }
        break;
    }
  }
  int ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
        if(field[i][j]==WHITE) ans++;
    }
  }
  cout<<ans<<endl;
  return 0;    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
/*（๑•﹏•๑｀) */
int main() {
    int N;
    cin >> N;
    vector<PII> ans;


    if (N % 2 == 1){
        FORq(i,1,N){
            FORq(j,i+1,N){
                if (i == j) continue;
                if (i+j == N) continue;
                ans.PB(MP(i,j));
            }
        }
    }else{
        FORq(i,1,N){
            FORq(j,i+1,N){
                if (i==j) continue;
                if (i+j == N+1) continue;
                ans.PB(MP(i,j));
            }
        }
    }

    int m = ans.size();
    cout << m << "\n";
    REP(i,m){
        cout << ans[i].fst << " " << ans[i].snd << "\n";
    }
}


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

using ll = long long int;

ll x, y;

int main(void) {
  // Here your code !
	scanf("%lld %lld", &x, &y);

	if (abs(x - y) > 1) printf("Alice\n");
	else printf("Brown\n");

	return 0;
}


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

int N;

int main() {
    cin >> N;
    int odd = 0;
    int even = 0;
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        if (A % 2 == 0) even++;
        else odd++;
    }
    even += odd/2;
    odd = odd % 2;

    if (odd == 0) {
        cout << ((even == 0) ? "NO" : "YES") << endl;
    }
    else {
        cout << ((even == 0) ? "YES" : "NO") << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  int n;
  cin >> n;
  vi h(n);
  REP(i,n) cin >> h[i];
  int now = 0,ans = 0;
  REP(i,n){
    if(now<=h[i]){
      now = h[i];
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())

lis = []
slis = []
now = 2

while len(lis) < N:

    flag = True
    
    for i in slis:

        if now % i == 0:
            flag = False
            break

    if flag:
        slis.append(now)

        if now % 5 == 1:
                lis.append(now)

    now += 1

print (" ".join(map(str,lis)))


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

using namespace std;

const int max_n = 200222, mod = 1000000007;

int n, a[max_n], dp[max_n], pr[max_n];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
    }
    memset(pr, 0, sizeof(pr));
    dp[0] = 1;
    for (int i = 1; i <= n; ++i) {
        dp[i] = dp[i - 1];
        if (i > 1 && a[i] != a[i - 1] && pr[a[i]]) {
            dp[i] += dp[pr[a[i]]];
            dp[i] %= mod;
        }
        pr[a[i]] = i;
        //cout << i << ": " << dp[i] << endl;
    }
    printf("%d\n", dp[n]);
    return 0;
}


Measured memory_bytes: 2560
func readInt() -> Int {
    return Int(readLine()!)!
}

func mainB() {
    let N = readInt()

    var counts = [0, 0, 0, 0]
    let results = ["AC", "WA", "TLE", "RE"]
    (0..<N).forEach { _ in
        let result = readLine()!
        counts[results.firstIndex(of: result)!] += 1
    }

    (0...3).forEach { n in
        print(results[n], "x", counts[n])
    }
}

mainB()

Measured memory_bytes: 7792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, sum = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int A,B,C,X;
    cin >> A >> B >> C >> X;
    
    int a,b,c;
    int ans = 0;
    
    for(a=0;a<=A;++a){
        for(b=0;b<=B;++b){
            for(c=0;c<=C;++c){
                if(X == (a*500)+(b*100)+(c*50)){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
    
    return 0;
}



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

#define ll long long

using namespace std;

const int MAXN = 200010;
const int MAXM = 100010;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n, m, k;
int tot, cnt;

int a[MAXN], f[MAXN], ans[MAXN];
int head[MAXN];

struct edge {
	int to, next;
}e[MAXN * 2];

void add_edge(int x, int y) {
	e[++tot].to = y;
	e[tot].next = head[x];
	head[x] = tot;
	return;
}

void Dfs(int x, int fa) {
	int last;
	int l = 1, r = ans[fa], mid;
	if (!fa) f[1] = a[x], ans[1] = 1;
	else {
		while (l <= r) {
			mid = (l + r) >> 1;
			if (a[x] <= f[mid]) r = mid - 1;
			else l = mid + 1;
		}
		last = f[l];
		f[l] = a[x];
		ans[x] = ans[fa];
		if (l > ans[fa]) ++ans[x];
	}
	for (int i = head[x]; i; i = e[i].next) {
		int v = e[i].to;
		if (v != fa) Dfs(v, x);
	}
	f[l] = last;
	return;
}

int main(){
	int t;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 1, u, v; i < n; i++) {
		scanf("%d%d", &u, &v);
		add_edge(u, v);
		add_edge(v, u);
	}
	
	Dfs(1, 0);
	
	for (int i = 1; i <= n; i++) {
		printf("%d\n", ans[i]);
	}
	return 0;
}


Measured memory_bytes: 23548
x=input().split()
h=int(x[0])
n=int(x[1])
import numpy as np
a=np.full(n,0,int)
b=np.full(n,0,int)
for k in range(n):
  x=input().split()
  a[k]=int(x[0])
  b[k]=int(x[1])
m=max(a)  
inf=10**8
dp=np.full(h+m+1,inf,int)
dp[0]=0
for k in range(1,h+m):
  dp[k]=(dp[k-a]+b).min()
print(dp[h:h+m].min())

Measured memory_bytes: 12528
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 1; i < (int)(n+1); i++)
#include <bits/stdc++.h>
using namespace std;

int main(){
    int a,b,c,a1,b1,c1,cnt = 0;
    cin >> a >> b >> c;
    if(a == b && c == b && a%2 == 0){
        cout << "-1" << endl;exit(0);
    }
    while(a%2 == 0 && b%2 == 0 && c%2 == 0){
        a1 = b/2 + c/2;
        b1 = a/2 + c/2;
        c1 = a/2 + b/2;
        a = a1;b = b1;c = c1;
        //cout << a<<b<<c <<"\n";
        cnt++;
    }
    cout << cnt << endl;
}

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

const int V_MAX=100000;

vector<int> G[V_MAX];
vector<bool> used(V_MAX,false);
vector<int> visit;
vector<int> first_visit(V_MAX,-1);
vector<int> dat(20*V_MAX,INT_MAX);
int counter=0;
int n;

void vector_out(vector<int> &vec,int k){
	for (int i=0;i<k;i++){
		cout << vec[i] << endl;
	}
}

void dfs(int s){
	if(used[s]==true){return;}
	used[s]=true;
	visit.push_back(s);
	first_visit[s]=counter;
	counter++;
	for (int i=0;i<G[s].size();i++){
		if(used[G[s][i]]==false){
			dfs(G[s][i]);
			visit.push_back(s);
			counter++;
		}
	}
	return;
}

void update(int k, int a){
	k+=n-1;
	dat[k]=a;
	while(k>0){
		k=(k-1)/2;
		dat[k]=min(dat[2*k+1],dat[2*k+2]);
	}
}

int query(int a,int b,int l,int r,int k){
	if(r<=a || b<=l){
		return INT_MAX;
	}
	if(a<=l && r<=b){
		return dat[k];
	}else{
		return min(query(a,b,l,(l+r)/2,2*k+1),query(a,b,(l+r)/2,r,2*k+2));
	}
}

int LCA(int u,int v,int n){
	u=first_visit[u];
	v=first_visit[v];
	int x = min(u,v);
	int y = max(u,v);
	return query(x,y+1,0,n+1,0);
}

int main(){
	int V,deg,to;
	cin>> V ;
	for (int i=0;i<V;i++){
		cin >> deg;
		for(int j=0;j<deg;j++){
			cin >> to;
			G[i].push_back(to);
		}
	}
	dfs(0);
	
	int R = visit.size();
	
	n=1;
	while(n<R){
		n=2*n;
	}
	
	for(int i=0;i<R;i++){
		update(i,visit[i]);
	}
	
	int Q;
	cin >> Q ;
	
	if(V==1){
		for(int i=0;i<Q;i++){
			cout << 0 <<endl;
		}
	}else{
		for (int i=0;i<Q;i++){
			int x,y;
			cin >> x >> y;
			cout << LCA(x,y,n) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 19120
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var ABK = ReadSplitLong();
            var A = ABK[0];
            var B = ABK[1];
            var K = ABK[2];

            var ans = new long[2];
            ans[1] = B;
            if (A >= 1)
            {
                ans[0] = A - K < 0 ? 0 : A - K;
                K -= A;
            }

            if (K > 0 && B >= 1)
                ans[1] = B - K < 0 ? 0 : B - K;

            Println($"{ans[0]} {ans[1]}");
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static void YESOrNO(bool e) => Println(e ? "YES" : "NO");

        static void YesOrNo(bool e) => Println(e ? "Yes" : "No");

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());
        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}

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

int main() {
  int64_t n, a = 0; 
  cin >> n;
  vector<int> v(n);
  for(int i = 0; i < n; i++)
    cin >> v.at(i);
  sort(v.begin(), v.end());
  for(int i = 0; i < n - 2; i++){
    for(int j = i + 1; j < n - 1; j++){
      for(int k = j + 1; k < n; k++){
        if(v.at(i) + v.at(j) > v.at(k))
          a++;
        else break;
      }
    }
  }
  cout << a << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = a; i < (b); ++i)
using namespace std;

int main() {

    int X;
    cin >> X;

    if (X >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;

//----------------------------------------------------------

int n, q;

int main(){
    cin >> n;
    string s;
    cin >> s >> q;
    vector<set<int>> str(26);
    REP(i,n)
    {
        str[s[i]-'a'].insert(i);
    }
    vector<int> ans;
    REP(i,q)
    {
        int t;
        cin >> t;
        if(t==1)
        {//type1
            int j;
            char c;
            cin >> j >> c;
            str[s[j-1]-'a'].erase(j-1);
            str[c-'a'].insert(j-1);
            s[j-1]=c;
        }
        else
        {//type2
            int l, r;
            cin >> l >> r;
            int sum=0;
            REP(d,26)
            {
                if(str[d].empty())continue;
                auto it = str[d].lower_bound(l-1);
                if(it!=str[d].end() && (*it)<=r-1)
                {
                    sum++;
                }
            }
            ans.push_back(sum);
        }
    }
    for(auto it=ans.begin();it!=ans.end();it++)
    {
        cout << (*it) << endl;
    }
    return 0;
}


Measured memory_bytes: 24452
#include <bits/stdc++.h>
#define NMAX (int)(2e5+4)
#define all(x) x.begin(),x.end()
#define rep(i, l, r) for(int i = l; i < r; ++i)
#define rev(i, r, l) for(int i = r - 1; i >= l; --i)
#define ft first
#define sd second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;

ll n,k;

int main(){
    cin>>n>>k;
    if(n < k)
        cout<<min(n, k-n);
    else{
        ll diff=n-k;
        n-=(diff/k)*k;
        cout<<min({n, n-k, 2*k-n});
    }
    return 0;
}


Measured memory_bytes: 256
import sys

INF = 1001001001

def resolve():
  n = int(input())
  a = list(map(int, input().split()))
  a.sort(reverse=True)
  ans = 0
  for i in range(n):
    ans += a[2*i + 1]
  print(ans)

  return

if __name__ == "__main__":
  resolve()


Measured memory_bytes: 37084
import sys,math

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	k = II()
	ans = 0
	for i in range(1,k+1):
		for j in range(i,k+1):
			for k in range(j,k+1):
				if(i==j==k):
					ans += math.gcd(math.gcd(i,j),k)
				elif(i!=j and j!=k and k!=i):
					ans += math.gcd(math.gcd(i,j),k)*6
				else:
					ans += math.gcd(math.gcd(i,j),k)*3
	print(ans)



if __name__ == '__main__':
	main()

Measured memory_bytes: 9284