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

int main()
{
    int maxDist = 0;
    int prev = -1;
    for (int i = 0; i < 5; ++i)
    {
        int input;
        cin >> input;

        if (prev == -1)
        {
            prev = input;
        }
        else
        {
            maxDist = max(maxDist, input - prev);
        }
    }

    int k;
    cin >> k;

    cout << (maxDist > k ? ":(" : "Yay!") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

bool check(vector<string> &V){
	for(int i=0;i<V.size();i++){
		for(int j=0;j<V.size();j++){
			if(V[i][j]!=V[j][i])return false;
		}
	}
	return true;
}

int main(){

	int N;
	cin>>N;
	
	vector<string> V(N);
	
	for(int i=0;i<N;i++){
		cin>>V[i];
	}
	
	int ans = 0;
	
	for(int i=0;i<N;i++){
		if(check(V))ans+=N;
		
		V.push_back(V[0]);
		V.erase(V.begin());
	}
	
	cout<<ans<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n - 1];
        for(int i = 0; i < 2; i++){
            for(int j = 0; j < n; j++){
                switch(i){
                    case 0:
                        a[j] = scan.nextInt();
                        break;
                    case 1:
                        b[j] = scan.nextInt();
                        break;
                }
            }
        }
        int out = 0;
        for(int i = 0; i < n - 1; i++){
            c[i] = scan.nextInt();
        }
        for(int i = 0; i < n - 1; i++){
            if(a[i + 1] - a[i] == 1){
                out += c[a[i] - 1];
            }
        }
        for(int i = 0; i < n; i++){
            out += b[i];
        }
        System.out.println(out);
    }
}

Measured memory_bytes: 21204
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>

using namespace std;
typedef long long ll;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)


int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (A + B >= C)cout << "Yes";
    else cout << "No" << endl;
    return 0;
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

string getNextLunLun(string numStr){
  int l = numStr.length();
  int nextV = 0;
  int carryOverDigit = -1;
  for(int i=0;i<l; i++){
    int d = numStr[i]-'0';
    if(d==9){
      //carry over
      carryOverDigit = i;
      continue;
    }
    if(i==l-1) continue;
    int nextD = numStr[i+1]-'0';
    if(d==nextD+1){
      //carry over
      carryOverDigit = i;
    }
    else{
      //Ready to find next LunLun
      break;
    }
  }

  if(carryOverDigit==l-1) {
    for(int i=0;i<l; i++){
      numStr[i]='0';
    }
    numStr += '1';
    return numStr;
  }
  
  char baseNum = numStr[carryOverDigit+1];
  for(int i=0;i<=carryOverDigit;i++){
    numStr[carryOverDigit-i] = baseNum;
    if(baseNum>'0') baseNum--;
  }
  numStr[carryOverDigit+1]++;
  return numStr;
}

signed main() {
  int64_t k;
  cin >> k;
  
  string numStr = "1";
  for(int64_t i=1;i<k;i++){
    numStr = getNextLunLun(numStr);
  }
  reverse(numStr.begin(),numStr.end());
  cout << numStr << endl;
  return 0;
}



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

int main() {
	// your code goes here
	int n,m,sum=0;
	cin>>n>>m;
	int a[m];
	for(int i=0;i<m;i++){
		cin>>a[i];
		sum+=a[i];
	}
	if(sum>n)
	cout<<"-1"<<endl;
	else
	cout<<n-sum<<endl;
	return 0;
}

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

#define pb push_back
#define rb  pop_back
#define rf  pop_front
#define ins insert
#define f   first
#define s   second
#define um  unordered_map
#define us  unordered_set
#define pq  priority_queue

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
typedef pair< long long int ,long long int > iil;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef vector<double> vd;
typedef pair<double,double> pd;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef us<int> si;
typedef us<double> sd;
typedef us<ll> sll;
typedef vector<vd> md;


