akhauriyash/Code-Regression huggingface dataset:
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        x: i64,
    }
    let mut max = 0;
    for i in 1..x + 1 {
        for j in 2..1000 {
            let num = (1..j).fold(i, |sum, _| sum * i);
            if num <= x {
                if max < num {
                    max = num;
                }
            } else {
                break;
            }
            if i == 1 {
                break;
            }
        }
    }
    println!("{}", max);
}


Measured memory_bytes: 4352
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    int N;
    cin >> N;

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

    deque<int> Q;

    if (N % 2 == 0) {
        for (int i = 1; i <= N; i++) {
            if (i % 2 == 0) Q.push_back(a[i-1]);
            if (i % 2 == 1) Q.push_front(a[i-1]);
        }
    }
    if (N % 2 == 1) {
        for (int i = 1; i <= N; i++) {
            if (i % 2 == 0) Q.push_front(a[i-1]);
            if (i % 2 == 1) Q.push_back(a[i-1]);
        }
    }

    vector<int> ans;
    while (!Q.empty()) {
        int d = Q.back();
        Q.pop_back();
        ans.push_back(d);
    }

    for (auto x : ans) cout << x << " ";

    return 0;
}





























































Measured memory_bytes: 4728
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
const long long INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    REP(i,n){
        cin >> p[i];
    }

    int num = 0;
    REP(i,n){
        if(p[i]!=i+1){
            num++;
        }
    }

    if(num==2 || num==0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    return 0;
}

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

arr = list(map(int,input().strip().split()))
s = []
a = []
arr.append(0)
for i in range(n+1):
    if arr[i]==0:
        if len(a) > 0:
            s.append(a)
            a = []
    else:
        a.append(arr[i])
ans = 0

#print(s)
while len(s)!=0:
    #ans+=len(s)
    d = []
    #print(s)
    for i in range(len(s)):
        x = min(s[i])
        s[i] = [ s[i][j]-x for j in range(len(s[i])) ]
        a = []
        e = []
        ans+=x
        s[i].append(0)
        for j in range(len(s[i])):
            if s[i][j]==0:
                if len(a) > 0:
                    d.append(a)
                    a = []
            else:
                a.append(s[i][j])
        
    s = d
print(ans)


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

const int MAX_S = 5005;
int Z[MAX_S][MAX_S];

int main()
{
	int N;
	string S;
	cin >> N >> S;

	for (int l = 0; l < S.size(); ++l)
	{
		Z[l][l] = S.size()-l;
		int i = l+1, j = 0;
		while(i < S.size())
		{
			while (i+j < S.size() && S[l+j] == S[i+j]) j++;

			Z[l][i] = j;

			if (j == 0)
			{
				i++;
				continue;
			}

			int k = 1;

			while(i+k < S.size() && k+Z[l][l+k] < j)
			{
				Z[l][i+k] = Z[l][l+k];
				k++;
			}
			i += k;
			j -= k;
		}
		//cout << "a" << endl;
	}

	//cout << "b" << endl;

	int ans = 0;

	for (int i = 0; i < S.size(); ++i)
	{
		for (int j = i; j < S.size(); ++j)
		{
			//cout << Z[i][j] << " ";
			int now = min(Z[i][j],j-i);
			ans = max(ans,now);
		}
		//cout << endl;
	}

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

Measured memory_bytes: 96768
a=int(input())
if a < 10:
    print(a)
elif a<10**2:
    print(9)
elif a<10**3:
    print(9+a%100+1)
elif a<10**4:
    print(909)
elif a<10**5:
    print(909+a-9999)
else:
    print(90909)

Measured memory_bytes: 38256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Globalization;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        SetOut(sw);
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";

    int H, W;
    void solve()
    {
        H = cin.nextint;
        W = cin.nextint;
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                if (cin.next == "snuke")
                {
                    WriteLine(alfa[j].ToString().ToUpper() + (i + 1));
                }

            }
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 2776
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const int M = 1e9 + 7;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};


int main() {
  int n,m;
  cin >> n >> m;
  vector<vector<int>> r(n);
  vector<int> d(n,-1);
  rep(i,m) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    r[a].push_back(b);
    r[b].push_back(a);
  }

  queue<int> q;
  q.push(0);

  while(!q.empty()){
    int k = q.front();
    q.pop();
    rep(i,r[k].size()) {
      if (d[r[k][i]] == -1){
        q.push(r[k][i]);
        d[r[k][i]] = k;
      }
    }
  }

  rep(i, d.size()-1) if(d[i+1] == -1){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  rep(i,d.size()-1) cout << d[i+1] + 1 << endl;

  return 0;
}


