akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;

int main() {
    int n, m, c[100][100], t[100][100];
    while(cin >> m >> n, n){
        for(int i=0;i<n;i++){
            fill(c[i],c[i]+n,IINF/3);
            fill(t[i],t[i]+n,IINF/3);
        }
        for(int i=0;i<m;i++){
            int a, b;
            cin >> a >> b;
            a--; b--;
            cin >> c[a][b] >> t[a][b];
            c[b][a] = c[a][b];
            t[b][a] = t[a][b];
        }
        for(int k=0;k<n;k++){
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
                    t[i][j] = min(t[i][j], t[i][k] + t[k][j]);
                }
            }
        }
        int q;
        cin >> q;
        for(int i=0;i<q;i++){
            int a, b, r;
            cin >> a >> b >> r;
            a--; b--;
            cout << (r ? t[a][b] : c[a][b]) << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3160
r = range(1, 10)
n = int(input())
a = [None] + [[0] * 10 for _ in r]
for i in r:
  if i <= n:
    a[i][i] += 1
for i in r:
  for j in r:
    k = 1
    while 10 * k * i + j <= n:
      a[i][j] += min(k, (n - j) // 10 - k * i + 1)
      k *= 10
print(sum(a[i][j] * a[j][i] for i in r for j in r))


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

int main() {
  long n,ans=0,fb=0,ea=0,fbea=0;
  cin >> n;
  vector<string> s(n);
  for(long i=0;i<n;i++) cin >> s[i];
  for(long i=0;i<n;i++) for(long j=0;j<s[i].size()-1;j++) if(s[i][j]=='A'&&s[i][j+1]=='B') ans++;
  for(long i=0;i<n;i++) {
    if(s[i][0]=='B') {
      if(s[i].back()=='A') {
        fbea++;
      } else {
        fb++;
      }
    } else if(s[i].back()=='A') {
      ea++;
    }
  }
  if(fbea>=2)ans+=fbea-1;
  if((fb>0||ea>0)&&fbea>=1) ans++;
  ans+=min(fb,ea);
  cout << ans << endl;
}

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

int main(void){
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
        sort(S[i].begin(), S[i].end());
    }
    sort(S.begin(), S.end());
    
    string s = S[0];
    int count = 1;
    long long int ans = 0;
    for (int i = 1; i < N; i++) {
        if (s == S[i])
            count++;
        else {
            if (count > 1)
                ans += (long long int)count * (count-1) / 2;
            count = 1;
            s = S[i];
        }
    }
    if (count > 1)
        ans += (long long int)count * (count-1) / 2;
    
    cout << ans << endl;
}

Measured memory_bytes: 7296
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        a: [u64; n]
    }

    let mut hmap = std::collections::HashMap::new();
    let mut pairs = vec![];
    for i in 0..n {
        *hmap.entry(a[i]).or_insert(0) += 1;
        let cnt = *hmap.get(&a[i]).unwrap_or(&0);
        if cnt % 2 == 0 && cnt >= 2 {
            pairs.push(a[i]);
        }
    }
    pairs.sort();
    pairs.reverse();
    let ret = if pairs.len() < 2 {
        0
    } else {
        pairs[0] * pairs[1]
    };
    println!("{}", ret);
}


