akhauriyash/Code-Regression huggingface dataset:
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 200005;

// fenwick

ll fen_tree[N];

void update(ll x,ll n){
    while(x<N){
        fen_tree[x] += n;
        x += (x&(-x));
    }
}
 
ll query(ll x){
    ll ans=0;
    while(x>0){
        ans += fen_tree[x];
        x -= (x&(-x));
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin >> n;
    rep(i,0,n){
    	ll x;
    	cin >> x;
    	update(x, x);
    }
    ll q;
    cin >> q;
    while(q--){
    	ll b,c;
    	cin >> b >> c;
    	ll y = query(b) - query(b-1);
    	ll z = y / b;
    	update(b, - z * b);
    	update(c, z * c);
    	ll ans = query(N);
    	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4412
#include<iostream>
using namespace std;
#define ll long long
int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll x1=a*c,x2=a*d,x3=b*c,x4=b*d;
    if(x1>=x2 && x1>=x3 && x1>=x4)
    cout<<x1;
    else if(x2>=x1 && x2>=x3 && x2>=x4)
    cout<<x2;
    else if(x3>=x2 && x3>=x1 && x3>=x4)
    cout<<x3;
    else
    cout<<x4;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
char str[100002]={'\0'};
int main()
{
    int len,a=0,b=0;
    int i;
    scanf("%s",str);
    len=strlen(str);
    for(i=0;i<len;i++)
    {
        if(str[i]=='0')
        {
            a++;
        }
        else if(str[i]=='1')
        {
            b++;
        }
    }
    printf("%d\n",min(a,b)*2);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LLINF = 9223372036854775807;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n, m; cin >> n >> m;
	vector<bool> f(n + 1, false);
	VI ps(n + 1, 0);
	int an = 0, pe = 0;
	int p; string s;
	REP(i, m) {
		cin >> p >> s;
		if (f[p] == false) {
			if (s == "AC") {
				f[p] = true;
				an++;
				pe += ps[p];
			}
			else {
				ps[p]++;
			}
		}
	}
	cout << an << ' ' << pe;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    string n;cin>>n;
    int divisor = 0;
    rep(i,n.size())divisor += n[i]-'0';
    cout<<((atoi(n.c_str())%divisor==0)?"Yes":"No")<<endl; return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        String T = sc.next();
        String result = "";
        for (int i = 0; i < N; i++) {
            result += S.charAt(i);
            result += T.charAt(i);
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

	vector<int> v = { a, b, c };
	sort(v.begin(), v.end());

	cout << v[0] * v[1] / 2 << endl;
}

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

dict = {'A':0, 'B':1, 'C':2, 'D':3, 'E':4,
        'F':5, 'G':6, 'H':7, 'I':8, 'J':9,
        'K':10, 'L':11, 'M':12, 'N':13, 'O':14,
        'P':15, 'Q':16, 'R':17, 'S':18, 'T':19,
        'U':20, 'V':21, 'W':22, 'X':23, 'Y':24, 'Z':25}

def inverse_dict(d):
    return {v:k for k,v in d.items()}

i_dict = inverse_dict(dict)

for i in range(len(S)):
  print(i_dict[(dict[S[i]] + N) % 26], end="")

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

ll n,a,b;
ll h[100005];

bool isok(ll key){
    ll count=0;
    for(ll i=0;i<n;i++){
        count+=max((h[i]-(b*key)+a-b-1)/(a-b),0LL);
    }
    return count<=key;
}

int main(){
    cin >> n >> a >> b;
    for(ll i=0;i<n;i++) cin >> h[i];
    ll ng=-1;
    ll ok=1e9+7;
    while(ok-ng>1){
        ll mid=(ng+ok)/2;
        if(isok(mid)) ok=mid;
        else ng=mid;
    }
    cout << ok << endl;
}


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

using ll = long long;

int main(){

  ll n;
  cin >> n;

  ll count=0;

  vector<pair<ll,int>> nums;
  ll now=1;


  if(n==1){
    cout << 0 << endl;
    return 0;
  }

  while(1){
    now++;
    if(now*now>n){
      if(n!=1){
        nums.emplace_back(n,1);
      }
      break;
    }


    if(n%now==0){
      count=1;
      n/=now;
      while(1){
        if(n%now!=0){
          nums.emplace_back(now,count);
          break;
        }else if(n%now==0){
          count++;
          n/=now;
        }
      }
    }

  }

  ll time=0;
  ll ans=0;
  ll fi;
  ll sec;
  for(auto& x:nums){
    //cout << x.first << ":" << x.second << endl;
    fi=x.first;
    sec=x.second;
    time=0;
    while(1){
      time++;
      if(time>sec){
        break;
      }else{
        ans++;
        sec=sec-time;
        // cout << "time:" << time << endl;
        // cout << "sec:" << sec << endl;
        // cout << "ans:" << ans << endl;
      }
    }
  }

  cout << ans << endl;




}

Measured memory_bytes: 3616
#include <stdio.h>

void swap(int *x, int *y)
{
        *x = *x ^ *y;
        *y = *x ^ *y;
        *x = *x ^ *y;
}

void bsort(int list[10])
{
        int needAgain = 0;
        int i;
        do {
                needAgain = 0;
                for(i = 0; i <= 8; i++) {
                        if(list[i]<list[i+1]) {
                                swap(&list[i],&list[i+1]);
                                needAgain = 1;
                        }
                }
        }while(needAgain);
}

int main()
{
        int heights[10];
        int i;
        for(i = 0; i < 10; i++) {
                scanf("%d",&heights[i]);
        }
        bsort(heights);
        for(i = 0; i < 3; i++) {
                printf("%d\n",heights[i]);
        }
        return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	int ar[b+1]={0};
	int cnt=0;
	for(int i=0;i<a;i++){
		int k;
		cin>>k;
		for(int j=0;j<k;j++){
			int z;
			cin>>z;
			ar[z]++;
			if(ar[z]==a){
				cnt++;
			}
		}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 256
defmodule Main do
  use Bitwise

  def main do
    [h, w, k] = IO.gets("")
                |> String.split()
                |> Enum.map(&String.to_integer/1)
    board = IO.stream(:stdio, :line)
           |> Enum.take(h)
           |> Enum.map(&String.trim/1)
           |> Enum.map(&String.codepoints/1)
           |> Enum.with_index()

    board
    |> calc(h, w, k)
    |> IO.puts()

  end

  def calc(board, h, w, k) do
    Enum.reduce(0..(1<<<h)-1, 0, fn x, acc0 ->
      Enum.reduce(0..(1<<<w)-1, 0, fn y, acc1 ->
        Enum.reduce(0..h-1, 0, fn i, acc2 ->
          Enum.reduce(0..w-1, acc2, fn j, acc3 ->
            board
            |> at(i, j)
            |> count({x, y}, {i, j}, acc3)
          end)
        end)
        |> add(k)
        |> Kernel.+(acc1)
      end) + acc0
    end)
  end

  defguard is_valid(cell, x, y, i, j) when (x>>>i &&& 1) == 0 and (y>>>j &&& 1) == 0 and cell=="#"

  def count(cell, {x, y}, {i, j}, acc) when is_valid(cell, x, y, i, j), do: acc+1
  def count(_, _, _, acc), do: acc

  def at(board, i, j) do
    board
    |> Enum.filter(fn {_, idx} -> idx==i end)
    |> List.first()
    |> elem(0)
    |> Enum.at(j)
  end

  def add(sum, k) when sum == k, do: 1
  def add(_, _), do: 0

end


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

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 300005
#define MOD 1000
#define oo 1000000000000000007LL
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, dp[2][maxN];
char s[maxN];

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

    fto(i, 1, n) {
        fto(c, 0, 1) dp[c][i] = dp[c][i-1];
        if (s[i-1] == 'W') ++dp[0][i];
        else ++dp[1][i];
    }

    int ans = maxN;
    fto(i, 1, n) {
        ans = min(ans, dp[0][i-1]+dp[1][n]-dp[1][i]);
    }

    printf("%d", ans);


    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007

int N;
vector<int> G[200100];
int memo[200100];
int ans = 0;

int mod_pow(int a, int n) {
    int res = 1;
    while (n>0) {
        if (n&1) res = res*a%MOD;
        a = a*a%MOD;
        n >>= 1;
    }
    return res;
}

int dfs(int v, int pv) {
    if (memo[v]!=-1) return memo[v];
    
    int res = 1;
    int add = mod_pow(2, N-1)-1;
    
    for (auto nv : G[v]) {
        if (nv==pv) continue;
        add -= mod_pow(2, dfs(nv, v))-1;
        if (add<0) add += MOD;
        res += dfs(nv, v);
    }
    
    add -= mod_pow(2, N-res)-1;
    if (add<0) add += MOD;
    ans += add;
    ans %= MOD;
    
    return memo[v] = res;
}

signed main() {
    cin >> N;
    
    for (int i=0; i<N-1; i++) {
        int ai, bi; cin >> ai >> bi;
        G[ai-1].push_back(bi-1);
        G[bi-1].push_back(ai-1);
    }
    
    for (int i=0; i<N; i++) memo[i] = -1;
    dfs(0, -1);
    
    ans *= mod_pow(mod_pow(2, N), MOD-2);
    ans %= MOD;
    
    cout << ans << endl;
}

Measured memory_bytes: 24192
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE long long
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
double dmax(double a,double b){
    return a>b?a:b;
}

int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}

int main(void){
    int i, j, n;
    n = in();
    int v[n];
    rep(i, n){
        v[i] = in();
    }
    int ans;
    int a[100001], b[100001];
    rep(i, 100001){
        a[i] = 0;
        b[i] = 0;
    }
    rep(i, n/2){
        a[v[2*i]]++;
        b[v[2*i+1]]++;
    }
    int max_a=0, max_a_1=0;
    int max_b=0, max_b_1=0;
    rep(i, 100001){
        if(a[max_a]<=a[i]){
            max_a_1 = max_a;
            max_a = i;
        }
        else if(a[max_a_1]<a[i]) max_a_1 = i;
        if(b[max_b]<=b[i]){
            max_b_1 = max_b;
            max_b = i;
        }
        else if(b[max_b_1]<b[i]) max_b_1 = i;
    }
    if(max_a==max_b){
        if(a[max_a]+b[max_b_1]>=a[max_a_1]+b[max_b]) max_b = max_b_1;
        else max_a = max_a_1;
    }
    ans = n - a[max_a] - b[max_b];
    print(ans);
    return 0;
}

Measured memory_bytes: 1280
//#define _USE_MATH_DEFINES
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }
inline int safe_mul(const int x, const int y) __attribute__ ((warn_unused_result));


int main()
{
//    freopen("in.txt","r", stdin);
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    vector<vector<char>> mask;
    int const ZZ = 'z' - 'a' + 1;
    while (n--) {
        string s;
        cin >> s;
        vector<char> cnt(ZZ, 0);
        for (char c : s)
            ++cnt[c - 'a'];
        mask.push_back(cnt);
    }
    sort(begin(mask), end(mask));
    int64_t ans = 0;
    for (auto it = mask.begin(); it != mask.end();) {
        auto nit = it;
        while (nit != mask.end() && *it == *nit)
            ++nit;
        int64_t c = distance(it, nit);
        ans += c * (c - 1) / 2;
        it = nit;
    }
    cout << ans << endl;
}


Measured memory_bytes: 10032
#include<bits/stdc++.h>
    #define ll long long
    #define debug(a) cout<<a<<endl
    #define MOD 1000000007
    using namespace std;
    ll pwr2[100009];
    void pow2(ll b){
        for(ll i=1;i<=b;i++){
            pwr2[i]=(pwr2[i-1]*2)%MOD;
        }
    }
    int main()
    {
        pwr2[0]=1;
        map<char,ll> cont;
        ll ans=1,n,ld=0,qtd=0;
        cin>>n;
        pow2(n);
        string s;
        cin>>s;
        for(int i=0;i<n;i++){
            cont[s[i]]++;
            ld+=(cont[s[i]]==1);
        }
        ll tirar=1;
        for(map<char,ll>:: iterator it=cont.begin();it!=cont.end();it++){
            ans=(ans*(it->second+1))%MOD;
        }

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


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int A,B;
  cin>>A>>B;
  int num=B-A;
  int T=0;
  rep(i,num)T+=i;
  int ans=T-A;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3676
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: String
    };

    let s: String = s;

    let (a, b): (i32, i32) = (
        s[..=1].parse::<i32>().unwrap(),
        s[2..].parse::<i32>().unwrap(),
    );

    let ans = match (a, b) {
        (1..=12, 1..=12) => "AMBIGUOUS",
        (_, 1..=12) => "YYMM",
        (1..=12, _) => "MMYY",
        _ => "NA",
    };

    println!("{}", ans);
}


Measured memory_bytes: 2200
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a>b)swap(a,b);
	if(b>c)swap(b,c);
	if(a>b)swap(a,b);
	cout<<a<<" "<<b<<" "<<c<<"\n";
	return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main( ) {
    //freopen("A.01.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,a;
    cin >> n >> a;
    if(n%500<=a){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


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

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

using namespace std;

ll a[1000], b[1000], c[1000];
ll x[1000];

int main()
{
  ll result = -1;
  int n, m;
  cin >> n >> m;
  REP(i, n)
  {
    cin >> a[i] >> b[i] >> c[i];
  }

  REP(j, 8)
  {
    REP(i, n)
    {
      x[i] = 0;
      if ((j & 1) == 0)
      {
        x[i] += a[i];
      }
      else
      {
        x[i] += -a[i];
      }
      if ((j & 2) == 0)
      {
        x[i] += b[i];
      }
      else
      {
        x[i] += -b[i];
      }
      if ((j & 4) == 0)
      {
        x[i] += c[i];
      }
      else
      {
        x[i] += -c[i];
      }
    }
    sort(x, x + n, greater<ll>());

    ll tmp = 0;
    REP(i, m)
    {
      tmp += x[i];
    }
    if (tmp > result)
    {
      result = tmp;
    }
  }
  cout << result << endl;
}


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

bool is_alpha(char c) {
    return (c >= 'a') && (c <= 'z');
}

int main(int argc, const char * argv[]) {
    char S[20] = {0};
    int counter = 0;
    
    cin >> S;
    
    if (S[0] != 'A') {
        cout << "WA" << endl;
        return 0;
    }
    
    for (int i = 2; i <= strlen(S) - 2; i++) {
        if (S[i] == 'C') {
            counter++;
        }
    }
    if (counter != 1) {
        cout << "WA" << endl;
        return 0;
    }
    
    for (int i = 1; i < strlen(S); i++) {
        if (S[i] != 'C') {
            if (!is_alpha(S[i])) {
                cout << "WA" << endl;
                return 0;
            }
        }
    }
    
    cout << "AC" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ls x<<1
#define rs x<<1|1
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
const ull hashp=1e7+19;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=5e3+100;
char s[maxn];
ull hashval[maxn],mi[maxn]={1};
void init_hash(int n){
	rep1(i,n){
		hashval[i]=hashval[i-1]*hashp+(ull)(s[i]-'a');
		mi[i]=mi[i-1]*hashp;
	}
}
ull gethash(int l,int r){
	return hashval[r]-hashval[l-1]*mi[r-l+1];
}
int check(int x,int n){
	for(int i=1;i<=n-x*2+1;i++)
		for(int j=i+x;j<=n-x+1;j++)
			if(gethash(i,i+x-1)==gethash(j,j+x-1))return 1;return 0;
		
}
void solve()
{
	int n;scd(n);
	scanf("%s",s+1);
	init_hash(n);
	int l=0,r=n/2,ans;
	while(l<=r){
		int mid=l+r>>1;
		if(check(mid,n)){
			l=mid+1;
			ans=mid;
		}
		else r=mid-1;
	}
	ac;
}
int main(){
    //IOS;
    //freopen("D://data.txt","r",stdin);
    solve();
    return 0;
}


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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

string youbi[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};

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

    int ans = 0;
    REP(i,7){
        if(s == youbi[i]){
            ans = 7 - i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
dp=[999999999]*n
dp[0]=0
for i in range(len(arr)):
    for j in range(i,i+k+1):
        if j<n:
            dp[j]=min(dp[j],dp[i] + abs(arr[j] - arr[i]))
    #print(dp)
print(dp[n-1])

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

#define ll long long

int main()
{
    ll n, w;
    cin >> n >> w;

    vector<pair<ll, ll>> wv(n + 1);

    for(ll i = 1; i <= n; i++)
    {
        cin >> wv[i].first >> wv[i].second;
    }

    ll sumValue = 0;

    for(ll i = 1; i <= n; i++)
    {
        sumValue += wv[i].second;
    }

    vector<ll> dp(sumValue + 1, 1e18L);

    dp[0] = 0;

    for(ll i = 0; i <= n; i++)
    {
        for(ll j = sumValue - wv[i].second; j >= 0; j--)
        {
            dp[j + wv[i].second] = min(dp[j + wv[i].second], wv[i].first + dp[j]);
        }
    }

    ll ans = 0;

    for(ll i = 1; i <= sumValue; i++)
    {
        if(dp[i] <= w)
        {
            ans = max(ans, i);
        }

        //cout << dp[i] << " ";
    }

    //cout << "\n";

    cout << ans;

    return 0;
}

Measured memory_bytes: 4028
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
 
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for (int i=a; i<b; i++)
// #define endl "\n"
const int mod = 1000000007;

ll power(ll x, ll y) 
{ 
    ll res = 1;     // Initialize result 
   
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = res*x; 
        res%=mod;
        // n must be even now 
        y = y>>1; // y = y/2 
        x = x*x;
        x%=mod;  // Change x to x^2 
    } 
    return res%mod; 
}

int main() {
    ios_base::sync_with_stdio(false);    //Fast I/O
    cin.tie(NULL);
 
    // freopen("input.txt", "r", stdin);    // Read and write from a file
    // freopen("output.txt", "w", stdout);
    int n, m, k;
    cin >> n >> m >> k;

    vector<vector<int> > arr(n, vector<int> (m,0));
    vector<vector<int> > nax(n, vector<int> (m,0));
    string tmp;
    vector<int> nax1(n, 0);
    int count;
    for(int i=0; i<n; i++){
        cin >> tmp;
        count=0;
        for(int j=0;j<m;j++){
            if(tmp[j]=='.')
                arr[i][j]=0;
            else{
                arr[i][j]=1;
                count++;
            }
        }
        nax1[i]=count;
    }
    stack<int> stk;
    int straw=1;
    int cum_sum=0;
    int last=0;
    for(int i=0; i<n; i++){
        if(nax1[i]==0)
            stk.push(i);
        else{
            straw=cum_sum+1;
            cum_sum+=nax1[i];
            for(int j=0; j<m; j++){
                nax[i][j]=straw;
                if(arr[i][j]==1 && straw<cum_sum)
                    straw++;
            }
            while(!stk.empty()){
                int tes = stk.top();
                stk.pop();
                nax[tes]=nax[i];
            }
            last=i;
        }
    }

    while(!stk.empty()){
        int tes = stk.top();
        stk.pop();
        nax[tes]=nax[last];
    }

    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++)
            cout << nax[i][j] << " ";
        cout << endl;
    }
 
 
    return 0;
}

Measured memory_bytes: 1536
#include<cstdio>
#include<iostream>
#define NIL -1
using namespace std;
int main(){
    int m,f,r =0;
    
    while(1){
        scanf("%d %d %d",&m,&f,&r);
        if(m == NIL && f == NIL && r == NIL) break;
        if ( m == NIL || f == NIL) printf("F\n");
        else if(m+f>= 30 && m+f<50){
            if(r>=50){
                printf("C\n");
            }else{
                printf("D\n");
            }
        }else if(m+f>= 50 && m+f<65){
            printf("C\n");
        }else if(m+f>= 65 && m+f<80){
            printf("B\n");
        }else if(m+f>= 80){
            printf("A\n");
        }else
        {
            printf("F\n");
        }

        
    }
    return 0;
}



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

int main() {
  long N;
  cin >> N;
  vector<int> a(N);
  if(N%2==0){
    int idx=N/2;
    for(int i=0;i<N;i++){
      //cout<<idx<<endl;
      cin>>a[idx];
      if(i%2==1) idx+=(i+1);
      else idx-=(i+1);
    }
  }
  else{
    int idx=N/2;
    for(int i=0;i<N;i++){
      cin>>a[idx];
      if(i%2==1) idx-=(i+1);
      else idx+=(i+1);
    }
  }

  for(int i=0;i<N;i++){
    if(i==N-1) cout<<a[i]<<endl;
    else cout<<a[i]<<" ";
  }

  }


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    vector<int>cnt(1e6,0);
    for(int x:a){
        if(x-1>=0) cnt[x-1]++;
        cnt[x]++;
        cnt[x+1]++;
    }
    sort(cnt.begin(),cnt.end());
    reverse(cnt.begin(),cnt.end());
    cout << cnt[0] << endl;
}

Measured memory_bytes: 7400
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N, H, W = ni()
    val ans = (N - H + 1) * (N - W + 1)
    out.println(ans)
  }


  def debug(as: Array[Boolean]): Unit = {
    System.err.println(as.map(x => if(x) "1" else "0").mkString)
  }

  def debug(as: Array[Int]): Unit = {
    System.err.println(as.mkString(" "))
  }

  def debug(as: Array[Long]): Unit = {
    System.err.println(as.mkString(" "))
  }

  def debug(s: String): Unit = {
    System.err.println(s)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }


  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

Measured memory_bytes: 25524
#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,M; cin>>N>>M;
    vint a(N),b(N),c(M),d(M);
    REP(i,N) cin>>a[i]>>b[i];
    REP(i,M) cin>>c[i]>>d[i];

    REP(i,N){
        int min_dist=1e18,min_idx=-1;
        REP(j,M){
            int dist=abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(dist<min_dist){
                min_dist=dist;
                min_idx=j+1;
            }
        }
        cout<<min_idx<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define len(x) (int) (x.size())
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> myvs(n);
    for(int i = 0; i < n; i++) cin >> myvs[i];

    int ans = 0, seq = 0;
    for(int i = 0; i < n; i++) {
        if (i > 0 && myvs[i] <= myvs[i-1]) seq++;
        else seq = 0;
        ans = max(seq, ans);
    }
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#define LEN 101
int main(void)
{
  int i,n;
  char str[2][LEN];
  int point[2];
  int cmp;
  point[0]=point[1]=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%s %s",str[0],str[1]);
      cmp=strcmp(str[0],str[1]);
      if(cmp>0) point[0]+=3;
      else if(cmp<0) point[1]+=3;
      else
        {
          point[0]++;
          point[1]++;
        }
    }
  printf("%d %d\n",point[0],point[1]);
  return 0;
}


Measured memory_bytes: 2036
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Diagnostics;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    
    class Solve
    {
        const int mod = 1000000007;
        
        
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            int A = int.Parse(Console.ReadLine());
            int B = int.Parse(Console.ReadLine());
            int C = int.Parse(Console.ReadLine());
            int X = int.Parse(Console.ReadLine());

            long ans = 0;
            for(var i = 0; i <= A; i++)
            {
                for(var j = 0; j <= B; j++)
                {
                    int r = X - 500 * i - 100 * j;
                    if (r >= 0 && r % 50 == 0 && r / 50 <= C)
                    {
                        ans++;
                    }
                }
            }

            Console.WriteLine(ans);

            //Console.Out.Flush();

        }

        
    }

    public class Calculation
    {

    }

    public class Graph
    {
        
    }
}




