akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <iomanip>
#include <cstdlib>
#include <climits>
#include <set>
using namespace std;

//関数getinputdata宣言
vector<vector<string>> getinputdata();
vector<vector<int>> getinputdata2();
vector<vector<double>> getinputdata3();

void abc129_b(vector<vector<int>> v) {

    int n = v[0][0];
    vector<int> vec = v[1];
    int mysum = accumulate(vec.begin(), vec.end(), 0);

    int sa = INT_MAX;
    for (int i = 1; i <= vec.size() - 1; i++) {

        int mytemp1 = accumulate(vec.begin(), vec.begin() + i, 0);
        int mytemp2 = mysum-mytemp1;
        
        sa = min(sa, abs(mytemp1 - mytemp2));

    }

    cout << sa << endl;

}

int main() {

    //    vector<vector < string>> vec_arr_result;
    vector<vector<int>> vec_arr_result;
    vec_arr_result = getinputdata2();

    abc129_b(vec_arr_result);

    return 0;
}

//関数getinputdata実装

vector<vector<double>> getinputdata3() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<double>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<double> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atof(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;
}

//関数getinputdata実装

vector<vector<int>> getinputdata2() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<int>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<int> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atoi(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;


}

//関数getinputdata実装

vector<vector < string >> getinputdata() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector < string>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<string> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(ret);
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;

}


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

int n;
vector<int> scjl[33];
vector<int> now[55];

int solve();

int main() {
  int i, j, f, x;
  while(1) {
    cin >> n;
    if(n == 0) break;
    for(i = 0; i < n; ++i) {
      cin >> f;
      for(j = 0; j < f; ++j) {
        cin >> x;
        scjl[x].push_back(i);
      }
    }
    for(i = 0; i < n; ++i) now[i].push_back(i);
    cout << solve() << endl;
    for(i = 0; i <= 30; ++i)
      scjl[i].erase(scjl[i].begin(), scjl[i].end());
    for(i = 0; i < n; ++i)
      now[i].erase(now[i].begin(), now[i].end());
  }
  return 0;
}

int solve() {
  int i, j;
  for(i = 1; i <= 30; ++i) {
    vector<int> nextv;
    for(j = 0; j < scjl[i].size(); ++j)
      nextv.insert(nextv.begin(), now[scjl[i][j]].begin(),
                   now[scjl[i][j]].end());
    sort(nextv.begin(), nextv.end());
    nextv.erase(unique(nextv.begin(), nextv.end()),
                nextv.end());
    if(nextv.size() == n) return i;
    for(j = 0; j < scjl[i].size(); ++j)
      now[scjl[i][j]] = nextv;
  }
  return -1;
}


Measured memory_bytes: 3128
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

k, x = map(int, input().split())
ans = 'No'
if 500 * k >= x:
    ans = 'Yes'

print(ans)

Measured memory_bytes: 13676
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

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

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

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    String c = sc.next();
    System.out.println(Character.toString((char) (c.codePointAt(0) + 1)));
  }
}

Measured memory_bytes: 19668
#include <iostream>

using namespace std;

bool PrimeOrNot(int p)
{
	if (p==1) return false;
	if (p==2) return true;

	for (int i=2;i*i<=p;++i)
	{
		if (p%i == 0) return false;
	}
	return true;
}

int main()
{
	int n;
	int count=0;
	cin>>n;

	while (n!=0)
	{
		for (int i=n+1;i<=2*n;++i)
		{
			if (PrimeOrNot(i)) ++count;
		}
		cout<<count<<endl;
		count =0;
		cin>>n;
	}
}

Measured memory_bytes: 868
#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>;

struct UnionFind {
  vector<int> d; // 親の番号、但し根の場合はサイズのマイナス
  UnionFind(int n): d(n,-1) {}
  int root(int x) { // 根を見つける
    if (d[x] < 0) return x;
    return d[x] = root(d[x]); // 経路圧縮
  }
  bool unite(int x, int y) { // 結合
    x = root(x); y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);} // 親が一緒
  int size(int x) { return -d[root(x)];} // サイズ
};