Measured memory_bytes: 10192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if(a < b && b < c){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 26228
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p;

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

int main()
{
  ll N;
  cin >> N;
  vector<ll> vec(N);
  for (ll i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  ll c_min=MOD;
  ll count = 0;
  for (ll i = 0; i < N; i++)
  {
    if(c_min>=vec.at(i)){
     c_min = vec.at(i);
     count++;
    }

  }
  cout << count << endl;

}

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

int main()
{

    int num,n,total,pos,c=0,c2=0;
    scanf("%d%d%d",&n,&total,&pos);

    for(int i=0;i<total;i++)
    {
        scanf("%d",&num);

        if(num>pos && num<=n)
            c++;

        else
            c2++;
    }
        int ans= min(c,c2);

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



   return 0;
}



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

using namespace std;

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

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

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

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

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

  cin >> h >> w >> n;
  rep(i, n) {
    cin >> a;
    rep(j, a) que.push(i + 1);
  }

  rep(i, h) {
    if (i % 2 == 0) {
      rep(j, w) {
        ans[i][j] = que.front();
        que.pop();
      }
    } else {
      rrrep(j, w - 1, 0) {
        ans[i][j] = que.front();
        que.pop();
      }
    }
  }

  rep(i, h) {
    rep(j, w) { cout << ans[i][j] << " "; }
    cout << "\n";
  }
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <string.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    long long k;
    cin >> n >> k >> q;
    int a[q];
    int player[n] = {0};
    for (int i=0; i<q; i++) {
        cin >> a[i];
        player[a[i]-1]++;
    }
    
    for (int i=0; i<n; i++) {
        if (k - q + player[i] <= 0) cout << "No\n";
        else cout << "Yes\n";
    }
    return 0;
}

Measured memory_bytes: 4392
n = int(input())
a = [int(item) for item in input().split()]

ans = 0
cur = 1
last = 0

if 1 not in a:
    print(-1)
else:
    for i in range(n):
        if a[i] == cur:
            ans += last
            last = 0
            cur += 1
        else:
            last += 1

    print(ans + last)


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

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    long long ans=0;
    long long R=0;
    long long B=0;
    long long G=0;
    long long count = 0;
    for(int i=0;i<N;i++)
    {
        if(S[i] == 'R') R++;
        if(S[i] == 'G') G++;
        if(S[i] == 'B') B++;
        for(int j=N-1;j>i+1;j--)
        {
            if((i+j)%2 ==0)
            {
                char temp = S[(i+j)/2];
                if(temp != S[j] && temp != S[i] && S[j] != S[i])
                    count++;
            }
        }
    }
    // Ans = R*G*B - count
    //cout << count << endl;
    cout << R*G*B-count << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;

int main()
{
    int n, m;
    cin >> n >> m;
    ll a[100002], c[100002];
    int b[100002];
    P p[100002];
    ll sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    sort(a, a + n);
    for(int i = 0; i < m; i++){
        cin >> b[i] >> c[i];
        p[i] = P(c[i], b[i]);
    }
    sort(p, p + m, greater<P>());
    int j = 0;
    int now = 0;
    for(int i = 0; i < n; i++){
        if(a[i] < p[j].first){
            sum += p[j].first - a[i];
        }
        now++;
        if(now == p[j].second){
            now = 0;
            j++;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin>>n;
 n=n%10;
  if(n==2||n==4||n==5||n==7||n==9)
    cout<<"hon";
  else if(n==3)
    cout<<"bon";
  else
    cout<<"pon";
}

Measured memory_bytes: 3608
import java.io.IOException;
import java.util.Scanner;

public class Main {

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

		Scanner scan = new Scanner(System.in);
		int a[][] = new int[3][3];
		int n;
		final int select = 500;

		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				a[i][j] = scan.nextInt();
			}
		}

		n = scan.nextInt();

		int inputN[] = new int[n];
		for (int n_count = 0; n_count < n; n_count++) {
			inputN[n_count] = scan.nextInt();

			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {

					if (a[i][j] == inputN[n_count]) {
						a[i][j] = select;
					}

				}
			}
		}

		//最後に確認
		//行確認
		//1行目 =
		int first_row = a[0][0] + a[0][1] + a[0][2];
		int secont_row = a[1][0] + a[1][1] + a[1][2];
		int third_row = a[2][0] + a[2][1] + a[2][2];

		//列
		int first_col = a[0][0] + a[1][0] + a[2][0];
		int secont_col = a[0][1] + a[1][1] + a[2][1];
		int third_col = a[0][2] + a[1][2] + a[2][2];
		//斜め1
		int naname1 = a[0][0] + a[1][1] + a[2][2];
		int naname2 = a[0][2] + a[1][1] + a[2][0];

		if (first_row == 1500) {
			System.out.println("Yes");
			return;
		}

		if (secont_row == 1500) {
			System.out.println("Yes");
			return;
		}
		if (third_row == 1500) {
			System.out.println("Yes");
			return;
		}

		if (first_col == 1500) {
			System.out.println("Yes");
			return;
		}
		if (secont_col == 1500) {
			System.out.println("Yes");
			return;
		}
		if (third_col == 1500) {
			System.out.println("Yes");
			return;
		}

		if (naname1 == 1500) {
			System.out.println("Yes");
			return;
		}

		if (naname2 == 1500) {
			System.out.println("Yes");
			return;
		}

		System.out.println("No");

		//ビンゴカード作成
		//		int bingoCard[][] = new int[3][3];
		//		for (int i = 0; i < 3; i++) {
		//			for (int j = 0; j < 3; j++) {
		//				a[i][j] = 0;
		//			}
		//		}

	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。ｓ
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param a 基数
	 * @param n 乗数
	 * @param primeNumMod 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myModPow(long a, long n, long primeNumMod) {

		long ans = 1;

		//乗数が0の場合→1
		if (n == 0)
			return 1;

		if (primeNumMod == 0) {
			//modを使わないとき

			while (n > 0) {

				if (n % 2 == 0) {
					//累乗が偶数の時

					a *= a;
					n = n / 2;
				} else {
					//累乗が奇数の時
					ans *= a;
					n--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			a = myMod(a, primeNumMod);

			while (n > 0) {

				if (n % 2 == 0) {
					//累乗が偶数の時

					a *= myMod(a, primeNumMod);
					n = n / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(a, primeNumMod);
					n--;

				}
			}

			return myMod(ans, primeNumMod);

		}

	}

}


Measured memory_bytes: 21716
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
const int mod = 1e9 + 7;

int main()
{
	char s1[20], s2[20], s3[20];
	int ans = 0;
	int ls1, ls2, ls3;
	scanf("%s", &s1);
	scanf("%s", &s2);
	scanf("%s", &s3);
	ls1 = strlen(s1);
	ls2 = strlen(s2);
	ls3 = strlen(s3);
	if(s1[ls1 - 1] == s2[0])
		ans++;
		if(s2[ls2 - 1] == s3[0])
			ans++;
			if(ans == 2)
				printf("YES\n");
				else
					printf("NO\n");
				


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    //freopen("in.txt", "r", stdin);
    int n;
    cin>>n;
    int a[n+3];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    int fuck=1;
    int cnt=0;
    for(int i=0;i<n;i++){
        if(a[i]==fuck) fuck++;
        else cnt++;
    }
    if(cnt==n){
        cout<<"-1"<<endl;
    }
    else{
        cout<<cnt<<endl;
    }
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define maxN 3000

int gcd(int a, int b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);

}

bool comp(int a, int b) {
	return abs(a) > abs(b);
}



int main()
{

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	{
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
#endif
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans = max((a * c), max(a * d, max(b * c, b * d)));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3648
n = int(input())
l = [input() for _ in [0]*n]
#print(l)
if len(set(l)) != n:
    print('No')
else:
    for i in range(n-1):
        #print(i)
        #print(list(l[i])[-1])
        #print(list(l[i+1])[0])
        if l[i][-1] != l[i+1][0]:
            print('No')
            break
        #else:
            #print('Noo')
            #break
        else:
            continue
    else:
        print('Yes')


Measured memory_bytes: 3060
import numpy as np

N, W = map(int, input().split())
dp = np.full(N*1000+1,W+1,dtype=np.int)
dp[0] = 0

for i in range(N):
    w, v = map(int, input().split())
    dp[v:] = np.minimum(dp[:-v]+w,dp[v:])

ans = np.max(np.where(dp<=W))
print(ans)

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

using ll = long long;
using P = pair<int, int>;

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    int a[n+1][m+1], c[n+1];
    set<int> left;
    for (int i=1; i<=n; i++) {
        cin >> c[i];
        for (int j=1; j<=m; j++) {
            cin >> a[i][j];
        }
    }

    int ans = INT32_MAX;

    for (int p=0; p<(1<<n); p++) {
        int cost = 0;
        int skill[m+1];
        for (int j=1; j<=m; j++) skill[j] = 0;

        for (int i=1; i<=n; i++) {
            if ((p>>(i-1))&1) {
                for (int j=1; j<=m; j++) {
                    skill[j] += a[i][j];
                }
                cost += c[i];
            }
        }

        bool completed = true;
        for (int j=1; j<=m; j++) {
            if (skill[j] < x) {
                completed = false;
            }
        }
        if (completed && cost < ans) {
            ans = cost;
        }
    }
    
    if (ans == INT32_MAX) ans = -1;
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <stack>
#include <cmath>
#include <vector>
using namespace std;

int main() {
    int n, a;
    bool good = true;
    cin >> n;
    for(int i=0; i<n; i++){
    	cin >> a;
    	if(a%2==0){
    		if(a%3 != 0 && a%5 != 0){
    			good = false;
    		}
    	}
    }
    if (good) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;

} 

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = x[0];
            int b = x[1];
            Console.WriteLine(a * b+" "+2*(a + b)   );


        }
    }
}



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

using namespace std;

int N, S[1000001];

int main()
{
  cin >> N;
  for(int i = 0; i < N; i++) {
    int X, Y;
    cin >> X >> Y;
    S[X + Y]++;
  }
  for(int i = 0; i < 1000000; i++) {
    S[i + 1] += S[i] >> 1;
    if(S[i] & 1) cout << i << " " << 0 << endl;
  }
}

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

int main(int argc, char* argv[])
{
	long long H, W, y;
	scanf("%lld %lld", &H, &W);

	if(H == 1 || W == 1){
		y = 1;
	}else{

		long long H_mod = H % 2;
		long long W_mod = W % 2;

		y = (H/2+H_mod) * (W/2+W_mod) + (H/2) * (W/2);
	}
	printf("%lld\n", y);
	return 0;
}





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

def readInts():
  return [int(s) for s in input().split(" ")]

def solve(N, A):
  s = sum(A)

  sp = 0
  last = A[0]
  for a in A:
    sp += a
    if sp >= s / 2:
      last = a
      break

  half = sp
  if sp - (s / 2) > abs(sp - last - (s / 2)):
    half = sp - last

  return abs(2 * half - s)

def main():
  N = readInts()
  A = readInts()

  print(solve(N, A))

if __name__ == "__main__":
  main()


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

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

int main() {
  int n, ans;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int cnt = 1;
  for (int i = 0; i < n; ++i)
    if (a[i] == cnt) cnt++;

  if (cnt == 1)
    ans = -1;
  else
    ans = n - cnt + 1;

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define N 101
using namespace std;
typedef long long ll;
ll n,p[N],q[N],r[N],b[N];
bool s[N];

ll func(int x){
  ll R=1,B=1;
  if(r[x]) R=func(r[x]);
  if(b[x]) B=func(b[x]);
  ll k=__gcd(R*p[x],B*q[x]);
  ll a=(R*p[x])/k,e=(B*q[x])/k;
  return (R*e)+(B*a);
}

int main(){
  while(cin>>n,n){
    memset(s,0,sizeof(s));
    for(int i=1;i<=n;i++){
      cin>>p[i]>>q[i]>>r[i]>>b[i];
      ll res=__gcd(p[i],q[i]);
      p[i]/=res,q[i]/=res;
      s[r[i]]=s[b[i]]=true;
    }
    for(int i=1;i<=n;i++)
      if(!s[i])cout<<func(i)<<endl;
  }
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  int atA, atZ;
  for(int i = 0; i < s.size();i++){
    if(s[i] == 'A'){
      atA = i;
      break;
    }
  }
  for(int i = s.size() - 1; i >= 0; i--){
    if(s[i] == 'Z'){
      atZ = i;
      break;
    }
  }
  cout << atZ - atA + 1 << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
string R,B;
map<string,int> T;
int main()
{
	int n,m;
	
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		cin>>R;
		T[R]++;
	}
	scanf("%d",&m);
	for(int i=0;i<m;i++)
	{
		cin>>B;
		T[B]--;
	}
	map<string,int>::iterator it;
	it=T.begin();
	pair<string,int> max= *it;
	for(;it!=T.end();it++)
	{
		pair<string,int> item = *it;
		if(max.second<item.second) max=item;
	}
	if(max.second<0) cout<<"0";
	else cout<<max.second;
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef complex<double> xy_t;
typedef pair<xy_t, int> pci;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int n;
lint m, v, p, a[MAX];

bool check(int mid){
    lint x=a[mid]+m;
    lint cnt=m*p;
    vector<lint> b;
    rep(i, n)if(i!=mid) b.push_back(a[i]);
    rep(i, p-1) b.pop_back();
    if(!b.empty() && b[b.size()-1]>x) return false;
    for(lint K: b){
        cnt+=min(m, x-K);
    }
    return cnt>=m*v;
}

int main(){
    scanf("%d%lld%lld%lld", &n, &m, &v, &p);
    rep(i, n) scanf("%lld", &a[i]);
    sort(a, a+n);
    if(check(0)){
        printf("%d\n", n);
        return 0;
    }
    int low=0, high=n-1;
    while(high-low>1){
        int mid=(high+low)/2;
        (check(mid) ? high : low) = mid;
    }
    printf("%d\n", n-high);
}

Measured memory_bytes: 2892
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
using namespace std;

int main() {
	int a, b; 
	cin >> a >> b;
	
	if (b % a == 0) {
		cout << a + b << endl;
		return 0;
	}
	cout << b - a << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque

def bfs():
    q = deque([0])
    visited = [False]*N
    visited[0] = True
    
    while q:
        v = q.popleft()
        
        for nv in G[v]:
            if not visited[nv]:
                cnt[nv] += cnt[v]
                visited[nv] = True
                q.append(nv)

N, Q = map(int, input().split())
G = [[] for _ in range(N)]

for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

cnt = [0]*N

for _ in range(Q):
    p, x = map(int, input().split())
    cnt[p-1] += x

bfs()

print(*cnt)

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

struct node{
  int par, left, right;
};
struct node tree[100005];
int cost[100005];

void dfs(int u, int d){
  cost[u] = d;
  if(tree[u].right != -1) dfs(tree[u].right, d);
  if(tree[u].left != -1) dfs(tree[u].left, d+1);
}

int main(){

  int n;
  int id, k, c;
  int l, root;
  cin >> n;
  for(int i = 0; i < n; i++) tree[i].par = tree[i].left = tree[i].right = -1;
  for(int i = 0; i < n; i++){
    cin >> id >> k;
    for(int j = 0; j < k; j++){
      cin >> c;
      if(j == 0) tree[id].left = c;
      else tree[l].right = c;
      l = c;
      tree[c].par = id;
    }
  }
  for(int i = 0; i < n; i++){
    if(tree[i].par == -1) root = i;
  }
  dfs(root, 0);
  for(int i = 0; i < n; i++){
    cout << "node " << i << ": ";
    cout << "parent = " << tree[i].par << ", ";
    cout << "depth = " << cost[i] << ", ";

    if(tree[i].par == -1) cout << "root, ";
    else if(tree[i].left == -1) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";
    for(int j = 0, c = tree[i].left; c != -1; j++, c = tree[c].right){
      if(j) cout << ", ";
      cout << c;
    }
    cout << "]\n";
  }
  return 0;
}


Measured memory_bytes: 7744
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;
using System.Threading;

class Program
{
    static void Main(string[] args)
    {
        var waCount = 0;
        var acCount = 0;
        int[] arr1 = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        int n = arr1[0];
        int m = arr1[1];
        var ac = new bool[n + 1];
        var wa = new int[n + 1];
        for (int i = 0; i < m; i++)
        {
            string[] arr = Console.ReadLine().Split(' ').ToArray();
            int qs = int.Parse(arr[0]);
            string wac = arr[1];

            if (ac[qs]) continue;

            if (wac == "WA") wa[qs]++;
            else
            {
                ac[qs] = true;
                acCount++;
                waCount += wa[qs];
            }

        }
        Console.WriteLine(acCount + " " + waCount);
        

    }

    

}

   

Measured memory_bytes: 46380
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        String s = std.next();
        char current = '.';
        long sum = 0;
        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);
            if (c != current) {
                sum++;
                current = c;
            }
        }

        System.out.println(sum);
    }
}

