akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

int main() {
    int a, b;
    char sign[4];
    
    cin >> a >> b ;
    if(a < b){
        strcpy(sign, "<");
    }else if(a == b) {
        strcpy(sign, "==");
    }else {
        strcpy(sign, ">");
    }
    printf("a %s b\n", sign);
    
    return 0;
}

Measured memory_bytes: 1140
#include<stdio.h>
int main(void)
{
	int S, h, m, s;
	scanf("%d", &S);
	h = S/3600;
	m = (S-3600*h)/60;
	s = S-h*3600-m*60;
	printf("%d:%d:%d\n", h, m, s);
	
	return 0;
}

Measured memory_bytes: 592
def Tree():
    S = input()
    N = len(S)

    if S[0] == "0" or S[-1] == "1":
        return []

    for i in range(N - 1):
        if S[i] != S[N - i - 2]:
            return []

    res = []
    path = S.count("1")
    for i in range(1, path + 1):
        res.append((i, i + 1))

    u = len(res) + 1
    v = 1
    for s in S[:-1]:
        if s == "1":
            v += 1
        else:
            u += 1
            res.append((v, u))

    return res


if __name__ == "__main__":
    tree = Tree()
    if tree:
        for x, y in tree:
            print(x, y)
    else:
        print(-1)

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
	int N;
	cin >> N;
	vector<vector<int>> K(N + 1);
	fx(N-1) {
		int a, b;
		cin >> a >> b;
		pb(K.at(a), b);
		pb(K.at(b), a);
	}

	int des[110000];
	int des2[110000];
	fx(N) {
		des[x + 1] = INT_MAX;
		des2[x + 1] = INT_MAX;
	}
	des[1] = 0;
	des2[N] = 0;
	queue<int> where;
	where.push(1);
	while (!where.empty()) {

		int x = where.front();
		where.pop();

		fy(K.at(x).size()) {
			if (des[K.at(x).at(y)]>des[x]+1) {
				des[K.at(x).at(y)] = des[x] + 1;
				where.push(K.at(x).at(y));
			}
		}
	}

	where.push(N);
	while (!where.empty()) {
		int x = where.front();
		where.pop();

		fy(K.at(x).size()) {
			if (des2[K.at(x).at(y)]>des2[x] + 1) {
				des2[K.at(x).at(y)] = des2[x] + 1;
				where.push(K.at(x).at(y));
			}
		}
	}

	int ans = 0;
	fx(N) {
		if (des[x+1]<=des2[x+1]) {
			ans++;
		}
		else {
			ans--;
		}
	}
	if (ans>0) {
		ce("Fennec")
	}
	else {
		ce("Snuke")
	}

    return 0;
}



Measured memory_bytes: 6528
#pragma warning (disable :4996)
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;

