akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

const int MAXN = 8010;
bool dpx[MAXN][2 * MAXN];
bool dpy[MAXN][2 * MAXN];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int x, y, n;
    cin >> s >> x >> y;
    n = s.size();

    vector<int> t;
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        if(s[i] == 'T') {
            if(cnt != 0) {
                t.emplace_back(cnt);
            }
            t.emplace_back(0);
            cnt = 0;
        } else {
            cnt++;
            if(i == n - 1) {
                t.emplace_back(cnt);
            }
        }
    }

    const int OFFSET = 8000;
    dpx[0][OFFSET] = dpy[0][OFFSET] = true;
    bool flg = false; // 最初はx軸正方向しか進まないので
    bool xy = true;   // true:x軸について見ている false:y軸
    int cntX = 0, cntY = 0;

    for(int i = 0; i < (int)t.size(); i++) {
        if(t[i] == 0) {
            xy = !xy;
        } else if(xy) {
            cntX++;
            for(int j = 0; j < 2 * MAXN; j++) {
                if(dpx[cntX - 1][j]) {
                    if(j + t[i] < 2 * MAXN) {
                        dpx[cntX][j + t[i]] = true;
                    }
                    if(j - t[i] >= 0 && flg) {
                        dpx[cntX][j - t[i]] = true;
                    }
                }
            }
        } else if(!xy) {
            cntY++;
            for(int j = 0; j < 2 * MAXN; j++) {
                if(dpy[cntY - 1][j]) {
                    if(j + t[i] < 2 * MAXN) {
                        dpy[cntY][j + t[i]] = true;
                    }
                    if(j - t[i] >= 0) {
                        dpy[cntY][j - t[i]] = true;
                    }
                }
            }
        }

        if(!flg) {
            flg = true;
        }
    }

    if(dpx[cntX][OFFSET + x] && dpy[cntY][OFFSET + y]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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


int main() {
	
	int n;
	cin >> n;
	vector<int> d(n);
	int sum=0;
	for(auto &i: d) cin >> i;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(i==j) continue;
			else{
				sum += d.at(i)*d.at(j);
			}
		}
	}
	cout << sum/2 << endl;
	
	return 0;
}

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

const lint MOD = 1e9 + 7;
const int MAX_N = 1005;
int N, M, A[MAX_N], B[MAX_N], C[MAX_N*MAX_N], D[MAX_N*MAX_N], E[MAX_N*MAX_N];

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    cin >> N >> M;
    for(int i=0;i<N;i++) {cin >> A[i]; D[A[i]]++;}
    for(int i=0;i<M;i++) {cin >> B[i]; E[B[i]]++;}

    for(int i=0;i<N;i++) for(int j=0;j<M;j++) C[min(A[i], B[j])]++;

    lint ans = 1;
    for(int i=N*M;0<i;i--){
        if(D[i]>1 || E[i]>1) {cout << 0 << endl; return 0;}
        else if(D[i] && E[i]) C[i]+=C[i+1];
        else if(D[i] || E[i]) {ans = ans * C[i] % MOD; C[i] += C[i+1];}
        else{
            C[i] += C[i+1];
            if(C[i]-N*M+i<=0) {cout << 0 << endl; return 0;}
            ans = ans * (C[i]-N*M+i) % MOD;
        }
    }

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

Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f(i,p,q) for(int i=p;i<q;i++)
#define vi vector<int>v;
#define tc int t; cin>>t; while(t--)
//#define an long long n; cin>>n; long long a[n]; for(int i=0;i<n;i++) cin>>a[i];
int main()
{   
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    long long i,j,x,y,len; string s; bool flag;
    // tc{
        
    // }
    cin>>s; len=s.length(); char ch = s[len-1];
    if(ch=='s')
    {
        cout<<s<<"es"<<endl;
    }
    else
    {
        cout<<s<<"s"<<endl;
    }
}


Measured memory_bytes: 3632
n,m,x,y=map(int, input().split())
x_list=[int(i) for i in input().split()]
y_list=[int(i) for i in input().split()]

ans="War"

for i in range(x+1, y+1):
    if max(x_list)<i<=min(y_list):
        ans="No War"
        break

print(ans)
        

Measured memory_bytes: 9004
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((a (read))
         (p (read)))
    (incf p (* 3 a))
    (println (floor p 2))))

#-swank(main)