Measured memory_bytes: 24356
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int n;
    cin >> n;
    vector<ll> a(n),s(n);
    rep(i,n)cin >> a[i];
    s[0] = a[0];
    map<ll,ll>mp;
    mp[0]++;
    mp[a[0]]++;
    for(int i=1;i<n;i++){
        s[i] = s[i-1] + a[i];
        mp[s[i]]++;
    }
    ll ans = 0;
    for(auto x : mp){
        ans += x.second*(x.second-1)/2;
    }
    cout <<ans << endl;
    return 0;
}

Measured memory_bytes: 15872
#!python3

def LI():
    return list(map(int, input().split()))

# input
N, K = LI()
A = LI()


def main():
    n = 0
    x = 1
    visit = [None] * N
    while visit[x - 1] is None:
        if n == K:
            print(x)
            return
        visit[x - 1] = n
        n += 1
        x = A[x - 1]
    
    v = n - visit[x - 1]
    s = (K - n) % v
    ans = visit.index(visit[x - 1] + s) + 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 32296
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  float sum=0.0;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    sum+=(double)1/(double)a[i];
  }
  sum=1/sum;
  cout<<sum;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#include <stdio.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 TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
const int INF = 1000*1000*1000;
const ll LINF = (ll)1e19;
int xv[4] = {-1, 1, 0, 0};
int yv[4] = {0, 0, -1, 1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, C;
    cin >> N >> C;
    vector<vector<int>> D(C, vector<int>(C,0));
    vector<vector<int>> c(N, vector<int>(N,0));
    vector<vector<ll>> cost(3,vector<ll>(C,0));
    
    REP(i, C){
        REP(j, C){
            cin >> D[i][j];
        }
    }
    REP(i, N){
        REP(j, N){
            cin >> c[i][j];
            c[i][j]--;
        }
    }
    
    REP(i, C){
        REP(x, N){
            REP(y, N){
                cost[(x+y)%3][i] += D[c[y][x]][i];
            }
        }
    }
    
    ll ans = LINF;
    REP(i, C){
        REP(j, C){
            REP(k, C){
                if(i != j && j != k && k != i){
                    ans = min(ans, cost[0][i] + cost[1][j] + cost[2][k]);
                }
            }
        }
    }
    cout << ans << endl;

    
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n][3];

    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++)
        {   cin>>a[i][j];   }
    }
    int d[n][3];
    memset(d,0,sizeof(d));
    
    d[0][0] = a[0][0];
    d[0][1] = a[0][1];
    d[0][2] = a[0][2];

    for(int i=1;i<n;i++){

        d[i][0] = a[i][0] + max(d[i-1][1], d[i-1][2]);
        d[i][1] = a[i][1] + max(d[i-1][0], d[i-1][2]);
        d[i][2] = a[i][2] + max(d[i-1][0], d[i-1][1]);
        
    }
    

    cout<<max(d[n-1][0], max(d[n-1][1], d[n-1][2]));

    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>