Measured memory_bytes: 13140
#include<algorithm>
#include<chrono>
#include<ctime>  
#include<climits>
#include<functional>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
// #include<bits/stdc++.h>
using namespace std;
 
struct Debug{
    int cnt = 0;
    bool on = false;
    char debug[10] = "debug";
    template<class T>
    Debug & operator<<(const T & v) {
        if(on && cnt++ == 0) cerr << "debug: ";
        if(on) cerr << v << ' ';
        return *this;
    }
    Debug & operator<<(ostream&(*pManip)(ostream&)) {
        if(on) cerr << (*pManip);
        cnt = 0;
        return *this;
    }
} debug;
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {if(debug.on){for(auto x : v) debug << x; debug << endl;}}
#define printn(v, n) {if(debug.on){for(int _i = 0; _i < n; _i++) debug << *(v + _i); debug << endl;}}
 
typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

const int MAXN = 5e5 + 10;


int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout.tie(nullptr);
    if(argc > 1 && !strcmp(argv[1], debug.debug)) debug.on = true;

    string s;
    cin >> s;
    int n = s.size();
    int a[MAXN] = {};

    int i = 0, j;
    while(i < n) {
    	for(j = i; j < n && s[j] == s[i]; j++);
    	if(s[i] == '<') {
    		for(int k = i; k <= j; k++)
    			a[k] = k - i;
    	}
    	else {
    		a[i] = max(a[i], j - i);
    		for(int k = j; k > i; k--)
    			a[k] = j - k;
    	}
    	// debug << i << j << endl;
    	// printn(a, n + 1);
    	i = j;
    }
    long long res = accumulate(a, a + n + 1, 0LL);
    cout << res << endl;

    return 0;
 
}














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