Measured memory_bytes: 12540
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main (){
    string s;
    cin >> s;
    int a = 0, b = 0, c = 0;
    for (int i = 0; i < 3; i++){
        if (s[i] == 'a'){
            a++;
        } else if (s[i] == 'b'){
            b++;
        } else {
            c++;
        }
    }
    if (a == 1 && b == 1 && c == 1){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin >> n;
  vector<int> vec(n);
  
  for ( int i=0 ; i < n; i++ ){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  int count=1;
  
  for( int i=1; i<n ; i++){
    if (vec.at(i) == vec.at(i-1)){continue;}
    count++ ;
  }
  cout << count <<endl;
}
    
    
   

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

int main() {
    int H, W;

    while (true) {
        cin >> H >> W;

        if (H == 0 && W == 0) {
            break;
        }

        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}



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

int main() {
  // ここにプログラムを追記
  string A,B;
  cin >>A>>B;
  sort(A.begin(),A.end());
    
  sort(B.begin(),B.end());
    reverse(B.begin(),B.end());
    if(A<B){
     cout<< "Yes"<<endl;
      
    }
  else {cout<<"No"<<endl;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll ans=0;
  rep(i,n){
    cin >> a[i];
    ans+=a[i];
  }
  int e;
  cin >> e;
  rep(i,e){
    ll f,g;
    cin >> f >> g;
    cout << ans-a[f-1]+g << endl;
  }
}


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

int main(void) {
	int H, W;
	vector<string> vs;

	cin >> H >> W;
	vs.resize(H + 2);
	vs[0] = vs[H + 1] = string(W + 2, '#');
	for (int j = 1; j <= H; ++j) {
		string str;
		cin >> str;
		vs[j] = "#" + str + "#";
	}
	for (int j = 0; j <= H + 1; ++j)
		cout << vs[j] << '\n';

	return 0;
}


Measured memory_bytes: 256
//============================================================================
// 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

//============================================================================
//============================================================================
void enter()
{
    int w,h,x,y,r;

    scanf("%d", &w);
    scanf("%d", &h);
    scanf("%d", &x);
    scanf("%d", &y);
    scanf("%d", &r);
    if (x+r<=w && 0<=x-r && y+r<=h && 0<=y-r)
        printf("Yes\n");
    else
        printf("No\n");
}
//============================================================================
int main(void)
{
    enter();
    return 0;
}
//============================================================================

Measured memory_bytes: 584
n = int(input())
A = list(map(int, input().split()))
for i in range(1, n):
    print(' '.join(map(str, A)))
    key = A[i]
    j = i - 1
    while j >= 0 and A[j] > key:
        A[j+1] = A[j]
        j = j - 1
    A[j+1] = key
print(' '.join(map(str, A)))



Measured memory_bytes: 5596
n = int(input())
ans = {}
li = []
for _ in range(n):
    li.append(input())

ma = 0

for i in li:
    if i in ans:
        ans[i] += 1
    else:
        ans[i] = 1
    if ma < ans[i]:
        ma = ans[i]

ans = [i for i, j in ans.items() if j==ma]
ans.sort()
for i in ans:
    print(i)


Measured memory_bytes: 35220
#include<iostream>
#include<vector>
#include<string>

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

using namespace std;

struct Node
{
    int p,lc,rs;
};
vector<Node> T;

int GetParent(int id)
{
    return T[id].p;
}

int GetDepth(int id)
{
    int depth=0;
    int now=id;
    while (T[now].p!=NIL)
    {
        now=T[now].p;
        depth++;
    }
    return depth;
}
string GetType(int id)
{
    string type;
    if(T[id].p==NIL)type="root";
    else if(T[id].lc==NIL)type="leaf";
    else type="internal node";

    return type;
}

void GetChildren(int id)
{
    int lc=T[id].lc;
    cout<<"[";
    if(lc==NIL)cout<<"]";
    else
    {
        cout<<lc;
        while(T[lc].rs!=NIL)
        {
            cout<<", ";
            cout<<T[lc].rs;
            lc=T[lc].rs;
        }
        cout<<"]";

    }
}


int main()
{
    int n;
    cin>>n;
    rep(i,n)
    {
        Node t;
        t.p=t.lc=t.rs=NIL;
        T.push_back(t);
    }
    rep(i,n)
    {
        int id,k,c;
        cin>>id>>k;
        rep(j,k)
        {
            int l;
            cin>>c;
            if(j==0)
            {
                T[id].lc=c;
            }
            else
            {
                T[l].rs=c;
            }
            l=c;
            T[c].p=id;
        }
    }
    rep(i,n)
    {
        cout<<"node "<<i<<": ";
        cout<<"parent = "<<T[i].p<<", ";
        cout<<"depth = "<<GetDepth(i)<<", ";
        cout<<GetType(i)<<", ";
        GetChildren(i);
        cout<<endl;
    }

    return 0;
}

//parent,depth,type,ようそ



Measured memory_bytes: 4552
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))
#define LLONG_MAX numeric_limits<long long>::max()
#define INT_MAX numeric_limits<int>::max()

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " " << p.second << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}


template <typename T>
void vecOutPadding(vector<T>& vec, string pad = " ") {
	for (const T& elem : vec)
		cout << elem << pad;
}

template <typename T>
void matOut(vector<vector<T>>& mat) {
	for (const auto& row : mat) {
		for (const T& col : row)
			cout << col << " ";
		cout << endl;
	}
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	ll N, x;
	cin >> N >> x;
	vi a(N);
	cin >> a;
	sortall(a);

	ll ans = 0;
	for (int i = 0; i < N; i++) {
		x -= a[i];
		ans++;
		if (x <= 0) break;
	}

	if (x != 0) ans--;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
use std::io::{BufRead, Write};
use std::io;
use std::cmp::min;

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let (q, h, s, d): (usize, usize, usize, usize) = {
        let mut split = buf.split_whitespace();
        let a = split.next().unwrap().parse().unwrap();
        let b = split.next().unwrap().parse().unwrap();
        let c = split.next().unwrap().parse().unwrap();
        let d = split.next().unwrap().parse().unwrap();
        (a, b, c, d)
    };
    buf.clear();
    input.read_line(&mut buf).unwrap();
    let n: usize = buf.trim().parse().unwrap();
    let one_liter = min(q * 4, min(h * 2, s));
    let two_liters = d;
    let price = if one_liter * 2 < two_liters {
        one_liter * n
    } else {
        n / 2 * two_liters + n % 2 * one_liter
    };
    writeln!(output, "{}", price).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "20 30 70 90
3\n",
            "150\n",
        );
    }
    #[test]
    fn case2() {
        test(
            "10000 1000 100 10
1\n",
            "100\n",
        );
    }
    #[test]
    fn case3() {
        test(
            "10 100 1000 10000
1\n",
            "40\n",
        );
    }
    #[test]
    fn case4() {
        test(
            "12345678 87654321 12345678 87654321
123456789\n",
            "1524157763907942\n",
        );
    }
}