using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  vector<double> p(n);
  vector<double> sums(n, 0);
  vector<double> acc(n, 0);
  for(int i = 0; i < n; i++){
    cin >> p[i];
  }
  double maxi = 0;
  for(int i = 0; i < n; i++){
    sums[i] = (p[i]+1.0);
    if(i > 0) acc[i] = acc[i-1] + sums[i];
    else acc[i] = sums[i];
    if(i >= k){
      acc[i] -= sums[i-k];
    }
    maxi = max(maxi, acc[i]);      
  }
  cout << fixed << setprecision(16) << maxi/2.0 << endl;
}


Measured memory_bytes: 4992
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll H, W;
vector<string> S;
ll group[400][400];

void print_group(){
    FOR(i, 0, H){
        FOR(j, 0, W){
            cout << group[i][j] << " ";
        }
        cout << endl;
    }
}

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

    // input
    cin >> H >> W;

    S.resize(H);
    FOR(i, 0, H){
        cin >> S.at(i);
    }

    FOR(i, 0, 400){
        FOR(j, 0, 400){
            group[i][j] = -1;
        }
    }

    queue<pair<ll, ll> > que;

    ll group_id = 0;
    FOR(i, 0, H){
        FOR(j, 0, W){

            // 点 i, jがすでにグループに所属しているか
            if(group[i][j]!=-1){
                continue;
            }else{
                group_id++;
            }

            auto p = make_pair(i, j);
            que.push(p);
            group[i][j] = group_id;

            while(!que.empty()){
                p = que.front();
                que.pop();

                ll p_i = p.first;
                ll p_j = p.second;

                char color = S[p_i][p_j];
                char nx_color;
                if(color=='.'){
                    nx_color = '#';
                }else{
                    nx_color = '.';
                }

                // 上下左右
                FOR(k, 0, 4){
                    ll nx_i = p_i + dy[k];
                    ll nx_j = p_j + dx[k];

                    if(0<=nx_i && nx_i < H && 0<=nx_j && nx_j < W && S[nx_i][nx_j]==nx_color && group[nx_i][nx_j]==-1){
                        group[nx_i][nx_j] = group_id;
                        que.push(make_pair(nx_i, nx_j));
                    }
                }
            }
        }
    }

    // グループごとに黒点・白点の統計を取る
    ll black[group_id+10];
    ll white[group_id+10];
    FOR(i, 0, group_id+10){
        black[i] = 0;
        white[i] = 0;
    }
    
    FOR(i, 0, H){
        FOR(j, 0, W){
            ll id = group[i][j];
            char color = S[i][j];
            if(color=='.'){
                white[id]++;
            }else{
                black[id]++;
            }
        }
    }

    ll sum = 0;
    FOR(i, 1, group_id+1){
        sum += black[i] * white[i];
    }

    p(sum);

    return 0;
}

