akhauriyash/Code-Regression huggingface dataset:
def merge(A, n, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = new_list("X", SENTINEL)
    R[n2] = new_list("X", SENTINEL)
    i = 0
    j = 0
    for k in range(left, right):
        if L[i].value <= R[j].value:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1


def mergeSort(A, n, left, right):
    if left+1 < right:
        mid = (left+right)//2
        mergeSort(A, n, left, mid)
        mergeSort(A, n, mid, right)
        merge(A, n, left, mid, right)


def partition(p, r):
    x = B[r].value
    i = p - 1  # <xの右端
    for j in range(p, r):
        if B[j].value <= x:
            i += 1
            B_tmp = B[i]
            B[i] = B[j]
            B[j] = B_tmp
    t = B[i+1]
    B[i+1] = B[r]
    B[r] = t
    return i+1


def quickSort(B, n, p, r):
    if p < r:
        q = partition(p, r)
        quickSort(B, n, p, q-1)
        quickSort(B, n, q+1, r)


class new_list:
    def __init__(self, a1, a2):
        self.suit = a1
        self.value = a2


n = int(input())
S_tmp = [input().split() for i in range(n)]
# for i in range(n):
#     print(S_tmp[i])
A = []
B = []
for i in range(n):
    A.append(new_list(S_tmp[i][0], int(S_tmp[i][1])))
    B.append(new_list(S_tmp[i][0], int(S_tmp[i][1])))

# for i in range(n):
#     print(i, A[i].suit, A[i].value)

L = [''] * (n//2+2)
R = [''] * (n//2+2)
SENTINEL = 2000000000
mergeSort(A, n, 0, n)
quickSort(B, n, 0, n-1)

for i in range(n):
    if A[i].suit != B[i].suit:
        break
if i == n-1:
    print("Stable")
else:
    print("Not stable")
for i in range(n):
    print(B[i].suit, B[i].value)



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

int func(int tmp[], int n){
  int i,j,k;
  int perm=1;
  int locate=1;
  int num;
  num = n;
  int array[105];
  for(i=0;i<100;i++){
      array[i]=1;
  }
  for(i=1;i<=n;i++){
      perm = perm*i;
  }

  for(i=0;i<n;i++){
      k=0;
      for(j=0;j<n;j++){
          if(tmp[j]<tmp[i] && array[tmp[j]-1]){
            k++;
          }
      }
      array[tmp[i]-1]=0;
      perm = perm / num;
      locate += perm*k;
      num--;
  }
  return locate;
}

int main(){
  int n,i;
  cin >> n;
  int p[n+3];
  int q[n+3];
  for(i=0;i<n;i++) cin >> p[i];
  for(i=0;i<n;i++) cin >> q[i];
  int a,b;
  a = func(p,n);
  b = func(q,n);
 //cout << a << " "<< b;
  cout << abs(a-b);
  
  return 0;
}

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

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

fn read_vec_i32() -> Vec<i32> {
    let mut l = String::new();
    std::io::stdin().read_line(&mut l).unwrap();
    l.trim()
        .split(' ')
        .map(|str| i32::from_str(str).unwrap())
        .collect()
}

fn main() {
    let n: i32 = read();
    let y: i32 = read();
    let mut ans = None;
    for i in 0..n + 1 {
        for j in 0..n - i + 1 {
            let k = n - i - j;
            if i * 10000 + j * 5000 + k * 1000 == y {
                ans = Some((i, j, k));
            }
        }
    }
    let (x, y, z) = ans.unwrap_or((-1, -1, -1));
    println!("{} {} {}", x, y, z);
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin>>n;
  vll a(n);
  REP(i,n)cin>>a[i];

  sort(ALL(a),greater<ll>());
  ll ans=0;

  if(n==1)
    ;
  else if(n==2)
    ans=a[0];
  else{
    ll cnt=n;
    cnt-=2;
    ans=a[0];
    REP(i,cnt){
      ans+=a[i/2+1];
    }
  }

  cout<<ans<<endl;
}



Measured memory_bytes: 4764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)
int main(){
    int n,a,b;
    string s;
    cin >> n >> a;
    if (n%a) cout << n/a+1 << endl;
   else cout << n/a << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		char[] op = new char[n];
		op[0] = '+';
		for (int i = 0; i < n; ++i) {
			if (i != 0)
				op[i] = sc.next().charAt(0);
			a[i] = sc.nextLong();
		}

		long[][] dp = new long[n][3];
		for (int i = 0; i < dp.length; ++i) {
			for (int j = 0; j < dp[i].length; ++j) {
				dp[i][j] = -Long.MAX_VALUE / 10;
			}
		}

		for (int i = 0; i < n; ++i) {
			if (i == 0) {
				dp[0][0] = a[0];
			} else {
				for (int pre = 0; pre <= 2; ++pre) {
					for (int next = op[i] == '-' ? 1 : 0; next <= pre + (op[i] == '-' ? 1 : 0); ++next) {
						if (next <= 2) {
							dp[i][next] = Math.max(dp[i][next], dp[i - 1][pre] + a[i] * (int) Math.pow(-1, next));
						}
					}
				}
			}
		}

		long ans = -Long.MAX_VALUE / 10;
		for (int i = 0; i <= 2; ++i) {
			ans = Math.max(ans, dp[n - 1][i]);
		}
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

int main()
{
    unsigned long long H, W;
    cin >> H >> W;
    if (H == 1 || W == 1)
    {
        cout << 1 << endl;
        return 0;
    }
    unsigned long long ans = (W % 2 == 0 ? W : W - 1) / 2 * (H % 2 == 0 ? H : H - 1) / 2 + (W % 2 == 0 ? W : W + 1) / 2 * (H % 2 == 0 ? H : H + 1) / 2;
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;



static class AT {
    static int N;
    static int[] A;
    static void Main() {
        N = int.Parse(Console.ReadLine());
        A = new int[N];
       int []B= new int[N];
        Dictionary<int, int> d = new Dictionary<int, int>();
        for (int i = 0; i < N; i++) {
         int j=int.Parse(Console.ReadLine());
            A[i] = j;
            B[i] = j;
            d.Add(j, i);
        }
        int c = 0;
        Array.Sort(B);
        for(int i = 0; i < N; i++) {
         if(d[B[i]] % 2 != i % 2) {
                c++;
            }
        }
        Console.WriteLine(c/2);
    }
}


Measured memory_bytes: 12760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=s;i<t;i++)
typedef long long ll;
#define MAXNUM 111111
ll num[MAXNUM],sum[MAXNUM],m;
int n;
ll check(ll x)
{
    ll res=0;
    rep(i,1,n+1)
    {
        ll k=lower_bound(num+1,num+n+1,x-num[i])-num;
        res+=n-k+1;
    }
    return res;
}
int main()
{
    scanf("%d%lld",&n,&m);
    rep(i,1,n+1)scanf("%lld",&num[i]);
    sort(num+1,num+n+1);
    rep(i,1,n+1)sum[i]=sum[i-1]+num[i];
    ll l=num[1]*2,r=num[n]*2,res=0;
    while(l<=r)
    {
        ll mid=(l+r)/2;
        if(check(mid)>=m)res=mid,l=mid+1;
        else r=mid-1;
    }
    ll nowr=0,rres=0;
    rep(i,1,n+1)
    {
        ll k=upper_bound(num+1,num+n+1,res-num[i])-num;
        nowr+=n-k+1,rres+=sum[n]-sum[k-1]+(n-k+1)*num[i];
    }
    rres+=(m-nowr)*res;
    printf("%lld\n",rres);
}


Measured memory_bytes: 1792
package main

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

func main() {
	var n int
	fmt.Scan(&n)

	rdr := NewReader()

	happiness := make([][]int, n)
	for i := range happiness {
		happiness[i] = rdr.Ints()
	}

	m := make([][]int, n)
	for i := range m {
		m[i] = make([]int, 3)
	}
	m[0][0] = happiness[0][0]
	m[0][1] = happiness[0][1]
	m[0][2] = happiness[0][2]

	for i := range happiness[1:] {
		m[i+1][0] = Max(m[i][1], m[i][2]) + happiness[i+1][0]
		m[i+1][1] = Max(m[i][0], m[i][2]) + happiness[i+1][1]
		m[i+1][2] = Max(m[i][0], m[i][1]) + happiness[i+1][2]
	}

	fmt.Println(MaxInts(m[n-1]...))
}

// generated by https://github.com/murosan/gollect

func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func MaxInts(n ...int) int {
	max := n[0]
	for _, v := range n[1:] {
		if v > max {
			max = v
		}
	}
	return max
}

type Reader struct {
	r    *bufio.Reader
	size int
	sep  string
}

func NewReader() *Reader {
	size := 4096
	return &Reader{
		r:    bufio.NewReaderSize(os.Stdin, size),
		size: size,
		sep:  " ",
	}
}

func (rdr *Reader) Bytes() []byte {
	buf := make([]byte, 0, rdr.size)
	for {
		line, isPrefix, err := rdr.r.ReadLine()
		if err != nil {
			panic(err)
		}
		buf = append(buf, line...)
		if !isPrefix {
			break
		}
	}
	return buf
}

func (rdr *Reader) BytesSlice() [][]byte {
	return bytes.Split(rdr.Bytes(), []byte(rdr.sep))
}

func (rdr *Reader) Ints() []int {
	a := rdr.BytesSlice()
	b := make([]int, len(a))
	for i, v := range a {
		b[i] = BytesToInt(v)
	}
	return b
}

func BytesToInt(b []byte) (n int) {
	var i int
	negative := b[0] == 45
	if negative {
		i++
	}
	for ; i < len(b); i++ {
		n = n*10 + int(b[i]-'0')
	}
	if negative {
		return -n
	}
	return
}


Measured memory_bytes: 14976
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;







public class Main{
	public static int n;
	public static boolean[] vis;
	public static int[] nums;
	public static void main(String[] args) throws IOException, InterruptedException {
		
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] a = new int[n][d];
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				a[i][j] = sc.nextInt(); 
			}
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				int sum= 0;
				for (int j2 = 0; j2 < d; j2++) {
					sum+= (a[j][j2]-a[i][j2])*(a[j][j2]-a[i][j2]);
				}
				if (Math.sqrt(sum) == Math.ceil(Math.sqrt(sum))) {
					ans++;
				}
			}
		}
		out.println(ans);
		out.flush();

	}


	
	

	
}
class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream system) {
		br = new BufferedReader(new InputStreamReader(system));
	}

	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public String nextLine() throws IOException {
		return br.readLine();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public char nextChar() throws IOException {
		return next().charAt(0);
	}

	public Long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	public boolean ready() throws IOException {
		return br.ready();
	}

	public void waitForInput() throws InterruptedException {
		Thread.sleep(3000);
	}


}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