Measured memory_bytes: 4352
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int a[] = new int[n];
        int b[] = new int[n];
        for (int i = 1; i < n; i++) {
            if (s.charAt(i) == 'E') {
                b[0]++;
            }
        }
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == 'W') {
                a[i] = a[i - 1] + 1;
            } else {
                a[i] = a[i - 1];
            }
            if (s.charAt(i) == 'E') {
                b[i] = b[i - 1] - 1;
            } else {
                b[i] = b[i - 1];
            }
        }
        int c[] = new int[n];
        for (int i = 0; i < n; i++) {
            c[i] = a[i] + b[i];
        }
        Arrays.sort(c);
        System.out.println(c[0]);
    }

}

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

using namespace std;

typedef long long LL;
typedef long double LD;

void func()
{
  LL N,K;
  cin >> N;
  string S;
  cin >> S; 

  LL counter_max = 0;
  for (LL i = 0; i < N; ++i) { // 部分文字列1の先頭
    for (LL j = i + counter_max+1; j < N; ++j) { // 部分文字列2の先頭
      if (i > 0 && S[i-1] == S[j - 1]) {
        continue;
      }
      LL counter = 0;
      for (LL k = 0; k + j < N; ++k) { // 何文字目か
        if (i + k < j) {
          if (S[i + k] == S[j + k]) {
            counter++;
          }
          else {
            break;
          }
        }
      }
      //cerr <<i<<" : "<<j <<" : " << counter << endl;
      counter_max = max(counter, counter_max);
    }
  }

  cout << counter_max;

}

#ifdef CALC_TIME 
#include <windows.h>
int main()
{
  LARGE_INTEGER freq;
  QueryPerformanceFrequency(&freq);

  LARGE_INTEGER start, end;

  QueryPerformanceCounter(&start);

  // 何かの処理
  func();

  QueryPerformanceCounter(&end);

  double time = static_cast<double>(end.QuadPart - start.QuadPart) * 1000.0 / freq.QuadPart;
  fprintf(stderr,"%lf[ms]\n", time);

  return 0;
}
#else 
int main()
{
  func();
return 0;
}
#endif