Measured memory_bytes: 3840
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
#define pb push_back
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int main(){
    int N; cin >> N;
    vl p(N, 0);
    rep(i, 0, N) cin >> p[i];
    ll cnt = 1;
    ll cur_min = p[0];
    rep(i, 1, N){
        if(cur_min >= p[i]) cnt += 1;
        cur_min = min(p[i], cur_min);
    }
    cout << cnt << endl;
    return 0;
}




Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define vvi vector<vi >
#define str string
#define vs vector<str>
#define vb vector<bool>
#define slli set<lli>
#define mii map<int, int>
#define mlli map<int, lli>
#define msi map<str, int>
#define mp make_pair
#define pii pair<int, int>
#define pll pair<lli, lli>
#define vpii vector<pii >
#define vpll vector<pll >
#define pb push_back
#define loop(i, s, l, j) for(int i = s; i < l; i += j)
#define rloop(i, s, l, j) for(int i = s; i >= l; i -= j)
#define rep(i, n) loop(i,0,n,1)
#define rrep(i, n) rloop(i,n-1,0,1) 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ft first
#define sd second   
#define mit mii::iterator
#define vit vi::iterator
#define all(a) a.begin(),a.end()
#define min3(a, b, c) min(a, min(b, c))
#define mod 998244353
#define inf 100000000000000000
#define limit 200005
/**********************************************************************************************************************************************/
int dx4[4] = {0, -1, 0, 1};
int dy4[4] = {1, 0, -1, 0};
int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Power(int base,int exp){int ans=1;  while(exp > 0){if(exp&1)ans=(1LL*ans*base)%mod; exp=exp>>1; base=(1LL*base*base)%mod;}  return ans;}
/**********************************************************************************************************************************************/ 