struct UnionFind
{
  vector<int> par;   // par[i]が親を表す
  vector<int> _size; // _size[i]でそのノードの属しているサイズを返す

  // コンストラクタ
  UnionFind(int n)
  {
    _size = vector<int>(n);
    par = vector<int>(n);
    for (int i = 0; i < n; i++)
    {
      par[i] = i;
      _size[i] = 1;
    }
  }

  // データxの根を求める
  int root(int x)
  {
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]); // 木構造の縮約を行っている
  }

  // xとyの親が違うとき、マージする。そのときyの根がxの根の子になる
  void merge(int x, int y)
  {
    int rootx = root(x);
    int rooty = root(y);
    if (rootx == rooty)
      return;
    par[rooty] = rootx;
    int s = _size[rooty] + _size[rootx];
    _size[rooty] = s;
    _size[rootx] = s;
  }

  // xの属している集団のサイズ
  int size(int x)
  {
    return _size[x];
  }

  // 同じグループに属しているか
  bool isSame(int x, int y)
  {
    return root(x) == root(y);
  }
};

int main()
{
  int n, m;
  cin >> n >> m;
  UnionFind uf = UnionFind(n);

  REP(i, m)
  {
    int x, y, z;
    cin >> x >> y >> z;
    uf.merge(x - 1, y - 1);
  }

  list<int> s;

  REP(i, n)
  {
    s.push_back(uf.root(i));
  }

  s.sort();
  s.unique();
  cout << s.size() << endl;
}


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

