akhauriyash/Code-Regression huggingface dataset:
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N, M := nextInt(), nextInt()
	An := make(map[int]int)
	keys := make([]int, 0)
	for i := 0; i < N; i++ {
		A := nextInt()
		if _, e := An[A]; !e {
			keys = append(keys, A)
		}
		An[A]++
	}
	for i := 0; i < M; i++ {
		B, C := nextInt(), nextInt()
		if _, e := An[C]; !e {
			keys = append(keys, C)
		}
		An[C] += B
	}
	sort.Ints(keys)
	var ans, index int
	index = N
	for i := len(keys) - 1; i >= 0; i-- {
		num := MinOf(index, An[keys[i]])
		ans += keys[i] * num
		index -= num
		if index == 0 {
			break
		}
	}
	fmt.Println(ans)
}

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

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

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

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

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

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

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

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}

// ここから拝借
// https://shoman.hatenablog.com/entry/2020/02/25/185456
// Stackは[]intのエイリアス
type Stack []int

// Push adds an element
func (s *Stack) Push(v int) {
	*s = append(*s, v)
}

// Pop removes the top element and return it
func (s *Stack) Pop() (int, error) {
	if s.Empty() {
		return 0, fmt.Errorf("stack is empty")
	}

	v := (*s)[len(*s)-1]
	*s = (*s)[:len(*s)-1]
	return v, nil
}

// Peek returns the top value
func (s *Stack) Peek() (int, error) {
	if s.Empty() {
		return 0, fmt.Errorf("stack is empty")
	}

	return (*s)[len(*s)-1], nil
}

// Size returns the length of stack
func (s *Stack) Size() int {
	return len(*s)
}

// Empty returns true when stack is empty
func (s *Stack) Empty() bool {
	return s.Size() == 0
}

// NewStack generates stack
func NewStack() *Stack {
	s := new(Stack)
	return s
}


Measured memory_bytes: 20436
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(M)]

ans = min(a) + min(b)
for x, y, c in xyc:
    ans = min(ans, a[x-1] + b[y-1] - c)
print(ans)

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

# 組み合わせ　n_C_r
def comb(n,r):
    r = min(r,n-r)
    result = 1
    for i in range(n-r+1,n+1):
        result *= i
    for i in range(1,r+1):
        result //= i
    return result

def root(x):
    # ノードが負 <=> xは根
    if nodes[x] < 0:
        return x
    else:
        # 経路圧縮:再帰的に根を調べてその過程で通った要素は全て根に直接つなぎ直す
        nodes[x] = root(nodes[x])
        return nodes[x]

def unite(x,y):
    root_x = root(x); root_y = root(y)
    # 根が同じなら結合済みなのでreturn(わざわざ分岐するのは自己ループを考慮)
    if root_x == root_y:
        return
    # 根ノードは木の高さを表す(負数で表していることに注意)
    rank_x = -nodes[root_x]; rank_y = -nodes[root_y]
    if rank_x >= rank_y:
        root_l = root_x; root_s = root_y
    else:
        root_l = root_y; root_s = root_x
    # 繋いだ分だけ木を高くする
    nodes[root_l] += nodes[root_s]
    # 低い木を高い木に繋げる
    nodes[root_s] = root_l

def same(x,y):
    return root(x) == root(y)

def rank(x):
    return -nodes[root(x)]

N,M = map(int,input().split())
info = [list(map(int,input().split())) for i in range(M)]

# ノードは-1で初期化, Nは頂点数
nodes = [-1]*N
ans_list = [comb(N,2)]
ans = comb(N,2)
for i in range(1,M)[::-1]:
    A = info[i][0]-1; B = info[i][1]-1
    if not(same(A,B)):
        ans -= rank(A)*rank(B)
    unite(A,B)
    ans_list.append(ans)

for e in ans_list[::-1]:
    print(e)

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

using namespace std;

int main(){

	int a,b;

	int soma;
	int su;
	int vezes;

	cin >> a;
	cin >> b;

	soma = a + b;
	su = a - b;
	vezes = a * b;

	if(soma >= su && soma >= vezes)
	{
		cout << soma << "\n";
	}else 

	if(su >= soma && su >= vezes)
	{
		cout << su << "\n";
	}else

	if(vezes >= soma && vezes >= su)
		cout << vezes << "\n";

	return 0;
}


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

int main(){

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

Measured memory_bytes: 256
cards = gets.to_i
array = gets.split(" ").map{|k|k.to_i}
 
cards_sum1 = 0
cards_sum2 = 0
array.each do |num|
    cards_sum1 += num
end


ans = Float::INFINITY
for i in 0..array.length-2 do
    cards_sum2 += array[i]
    a = (cards_sum1 - (cards_sum2 * 2)).abs
    if ans > a
        ans = a
    end
end
 
puts ans

Measured memory_bytes: 15236
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int ans = b/a;
  if(ans > c) ans = c;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
// #include<unordered_map>
#include<set>
// #include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y, idx;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

template<typename T>
T minT(T a, T b) {
	if (a < b) return a;
	else return b;
}

template<typename T>
T maxT(T a, T b) {
	if (a > b) return a;
	else return b;
}

template<typename T>
T absT(T a) {
	if (a < 0) a *= -1;
	return a;
}

template<typename T>
T powT(T a, T x) {
	T res = 1;
	while (x > 0) {
		if (x & 1) res = res * a;
		a = a * a;
		x >>= 1;
	}
	return res;
}

ll StoLL(string str) {
	ll ret = 0, ini = 0;
	if (str[0] == '-') ini = 1;
	repi(i, ini, str.length()) {
		ret *= 10;
		ret += (ll)(str[i] - '0');
	}
	if (ini) ret *= -1;
	return ret;
}

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

string s, t;
bool ans = false;

int main() {
	cin >> s >> t;
	s += s;
	repd(i, t.length(), 0) {
		repi(j, 0, t.length()) {
			if (s[i + j] != t[j]) break;
			if (j == t.length() - 1) ans = true;
		}
	}

	if (ans) wrln("Yes");
	else wrln("No");

	return 0;
}


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();
        long ans = 0;
        for (int i=1;i<=n;i++) {
            if (i%3>0 && i%5>0) {
                ans += i;
            }
        }
        System.out.println(ans);
    }
}


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