const int MAX = 1e6;
const int N = 200043;
const int MOD = 998244353;

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for( auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define EE endl
#define PI 3.14159265
#define g(a,b) a>b?a:b
#define l(a,b) a<b?a:b
#define SOT(A) sort(A.begin(),A.end())
#define SOTR(A) sort(A.rbegin(),A.rend())
#define REV(a) reverse(ALL(a))

// LOOP Control Statements
#define forn(i,j,n) for ( auto i=j ; i<n ; i++ )
#define fornd(i,j,n) for ( auto i=j ; i>n ; i-- )
#define FORE(i, b) for(auto &i:b)


#define SQ(i) (i*i)
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) cout << i << " "; cout << endl
#define take(V,f,n) for(int i=f;i<f+n;i++) cin>>V[i]
#define tcase(term) int tc;cin>>tc;for(int term=0; cout<<"CASE "<<term+1<<EE,term<tc;term++)





int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	// tcase(terms)
	{
		ll n,x,g=1e10;
		cin>>n>>x;
		vl X(n);
		forn(i,0,n) cin>>X[i];
		X.pb(x);
		SOT(X);
		set<ll> A;
		forn(i,1,n+1){
			A.insert(X[i]-X[i-1]);
			g=min(g,X[i]-X[i-1]);
		}
		for(auto y:A){
			// cout<<y<<" "<<g<<endl;
			g=__gcd(g,y);
		}
		cout<<g<<endl;

	}
}


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

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

inline void Main() {
  // code
  int n, l, r = 0;
  cin >> n;
  l = to_string(n).length();

  if(l % 2 == 1) {
    r += n - pow(10, l-1) + 1;
  }

  rep(i, l-1) {
    if((i+1) % 2 == 1) {
      r += pow(10, i+1) - pow(10, i);
    }
  }

  cout << r << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 512
import java.util.*;
public class Main {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();
    int max =a;
    int cd =0;
if(b>=max){
max =b;
cd =1;
}
if(c>=max){
max =c;
cd =2;
}
for(int i=0;i<k;i++){
 max = max *2;
}
if(cd ==0){
max =max+b+c;
}else if(cd ==1){
max =max+a+c;
}else{
max = max+a+b;
}
 
 System.out.println(max);
 }
}

Measured memory_bytes: 21460
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
ll n,a[100005]={0};
cin>>n;
ll ans=0;
rep(i,1,n)
{
	cin>>a[i];
	
}
a[n+1]=0;
rep(i,1,n)
{
	if(a[i]%2==1)
	{
		if(a[i+1]>0)
		{
			a[i]++;a[i+1]--;
		}
		ans+=a[i]/2;
	}
	else
	{
		ans+=a[i]/2;
	}
}
ol(ans);
return 0;
}


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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int A,B;
    string S,T,U;
    cin >> S >> T >> A >> B >> U;
    if(S==U){
        P2(A-1,B);
    }else{
        P2(A,B-1);
    }
}