;; For Test
#+swank
(defun io-equal (in-string out-string &optional (func #'main))
  (labels ((ensure-last-lf (s)
             (if (and (> (length s) 0)
                      (eql (char s (- (length s) 1)) #\Linefeed))
                 s
                 (uiop:strcat s uiop:+lf+))))
    (equal (ensure-last-lf out-string)
           (with-output-to-string (out)
             (let ((*standard-output* out))
               (with-input-from-string (*standard-input* (ensure-last-lf in-string))
                 (funcall func)))))))

#+swank
(defun get-clipbrd ()
  (with-output-to-string (out)
    (run-program "C:/msys64/usr/bin/cat.exe" '("/dev/clipboard") :output out)))

#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))
#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* "test.dat" *this-pathname*))

#+swank
(defun run (&optional thing (out *standard-output*))
  (let ((*standard-output* out))
    (etypecase thing
      (null ; Runs #'MAIN with the string on clipboard
       (with-input-from-string (*standard-input* (delete #\Return (get-clipbrd)))
         (main)))
      (string
       (with-input-from-string (*standard-input* (delete #\Return thing))
         (main)))
      (symbol (5am:run! thing))
      (pathname ; Runs #'MAIN with the string in a text file
       (with-open-file (*standard-input* thing)
         (main))))))

#+swank
(defun gen-dat ()
  (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)
    (format out "")))

#+swank
(defun bench (&optional (out (make-broadcast-stream)))
  (time (run *dat-pathname* out)))


Measured memory_bytes: 16232
#include<iostream>
using namespace std;
int main(){
	int x1,y1,x2,y2,x3,y3,x4,y4;
	cin>>x1>>y1>>x2>>y2;
	x3=x2-(y2-y1);
	y3=y2+(x2-x1);
	x4=x3-(x2-x1);
	y4=y3-(y2-y1);
	cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int a,b,c,d,e,f;
int main()
{
	scanf("%d %d %d",&a,&b,&c);
	d=a+b;
	e=b+c;
	f=c+a;
	if(d<=e && d<=f) printf("%d",d);
	else if(e<=f && e<=d) printf("%d",e);
	else printf("%d",f);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<int> repl(S.size());

    vector<char> alpha{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
    for(int i=0;i<S.size();i++){
        if (S.at(i)=='A'){
            repl.at(i) = 1;
        }
        if (S.at(i)=='B'){
            repl.at(i) = 2;
        }
        if (S.at(i)=='C'){
            repl.at(i) = 3;
        }
        if (S.at(i)=='D'){
            repl.at(i) = 4;
        }
        if (S.at(i)=='E'){
            repl.at(i) = 5;
        }
        if (S.at(i)=='F'){
            repl.at(i) = 6;
        }
        if (S.at(i)=='G'){
            repl.at(i) = 7;
        }
        if (S.at(i)=='H'){
            repl.at(i) = 8;
        }
        if (S.at(i)=='I'){
            repl.at(i) = 9;
        }
        if (S.at(i)=='J'){
            repl.at(i) = 10;
        }
        if (S.at(i)=='K'){
            repl.at(i) = 11;
        }
        if (S.at(i)=='L'){
            repl.at(i) = 12;
        }
        if (S.at(i)=='M'){
            repl.at(i) = 13;
        }
        if (S.at(i)=='N'){
            repl.at(i) = 14;
        }
        if (S.at(i)=='O'){
            repl.at(i) = 15;
        }
        if (S.at(i)=='P'){
            repl.at(i) = 16;
        }
        if (S.at(i)=='Q'){
            repl.at(i) = 17;
        }
        if (S.at(i)=='R'){
            repl.at(i) = 18;
        }
        if (S.at(i)=='S'){
            repl.at(i) = 19;
        }
        if (S.at(i)=='T'){
            repl.at(i) = 20;
        }
        if (S.at(i)=='U'){
            repl.at(i) = 21;
        }
        if (S.at(i)=='V'){
            repl.at(i) = 22;
        }
        if (S.at(i)=='W'){
            repl.at(i) = 23;
        }
        if (S.at(i)=='X'){
            repl.at(i) = 24;
        }
        if (S.at(i)=='Y'){
            repl.at(i) = 25;
        }
        if (S.at(i)=='Z'){
            repl.at(i) = 26;
        }
        
        

    }
    for (int j=0;j<S.size();j++){
            
            if (repl.at(j) + N >= 27){
                repl.at(j) = repl.at(j) + N - 27;
            }
      		else{
            	repl.at(j) = repl.at(j) + N - 1;
            }
      		
        }

        for (int k =0;k<S.size();k++){
            S.at(k) = alpha.at(repl.at(k));
        }

        cout << S << endl;


}

Measured memory_bytes: 384
#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 bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
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 namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 30;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string n; cin >> n;
    string res = (n[0] == n[2] ? "Yes":"No");
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
import kotlin.math.*

fun main(){
    val (A, B, H, M) = readLine()!!.split(" ").map { it.toDouble() }

    val hRad = (H * 2.0 * PI) / 12.0 + (2 * PI * M) / (12 * 60)
    val mRad = (M * 2.0 * PI) / 60.0
    println(sqrt(A.pow(2.0) + B.pow(2.0) - 2.0*A*B*cos(abs(mRad - hRad))))
}

Measured memory_bytes: 36616
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#define LL long long
#define N 1000001
using namespace std;
const int NN=2e5+7;
LL x[NN],y[NN];
LL p[4][NN];
LL i,j,k;
LL pd;
int main()
{
	ios::sync_with_stdio(false);
  	LL n;
  	cin>>n;
  	for(i=1;i<=n;i++)
  	{
  		cin>>x[i]>>y[i];
  		p[0][i]=x[i]+y[i],p[1][i]=y[i]-x[i],p[2][i]=x[i]-y[i],p[3][i]=-(x[i]+y[i]);
	}
	for(i=0;i<=3;i++)
	sort(p[i]+1,p[i]+1+n);
	for(i=0;i<=3;i++)
	{
		pd=max(pd,p[i][n]-p[i][1]);
		//cout<<i<<"  "<<p[i][n]<<"  "<<p[i][1]<<endl;
	}
	cout<<pd;
	return 0;
}

Measured memory_bytes: 13024
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>
#include <tuple>

#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000000; //10^18
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}

ll gcd(ll a, ll b) {
  if (a == 0 || b == 0) return a + b;
  if (b > a) return gcd(b, a);
  return gcd(b, a % b);
}



int main(void) {

  int h1, h2, m1, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;

  int x1 = 60*h1 + m1, x2 = 60*h2 + m2;
  int d = x2 - x1;
  cout << max(0, d - k) << endl;

}


Measured memory_bytes: 3672
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
	int n, m;
	cin >> n >> m;
	VL a(n);
	REP(i,n) scanf("%lld", &a[i]);

	ll sum = 0;
	REP(i,n-1){
		sum += (a[i+1] - a[i] + m) % m;
	}

	VL s1(2*m+2), s2(2*m+2);
	REP(i,n-1){
		int st = a[i], go = a[i+1];
		if (go < st) go += m;
		if (go - st <= 1) continue;
		s1[st+2]++;
		s1[go+1]--;
		s2[go+1] -= go - st - 1;
	}

	REP(i,2*m) s1[i+1] += s1[i];
	REP(i,2*m) s2[i+1] += s1[i+1];
	REP(i,2*m) s2[i+1] += s2[i];
	REP(i,m) s2[i+1] += s2[i+1+m];

	ll ans = 1e18;
	FOR(i,1,m) ans = min(ans, sum - s2[i]);

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

Measured memory_bytes: 4096
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string S, T;
    cin >> S >> T;

    int dp[S.size()+1][T.size()+1];
    memset(dp, 0, sizeof(dp));

    REP(i, S.size()) REP(j, T.size()) {
        if (S[i] == T[j]) {
            dp[i+1][j+1] = dp[i][j] + 1;
        }
        else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
    }

    string ans;
    ans.reserve(dp[S.size()][T.size()]);

    int x = T.size(), y = S.size();
    int cnt = dp[S.size()][T.size()];
    while (cnt > 0) {
        while(cnt == dp[y-1][x-1]) {
            --x; --y;
        }

        while(cnt == dp[y-1][x]) {
            --y;
        }

        while(cnt == dp[y][x-1]) {
            --x;
        }

        ans += S[y-1];
        --cnt;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    
}


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


int main(){
    int h,n;cin >> h >> n;
    vector<P> magic(n);
    vector<int> dp(h+1,INF);
    rep(i,n){
        int a,b;cin >> a >> b;
        magic[i] = make_pair(a,b);
    } 
    dp[0]=0;
    for(int i = 1;i<=h;i++){
        for(auto p:magic){
            dp[i] = min(dp[i],dp[max(0,i-p.first)]+p.second);
        }
    }
    cout << dp[h] << endl;
 }

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

using namespace std;

int main(){

    int year, cost;

    cin >> year >> cost;

    if(year >= 13){
        cout << cost << endl;
    }
    else if(year >= 6 && year <= 12){
        cout << cost / 2 << endl;
    }
    else{
        cout << 0 << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include <iomanip>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

vvi g;
vi v;

void dfs(int u, int k) {
	v[u] = k;
	for (auto z:g[u]) {
    if (v[z]) continue;
    dfs(z, k);
  }
}

int main() {
	int n, m;
	cin >> n >> m;
	vi a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	g = vvi(n);
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	v = vi(n);
  int k = 1;
	for (int i = 0; i < n; i++) {
		if (v[i]) continue;
		dfs(i, k);
    k++;
	}
	int c = 0;
  for (int i = 0; i < n; i++) c += v[i] == v[a[i]];
	cout << c << endl;
}






























Measured memory_bytes: 8576
#include<bits/stdc++.h>
#define ll long long
#define N 20
#define inf 1e9
#define rep(i,j,k) for(ll i=j;i<=k;++i)
using namespace std;
inline ll read(){
    ll x=0,f=0;char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1;
    for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-48;
    return f?-x:x;
}
ll n,m,G[N][N],f[1<<N][N],s[1<<N],sum;
int main(){
    n=read();m=read();
    rep(i,1,m){
		ll x=read()-1,y=read()-1;
		G[x][y]=G[y][x]=read(); sum+=G[x][y];
	}
    rep(i,0,1<<n) rep(j,0,n) if((i>>j)&1)
		rep(k,j+1,n) if((i>>k)&1) s[i]+=G[j][k];
    rep(i,0,1<<n) rep(j,0,n) f[i][j]=-inf;
    rep(i,0,1<<n) if(i&1) f[i][0]=s[i];
    rep(i,0,1<<n) rep(j,0,n) if((i>>j)&1)
		for(ll k=i;k;k=(k-1)&i) if(k&1)
			rep(l,0,n) if(((k>>l)&1)&&((~k>>j)&1)&&G[l][j])
				f[i][j]=max(f[i][j],f[k][l]+G[l][j]+s[i^k]);
    printf("%d\n",sum-f[(1<<n)-1][n-1]);
    return 0;
}

Measured memory_bytes: 6656
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
typedef pair<int,int> P;
vector<P> v[1000];
int main(){
  int n,m,a;
  while(cin >> n >> m >> a,n){
    a--;
    rep(i,1000) v[i].clear();
    int h,p,q;
    rep(i,m){
      cin >> h >> p >> q;
      v[h-1].push_back(P(p-1,q-1));
    }
    rep(k,1000){
      int i=999-k;
      rep(j,v[i].size()){
        if(v[i][j].first==a) a=v[i][j].second;
        else if(v[i][j].second==a) a=v[i][j].first;
      }
    }
    cout << a+1 << endl;
  }
  return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
 
int main(){
  int n;
  int c=0;
  cin >> n;
  vector <string> s(n);
  for(int i=0;i<n;i++)cin >> s[i];
  sort(ALL(s));
  for(int i=0;i<n-1;i++){
    if(s[i] == s[i+1])c++;
  }
  cout << n-c;
  return 0;
}


Measured memory_bytes: 9572
#include <stdio.h>

int main(void)
{
    int data[128] = {0};
    int n;
    int maxi;
    int i;

    maxi = 0;
    while (scanf("%d", &n) != EOF){
        data[n]++;
        if (maxi < data[n]){
            maxi = data[n];
        }
    }
    for (i = 1; i <= 100; i++){
        if (maxi == data[i]){
            printf("%d\n", i);
        }
    }

    return (0);
}

Measured memory_bytes: 596
import java.util.*;

public class Main{
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int n = Integer.parseInt(sc.next());

      String s = sc.next();

      int ans = 0;

for(int i=0;i<10;i++){
  for(int j=0;j<10;j++){
    for(int k=0;k<10;k++){
      int flagi = 0;
      int flagj = 0;
      int flagk = 0;
////////////////////////////////////////////////////////////
for(int l=0;l<n;l++){
  int a = s.charAt(l) - 48;
  if(flagi==0 && a==i){
    flagi = 1;
  }
  else if(flagi==1 && flagj==0 && a==j){
    flagj = 1;
  }
  else if(flagi==1 && flagj==1 && flagk==0 && a==k){
    ans++;
    //System.out.println("ijk="+i+""+j+""+k);
    break;
  }
}
////////////////////////////////////////////////////////////
    }
  }
}

      System.out.println(ans);

    }
}


Measured memory_bytes: 24276
# -*- coding: utf-8 -*-
 
n,max_k=list(map(int, input().split()))
d=list(map(int, input().split()))
answer=0
for k in range(1,max_k+1):
    for a in range(k+1):
        for b in range(k-a+1):
            if a+b<=k-a-b:
                continue
            if n<=a+b:
                in_hand=d
            else:
                in_hand=d[:a]
                in_hand+=d[n-b:]
            in_hand=sorted(in_hand)
            answer=max(answer,sum(in_hand[k-a-b:]))
print(answer)

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int A = Integer.parseInt(sc.next());
        final int B = Integer.parseInt(sc.next());
        final int M = Integer.parseInt(sc.next());
        int[] a = new int[A];
        int[] b = new int[B];
        int[] z = new int[M];
        for (int i = 0; i < A; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        for (int i = 0; i < B; i++) {
            b[i] = Integer.parseInt(sc.next());
        }
        for (int i = 0; i < M; i++) {
            int x = Integer.parseInt(sc.next());
            int y = Integer.parseInt(sc.next());
            int c = Integer.parseInt(sc.next());
            z[i] = a[x-1] + b[y-1] - c;
        }
        Arrays.sort(a);
        Arrays.sort(b);
        Arrays.sort(z);
        out.println(Math.min(a[0] + b[0], z[0]));
        
        out.flush();
    }
}

Measured memory_bytes: 93164
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
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; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    string S, T;
    cin >> S >> T;
    
    vector<int> SA(S.size() + 1), SB(S.size() + 1);
    rep(i, S.size()) {
        SA[i + 1] = SA[i];
        SB[i + 1] = SB[i];
        if (S[i] == 'A') SA[i + 1]++;
        else SB[i + 1]++;
    }
    vector<int> TA(T.size() + 1), TB(T.size() + 1);
    rep(i, T.size()) {
        TA[i + 1] = TA[i];
        TB[i + 1] = TB[i];
        if (T[i] == 'A') TA[i + 1]++;
        else TB[i + 1]++;
    }
    
    int Q;
    cin >> Q;
    rep(i, Q) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; c--;

        int pS = ((SA[b] - SA[a]) + (SB[b] - SB[a]) * 2) % 3;
        int pT = ((TA[d] - TA[c]) + (TB[d] - TB[c]) * 2) % 3;
        if (pS == pT) {
            write("YES");
        }
        else {
            write("NO");
        }
    }
}

Measured memory_bytes: 2512
H, W = map(int,input().split())
mp = [list(input()) for i in range(H)]
for i in range(H):
    mp[i].insert(0,'.')
    mp[i].append('.')
lo = ['.' for i in range(W+2)]
mp.insert(0,lo)
mp.append(lo)

dir =[[-1,0], [0,-1], [0,1], [1,0]]
def check(x,y):
    if mp[x][y] =='#':
        bw =False
        for i in range(len(dir)):
            if mp[x + dir[i][0]][y + dir[i][1]] =='#':
                bw = True
        if bw == True:
            return True
        else:
            return False
    else:
        return True

ok =True
for i in range(1,H+1):
    for k in range(1,W+1):
        if check(i,k) == False:
            ok = False
            break

if ok == True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    unsigned long long coin,glad=0;
    cin >> coin;
    if(coin>=500){
        glad += (coin/500)*1000;
        coin -= (coin/500)*500;
    }
    glad += (coin/5)*5;
    cout << glad << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut s1 = read::<String>().chars().collect::<Vec<char>>();
    let mut s2 = read::<String>().chars().collect::<Vec<char>>();
    s1.reverse();
    println!("{}", if s1 == s2 { "YES" } else { "NO" });
}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	
	int n;
	cin >> n;
	vector<int>a, b;
	int s = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		a.push_back(x);
		s += x;

	}
	int ans = 0;
	if (s % 10)ans = s;
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		if ((s - a[i]) % 10)ans = max(ans, s - a[i]);

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

}




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

//http://arc060.contest.atcoder.jp/tasks/arc060_a

using namespace std;

typedef long long LL;
typedef pair<LL,LL> pp;

int N, A;
vector<int> v(50);
LL memo[51][51][51*51];

LL f(int p, int k, int S) // return number of ways to make an average of A from remaining numbers [p,N) if so far we have k numbers adding up to S
{
	if (p == N)
		return (k > 0) && k*A == S;

	LL& res = memo[p][k][S];
	if (res != -1LL)
		return res;
	res = f(p+1, k, S);
	if (S+v[p] <= N*A)
		res += f(p+1, k+1, S+v[p]);
	return res;
}

int main()
{

	cin >> N >> A;
	for (int i = 0; i < N; i++)
	{
		cin >> v[i];
	}

	memset(memo, -1LL, sizeof(memo));
	cout << f(0, 0, 0) << endl;
	exit(0);
}


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

using namespace std;

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

	long long int res = 0;
	long long int n;

	cin >> n;

	for(long long int i=1;i<=sqrt(n);i++)
	{
		if(n%i==0)
		{
			long long int a = i - 1;
			long long int b = (n/i) - 1;
			if(a==b)
			{
				if(a!=0)
				{
					if((n/a)==n%a)
					{
						res += a;
					}
				}
			}
			else
			{
				if(a!=0)
				{
					if((n/a)==n%a)
					{
						res += a;
					}
				}
				if(b!=0)
				{
					if((n/b)==n%b)
					{
						res += b;
					}
				}
			}
		}
	}

	cout << res << '\n';
	
	return 0;
}

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

using ll = long long;

#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define clr(a, b) memset(a, b, sizeof(a))
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REPD(i, a, b) for(int i=(int)(a)-1; i>=(int)(b); --i)

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2e5 + 5, MOD = 1e9 + 7;
int n;
ll a[N];

ll add(ll aa, ll b) {
	while(aa < 0) aa += MOD;
	while(b < 0) b += MOD;
	return (aa % MOD + b % MOD) % MOD;
}

ll mul(ll aa, ll b) {
	while(aa < 0) aa += MOD;
	while(b < 0) b += MOD;
	b %= MOD;
	aa %= MOD;
	return (aa * b) % MOD;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // cout << (int)1e9 << endl;
    cin >> n;
    ll tot = 0;
    REP(i, 0, n) {
    	cin >> a[i];
    	tot += a[i];
    }
    ll res = 0;
    REP(i, 0, n) {
    	res = add(res, mul(a[i], (tot - a[i])));
    	tot -= a[i];
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 5168
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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

			String in = br.readLine();
			String chr[] = in.split(" ");
			char x = (chr[0].charAt(0));
			char y = (chr[1].charAt(0));
			System.out.println(x<y?"<"
							  :x>y?">"
							  :"=");

		}
	}
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

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


int main() {
  ll N; cin >> N;
  double L; cin >> L;
  double T[N]; rep(i,N) cin >> T[i];

  double rx = 0, ry = 0;
  rep(i,N) repr(j,i+1,N) {
    double theta1 = ((double)(T[i]+T[j])/2)*M_PI*2/L;
    double theta2 = (theta1<M_PI) ? theta1 + M_PI : theta1 - M_PI;
    // cout << theta1 << "->" << (N+i)-j-1 << " ";
    // cout << theta2 << "->" << j-i-1 << endl;
    rx += cos(theta1)*((N+i)-j-1) + cos(theta2)*(j-i-1);
    ry += sin(theta1)*((N+i)-j-1) + sin(theta2)*(j-i-1);
  }
  rx /= N*(N-1)*(N-2)/6; ry /= N*(N-1)*(N-2)/6;
  cout << fixed << setprecision(10) << rx << " " << ry << endl;
  // cout << result << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void) {
	int N, A, B;
	string s;
	cin >> N >> A >> B >> s;
	int foreigners = 1;
	int pass = A + B;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == 'a' && pass > 0) {
			--pass;
			cout << "Yes" << endl;
		}
		else if (s[i] == 'b' && pass > 0 && foreigners <= B) {
			++foreigners;
			--pass;
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 896
import java.util.Scanner;

public class Main {

	private static int N;
	private static int W;
	private static long[][] dp;
	private static int[] w;
	private static int[] v;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		W = sc.nextInt();
		dp = new long[N+1][W+1];
		w = new int[N+1];
		v = new int[N+1];
		w[0] = 0; v[0] = 0;
		for(int i = 1; i <= N; i++) {
			w[i] = Integer.parseInt(sc.next());
			v[i] = Integer.parseInt(sc.next());
		}
		for(int i = 0; i <= N; i++) {
			for(int j = 0; j <= W; j++) {
				dp[i][j] = -1;
			}
		}
		System.out.println(nap(N, W));
		sc.close();
	}

	private static long nap(int i, int j) {
		if(dp[i][j] >= 0) return dp[i][j];
		long rem;
		if(i == 0) {
			rem = 0;
		}else if(j < w[i]) {
			rem = nap(i-1, j);
		}else {
			rem = Math.max(nap(i-1, j-w[i])+v[i], nap(i-1,j));
		}
		dp[i][j] = rem;
		return rem;
	}

}

Measured memory_bytes: 125780
/*raghav0307 - Raghav Gupta*/
 
#include <bits/stdc++.h>
using namespace std;
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#define ff first
#define ss second
#define pb push_back
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int ll

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
 
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int MAXN = 1e5 + 5;

int n;
int leaves[MAXN];
int maxNodes[MAXN];

signed main(){
	fast_io();
	
	cin >> n;
	for(int i = 0; i <= n; i++){
		cin >> leaves[i];
	}

	if(n == 0 and leaves[0] != 1){
		cout << "-1\n";
		return 0;
	}

	maxNodes[0] = 1;
	for(int i = 1; i <= n; i++){
		maxNodes[i] = min((ll) 1e18, maxNodes[i-1]*2);
	}

	int l[n+1];
	l[n] = leaves[n];
	int r[n+1];
	r[n] = leaves[n];

	// cout << "level: " << n << " l: " << l << " r: " << r << "\n";

	for(int i = n-1; i >= 0; i--){
		
		l[i] = leaves[i] + (l[i+1] + 1)/2;
		r[i] = min(r[i+1] + leaves[i], maxNodes[i]);
		
		// if(l[i] > r[i]){
		// 	cout << "-1\n";
		// 	return 0;
		// }
		// cout << "level: " << i << " l: " << l << " r: " << r << "\n";
	}

	int ans = 1;
	for(int i = 1; i <= n; i++){
		r[i] = min(r[i], 2*(r[i-1] - leaves[i-1]));
		l[i] = max(l[i], l[i-1] - leaves[i-1]);
		ans += r[i];
		// if(l[i] > r[i]){
		// 	cout << "-1\n";
		// 	return 0;
		// }
		// if(r[i] <= 0){
		// 	cout << "-1\n";
		// 	return 0;
		// }
		if(r[i] < leaves[i]){
			cout << "-1\n";
			return 0;
		}
		// cout << "level: " << i << " l: " << l << " r: " << r << "\n";
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 6724
/* ***************************************************
 *	Author        :mutinner
 *	Created Time  :Sat 01 Sep 2018 08:51:31 PM CST
 *	File Name     :20:51:31.cpp
 *************************************************** */

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

int main() {
	int n;	cin >> n;
	cout << ( n / 2 ) * ( ( n + 1 ) / 2 ) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <limits>
#include <math.h>
#include <cmath>
#include <cctype>
#include <cstdio>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll> ;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vvll = vector<vector<long long >>;
#define PI  3.1415926535
#define rep(i, k, n) for(ll i = k; i < n; i++)

int main(){
  string num; cin >> num;
  ll s = num.size();
  
  ll res = 0;
  rep(i, 0, s){
    res += ll(num[i]) - 48;
  }
  
  if(res % 9 == 0){cout << "Yes" << endl;}
  else{cout << "No" << endl;}
  
}
      
    
  
  
    
    


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int n,m;
vector< pair<int,int> >edges;
vector<int>outdegree,dp;
bool visited[100002];
vector<int>grp[100002];
void topo(){
	queue<int>q;
	for(int i=1;i<=n;i++){
		if(outdegree[i]==0){
			q.push(i);
			dp[i]=1;
		}
	}
	while(!q.empty()){
		int node=q.front();
		visited[node]=true;
		q.pop();
		for(int i=0;i<grp[node].size();i++){
			if(--outdegree[grp[node][i]]==0){
				q.push(grp[node][i]);
				dp[grp[node][i]]=max(dp[grp[node][i]],dp[node]+1);
			}
		}
	}
}
int main(){
	cin>>n>>m;
	dp.resize(n+1);
	outdegree.resize(n+1);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		edges.push_back(make_pair(u,v));
		outdegree[u]++;
		grp[v].push_back(u);
	}
	topo();
	int res=0;
	for(int i=1;i<=n;i++){
		res=max(res,dp[i]);
	}
	cout<<res-1<<endl;


}

Measured memory_bytes: 7412
#include <iostream>
#include <string>
using namespace std;
typedef long long l;
l f(l n){return n? n*f(n-1):1;}
int main(){
	string s;
	cin>>s;
	int m[256]={0},i,b=1,n=0,c;
	for(i=0;i<s.size();i++)m[s[i]]++;
	
	l a=f(s.size()/2);
	for(c=97;c<123;c++)if(m[c]%2)n++;
	if(n>s.size()%2)b=0;
	if(b)for(c=97;c<123;c++)a/=f(m[c]/2);
	cout << (b?a:0) << endl;
}

Measured memory_bytes: 0
import numpy as np

N = int(input())
a = np.array([input().split() for i in range(N)], dtype=int)

dp = np.zeros((N, 3), dtype=int)
dp[0] = a[0]

for i in range(1, N):
    dp[i] = [
        a[i][0] + max(dp[i - 1][1], dp[i - 1][2]),
        a[i][1] + max(dp[i - 1][2], dp[i - 1][0]),
        a[i][2] + max(dp[i - 1][0], dp[i - 1][1]),
    ]

print(np.max(dp[-1]))


Measured memory_bytes: 56144
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL

struct Edge {
	ll from, to;
	ll w;
};
signed main(void) {
	int n;
	
	string str;
	cin >> n >> str;

	vector<int> ar(9);
	
	REP(i, 9)
		ar[i] = i;

	int cou[9][9] = {};

	REP(i, n-1) {
		cou[str[i] - '1'][str[i + 1] - '1']++;
	}

	int dist[9][9];

	REP(i, 3) {
		REP(j, 3) {
			REP(k, 3) {
				REP(l, 3) {
					dist[i * 3 + j][k * 3 + l] = abs(i - k) + abs(j - l);
				}
			}
		}
	}

	ll Min = LLONG_MAX;
	int ans[9];
	do {
		ll cos = 0;
		REP(i, 9) {
			REP(j, 9) {
				int a = ar[i], b = ar[j];
				cos += cou[a][b] * dist[i][j];
			}
		}

		if (Min > cos) {
			REP(i, 9)
				ans[i] = ar[i];
			Min = cos;
		}

	} while (next_permutation(ALL(ar)));

	REP(i, 9) {
		printf("%d", ans[i] + 1);
		if ((i + 1) % 3 == 0) cout << endl;
		else " ";
	}

	return 0;
}


Measured memory_bytes: 3372
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[][] graph = new int[n][n];
      String[] vInfo;
      int degree;

      for(int i=0,v=0; i<n; i++) {
        vInfo = br.readLine().split(" ");
        degree = Integer.parseInt(vInfo[1]);
        for(int j=0,k=2; j<degree; j++) {
          v = Integer.parseInt(vInfo[k++]);
          graph[i][v-1] = 1;
        }
      }

      StringBuilder buf = new StringBuilder(n*n*2);
      for (int[] vertex : graph) {
        for (int v : vertex) {
          buf.append(v).append(" ");
        }
        buf.setLength(buf.length()-1);
        buf.append("\n");
      }

      System.out.print(buf);
    }
    catch (IOException e) {
      System.out.println("IOException!");
    }
  }
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const double INF=1e12;
int M,N;
int X1[100],X2[100],Y1[100],Y2[100];

double f(int *X,int *Y,int n,double x){
    double l=INF,r=-INF;
    rep(i,n){
        double x1=X[i],y1=Y[i],x2=X[(i+1)%n],y2=Y[(i+1)%n];
        if((x1-x)*(x2-x)>0||x1==x2)continue;
        double y=y1+(y2-y1)/(x2-x1)*(x-x1);
        chmin(l,y);
        chmax(r,y);
    }
    return max(0.0,r-l);
}

void solve(){
    vint xs;
    rep(i,M)xs.pb(X1[i]);
    rep(i,N)xs.pb(X2[i]);
    sort(all(xs));
    int min1=*min_element(X1,X1+M),max1=*max_element(X1,X1+M);
    int min2=*min_element(X2,X2+N),max2=*max_element(X2,X2+N);
    double ans=0;
    for(int i=0;i+1<xs.size();i++){
        double a=xs[i],b=xs[i+1],c=(a+b)/2.0;
        if(c<min1||c>max1||c<min2||c>max2)continue;
        double fa=f(X1,Y1,M,a)*f(X2,Y2,N,a);
        double fb=f(X1,Y1,M,b)*f(X2,Y2,N,b);
        double fc=f(X1,Y1,M,c)*f(X2,Y2,N,c);
        ans+=(b-a)/6*(fa+fb+fc*4);
    }
    printf("%.20f\n",ans);
}

signed main(){
    while(cin>>M>>N,M||N){
        rep(i,M)cin>>X1[i]>>Y1[i];
        rep(i,N)cin>>X2[i]>>Y2[i];
        solve();
    }
}

Measured memory_bytes: 3144
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        a: chars,
        b: chars,
        c: chars,
    }
    let mut ai: usize = 0;
    let mut bi: usize = 0;
    let mut ci: usize = 0;
    let mut i;
    let mut p;
    let mut t = 'a';
    loop {
        match t {
            'a' => { i = ai; p = &a; ai+=1; },
            'b' => { i = bi; p = &b; bi+=1; },
            'c' => { i = ci; p = &c; ci+=1; },
            _ => { break; }
        };
        if let Some(y) = p.get(i) {
            t = *y;
        } else {
            println!("{}", t.to_uppercase().next().unwrap());
            break;
        }
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int main()
{
    
    ll h, w;
    cin >> h >> w;
    if (h == 1 || w == 1) {
        cout << 1 << endl;
        return 0;
    }

    if (h % 2 == 0) {
        cout << (h * w) / 2 << endl;
        return 0;
    }

    ll ans = 0;
    ll n = (h + 1) / 2;
    rep(i, w) {
        ans += n;
        if (i % 2 == 0) n--;
        else n++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define INF 10000000000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,int> PP;
int n;
ll x,d,restx;
ll m[51];
int p[51];
vector<int> G[51];
ll sum[51];
ll cnt[51];
PP po[51];

ll dfs(int v,int p){
	ll si=m[v];
	for(int i=0;i<G[v].size();i++){
		if(p!=G[v][i])si+=dfs(G[v][i],v);
	}
	return sum[v]=si;
}

ll dfs2(int v,int p){
	ll si=1;
	for(int i=0;i<G[v].size();i++){
		if(p!=G[v][i])si+=dfs2(G[v][i],v);
	}
	return cnt[v]=si;
}

ll dp[51][125001];

int main(void){
	scanf("%d%lld%lld",&n,&x,&d);
	scanf("%lld",&m[0]);
	for(int i=1;i<n;i++){
		scanf("%lld%d",&m[i],&p[i]);
		p[i]--;
		G[p[i]].push_back(i);
		G[i].push_back(p[i]);
	}
	dfs(0,-1);
	dfs2(0,-1);
	for(int i=0;i<n;i++){
		po[i]=PP((double)cnt[i]/sum[i],i);
	}
	sort(po,po+n);
	reverse(po,po+n);
	for(int i=0;i<=n;i++){
		for(int j=0;j<=125000;j++){
			dp[i][j]=INF;
		}
	}
	dp[0][0]=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<=i*2500;j++){
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
			for(ll k=0;k<=min(50,(int)d);k++){
				dp[i+1][j+k*cnt[i]]=min(dp[i+1][j+k*cnt[i]],dp[i][j]+sum[i]*k);
			}
		}
	}
	int ans=0;
	for(int i=0;i<=125000;i++){
		if(dp[n][i]<=x){
			int tmp=i;
			ll rest=x-dp[n][i];
			for(int j=0;j<n;j++){
				int v=po[j].second;
				if(v==0){
					int cn=rest/sum[v];
					tmp+=cn*cnt[v];
					rest-=(ll)sum[v]*cn;
				}else{
					int cn=rest/sum[v];
					tmp+=min(cn,max((int)d-50,0))*cnt[v];
					rest-=sum[v]*(ll)min(cn,max((int)d-50,0));
				}
			}
			ans=max(ans,tmp);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 50048
<?php
fscanf(STDIN,"%d %d",$K,$S);
$result = 0;
for($i=0;$i<=$K;$i++){
  for($j=0;$j<=$K;$j++){
    if($i+$j<=$S && $S-$i-$j<=$K){
      $result++;
    }
  }
}
echo $result;

Measured memory_bytes: 3576
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int p[21];
int main()
{
  int n, i, ans = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++)
  {
    // scanf("%d", &p[i]);
    scanf("%d", p + i);
  }
  for (i = 1; i <= n - 2; i++)
  {
    if ((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i - 1] > p[i] && p[i] > p[i + 1]))
      ans++;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128