for a in A:
    if a % 2 == 1:
        # 奇数個のりんごの木が一つでもあれば、先行がそれをとり、後攻にEの状態を押し付けるので先行の勝ち
        print("first")
        exit()

print("second")

Measured memory_bytes: 7072
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

template <typename T>
vector<T> dijkstra(int s, vector<vector<pair<int, T>>> &G) {
    const T INF = numeric_limits<T>::max();
    using P     = pair<T, int>;
    int n       = G.size();
    vector<T> d(n, INF);
    vector<int> b(n, -1);
    priority_queue<P, vector<P>, greater<P>> q;
    d[s] = 0;
    q.emplace(d[s], s);
    while (!q.empty()) {
        P p = q.top();
        q.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;
        for (auto &e : G[v]) {
            int u = e.first;
            T c   = e.second;
            if (d[u] > d[v] + c) {
                d[u] = d[v] + c;
                b[u] = v;
                q.emplace(d[u], u);
            }
        }
    }
    return d;
}

int main() {
    ll n, u, v;
    cin >> n >> u >> v;
    u--, v--;

    vector<vector<pii>> edges(n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        edges[a].emplace_back(b, 1);
        edges[b].emplace_back(a, 1);
    }

    if (u == v) {
        cout << 0 << "\n";
        return 0;
    }
    auto dist  = dijkstra(u, edges);
    auto dist2 = dijkstra(v, edges);

    int atot = dist2[u];
    atot /= 2;

    vector<vector<pii>> edges2(n);
    for (int i = 0; i < n; ++i) {
        if (dist2[i] > atot) {
            for (auto &p : edges[i]) {
                if (dist2[p.first] > atot)
                    edges2[i].emplace_back(p.first, p.second);
            }
        }
    }
    auto dist3 = dijkstra(u, edges2);
    int ret    = 0;
    for (int i = 0; i < n; ++i) {
        if (dist3[i] < 10000000)
            chmax(ret, dist2[i]);
    }
    cout << ret - 1 << "\n";

    return 0;
}