Measured memory_bytes: 256
// E.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
	int n, k, q;
	cin >> n >> k >> q;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	int ans = 1 << 30;
	for (int i = 0; i < n; ++i) {
		vector<int> x, y;
		for (int j = 0; j <= n; ++j) {
			if (j == n || a[j] < a[i]) {
				if (y.size() >= k) {
					sort(y.begin(), y.end());
					x.insert(x.end(), y.begin(), y.end() - k + 1);
				}
				y.clear();
			} else {
				y.push_back(a[j]);
			}
		}
		if (x.size() >= q) {
			sort(x.begin(), x.end());
			ans = min(ans, x[q - 1] - x[0]);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
//NIL is NULL
#define NIL NULL
//Node structure
struct Node{
  int key;
  struct Node *parent;
  struct Node *leftc;
  struct Node *rightc;
};
//define Nodepointer
typedef struct Node * Nodepointer;

//root         
Nodepointer root;

//function insert
void insert(int k){
  Nodepointer x,y,z;
  y=NIL;
  x=root;
  //make memory
  z=new struct Node();

  z->key=k;
  z->leftc=NIL;
  z->rightc=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->leftc;
    else x=x->rightc;
  }

  z->parent=y;

  if(y==NIL) root=z;

  else if(z->key<y->key) y->leftc=z;

  else y->rightc=z;


}

//function search
Nodepointer find(Nodepointer now,int data){
  if(now==NIL||data==now->key) return now;
  if(data<now->key) return find(now->leftc,data);
  else return find(now->rightc,data);
}

//function treeminimum
Nodepointer treeminimum(Nodepointer x){
  while(x->leftc!=NIL){
    x=x->leftc;
  }
  return x;
}
//function treesuccerssor
Nodepointer treesuccessor(Nodepointer x){
  Nodepointer y;
  if(x->rightc!=NIL) return treeminimum(x->rightc);
  y=x->parent;
  while(y!=NIL && x==x->rightc){
    x=y;
    y=y->parent;
  }
  return y;
}
//function treedelete
void treedelete(Nodepointer z){
  Nodepointer x,y;
  if(z->leftc==NIL ||z->rightc==NIL)y=z;
  else y=treesuccessor(z);

  if(y->leftc!=NIL)x=y->leftc;
  else x=y->rightc;
 
  if(x!=NIL)x->parent=y->parent;
  if(y->parent==NIL) root=x;
  else if(y==y->parent->leftc) y->parent->leftc=x;
  else y->parent->rightc=x;
  if(y!=z) z->key=y->key;

}

//print
void inorderprint(Nodepointer now){
  if(now!=NIL){
    inorderprint(now->leftc);
    printf(" %d",now->key);
    inorderprint(now->rightc);
  }
}

void preorderprint(Nodepointer now){
  if(now!=NIL){
    printf(" %d",now->key);
    preorderprint(now->leftc);
    preorderprint(now->rightc);
  }
}


int main(){

  int n,i,j,data;
  Nodepointer del;
  char str[10];
  //load n
  scanf("%d",&n);
  //load commnad and key
  for(i=0;i<n;i++){
    scanf("%s",str);
    //insert
    if(strcmp(str,"insert")==0) {
      scanf("%d",&data);
      insert(data);
    }
    //find
    else if(strcmp(str,"find")==0){
      scanf("%d",&data);
      if(find(root,data)!=NIL) printf("yes\n");
      else printf("no\n");
    }
    //delete
    else if(strcmp(str,"delete")==0){
      scanf("%d",&data);
      del=find(root,data);
      treedelete(del);
    }
    //print
    else if(strcmp(str,"print")==0){
      inorderprint(root);
      cout <<endl;
      preorderprint(root);
      cout <<endl;
    }
  }

  return 0;
}

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

typedef vector<int> veci;
typedef pair<int, int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9 + 7)
#define fi first
#define se second
#define endl '\n'

void solve() {
    int h, a;
    cin >> h >> a;

    cout << h/a+(h%a==0?0:1) << endl;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL_TEST
    (void)argc;
    const string strpath = string(argv[0]) + string("-test.in");
    freopen(strpath.c_str(), "r", stdin);
    int tcs;
    cin >> tcs;
    while (tcs-- > 0)
#endif
        solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int N;
int HS[1001];
int main(){
  cin>>N;
  ll res=1;
  for(int i=0;i<N;i++)cin>>HS[i];
  if(N==1){
    cout<<HS[0]+1<<endl;
    return 0;
  }
  sort(HS,HS+N,greater<int>());
  int pos=0;
  res+=HS[pos++];
  res+=HS[pos++];
  int cnt=0;
  int add=0;
  for(int i=pos;i<N;i++){
    if(cnt<2)res+=max(HS[i]-add,0);
    else res+=max(HS[i]-add-1,0);
    cnt++;
    cnt%=4;
    if(cnt==0)add++;
  }
  cout<<res<<endl;
  
  return 0;
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;

	int x = N / 2;
	x += N & 1;
	dump(x);
	cout << (double)(x) / N << endl;

	return 0;
}


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

const int maxn = 500;

int n, a[maxn][maxn];
long long from[maxn][maxn], to[maxn][maxn], dp[2][maxn][maxn], ans;

void cmin(long long &x, long long y) { x = min(x, y); }

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) if (j != i) {
			scanf("%d", &a[i][j]);
			from[i][j] = (j?from[i][j-1]:0) + a[i][j];
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			to[i][j] = (j?to[i][j-1]:0) + a[j][i];
		}
	}
	memset(dp[0], 0x3f, sizeof(dp[0]));
	ans = dp[0][0][0];
	dp[0][0][0] = 0;
	for (int i = 0; i < n-1; ++i) {
		memset(dp[i&1^1], 0x3f, sizeof(dp[0]));
		for (int j = 0; j <= i; ++j) {
			for (int k = 0; k <= j; ++k) {
				cmin(dp[i&1^1][j][k], dp[i&1][j][k]+(to[i+1][i]-(j?to[i+1][j-1]:0))+(k?from[i+1][k-1]:0));
				cmin(dp[i&1^1][i+1][j], dp[i&1][j][k]+(j?from[i+1][j-1]:0));
			}
		}
	}
	for (int j = 0; j < n; ++j)
		for (int k = 0; k <= j; ++k)
			cmin(ans, dp[n&1^1][j][k]);
	cout << ans << endl;
}


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