void input()
{
	lli X, K, D;
	cin >> X >> K >> D;

	if(X == 0)
	{
		if(K%2 == 0)
			cout << 0 << '\n';
		else
			cout << D << '\n';
		return;
	}

	X = abs(X);
	lli K_ = ceil(1.0 * X/D);
	if(K <= K_)
		cout << abs(X - K * D) << '\n';
	else
	{
		if(K%2 == K_%2)
			cout << abs(X-K_*D) << '\n';
		else
			cout << abs(X-K_*D+D) << '\n';
	}


}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
 
    fastio();
    int q = 1;
    //cin >> q;
    while(q--)
        input();
}

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

using namespace std;

int main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    int x;
    scanf("%d", &x);

    int ans = 0;

    for(int na = 0; na <= a; na++){
        for(int nb = 0; nb <= b; nb++){
            for(int nc = 0; nc <= c; nc++){
                if(na * 500 + nb * 100 + nc * 50 == x)
                    ans++;
            }
        }
    }

    printf("%d", ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N];
typedef long long ll;

int main()
{
    ll h,n,a=0;
    cin>>h>>n;
    for(int i=0;i<n;++i){
        ll t;
        cin>>t;
        a+=t;
    }
    if(a>=h)
        puts("Yes");
    else puts("No");
    return 0;
}
/*

*/

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