Measured memory_bytes: 14232
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<ld> vld;

#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()

int main()
{
	fastIO;
	int n; cin >> n;
	vll l(n);
	for(int i = 0; i < n; i++) cin >> l[i];
	if(n < 3) cout << 0 << endl;
	else
	{
		int cnt = 0;
		for(int i = 0; i < n; i++)
			for(int j = i + 1; j < n; j++)
				for(int k = j + 1; k < n; k++)
				{
					ll sum = l[i] + l[j] + l[k];
					if(l[i] == l[j] || l[i] == l[k] || l[j] == l[k]) continue;
					if(sum > 2*l[i] && sum > 2*l[j] && sum > 2*l[k]) 
						cnt++;
				}
		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <cstdlib>
#include <string.h>
#include <string>
#include <cstring>
using namespace std;

int main(){
	int N;
	cin >> N;
	int data[N];
	int count[100000];
	for(int i=0;i<N;i++){
		cin >> data[i];
	}

	for(int i=0;i<100000;i++){
		count[i]=0;
	}

	int j=0;
	for(int i=0;i<N;i++){
		j= data[i];
		if(j==0){
			count[0]++;
			count[1]++;
		}else if(j==99999){
			count[99998]++;
			count[99999]++;
		}else{
			count[j-1]++;
			count[j]++;
			count[j+1]++;
		}
	}

	int max=count[0];
	for(int i=1;i<99999;i++){
		if(max < count[i]){
			max = count[i];
		}
	}
	cout << max << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

int main() {
	
	int n;
	char s[n];
	
	scanf("%d", &n);
	
	scanf("%s", s);
	
	int ctr=0;
	
	for(int i=0, j=n/2; i<n; i++, j++){
		if(s[i]==s[j]){
			ctr++;
		}
	}
	
	if(n%2==0 && ctr==n/2){
		printf("Yes\n");
	}
		
	else{
		printf("No\n");
	}
	
	return 0;
}

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


main(){
   ll r,d,x,ans,i;
   cin >> r >> d >> x;

   for(i=0;i<10;i++){
       ans = r*x-d;
       x=ans;
       cout << ans << endl; 
   }
}

Measured memory_bytes: 256
N,T = map(int, input().split())
c = []
t = []

for i in range(N):
    a,b = map(int, input().split())
    c.append(a)
    t.append(b)

m = 100000
for i in range(len(c)):
    if t[i]<= T:
        if m > c[i]:
            m = c[i]
if m == 100000:
    print("TLE")
else:
    print(m)


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

public class Main {

   static List<Integer> al[];
    private  static void solver(InputReader sc, PrintWriter out) {
      int n = sc.nextInt();
      double ans = n/3.0;
      ans = (ans * ans * ans);
      out.printf("%.12f",ans);
    }

    public static void main(String[] args) throws Exception{
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in,out);
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong(){
            return Long.parseLong(next());
        }

        public long[] readLongArr(int n){
            long arr[] = new long[n];
            for(int i=0; i<n; i++){
                arr[i] = nextLong();
            }
            return arr;
        }
        public int[] readIntArr(int n){
            int arr[] = new int[n];
            for(int i=0; i<n; i++){
                arr[i] = nextInt();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 21204
using System;
using System.Collections;
using System.Collections.Generic;

class Program {

    static void Main (string[] args) {
        string[] str = Console.ReadLine ().Split (' ');
        int N = int.Parse (str[0]);
        int M = int.Parse (str[1]);
        int X = int.Parse (str[2]);

        int[, ] list = new int[N, M + 1];

        for (int i = 0; i < N; i++) {
            string[] temp = Console.ReadLine ().Split (' ');
            for (int j = 0; j < M + 1; j++) {
                list[i, j] = int.Parse (temp[j]);
            }
        }

        int total = int.MaxValue;
        for (int i = 0; i < Math.Pow (2, N); i++) {
            int[] temp = new int[M + 1];
            for (int k = 0; k < N; k++) {
                if (((i >> k) & 1) == 1) {
                    temp[0] += list[k, 0];
                    for (int x = 0; x < M; x++) {
                        temp[x + 1] += list[k, x + 1];
                    }
                }
            }
            bool ans = true;
            for (int j = 0; j < M; j++) {
                if (temp[j + 1] < X) {
                    ans = false;
                    break;
                }
            }
            if (ans) {
                total = Math.Min (total, temp[0]);
            }
        }
        if (total == int.MaxValue) {
            total = -1;
        }
        Console.WriteLine (total);
    }
}

Measured memory_bytes: 28192
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 998244353
typedef long long ll;

using namespace std;
#define N 5010
class Comb{public:
    ll inv[N],fact[N],invfact[N];
    void init(){
	inv[1]=fact[0]=invfact[0]=1;
	for(ll i=1;i<N;i++){
	    if(i>1)inv[i]=(mod-((mod/i)*inv[mod%i]%mod))%mod;
	    fact[i]=fact[i-1]*i%mod;
	    invfact[i]=invfact[i-1]*inv[i]%mod;
	}
    }
    ll C(ll n,ll k){
	if(n<0||k<0||n<k)return 0;
	return fact[n]*invfact[n-k]%mod*invfact[k]%mod;
    }
};
Comb C;

class Pow{public:
    ll res[N];
    void init(){
	res[0]=1;
	for(ll i=1;i<N;i++)res[i]=res[i-1]*2%mod;
    }
    ll P(ll x){
	if(x<0)return 0;
	return res[x];
    }
};
Pow P;


ll V(ll n,ll k,ll a,ll b,ll p){
    ll res=C.C(a+n-1,n-p);
    res=res*C.C(b,p)%mod;
    res=res*P.P(p)%mod;
    return res;
}
ll B(ll n,ll k,ll m){
    if(m%2==0)m++;
    ll a=k-m+1,b=m/2;
    //cout<<m<<" "<<a<<" "<<b<<endl;
    ll sum=0;
    for(ll p=0;p<=b;p++){
	sum+=V(n,k,a,b,p);
    }
    return sum%mod;
}
int main(){
    C.init(); P.init();
    vector<ll> ans;
    ll n,k;cin>>k>>n;
    for(ll m=2;m<=k;m++){
	ans.push_back(B(n,k,m));
    }
    for(auto x:ans)cout<<x<<endl;
    cout<<B(n,k,k+1)<<endl;
    reverse(ans.begin(),ans.end());
    for(auto x:ans)cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,PA,PB;
  PA = 0;
  PB = 0;
  cin >> N;
  vector<int> C(N);
  
  for(int i = 0;i < N;i++){
    cin >> C.at(i);
  }

  sort(C.begin(),C.end());
  reverse(C.begin(),C.end());

  for(int i = 0;i < N;i++){
    if(i%2 == 1){
      PA += C.at(i);
    }else {
      PB += C.at(i);
    }
  }
  cout << max(PA,PB)-min(PA,PB) << endl;
}

Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n,y;
	cin>>n>>y;
	for(int i=0;i<=n;i++) {
		for(int j=0;j<=n-i;j++) {
				if(i*10000+j*5000+(n-i-j)*1000==y) {
					cout<<i<<" "<<j<<" "<<n-i-j;
					return;
				}
			
		}
	}
	cout<<"-1 -1 -1";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3604
//author: hitch_hiker42;
#include "bits/stdc++.h"
using namespace std;
 
//solution:
#define int int64_t
#define span(a) begin(a), end(a)
 
void hike() {
    int n; cin >> n;
   	vector<int> a(n);
  	for(int& i: a) cin >> i;
  	sort(span(a), greater<int>());
  	int cost = a.front(), j = 1;
    for(int i = n - 2; i > 0; i -= 2, ++j) {
        cost += a[j] << 1;
    }
    if(n % 2 == 0) cout << cost << "\n";
    else cout << cost - a[j - 1] << "\n";
}
 
signed main() {
    int t = 1; //cin >> t;
    while(t--) hike();
    return 0;
} //farewell, until we meet again..

Measured memory_bytes: 4796
int main(){
  long long int A,B,K;
  scanf("%lld %lld %lld",&A,&B,&K);
  if(A>K){
    A-=K;
  }else if(A+B<=K){
    A=B=0;
  }else{
    B-=K-A;
    A=0;
  }
  printf("%lld %lld\n",A,B);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define MAX 8
int n, m;
bool graph[MAX][MAX];
bool visited[MAX];

int dfs(int v ){
    bool all_visited = true;
    for(int i=0; i<n; i++) if(visited[i] == false) all_visited = false;
    if(all_visited) return 1;

    int ret = 0;
    for(int i=0; i<n; i++){
        if(graph[v][i] == false) continue;
        if(visited[i]) continue;
        

        visited[i] = true;
        ret += dfs(i);
        visited[i] = false;
    }

    return ret;
}

int main(){
    cin >> n >> m;

    for(int i=0; i<m; i++) {
        int from, to;
        cin >> from >> to;
        from--; to--;
        graph[from][to] = true;
        graph[to][from] = true;
    }

    for(int i=0; i<n; i++) visited[i] = false;
    visited[0] = true;
    cout << dfs(0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

template <class RandomIt>
auto rsort(RandomIt first, RandomIt last)
  -> typename std::enable_if<std::is_integral<
    typename RandomIt::value_type::first_type>::value>::type
{
  using PairType = typename RandomIt::value_type;
  using KeyType = typename PairType::first_type;

  intmax_t cur_shift=0, max_exp=sizeof(KeyType);
  std::vector<PairType> work(last-first);
  for (int i=0; i<max_exp; ++i) {
    size_t num[256]={};

    for (RandomIt it=first; it<last; ++it)
      ++num[((it->first)>>cur_shift)&255];

    {
      size_t tmp=0;
      for (int j=0; j<256; ++j)
        std::swap(tmp, num[j]+=tmp);
    }

    for (RandomIt it=first; it<last; ++it)
      work[num[((it->first)>>cur_shift)&255]++] = std::move(*it);

    {
      size_t j=0;
      for (RandomIt it=first; it<last; ++it)
        *it = std::move(work[j++]);
    }

    cur_shift += 8;
  }

  if (!std::is_signed<KeyType>::value) return;

  RandomIt mid=last;
  for (RandomIt it=last; --it>=first;)
    if ((it->first) >= 0) {
      mid = ++it;
      break;
    }

  if (mid == last)
    return;

  std::copy(first, mid, work.begin()+(last-mid));
  std::copy(mid, last, work.begin());
  std::copy(work.begin(), work.end(), first);
}

int main() {
  size_t W, H;
  scanf("%zu %zu", &W, &H);

  std::vector<std::pair<unsigned, size_t>> es;
  for (size_t j=0; j<H+W; ++j) {
    unsigned p;
    scanf("%u", &p);
    es.emplace_back(p, j);
  }

  rsort(es.begin(), es.end());
  size_t a=W+1, b=H+1;
  uintmax_t res=0;
  for (const auto &e: es) {
    if (e.second < W) {
      res += e.first*b;
      --a;
    } else {
      res += e.first*a;
      --b;
    }
  }

  printf("%ju\n", res);
}


Measured memory_bytes: 7532
r=lambda x:p[x]>=0and r(p[x])or x
(n,m,k),*t=[map(int,t.split())for t in open(0)]
p,s=[-1]*-~n,[-1]*-~n
for i,(a,b)in enumerate(t):
 x,y=sorted((r(a),r(b)))
 if(x!=y)*m>i:p[x]+=p[y];p[y]=x
 if(x!=y)*i<m:s[a]-=1;s[b]-=1
print(*[s[i+1]-p[r(i+1)]for i in range(n)])

Measured memory_bytes: 96856