Measured memory_bytes: 256
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n=0,d=0) Array.new(n,d)end
def na2(n=0,m=0,d=0) Array.new(n){Array.new(m,d)}end
def na3(n=0,m=0,l=0,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
s = inps[0]
a = na(26,0)
h = {}
s.each_char.with_index do |c,i|
  sa = (h[c] == nil)? i+1 : i-h[c] 
  h[c] = i
  a[c.ord - "a".ord] = [a[c.ord - "a".ord],sa].max
end
("a".."z").each do |c|
  sa = (h[c] == nil)? 0 : s.size - h[c]
  a[c.ord - "a".ord] = [a[c.ord - "a".ord],sa].max
end
a.delete(0)
p a.min - 1

=begin
3 2
3 3
0 0
=end

Measured memory_bytes: 1788
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

ll vs[100000+10];
int n;

vector<ll> cs[100000+10];
vector<ll> cs2[100000+10];

vector<int> memoDs[100000+10];
vector<int> calcDs(int v) {
  vector<int> &ds = memoDs[v];
  if(ds.empty()) {
    for(int d = 1; d*d <= v; ++d) {
      if(v % d == 0) {
        ds.push_back(d);
        if(d*d != v) {
          ds.push_back(v/d);
        }
      }
    }
  }
  return ds;
}

ll calc(int a, int b) {
  if(a <= b) {
    // cerr << "HOGE" <<  " " << a << " " << b << endl;
    return -1;
  }
  if((n-1-b) % (a-b) != 0) {
    // cerr << "HOGE2" <<  " " << a << " " << b << endl;
    return -1;
  }
  ll k = (n-1-b) / (a-b);
  if(b % (a-b) == 0) {
    ll x = b / (a-b) + 1;
    if(x <= k-1) {
      // cerr << "HOGE3" <<  " " << a << " " << b << endl;
      return -1;
    }
  }
  // 落ちずに到着できる。
  ll res = 0;
  res += cs2[a-b][k-1];
  res += cs[a-b][k-1];
  // cerr << ">" << a << " " << b << " " << res << endl;
  return res;
}

int main(void) {
  scanf("%d", &n);
  REP(i, n) {
    scanf("%lld", &vs[i]);
  }
  for(int i = 1; i <= n; ++i) {
    ll cur = 0;
    cs[i].push_back(cur);
    for(int j = i; j < n; j += i) {
      cur += vs[j];
      cs[i].push_back(cur);
    }
  }
  for(int i = 1; i < n; ++i) {
    ll cur = 0;
    cs2[i].push_back(cur);
    for(int j = n-1-i; j >= 0; j -= i) {
      cur += vs[j];
      cs2[i].push_back(cur);
    }
  }

  ll res = 0;
  // for(int a = 2; a <= n-1; ++a) {
  //   int rem = (n-1) % a;
  //   if(rem == 0) {
  //     continue;
  //   }
  //   vector<int> ds = calcDs(rem);
  //   for(int d : ds) {
  //     int b = a - d;
  //     ll cur = calc(a, b);
  //     res = max(res, cur);
  //   }
  // }
  for(int b = 1; b <= n-1; ++b) {
    vector<int> ds = calcDs(n-1-b);
    for(int d : ds) {
      int a = b + d;
      ll cur = calc(a, b);
      res = max(res, cur);
    }
  }
  cout << res << endl;
  return 0;
}


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

int main(){
  string N;
  cin>>N;
  
  int sum=0;
  
  for(int i=0;i<N.size();i++){
    sum+=N[i]-'0';
  }
  
  if(sum%9==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3744
n = int(input())
a = list(map(int, input().split()))

sum_a = sum(a)

dp = 1
for i in range(n):
    dp |= dp << a[i]

for i in range((sum_a + 1) // 2, sum_a + 1):
    if dp & (1 << i):
        print(i)
        exit()

Measured memory_bytes: 134168
#include<iostream>
#include<algorithm>
#include<stdlib.h>
using namespace std;

int main() {
	string S, T;
	cin >> S >> T;
	int sw = 0;
	int n = S.length();
	for (int i = 0; i < n; i++) {
		char t = S[0];
		int j = 0;
		while (j < n-1) {
			S[j] = S[j + 1];
			j++;
		}
		S[n-1] = t;
		if (S.compare(T) != 0) continue;
		else {
			sw = 1;
			break;
		}
	}
	if (sw == 1)cout << "Yes" << endl;
	else cout << "No" << endl;
	
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int,int> P;

const int MAX_N = 100000;
const int INF = 100000000;

template <typename T>
struct edge
{
    int from, to;
    T cost;
};

template<typename T>
struct Graph
{
    int n;
    vector<edge<T>> g[MAX_N + 4];
    T d[MAX_N + 4];
    int pre[MAX_N + 4];
    vector<int> tips;
    
    Graph(int n) : n(n) {};
    
    void add_edge(int from, int to, int cost){
        g[from].push_back(edge<T>{from, to, cost});
    }
    
    void Dijkstra(int s){
        typedef pair<T, int> PT;
        queue<PT> que;
        fill(d, d + n, INF);
        fill(pre, pre + n, -1);
        d[s] = 0;
        que.push(PT(0, s));
        while(que.size()){
            PT nowp = que.front();
            que.pop();
            int now = nowp.second;
            if(d[now] < nowp.first) continue;
            if((int)g[now].size() == 1) tips.push_back(now);
            for(edge<T> e : g[now]){
                if(d[e.to] > d[now] + e.cost){
                    d[e.to] = d[now] + e.cost;
                    que.push(PT(d[e.to], e.to));
                    pre[e.to] = e.from;
                }
            }
        }
    }
};

int main()
{
    int n;
    cin >> n;
    Graph<int> g(n);
    int a[100002], b[100002];
    for(int i = 0; i < n - 1; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        g.add_edge(a[i], b[i], 1);
        g.add_edge(b[i], a[i], 1);
    }
    g.Dijkstra(0);
    int k;
    cin >> k;
    int lar[100002], les[100002];
    fill(lar, lar + n, INF);
    fill(les, les + n, -INF);
    int v[100002], p[100002];
    int eo;
    for(int i = 0; i < k; i++){
        cin >> v[i] >> p[i];
        v[i]--;
        lar[v[i]] = p[i];
        les[v[i]] = p[i];
        if(i == 0) eo = (g.d[v[i]] + p[i]) % 2;
        if((g.d[v[i]] + p[i]) % 2 != eo){
            cout << "No" << endl;
            return 0;
        }
    }
    P pa[100002];
    for(int i = 0; i < n; i++) pa[i] = P(g.d[i], i);
    sort(pa, pa + n, greater<P>());
    for(int i = 0; i < n - 1; i++){
        lar[g.pre[pa[i].second]] = min(lar[g.pre[pa[i].second]], lar[pa[i].second] + 1);
        les[g.pre[pa[i].second]] = max(les[g.pre[pa[i].second]], les[pa[i].second] - 1);
        if(lar[g.pre[pa[i].second]] < les[g.pre[pa[i].second]]){
            cout << "No" << endl;
            return 0;
        }
    }
    int ans[100002];
    for(int i = 0; i < n; i++) ans[i] = INF;
    queue<int> que;
    ans[0] = les[0];
    que.push(0);
    while(que.size()){
        int now = que.front();
        que.pop();
        for(edge<int> e : g.g[now]){
            if(ans[e.to] == INF){
                if(les[e.to] <= ans[e.from] - 1) ans[e.to] = ans[e.from] - 1;
                else ans[e.to] = ans[e.from] + 1;
                que.push(e.to);
            }
        }
    }
    cout << "Yes" << endl;
    for(int i = 0; i < n; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 13620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    vector<int> a(9);
    int n;
    rep(i,9){
            cin >> a[i];
    }
    cin >> n;
    vint b(n);
    rep(i,n) cin >> b[i];
    vint bingo(9);
    rep(i,n){
        rep(j,9){
            if(b[i]==a[j]) bingo[j]=1;
        }
    }
    bool flag = false;
    for(int i=0;i<3;i++) {
        if((bingo[i*3]+bingo[i*3+1]+bingo[i*3+2]) == 3) flag =true;
        if((bingo[i]+bingo[i+3]+bingo[i+6]) == 3) flag =true;
    }
        if((bingo[0]+bingo[4]+bingo[8]) == 3) flag =true;
        if((bingo[2]+bingo[4]+bingo[6]) == 3) flag =true;
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int a, nodd = 0;
  for (int i = 0; i < N; i++) {
    cin >> a;
    nodd += a % 2;
  }
  if (nodd % 2) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 256
# N, Q = map(int, input().split())
import sys

input = sys.stdin.readline

N, Q = tuple(map(int, input().split()))
s = input()

Query = [input().split() for i in range(Q)]

left, right = 0, N - 1

for t, d in reversed(Query):
    if d == "L":
        if t == s[left]:
            left += 1
        if right < N - 1 and t == s[right + 1]:
            right = min(right + 1, N - 1)
    else:
        if left > 0 and t == s[left - 1]:
            left = max(left - 1, 0)
        if t == s[right]:
            right -= 1
print(max(right - left + 1, 0))


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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(),(c).end())

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

// constant
// -----------------------------------------------------------------------------
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int H, W, K; cin >> H >> W >> K;

    string board[H];
    int sum = 0;
    REP(i, H) {
        cin >> board[i];
        sum += count(board[i].begin(), board[i].end(), '#');
    }

    vector<int> dp_w(W, 0);
    REP(i, H) REP(j, W) if (board[i][j] == '#') dp_w[j]++;

    int ans = 0;
    for (int bit_h = 0; bit_h < (1 << H); bit_h++) {
        bool flag_h[H];
        REP(h, H) flag_h[h] = bit_h & (1 << h);

        for (int bit_w = 0; bit_w < (1 << W); bit_w++) {
            bool flag_w[W];
            REP(w, W) flag_w[w] = bit_w & (1 << w);
    
            int cnt = 0;
            REP(i, H) {
                REP(j, W) {
                    if ((flag_h[i] || flag_w[j]) && board[i][j] == '#') {
                        cnt++;
                    }
                }
            }
            if (sum - cnt == K) ans++;
        }
    }
    cout << ans << "\n";

}

Measured memory_bytes: 3656
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;

ll dp[200005][5];

int main(int argc, char* argv[])
{
    long L;
    scanf("%ld", &L);

    vector<long> a(L+1);
    long i;
    for(i=1; i<=L; i++) {
        scanf("%ld", &a[i]);
    }

    for(i=1; i<=L; i++) {
        dp[i][0] = dp[i-1][0] + a[i];
        ll tmp = MIN(dp[i-1][0], dp[i-1][1]);
        dp[i][1] = tmp + (a[i]<2? 2-a[i]: a[i]%2);
        tmp = MIN(tmp, dp[i-1][2]);
        dp[i][2] =tmp + (a[i]+1)%2;
        tmp = MIN(tmp, dp[i-1][3]);
        dp[i][3] = tmp + (a[i]<2? 2-a[i]: a[i]%2);
        tmp = MIN(tmp, dp[i-1][4]);
        dp[i][4] = tmp + a[i];
    }

    ll ans=LINF;
    long k;
    for(k=0; k<5; k++) {
        ans = MIN(ans, dp[L][k]);
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
using namespace std;


 int main(){

   int w,n,u,t,p;
   cin >> w>>n;
   int a[w];
   for(int i=0; i<w;i++)
    a[i]=i+1;

   for(int i=0; i<n;i++){
     scanf("%d,%d\n",&u,&t);
     p=a[t-1]; a[t-1]=a[u-1];a[u-1]=p;
   }
   for(int i=0; i<w ;i++)printf("%d\n",a[i]);
 }



Measured memory_bytes: 3144
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		long x=sc.nextLong();
		long ans=0;

		long mod=x%11;
		long tmp=(x-mod)/11;
		if(mod==0) ans=tmp*2;
		else if(mod>=1 && mod<=6) ans=tmp*2+1;
		else ans=tmp*2+2;

		System.out.println(ans);
	}
}

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

using namespace std;

#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORD(i, m, n) for (int i = m; i >= n; i--)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 0; i <= n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using ll = long long;
using ull = unsigned long long;
using ld = long double;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin>>s;
	if(s=="SSS")cout << 0 << endl;
	else if(s=="RRR")cout << 3 << endl;
	else if(s=="RRS"||s=="SRR")cout << 2 << endl;
	else cout << 1 << endl;
	
	return 0;
}

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

ll abc174d(string s) {
  auto length = (ll) s.size();
  ll num_w = 0;
  for(ll i =0;i<length;i++) {
    char ss = s[i];
    if(ss == 'W') {
      num_w++;
    }
  }
  //cout << "num of w is " << num_w << endl; 
  ll num_move_r = 0;
  for(int i=0;i<num_w;i++) {
    char ss = s[length - 1 - i];
    // cout << "index " << length -1 -i << endl;
    if(ss == 'R') {
      num_move_r++;
    }
  }
  //cout << "move r is " << num_move_r << endl;
  return num_move_r;
}

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  cout << abc174d(s);
}


Measured memory_bytes: 3896
N = int(input())
cards = []
for i in range(N):
    line = input().split()
    a = line[0]
    num = int(line[1])
    cards.append((a, num))

# cards = []
# with open('input_itp1_6_b_1.txt', mode='r', encoding='utf8') as f:
#     N = int(next(f))
#     for _i in range(1, N + 1):
#         line = next(f).split()
#         cards.append((line[0], int(line[1])))

# print(N)
# for card in cards:
#     print(' '.join(map(str, card)))

tarinai_list = []
for a in ['S', 'H', 'C', 'D']:
    for num in range(1, 14):
        find = False
        for card in cards:
            if a == card[0] and num == card[1]:
                find = True
                break
        if not find:
            tarinai_list.append((a, num))
for l in tarinai_list:
    print(' '.join(map(str, l)))


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

using namespace std;

template <typename T>
using Vec = vector<T>;

typedef long double ld;
typedef long long ll;

#define FO(i, N) for (int (i) = 0; (i) < (N); ++(i))
#define FOll(i, N) for (ll (i) = 0; (i) < (N); ++(i))
#define READALL(c) for (auto &e : c) { cin >> e; }
#define PRINTALL(c) for (const auto &e : c) { cout << e << "\t"; } cout << "\n";
#define MP(x, y) (make_pair((x), (y)))
#define MT(...) make_tuple(__VA_ARGS__)
#define G(i, x) get<i>(x)
#define ALL(x) begin(x), end(x)

int A[3123];

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

	int N;
	cin >> N;
	FO(i, N) cin >> A[i];
	ll ans = 0;
	FO(i, N) ans += A[i]-1;

	cout << ans << endl;
}

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

ll N;
ll a[444];
ll dp[444][444];

ll rec(ll l, ll r) {
    if(r-l==1) return 0;
    if(dp[l][r]!=-1) return dp[l][r];
    
    ll res=INF;
    ll sum=0;
    for(ll i=l; i<r; i++) {
        sum+=a[i];
    }
    
    for(ll mid=l+1; mid<r; mid++) {
        res=min(res, rec(l, mid)+rec(mid, r)+sum);
    }
    
    return dp[l][r]=res;
}

int main() {
    cin >> N;
    
    memset(dp, -1, sizeof(dp));
    
    for(ll i=0; i<N; i++) {
        cin >> a[i];
    }
    
    pr(rec(0, N));
    
    
    
    
    
}













Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	string str;
	
	cin >> n;
	while (n-- > 0) {
		cin >> str;

		sort(str.begin(), str.end());
		
		int min = 0, max = 0;
		for (int i = 0; i < 8; i++) {
			min = min * 10 + str[i];
			max = max * 10 + str[7 - i];
		}

		cout << max - min << endl;
	}
	return 0;
}


Measured memory_bytes: 3172
#include <stdio.h>

int rev(int n) {
	int r = 0;

	while (n > 0) {
		r = r * 10 + n % 10;
		n /= 10;
	}
	return r;
}

int pal(int n) {
	return n == rev(n);
}

int main() {
	int a, b, n, cnt;

	scanf("%d%d", &a, &b);
	cnt = 0;
	for (n = a; n <= b; n++)
		if (pal(n))
			cnt++;
	printf("%d\n", cnt);
	return 0;
}


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


int main(){
  long long int L, R;
  cin >> L >> R;
  long long int ans = 3000;
  for(long long int ii=L; ii<=min(R, L+2019); ii++){
    for(long long int jj=ii+1; jj<=min(R, ii+1+2019); jj++){
      ans = min(ans, (ii*jj)%2019);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = SS()

    d = ('SUN' ,'MON' ,'TUE' ,'WED' ,'THU' ,'FRI' ,'SAT')

    ans = 7 - d.index(S)
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9972
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
 
int main()
{
	int N, M, C, B[20], A[20],sum=0,cnt=0;
	cin >> N >> M >> C;
	for (int i = 0; i < M; i++)cin >> B[i];
	for (int i = 0; i < N; i++) {
		for (int k = 0; k < M; k++) {
			cin >> A[k];
			sum += A[k] * B[k];
		}
		if (sum + C > 0)cnt++;
		sum = 0;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int func(int A,int B,int C){
      if(A%2==1||B%2==1||C%2==1){return 0;}
      else if(A==B&&A==C){return -1;}
      else{return func((B+C)/2,(A+C)/2,(A+B)/2) +1;}
    }

    int main() {
     int A,B,C;
     cin>>A>>B>>C; 
     int ans=func(A,B,C);
     cout<<ans<<endl;
     return 0;
    }

Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c[ohara], d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n >> k;
  rep(i, n) cin >> a[i], a[i]--;
  rep(i, n) cin >> c[i];
  ans = -LINF;
  rep(i, n) {
    ll now = i;
    ll now_k = k;
    ll now_ans = -LINF;
    ll now_cnt = 0;
    ll len = 0;
    while (1) {
      if (now_k == 0) break;
      if (now == i && len != 0) break;
      now = a[now];
      now_k--;
      now_cnt += c[now];
      now_ans = max(now_ans, now_cnt);
      len++;
    }
    if (now_k == 0)
      ans = max(ans, now_ans);
    else {
      ans = max(ans, now_ans);
      now_ans = (k / len - 1) * now_cnt;
      // debug(k / len - 1);
      now_k = (k % len) + len;
      // debug(now_k);
      now_cnt = 0;
      ll sp = 0;
      now = i;
      while (1) {
        if (now_k == 0) break;
        now = a[now];
        now_k--;
        now_cnt += c[now];
        sp = max(sp, now_cnt);
      }
      now_ans = max(now_ans, now_ans + sp);
      ans = max(ans, now_ans);
    }
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 3736
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll beki[200020];
ll l[200020],r[200020];

int main(){
  string s;
  cin >> s;
  int q;
  cin >> q;
  int sig=1;
  string front="",back="";
  rep(_,q){
    int t;
    cin >> t;
    if(t==1){
      sig*=-1;
    }else{
      int f;
      char c;
      cin >> f >> c;
      if(f==2)f=-1;
      if(sig*f==1){
        back+=c;
      }else{
        front+=c;
      }
    }
  }
  reverse(back.begin(),back.end());
  s=back+s+front;
  if(sig==-1)reverse(s.begin(),s.end());
  cout << s << endl;
return 0;}

Measured memory_bytes: 1348
#include <stdio.h>

int main(void)
{
    int i, n;
    long long L0, L1, Li;

    scanf("%d", &n);

    L0 = 2;
    L1 = 1;
    Li = 1;

    for (i=0; i<n-1; i++) {
        Li = L1 + L0;
        L0 = L1;
        L1 = Li;
    }
    printf("%ld\n", Li);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
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; }

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*------------------------------------/
for library*/

/*------------------------------------*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N,K;
    cin>>N>>K;
    vector<ll> A(N),B(N);
    rep(i,N){
        cin>>A[i];
        B[i] = - A[i];
    }
    sort(all(A));
    sort(all(B));
    //X未満の数がK個未満かどうか
    auto check = [&](ll X){
        ll res = 0;
        //vector<ll> cnt(N, 0);
        rep(i,N){
            ll cnt = 0;
            //A[i] == 0
            if(A[i] == 0){
                if(X > 0)cnt = N - 1;
            }
            //左側を数える
            else if(A[i]>0){
                //indexの二分探索
                int ok = -1;
                int ng = N;
                while(ng - ok > 1){
                    int mid = (ok + ng) / 2;
                    if(A[i] * A[mid] < X)ok = mid;
                    else ng = mid;
                }
                //0-indexedなので
                cnt = ok + 1;
                if(A[i] * A[i] < X)cnt--;
            }
            
            //右側を数える
            else if(A[i]<0){
                //indexの二分探索
                int ok = -1;
                int ng = N;
                while(ng - ok > 1){
                    int mid = (ok + ng) / 2;
                    if(B[N-1-i] * B[mid] < X)ok = mid;
                    else ng = mid;
                }
                cnt = ok + 1;
                if(B[N-1-i] * B[N-1-i] < X)cnt--;
            }
            res += cnt;
        }
        //print(cnt);
        //cerr<<X<<": "<<res/2<<" 個"<<endl;
        return res/2 < K;
    };

    ll ok = - INFLL -1;
    ll ng = INFLL + 1;
    while(abs(ok - ng) > 1){
        ll mid = (ok + ng) / 2;
        if(check(mid))ok = mid;
        else ng = mid;
    }
    cout<<ok<<endl;
}

Measured memory_bytes: 3456
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N, vector<long long> A) {
  sort(ALL(A));
  reverse(ALL(A));

  std::vector<ll> v;

  REP(i, N) { cerr << A[i] << " "; }
  cerr << "\n";

  FOR(i, 1, N) {
    if (A[i] == A[i - 1]) {
      v.push_back(A[i]);
      dump(A[i]);
      i += 1;
    }
  }

  if (v.size() < 2) {
    cout << "0" << endl;
  } else {
    cout << (v[0] * v[1]) << endl;
  }
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  vector<long long> A(N - 1 + 1);
  for (int i = 0; i <= N - 1; i++) {
    cin >> A[i];
  }
  solve(N, A);
  return 0;
}


Measured memory_bytes: 2428
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define INF 10000000000

ll a, b, c, n, m, x, y, z, w, h, ans = 1, cnt = 0, mx = 0, mn = INF;
string s;

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

    cin >> x;
    rep(i, 2, sqrt(x) + 1){
        ll j = i * i;
        while(j <= x){
            j *= i;
        }
        ans = max(ans, j / i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
    int a;
    cin >> a;
    int num;
    num = a % 10;
    if(num == 0 || num == 1 || num == 6 || num == 8){
        cout  << "pon";
    }else if(num == 3){
        cout  << "bon";
    }else{
        cout << "hon";
    }

    return 0;
}


Measured memory_bytes: 3596