int main() {
    string S;
    cin >> S;
    stack<char> A;
    int res = 0;
    for(int i=0; i<S.size(); ++i) {
        if(S[i] == '0') {
            if(A.size() && A.top() == '1') {
                ++res;
                A.pop();
            } else {
                A.push('0');
            }
        } else {
            if(A.size() && A.top() == '0') {
                ++res;
                A.pop();
            } else {
                A.push('1');
            }
        }
    }
    cout << 2 * res << endl;
}

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

const int maxn = 1e5 + 10;
int n, l, r, q[maxn], vis[maxn];
vector <int> e[maxn];

int main()
{
	cin >> n;
	for (int i = 1, u, v; i < n; i++) {
		scanf("%d%d", &u, &v);
		e[u].push_back(v), e[v].push_back(u);
	}
	l = 1, r = 0;
	vis[1] = 1; vis[n] = 2;
	q[++r] = 1; q[++r] = n;
	while (l <= r) {
		int u = q[l++];
		for (int v : e[u]) {			
			if (!vis[v]) {
				vis[v] = vis[u];
				q[++r] = v;
			}
		}
	}
	int sum1 = 0, sum2 = 0;
	for (int i = 1; i <= n; i++) {
		if (vis[i] == 1)sum1++;
		else sum2++;
	}
	puts(sum1 > sum2 ? "Fennec" : "Snuke");

	return 0;
}

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

Bool = True

aintlist = input().split(" ")

alist=[]

for i in range(n):
    alist.append(int(aintlist[i]))

for i in range(n):
    if alist[i]%2==0 and not(alist[i]%3==0 or alist[i]%5==0):
        Bool = False

if Bool == True:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

ll _find(ll n){
    int cnt=0;
    while(n%2==0){
        cnt++;
        n/=2;
    }    
    return cnt;
}
void solve(){
    
    int n;
    cin>>n;
    
    ll ans=0;
    while(n-->0){
        ll x;
        cin>>x;
        ans+=_find(x);
    }
    cout<<ans<<endl;
}

int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<stdio.h>
#define N 30
using namespace std;
int main(){
  int w,n,tmp;
  int lod[N]; int lis[N][3];
  while(cin >> n >> w){
  for(int i = 0;i<n;i++){
    lod[i] = i+1;
  }
 
  for(int i=0;i<w;i++){
    scanf("%d,%d",&lis[i][0],&lis[i][2]);
  }
  for(int i=0;i<w;i++){
    tmp = lod[lis[i][0]-1];
    lod[lis[i][0]-1] = lod[lis[i][2]-1];
    lod[lis[i][2]-1] = tmp;
  }
  for(int i=0;i<n;i++){
    cout << lod[i] << endl;
  }
  }
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e18;
template<typename T> void cmax(T &a, T b) {a = max(a, b);}
template<typename T> void cmin(T &a, T b) {a = min(a, b);}

signed main(){
  string s;
  cin>>s;
  cout<<(s.size()%2==0^s.front()==s.back()?"Second":"First")<<endl;
  return 0;
}


Measured memory_bytes: 512
//#include "b_impl.hpp"

//int main() {
//  freopen("/Users/simon/tmp/test.txt", "r", stdin);
//  // freopen("/Users/simon/tmp/test_output.txt", "w", stdout);
//  int num_cases;
//  cin >> num_cases;
//  for (int i = 0; i < num_cases; ++i) {
//    cout << "Case #" << i + 1 << ": ";
//    solve();
//  }
//}

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

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

void solve() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;

  if (d < b || a < b) {
    cout << "No" << endl;
    return;
  }

  if (b <= c + 1) {
    cout << "Yes" << endl;
    return;
  }

  long long g = gcd(b, d);
  long long k = (b - a % b + g - 1) / g  - 1;
  long long mx = a % b + k * g;
  if (mx <= c) {
    cout << "Yes" << endl;
    return;
  }

  cout << "No" << endl;
}