int main(){
    int n; // 頂点数
    cin>>n;
    UnionFind uf(2*n+1); // 初期化
    int u,v,w;
    rep(i,n-1){
        cin>>u>>v>>w;
        if(w%2==0){
            uf.unite(u,v);
            uf.unite(n+u,n+v);
        }
        else{
            uf.unite(u,n+v);
            uf.unite(n+u,v);
        }
    }
    cout<<"0"<<endl;
    for(int i=2;i<=n;i++){
        if(uf.same(1,i)) cout<<"0"<<endl;
        else cout<<"1"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3956
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cmath>
#include<algorithm>
#define pi acos(-1.0)
using namespace std;

int main(){
	double r;
	while(cin>>r ){

		cout<<setprecision(6)<<fixed<<pi*r*r<<" "<<setprecision(6)<<fixed<<2*pi*r<<endl;
	}
	return 0;
}

Measured memory_bytes: 1284
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		int[] N = new int[5];
		int result = 0;
		Scanner scan = new Scanner(System.in);
		for(int i =0;i<5;i++) {
			N[i]=scan.nextInt();
			if(N[i]==0) {
				result = i+1;
			}
		}		
		scan.close();
		System.out.println(result);
	}
}

Measured memory_bytes: 35748
a,b,c=map(int,input().rstrip().split(' '))
if(a==b and b==c):
	if(a%2==0):
		print(-1)
	else:
		print(0)
else:
	n=0
	while(a%2==0 and b%2==0 and c%2==0):
		n+=1
		tmp_a=(b+c)/2
		tmp_b=(a+c)/2
		tmp_c=(b+a)/2
		a=tmp_a
		b=tmp_b
		c=tmp_c
	print(n)


Measured memory_bytes: 3064
import fractions