int n, a[10010];
int q, b[510];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
		scanf("%d", &b[i]);
	int ans = 0;
	for (int j = 0; j < q; j++) {
		for (int i = 0; i < n; i++) {
			if (a[i] == b[j]) {
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

const int INF = 100000 + 1000;

map<int, bool> factors;


int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if (a + b < c + d) {
        cout << "Right" << endl;
    } else if (a + b == c + d) {
        cout << "Balanced" << endl;
    } else {
        cout << "Left" << endl;
    }
}

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

#define mp make_pair
#define pb push_back
#define fst first
#define snd second
#define int long long
#define fast_io() ios::sync_with_stdio(false)
#define FOR(i, l, r) for(int i = (l); i < (r); i++)
#define H(x) cout << #x << " " << x << endl;

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef set<int> si;
typedef double ld;
typedef pair<ld, ld> dd;

const ll INF = 1000000000000000000LL;
const int NMAX = 1e6+4;
const int mod = 1e9+7;
const ld eps = 1e-10;
const ld PI = acos(-1);

signed main(){
    int A, B, N;
    cin >> N >> A >> B;
    cout << min(A, B) << " " << max(A+B-N, 0LL) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 100020
#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next)
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define inf 0x3f3f3f3f
typedef long long ll;
typedef pair<int,int> pr;

set <ll> s;
set <ll>::iterator it;
int k;
ll pow_[20];

void init(){
	int a[28] = {0,1,2,3,4,5,6,7,8,9,19,29,39,49,59,69,79,89,99,199,299,399,499,599,699,799,899,999};
	rep(i,1,27) s.insert(a[i]);
	pow_[0] = 1;
	rep(i,1,18) pow_[i] = pow_[i - 1] * 10;
}
int cal(ll n){
	int res = 0;
	while ( n ) res += n % 10 , n /= 10;
	return res;
}
bool check(ll a,ll b){
	return a * cal(b) <= b * cal(a);
}
void expand(ll cur,int id){
	rep(i,1,9){
		ll x = cur - pow_[id];
		if ( !check(x,cur) ) return;
		s.insert(cur = x);
	}
	if ( id > 2 ) expand(cur,id - 1);
}
void solve(){
	if ( k <= s.size() ){
		int cnt = 1;
		for ( it = s.begin() ; cnt <= k ; cnt++ , it++){
			printf("%lld\n",(*it));
		}
		return;
	}
	rep(i,3,14){ //10^3 - 10^15
		rep(j,1,9){ //the front number , 19999 is legal
			s.insert(pow_[i] * (j + 1) - 1);
			expand(pow_[i] * (j + 1) - 1,i - 1);
		}
		if ( k <= s.size() ){
			int cnt = 1;
			for ( it = s.begin() ; cnt <= k ; cnt++ , it++){
				printf("%lld\n",(*it));
			}
			return;
		}
	}
}
int main(){
	init();
	cin>>k;
	solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<int,int> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> a(n+1),sum(n+1,0);
    FOR(i,1,n+1){
      cin>>a[i];
      sum[i]=sum[i-1]+a[i];
    }
    ll x=sum[1];
    ll y=sum[n]-x;
    ll ans=abs(x-y);
    FOR(i,1,n){
      x=sum[i];
      y=sum[n]-x;
      if(abs(x-y)<ans){
        ans=abs(x-y);
      }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3456
#include<stdio.h>
#include<stdlib.h>

int k;
int *A;

void maxHeap(int);
void construct();
void up(int *, int *);

int main(){
  int i;

  scanf("%d",&k);

  A = (int *)malloc((k+1) * sizeof(int));

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

  construct();

  for(i=1; i<=k; i++)
    printf(" %d",A[i]);

  printf("\n");

  free(A);
  return 0;
}

void maxHeap(int i){
  int l = 2*i;
  int r = 2*i + 1;
  int largest;

  if(l <= k && A[l] > A[i])
    largest = l;

  else
    largest = i;

  if(r <= k && A[r] > A[largest])
    largest = r;

  if(largest != i){
    up(&A[i], &A[largest]);
    maxHeap(largest);
  }
}

void construct(){
  int i;

  for(i=k/2; i>0; i--)
    maxHeap(i);
}

void up(int *a, int *b){
  int tmp;

  tmp = *a;
  *a = *b;
  *b = tmp;
}





Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n;
    cin>>n;
    vector<int>v(n);
    int i,j;
    int ans=0;
    for(i=0;i<n;i++)
    {
        cin>>v[i];
    }

    sort(v.begin(),v.end());

    for(i=n-1;i>=0;i--)
    {
        for(j=i-1;j>=0;j--)
        {
            int x=lower_bound(v.begin(),v.end(),v[i]+v[j])-v.begin();
            int y=n-x;
            ans+=n-1-i-y;
        }
    }
    cout<<ans<<endl;

}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long N;
  cin >> N;
  vector<long> A(N);
  for (long i = 0; i < N; i++) cin >> A.at(i);
  map<long, long> MA;
  for (long i = 0; i < N; i++) {
    MA[A.at(i)]++;
  }
  long sum = accumulate(A.begin(), A.end(), 0L);
  long Q;
  cin >> Q;
  while (Q--) {
    long B, C;
    cin >> B >> C;
    long tmp = MA[B];
    sum -= B * tmp;
    sum += C * tmp;
    MA[B] = 0;
    MA[C] += tmp;
    cout << sum << "\n";
  }
}

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

int main(){
    int p,q,r;
    cin >> p >> q >> r;
    cout << p + q + r - max(p,max(q,r)) << endl;
}


Measured memory_bytes: 764
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

int main() {
  //
  ll n;
  cin >> n;
  vl a(n), b(n);
  rep(i, n) {
    a[i] = 30000 * (1 + i);
    b[n - 1 - i] = 30000 * (1 + i);
  }
  map<ll, ll> r;
  int idx = 1;
  rep(i, n) {
    ll p;
    cin >> p;
    p--;
    r[p] = idx++;
  }
  rep(i, n) { b[i] += r[i]; }
  rep(i, n) {
    cout << a[i];
    if (i < n - 1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
  rep(i, n) {
    cout << b[i];
    if (i < n - 1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
  return 0;
}


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

int main(){
	int n, k;
	
	while( cin >> n >> k , n || k ){
		int C[100002] = {0};
		int dp[100002] = {0};
		
		for(int i=0 ; i < k ; i++ ){
			int j;
			cin >> j;
			C[j] = 1;
		}
		if( C[1] == 1 ){
			dp[1] = 1;
		}
		for(int i=2 ; i <= n ; i++ ){
			if( C[i] == 1 ){
				if( dp[i-1] > 0 ){
					dp[i] = dp[i-1] + 1;
				}else{
					dp[i] = 1;
				}
			}
		}
		for(int i=n ; i > 0 ; i-- ){
			if( C[i] == 1 ){
				if( dp[i+1] > 0 ){
					dp[i] = dp[i+1];
				}
			}
		}
		int ans = 0;
		if( C[0] == 1 ){
			for(int i=2 ; i <= n ; i++ ){
				ans = max( ans , dp[i] );
				if( C[i] == 0 ){
					ans = max( ans , dp[i-1] + dp[i+1] + 1 );
				}
			}
		}else{
			for(int i=1 ; i <= n ; i++ ){
				ans = max( ans , dp[i] );
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    int a[N], b[N], c[M], d[M];
    for(int i = 0; i < N; i++) cin >> a[i] >> b[i];
    for(int i = 0; i < M; i++) cin >> c[i] >> d[i];
    for(int i = 0; i < N; i++) {
        int ans = 0, best = inf;
        for(int j = 0; j < M; j++) {
            if(best > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
                best = abs(a[i] - c[j]) + abs(b[i] - d[j]);
                ans = j;
            }
        }
        cout << ans + 1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
nums=list(map(int,input().split()))
N=nums[0]
L=nums[1]
taste=[L+i for i in range(N)]
abs_taste=[abs(x) for x in taste]
tabel=min(abs_taste)
if(tabel in taste):
  taste.remove(tabel)
  print(sum(taste))
else:
  taste.remove(-tabel)
  print(sum(taste))

Measured memory_bytes: 3064
#include <iostream>
#include<algorithm>

using namespace std;

int main(){
        int N,T;
        int c,t;
        int ans=1010;

        cin>>N>>T;
        for(int i=0; i<N; i++){
                cin>>c>>t;
                if(t<=T){
                        ans=min(ans,c);
                }
        }
        if(ans==1010) cout<<"TLE"<<endl;
        else cout<<ans<<endl;
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c)
{
    stack<int> S;
    S.push(r);
    color[r] = c;
    while(!S.empty())
    {
        int u = S.top();
        S.pop();
        for(int i=0; i<G[u].size(); i++)
        {
            int v = G[u][i];
            if(color[v] == NIL)
            {
                color[v] = c;
                S.push(v);
            }
        }
    }
}

void assignColor()
{
    int id = 1;
    for(int i=0; i<n; i++) color[i] = NIL;
    for(int u=0; u<n; u++)
    {
        if(color[u] == NIL) dfs(u, id++);
    }
}



int main() 
{
    ios::sync_with_stdio(false);
    
    int s, t, m, q;

    cin >> n >> m;

    for(int i=0; i<m; i++)
    {
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    assignColor();

    cin >> q;

    for(int i=0; i<q; i++)
    {
        cin >> s >> t;
        if(color[s] == color[t])
        {
            cout << "yes" << endl;
        }
        else
        {
            cout << "no" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 8972
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		String T = "keyence";
		int l = 0;
		for(int i=0;i<7;i++){
			if(S[i] == T[i]){
				l++;
				continue;
			}
			break;
		}
		int r = 0;
		int N = S.Length;
		for(int i=0;i<7;i++){
			if(S[N - 1 - i] == T[6 - i]){
				r++;
				continue;
			}
			break;
		}
		//Console.WriteLine("{0} {1}", l, r);
		Console.WriteLine((l + r) >= 7 ? "YES" : "NO");
		
	}
	String S;
	public Sol(){
		S = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{

	//Main
	static void Main(string[] args)
	{
		//読み込む
		string[] S = Console.ReadLine().Split(' ');
		int N = int.Parse(S[0]);
		int K = int.Parse(S[1]);

		//累積和を格納する配列
		long[] sumArr = new long[N+1];
		for(int i=1; i<N+1; i++){
				long idx = (long)i;
				sumArr[i] = idx*(idx+1)/2;
		}

		/*
		K<=i<=N+1となる各iについて、有り得る組み合わせの数は、
		それぞれ最大値-最小値+1通りである。（∵最小値から最大値までの全ての数を作成可能）
		最大値-最小値については、累積和から容易に求められる
		*/
		long ans = 0;

		for(int i=K; i<N+1; i++){
				//最小値
				long min = sumArr[i-1];
				//最小値
				long max = sumArr[N] - sumArr[N-i];

				//組み合わせの数を答えに加算
				ans += (max-min+1);
		}

		//i=N+1のとき、1通りのみ存在する
		ans ++;

		Console.WriteLine(ans%1000000007);
	}
}



Measured memory_bytes: 18564
#include <iostream>

using namespace std;
long long NMAX,NMIN;
int K;
int A[100005];
long long eval(long long N){
    for(int i = 1;i <= K;i++){
        N = (N / A[i]) * A[i];
    }
    return N;
}
int main()
{
    cin >> K;
    for(int i = 1;i <= K;i++){
        cin >> A[i];
    }
    long long st = 0,dr = 1e18;
    while(dr - st > 1){
        long long mid = (st + dr) / 2;
        if(eval(mid) >= 2){
            dr = mid;
        }
        else {
            st = mid;
        }
    }
    if(eval(dr) != 2){
        cout << -1;
        return 0;
    }
    cout << dr << " ";
    st = 0,dr = 1e18;
    while(dr - st > 1){
        long long mid = (st + dr) / 2;
        if(eval(mid) <= 2){
            st = mid;
        }
        else {
            dr = mid;
        }
    }
    cout << st << " ";
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}

vector<ll> pw2(51,1);vector<ll> pw10(19,1);
int main(){
    {rep1(i,50) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N,M; cin>>N>>M;
    if(((1<=N)&&(N<=9))&&((1<=M)&&(M<=9))) cout<<N*M<<endl;
    else cout<<-1<<endl;
    
}



Measured memory_bytes: 3644
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 500001
#define pll pair<ll,ll>
#define pii pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define get(n) ll (n); scanf("%lld",&(n));
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);


int main() {

    get(a);
    get(b);

    if(a<=9 && a>=1 && b<=9 && b>=1)
        cout<<a*b<<endl;
    else
        cout<<-1<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin >> a;
	double sum = 0;
	for(int i=0; i<a; i++)
	{
		double temp;
		cin >> temp;
		sum += (double)1 / temp;
	}
	double ans = (double) 1 / sum;
	printf("%.20lf", ans);
	return 0;	
}

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

int main(){
    int n, x;
    cin >> n >> x;
    vector<int> l;
    for (auto i = 0; i < n; i++)
    {
        int l_i;
        cin >> l_i;
        l.push_back(l_i);
    }

    int bound = 1;
    int d = 0;

    for (auto i = 0; i < n; i++)
    {
        d += l[i];
        if(d <= x){
            bound += 1;
            continue;
        }
        break;
    }

    cout << bound << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	string S;
	cin>>S;
	if (S[3-1]==S[4-1] && S[5-1]==S[6-1]){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    def dfs(i,k):
        if i == d:
            l.append(k)
        else:
            for j in range(2):
                dfs(i+1,k+[j])
    d,g = LI()
    p = LIR(d)
    ans = float("inf")
    l = []
    dfs(0,[])
    for k in l:
        m = 0
        o = 0
        q = [[p[i][0],p[i][1]] for i in range(d)]
        for i in range(d):
            if k[i]:
                o += q[i][0]
                m += q[i][0]*(i+1)*100+q[i][1]
                q[i][0] = 0
        while m < g:
            for i in range(d)[::-1]:
                for j in range(q[i][0]):
                    m += (i+1)*100
                    o += 1
                    if m >= g:break
                if m >= g:break
        ans = min(ans,o)
    print(ans)
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 46300
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n=I()
lis=[0 for i in range(100000)]
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            u=x**2+y**2+z**2+x*y+y*z+z*x
            lis[u-1]+=1
for i in range(n):
    print(lis[i])

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

int main(){
  int h;
  int g[11][11];

  while(cin >> h, h){
    rep(i,h)rep(j,5)cin >> g[i][j];

    int score = 0;
    bool flag = true;
    while(flag){
      flag = false;
      rep(i,h){
	int len = 0, prv = -1, col = -1;
	rep(j,5){
	  if(col==g[i][j] && g[i][j]!=-1){
	    len++;
	  }else{
	    if(len>=3){
	      flag = true;
	      for(int k=prv;k<prv+len;k++){
		score += g[i][k];
		g[i][k] = -1;
	      }
	    }
	    len=1;
	    prv = j;
	    col = g[i][j];
	  }
	}
	if(len>=3){
	  flag = true;
	  for(int k=prv;k<prv+len;k++){
	    score += g[i][k];
	    g[i][k] = -1;
	  }
	}
      }
      
      rep(j,5){
	for(int i=h-1;i>=1;i--){
	  for(int tmp=0;tmp<10 && (g[i][j]==-1);tmp++){
	    for(int k=i;k>=1;k--)swap(g[k][j],g[k-1][j]);
	  }
	}
      }
    }
    cout << score << endl;
  }
}

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

int main() {
  string s;cin>>s;
  int x=1e9,y=0;
  rep(i,s.size()){
      if(s[i]=='A')x=min(x,i+1);
      if(s[i]=='Z')y=max(y,i+1);
    }
  cout<<y-x+1<<endl;
}

Measured memory_bytes: 3680
# 解説

n,m = map(int, input().strip().split(' '))
x = list(map(int, input().strip().split(' ')))
y = list(map(int, input().strip().split(' ')))

X = sum([(2*i-n+1)*x[i] for i in range(n)]) % 1000000007
Y = sum([(2*i-m+1)*y[i] for i in range(m)]) % 1000000007
ans = (X*Y) % 1000000007
print(ans)


Measured memory_bytes: 18624
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  int sum = 0;
  rep(i,N+1)
  {
    sum += i;
  }
  cout << sum << endl;
  return 0;
}


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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return abs(x-y)/gcd(x,y); }


int main() {
  lint l,r; cin >> l >> r;

  lint ans=2019;
  if(r-l>=2019) { ans = 0; }
  else {
    for(lint i=l;i<r;i++) {
      for(lint j=i+1;j<=r;j++) {
        ans = min(ans,(i*j)%2019);
      }
    }
  }

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

Measured memory_bytes: 256
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();
        long m = sc.nextLong();
        long[] sum = new long[n + 1];
        Map<Long, Long> map = new TreeMap<>();
        List<Long> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            sum[i + 1] = sum[i] + sc.nextLong();
            if (!map.containsKey(sum[i + 1] % m)) {
                map.put(sum[i + 1] % m, 1l);
                list.add(sum[i + 1] % m);
            } else {
                map.put(sum[i + 1] % m, map.get(sum[i + 1] % m) + 1);
            }
        }
        long count = 0;
        for (int i = 0; i < map.size(); i++) {
            long tmp = map.get(list.get(i));
            if (list.get(i) == 0) {
                count += tmp + tmp * (tmp - 1) / 2;
            } else {
                count += tmp * (tmp - 1) / 2;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 66560
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        int a[3];
        for(int i=0;i<3;i++)
            cin>>a[i];
        sort(a,a+3);
        if(a[2]*a[2]==a[0]*a[0]+a[1]*a[1])
            printf("YES\n");
        else
            printf("NO\n");
    }
}

Measured memory_bytes: 1132
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int n,a[N],x,y;
map<int,int>mp;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	sort(a,a+n);
	x=y=-1;
	for(int i=0;i<n;i++){
		if(mp[a[i]]>=2&&a[i]>=x){
			y=x;
			x=a[i];
			mp[a[i]]-=2;
		}
		else if(mp[a[i]]>=2&&a[i]>y){
			y=a[i];
			mp[a[i]]-=2;
		}
	}
	if(x!=-1&&y!=-1) cout<<1LL*x*y<<endl;
	else puts("0");
	return 0;
}

Measured memory_bytes: 8656
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define F first
#define S second
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};


signed main(){
	int n,l;
	cin>>n>>l;
	int s=0,ans=1e18;
	r(i,n){
		int t=0,x=0;
		r(j,n){
			x+=(j+1)-1+l;
			if(i==j)continue;
			t+=(j+1)-1+l;
		}
		

		int p=abs(x-t);

		if(ans>p){
			ans=p;
			s=t;
		}
	}
	cout<<s<<endl;
}


Measured memory_bytes: 256
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N, K = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype = np.int64)
F = np.array(list(map(int, input().split())), dtype = np.int64)
A.sort()
F.sort()
F = F[::-1]

l = 0
r = 10**12 + 100

def solve(num):
	B = num // F
	tmp = np.sum(np.maximum(0, A - B))
	if tmp <= K:
		return 1
	else:
		return 0

while r - l > 1:
	mid = (l + r) // 2
	if solve(mid):
		r = mid
	else:
		l = mid

if solve(l):
	print(l)
else:
	print(r)



Measured memory_bytes: 37164
#include<bits/stdc++.h>
using namespace std;
int n,m;
void dfs(int i, vector<bool> &checked, bool c[10][10], int &ans){
    int t = 0;
    for (int j = 0; j < n; j++)
    {
        if(checked[j]) t++;
    }
    if(t == n) ans ++;
    else{
        for (int j; j < n; j++)
        {
            if(c[i][j] == true && !checked[j]){
                checked[j] = true;
                dfs(j,checked,c,ans);
                checked[j] = false;
            }
        }
        
    }
    
}

int main(){
    cin>> n >> m;
    vector<bool> checked(n,false);
    bool c[10][10] = {false};
    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        x--; y--;
        c[x][y] = true;
        c[y][x] = true;
    }
    checked[0] = true;
    int ans = 0;
    dfs(0,checked,c,ans);

    cout << ans << endl;
}

Measured memory_bytes: 3600
import sys
#import numpy as np

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    S = i2s()
    n = len(S)
    mi = 15 - n
    ok = len([s for s in S if s == 'o'])
    if ok + mi >= 8:
        print('YES')
    else:
        print('NO')

main()


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

const int INF = (1<<30)-1;

int N, Z, W, A[2010];

int memo[2010][2];
int f(int id, int turn, int x, int y) {
    // cout << id << " " << turn << " " << x << " " << y << endl;
    if (id == N) return abs(x - y);
 
    if (0 <= memo[id][turn]) return memo[id][turn];
 
    if (turn == 0) {
        int ma = -1;
        rep(i, id, N) ma = max(ma, f(i + 1, 1 - turn, A[i], y));
        // cout << "  " << "memo[id][turn] " << id << " " << turn << " " << ma << endl;
        return memo[id][turn] = ma;
    } else {
        int mi = INF;
        rep(i, id, N) mi = min(mi, f(i + 1, 1 - turn, x, A[i]));
        // cout << "  " << "memo[id][turn] " << id << " " << turn << " " << mi << endl;
        return memo[id][turn] = mi;
    }
}

int main(){
    cin >> N >> Z >> W;
    rep(i, 0, N) cin >> A[i];
 
    rep(i, 0, N) rep(t, 0, 2) memo[i][t] = -1;
    cout << f(0, 0, Z, W) << endl;
}

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

#define MM 1000000000
#define mod MM+7
#define INF (ll)1e18
#define PI acos(-1.0)
#define NIL -1
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main(){
    int n,W; cin >> n >> W;
    int weight[110],value[110];
    int dp[110][10010];
    for(int i = 0; i < n; i++) cin >> value[i] >> weight[i];
    for(int w = 0; w <= W; w++) dp[0][w] = 0;

    for(int i = 0; i < n; i++){
        for(int w = 0; w <= W; w++){
            if(w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
            else dp[i+1][w] = dp[i][w];
        }
    }
    cout << dp[n][W] << endl;
}



Measured memory_bytes: 7076
#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);
    map<int,int> mp;
    int n,m,k,a;
    cin >> n >> m;
    for(int i=0;i<n;i++){
        cin >> k;
        for(int j=0;j<k;j++){
            cin >> a;
            mp[a]++;
        }
    }
    int ans=0;
    for(auto x:mp){
        if(x.second==n){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>


using namespace std;

int main()	{
	int n;
	cin >> n;
	vector<int> a(n, 0);
	unordered_map<int, int> freq;
	for (int i = 0; i < n; i++)	{
		cin >> a[i];
		freq[a[i]]++;
	}
	int res = 0;
	for (auto x : freq)	{
		if (x.first > x.second)	{
			res += x.second;
		}
		else if (x.first < x.second)	{
			res += (x.second - x.first);
		}
	}
	cout << res << endl;
	return 0;
}


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

int main()
{
	char a[10], b[10];
	cin>>a>>b;
	strcat(a,b);
	int n;
	sscanf(a, "%d", &n);
	//cout << n << endl;
	if(pow((int)sqrt(n),2)==n)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main() {
  int X;
  cin >> X;

  bool ans = 0;
  rep(i,1,X) {
    int l = 100 * i, r = 105 * i;
    if (l <= X && X <= r) ans = 1;
  }

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


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans=0;

    if ((b-a)%2 == 0){
        ans = (b-a)/2;
    } else if (a-1 <= n-b) {
        ans = a+(b-a-1)/2;
    } else if (a-1 > n-b){
        ans = n-b+(b-a-1)/2+1;
    }

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


Measured memory_bytes: 256
import bisect
import os

import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))
VU = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N)]
for v, u in VU:
    v -= 1
    u -= 1
    graph[v].append(u)
    graph[u].append(v)

dp = [INF] * (N + 10)
ans = [0] * N
root = 0


def dfs(v, p):
    i = bisect.bisect_left(dp, A[v])
    prev = dp[i]
    dp[i] = A[v]
    ans[v] = bisect.bisect_left(dp, INF)
    # print(dp)
    for u in graph[v]:
        if u == p:
            continue
        dfs(u, v)
    assert dp[i] <= prev
    dp[i] = prev
    # print(dp)


dfs(root, None)
print(*ans, sep='\n')


Measured memory_bytes: 373796
#include<stdio.h>
#include<math.h>
int main(void){
    int n, m, t, u=0, x, y=0;
    scanf("%d %d", &n, &m);
    int k[10], s[10][10], p[10];
    for(int i=0; i<m; i++){
        scanf("%d", &k[i]);
        for(int j=0; j<k[i]; j++){
           scanf("%d", &s[i][j]); 
        }
    }
    for(int i=0; i<m; i++){
        scanf("%d", &p[i]);
    }
    
    t=(int)pow(2, n);
    
    for(int j=0; j<t; j++){
        x=0;
        for(int i=0; i<m; i++){
            u=0;
            for(int l=0; l<k[i]; l++){
                u+=j / (int)pow(2, s[i][l]-1);
            }  
            if(u%2==p[i]){
                x+=1;
            }
        } 
        if(x==m){
            y+=1;
        }
    }

    printf("%d", y);
    return 0;
}

Measured memory_bytes: 128
from sys import stdin
import itertools
import numpy as np
from numba import njit

#入力
readline=stdin.readline
N,M,Q=map(int,readline().split())
a=np.zeros(Q,dtype=np.int64)
b=np.zeros(Q,dtype=np.int64)
c=np.zeros(Q,dtype=np.int64)
d=np.zeros(Q,dtype=np.int64)
for i in range(Q):
    a[i],b[i],c[i],d[i]=map(int,readline().split())

arrays=np.array(list(itertools.combinations_with_replacement(range(1,M+1),N)),dtype=np.int64)
l=len(arrays)

@njit
def f():
    max_res=0
    for i in range(l):
        res=0
        for j in range(Q):
            if arrays[i][b[j]-1]-arrays[i][a[j]-1]==c[j]:
                res+=d[j]
        max_res=max(max_res,res)
    return max_res

print(f())

Measured memory_bytes: 136828
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;

int main() {
    fast();
    // ll t;
    // cin>>t;
    // while(t--)			
    // {
        
    // }
    ll n;
    cin>>n;
    ll a[n];
    vector<int>v;
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<n;i++)
    {
        v.push_back(a[i]);
        v.push_back(a[i]);
    }
    sort(v.begin(),v.end(),greater<int>());
    ll sum=v[0];
    for(int i=1,p=2;i<n-1;i++)
    {
        sum+=v[p];
        p++;
    }
    cout<<sum<<endl;    
    
}


Measured memory_bytes: 6824
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll H, W, K;
    cin >> H >> W >> K;
    vector<string> field(H);
    loop(i, H)
    {
        cin >> field[i];
    }
    ll ans = 0;
    loop(bit1, 1 << H)
    {
        loop(bit2, 1 << W)
        {
            vector<string> check = field;
            loop(i, H)
            {
                if (flagon(bit1, i))
                {
                    loop(j, W) check[i][j] = '.';
                }
            }
            loop(i, W)
            {
                if (flagon(bit2, i))
                {
                    loop(j, H) check[j][i] = '.';
                }
            }
            ll count = 0;
            loop(i, H)
            {
                loop(j, W)
                {
                    if (check[i][j] == '#')
                        count++;
                }
            }
            if (count == K)
                ans++;
        }
    }
    putout(ans);
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    string s; cin>>s;

    int x=0,ans=0;
    REP(i,N){
        if(s[i]=='I') x++;
        else x--;
        ans=max(ans,x);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
def main():
    s = list(input())
    l = ["b"]
    for i in range(len(s)):
        if s[i] == "S":
            l.append("S")
        elif s[i] == "T" and (l[-1] == "T" or len(l) == 1):
            l.append("T")
        elif s[i] == "T" and l[-1] == "S":
            l.pop()
    print(len(l) - 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 6204
#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>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin>>n;
    string s;
    cin>>s;
    rep(i,s.size()){
        s[i]=s[i]+n-'A';
        s[i]=s[i]%26;
        s[i]+='A';
    }
    cout<<s<<endl;


    return 0;
}


Measured memory_bytes: 3632
let rec solve ss is p =
  if String.length ss.(p) <= is.(p) then p
  else begin
    let p' = Char.code ss.(p).[is.(p)] - Char.code 'a' in
    is.(p) <- 1 + is.(p);
    solve ss is p'
  end

let () =
  Printf.printf "%c\n" @@ Char.chr @@ ( + ) (Char.code 'A') @@
    solve (Array.init 3 @@ fun _ -> read_line ()) [| 0; 0; 0 |] 0


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int noa,nol;
  cin>>noa>>nol;
  if(nol>noa*4) cout<<"No";
  else if(nol%2==1) cout<<"No";
  else
  {
    int sum=noa*4;
    bool k=true;
    for(int i=0;i<noa;++i)
    {
      if(sum==nol)
      {
        cout<<"Yes";
        k=false;
        break;
      }
      else sum-=2;
  }
  if(sum==nol&&k)
      {
        cout<<"Yes";
        k=false;
      }
    if(k) cout<<"No";
  }
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k, q; cin >> n >> k >> q;
    vll ansa(n);
    REP(i, q) {
        ll a; cin >> a;
        ansa[a-1]++;
    }
    REP(i, n) {
        if (q-ansa[i] >= k) cout << "No\n";
        else cout << "Yes\n";
    }
    return 0;
}


Measured memory_bytes: 1408
/************************Code by Hardik Aggarwal!!!!***********************************/

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % mod; 
    p = (p * p) % mod; 
  
    return (y%2 == 0)? p : (x * p) % mod; 
}

int main()
{	
	

	IOS
	string s;
	cin>>s;
	ll n=s.size();
	ll a[n],b[n],next[n],prev[n];
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	memset(next,0,sizeof(next));
	memset(prev,0,sizeof(prev));
	for(ll i=0;i<n-1;i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
			{
				a[i]=1;
			}
	}

	for(ll i=1;i<n;i++)
	{
		if(a[i]==1)
		{
			prev[i]=i;
		}
		else
			prev[i]=prev[i-1];
	}


	for(ll i=n-2;i>=0;i--)
		{
			if(a[i]==1)
			{
				next[i]=i;
			}
			else
				next[i]=next[i+1];
		}

	for(ll i=0;i<n;i++)
	{
		if(s[i]=='R')
		{
			if((next[i]-i)%2==1)
			{
				b[next[i]+1]++;
			}
			else
				b[next[i]]++;
		}

		else
		{
			if((i-prev[i])%2==1)
			{
				b[prev[i]+1]++;
				
			}
			else
					b[prev[i]]++;
		}
	}

	for(ll i=0;i<n;i++)
	{	
		//cout<<next[i]<<" ";
		cout<<b[i]<<" ";
	}
}
    
 
    
    


Measured memory_bytes: 3792
import numpy as np


def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]


n = int(input())
a = list(map(int, input().split()))
ma = max(a)
h = getNearestValue(a, ma//2)
if h == ma:
    h = 0
print(ma, h)

Measured memory_bytes: 29052