int main(){
    Int t,u; cin >> t >> u;
    Int a,b,c,d; cin >> a >> b >> c >> d;
    if(a * t + b  * u == c * t + d * u) return puts("infinity") * 0;
    
    if(a >= c and b >= d){
        // A is faster than B
        return puts("0") * 0;
    }
    if(c >= a and d >= b){
        // B is fastar than A
        return puts("0") * 0;
    }
    if(a >= c and b < d){
        Int dift = a - c;
        Int difu = d - b;
        // if (t > u)
        if(dift * t > difu * u) {
            return puts("0") * 0;
        } else {
            Int ddif = difu * u - dift * t;
            Int div = a * t - c * t;
            Int mod = div % ddif;
            Int pre = (Int)((((long double)div / ddif)));
            cout << pre + pre  + (mod == 0 ? 0 : +1 ) << endl;
            return 0;
        }
    }
    if(c >= a and b  >= d){
        Int dift = c - a;
        Int difu = b - d;
        // if (t > u)
        if(dift * t > difu * u) {
            return puts("0") * 0;
        } else {
            Int ddif = difu * u - dift * t;
            Int div = c * t - a * t;
            Int mod = div % ddif;
            Int pre = (Int)((((long double)div / ddif)));
            cout << pre + pre + (mod == 0 ? 0 : 1) << endl;
            return 0;
        }
    }
    assert(false);
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.TreeMap;

import static java.lang.System.exit;

public class Main
{
  
  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String s = r.readLine();
    String[] sl = s.split("[\\s]+");
    int n = Integer.parseInt(sl[0]);
    int k = Integer.parseInt(sl[1]);
  
    if (k == 0)
    {
      long ln = n;
      System.out.println(ln * ln);
      System.exit(0);
    }
    
    long ans = 0;
    for(int b = k + 1; b <= n; b++)
    {
      int t = n / b;
      ans += t * (b - k);
      int z = n - t * b - k + 1;
      if (z > 0)
      {
        ans += z;
      }
    }
    System.out.println(ans);
  }
    
}


