akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define repd(i,a,b) for (ll i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void)
{
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	rep(i,M) cin >> A[i];
	ll ans = N - accumulate(A.begin(), A.end(), 0LL);
	if(ans<0) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7212
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007
#define MODB  998244353 

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

int main() {
	ll ans = 0;
	ll tmp;
	//int n; cin >> n;
	ll a, b, c, d;
	cin >> a >> b >>  c >> d;
	cout << max({a*c, a*d, b*c, b*d})<< endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int main(){
	double x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	printf("%lf\n", sqrt(pow(x1-x2,2)+pow(y1-y2,2)));
	return 0;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define vi vector<int>

#define ll long long int

int ctoi(char c) {return c-'0';}
int ord(char c) {return c-'a';}
int len(string s) {return s.length();}
int itoc(int i) {return i+'a';}

int main() {
string s;
cin>>s;
int diff = 1e9;
for(int i=0;i<s.length()-2;i++) {
    string temp = s.substr(i,3);
    diff = min(diff,abs(753-stoi(temp)));
}
cout<<diff<<endl;
return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String target = scan.next();
    for(int i = 0; i < target.length() - 1; i++){
      if(target.charAt(i) == target.charAt(i+1)){
        System.out.println("Bad");
        return;
      } 
    }
    System.out.println("Good");
  }
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define all(a) a.begin(), a.end()

typedef long long lint;

int table[3][26];
int mod[3];
vector<int> primes;

struct node {
    int h[3];
    bool operator == (const node &other) {
        return h[0] == other.h[0] && h[1] == other.h[1] && h[2] == other.h[2];
    }
    bool operator < (const node &other) const {
        if (h[0] == other.h[0]) {
            if (h[1] == other.h[1]) return h[2] < other.h[2];
            return h[1] < other.h[1];
        }
        return h[0] < other.h[0];
    }
};

map<node, int> mp;

int main() {
    rep(i, 2309) {
        int cnt = 0;
        rep(j, (i + 1)) {
            if ((i + 1) % (j + 1) == 0) ++cnt;
        }
        if (cnt == 2) primes.push_back((i + 1));
    }
    rep(i, 3) {
        mod[i] = primes.back();
        primes.pop_back();
        rep(j, 26) {
            table[i][j] = primes.back();
            primes.pop_back();
        }
    }
    int N;
    scanf("%d", &N);
    rep(i, N) {
        char s[11];
        scanf("%s", s);
        int sn = (int)strlen(s);
        node tmp = {{1, 1, 1}};
        rep(j, 3) rep(k, sn) tmp.h[j] *= table[j][s[k] - 'a'];
        mp[tmp]++;
    }
    lint ans = 0LL;
    for (auto m : mp) ans += m.second * (m.second - 1LL) / 2LL;
    printf("%lld\n", ans);
}


Measured memory_bytes: 6528
#include "bits/stdc++.h"
using namespace std;

#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

typedef long long ll;
#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>
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
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 };


int main() {
	ll x, y;
	cin >> x >> y;
	if (x%y == 0) {
		cout << -1 << endl;
		return 0;
	}
	else {
		cout << x << endl;
	}
}



Measured memory_bytes: 256
H,W = map(int,input().split())
S = list(input() for i in range(H))
Grid1 = [[0]*W for i in range(H)]
for i in range(H):
    cou = 0
    l = 0
    for j in range(W):
        if S[i][j] == ".":
            cou += 1
        else:
            for x in range(l,j):
                Grid1[i][x] = cou
            l = j+1
            cou = 0
    for x in range(l,j+1):
        Grid1[i][x] = cou    
for i in range(W):
    cou = 0
    l = 0
    for j in range(H):
        #print(i,j,S[i][j])
        if S[j][i] == ".":
            cou += 1
        else:
            for x in range(l,j):
                Grid1[x][i] += cou
            l = j+1
            cou = 0
    for x in range(l,j+1):
        Grid1[x][i] += cou

print(max(max(Grid1[i]) for i in range(H))-1)


Measured memory_bytes: 100056
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll long long int
#define endl "\n"
#define db(x) cout<<#x<<" ->"<<x<<endl
#define db2(x,y) cout<<#x<<"->"<<x<<", "<<#y<<" -> "<<y<<endl
#define db3(x,y,z) cout<<#x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define db4(w,x,y,z) cout<<#w <<" -> " << w << " , " << #x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define prt(x) for(auto it = x.begin(); it!=x.end(); it++) { cout<<*it<<" "; } cout<< endl
#define IN freopen("input.txt","r",stdin)
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = (int)4e5+4;

int sum[N][4];

int f(int x, int y){
    for(int i = 0 ; i < 3; i++){
        if(i!=x && i!=y){ return i; }
    }
}

int decide(char ch){
    if(ch=='R'){ return 0 ;}
    else if(ch=='G'){ return 1;}
    else if(ch=='B') { return 2;}
    return 3;
}

int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
//    IN;
    int n ;
    string s;
    cin >> n >> s;
    s = "#" + s;
    for(int i = 1; i < s.size(); i++){
        int ch = s[i];
        sum[i][0]+=(sum[i-1][0] + (ch=='R'));
        sum[i][1]+=(sum[i-1][1] + (ch=='G'));
        sum[i][2]+=(sum[i-1][2] + (ch=='B'));
    }
    ll ans  = 0LL;
    int sz = s.size() - 1;
    for(int i = 1 ; i < s.size(); i++){
        for(int j = i + 1; j < s.size(); j++){
            if(s[i]==s[j]){ continue ; }
//            db2(i , j);
            int x = decide(s[i]);
            int y = decide(s[j]);
            int rem = f(x,y);
            int cur = sum[sz][rem] - sum[j][rem];
//            db2(cur,rem);
            int res = j - i;
//            if( j + res > sz){ continue ; }
//            db2(res,j+res);
            cur-=(decide(s[j + res])==rem);
            ans+=cur;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3668
using System;
using System.Collections.Generic;
using System.Linq;

namespace AC {
    class Program {
        static void Main (string[] args) {
            var N = ReadInt ();
            var S = Read ();
            var alpha = new List<char> ();
            var ans = "";
            for (char c = 'A'; c <= 'Z'; c++) {
                alpha.Add (c);
            }
            for (int i = 0; i < S.Length; i++) {
                ans += alpha[(alpha.IndexOf (S[i]) + N) % 26].ToString ();
            }

            Console.WriteLine (ans);
        }

        static string Read () { return Console.ReadLine (); }
        static int ReadInt () { return int.Parse (Read ()); }
        static long ReadLong () { return long.Parse (Read ()); }
        static int[] ReadArrayInt () { return Read ().Split (' ').Select (s => int.Parse (s)).ToArray (); }
        static long[] ReadArrayLong () { return Read ().Split (' ').Select (s => long.Parse (s)).ToArray (); }
    }
}

Measured memory_bytes: 37076
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = std::pair<ll, ll>;

ll X, Y, Z;

int main()
{
  std::cin >> X >> Y >> Z;

  X -= Z;

  std::cout << X / (Y+Z) << std::endl;

  return 0;
}

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

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

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

    long long res = 0;
    long long res2 = 0;
    long long idx_small = 0;
    long long idx_large = n-1;

    vector<long long> p1(n);
    vector<long long>p2(n);
    p2[n-1] = -1;
    p1[n-1] = -1;

    for(i=1;i<n-1;i+=2){
        p2[i] = a[idx_small];
        p2[i+1] = a[idx_large];
        p1[i] = a[idx_large--];
        p1[i+1] = a[idx_small++];
    }
    p1[0] = a[idx_small];
    p2[0] = a[idx_large];
    if(p1[n-1]==-1)p1[n-1] = a[idx_large];
    if(p2[n-1]==-1)p2[n-1] = a[idx_small];

    for(i=0;i<n-1;i++){
        res += abs(p1[i]-p1[i+1]);
        res2 += abs(p2[i]-p2[i+1]);
    }
    cout << max(res,res2) << endl;
    return 0;
}


Measured memory_bytes: 2688
n = int(input())
s = [input() for i in range(n)]
s.sort()
s += ["0"]

ans = []
count = 1
max_count = 0

for i in range(n):
    if s[i] == s[i+1]:
        count += 1

    else:
        if count > max_count:
            ans = [s[i]]
            max_count = count
            count = 1
        elif count == max_count:

            ans += [s[i]]
            count = 1
        else:
            count = 1

for a in ans:
    print(a)

Measured memory_bytes: 20680
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author HARSHAD
 */

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

#define int long long
#define f(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)

class BStringRotation {
public:
	void solve(std::istream& in, std::ostream& out) {
		string a, b; in >> a >> b;
		a = a+a;
		bool ok = a.find(b)!=string::npos;
		out << (ok?"Yes":"No");
	}
};


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	BStringRotation solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int MOD = 1000000007;

long long mod(long long a) {
	a %= MOD;
	return a >= 0 ? a : a+MOD;
}

int main() {
	string s;
	cin >> s;
	long long len = s.size();
	long long dp[len+1][2];
	fill((long long *)dp, (long long *)dp + sizeof(dp)/sizeof(long long), 0);
	dp[0][0] = 1;
	for (int i = 0; i < len; i++) {
		const int D = s[i] - '0';
		if (D == 1) {
			dp[i+1][0] = mod(dp[i][0] * 2);
			dp[i+1][1] = mod(dp[i][0] + dp[i][1]*3);
		} else {
			dp[i+1][0] = dp[i][0];
			dp[i+1][1] = mod(dp[i][1]*3);
		}
	}
	long long ans = mod(dp[len][0] + dp[len][1]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5244
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

struct UnionFind {
	vector<int> par, siz;
	UnionFind(int n): par(n), siz(n, 1) {
		rep(i,n) par[i] = i;
	}

	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
	}
	int size(int x) {
		return siz[find(x)];
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	UnionFind uf(n);
	rep(i,m) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		uf.unite(a, b);
	}
	int ans = 0;
	rep(i,n) {
		ans = max(ans, uf.size(i));
	}
	cout << ans << endl;
}

Measured memory_bytes: 4824
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int N,a[100000],b[100000],c[100000];
int x[100000][3],y[100000];


int happy(int n, int m)
{
  int k,temp;
  
  if(n==0)
  {
    if(m==2)
    {
      temp=c[0];
    }
    else if(m==1)
    {
      temp=b[0];
    }
    else
    {
      temp=a[0];
    }
  }
  else if(x[n][m]>0)
  {
    temp=x[n][m];
  }
  else
  {
    if(m==2)
    {
      temp=fmax(happy(n-1,1),happy(n-1,0))+c[n];
    }
    else if(m==1)
    {
      temp=fmax(happy(n-1,0),happy(n-1,2))+b[n];
    }
    else
    {
      temp=fmax(happy(n-1,1),happy(n-1,2))+a[n];
    }
  }
  
  x[n][m]=temp;
                 
  return x[n][m];
}

int main()
{

  int j;
  scanf("%d",&N);
  for(j=0;j<N;j++)
  {
    scanf("%d %d %d",&a[j],&b[j],&c[j]);
    x[j][0]=0;
    x[j][1]=0;
    x[j][2]=0;
  }
  
  j=fmax(fmax(happy(N-1,0),happy(N-1,1)),happy(N-1,2));
  
  printf("%d",j);
  
  return 0;
}

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

int N, K;
int a,d,k,ans=0;

int main(){

    cin >> N >> K;
    int a[N+1];
    a[0]=0;
    for(int i=1;i<=N;i++){
        a[i] = 1;
    }
    for(int i=0;i<K;i++){
        cin >> d;
        for(int j=0;j<d;j++){
            cin >> k;
            a[k]=0;
        }
    }
    for(int i=0;i<=N;i++){
        ans+=a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
def main():
    H, W = list(map(int, input().split()))
    dp = [['0'] * (W + 2)] + [['0', ] + ['0' if a == '#' else a for a in list(input())] + ['0', ] for _ in range(H)] + [['0'] * (W + 2)]
    mod = 1000000007
    dp[1][1] = '1'
    for h in range(1, H + 1):
        for w in range(1, W + 1):
            if dp[h][w] == '.':
                dp[h][w] = str((int(dp[h - 1][w]) + int(dp[h][w - 1])) % mod)
    print(dp[H][W])

if __name__ == '__main__':
    main()


Measured memory_bytes: 126044
// ConsoleApplication3.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

//#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
	int S,h,m,s;
	cin >> S;
	h = S / 3600;
	m = (S % 3600) / 60;
	s = (S % 3600) % 60;
	cout << h << ":" << m << ":" << s << endl;
    return 0;
}




Measured memory_bytes: 3120
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  auto s=readln.chomp.to!(char[]);
  int k; rd(k);

  import std.array;

  int n=s.length.to!(int);
  bool[string] m;
  for(int len=1; len<=min(10, n); len++){
    for(int i=0; i+len<=n; i++){
      m[s[i..(i+len)].to!(string)]=true;
    }
  }
  auto arr=m.keys.array;
  sort(arr);
  bool[string] h;
  foreach(t; arr){
    h[t]=true;
    if(h.length==k){
      writeln(t);
      break;
    }
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}

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

int main(){
	int n, in;
	cin >> n;
	int ans = 0;
	rep(i, n){
		cin >> in;
		while(in%2 == 0){
			ans++;
			in /= 2;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)

int main(void)
{
	int H, W;
	cin >> H >> W;
	int count = 0;
	Rep(i, H){
		string str;
		cin >> str;
		Rep(j, str.length()){
			if(str[j] == '#') count++;
		}
	}
	PrintLn(((count == H + W - 1) ? "Possible" : "Impossible"));
	return 0;
}


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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("2");
            WillReturn.Add("3 4");
            //3.5
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("3");
            WillReturn.Add("500 300 200");
            //375
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("5");
            WillReturn.Add("138 138 138 138 138");
            //138
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        decimal[] VArr = InputList[1].Split(' ').Select(X => decimal.Parse(X)).ToArray();
        Array.Sort(VArr);

        int UB=VArr.GetUpperBound(0);

        for (int I = 1; I <= UB; I++) {
            VArr[I] += VArr[I - 1];
            VArr[I] /= 2;
        }
        Console.WriteLine(VArr[UB]);
    }
}


Measured memory_bytes: 13524
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define ull unsigned long long int
#define ll long long
#define vi vector<int>
#define mii map<int,int>
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define MOD 1e9+7
#define INF 0x3f3f3f3f
//#define show(x) cerr<<x#<<" "<<x<<"\n";

//typedef tree<pair<int,int>,null_type, 
//less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN NEEDED)\
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("O3")
//uncoment for large int requirement

//using boost::multiprecision::cpp_int;
//using namespace _gnu_pbds;
using namespace std;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main()
{
ll n;
cin>>n;
ll ans=(n/1000+1)*1000-n;
cout<<ans%1000<<endl;
}


Measured memory_bytes: 3676
import sys
readline = sys.stdin.readline
      
class BIT:
    #1-indexed
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.p = 2**(n.bit_length() - 1)
        self.dep = n.bit_length()
    def get(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
    
    def bl(self, v):
        if v <= 0:
            return -1
        s = 0
        k = self.p
        for _ in range(self.dep):
            if s + k <= self.size and self.tree[s+k] < v:
                s += k
                v -= self.tree[s+k]
            k //= 2
        return s + 1
  
N, Q = map(int, readline().split())

T = BIT(N+1)
A = [0] + list(map(int, readline().split()))

for i in range(N+1):
    T.add(i+1, A[i])

Ans = []
for _ in range(Q):
    t, a, b = map(int, readline().split())
    if t == 0:
        T.add(a+2, b)
    else:
        Ans.append(T.get(b+1) - T.get(a+1))

print('\n'.join(map(str, Ans)))

Measured memory_bytes: 182104
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
using ll = long long;

int main() {
    ll q,h,s,d,n,lmin,pay;
    cin >> q >> h >> s >> d;
    lmin = min(q*4,h*2);
    lmin = min(lmin,s);
    cin >> n;
    if (n>=2) {
        ll twol=n/2,res=n%2;
        if (lmin * 2 > d) pay = (n/2)*d + (n%2)*lmin;
        else pay = n * lmin;
    }
    else pay = lmin;

    cout << pay << endl;
    return 0;
}

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

typedef pair<int, int> P;
#define int long long

int K, T;
P A[100];

signed main() {
    cin >> K >> T;
    for(int i = 0; i < T; ++i) {
        int z;
        cin >> z;
        A[i] = make_pair(z, i);
    }
    int prev = -1;
    int ans = 0;
    for(int i = 0; i < K; ++i) {
        sort(A, A+T, greater<P>());
        if(A[0].second == prev) {
            if(A[1].first > 0) {
                prev = A[1].second;
                A[1].first--;
                continue;
            }
            else {
                ++ans;
            }
        }
        prev = A[0].second;
        A[0].first--;
    }
    cout << ans << endl;
    return 0;
}

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

using P=tuple<int, int, int>;
using T=tuple<long, P>;
const long inf=1L<<60;

int main()
{
    int H, W, K; cin>>H>>W>>K;
    int sx, sy, gx, gy; cin>>sx>>sy>>gx>>gy;
    --sx, --sy, --gx, --gy;

    vector<string> a(H);
    for(auto& s: a) cin>>s;

    vector d(H, vector(W, vector(4, inf)));
    priority_queue<T, vector<T>, greater<T>> q;
    for(int i=0; i<4; ++i) {
        q.emplace(0L, P({sx, sy, i}));
        d[sx][sy][i]=0;
    }

    int dx[4]={-1, 0, 1, 0};
    int dy[4]={0, -1, 0, 1};
    while (!q.empty()) {
        auto [cost, pos]=q.top(); q.pop();
        auto [x, y, z]=pos;

        uint nx=x+dx[z];
        uint ny=y+dy[z];
        auto nc=cost+1;
        P np={nx, ny, z};

        if (!(nx>=H or ny>=W or a[nx][ny]=='@')) {
            if (d[nx][ny][z]>nc) {
                q.emplace(nc, np);
                d[nx][ny][z]=nc;
            }
        }
        for(int i=0; i<4; ++i) if (i!=z) {
            np={x, y, i};
            nc=(cost+K-1)/K*K;
            if (d[x][y][i]<=nc) continue;
            q.emplace(nc, np);
            d[x][y][i]=nc;
        }
    }

    long res=inf;
    for(int i=0; i<4; ++i)
        res=min(res, d[gx][gy][i]);
    cout<<(res<inf ? (res+K-1)/K : -1)<<endl;
}


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

using namespace std;
int main()
{
    int n, mn=109, tm, sum=0;
    cin >> n;
    while(n--)
    {
        scanf("%d",&tm);
        sum+=tm;
        if(tm%10) mn=min(mn,tm);
    }
    if(sum%10) printf("%d\n",sum), exit(0);
    mn<100 ? printf("%d\n",sum-mn) : printf("0\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
    string s;cin>>s;
    int l = -1;
    int r = -1;
    int n = s.size();
    rep(i,0,n-2){
        if(s[i]==s[i+1]){
            l = i+1;
            r = i+2;
        }
    }
    rep(i,0,n-3)
    {
        if(s[i]==s[i+2]){
            l = i + 1;
            r = i + 3;
        }
    }
    cout<<l<<" "<<r<<endl;
}


Measured memory_bytes: 512
if __name__ == '__main__':
    x = input()
    x = int(x)

    flag = False
    a = 0
    b = 0
    for i in range(1,120):
        for j in range(1,120):
            ab = i**5 - (i-j)**5
            if ab == x:
                flag = True
                a = i
                b = i-j
                break
        if flag:
            break

    print(a,b)

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/*
願はくは花の下にて春死なんそのきさらぎの望月のころ（西行 1118-1190）
--This is old Japanese poem expressing the desire to die under tree on the full moon night.(written by Saigyo)
In my research, there is possibility that the tree may be seg-tree.
*/

/*Coding Space*/
int main(){
  string s; cin >> s;
  if(s.find("AC") != string::npos)
    cout <<"Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
var binarySearch = function(key, n, a) {
  var left = 0;
  var right = n;
  while (left < right) {
    var mid = Math.floor((left + right) / 2);
    if (a[mid] == key) {
      return true;
    } else if (key < a[mid]) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }

  return false;
};

(function(stdin) {
  var arr = (stdin.trim()).split('\n');
  var s = arr[1].split(" ").map(Number);
  var t = arr[3].split(" ").map(Number);
 
  var ans = 0;
  for (var i = 0; i < t.length; i++) {
    if (s.indexOf(t[i]) !== -1) {
      ans++;
    }
  }
  console.log(ans);
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 30864
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;
int mod = 1000000007;

int N, K, X, Y;
int main() {
  cin >> N >> K >> X >> Y;

  int ans;
  if (N <= K) {
    ans = X*N;
  } else {
    ans = X*K + Y*(N-K);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+7;
int n;
ll ans,a[N],f[N][5];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	memset(f,0x3f,sizeof f);
	ans=f[0][0];
	f[0][0]=0;
	for(int i=1;i<=n;i++)
	{
		ll mn=f[i-1][0];
		for(int j=0;j<5;j++)
		{
			mn=min(mn,f[i-1][j]);
			if(!j||j==4)f[i][j]=mn+a[i];
			else if(j==1||j==3)f[i][j]=mn+(a[i]?(a[i]&1):2);
			else f[i][j]=mn+((a[i]+1)&1);
		}
	}
	for(int i=0;i<5;i++)ans=min(ans,f[n][i]);
	cout<<ans<<endl;
}

Measured memory_bytes: 9600
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)*}
    };
}

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
    n: usize,
    p: [usize; n],
    q: [usize; n],
    }
    let mut t: Vec<usize> = (1..n + 1).collect();
    let mut a:i64 = 0;
    let mut b:i64 = 0;
    let mut c:i64 = 1;
    while {
        if t == p {
            a = c
        }
        if t == q {
            b = c
        }
        c += 1;
        t.next_permutation()
    } {}
    let ans = (a - b).abs();
    println!("{}", ans);
}

pub trait LexicalPermutation {
    fn next_permutation(&mut self) -> bool;
    fn prev_permutation(&mut self) -> bool;
}

impl<T> LexicalPermutation for [T] where T: Ord {
    fn next_permutation(&mut self) -> bool {
        if self.len() < 2 { return false; }
        let mut i = self.len() - 1;
        while i > 0 && self[i - 1] >= self[i] {
            i -= 1;
        }
        if i == 0 {
            return false;
        }
        let mut j = self.len() - 1;
        while j >= i && self[j] <= self[i - 1] {
            j -= 1;
        }
        self.swap(j, i - 1);
        self[i..].reverse();
        true
    }

    fn prev_permutation(&mut self) -> bool {
        if self.len() < 2 { return false; }
        let mut i = self.len() - 1;
        while i > 0 && self[i - 1] <= self[i] {
            i -= 1;
        }
        if i == 0 {
            return false;
        }
        self[i..].reverse();
        let mut j = self.len() - 1;
        while j >= i && self[j - 1] < self[i - 1] {
            j -= 1;
        }
        self.swap(i - 1, j);
        true
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

void solve() {
	int n, m;
	cin >> n >> m;
	if (n > m) swap(n, m);
	if (m - n > 1) cout << 0;
	else {
		ll ans = 1;
		for (int i = 1; i <= n; i++) {
			ans *= i;
			if (ans >= MOD) {
				ans %= MOD;
			}
		}

		for (int i = 1; i <= m; i++) {
			ans *= i;
			if (ans >= MOD) ans %= MOD;
		}
		if (n == m) ans *= 2;
		ans %= MOD;
		cout << ans;

	}	
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
	int T = 1; 
    //cin >> T;
    while(T--) solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long,long>> vpll;
typedef vector<pair<int,int>> vpii;

struct union_find
{
	typedef vector<int> vi;
	vi par,cnt,rank;
	union_find(int x):par(x),cnt(x,1),rank(x,0){
		for (int i = 0;i < x; i++) {
			par[i] = i;
		}
	}

	int find(int x){
		if(par[x] == x)return x;
		return par[x] = find(par[x]);
	}

	void unite(int x_,int _x){
		x_ = find(x_);
		_x = find(_x);
		if(x_!=_x){
			if(rank[x_] >= rank[_x]){
				if(rank[x_] == rank[_x]){rank[x_]++;}
				par[_x] = x_;
				cnt[x_] += cnt[_x];
			}
			else{
				par[x_] = _x;
				cnt[_x] += cnt[x_];
			}
		}
	}

	int count(int x){
		return cnt[find(x)];
	}

	bool same(int x_,int _x){
		return find(x_) == find(_x);
	}

};
int main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	ini(n);
	ini(n1);
	ini(n_);
	vector<vi> fr(n);
	vector<vi> bl(n);
	union_find uf(n);
	FOR(i,0,n1){
		ini(x);
		x--;
		ini(x1);
		x1--;
		fr[x].push_back(x1);
		fr[x1].push_back(x);
		uf.unite(x,x1);
	}
	FOR(i,0,n_){
		ini(x);
		x--;
		ini(x1);
		x1--;
		bl[x].push_back(x1);
		bl[x1].push_back(x);
	}
	FOR(i,0,n){
		int total = uf.count(i)-1;
		for (auto x : fr[i]) {
			if (uf.same(i, x)) {
				total--;
			}
		}
		for(auto x:bl[i]){
			if(uf.same(i,x)){
				total--;
			}
		}
		cout<<total<<" ";
	}
	return 0;
}

Measured memory_bytes: 13048
package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var sc = bufio.NewScanner(os.Stdin)
var ReadString func() string
var ReadLine func() string
var ReadInt64 func() int64
var ReadInt func() int
var ReadIntSlice func(int) []int
var ReadInt64Slice func(int) []int64
var GetIntAbs func(int) int
var Atoi func(string) int
var FindMin func([] int) int
var FindMax func([] int) int

func init() {
	ReadString = newReadString()
	ReadLine = readLine
	ReadInt64 = readInt64
	ReadInt = readInt
	ReadIntSlice = readIntSlice
	FindMin = findMin
	FindMax = findMax
}

func main() {
	A := ReadInt()
	B := ReadInt()
	C := ReadInt()
	X := ReadInt()

	var r int
	for a := 0; a <= A; a++ {
		for b := 0; b <= B; b++ {
			for c := 0; c <= C; c++ {
				total := (500 * a) + (100 * b) + (50 * c)
				if total == X {
					r += 1
				}
			}
		}
	}
	fmt.Println(r)
}

/*------ scan ------*/

func newReadString() func() string {
	sc.Buffer(make([]byte, 1024), 2048)
	sc.Split(bufio.ScanWords)
	return func() string {
		if !sc.Scan() {
			panic("scanできなかった")
		}
		return sc.Text()
	}
}

func readLine() string {
	if !sc.Scan() {
		panic("line をscanできなかった")
	}
	return sc.Text()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		fmt.Println("parseInt失敗")
		panic(err.Error())
	}
	return int64(i)
}

func readInt() int {
	i := ReadInt64()
	return int(i)
}

func readIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}

func readInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt64()
	}
	return arr
}

/*------ number util ------*/

func getIntAbs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func atoi(a string) int {
	i, err := strconv.Atoi(a)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func findMin(arr []int) int {
	if len(arr) == 0 {
		return 0
	}
	min := arr[0]
	for _, v := range arr {
		if v < min {
			min = v
		}
	}
	return min
}

func findMax(arr []int) int {
	if len(arr) == 0 {
		return 0
	}
	max := arr[0]
	for _, v := range arr {
		if v > max {
			max = v
		}
	}
	return max
}

Measured memory_bytes: 640
X = int(input())
N = 200
for i in range(N):
    for j in range(N):
        if i**5 - j**5 == X:
            print(i, j)
            exit()
        if (-i)**5 - j**5 == X:
            print(-i, j)
            exit()
        if i**5 - (-j)**5 == X:
            print(i, -j)
            exit()
        if (-i)**5 - (-j)**5 == X:
            print(-i, -j)
            exit()


Measured memory_bytes: 9112
#include <cstdio>
#include <cmath>
#include <cstdlib>
using namespace std;

int n, m;

int EXP(int num, int times)
{
	int ans=1;
	for (int i=1; i<=times; ++i) ans*=num;
	return ans;
}
int main()
{
	scanf("%d%d", &n, &m);
	printf("%d\n", EXP(2, m)*(m*1900+(n-m)*100));
	return 0;
}

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

int main()
{
  int n;
  cin>>n;
  map<string,int> m;
 // int count=0;
  
  for(int i=0;i<n;i++)
  {
    string str;
    cin>>str;
    m[str]++;
  }
  
  cout<<m.size()<<endl;
  return 0;
}

Measured memory_bytes: 19224
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <string>
using namespace std;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    if(s[s.size()-1]=='3'){
      cout << "bon" << endl;
    }
    else if(s[s.size()-1]=='0'||s[s.size()-1]=='1'||s[s.size()-1]=='6'||s[s.size()-1]=='8'){
      cout << "pon" << endl;
    }
    else{
      cout << "hon" << endl;
    }
  
    return 0;
}

Measured memory_bytes: 3652
K, T = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
amax = a[-1]
asum = sum(a[:-1])
ans = 0
if T == 1:
    ans = K - 1
else:
    ans = max(amax - asum - 1, 0)
print(ans)

Measured memory_bytes: 3064
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
preNum=-2
ans=0
for i in range(N):
  ans+=B[A[i]-1]
  if(preNum+1==A[i]-1):
    ans+=C[preNum]
  preNum=A[i]-1
print(ans)

Measured memory_bytes: 38256
n = int(input())
money_list = (59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1)
ans = 0
for i in money_list:
  while n >= i:
    if (46656*2) <= n:
      n -= 46656
      ans += 1
    elif (6561*2) <= n < (7776+6561) or (6561*3) <= n <= (6561*3+1296):
      n -= 6561
      ans += 1
    elif (729*2) <= n < (1296+729) or (729*3) <= n < (1259+729+216):
      n -= 729
      ans += 1
    elif (81*3) <= n <= (81*3+2) or (81*3+6) <= n < (216+36): #249: #(245):
      n -= 81
      ans += 1
    elif 12 <= n < 15:
      n -= 6
      ans += 1
    else:
      n -= i
      ans += 1

print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;

ll H, W;

int main() {
    cin >> H >> W;

    if (H != 1 && W != 1) {
        ll ans = ((W+1)/2) * ((H+1)/2);
        ans += (W/2) * (H/2);
        cout << ans << endl;
    }
    else {
        cout << 1 << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int H, W, i_H, i_W;
    while (1) {
        scanf("%d %d", &H, &W);
        if (H == 0 && W == 0) break;
        for (i_H = 0; i_H < H; i_H++) {
            /* the first line */
            if (i_H == 0){
                for (i_W = 0; i_W < W; i_W++) printf("#");
                printf("\n");
            } else if (i_H == H-1){
                /* the last line */
                for (i_W = 0; i_W < W; i_W++) printf("#");
                printf("\n\n");
            } else {
                /* the intermediate lines */
                printf("#");
                for (i_W = 1; i_W < W-1; i_W++) printf(".");
                printf("#\n");
            }
        }
    }    
    return 0;
}


Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std;
int main()
{
	 int d, n;
        cin >> d >> n;
        if(d == 0){
            if(n == 100) cout << 101 << endl;
            else cout << n << endl;
        }else if(d == 1){
            if(n == 100) cout << n*100 + 100 << endl;
            else cout << n*100 << endl;
        }else if(d == 2){
            if(n == 100) cout << n*10000 + 10000 << endl;
            else cout << n*10000 << endl;
        }
        return 0;
}

Measured memory_bytes: 256
N, M = map(int,input().split())
X = sorted(list(map(int,input().split())))

tmp = sorted([X[i+1] - X[i] for i in range(M-1)])
if(tmp != []):
  if(len(tmp) == 1):
    print(*tmp)
  elif(N == 1):
    print(sum(tmp))
  else:
    print(sum(tmp[:-(N-1)]))
else:
  print(0)

Measured memory_bytes: 13968
/*input
5
10 -4 0 -11 3
*/
#include <bits/stdc++.h>
using namespace std;
		 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }


int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int N;
	int minusai = 0;
	cin >> N;
	ll maz = MOD;
	ll sum = 0;	
	ll a;
	for (int i = 0; i < N; ++i)
	{
		cin >> a;
		if(a < 0){
			minusai++;
			a *= -1;
		}
		sum += a;
		maz = min(maz, a);
	}
	if(minusai & 1){
		printf("%lld\n", sum - 2*maz);
	} else{
		printf("%lld\n", sum);
	}
}

/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* array bounds
*/
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const int DAYMAX = 100005;
const int ACTIONMAX = 3;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<vector<int>> happiness(N, vector<int>(ACTIONMAX));
    for (int i = 0; i < N; i++)
        for (int j = 0; j < ACTIONMAX; j++)
        cin >> happiness[i][j];

    vector<int> dp(ACTIONMAX, 0);
    vector<int> tmp(ACTIONMAX, 0);
    for (int d = 0; d < N; d++) {
        for (int todayAction = 0; todayAction < ACTIONMAX; todayAction++) {
            for (int yesterdayAction = 0; yesterdayAction < ACTIONMAX; yesterdayAction++) {
                if (todayAction == yesterdayAction) continue;
                tmp[todayAction] = max(tmp[todayAction],
                                        dp[yesterdayAction] + happiness[d][todayAction]);
            }
        }
        swap(dp, tmp);
        for (int i = 0; i < ACTIONMAX; i++) tmp[i] = 0;
    }
    cout << *max_element(dp.begin(), dp.end()) << '\n';
}


Measured memory_bytes: 8724
#include<bits/stdc++.h>
 
using namespace std;
 
struct SuffixArray
{
  vector< int > SA;
  string s;
 
  void Build_SA(const string &str)
  {
    s = str;
    SA.resize(s.size());
    iota(begin(SA), end(SA), 0);
    sort(begin(SA), end(SA), [&](const int &a, const int &b)
    {
      if(s[a] == s[b]) return (a > b);
      return (s[a] < s[b]);
    });
    vector< int > classes(s.size()), c(s.size()), cnt(s.size());
    for(int i = 0; i < s.size(); i++) {
      c[i] = s[i];
    }
    for(int len = 1; len < s.size(); len <<= 1) {
      for(int i = 0; i < s.size(); i++) {
        if(i > 0 && c[SA[i - 1]] == c[SA[i]] && SA[i - 1] + len < s.size() && c[SA[i - 1] + len / 2] == c[SA[i] + len / 2]) {
          classes[SA[i]] = classes[SA[i - 1]];
        } else {
          classes[SA[i]] = i;
        }
      }
      iota(begin(cnt), end(cnt), 0);
      copy(begin(SA), end(SA), begin(c));
      for(int i = 0; i < s.size(); i++) {
        int s1 = c[i] - len;
        if(s1 >= 0) SA[cnt[classes[s1]]++] = s1;
      }
      classes.swap(c);
    }
  }
 
  int operator[](int k) const
  {
    return (SA[k]);
  }
 
  int size() const
  {
    return (s.size());
  }
 
  bool lt_substr(string &t, int si = 0, int ti = 0)
  {
    int sn = s.size(), tn = t.size();
    while(si < sn && ti < tn) {
      if(s[si] < t[ti]) return (true);
      if(s[si] > t[ti]) return (false);
      ++si, ++ti;
    }
    return (si >= sn && ti < tn);
  }
 
  int lower_bound(string &t)
  {
    int low = -1, high = SA.size();
    while(high - low > 1) {
      int mid = (low + high) >> 1;
      if(lt_substr(t, SA[mid])) low = mid;
      else high = mid;
    }
    return (high);
  }
 
  pair< int, int > lower_upper_bound(string &t)
  {
    int idx = lower_bound(t);
    int low = idx - 1, high = SA.size();
    t.back()++;
    while(high - low > 1) {
      int mid = (low + high) >> 1;
      if(lt_substr(t, SA[mid])) low = mid;
      else high = mid;
    }
    t.back()--;
    return (make_pair(idx, high));
  }
 
  void output()
  {
    for(int i = 0; i < size(); i++) {
      cout << i << ": " << s.substr(SA[i]) << endl;
    }
  }
};
 
 
int main()
{
  int N, M;
  while(cin >> N, N) {
    cin  >> M;
    string S;
    cin >> S;
    SuffixArray sa;
    sa.Build_SA(S);
    string T = "I";
    for(int i = 0; i < N; i++) T += "OI";
    auto p = sa.lower_upper_bound(T);
    cout << p.second - p.first << endl;
  }
}

Measured memory_bytes: 20428
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5100+10;
const ll inf = 1e9+7;
int main(){
    ios::sync_with_stdio(0);
    int t,a,b;
    cin>>t>>a>>b;
    a = (a-1)/t,b=b/t;
    if(a==b)
        cout<<"NG"<<endl;
    else
    cout<<"OK"<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
int main()	{
  string s;
  cin>>s;
  rep(i,s.size())
    s[i]='x';
  cout<<s<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
  int X,Y;
  scanf("%d %d",&X,&Y);
  for(int i=0;i<=X;i++){
    if((2*i+(X-i)*4)==Y){
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
  return 0;
}

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

//#define int long long

using namespace std;
int main() {
	int N, M, C; cin >> N >> M >> C;
	int ans = 0;
	vector <int> A(M) ,B(M);
	
	for (int i = 0; i < M; i++) { cin >> B[i]; }
	for (int i = 0; i < N; i++) {
		int t = C;
		for (int j = 0; j < M; j++) { cin >> A[j]; t += A[j] * B[j]; }
		if (t > 0) { ans++; }
	}
	cout << ans << endl;
	return 0;
}

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

public class Main {
	Scanner sc = new Scanner(System.in);
	long DP(int a[],int n){
		long array[] = new long [21];
		array[a[0]] = 1;
		for(int i = 1;i < n-1;i++){
			long array2[] = new long [21];
			for(int j = 0;j < 21;j++){
				if(j - a[i] >= 0){
					array2[j-a[i]] = array2[j-a[i]] + array[j];
				}
				if(j + a[i] < 21){
					array2[j+a[i]] = array2[j+a[i]] + array[j];
				}
			}
			for(int j = 0;j < 21;j++){
				array[j] = array2[j];
			}
		}
		return array[a[n-1]];
	}
	void doIt() {
		int n = sc.nextInt();
		int a[] = new int [n];
		for(int i = 0;i < n;i++){
			a[i] = sc.nextInt();
		}
		System.out.println(DP(a,n));
     }
    public static void main(String[] args) {
    	// TODO Auto-generated method stub
    	new Main().doIt();
    }
}

Measured memory_bytes: 18208
import java.util.stream.*;
class Main {
  public static void main(String[] args) {
    IntStream.rangeClosed(1, 9)
      .forEach(i -> {
        IntStream.rangeClosed(1, 9)
          .forEach(j -> {
            System.out.println(i + "x" + j + "=" + i * j);
          });
      });
  }
}

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

int main(){
  int X, A, B, C, remain, remain2, count;

  count = 0;
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> X;
  for(int i = min((X / 500), A); i >= 0; i--){
    remain = X - 500 * i;
    for(int j = min((remain / 100), B); j >= 0; j--){
      remain2 = remain - 100 * j;
      if ((remain2 % 50) == 0 && (remain2 / 50) <= C){
        count++;
      }
    }
  }

  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string.h>
#include<string>
#include<map>
#include<utility>
#include<functional>
typedef long long ll;
using namespace std;
typedef pair<int,float> p;

vector<ll> a,b,c;
int n,m;
string s;

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

  cout << n*n - m << endl;
  return 0;
}


Measured memory_bytes: 256