// MainT1P2018C
public class Main {

    private static boolean isOdd(int val) {
        return ((val & 1) != 0);
    }

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in);
             PrintWriter out = new PrintWriter(System.out))
        {
            final int N = in.nextInt();
            final int[] A = new int[N];
            Arrays.setAll(A, i -> Integer.parseInt(in.next()));

            final int halfN = N / 2;
            long result = 0L;
            Arrays.sort(A);
            if (isOdd(N)) {

                long r1 = 0L;
                r1 -= 2 * Arrays.stream(A, 0, halfN).asLongStream().sum();
                r1 += 2 * Arrays.stream(A, halfN, N).asLongStream().sum();
                r1 -= A[halfN];
                r1 -= A[halfN + 1];

                long r2 = 0L;
                r2 -= 2 * Arrays.stream(A, 0, halfN + 1).asLongStream().sum();
                r2 += 2 * Arrays.stream(A, halfN + 1, N).asLongStream().sum();
                r2 += A[halfN];
                r2 += A[halfN - 1];

                result = Math.max(r1, r2);

            } else {
                result -= 2 * Arrays.stream(A, 0, halfN).asLongStream().sum();
                result += 2 * Arrays.stream(A, halfN, N).asLongStream().sum();
                result -= A[halfN];
                result += A[halfN - 1];
            }
            out.println(result);
        }
    }
}