Measured memory_bytes: 21332
#include<iostream>
using namespace std;
int main(){
    int n,x;
    while(1){
        int count=0;
        cin>>n>>x;
        if(n==0 && x==0)    break;
        for(int i=1; i<=n-2; i++){
            for(int j=i+1; j<=n-1; j++){
                for(int k=j+1; k<=n; k++){
                    if(i+j+k==x)    count++;
                }
            }
        }
        cout<<count<<endl;
    }
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
   int r;cin>>r;
   if (r<1200)
   {
      /* code */
      cout<<"ABC"<<endl;
   }
   else if (r<2800)
   {
      /* code */
      cout<<"ARC"<<endl;
   }
   else
   {
      cout<<"AGC"<<endl;
   }
   
   
   
   }
   


Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
//#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define reps(i, j, k) for(auto i = j; i < k; ++i)
#define rep(i, j) reps(i, 0, j)
#define decs(i, j, k) for(auto i = j; i >= k; --i)
#define dec(i, j) decs(i, j, 0)
#define iter(i, j) for(auto i = j.begin(); i != j.end(); ++i)
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int, int>
#define vpi vector<pi>
#define vb vector<bool>
#define F first
#define S second
#define mp make_pair
#define um unordered_map
#define all(x) (x).begin(), (x).end()  
#define fast_io ios::sync_with_stdio(0); cin.tie(0);
#define file_io freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define IMAX std::numeric_limits<int>::max()
#define IMIN std::numeric_limits<int>::min()
using namespace std;

int main()
{
    //fast_io
    //file_io
	string s; cin >> s;
	int q, t, f; 
	char c;
	cin >> q;
	list<char> l;
	rep(i, s.length())
		l.push_back(s[i]);
	int state = 0; // 0 - normal, 1 - reversed
	while(q--)
	{
		cin >> t;
		if(t == 1)
			state = (state + 1) % 2;
		else
		{
			cin >> f >> c;
			if(f == 1)
			{
				if(state == 0)
					l.push_front(c);
				else 
					l.push_back(c);
			}
			else
			{
				if(state == 0)
					l.push_back(c);
				else 
					l.push_front(c);
			}
		}
	}
	string ans = "";
	if(state == 0)
		for(char cval : l) ans += cval;
	else
		for(auto it = l.rbegin(); it != l.rend(); ++it) ans += *it;
	cout << ans;
	return 0;
}


Measured memory_bytes: 10372
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1){
            res *= a; if(mod>=1) res %= mod;
        }
        a *= a; if(mod>=1) a %= mod;
        n >>= 1;
    }
    return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  ll dp[LIMIT1]={0};
  
  scanf("%lld %lld",&n,&m);
  rep(i,m) scanf("%d",&a[i]);
  
  dp[0]=1;
  j=0;
  rep(i,n){
    if(j<m && i+1==a[j]){
      dp[i+1]=0;
      j++;
      continue;
    }
    dp[i+1] = dp[i]+((i>=1) ? (dp[i-1]) : 0);
    dp[i+1] %= MOD1;
  }
  printf("%lld\n",dp[n]);
  return 0;
}



Measured memory_bytes: 3712
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
void func(int,int);
int n,m,a[9][8],cnt[9],sum,flg[9];
int main(void)
{
	int i,j,x,y;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++)	cnt[i]=0;
	for(i=0;i<m;i++)	{
		scanf("%d %d",&x,&y);
		a[x][cnt[x]]=y;
		cnt[x]++;
		a[y][cnt[y]]=x;
		cnt[y]++;
	}
	sum=0;
	for(i=1;i<=n;i++)	flg[i]=0;
	flg[1]=1;
	func(1,1);
	printf("%d\n",sum);
	return 0;
}
void func(int xx,int nn)
{
	int i,x2;
//	printf("xx=%d nn=%d\n",xx,nn);
	if(nn==n)	{
		sum++;
	}
	else {
		for(i=0;i<cnt[xx];i++)	{
			x2=a[xx][i];
			if(flg[x2]==0)	{
				flg[x2]=1;
				func(x2,nn+1);
				flg[x2]=0;
			}
		}
	}
}

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