string fight_class(double wight) {
	if (wight <= 48.0) return "light fly";
	else if (wight > 48.0&&wight <= 51.0)return "fly";
	else if (wight > 51.0&&wight <= 54.0)return "bantam";
	else if (wight > 54.0&&wight <= 57.0)return "feather";
	else if (wight > 57.0&&wight <= 60.0)return "light";
	else if (wight > 60.0&&wight <= 64.0)return "light welter";
	else if (wight > 64.0&&wight <= 69.0)return "welter";
	else if (wight > 69.0&&wight <= 75.0)return "light middle";
	else if (wight > 75.0&&wight <= 81.0)return "middle";
	else if (wight > 81.0&&wight <= 91.0)return "light heavy";
	else if (wight > 91.0)return "heavy";
}

int main() {
	double wight; vector<string> v;
	while (cin>>wight){
		v.push_back(fight_class(wight));
	}
	for (int i = 0; i < v.size(); i++) {
		cout << v[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3248
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repn(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define sz(v) (ll)v.size()
using namespace std;

ll MOD=1e9+7;
ll g,h,l;
const ll N=100005;

ll add(ll a,ll b); ll mul(ll a,ll b); ll binpo(ll a,ll b);

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n,x,y;
    cin>>n>>x>>y;
    x--;y--;
    set<pair<int,int>> s[n];
    vector<int> adj[n];
    for(int i=1;i<n;i++){
        adj[i].push_back(i-1);
        adj[i-1].push_back(i);
    }
    adj[x].push_back(y);
    adj[y].push_back(x);
    for(int i=0;i<n;i++){
        int par = i;
        int dis[n];
        for(int j=0;j<n;j++){
            dis[j]=2*n;
        }
        queue<int> q;
        q.push(par);
        dis[par]=0;
        while(!q.empty()){
            auto top = q.front();
            q.pop();
            for(auto c:adj[top]){
                if(dis[c]>dis[top]+1){
                    q.push(c);
                    dis[c]=dis[top]+1;
                }
            }
        }
        for(int j=0;j<n;j++){
            s[dis[j]].insert({min(par,j),max(par,j)});
        }
    }
    for(int j=1;j<n;j++){
        // for(auto i:s[j]){
        //     cout<<i
        // }
        cout<<s[j].size()<<endl;
    }

}

ll add(ll a,ll b)
{
    return (a%MOD+b%MOD)%MOD ;
}
ll mul(ll a,ll b)
{
    return (a* 1ll *b)%MOD ;
}
ll binpo(ll a,ll b)
{
    int ans = 1 ;
    while(b)
    {
        if( b % 2 != 0)
        {
            ans = mul(ans,a);
        }
        a = mul(a,a);
        b = b/2;
    }
    return ans;
}

Measured memory_bytes: 94372
N = int(input())
A = [int(i) for i in input().split()]

MOD = 10**9+7

from collections import Counter
 
for key,count in sorted(Counter(A).items(), key=lambda x:x[0]):
    if key == 0 and N % 2 == 1:
        continue
    if count == 2 and key % 2 != N % 2:
        continue
    print(0)
    exit()
 
# 0は1つだけだから
if N % 2 == 1:
    N -= 1
 
print(2 ** (N//2) % MOD)

Measured memory_bytes: 15904
#include <bits/stdc++.h>
using namespace std;
 
 
string substrBack(string str, size_t pos, size_t len) {
    const size_t strLen = str.length();
    return str.substr(strLen - pos, len);
}

int main() {
  
    string S;
    cin >> S;
    int result = 0;
    for(int i = 0; i < S.length() / 2; i++){
        if(S.substr(i,1) != substrBack(S, i+1, 1)){
            result++;
        }
    }

    cout << result << endl;


}

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

import math
 
a = N // 3
b = N // 5
c = N // 15
 
d = 3*a*(a+1)/2
e = 5*b*(b+1)/2
f = 15*c*(c+1)/2
 
g = N*(N+1)/2
 
print(math.floor(g-d-e+f))

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
using namespace std;
template <class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b<a) {a = b; return 1;} return 0;}
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
    int n;
    cin >> n;
    int res = 0;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    rep(i,n) {
        if (v[i] != i+1) {
            ++res;
        }
    }
    if (res <= 2) {
        cout << "YES" << "\n";
    } else {
        cout << "NO" << "\n";
    }
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import numpy as np

def main():
    p = [list(map(int, input().split() ) ) for i in range(3)]
    n = int(input())
    bl = [int(input()) for i in range(n)]

    arr = np.array(p, dtype=np.float64)

    for b in bl:
        if b in arr:
            arr[arr==b] = 0
    yoko0 = np.sum(arr[0])
    yoko1 = np.sum(arr[1])
    yoko2 = np.sum(arr[2])
    tate0 = np.sum(arr[:, 0])
    tate1 = np.sum(arr[:, 1])
    tate2 = np.sum(arr[:, 2])
    naname0 = arr[0][0] + arr[1][1] + arr[2][2]
    naname1 = arr[0][2] + arr[1][1] + arr[2][0]
    if yoko0*yoko1*yoko2*tate0*tate1*tate2*naname0*naname1 == 0:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Measured memory_bytes: 12500
N,Q=[int(s) for s in input().split()]
#辺でつながれた場所をすべてリストアップ
con_list=[set() for s in range(N+1)]
for i in range(N-1):
  a,b=[int(s) for s in input().split()]
  con_list[a].add(b)
  con_list[b].add(a)

v_list=[0 for s in range(N+1)]
for i in range(Q):
  x,y=[int(s) for s in input().split()]
  v_list[x]+=y

position=1 #現在位置
counter=v_list[1] #カウンター
ans_list=[0 for s in range(N+1)] #答え
ans_list[1]=counter 
vertex_num=1 #訪れた場所の数
oya_list=[-1 for s in range(N+1)] #親に戻るためのリスト

while vertex_num<N:
  #まだ行っていない子があるか？
  if len(con_list[position])>0:
    x=con_list[position].pop()
    con_list[x].remove(position) #xの行先から親を消す
    oya_list[x]=position
    position=x
    counter+=v_list[position] #カウンターの更新
    ans_list[position]=counter
    vertex_num+=1
  else: #行き先がないなら戻る
    position=oya_list[position]
    counter=ans_list[position] #カウンターを戻す
print(*ans_list[1:])

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int h, w;
  cin >> h >> w;
  // char a[h][w];
  // rep(i, h) rep(j, w)  cin >> a[i][j]; 
  h += 2;
  w += 2;
  char a[h][w],c;
  rep(i, h) rep(j, w) {
    if (i == 0 || i == h - 1 || j == 0 || j == w - 1) {
      cout << '#';
      if (j == w - 1) cout << endl;
    } else {
      cin >> c;
      cout << c;
    }
  }

  return 0;
}


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

using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define FASTIO cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); cout.tie(0);

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define DEBUG 1
#define ddcout if (DEBUG) cout
#define ddprintf(fmt, ...) if (DEBUG) printf (fmt, __VA_ARGS__)

int main() {
    string s, t;
    cin >> s >> t;
    cout << t + s << '\n';
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())


def getP(p, i):
    if i*2 < K:
        return getP(p+1, i*2)
    else:
        return p+1

ans = 0
for i in range(1, N+1):
    if i >= K:
        ans += 1 / N
    else:
        ans += 0.5 ** getP(0, i) / N

print(ans)



Measured memory_bytes: 2940
#include <stdio.h>
#include <limits.h>

#define MAX_NUM 10000   //与えられる整数の個数の最大値
#define MAX_PRIME 10e8  //与えられる整数の最大値

int main(void) {
  int n;            //与えられる整数の個数
  long num[MAX_NUM]; //与えられた整数を格納
  int cnt;      //素数の個数
  int i, j, k;

  scanf("%d", &n);
  if(!(1 <= n && n <= MAX_NUM))
    return 0;
  cnt = n;

  for (i = 0; i < n; i++){
    scanf("%ld", &num[i]);
    if(!(2 <= num[i] && num[i] <= MAX_PRIME))
      return 0;
  }

  for (i = 0; i < n; i++) {
    for (j = 2; j * j <= num[i]; j ++) {
      if(num[i] % j == 0) {
        //printf("%d,%d\n", i, j);
        cnt--;
        break;
      }
    }

  }

  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 672
s = input()
k = 'keyence'
res = 'NO'
if s[:len(k)]==k or s[len(s)-len(k):]==k:
    res = 'YES'
else:
    for i in range(len(k)+1):
        if s[:i]+s[len(s)-len(k)+i:] == k:
            res = 'YES'
            break
print(res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

const int N = 1e5 + 5;
vi g[N];
int col[N];
bool vis[N][11];

void bfs(int v, int d, int c){
	if(vis[v][d])return;
	queue<pii> q;
	q.push({v,d});
	while(q.size()){
		int u = q.front().first;	
		int dist = q.front().second;	
		q.pop();
		if(!vis[u][dist]){
			vis[u][dist] = 1;		
			if(col[u] == 0)col[u] = c;
			if(dist){
				for(int v:g[u]){
					q.push({v,dist-1});	
				}
			}
		}
	}
}


int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,m,q;
	cin >> n >> m;
	rep(i,0,m){
		int x,y;
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	cin >> q;
	vector<array<int,3>> v(q);
	rep(i,0,q)cin >> v[i][0] >> v[i][1] >> v[i][2];
	for(int i = q-1;i >= 0;--i){
		bfs(v[i][0], v[i][1], v[i][2]);
	}
	rep(i,1,n+1){
		cout << col[i] << '\n';	
	}
}


Measured memory_bytes: 10472
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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

signed main(void) {
    int n,m,k;
    cin >> m >> k;
    n = 1<<m;
    if(k >= n){
        cout << -1 << endl;
        return 0;
    }
    if(m == 1 && k == 0){
        cout << "0 1 1 0" << endl;
    }else{
        deque<int> ans;
        ans.push_back(k);
        int t = 0;
        rep(i,n)if(i != k){
            t ^= i;
            ans.push_front(i);
            ans.push_back(i);
        }
        ans.push_back(k);
        //rep(i,2*n)cout << ans[i] << " \n"[i==2*n-1];
        if(t == k){
            rep(i,ans.size())cout << ans[i] << " \n"[i==2*n-1];
        }else{
            cout << -1 << endl;
        }
    }
}


Measured memory_bytes: 3968
#include <cstdio>
//#include <string>

int main(){
	int n, c, d[6], t;
	char s[10];
	while(scanf("%d", &n), n != 0){
		for(int i = 0;i < 6;i++)d[i] = i + 1;
		t = 1;
		for(int i = 0;i < n;i++){
			scanf("%s", s);
			if(s[0] == 'N'){
				c = d[0];
				d[0] = d[1];
				d[1] = d[5];
				d[5] = d[4];
				d[4] = c;
			}
			if(s[0] == 'E'){
				c = d[0];
				d[0] = d[3];
				d[3] = d[5];
				d[5] = d[2];
				d[2] = c;
			}
			if(s[0] == 'W'){
				c = d[0];
				d[0] = d[2];
				d[2] = d[5];
				d[5] = d[3];
				d[3] = c;
			}
			if(s[0] == 'S'){
				c = d[0];
				d[0] = d[4];
				d[4] = d[5];
				d[5] = d[1];
				d[1] = c;
			}
			if(s[0] == 'R'){
				c = d[1];
				d[1] = d[2];
				d[2] = d[4];
				d[4] = d[3];
				d[3] = c;
			}
			if(s[0] == 'L'){
				c = d[1];
				d[1] = d[3];
				d[3] = d[4];
				d[4] = d[2];
				d[2] = c;
			}
			//printf("%d%d%d%d%d%d\n", d[0], d[1], d[2], d[3], d[4], d[5]);
			t += d[0];
		}
		printf("%d\n", t);
	}
	return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuffer sb = new StringBuffer();

		String[] strArray = br.readLine().split(" ");
		int a = Integer.parseInt(strArray[0]);
		int b = Integer.parseInt(strArray[1]);
		int c = Integer.parseInt(strArray[2]);

		int cnt = 0;
		for (int i = a; i <= b; i++) {
			if (c%i == 0) {cnt++;}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 24428
def searchstar(i,j):
    global vector
    global star
    global n
    flag = False
    for k in range(n):
        if star[i][0] + vector[j][0] == star[k][0] and star[i][1] + vector[j][1] == star[k][1]:
            flag = True
            break
    return flag

while True:
    m = int(input())
    if m==0: break

    vector = []

    x1,y1 = map(int, input().split())
    for i in range(m-1):
        x2,y2 = map(int, input().split())
        vector.append([x2-x1,y2-y1])

    star = []
    n = int(input())
    for i in range(n):
        a,b = map(int, input().split())
        star.append([a,b])

    for i in range(n-1,-1,-1):
        for j in range(m-1):
            if not searchstar(i, j):
                break
        else:
            print(star[i][0] - x1, star[i][1] - y1)
            break

Measured memory_bytes: 7612
#include<algorithm>
#include<functional>
#include<memory>
#include<stack>
#include<queue>
#include<vector>

using Vertex = int;
struct Edge {Vertex from, to;};
using Graph = std::vector<std::vector<Edge>>;

std::vector<std::vector<Vertex>> strongly_connected_component(const Graph& G) {
  std::vector<std::vector<Vertex>> scc;
  std::stack<Vertex> S;
  std::vector<bool> inS(G.size());
  std::vector<int> num(G.size()), low(G.size());
  int timer = 0;
  // Tarjan
  std::function<int(Vertex v)> dfs = [&](Vertex v){
    num[v] = low[v] = ++timer;
    S.push(v); inS[v] = true;
    for(const auto& e: G[v]) {
      if(!num[e.to])     low[v] = std::min(low[v], dfs(e.to));
      else if(inS[e.to]) low[v] = std::min(low[v], num[e.to]);
    }
    if(num[v] == low[v]) {
      scc.push_back(std::vector<Vertex>());
      while(true) {
        auto w = S.top(); S.pop(); inS[w] = false;
        scc.back().push_back(w);
        if(v == w) break;
      }
    }
    return low[v];
  };
  for(Vertex v = 0; v < G.size(); ++v) if(!num[v]) dfs(v);
  return scc;
}

#include<bits/stdc++.h>
using namespace std;

int main() {
  const int M = 101;
  int N;
  cin >> N;
  Graph G(M+M);
  for(int i = 0; i < N; ++i) {
    int u, d; string r;
    cin >> u >> r >> d;
    d += M;
    if(r == "lock") G[d].push_back({d, u});
    if(r == "wait") G[u].push_back({u, d});
  }
  cout << (strongly_connected_component(G).size() == G.size() ? 0 : 1) << endl;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	ll N, A, B; cin >> N >> A >> B;

	if(A>B){
		cout << 0 << endl;

	}else{

		ll cnt = (N-2)*(B-A);

		ll ans = cnt+1;

		cout << max(ans,0LL) << endl;

	}





	return 0;

}


Measured memory_bytes: 3536
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;

int s;
int c[1000000];

int main(){

	cin >> s;

	for (int i = 1; i < 1000001;i++) {
		if (c[s] != 0){
			cout << i << endl;
			break;
		}
		c[s]++;

		if (s % 2 == 0){
			s /= 2;
		}
		else{
			s = 3 * s + 1;
		}
	}

	return 0;
}

Measured memory_bytes: 256
k=int(input())
import math
x=0
c=0
d=0
for i in range(1,k+1):
  for j in range(i,k+1):
    for k in range(j,k+1):
      d=math.gcd(i,j)
      c=math.gcd(d,k)
      if i!=j and j!=k:
        x+=6*c
      elif i==j==k:
        x+=c
      else:
        x+=3*c
print(x)

Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
long long a[300000],t1[300000],t2[300000];
int main()
{
	long long n,k;
	cin>>n>>k;
	for (long long i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	long long f = 1;
	while(k>0 && f==1)
	{
		f = 0;
		for (long long i = 0; i < n; ++i)
		{
			long long g = i+a[i]+1;
			t1[i]++;
			if(g<n)
			t1[g]--;
		}
		for (long long i = 1; i < n; ++i)
		{
			long long g = i-a[i]-1;
			t2[i-1]++;
			if(g>=0)
			t2[g]--;
		}
		for (long long i = 1; i < n; ++i)
		{
			t1[i] += t1[i-1];
		}
		for (long long i = n-2; i >= 0; i--)
		{
			t2[i] += t2[i+1];
		}
		for (long long i = 0; i < n; ++i)
		{
			a[i] = t1[i] + t2[i];
			t1[i] = 0;
			t2[i] = 0;
			// printf("%lld ",a[i] );
			if(a[i]<n)
				f = 1;
		}
		// printf("\n");
		k--;
	}
	if(f==0)
	{
		for (long long i = 0; i < n; ++i)
		{
			// a[i] += k;
			printf("%lld ",n );
		}
		printf("\n");
	}
	else
	{
		for (long long i = 0; i < n; ++i)
		{
			// a[i] += k;
			printf("%lld ",a[i] );
		}
		printf("\n");
	}

	
	return 0;
}

Measured memory_bytes: 8408
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int num1 = sc.nextInt(), num2 = sc.nextInt();
            if (num1 == 0 && num2 == 0) {
                break;
            }
            if (num1 > num2) {
                System.out.println(num2 + " " + num1);
            } else if (num1 < num2) {
                System.out.println(num1 + " " + num2);
            } else {
                System.out.println(num1 + " " + num2);
            }
        }
    }
}


Measured memory_bytes: 36048
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MAX_N 55
#define MAX_VALUE 55555
using namespace std;

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

  int n;
  cin >> n;

  bool prime[MAX_VALUE + 1];
  fill(prime, prime + MAX_VALUE + 1, true);
  prime[0] = prime[1] = false;
  for(int i = 2; i <= MAX_VALUE; i++){
    if(prime[i]){
      for(int j = 2; i * j <= MAX_VALUE; j++){
        prime[i * j] = false;
      }
    }
  }

  int sp = 0;
  int b[n];
  for(int i = 2; sp < n && i <= MAX_VALUE; i++){
    if(prime[i] && i % 5 == 1){
      b[sp++] = i;
    }
  }

  string buf;
  for(int i = 0; i < n; i++){
    buf += to_string(b[i]) + " ";
  }

  cout << buf << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
ans = 0
ab = 0
a = 0
b = 0
for i in range(n):
    s = input()
    ans += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        ab += 1
    elif s[0] == "B":
        b += 1
    elif s[-1] == "A":
        a += 1

b,a = sorted([a,b])
if ab > 0:
    ans += ab-1
    ab = 1
if a > 0:
    ans += ab
ans += b
print(ans)

Measured memory_bytes: 44008
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 5050
#define mo 1000000007
char s[N];
int i,j,k,n,m,x,y,dp[N][N],re[N];
inline ll Pow(ll x,ll d) {
    ll ans = 1, y = x;
    for (; d; y = y * y % mo, d >>= 1)d & 1 ? ans = ans * y % mo : 0;
    return ans;
}
int main() {
    re[re[0] = 1] = Pow(2, mo - 2);
    for (i = 2; i < N; ++i)re[i] = 1ll * re[i - 1] * re[1] % mo;
    cin >> n >> s + 1;
    m = strlen(s + 1);
    for (dp[0][0] = i = dp[1][0] = 1, dp[1][1] = 2; i <= n; ++i)
        for (j = 0; j <= i; ++j) {
            if (j)(dp[i + 1][j - 1] += dp[i][j]) %= mo;
            else (dp[i + 1][j] += dp[i][j]) %= mo;
            (dp[i + 1][j + 1] += 2ll * dp[i][j] % mo) %= mo;
        }
    cout << 1ll * dp[n][m] * re[m] % mo << endl;
}

Measured memory_bytes: 97408
#include "bits/stdc++.h"

using namespace std;

// https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/all/ALDS1_13_A

void Main() {
    int k;
    cin >> k;
    map<int, int> initQueens;
    for (int i = 0; i < k; ++i) {
        int r, c;
        cin >> r >> c;
        initQueens.insert(make_pair(r, c));
    }

    vector<int> perm({ 0, 1, 2, 3, 4, 5, 6, 7 });
    do {
        bool consistent = true;
        for (auto rc : initQueens) {
            if (rc.second != perm[rc.first]) {
                consistent = false;
                break;
            }
        }
        if (!consistent) {
            continue;
        }

        vector<vector<bool>> queens(8, vector<bool>(8, false));
        for (int i = 0; i < 8; ++i) {
            queens[i][perm[i]] = true;
        }

        bool ok = true;
        for (int i = 0; i < 8; ++i) {
            int r = i;
            int c = perm[i];
            for (int j = 1; j < 8; ++j) {
                if (r + j < 8 && c + j < 8) {
                    if (queens[r + j][c + j]) {
                        ok = false;
                        break;
                    }
                }
                if (r + j < 8 && c - j >= 0) {
                    if (queens[r + j][c - j]) {
                        ok = false;
                        break;
                    }
                }
                if (r - j >= 0 && c + j < 8) {
                    if (queens[r - j][c + j]) {
                        ok = false;
                        break;
                    }
                }
                if (r - j >= 0 && c - j >= 0) {
                    if (queens[r - j][c - j]) {
                        ok = false;
                        break;
                    }
                }
            }
        }
        if (ok) {
            for (int i = 0; i < 8; ++i) {
                for (int j = 0; j < 8; ++j) {
                    if (queens[i][j]) {
                        cout << "Q";
                    }
                    else {
                        cout << ".";
                    }
                }
                cout << endl;
            }
            break;
        }
    } while (next_permutation(perm.begin(), perm.end()));
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}



Measured memory_bytes: 3092
#include <stdio.h>

int main(void){
    char s[2000000];
    char t[2000000];
    int times_n=0;
    scanf("%s", s);
    scanf("%s", t);
    for(int i=0; s[i] != '\0'; i++){
        if(s[i] != t[i]){
            times_n++;
        }
    }
    printf("%d\n", times_n);
    return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
 
#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// typedef
typedef std::vector<int> VI;
typedef std::vector<VI> VII;
typedef std::vector<bool> VB;
typedef std::vector<std::string> VS;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

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

void solve() {
  int n, k;
  std::string s;
  std::cin >> n >> k >> s;
  s.at(k - 1) = s.at(k - 1) + 32;
  cout(s);
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, X) = Slice2<long>();
            var lNum = new long[51];
            var pNum = new long[51];
            lNum[0] = 1;//層数
            pNum[0] = 1;//パティの数
            for (var i = 1; i <= N; ++i)
            {
                //B L(i-1) P L(i-1) B
                lNum[i] = 1 + lNum[i - 1] + 1 + lNum[i - 1] + 1;
                pNum[i] = pNum[i - 1] + 1 + pNum[i - 1];
            }
            //L(i)からX枚食べる
            long  fnc(long i, long x)
            {
                if (lNum[i] == x) return pNum[i];
                if (x == 1) return 0;
                if (x <= 1 + lNum[i - 1]) return fnc(i - 1, x - 1);
                if (x == 1 + lNum[i - 1] + 1) return pNum[i - 1] + 1;
                else return pNum[i - 1] + 1 + fnc(i - 1, x - 2 - lNum[i - 1]);
            }
            var nums = fnc(N, X);
            WriteLine(nums);
        }

        static long Mod = (long)1e9 + 7;

        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

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

int main()
{
  int x;
  int ans;

  cin >> x;

  ans = (x / 500) * 1000;
  x %= 500;
  ans += (x / 5) * 5;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vd(T) vector<vector<T>>
#define v(T) vector<T>
#define mod (ll)(1e9+7)
#define pp(T) pair<T,T>
#define pb push_back
#define read1(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define read4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define mp make_pair
#define NN 100005
#define IO ios_base::sync_with_stdio(NULL),cin.tie(0),cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define DEBUG cout<<"***********DEBUGGING***********"<<endl
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; 
ll power(ll a,ll b){ if(b==0) return 1; ll s=power(a,b/2); s*=s;if(b&1) return s*a; return s;}
ll powermod(ll a,ll b,ll m){ if(b==0) return 1; ll s=power(a,b/2);s*=s; s%=m; if(b&1) return (s*a)%m; return s;}
inline int add(ll a,ll b,ll m=0){
    if(m==0) return a+b;
    return (a%m+b%m)%m;
}

inline int sub(ll a,ll b ,ll m=0){
    if(m==0) return a-b;
    return ((a%m-b%m)%m+m)%m;
}

inline int mul(ll a,ll b,ll m=0){
    if(m==0)return (a*b);
    return ((a%m)*(b%m))%m;
}

inline int div(ll a,ll b,ll m=0){
    if(m==0) return a/b;
    return ((a%m)*(powermod(a,b,m-2)%m))%m;
}

bool isopen(char c){
    return ((c=='(')||(c=='{')||(c=='['));
}

ll longest_balanced_parenthesis(string a,ll n){
    stack<char> s;
    ll start=0;
    ll ans=0,m=0;
    for(ll i=0;i<n;i++){
        if(isopen(a[i])){
            s.push(a[i]);
        }
        else{
            if(isopen(a[i])|| s.empty()){
                m=max(m,ans);
                continue;
            }
            else{
                s.pop();
                ans+=2;
                m=max(ans,m);
            }
        }
    }

    return m;

}

ll setup_k(ll *a,ll k){
  ordered_set x;
  // Now , insert and then check number of integers less than k by just using x.order_of_key(k+1)
  return 0;
}

int main() {

    IO; 

    ll a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,(a*b)));
    cout<<endl;

}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

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

func main() {
	n := nextInt()
	k := nextInt()

	h := make([]int, 0, n)
	for i := 0; i < n; i++ {
		h = append(h, nextInt())
	}

	IntReverse(h)

	re := 1000000000
	r := k - 1
	for index := 0; r < n; index++ {
		if h[r]-h[index] < re {
			re = h[r] - h[index]
		}
		// fmt.Printf("%#v %#v\n", index, r)
		r++
	}

	fmt.Println(re)
}

func IntReverse(vv []int) {
	sort.Sort(sort.IntSlice(vv))
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define ll     long long int 
#define pb     push_back
#define umap   unordered_map
#define mod    1000000007
#define all(x) (x).begin(), (x).end()
//__builtin_popcount(x)
//__builtin_parity(x)   =(number of set bits)%2
//__builtin_clz(x)      to count the number of leading  zeroes 
//__builtin_ctz(x)      to count the number of trailing zeroes 
//__gcd(a,b)
using namespace std;
int main()
{
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
int n;cin>>n;
string s;cin>>s;
int nr=0;
int pref[n];
for(int i=0;i<n;i++)
{
  if(i==0)
  {
    if(s[i]=='R'){pref[i]=0;nr++;}
    else         {pref[i]=1;}
  }
  else
  {
    if(s[i]=='R'){pref[i]=pref[i-1];nr++;}
    else         {pref[i]=1+pref[i-1];}
  }
}
nr--;
cout<<pref[nr];
}

Measured memory_bytes: 4512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(void){
    int N; cin >> N;
    vector<ll> a(N);
    for(int i=0; i<N; i++) cin >> a[i];

    sort(a.begin(), a.end(), greater<ll>());

    ll x,y;
    int pos = 0;
    bool flg = false;
    for(int i=1; i<N; i++){
        if(a[i] == a[i-1]){
            x = a[i];
            pos = i+2;
            flg = true;
            break;
        }
    }

    if(!flg){
        cout << 0 << endl;
        return 0;
    }

    for(int i=pos; i<N; i++){
        if(a[i] == a[i-1]){
            y = a[i];
            cout << x*y << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;


const int y_min = -2000, y_max = 2000;
const int x_min = -2000, x_max = 2000;
const double eps = 1e-7;


vector<pair<int, int> > enumerate_lines(int y, vector<pair<int, int> > &pol)
{
	vector<pair<int, int> > ls;
	int n = pol.size();

	for(int l = 0; l < n; ++l) {

		int tx1 = pol[l].first, ty1 = pol[l].second;
		int tx2 = pol[(l + 1) % n].first, ty2 = pol[(l + 1) % n].second;

		int y1 = min(ty1, ty2), y2 = max(ty1, ty2);
		int x1, x2;
		if(y1 == ty1) x1 = tx1, x2 = tx2;
		else x1 = tx2, x2 = tx1;
		int dx = x2 - x1, dy = y2 - y1;
		double r = (double)dx / dy;

		if(y1 >= y + 1 || y2 <= y)
			continue;

		double fcx1 = x1 + r * ((y) - y1);
		double fcx2 = x1 + r * ((y + 1) - y1);

		/*printf("debug: %d %d %d %d\n", x1, y1, x2, y2);
		printf("debug: %f %f\n", fcx1, fcx2);*/
		int cx1 = floor(min(fcx1 + eps, fcx2 + eps));
		int cx2 = floor(max(fcx1 + (1 - eps), fcx2 + (1 - eps)));

		ls.push_back(make_pair(min(cx1, cx2), max(cx1, cx2)));
	}

	return ls;
}


int count_area(vector<pair<int, int> > &ls)
{
	vector<int> imos(x_max - x_min + 1, 0);

	sort(ls.begin(), ls.end());
	for(int i = 0; i < ls.size(); ++i) {
		int a = ls[i].first + -x_min;
		int b = ls[i].second + -x_min;
		if(i % 2 == 0)
			imos[a] += 1;
		else
			imos[b] -= 1;
	}

	int ans = imos[0] > 0;

	for(int i = 1; i < imos.size(); ++i) {
		imos[i] += imos[i - 1];
		ans += imos[i] > 0;
	}

	return ans;
}


int main()
{
	while(true) {

		int n;
		vector<pair<int, int> > pol;

		scanf("%d", &n);
		if(n == 0)
			break;
		pol.resize(n);
		for(int i = 0; i < n; ++i)
			scanf("%d%d", &pol[i].first, &pol[i].second);

		int ans = 0;

		for(int y = y_min; y < y_max; ++y) {
			vector<pair<int, int> > ls = enumerate_lines(y, pol);
			/*if(ls.size() > 0)
				printf("debug: line %d\n", y);
			for(int i = 0; i < ls.size(); ++i)
				printf("debug: %d %d\n", ls[i].first, ls[i].second);*/
			ans += count_area(ls);
		}

		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1052
import java.util.Scanner;


public class Main {

	public static void main(String [] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int[] a = new int[n];
		
		for(int i = 0;i < n;i++) {
			
			a[i] = sc.nextInt();
			
		}
		
		int minInt = 0;
		
		
		for(int j = 0;j < n;j++) {   //最小値を求める工程
			if(j == 0) {
				minInt = a[j];

				
			}else {
				if(a[j] < minInt) {
					minInt = a[j];

					
				}
				
			}
			
		}
		
		int maxInt = 0;

		
		
		for(int k = 0;k < n;k++) {   //最大値を求める工程
			if(k == 0) {
				maxInt = a[k];

				
			}else {
				if(a[k] > maxInt) {
					maxInt = a[k];

					
				}
				
			}
			
		}
		
		long sum = 0;
		
		for(int l = 0;l < n;l++) {
			sum = sum + a[l];
			
		}
		
		System.out.println(minInt + " " + maxInt + " " + sum);
		
				
	}
}


Measured memory_bytes: 41780
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  int key;
  struct node *next,*prev;
};
  struct node *nil;

void set(void){
  nil=(struct node *)malloc(sizeof(struct node));
  nil->next =nil;
  nil->prev =nil;
}

void insert(int key){
  struct node *x;
  x=(struct node *)malloc(sizeof(struct node));
  x->key=key;
  x->next=nil->next;
  nil->next->prev=x;
  x->prev=nil;
  nil->next=x;
    }

struct node*  finditem(int key){
  struct node *n=nil->next;

  while(n!=nil&&n->key!=key){
    n=n->next;
  }
  return n;
  }

void deletenode(struct node *t){
    if(t==nil) return;
    t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
    }

void print(){
  struct node *n;
  int i=0;

  for(n=nil->next;n!=nil;n=n->next){
    if(i++!=0) printf(" ");
    printf("%d",n->key);
  }
  printf("\n");
}

int main(){
  int n,key,i;
  char c[20];

  scanf("%d",&n);
  set();
  for(i=0;i<n;i++){
    scanf("%s",c);
    if(c[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }
    else if(c[0]=='d'&&strlen(c)>6){
      if(c[6]=='F') deletenode(nil->next);
      else if(c[6]=='L')deletenode(nil->prev);
    }
    else{
      scanf("%d",&key);
      deletenode(finditem(key));
    }
  }

  print();

  return;
}


Measured memory_bytes: 32984
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s,ss;
	int sum=0,i;
	cin>>s;
	for(i=0;i<=s.length()-1;i++){
		if(s[i]=='C'&&sum==0)sum++;
		if(s[i]=='F'&&sum==1)sum++;
	}
	if(sum==2)cout<<"Yes";
	else cout<<"No";
}

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

const int N = 200005;
const int INF = 1000000000;

int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {if (ch == '-') f = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}

int n,a[N],rmq[2][N][20],bin[20],lg[N];

struct Data
{
    int l,r,x,y;

    bool operator < (const Data &p) const
    {
        return a[x] > a[p.x];
    }
};

std::priority_queue<Data> Q;

void pre()
{
    for (int i = 1; i <= n; i += 2) 
        rmq[1][i][0] = i;
    for (int i = 2; i <= n; i += 2) 
        rmq[0][i][0] = i;
    bin[0] = 1;
    for (int i = 1; i <= 17; i++) 
        bin[i] = bin[i - 1] * 2;
    for (int i = 1; i <= n; i++) 
        lg[i] = log(i) / log(2);
    for (int j = 1; j <= lg[n]; j++)
        for (int i = 1; i + bin[j] - 1 <= n; i++)
            rmq[0][i][j] = a[rmq[0][i][j - 1]] < a[rmq[0][i + bin[j - 1]][j - 1]] ? rmq[0][i][j - 1] : rmq[0][i + bin[j - 1]][j - 1],
            rmq[1][i][j] = a[rmq[1][i][j - 1]] < a[rmq[1][i + bin[j - 1]][j - 1]] ? rmq[1][i][j - 1] : rmq[1][i + bin[j - 1]][j - 1];
}

int getMn(int ty,int l,int r)
{
    int w = lg[r - l + 1];
    return a[rmq[ty][l][w]] < a[rmq[ty][r - bin[w] + 1][w]] ? rmq[ty][l][w] : rmq[ty][r - bin[w] + 1][w];
}

Data get(int l,int r)
{
    int p = getMn(l & 1, l, r - 1), q = getMn((p & 1) ^ 1, p + 1, r);
    return (Data){l,r,p,q};
}

int main()
{
    n = read();
    a[0] = INF;
    for (int i = 1; i <= n; i++) 
        a[i] = read();
    pre();
    Q.push(get(1,n));
    for (int i = 1; i <= n / 2; i++)
    {
        Data u = Q.top();
        Q.pop();
        int l = u.l, r = u.r, x = u.x, y = u.y;
        printf("%d %d ",a[x],a[y]);
        if (l < x - 1) 
            Q.push(get(l,x - 1));
        if (x + 1 < y - 1) 
            Q.push(get(x + 1, y - 1));
        if (y + 1 < r) 
            Q.push(get(y + 1, r));
    }
}

Measured memory_bytes: 35060
# -*- coding: utf-8 -*-
s = list(input())
n = len(s)

l = []
for i in range(n):
    if s[i]=="B":
        l.append(i)

l.sort(reverse=True)

res = 0
cnt = 0
for idx in l:
    res += n-idx-1 - cnt
    cnt += 1

print(res)


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

using ll = long long;
const int mod = 1000000007;


int main()
{
    ll n, res = 0;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n + 1, 0);

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

    for(int i = 0; i < n - 1; ++i)
    {
        res += a[i] * ((b[n] - b[i + 1]) % mod); 
        res %= mod;
    }    

    cout << res << "\n";
    return 0;
}


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

int main(){
	int n,x;
	cin >> n >> x;
	//まず,最小値と最大値は選ばれない.
	if(x == 1 || x == 2 * n - 1){
		cout << "No" << endl;
		return 0;
	}

	//それ以外なら,連続して2つ選ばれる構築をすることでずっと上に持ち上げられる.

	vector<int> ans(2 * n - 1, 0);
	vector<bool> used(2 * n);

	ans[(2 * n - 2) / 2] = x, used[x] = true;
	ans[(2 * n - 2) / 2 + 1] = x + 1, used[x + 1] = true;
	ans[(2 * n - 2) / 2 - 1] = x - 1, used[x - 1] = true;

	if(x + 2 <= n){
		ans[(2 * n - 2) / 2 - 2] = x + 2, used[x + 2] = true;
	}
	else if(x - 2 >= 1){
		ans[(2 * n - 2) / 2 + 2] = x - 2, used[x - 2] = true;
	}

	int now = 1;
	for(int i = 0;i < 2 * n - 1;i++){
		if(ans[i] == 0){
			while(used[now])now++;
			ans[i] = now;
			used[now] = true;
		}
	}

	cout << "Yes" << endl;
	for(int i = 0;i < 2 * n - 1;i++){
		cout << ans[i] << endl;
	}
}


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

int main()
{
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 105, c = 0; i <= n; i += 2, c = 0)
  {
    for (int k = 1; k <= i; k += 2)
    {
      if (i % k == 0) c++;
    }
    if (c == 8) ++ans;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256