int main() {
//  freopen("/Users/simon/tmp/test.txt", "r", stdin);

  int num_cases;
  cin >> num_cases;
  for (int i = 0; i < num_cases; ++i) {
    solve();
  }
}


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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

int main() {
    ll n, k;
    vector<ll> monsters;

    cin >> n >> k;

    ll tmp;
    REP(i, n){
        cin >> tmp;
        monsters.PB(tmp);
    }

    sort(ALL(monsters));

    ll ans = 0;
    REP(i, n-k){
        ans += monsters[i];
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    string s;
    cin >> s;
    for (int i = 1; i != s.size(); ++i) {
        if (s[i-1] == s[i]) {
            cout << i-1+1 << " " << i+1 << endl;
            return 0;
        } else if (i > 1 && s[i-2] == s[i]) {
            cout << i-2+1 << " " << i+1 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <vector>
#include <algorithm>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;

#define rep(i,n) for(int i=0; i<(n); i++)
LL floor_usr(LL a, int b){ return (a + (b - 1)) / b;}
const int maxN =200001;
// 当分割するのが最適なメソッド。
// 各丸太についてn[i]回切るとすると、最大n[i]+1で割った値になる。
// n[i](sum(n[i])=K)を最適に分配するという問題に帰着する。
// O(nlog(K))かO(Klog(n))ぐらいならいけそう。後者はソートか？
// 基本、数値に比例した(n+1)を当てれば全ての丸太は均一な大きさになる。
// その和をKに合わせればそもそも計算がいらないか。A[i]=min*(n[i]+1)
int main() {
  int N, K; scanf("%d %d" ,&N, &K);

  LL A[maxN]; 

  LL sumA = 0;
  vector<vector<LL>> dn;
  rep(i, N) scanf("%ld",&A[i]);
  sort(A, A+N);
  rep(i, N) sumA += A[i];
  int n;
  int sumn = 0;
  rep(i, N){
    if(sumA!=0) n = K*A[i]/sumA;
    else n = 0;
    sumn += n;
    dn.push_back({floor_usr(A[i],(n+1)),A[i], n});
  }

  vector<LL> B;
  sort(dn.begin(), dn.begin()+N, greater<vector<LL>>());
  rep(i, K-sumn){
    dn[i%N][2]++;
    dn[i%N][0] = floor_usr(dn[i%N][1], dn[i%N][2]+1);
  }
  sort(dn.begin(), dn.begin()+N, greater<vector<LL>>());
  printf("%ld", dn[0][0]);
  //真の値より一回小さいnが得られているので、追加するiを選んで最小値を求める
  return 0;
}



Measured memory_bytes: 15852
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int c[3][3];
int n = 3;

int main(){
    rep(i,n)rep(j,n) cin >> c[i][j];
    for(int a1 = 0; a1 <= 100; a1++){
        int b1 = c[0][0] - a1;
        int b2 = c[0][1] - a1;
        int b3 = c[0][2] - a1;

        int a2 = c[1][0] - b1;
        int a3 = c[2][0] - b1;

        if (a2+b2 != c[1][1]) continue;
        if (a2+b3 != c[1][2]) continue;
        if (a3+b2 != c[2][1]) continue;
        if (a3+b3 != c[2][2]) continue;
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n, m;

int main() {
	cin >> n >> m;
	cout << (n - 1)*(m - 1) << endl;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> X(N);
    for (int i = 0; i < N; i++) {
        cin >> X.at(i);
    }

    int sum = 0;
    for (int i = 0; i < N; i++) {
        sum += min(X.at(i), K - X.at(i));
    }
    cout << sum * 2 << endl;
}

Measured memory_bytes: 3576
N = gets.to_i

hs = gets.split.map{|i| i.to_i }
 
sum = 0
 

hs.length.times do |i|
  while hs[i] > 0
    hs[i] -= 1
    sum += 1
    for j in 1..hs.length - i - 1 do
      break if(hs[i+j] <= 0)
      hs[i+j] -= 1
    end
  end

end

puts sum

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <queue>
#include <string>

using namespace std;

int main()
{
	long long n;
	cin >> n;
	queue<unsigned long long> q;
	q.push(1);
	q.push(2);
	q.push(3);
	q.push(4);
	q.push(5);
	q.push(6);
	q.push(7);
	q.push(8);
	q.push(9);

	unsigned long long ans = 0;
	for (long long i = 0; i < n; ++i)
	{
		ans = q.front();
		q.pop();
		if (ans % 10 != 0) q.push(ans * 10 + (ans % 10) - 1);
		q.push(ans * 10 + (ans % 10));
		if (ans % 10 != 9) q.push(ans * 10 + (ans % 10) + 1);
	}

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

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;


int main(){
    string S;
    cin >> S;
    int ans = 0;
    int num=1;
    int N=S.length();
    for(int i=1; i<=N; i++){
        if(i==N || S[i]!=S[i-1]){
            ans += (num/3)*2;
            if(num%3==0){
            }else if(num%3==1){
                ans++;
            }else if(num%3==2){
                if(i==N){
                    ans++;
                }else{
                    ans+=2;
                    S[i]='.';
                    i++;
                }
            }
            
            num=1;
        }else{
            num++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
S = input()
upper = int(S[:2])
lower = int(S[2:])
if 1 <= upper <= 12:
  if 1 <= lower <= 12:
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if 1 <= lower <= 12:
    print('YYMM')
  else:
    print('NA')
    

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
// #include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{ 
  string str;cin>>str;
  int P = 0;
  int res = 0;
  for (auto &&s : str)
  {
    if(P == 0)
    {
      if(s == 'p')
      {
        res--;
        P++;
      }
      else
      {
        P++;
      }
    }
    else
    {
      if(s == 'p')
      {
        P--;
      }
      else
      {
        P--;
        res++;
      }
    }
    
  }
  cout<<res<<endl;
  

  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


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

using namespace std;
typedef long long int lli;
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
typedef pair<lli, lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
#define EPS 1e-6
const lli MAX = 1e9 + 7;

int main()
{
    fast;
    int t = 1;
    while (t--)
    {
        string s, t;
        cin >> s >> t;
        int n = t.size();
        int ans = n;
        for (int i = 0; i <= s.size() - n; i++)
        {
            int diff = 0;
            for (int j = 0; j < n; j++)
                if (s[i + j] != t[j])
                    diff++;
            ans = min(ans, diff);
        }
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 3644
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define mod 1000000007
#define mod1 998244353
#define INF LLONG_MAX
#define NINF LLONG_MIN
#define inf 1e18
#define all(v) v.begin(),v.end()
#define T ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define rep1(i,a,n) for(ll i=a;i<=(long long)n;++i)
#define rep2(i,n,a) for(ll i=n;i>(long long)a;--i)
#define rep3(i,n,a) for(ll i=n;i>=(long long)a;--i)
#define repi(i,a,n) for(int i=a;i<=(int)n;++i)
#define repl(i,a,n) for(int i=a;i<(int)n;++i)
#define PI 3.141592653589793238510
#define en '\n'
#define MAX 100005
#define less_time ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define debug cout<<"HERE"<<en;
#define setbits(x)  __builtin_popcountll(x)
#define zrobits(x)  __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vi vc<int>
#define mii unordered_map<int,int>
#define pql priority_queue<int>
#define pqs priority_queue<int,vi,greater<int>>
#define vll vector<long long>
#define pll pair<long long,long long>
#define pl pair<int,int>
#define eb emplace_back
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace std::chrono;
int main(){
    less_time;
    int h,w;
    cin>>h>>w;
    char mat[h+5][w+5];
    ll dp[h+5][w+5];
    memset(dp,0,sizeof dp);
    repi(i,1,h)
     repi(j,1,w)
      cin>>mat[i][j];
    repi(i,1,w)
    {
      if(mat[1][i]=='.')
      dp[1][i]=1ll;
      else
      break;
    }
    repi(i,1,h)
    {
      if(mat[i][1]=='.')
      dp[i][1]=1ll;
      else
      break;
    }
    repi(i,2,h)
    {
      repi(j,2,w)
      {
        if(mat[i][j]=='#')continue;
        else
        {
          if(mat[i-1][j]!='#')
          dp[i][j]=(dp[i][j]+dp[i-1][j]+mod)%mod;
          if(mat[i][j-1]!='#')
          dp[i][j]=(dp[i][j]+dp[i][j-1]+mod)%mod;
        }
      }
    }
    cout<<dp[h][w];
return 0;
}


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

int main() {
	long long N;
	cin >> N;
	long long ans = 0;
	if (N % 2 == 0) {
		long long b = 10;
		while (b <= N) {
			ans += N / b;
			b *= 5;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>

using namespace std;

char affine(int a, int b, char c)
{
    if(c == ' ') return c;
    else return (a*(c-'a')+b)%26+'a';
}
int gcd(int a, int b)
{
    if(a<b) swap(a,b);
    while(b!=0){
        int t = a%b;
        a = b;
        b = t;
    }
    return a;
}
int main()
{
    int n;
    string str;
    cin >> n;
    getline(cin, str);
    while(n)
    {
        bool f=0;
        getline(cin, str);
        string ss="";
        for(int i=0;i<100&&!f;++i)
        {
            for(int j=0;j<26&&!f;++j)
            {
                if(gcd(i,j)!=1) continue;
                for(int k=0;k<str.length();++k){
                    ss += affine(i,j,str[k]);
                }
                if(ss.find("that")!=string::npos ||
                   ss.find("this")!=string::npos)
                {
                    cout << ss << endl;
                    f = 1;
                }
                ss.clear();
            }
        }
        --n;
    }

}

Measured memory_bytes: 1220
#include <stdio.h>
int main(void){
	long int i=0,a[1000000]={0},j[1000000]={0},tya=0,t=0,b=0;
	scanf("%ld",&b);
	for(i=0;i<b;i++){
		scanf("%ld",&a[i]);
	}
	j[0]=0;
	i=0;
	t=1;
	while(i!=b){
	if(a[i]<=a[i+1]){
		j[t]=0;
		i++;
		t++;
	}
	else if(a[i]>a[i+1]){
		j[t]=a[i]-a[i+1];
		a[i+1]=a[i+1]+j[t];
		i++;
		t++;
	}
	}
	t=0;
	while(t!=b){
	tya=tya+j[t];
	t++;
	}
	printf("%ld\n",tya);
	return 0;
}

Measured memory_bytes: 17328
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  sort(ALL(A));

  int P = 0, Q = 0;
  REP(i, N) if(A[i] < 0)  P++;
  REP(i, N) if(A[i] >= 0) Q++;
  if(Q == 0) Q++, P--;
  if(P == 0) P++, Q--;


  vector<pair<int, int>> ans;
  FOR(i, P+1, N){
    ans.emplace_back(A[0], A[i]);
    A[0] -= A[i];
  }
  REP(i, P){
    ans.emplace_back(A[P], A[i]);
    A[P] -= A[i];
  }

  cout << A[P] << endl;
  REP(i, ans.size()){
    cout << ans[i].first << " " << ans[i].second << endl;
  }


  return 0;
}

Measured memory_bytes: 4336
n = int(input())
s = input()

R = []
G = []
B = []
for i in range(n):
    if(s[i] == 'R'):
        R.append(i)
    elif(s[i] == 'G'):
        G.append(i)
    else:
        B.append(i)

samu = len(R) * len(G) * len(B)

for i in R:
    for j in G:
        k = int(2 * j - i)
        if(0 <= k < n):
            if(s[k] == 'B'):
                samu -= 1
        k = int(2 * i - j)
        if(0 <= k < n):
            if(s[k] == 'B'):
                samu -= 1
        if(i % 2 == j % 2):
            k = int((i + j) / 2)
            if(s[k] == 'B'):
                samu -= 1

print(samu)

Measured memory_bytes: 9232
import java.util.*;
import java.io.*;
 
public class Main {
    static boolean[] arrived;
    static ArrayList<ArrayList<Integer>> li;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        System.out.println(sc.nextInt()/3);
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }
    
    public void close() throws Exception{
        this.reader.close();
        return;
    }

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

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

int main() {
    int n,k;
    cin >> n >> k;
    vector<double> vt(n);
    double s=0, M=0;
    rep(i,n) {
        int p;
        cin >> p;
        vt.at(i) = (double) (p+1)/2;
    }
    rep(i,k) s += vt.at(i);
    M = s;
    for(int i=0; i<n-k; ++i) {
        s = s - vt.at(i) + vt.at(i+k);
        M = max(M,s);
    }
    // M /= 2;
    cout << fixed << setprecision(10) << M << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
#include <functional>
using namespace std;
int main() {
	int n,a;
	cin >> n >> a;
	n %= 500;

	if (n<=a) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,M;
const int INFTY = 99999; 
vector<list<int>> G;
vector<int> dis;
bool POSSIBLE = false;

void print_list(list<int> list){
  for(auto itr = list.begin(); itr != list.end(); itr++){
    cout << *itr << ' ';
  }
}
void bfs(){
  queue<int> q;
  dis.at(0) = 0;
  q.push(0);
  int u;
  list<int> list;
  while(!q.empty()){
    u = q.front(); q.pop();
    list = G.at(u);
    if(dis.at(u) <= 2 && u == N - 1){
      POSSIBLE = true;
      return;
    }
    for(auto itr = ++list.begin(); itr != list.end(); ++itr){
      if(dis.at(*itr) == INFTY){
        q.push(*itr);
        dis.at(*itr) = dis.at(u) + 1;
      }
    }
  }
}

int main(){
  cin >> N >> M;
  G = vector<list<int>>(N);
  dis = vector<int>(N,INFTY);
  for(int i = 0; i < N; i++){
    G.at(i).push_back(i);
  }
  for(int i = 0; i < M; i++){
    int a,b; cin >> a >> b;
    a--;
    b--;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }
  /*for(int i = 0; i < N; i++){
    Print_list(G.at(i));
    cout << endl;
  }*/
  bfs();
  if(POSSIBLE) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 26496
#include <iostream>
#include <algorithm>
using namespace std;
int a[100];

int main(){
    int n,count = 0;
    cin >> n;
    for(int i = 0;i < n;i++)
        cin >> a[i];
    bool flag = 1;
    int i = 0;
    while(flag){
        flag = 0;
        for(int i = 0;i < n;i++){
            if(a[i] < a[i-1]){
                swap(a[i],a[i-1]);
            flag = 1;
            count++;
            }
        }
    }   
    for(int i = 0;i < n;i++){
        if(i == 0)
            cout << a[i];
        else
            cout << ' ' << a[i];
    }
    cout << '\n' << count << endl;

    return 0;
}



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

int main() {
  string s,t;
  cin>>s>>t;
  
  bool ans=false;
  int a=0;
  if(s.size()+1==t.size())a++;
   for (int i = 0; i < s.size(); i++) { 
     if(s[i]==t[i])a++;
   }
  if(a==t.size())ans=true;

 if(ans)cout<<"Yes"<<endl;
else{cout<<"No"<<endl;}
    
}


Measured memory_bytes: 3624
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
    int n;
    int t,a;
    cin>>n;
    cin>>t>>a;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }

    int ans=1;
    int pos=1;
    int dif;
    for(int j=0;j<n;j++){
        int tmp = 0;
        tmp = a*1000-(t*1000-6*h[j]);
        tmp = abs(tmp);
        if(j==0) dif = tmp;
        if(dif>tmp && j>=1){
            ans = pos;
            dif = tmp;
        } 
        pos++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
fun main() {
    println(if (readInt() >= 30) "Yes" else "No")
}

// Input Reader
private fun readLn() = readLine()!!

private fun readStrings() = readLn().trim().split(" ")
private fun readInt() = readLn().toInt()
private fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 34564
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
int main(){
  int n,m; cin >> n >> m;
  vector<int> k(n);
  vector<vector<int>> a(n,vector<int>(m));
  rep(i,n){ cin >> k[i]; rep(j,k[i]) cin >> a[i][j]; }
  vector<vector<int>> v(n,vector<int>(m+1,0));
  rep(i,n) rep(j,k[i]) v[i][a[i][j]]=1;
  int ans = 0;
  rep(j,m+1){
    int cnt=0;
    rep(i,n) cnt += v[i][j];
    if(cnt==n)ans++;
  }
  cout << ans;
  

  return 0;
}

Measured memory_bytes: 256