using namespace std;


int main()
{
  map< pair< string, string >, int > cnt;
  int N, F;

  cin >> N >> F;
  for(int i = 0; i < N; i++) {
    int M;
    cin >> M;
    vector< string > QQ(M);
    for(int j = 0; j < M; j++) cin >> QQ[j];
    for(int j = 0; j < M; j++) {
      for(int k = 0; k < j; k++) cnt[minmax(QQ[j], QQ[k])]++;
    }
  }

  int ret = 0;
  for(auto &s : cnt) ret += s.second >= F;
  cout << ret << endl;
  for(auto &s : cnt) if(s.second >= F) cout << s.first.first << " " << s.first.second << endl;
}

Measured memory_bytes: 3440
//package Atcoder;
import java.util.*;
import java.io.*;
public class Main
{
	static final int mod=(int)1e9+7;
	static final int inf=(int)1e9;
	static final long INF=(long)1e18;
	public static void main(String[] args)
	{
		FastScanner fs=new FastScanner();
		int n=fs.nextInt();
		while(n>0)
		{
			if(n%10==7)
			{
				System.out.println("Yes");
				return;
			}
			n/=10;
		}
		System.out.println("No");
		
	}
}
class FastScanner 
{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		public String next() 
		{
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
			
		}
		
		long pow(long x,long n)
		{
			long res=1;
			while(n>0)
			{
			   	if(n%2!=0)
			   	{
			   		res=(res*x);n--;
			   	}
			   	else
			   	{
			   		x=(x*x);n/=2;
			   	}
			}
			return res;
		}
		int gcd(int a,int b)
		{
			if(b==0)
			{
				return a;
			}
			return gcd(b,a%b);
		}
		long longgcd(long a,long b)
		{
			if(b==0)
			{
				return a;
			}
			return longgcd(b,a%b);
		}
		int[] sort(int arr[])
		{
			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		char[] charsort(char arr[])
	        {
	    	ArrayList<Character> list = new ArrayList<>();
	    	for(char c:arr)list.add(c);
	    	Collections.sort(list);
	    	for(int i=0;i<list.size();i++)
	    	{
	    		arr[i]=list.get(i);
	    	}
	    	return arr;
	        }
		long[] longsort(long arr[])
		{
			ArrayList<Long> list = new ArrayList<Long>();
			for(long i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		public int nextInt() 
		{
			return Integer.parseInt(next());
		}
		public int[] readArray(int n)
		{
			int[] arr=new int[n];
			for (int i=0; i<n; i++) arr[i]=nextInt();
			return arr;
		}	
		public long nextLong()
		{
			return Long.parseLong(next());
		}
		public long[] longreadArray(int n) 
		{
			long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextLong();
			return a;
		}
}

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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;





int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    
    int H, W, h , w;
    cin >> H >> W >> h >> w;


    cout << (H-h)*(W-w) << "\n";

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
using namespace std;
#define int long long
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}
#define maxn 100005
int n,m;
struct edge{
	int to,nxt;
}e[maxn<<1];
int tot,head[maxn];
inline void adde(int u,int v){
	e[++tot]=(edge){v,head[u]};
	head[u]=tot;
}

int s,t,k;
int fa[maxn],d[maxn],dis[maxn],cnt;
int dep[maxn],mx[maxn],top[maxn],sz[maxn];
bool vis[maxn];
void dfs(int u,int pa)
{
	fa[u]=pa;
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;
		if(v==pa)continue;
		dis[v]=dis[u]+1;
		dfs(v,u);
	}
}
void dfs2(int u,int p,int pa)
{
	mx[p]=max(mx[p],dep[u]);
	top[u]=p,sz[p]++;
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;
		if(v==pa||vis[v])continue;
		dep[v]=dep[u]+1;
		dfs2(v,p,u);
	}
}
void find()
{
	s=t=1,dis[1]=0;dfs(1,0);
	For(i,1,n)if(dis[i]>dis[t])t=i;
	dis[t]=fa[t]=0;dfs(t,0);
	For(i,1,n)if(dis[i]>dis[s])s=i;
	int u=s;cnt=0;
	while(fa[u])d[++cnt]=u,vis[u]=1,u=fa[u];
	d[++cnt]=t;vis[t]=1;
}
int p1[maxn],p2[maxn];
void print(int *a){
	For(i,1,n)cout<<a[i]<<' ';
	exit(0);
}
signed main()
{
	n=read();
	For(i,2,n){
		int u=read(),v=read();
		adde(u,v);adde(v,u);
	}
	find();
	For(i,1,cnt){
		dfs2(d[i],i,0);
		if(mx[i]>1){puts("-1");return 0;}
	}
	int c=0;
	For(i,1,cnt)
	{
		p1[c+sz[i]]=c+1;
		For(j,1,sz[i]-1)p1[c+j]=c+j+1;
		c+=sz[i];
	}
	c=0;
	Rep(i,cnt,1)
	{
		p2[c+sz[i]]=c+1;
		For(j,1,sz[i]-1)p2[c+j]=c+j+1;
		c+=sz[i];
	}
	For(i,1,n)
		if(p1[i]<p2[i])print(p1);
		else if(p1[i]>p2[i])print(p2);
	print(p1);
    return 0;
}