def main():
    n, m = map(int, input().split())
    s = input()
    t = input()
    l = n * m // fractions.gcd(n, m)
    x = {}
    for i in range(n):
        x[i * (l // n)] = s[i]
    for i in range(m):
        if i * (l // m) not in x:
            continue
        if x[i * (l // m)] != t[i]:
            print(-1)
            return
    print(l)


if __name__ == '__main__':
    main()


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Description: ????????????
// Verifyed: various problem 
const R INF = 1E40L;
const R PI = acos(-1.0L);
using P=complex<R>;
const P O=0.0L;
using L=struct{P s,t;};
using VP=vector<P>;
using C=struct{P p;R c;};

istream& operator >> (istream& is,P& p){ R x,y;is >> x >> y; p=P(x,y); return is;}
ostream& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}

inline R dot(P o,P a,P b){return real(conj(a-o)*(b-o));}
inline R det(P o,P a,P b){return imag(conj(a-o)*(b-o));}
inline int sdot(P o,P a,P b){return sgn(dot(o,a,b));}
inline int sdet(P o,P a,P b){return sgn(det(o,a,b));}

//projection verify AOJ CGL_1_A
P proj(L l,P p){ R u=real((p-l.s)/(l.t-l.s)); return (1-u)*l.s+u*l.t;}

// farthest point pair Verify AOJ CGL_4_B
R fpp(VP pol){
	int n=pol.size(),i=0,j=0;
	if(n<=2) return abs(pol[0]-pol[1]);
	R res=0.0;
	auto cmp_x=[](P a,P b)->bool{return sgn(real(a)-real(b))?sgn(real(a)-real(b))<0:sgn(imag(a)-imag(b)<0);};
	
	rep(k,n){
		if(!cmp_x(pol[i],pol[k]))i=k;
		if(cmp_x(pol[j],pol[k]))j=k;
	}

	int si=i,sj=j;
	while(i!=sj||j!=si){
		chmax(res,abs(pol[i]-pol[j]));
		if(sdet(O,pol[(i+1)%n]-pol[i],pol[(j+1)%n]-pol[j])<0)
			i=(i+1)%n;
		else 
			j=(j+1)%n;
	}
	return res;
}

int main(void){
	int n;
	cin >> n;
	VP pol;
	rep(i,n){
		P p;
		cin >> p;
		pol.push_back(p);
	}
	cout.precision(10);
	cout << fixed << fpp(pol) << endl;
	return 0;
}

Measured memory_bytes: 7936
/* 拡張ダイクストラ */
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

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

    int ichi = min(a, k);
    int ni = min(b, k-ichi);
    int san = min(c, k-ichi-ni);
    cout << ichi - san << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <cstdint>
#include <iostream>
#include <math.h>

namespace null_null {

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using usize = std::size_t;

} // namespace null_null

namespace null_null {

void main_() {
  i32 A,B;
  std::cin>>A>>B;
  std::cout<<std::max((i32)0,A-2*B)<<std::endl;
}

} // namespace null_null

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  null_null::main_();
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) std::cerr<< #x <<": "<<x<<"\n"
#define debug2(x,y) std::cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<"\n"
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

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

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

int n, m;
vvi g;
vector<bool> used;

int main() {
  scanf("%d %d", &n, &m);
  g.resize(n);
  rep (i, m) {
    int a, b;
    scanf("%d %d", &a, &b);
    a -= 1; b -= 1;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  used.assign(n, false);
  vi path = {0};
  used[0] = true;

  while (true) {
    int u = *(path.end() - 1);
    for (int v : g[u]) {
      if (used[v]) {
        continue;
      }
      path.push_back(v);
      used[v] = true;
      break;
    }
    if (u == *(path.end() - 1)) {
      break;
    }
  }

  reverse(all(path));

  while (true) {
    int u = *(path.end() - 1);
    for (int v : g[u]) {
      if (used[v]) {
        continue;
      }
      path.push_back(v);
      used[v] = true;
      break;
    }
    if (u == *(path.end() - 1)) {
      break;
    }
  }

  printf("%lu\n", path.size());
  for (int u : path) {
    printf("%d ", u+1);
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 6776
/*
改善点：
数式を一般式に落とし込んで考えていなかった
1+2+3+......+xみたいな
よかった：
図を書いた
*/

#include<stdio.h>

int main(void)
{
  int a = 0, b = 0;
  scanf("%d%d", &a, &b);

  int i = 0;
  int sum = 0;
  for(i=1; i<=b-a; i++){
    sum += i;
  }
  printf("%d\n", sum-b);
}


Measured memory_bytes: 128
// 解答不能.
// 以下のソースコードを勉強する.
// pekempey氏.
// https://atcoder.jp/contests/abc141/submissions/7548203
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

int main(){
    int N;
    scanf("%d", &N);
    vector<ll> A(N); rep(i, N) scanf("%lld", &A[i]);
    ll ans = 0;
    rep(i, 60){
        int s = 0;
        rep(j, N) s ^= A[j] >> i & 1;
        if(s == 1){
            ans += 1LL << i;
            rep(j, N) A[j] &= ~(1LL << i);
        }
    }
    vector<ll> bases;
    sort(range(A), greater<>());
    for(ll x : A){
        for(ll y : bases) x = min(x, x ^ y);
        if(x != 0) bases.push_back(x);
    }
    ll s = 0;
    for(ll x : bases) s = max(s, s ^ x);
    printf("%lld\n", ans + s * 2);
    return 0;
}

Measured memory_bytes: 1024
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
using namespace std;
typedef long long ll;
typedef string str;

int main(){
  str s;
  cin >> s;
  str ans = s[0] + to_string(s.length()-2) + s[s.length()-1];
  cout << ans << endl;
  return 0;
}


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

int main()
{
    string N;
    cin >> N;
    int sum_digits = 0;
    for (char c : N) {
        sum_digits += c - '0';
    }
    if (sum_digits % 9 == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

using namespace std;

int n, m, a[15], stat[15], ans = 0;

bool valid (int mask) {
  for (int i = 0; i < m; i++) {
    if (((__builtin_popcount(a[i] & mask) & 1) != 0) != stat[i]) return false;
  }
  return true;
}

int solve (int p, int mask) {
  if (p > n) return (valid (mask) == 1);
  return solve (p + 1, mask) + solve (p + 1, mask | (1 << p));
}

int main () {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int mask = 0, k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int p;
      cin >> p;
      mask |= (1 << p);
    }
    a[i] = mask;
  }
  for (int i = 0; i < m; i++) {
    cin >> stat[i];
  }
  cout << solve (1, 0) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
#define Pair pair<int,int>


int N;
string S;

Pair sub_solve(vector<int> v){
	for(int i=0;i<v.size();i++){
		if(v[i]==0){
			for(int j=i+1;j<v.size();j++){
				if(v[j]==1){
					return {i,j};
				}
			}
		}
	}
	return {-1,-1};
}

int solve(){
	vector<int> s(N);
	for(int i=0;i<N;i++){
		if(S[i]=='(') s[i] = 0;
		else s[i] = 1;
	}
	while(sub_solve(s).first != -1){
		int i=sub_solve(s).first;
		int j=sub_solve(s).second;
		s.erase(s.begin()+i); s.erase(s.begin()+j-1);
	}

	for(auto e:s){
		if(e==1) cout << '(';
	}
	cout << S;
	for(auto e:s){
		if(e==0) cout << ')';
	}
	cout << endl;
	return 0;
}



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

	solve();
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int N,K;cin>>N>>K;

  int ans=1;
  for(int t=1;t<=N;t++){
    if(ans<K){
      ans*=2;
      continue;
    }
    if(ans>=K)ans+=K;
  }

  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

    string ref = "keyence";

    if (S.size() < ref.size()) {
        cout << "NO" << endl;
        return 0;
    }

    for (int i = 0; i <= ref.size(); i++) {
        int j = ref.size() - i;
        if (S.substr(0, i) == ref.substr(0, i) && S.substr(S.size() - j, j) == ref.substr(ref.size() - j, j)) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MAX = 410;
ll dp[MAX][MAX];
vector<ll> a, sum;
ll dfs(int l, int r) {
  if (dp[l][r] >= 0)
    return dp[l][r];
  if (r-l == 1)
    return dp[l][r] = 0;
  ll res = LINF;
  for (int i = l+1; i < r; i++)
    chmin(res, dfs(l, i)+dfs(i, r));
  return dp[l][r] = sum[r]-sum[l]+res;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  a.resize(n);
  rep(i, n) cin >> a[i];
  sum.resize(n+1, 0);
  rep(i, n) sum[i+1] = sum[i]+a[i];
  rep(i, MAX) rep(j, MAX) dp[i][j] = -1;
  ll ans = dfs(0, n);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1664
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")
#include"bits/stdc++.h"
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long
#define ends ' '
#define endl '\n'
#define pb emplace_back
#define x first
#define y second
#define pii pair<int, int>
#define sz(x) (int)(x).size()

int32_t main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif
	IOS;

	int n;
	cin >> n;

	multiset<int> ms;

	int a[n];

	for(int i = 0; i < n; ++i)
	{
		cin >> a[i];
		ms.insert(a[i]);
	}

	for(int i = 0; i < n; ++i)
	{
		ms.erase(ms.find(a[i]));
		cout << *(--ms.end()) << endl;
		ms.insert(a[i]);
	}

	return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll n;cin>>n;
  vector<P>v;
  rep(i,0,n){
    ll a,b;cin>>a>>b;
    v.push_back(P(a,b));
  }

  sort(v.begin(),v.end());
  bool num[n];CLR(num,true);
  ll c=0;
  rep(i,1,n){
    if(num[i]){
      if(v[c].first+v[c].second>v[i].first+v[i].second){
        num[c]=false;
        c=i;
      }else if(v[c].first+v[c].second>v[i].first-v[i].second){
        num[i]=false;
      }else if(v[c].first+v[c].second<=v[i].first-v[i].second){
        c=i;
      }
    }
  }
  ll ans=0;
  rep(i,0,n){
    if(num[i])ans++;
  }

  out(ans);



  return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

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

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv){
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	int a; cin >> a;
	string s; cin >> s;
	if(a>=3200)out(s); else out("red");
}




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


using namespace std;

/* macros */
#define all(v)			((v).begin()), ((v).end())
#define SIZE(v)			((int)((v).size()))
#define LOG(x)			log((double)x)
#define TOLOWER(x)          transform(all(x),x.begin(),::tolower)
#define TOUPPER(x)          transform(all(x),x.begin(),::toupper)
#define ROUND(x,m)			(round((double)x/m)*m)
#define DIGITS(x)			(floor(log10((double)x))+1)
#define READSTR(x)			getline(cin,x)
#define sort_g(a,b)              sort(a, b, greater<int>());
#define IOS() ios_base::sync_with_stdio(0);cin.tie(NULL);
#define REP(i, n) for (int i = 0; i < n; i++)
#define FILE_INPUT() 	freopen( "input.txt", "r", stdin)
#define FILE_OUTPUT()   freopen( "output.txt", "w", stdout)

/*typedefs*/
typedef long long ll;

/*functions*/
bool myCmp(pair<int,int> &p1 , pair<int,int>&p2)
{
    return p1.first > p2.first;
}
unsigned long long
choose(unsigned long long n, unsigned long long k) {
    if (k > n) {
        return 0;
    }
    unsigned long long r = 1;
    for (unsigned long long d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}
int toInt(string str) {
    int num;
    istringstream iss(str); //put string in input stream
    iss>>num; return num; //read from stream as integer
}

template <class T> string toStr(T par) {
    ostringstream oss;  //output stream string
    oss<<par;    //write par to the stream
    return oss.str(); //return string of output
}

const int MAXN = 50;
int arr[MAXN] = {0};

int main() {
    IOS();
    int n;
    cin>>n;
    REP(i,n)
    cin>>arr[i];
    ll sm = 0;
    for(int i = 0 ; i < n ; ++i)
    {
        for(int j = i+1 ; j < n ; ++j)
        {
            sm += (arr[i]*arr[j]);
        }
    }
    cout<<sm<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int x[2],i;
	scanf("%d %d",&x[0],&x[1]);
	if(x[0]>x[1]){
		i=x[0]-x[1];
	}
	else if(x[0]<x[1]){
		i=x[1]-x[0];
	}
	else if(x[0]==x[1]){
		i=0;
	}
	printf("%d\n",i);
	return 0;
}


Measured memory_bytes: 2104
#include<stdio.h>
#include<ctype.h>

int main(void)
{
	char c;

	while(1){
		scanf("%c",&c);
		if(c == '\n')break;
		if(islower(c) != 0){
			c = toupper(c);
			printf("%c",c);
		}else{
			c = tolower(c);
			printf("%c",c);
			}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 524
#include <cstdio>
#include <cstring>
#include <algorithm>

int n;
int w,h;
int x[501],y[501];
int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		scanf("%d %d",&w,&h);
		for(int i=0;i<n;i++){
			scanf("%d %d",&x[i],&y[i]);
		}
		int s,t;
		scanf("%d %d",&s,&t);
		int res=0;
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				int cnt=0;
				for(int k=0;k<n;k++){
					if(i<=y[k] && y[k]<i+t && j<=x[k] && x[k]<j+s)cnt++;
				}
				res=std::max(res,cnt);
			}
		}
		printf("%d\n",res);
	}
	return 0;
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  P p[n];
  rep(i, n) cin >> p[i].first >> p[i].second;
  sort(p, p+n);
  rep(i, n) {
    k -= p[i].second;
    if (k <= 0) {
      cout << p[i].first << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 1024
/* Tenka1 Programmer Contest E
   首先,考虑到曼哈顿距离=|xi-xj|+|yi-yj|,
   由这样的性质,可以得到x,y是相互独立的.
   问题被转化为一维的情况,
   现在就是对k*(k-1)/2个点,需要去寻找一个值k使得sigma(abs(k-xi))最小,
   由中位数的性质,显然,k就是这k*(k-1)/2个点的中位数.
   考虑二分答案,现在就是要求对于每个k统计出x坐标小于k的点的数量.
   将所有线按照斜率排序,当x很小时,用一条竖直线段去切这n条线,斜率小的位置最靠下,而斜率大的位置最靠上,
   当x=k时,如果在x<k时l1和l2发生了相交,则l1和l2的相对顺序就会发生变化,
   于是问题就转化为了求逆序对的数量,这是O(nlogn)复杂度的,
   于是就可以得到一个O(nlognlog(eps^(-1)))的解法.
*/
#include <bits/stdc++.h>
#define lim 200000005
using namespace std;
struct line
{double a,b,c,k;
int id;
}p[40005];
inline bool cmp(line p,line q)
{return p.k<q.k;}
int n,all,nd,t[40005];
int e[40005];
inline void add(int pos)
{while (pos<=n)
{e[pos]++;pos+=(pos&(-pos));}
}
inline int ask(int pos)
{int s=0;
while (pos)
{s+=e[pos];pos-=(pos&(-pos));}
return s;
}
inline int calc(double mid)
{int i;
for (i=1;i<=n;i++)
{p[i].k=(-p[i].a/p[i].b)*mid+p[i].c/p[i].b;}
sort(p+1,p+n+1,cmp);
for (i=1;i<=n;i++)
{t[i]=p[i].id;}
int ans=0;
memset(e,0,sizeof(e));
for (i=1;i<=n;i++)
{ans+=ask(n)-ask(t[i]-1);
add(t[i]);
}
return ans;
}
inline void solve()
{int i,tms=66;
for (i=1;i<=n;i++)
{p[i].id=n-i+1;}
double l=-lim,r=lim;
while (tms--)
{double mid=(l+r)/2.0;
if (calc(mid)<nd) {l=mid;}
else {r=mid;}
}
printf ("%.12lf",l);
return;
}
int main (){
	int i;
	scanf ("%d",&n);
	all=n*(n-1)/2;
	if (all&1) {nd=(all+1)/2;}
	else {nd=all/2;}
	for (i=1;i<=n;i++)
	{scanf ("%lf%lf%lf",&p[i].a,&p[i].b,&p[i].c);
	p[i].k=-p[i].a/p[i].b;
	//a*x+b*y=c---->y=-a/b*x+c/b
	}
	sort(p+1,p+n+1,cmp);
	solve();
	printf (" ");
	for (i=1;i<=n;i++)
	{double tp=p[i].a;
	p[i].a=p[i].b;
	p[i].b=tp;
	p[i].k=-p[i].a/p[i].b;
	}
	sort(p+1,p+n+1,cmp);
	solve();
	printf ("\n");
	return 0;
}
	
	
	


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

int main(){
    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    // DP
    vector<vector<int>> former(n+2, vector<int>(k+1)), latter(n+2, vector<int>(k+1));
    former[0][0] = 1;
    latter[n+1][0] = 1;

    for(int i=0; i<n; i++){
        for(int j=0; j<=k; j++){
            if(j - a[i] >= 0) former[i+1][j] = max(former[i+1][j], former[i][j - a[i]]);
            former[i+1][j] = max(former[i+1][j], former[i][j]);
        }
    }
    for(int i=n-1; i>=0; i--){
        for(int j=0; j<=k; j++){
           if(j - a[i] >= 0) latter[i+1][j] = max(latter[i+1][j], latter[i+2][j - a[i]]);
            latter[i+1][j] = max(latter[i+1][j], latter[i+2][j]);
        }
    }

    // cumulative sum
    for(int i=0; i<n+2; i++){
        for(int j=0; j+1<=k; j++){
            latter[i][j+1] += latter[i][j];
        }
    }

    int ans = 0;
    for(int i=0; i<n; i++){
        bool flag = false;
        for(int j=0; j<k; j++){
            if(former[i][j] == 1){
                int test = latter[i+2][k-1-j];
                if(k-a[i]-1-j >= 0) test -= latter[i+2][k-a[i]-1-j];
                
                if(test > 0) flag = true;
            }
        }
        if(flag == false) ans += 1;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int b[200001];

int main(void) {
    int i, a, n;
    cin >> n;
    int mid = (n - 1) / 2;
    for(i=0; i<n; i++) {
        cin >> a;
        if(i % 2 == 0) b[mid-(i+1)/2] = a;
        else           b[mid+(i+1)/2] = a;
    }

    if(n % 2 == 0) for(i=n-1; i>=0; i--) {
        printf("%d ", b[i]);
    }
    else for(i=0; i<n; i++) {
        printf("%d ", b[i]);
    }

    puts("");

    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    ll ans = 1e12;
    for(int i = 0; i < 1<<n; i++)
    {
        int count = __builtin_popcount(i);
        if(count != k) continue;
        ll cost = 0;
        int h = 0;
        for(int j = 0; j < n; j++)
        {
            if(i >> j & 1)
            {
                if(a[j] <= h)
                {
                    cost += h - a[j] + 1;
                    h++;
                }
                else
                {
                    h = a[j];
                }
            }
            else h = max(h, a[j]);
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[26];
int main(){
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++){
        a[s[i]-'a']++;
    }
    for(int i=0;i<26;i++){
        if(a[i]%2!=0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define DEC(x) fixed<<setprecision(x)
#define FAST ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);
const long long INF=2e18;

template<typename T,typename T1>void amax(T &a,T1 b){if(b>a)a=b;}
template<typename T,typename T1>void amin(T &a,T1 b){if(b<a)a=b;}

ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll modinv(ll a,ll m)
{
    return power(a,m-2,m);
}

// #define _NCR_

int TLE_TERROR()
{
 	ll n,l,r,f=0;
 	cin>>n;
 	vector<pll>v;
 	for(ll i=0;i<n;i++)
 	{
 		cin>>l>>r;
 		v.pb({l,r});
 	}
 	for(ll i=0;i<n-2;i++)
 	{
 		if((v[i].F==v[i].S)&&(v[i+1].F==v[i+1].S)&&(v[i+2].F==v[i+2].S))
 		{
 			f=1;
 			break;
 		}
 	}
 	if(f==1)
 		cout<<"Yes";
 	else
 		cout<<"No";
 	
 	return 0;   
}

int main()
{
    FAST
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll int TESTS=1;
    // cin>>TESTS;
    #ifdef _NCR_
        initialvalues();
    #endif
    while(TESTS--)
        TLE_TERROR();
    return 0;
}

Measured memory_bytes: 3640
n = int(input())
l = list(map(int, input().split()))

odd, even = [], []

for i in range(n):
    if (i + 1) % 2 ==1:
        odd += [l[i]]
    else:
        even += [l[i]]

even.reverse()
e_o = even + odd

if n % 2 == 1:
    e_o.reverse()
    print(*e_o)
else:
    print(*e_o)

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

int main() {
	// your code goes here
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(1){
		c=c-b;
		if(c<=0){
			cout<<"Yes";
			break;
		}
		a=a-d;
		if(a<=0){
			cout<<"No";
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b, c; cin >> a >> b >> c;
    if (a == b && a != c) puts("Yes");
    else if (a == c && a != b) puts("Yes");
    else if (b == c && a != b) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
		int countA = 0;
		int countB = 0;
		int A =0;
		int B =1;
		for (int i = 0; i < input.length() ; i++) {
			int tmp = combertInt(input,i);
			if(A == tmp) {
            	countA++;
            }
          	if(A==0) {
				A=1;
			}else{
				A=0;
			}
          	if(B == tmp) {
            	countB++;
            }
			if(B==1) {
				B=0;
			}else{
				B=1;
			}
		}
		System.out.println(Math.min(countA, countB));
	}
	
	private static Integer combertInt(String s, int i) {
		return Integer.parseInt(s.substring(i,i+1));
	}
}

Measured memory_bytes: 30560
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, x[50], y[50], res, cnt;
bool vis[50];
map<pair<int, int>, int>mp;

int main() {
	cin >> N;
	res = intmax;
	for (int i = 0; i < N; ++i) {
		cin >> x[i] >> y[i];
		mp[mkp(x[i], y[i])] = i;
	}
	if (N == 1)res = 1;
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			for (int k = 0; k < N; ++k) {
				vis[k] = false;
			}
			int p = x[j] - x[i];
			int q = y[j] - y[i];
			cnt = 0;
			for (int k = 0; k < N; ++k) {
				++cnt;
				cnt -= vis[k];
				vis[k] = true;
				if (mp.find(mkp(x[k] + p, y[k] + q)) != mp.end()) {
					cnt -= vis[mp[mkp(x[k] + p, y[k] + q)]];
					vis[mp[mkp(x[k] + p, y[k] + q)]] = true;
				}
			}
			res = min(res, cnt);
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	char s[11], d[11];
	int i, t, k,c,p,n;
	char o[11];
	char y;
	int flag=0;
	c = 0;
	scanf("%d %d", &n, &k);
	scanf("%c", &y);
	for (i = 0; i < k; i++)
	{
		scanf("%c", &d[i]);
		scanf("%c",&y);
	}


	for(t=0;t>=0;t++)
	{
		
		flag = 0;
		sprintf(s, "%d", n);
		for (i = 0;s[i]!='\0'; i++)
		{
			
			for (p = 0; p < k; p++)
			{
				if (d[p] == s[i])
				{
					flag = 1;
					n++;
					break;
				}
			}
			if (flag == 1)
				break;
		}
		if (flag == 1)
		{
			continue;
		}
			break;
		
	}
	printf("%d\n", n);
	return 0;
}

Measured memory_bytes: 128
def is_kaibun(s1):
    kaibun = True
    for a,b in zip(s1, s1[::-1]):
        if a != b:
            kaibun = False
    return kaibun

if __name__ == "__main__":
    s = input()
    n = len(s)

    hantei = "Yes"
    mae = s[0:int((n-1)/2)]
    ushiro = s[int((n+3)/2)-1:]
    if not is_kaibun(mae):
        hantei = "No"
    if not is_kaibun(ushiro):
        hantei = "No"
    if not is_kaibun(s):
        hantei = "No"
    print(hantei)

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

#define rep(i, N) for (int i = 0; i < N; i++)

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define NVALUE 3

int main()
{
    int N, M;
    cin >> N >> M;
    vector<ll> x(N), y(N), z(N);
    rep(i, N) cin >> x[i] >> y[i] >> z[i];

    ll max_sum = 0;
    rep(s, 1 << NVALUE)
    {
        // calculate total
        vector<ll> total(N, 0);
        rep(i, N)
        {
            total[i] += x[i] * ((s >> 0 & 1) ? 1 : -1);
            total[i] += y[i] * ((s >> 1 & 1) ? 1 : -1);
            total[i] += z[i] * ((s >> 2 & 1) ? 1 : -1);
        }

        // sort and sum
        sort(total.rbegin(), total.rend());
        ll sum = accumulate(total.begin(), total.begin() + M, 0LL);
        max_sum = max(max_sum, sum);
    }

    cout << max_sum << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int a, b;

int main()
{
    cin >> a >> b;
    string aa;
    string bb;
    rep(i, 0, b)
    {
        aa = aa + to_string(a);
    }
    rep(i, 0, a)
    {
        bb = bb + to_string(b);
    }
    if (aa < bb)
    {
        cout << aa << endl;
        return 0;
    }
    else
    {
        cout << bb << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s, t;
    while(cin >> s >> t){
        n = s.size();
        vector<vector<int>> tbl(26, vi(n, -1));
        REP(i, n) {
            tbl[s[i] - 'a'][i] = i;
        }
        REP(_, 2) {
            RREP(i, n) {
                REP(j, 26) {
                    if (tbl[j][i] == -1) {
                        tbl[j][i] = tbl[j][(i + 1) % n];
                    }
                }
            }
        }
        ll ans = 0, p = 0;
        REP(i, t.size()) {
            ll q = tbl[t[i] - 'a'][p];
            if (q == -1) {
                ans = -1;
                break;
            }
            if (q < p) ans += n;
            ans += q - p + 1;
            p = (q + 1) % n;
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main(void){

  int N,i,v,j,b,minj;
  int a[100]={};
  int temp;
  int time=0;

  scanf("%d",&N);

    for(i=0;i<N;i++){
   scanf("%d",&a[i]);
  } 


  for(i=0; i<N-1;++i){
    minj = i;

    for(j=i;j<N;++j){
      if(a[j]<a[minj]){
	minj=j;

      }
    }
      if(a[minj] != a[i]){
       temp=a[i];
      a[i]=a[minj];
      a[minj]=temp;
        time++;
      }

      }
      
      
     
 
    for(b=0;b<N;b++){

    printf("%d",a[b]);

    if(b!=N-1)
      printf(" ");

    }
    	printf("\n");
	printf("%d\n",time);
    }


  

Measured memory_bytes: 1852
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){
  int q;
  cin >> q;
  rep(i,q){
    string X,Y; cin >> X >> Y;
    vector<vector<int>> dp(1010,vector<int>(1010,0));
    rep(i,X.size())rep(j,Y.size()){
      if(X[i]==Y[j]){
        dp[i+1][j+1]=max({dp[i][j]+1,dp[i+1][j],dp[i][j+1]});
      }
      else{
        dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
      }
    }
    cout << dp[X.size()][Y.size()] << endl;
  }
  return 0;
}



Measured memory_bytes: 10812
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  ll r = 0, g = 0, b = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'R') r++;
    if (s[i] == 'G') g++;
    if (s[i] == 'B') b++;
  }
  ll ans = r * g * b;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int k = 2 * j - i;
      if (j < k && k < n && s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) {
        ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<cstdio>
int n,a[105],ans[105];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)scanf("%d",&a[i]);
	for (int i=n;i>=1;i--){
		int j=-1; 
		for (j=i;j>=1;j--)if (a[j]==j)break;
		if (!j){printf("-1\n");return 0;}
		ans[i]=j;
		for (int k=j;k<i;k++)a[k]=a[k+1];
	}
	for (int i=1;i<=n;i++)printf("%d\n",ans[i]);
} 

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

struct Dice {
  int label[6];
  void swap(int a, int b, int c, int d) {
    int temp = label[a];
    label[a] = label[b];
    label[b] = label[c];
    label[c] = label[d];
    label[d] = temp;
  }
  void roll(char dir) {
    switch (dir) {
    case 'N': swap(0, 1, 5, 4); break;
    case 'E': swap(0, 3, 5, 2); break;
    case 'W': swap(0, 2, 5, 3); break;
    case 'S': swap(0, 4, 5, 1); break;
    case 'R': swap(1, 2, 4, 3); break;
    }
  }
  bool is_same(Dice& d) {
    for (auto& dir : "RRRRNRRRRERRRRNRRRRERRRRNRRRR") {
      if (sequence_equal(d)) return true;
      roll(dir);
    }
    return false;
  }
  bool sequence_equal(Dice& d) {
    for (int i = 0; i < 6; i++) {
      if (label[i] != d.label[i]) return false;
    }
    return true;
  }
};

int main() {
  Dice a, b;
  for (int i = 0; i < 6; i++) {
    cin >> a.label[i];
  }
  for (int i = 0; i < 6; i++) {
    cin >> b.label[i];
  }
  cout << (a.is_same(b) ? "Yes\n" : "No\n");
}


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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<vector<long long>> mll;
typedef vector<pair<long long, long long>> vpl;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long>> mbl;
#define minimize(var, val) (var = min((val), var))
#define MOD ((long long)1e9 + 7)

int main() {
    ll n;
    cin >> n;
    vector<vector<bool>> a(n, vector<bool>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int temp;
            cin >> temp;
            a[i][j] = temp == 1;
        }
    }
    vll dp(1 << n, 0);
    dp[0] = 1;
    for (int women = 0; women < (1 << n); women++) {
        bitset<21> women_set(women);
        ll man = women_set.count() - 1;
        for (int woman_marrying = 0; woman_marrying < n; woman_marrying++) {
            if (!women_set.test(woman_marrying) || !a[man][woman_marrying])
                continue;
            dp[women] = (dp[women] + dp[women & ~(1 << woman_marrying)]) % MOD;
        }
    }
    cout << dp[(1 << n) - 1] << endl;
}

Measured memory_bytes: 16640