Measured memory_bytes: 50340
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String str[] = br.readLine().split(" ");
		Map<Long, Integer> map = new HashMap<>();

		for (int i = 0; i < n; i++) {
			long d = Long.parseLong(str[i]);

			if (map.containsKey(d))
				map.put(d, map.get(d) + 1);
			else
				map.put(d, 1);
		}

		int m = Integer.parseInt(br.readLine());
		str = br.readLine().split(" ");

		for (int i = 0; i < m; i++) {
			long t = Long.parseLong(str[i]);
			if (!map.containsKey(t)) {
				System.out.println("NO");
				return;
			} else {
				if (map.get(t) <= 0) {
					System.out.println("NO");
					return;
				} else {
					map.put(t, map.get(t) - 1);
				}
			}
		}

		System.out.println("YES");

	}
}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

   vector<int>p(N);
   rep(i,N) cin >> p[i];

   int ans = 0;
   rep(i,N-2)
   {
       if( min(p[i],p[i+2]) <= p[i+1] && max(p[i],p[i+2]) >= p[i+1]) ans++;
   }
   cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn=100005;
ll x,y,z,n;
ll ans=0;
struct node{
	ll a,b,c;
}e[maxn];
bool cmp(node x,node y){
	return x.a-x.b>y.a-y.b;
}
ll l[maxn],r[maxn];
priority_queue<ll> q;
int main(){
	scanf("%lld%lld%lld",&x,&y,&z);
	n=x+y+z;
	for(ll i=1;i<=x+y+z;i++){
		scanf("%lld%lld%lld",&e[i].a,&e[i].b,&e[i].c);
	}	
	sort(e+1,e+1+n,cmp);
	ll sum=0;
	for(ll i=1;i<=x;i++){
		sum=sum+e[i].a;
		q.push(e[i].c-e[i].a);
	}
	l[x]=sum;
	for(ll i=x+1;i<=x+z;i++){
		ll x=q.top();
		if(x+e[i].a<e[i].c)sum=sum+e[i].c;
		else{
			sum=sum+x+e[i].a;
			q.pop();
			q.push(e[i].c-e[i].a);
		}
		l[i]=sum;
	}
	while(!q.empty()) q.pop();
	sum=0;
	for (ll i=n;i>n-y;i--){
		sum=sum+e[i].b;
		q.push(e[i].c-e[i].b);
	}
	r[n-y+1]=sum;
	for (ll i=n-y;i>x;i--){
		ll x=q.top();
		if(x+e[i].b<e[i].c)sum=sum+e[i].c;
		else{
			sum=sum+x+e[i].b;
			q.pop();
			q.push(e[i].c-e[i].b);
		}
		r[i]=sum;
	}
	for(ll i=x;i<=x+z;i++){
		ans=max(ans,l[i]+r[i+1]);
	}	
	printf("%lld\n",ans);
	return 0;
}


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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;;
    if(a*b<c*d){
        cout<<c*d;
    }else{
        cout<<a*b;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;
typedef pair<ll, ll> Pll; 

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if (a+b == 60 && c > a) {
		cout << -1 << endl;
		return 0;
	}
	while (1) {
		if (c > inf) {
			cout << -1 << endl;
			break;
		}
		if (c % (a+b) <= a) {
			cout << c << endl;
			break;
		}
		else c += 60;
	}

	return 0;
}

Measured memory_bytes: 3108
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Robot Arms
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

pii ps[MAX_N];
int dp[MAX_N + 1];

/* subroutines */

inline void setmax(int &a, int b) { if (a < b) a = b; }

/* main */

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

  for (int i = 0; i < n; i++) {
    int xi, li;
    scanf("%d%d", &xi, &li);
    ps[i] = pii(xi - li, xi + li);
  }
  sort(ps, ps + n);

  for (int i = 0; i < n; i++) {
    int x0 = ps[i].first, x1 = ps[i].second;

    setmax(dp[i + 1], dp[i]);

    int k = lower_bound(ps, ps + n, pii(x1, 0)) - ps;
    setmax(dp[k], dp[i] + 1);
  }

  printf("%d\n", dp[n]);
  return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    ll N;
    cin >> N;

    ll c[10][10] = {0};
    for (int i = 1; i < N + 1; i++) {
        string s = to_string(i);
        int a = s[0] - '0';
        int b = s[s.size() - 1] - '0';
        c[a][b]++;
    }

    ll ans = 0;
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            ans += c[i][j] * c[j][i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256