Measured memory_bytes: 14976
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    int N,K,Q;
    cin>>N>>K>>Q;
    vector<int> point(N,K-Q);
    REP(i,Q){
        int a;cin>>a;
        point[a-1]++;
    }
    REP(i,N)cout<<(point[i]>0?"Yes":"No")<<endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
using namespace std;
#define INF (1<<27)
int cost[100][100];
int main() {
	int n,k;
	while(scanf("%d %d",&n,&k),n) {
		fill((int*)cost,(int*)(cost+100),INF);
		for(int i=0;i<k;i++) {
			int a,b,c;
			scanf("%d",&a);
			if(a==0) {
				scanf("%d %d",&a,&b);
				if(cost[a-1][b-1]==INF)
					printf("-1\n");
				else
					printf("%d\n",cost[a-1][b-1]);
			}else {
				scanf("%d %d %d",&a,&b,&c);
				if(cost[a-1][b-1]>c) {
					cost[a-1][b-1]=cost[b-1][a-1]=c;
					for(int k=0;k<n;k++) {
						for(int i=0;i<n;i++) {
							for(int j=0;j<n;j++) {
								cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
							}
						}
					}
				}
			}
		}
	}
}

Measured memory_bytes: 1076
(* Vicfred
 * https://atcoder.jp/contests/abc137/tasks/abc137_b
 * implementation
 * *)

let rec solve i n =
    if i > n then Printf.printf "\n" else
        (Printf.printf "%d " i; solve (i+1) n);;

Scanf.scanf "%d %d" @@ fun k x ->
    solve (x - k + 1) (x + k - 1);;



Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define SP << " " <<
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

#define int long long

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  int x = A[0];
  FOR(i, 1, N) {
    if(i % 2 == 0) {
      x -= A[i];
    } else {
      x += A[i];
    }
  }
  x /= 2;
  vector<int> b(N);
  b[0] = A[0] - x;
  for(int i = 0; i < N - 1; i++) {
    b[i + 1] = A[i] - b[i];
  }
  REP(i, N - 1) { cout << b[i] * 2 << ' '; }
  cout << b[N - 1] * 2 << endl;
  return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; } 
template<class T> void chmax(T &t, T f) { if (t < f) t = f; } 

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())


LL a, b;
string s;

void init() {
}

void input() {
	cin >> a >> s >> b;
}

void solve() {
	if (s == "+") cout << a+b << endl;
	else cout << a-b << endl;
}

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








Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n,x;cin>>n>>x;
  int m[100];
  REP(i,n)cin>>m[i];
  sort(m,m+n);
  int sum=0;
  REP(i,n){
    sum+=m[i];
  }
  x-=sum;
  P(x/m[0] + n);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main()
{
    int s;
    vector<int> a(1000010);

    cin >> s;

    a[0] = s;

    for (int i = 1; i < 1000010; i++) {
        if (a[i-1] % 2 == 0) {
            a[i] = a[i-1]/2;
        }
        else {
            a[i] = (a[i-1]*3)+1;
        }
    }

    for (int i = 0; i < 1000010; i++) {
        auto ite = find(a.begin()+i+1, a.end(), a[i]);
        if (ite != a.end()) {
            cout << distance(a.begin(), ite)+1 << endl;
            return (0);
        }
    }
}


Measured memory_bytes: 4096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    for(int i=0;i<s.size();i++){
        if(s==t){
            cout << "Yes" << endl;
            return 0;
        }
        s = s[s.size()-1] + s.substr(0,s.size()-1);
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

A = int(input())
B = int(input())
C = int(input())
X = int(input())

counter = 0
for a in range(A+1):
    X_a = X-a*500
    if X_a == 0:
        counter+=1
        continue
    for b in range(B+1):
        X_b = X_a - b*100
        if X_b == 0:
            counter+=1
            continue
        for c in range(C+1):
            X_c = X_b - c*50
            if X_c == 0:
                counter+=1
                continue
print(counter)


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

using namespace std;

int main()
{
int H,W;
cin >> H >> W;
while(H!=0&&W!=0)
{
for (int i=0;i<H;i++)
{
for (int j=0;j<W;j++)
{
if((i%2+j%2)%2==0)cout << "#";
else cout << ".";
}
cout << endl;
}
cout << endl;
cin >> H >> W;
}
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 310;
char s[SIZE][SIZE];
int dp[SIZE][SIZE],v[SIZE][SIZE];
void mii(int &x,int v){
    if(x>v||x==-1)x=v;
}
int solve(vector<char>s1,vector<char>s2){
    MS1(dp);
    MS0(v);
    int H=SZ(s1);
    dp[0][0]=0;
    REPP(i,1,H+1)
        REPP(j,1,H+1){
            v[i][j]=v[i-1][j-1]+(s1[i-1]==s2[j-1]);
            //REP(k,min(i,j))v[i][j]+=(s1[i-1-k]==s2[j-1-k]);
        }
    REP(i,H+1)REP(j,H+1){
        mii(dp[i+1][j],dp[i][j]+v[i+1][j]);
        mii(dp[i][j+1],dp[i][j]+v[i][j+1]);
    }
    return dp[H][H];
}
int main(){
    DRII(H,W);
    REP(i,H)RS(s[i]);
    int an=0;
    REPP(i,1,W){
        vector<char>s1,s2;
        REP(j,H)s1.PB(s[j][i-1]);
        REP(j,H)s2.PB(s[j][i]);
        an+=solve(s1,s2);
    }
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 1152
lis = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","None"]
n = list(input())
k = 0
while 1:
  if lis[k] not in n:
    print(lis[k])
    break
  k += 1

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m,i,j,sum;
  int t[100],p[100],x[100];
  cin>>n;
  for(i=0;i<n;++i){
    cin>>t[i];
  }
  cin>>m;
  for(i=0;i<m;++i){
    cin>>p[i]>>x[i];
  }
  for(i=0;i<m;++i){
    sum=0;
    for(j=0;j<n;++j){
      if(j==p[i]-1) sum+=x[i];
      else sum+=t[j];
    }
    cout<<sum<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>

using namespace std;

long compute(vector<array<long, 3>> data, int m, bool max_x, bool max_y, bool max_z)
{
    auto sum = [&](const array<long, 3> &d) {
                   return
                       (d[0] * (max_x ? 1 : -1)) +
                       (d[1] * (max_y ? 1 : -1)) +
                       (d[2] * (max_z ? 1 : -1));
               };
    sort(data.begin(), data.end(),
         [&](const array<long, 3> &d1, const array<long, 3> &d2) { return sum(d1) > sum(d2); });

    long out(0);
    for (int i = 0; i < m; ++i)
        out += sum(data[i]);

    return out;
}


int main()
{
    int n, m;
    cin >> n >> m;
    
    vector<array<long, 3>> data(n);
    for (int i = 0; i < n; ++i)
    {
        auto &d = data[i];
        cin >> d[0] >> d[1] >> d[2];
    }

    long out(0);
    for (auto max_x : { true, false })
    {
        for (auto max_y : { true, false })
        {
            for (auto max_z : { true, false })
            {
                auto v = compute(data, m, max_x, max_y, max_z);
                out = max(v, out);
            }
        }
    }
    
    cout << out << endl;
}


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


int main(){
    ll X, Y; cin >> X >> Y;
    ll res = 0;
    while(X <= Y){
        X *= 2;
        ++res;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main()
{
	int i, n, a[200001];
	scanf("%d", &n);
	for (i = 1; i <= n; i++) scanf("%d", &(a[i]));

	if (n % 2 == 0) {
		for (i = 0; i < n / 2; i++) printf("%d ", a[n - i * 2]);
		for (i = 0; i < n / 2; i++) printf("%d ", a[i * 2 + 1]);
	} else {
		for (i = 0; i <= n / 2; i++) printf("%d ", a[n - i * 2]);
		for (i = 0; i < n / 2; i++) printf("%d ", a[i * 2 + 2]);
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin>>n;
  vector<int> a(n);
  set<int> st;
  for(int i=0;i<n;i++){
    cin>>a[i];
    st.insert(a[i]);
  }
  sort(a.begin(),a.end());
  vector<int> vec;
  for(auto &e:st){
    auto l=lower_bound(a.begin(),a.end(),e);
    auto u=upper_bound(a.begin(),a.end(),e);
    if(u-l>=2){
      vec.push_back(e);
    }
    if(u-l>=4){
      vec.push_back(e);
    }
  }
  if(vec.size()<2) {
    cout<<0;
    return 0;
  }
  sort(vec.begin(),vec.end(),greater<int>());
  cout<<(ll)vec[0]*vec[1];
}

Measured memory_bytes: 5376
#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##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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;
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    int N; cin >> N;
    vector<string> S(N);
    REP(i,N) cin >> S[i];

    ll ans=0;
    int BA=0, B=0, A=0;


    REP(i,N){
        REP(j,S[i].size()-1){
            if(S[i][j]=='A' and S[i][j+1]=='B') ans++;
        }
        if(S[i][0]=='B' and S[i][S[i].size()-1]=='A') BA++;
        else if(S[i][0]=='B' and S[i][S[i].size()-1]!='A') B++;
        else if(S[i][0]!='B' and S[i][S[i].size()-1]=='A') A++;
    }

    if(BA==0) ans += llmin(B,A);
    else{
        if(B+A>0) ans += (BA + llmin(B,A));
        if(B+A==0) ans += (BA-1);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 768
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		int num = -1;
		List<Integer> lista = func(a);
		List<Integer> listb = func(b);
		Collections.sort(lista, Collections.reverseOrder());
		int cnt = 0;
		for(int i = 0; i < lista.size(); i++) {
			num = lista.get(i);
			if (listb.contains(num)) {
				cnt++;
			}
			if (cnt == k)
				break;
		}
		out.println(num);
		
		out.close();
	}
	static ArrayList<Integer> func(int n) {
		ArrayList<Integer> ret = new ArrayList<>();
		int num = (int)Math.sqrt((double)n);
		for(int i = 1; i <= num; i++) {
			if (n % i == 0) {
				int j = n / i;
				if (!ret.contains(i))ret.add(i);
				if (!ret.contains(j))ret.add(j);
			}
		}
		return ret;
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}



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

using namespace std;

typedef long long ll;


int a;
int main()
{
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> a;

    cout << a + a*a + a*a*a << endl;
 
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;

const ll mod =  1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

int main()
{
    int n;
    cin >> n;
    int cnt[n];
    for(int i = 0; i < n; i++) cnt[i] = 0;
    map<int,int> m;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        m[a]++;
    }
    int ans = 0;
    for(auto i : m){
        if(i.second % 2 == 1){
            ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 5376
#include<iostream>
#include<cstdio>
using namespace std;
int a,b;
int main()
{
    while(~scanf("%d%d",&a,&b))
    {
        if(a+b<10)
        {
            cout<<a+b<<endl;
            continue;
        }
        cout<<"error"<<endl;
    }
    return 0;
}


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

int main()
{
    string s;
    cin>>s;
    long long cnt=0;
    long long sum=0;
    for(long long i=0;i<s.size();i++)
    {
        if(s[i]=='W')
        {
            sum+=cnt;
        }
        else cnt++;
    }
    cout<<sum<<"\n";
    return 0;
}


Measured memory_bytes: 640
/*
sonu_verma1
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(a) push_back(a)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
	int n;
	cin>>n;
	cout<<n*n;

	return 0;
}

Measured memory_bytes: 256
from collections import deque
n = int(input())
a = list(map(int,(input().split())))
b = deque([])
for i in range(n):
    if i%2 == 0:
        b.appendleft(a[i])
    else:
        b.append(a[i])
if n%2 == 0:
    b.reverse()
print(*b)

Measured memory_bytes: 99000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n;cin>>n;
	int cnt[n],a[n];
	rep(i,n) cnt[i]=0;
	for(int i=1;i<n;i++){
		cin>>a[i];
		cnt[a[i]-1]++;
	}
	rep(i,n) cout<<cnt[i]<<"\n";
}

Measured memory_bytes: 5188
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{ 
	double v;
	double y,t;
	int N;
        while(1){
		cin>>v;
 		if(cin.eof()) return 0;
		t=v/9.8;
		y=4.9*t*t;
                N=1+(int)y/5.0;
		if((double)5.0*(N-1)==N) cout<<N<<endl;
		else cout<<(N+1)<<endl;
	}
}

Measured memory_bytes: 1224