akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
using namespace std;
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; /*long long int は64bit*/
using vi = vector<int>;using Vi = vector<long long int>;using matrix = vector<vector<ll> >;using Pair = pair<ll,ll>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(long long int i=0;i<N;i++) 
#define rev(i,N) for(long long int i=N-1;i>=0;i--) /*N-1からスタート*/
#define np nullptr
template<class T,class T2>bool chmax(T &former, const T2 &b) { if (former<=b) { former=b; return true; } return false; }
template<class T,class T2>bool chmin(T &former, const T2 &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; } /*sqrt(x)は平方根*/
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) /*降順↓でVをソート*/
#define fill(x,num) memset(x,num,sizeof(x));
template<class T1,class T2>bool p_compare(const pair<T1,T2> fir,const pair<T1,T2> sec){ return fir.second < sec.second; }
bool p_comp(const Pair fir,const Pair sec){return p_compare<ll,ll>(fir,sec);}
template<class T1,class T2>bool pcompare(pair<T1,T2> fir,pair<T1,T2> sec){ return !p_comp(fir,sec); }
bool pcomp(const Pair fir,const Pair sec){return pcompare<ll,ll>(fir,sec);}
/*sort(all(v),p_compare<ll,ll> 又は p_comp)で↑ソート , pcompは↓ソート*/

//////////////////////////^^ *Emile ^^^//////////////////////////////////////////////////////
//Snipet -> Caps Lock

string s;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>s;
    char tmp = '0';//0
    ll ct = 0;
    ll ans = 0;
    rep(i,s.size()){
        if(s[i]!=tmp)ct++;
        if(tmp == '1')tmp='0';
        else tmp = '1';
    }
    ans = ct;
    ct = 0;
    tmp = '1';
    rep(i,s.size()){
        if(s[i]!=tmp)ct++;
        if(tmp == '1')tmp='0';
        else tmp = '1';
    }
    chmin(ans,ct);
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    vector<ll> A(N); rep(i, N){cin >> A.at(i);}
    double x = 0;
    rep(i, N){x += 1.0 / (double) A.at(i);}
    cout << 1.0 / x << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define repi(i,a,b) for (int i=a;i<(b);i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;
typedef long long ll;
  
  int main(void){
    cin.tie(0); //cin高速化
    ios::sync_with_stdio(false); //cin高速化
	int n;
    cin >> n;
    char s[n];
    rep(i,n){
      cin >> s[i];
    }
    rep(i,n){
      if(s[i]=='Y'){
        cout <<"Four"<<endl;
        return 0;
      }
    }
    cout << "Three" << endl;
    return 0;
  } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n;
    cin >> n;
    ll res = n/2-!(n%2);
    if(n==2) res = 1;
    cout << res << endl;
}

Measured memory_bytes: 3624
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>

using namespace::std;


int main(void){
  int N,H,W;

  cin >> N >> H >> W;

  int res;
  int h=0,w=0;
  if(N%H)h++;
  if(N%W)w++;
  res = (N+1-H) * (N-W+1);

  cout << res << endl;
  return 0;
}



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

int main(){
    long long int a, b, c;
    cin >> a >> b >> c;
    
    if((c-(a+b)) > 0 && a* (a-2*b) + b*(b-2*c) + c*(c-2*a) > 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

int main (){
    int n; 
    cin>>n;
    int i,x,z,c=0,ret=0;
    cin>>z;
    for(i=1;i<n;i++){
        cin>>x;
        if(z>=x){
            c++;
        }
        else {
            if(ret<c)
            ret=c;
            c=0;
        }
        z=x;
    }
    cout<<max(ret,c)<<endl;
    return 0;

}

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

using namespace std;

int main() {
	string s;
	cin >> s;
	int r = 0;
	for (int i = s.length(); i--;)
		r += (i^s[i]) & 1;
	cout << min(r, (int)s.length() - r) << endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

vector<ll> sil(2000010), inv(2000010);

ll Pot(ll p, ll w)
{
    if (w == 0)
        return 1;
    if (w % 2 == 0)
    {
        ll pol = Pot(p, w / 2);
        return pol * pol % MOD;
    }
    return Pot(p, w - 1) * p % MOD;
}

ll C(ll n, ll k)
{
    return sil[n] * inv[n - k] % MOD * inv[k] % MOD;
}

ll Ile(ll a, ll b)
{
    return C(a + b + 2, b + 1);
}

int main()
{
    ios_base::sync_with_stdio(0);
    sil[0] = 1;
    inv[0] = 1;
    for (ll i = 1; i < 2000010; ++i)
    {
        sil[i] = (sil[i - 1] * i) % MOD;
        inv[i] = Pot(sil[i], MOD - 2);
    }
    ll a1, a2, b1, b2;
    cin >> a1 >> b1 >> a2 >> b2;
    ll odp = Ile(a2, b2) % MOD;
    odp -= Ile(a2, b1 - 1);
    if (odp < 0)
        odp += MOD;
    odp -= Ile(a1 - 1, b2);
    if (odp < MOD)
        odp += MOD;
    odp = (odp + Ile(a1 - 1, b1 - 1)) % MOD;
    cout << odp;
    return 0;
}


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

struct node{
	int ti,xi,yi;
}n[100005];

int k;

int main()
{
	cin>>k;
	for(int i=1;i<=k;i++)	cin>>n[i].ti>>n[i].xi>>n[i].yi;
	
	if(fabs(n[1].xi)+fabs(n[1].yi)>n[1].ti){
		cout<<"No"<<endl;
		return 0;
	}
	else{
		for(int i=2;i<=k;i++){
			int p=n[i].ti-n[i-1].ti;
			int q=fabs(n[i].xi-n[i-1].xi)+fabs(n[i].yi-n[i-1].yi);
		    if(q>p || (q%2!=p%2)){
		    	cout<<"No"<<endl;
		    	return 0;
		    }
		}
		
		cout<<"Yes"<<endl;
		return 0;
	}
}

Measured memory_bytes: 1408
#include <iostream>
#define MAX_N 50
using namespace std;


int a[MAX_N];
int n, r, p, c;


void set_deck() {
  for(int i = 0; i < n; ++i) {
    a[i] = n - i;
  }
}


void PRINT() {
  cout << "----------" << endl;
  for(int i = 0; i < n; ++i) {
    cout << a[i] << endl;
  }
  cout << "----------" << endl;
}


void cut() {
  int tmp[MAX_N];

  // 青を避難
  for(int i = 0; i < p - 1; ++i) {
    tmp[i] = a[i];
  }

  // 黄色を配置
  for(int i = 0; i < c; ++i) {
    a[i] = a[p - 1 + i];
  }

  // 青を配置
  for(int i = 0; i < p - 1; ++i) {
    a[c + i] = tmp[i];
  }
}


int main() {
  while(cin >> n >> r && n && r) {
    set_deck();
    //PRINT();
    for(int i = 0; i < r; ++i) {
      cin >> p >> c;
      cut();
      //PRINT();
    }
    cout << a[0] << endl;
  }
  return 0;
}



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

int N;
int A1[110], A2[110];
int answer;
int main(){
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> A1[i];
  }
  for(int i=0; i<N; i++){
    cin >> A2[i];
  }
  answer = 0;
  for(int i=0; i<N; i++){
    int S = 0;
    for(int j=0; j<i; j++){
      S += A1[j];
    }
    S += A1[i] + A2[i];
    for(int j=i+1; j<N; j++){
      S += A2[j];
    }
    if (S > answer){
      answer = S;
    }
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define db(a) cout << a << endl
#define db2(a,b) cout << a << " " << b << endl
#define dbp(a) cout << a.first << " " << a.second << endl
#define adb(a) for(auto i:a) cout << i << " "; cout << endl
#define adb2(a) for(auto i:a) cout << i.first << " " << i.second << endl;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define N 100010
using namespace std;

int main()
{
    fastIO;
    long long x;
    cin >> x;

    long long i, j, a, b;
    for(i=1; i*i<=x; i++)
    {
        if(x%i == 0)
        {
            for(a=0, b=-i; a<1010; a++, b++)
            {
                if((a*a*a*a*a - b*b*b*b*b) == x)
                {
                    cout << a << " " << b << endl;
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 3568
#include <stdio.h>
int main(void){
    int k,x,kl,ki,ans[300];
    int i;
    scanf("%d", &k);
    scanf("%d", &x);
    kl = (k * 2) - 1;
    ki = k - 1;
    for(i = 0;i < kl;i ++){
        ans[i] = x + (i - ki);
    }
    for(i = 0;i < kl;i ++){
        printf("%d\n", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
int main() {
	int n, a, b, c;
	cin >> n >> a >> b >> c;
	int l[n];
	int m = 1;
	rep(i, n) cin >> l[i], m *= 4;
	int ans = 1e9;
	rep(bit, m) {
		int lp = 0, lq = 0, lr = 0, cp = 0, cq = 0, cr = 0;
		int k = bit;
		rep(i, n) {
			int v = k % 4;
			k /= 4;
			if (v == 1)
				lp += l[i], cp++;
			else if (v == 2)
				lq += l[i], cq++;
			else if (v == 3)
				lr += l[i], cr++;
		}
		if (cp == 0 or cq == 0 or cr == 0) continue;
		int now = abs(lp - a) + abs(lq - b) + abs(lr - c) + 10 * (cp + cq + cr - 3);
		ans = min(ans, now);
	}
	cout << ans << endl;
	return 0;
}

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

#define PI 3.141592

int main(){
  int tmp1, tmp2;
  double r=90.0, nx=0.0, ny=0.0;

  while(true){
    scanf("%d,%d", &tmp1, &tmp2);
    if(tmp1==0 && tmp2==0)break;
    //printf("sin=%f cos=%f\n", sin(r/RAD), cos(r/RAD));
    nx+=tmp1*cos(r*PI/180);
    ny+=tmp1*sin(r*PI/180);
    r+=tmp2;
    //printf("nx=%f, ny=%f\n", nx, ny);
  }
  printf("%d\n%d\n", (int)nx*(-1), (int)ny);

  return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int pn[1000002];

int solve (int n) {
  int Count = 0;
  memset(pn, 0, n);
  pn[0] = pn[1] = 1;
  for (int i = 2; i <= n; i++) if (!pn[i]) for (int j = 2; i * j <= n; j++) pn[i * j] = 1;
  Count = count(pn, pn+n+1, 0);
  return Count;
}
	

int main (void) {
  int n;
  cin.tie(0);
  while (scanf("%d", &n) != EOF) {
    cout << solve(n) << endl;
  }
  return 0;
}

Measured memory_bytes: 5124
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(c > a + b ) cout << a+b+1+b<<endl;
  else cout << b + c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main()
{
    int a[1005];
   int n,k;
   cin>>n>>k;
   int i,sum=0;
   for(i=0;i<n;i++)
    cin>>a[i];
   sort(a,a+n);
   for(i=0;i<k;i++)
    sum+=a[i];
    printf("%d\n",sum);
    return 0;
}


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

int main() {
  string s, t;
  int a=0;
  cin >> s >> t;
  for (int i=0; i<t.size(); i++) {
    if(s[i] != t[i]) break;
    else a++;
  }
  
  if (a == s.size()) cout << "Yes" <<endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <numeric>
#include <array>
#include <queue>
#include <set>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

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

    cout << 3 * r * r << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
/* テンプレートここまで */

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

  map<int, int> mp;

  REP(i, N){
    int a;
    cin >> a;
    mp[a]++; mp[a-1]++; mp[a+1]++; 
  }

  int ans = 0;

  FOREACH(x, mp){
    ans = max(x.second, ans);
  }

  cout << ans << endl;
}

Measured memory_bytes: 4736
#include <iostream>
#include<string.h>
#include<vector>
using namespace std;
int main()
{
   long long int n,x;
   vector<long long> v ;
   cin>>n;
   long long int stool=0;
   for(long int i=0;i<n;++i)
   {cin>>x;v.push_back(x);}
   
  if(n==1) cout<<0<<endl;
  else
  {for(long int i=1;i<n;++i)
   {
       
       if(v[i]<v[i-1])
       {
           stool=stool+(v[i-1]-v[i]);
           v[i]=v[i-1];
       }
   }
   cout<<stool;}
    return 0;
}

Measured memory_bytes: 5324
#include <stdio.h>
#include <string.h>

int main() {
    char str1[401] = {"\0"}, str2[201] = {"\0"}, ans[201] = {"\0"};
    int m = 0;
    int i = 0;
    int j = 0;
    int h = 0;
    int sum = 0;
    
    while(1) {
        scanf("%s", str1);
        if(strcmp(str1, "-") == 0) {
            break;
        }
        strcpy(str2, str1);
        strcat(str1, str2);
        
        scanf("%d", &m);
        for (i = 0; i < m; i++) {
            scanf("%d", &h);
            sum += h;
            if (sum >= strlen(str2)) {
                sum -= strlen(str2);
            }
        }
        
        for (i = 0, j = sum; i < strlen(str2); i++, j++) {
            ans[i] = str1[j];
        }
        ans[i] = '\0';
        
        printf("%s\n", ans);
        sum = 0;
    }
    
    return 0;
}


Measured memory_bytes: 2052
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main() {
    int a[3][3];
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }

    bool c[3][3];
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            c[i][j] = false;
        }
    }

    int N;
    cin >> N;
    for(int i = 0; i < N; i++) {
        int b;
        cin >> b;

        for(int i = 0; i < 3; i++) {
            for(int j = 0; j < 3; j++) {
                if(a[i][j] == b) {
                    c[i][j] = true;
                }
            }
        }
    }

    bool ans = false;
    for(int i = 0; i < 3; i++) {
        bool check = true;
        for(int j = 0; j < 3; j++) {
            if(!c[i][j]) check = false;
        }

        if(check) ans = true;
    }

    for(int j = 0; j < 3; j++) {
        bool check = true;
        for(int i = 0; i < 3; i++) {
            if(!c[i][j]) check = false;
        }

        if(check) ans = true;
    }

    if(c[0][0] && c[1][1] && c[2][2]) ans = true;
    if(c[2][0] && c[1][1] && c[0][2]) ans = true;

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

    return 0;
}


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

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> p(N);
	vector<int> q(K);
	for (int i = 0; i < N; i++) {
		cin >> p.at(i);
	}
	for (int i = 0; i < K; i++) {
		q.at(i) = p.at(0);
		for (int j = 0; j < (N - 1); j++) {
			if (q.at(i) >= p.at(j + 1)) {
				q.at(i) = p.at(j + 1);
			}
		}
		for (int j = 0; j < N; j++) {
			if (q.at(i) == p.at(j)) {
				p.at(j) = 2000;
				break;
			}
		}
	}
	int sum(int, vector<int>);
	printf("%d", sum(K, q));
}

int sum(int K, vector<int> q) {
	int Buffer = 0;
	for (int i = 0; i < K; i++) {
		Buffer += q.at(i);
	}
	return Buffer;
}

Measured memory_bytes: 3736
// Last Change: 04/22/2019 19:22:52.
//////////////////////////////////////////////////////////////////////////////
// 0~Bまでの排他論理和と0~Aの排他論理和をもとめ、それを利用することでA~Bの
//排他論理和を求めることができるだろうという予想はたった。
//
// nが偶数の時、n XOR N+1 は1
// n XOR n は0
//
// 0~Kの排他論理和の求め方は以下のgetXORを参照
//////////////////////////////////////////////////////////////////////////////
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

ll GetXOR(ll X) {
  ll ans;

  ll cnt = (X + 1) / 2;
  if (cnt % 2 == 1) {
    ans = 1;
  } else {
    ans = 0;
  }

  if ((X + 1) % 2 == 1) {
    ans ^= X;
  }

  return ans;
}

int main() {
  ll A, B;
  cin >> A >> B;

  ll aXOR, bXOR;
  aXOR = GetXOR(A - 1);
  bXOR = GetXOR(B);
  cout << (aXOR ^ bXOR) << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct student
{
	int i,cnt;
	bool operator<(const student& t)const
	{
		return cnt<t.cnt; 
	} 
}st[100000+10];


int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		st[i].i=i;
		scanf("%d",&st[i].cnt);
	}
	sort(st+1,st+1+n);
	for(int i=1;i<=n;i++)
	{
		if(i!=n)
			printf("%d ",st[i].i);
		else
			printf("%d\n",st[i].i);
	}
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
struct pnt{
  int v, x, y;
};
bool operator < (pnt a, pnt b){
  return a.v>b.v;
}
pnt mkk(int x, int y, int z){
  pnt tmp;
  tmp.v=x;
  tmp.x=y;
  tmp.y=z;
  return tmp;
}
int dx[4]={0, 0, 1, -1}, dy[4]={1, -1, 0, 0};
string s[100];
int dis[100][100];
bool vis[100][100];
int main(){
  int h, w, black;
  while(cin>>h>>w){
    black=0;
    memset(vis, 0, sizeof vis);
    for(int i=0; i<h; ++i){
      cin>>s[i];
      for(int j=0; j<w; ++j)
        if(s[i][j]=='#')
          ++black;
    }
    priority_queue <pnt> q;
    q.push(mkk(1,0,0));
    pnt tp;
    int x, y;
    for(int i=0; i<h; ++i){
      for(int j=0; j<w; ++j){
        dis[i][j]=1000000;
      }
    }
    while(!q.empty()){
      tp=q.top();
      q.pop();
      if(dis[tp.x][tp.y]<=tp.v)
        continue;
      dis[tp.x][tp.y]=tp.v;
      for(int i=0; i<4; ++i){
        x=tp.x+dx[i];
        y=tp.y+dy[i];
        if(x<0||y<0||x>=h&&y>=w)
          continue;
        if(s[x][y]=='#')
          continue;
        if(dis[x][y]>tp.v+1){
          q.push(mkk(tp.v+1, x, y));
        }
      }
    }
    if(dis[h-1][w-1]==1000000){
      cout<<-1<<endl;
    }
    else{
      int tmp=h*w;
      tmp-=dis[h-1][w-1];
      tmp-=black;
      tmp=max(tmp, 0);
      cout<<tmp<<endl;
    }
  }
  return 0;
}




Measured memory_bytes: 256
import heapq as hq
N = int(input())
a = list(map(int,input().split()))
heap = a[:N].copy()
hq.heapify(heap)
s = sum(heap)
ls = [s]
for k in range(N,2*N):
    x = hq.heappushpop(heap, a[k])
    s = s + a[k] - x
    ls.append(s)
heap = [-x for x in a[2*N:]]
hq.heapify(heap)
s = sum(heap)
rs = [s]
for k in range(2*N-1, N-1, -1):
    x = hq.heappushpop(heap,-a[k])
    s = s - a[k] - x
    rs.append(s)
print(max([ls[k] + rs[-k-1] for k in range(N+1)]))

Measured memory_bytes: 38292
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    d = list(map(int, input().split()))
    ans = 0
    for i in range(N-1):
        for j in range(i+1, N):
            ans += d[i] * d[j]
    print(ans)


if __name__ == '__main__': main()

Measured memory_bytes: 3060
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mm(a,x) memset(a,x,sizeof(a))
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
#define ll long long
using namespace std;
int main(void)
{
    sync;
    double r;
   	cin>>r;
    cout<<2.0*acos(-1)*r<<endl;
    return 0;
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <fstream>
#define ni(n) scanf("%d", &n)
#define nl(n) scanf("%I64d", &n)
#define nai(a,n) for (int i = 0; i < (n); i++) ni((a)[i])
#define nal(a,n) for (int i = 0; i < (n); i++) nl((a)[i])
#define case(t) printf("Case #%d: ", (t))
#define pii pair<int, int>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define f first
#define s second
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e5 + 5;
const double eps = 1e-9;
using namespace std;

int main()
{
    ll n, m;
    cin >> n >> m;
    if (n == 1 && m == 1)
        cout << 1 << endl;
    else if (n == 1)
        cout << m - 2 << endl;
    else if (m == 1)
        cout << n - 2 << endl;
    else
    {
        ll ans = (n - 2) * (m - 2);
        cout << ans << endl;
    }
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    double answer;
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        vec.at(i) = A;
    }
    double numerator = 1;
    for (int i = 0; i < N; i++) {
        numerator *= vec.at(i);
    }
    double denominator;
    for (int i = 0; i < N; i++) {
        denominator += numerator / vec.at(i);
    }
    answer = numerator / denominator;
    cout << answer << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846

int n, ltype, rtype, lft, rit, mid, mtype;
string s;
void query(int P){
    cout << P << endl;
    fflush(stdout);
    cin >> s;
}
int main(){
    cin >> n;
    lft=1; rit=n-1;
    query(0);
    if (s[0]=='V') return 0;
    ltype=rtype=(s[0]=='M');
    while(lft<rit){
        //cout << lft << ' ' << rit << endl;
        mid=(lft+rit)/2;
        query(mid);
        if (s[0]=='V') return 0;
        mtype=(s[0]=='M');
        if ((mid-lft+1)%2!=(mtype+ltype)%2){
            rit=mid-1;
            rtype=mtype;
        }
        else {
            lft=mid+1;
            ltype=mtype;
        }
    }
    //cout << rit << endl;
    cout << lft;
    return 0;
}


Measured memory_bytes: 852
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define pii pair<int, int>
#define plli pair <lli, lli>
#define F(i,n) for(lli (i)=0;(i)<(n);(i)++)
#define FR(i,n) for(lli (i)=(n)-1;(i)>=0;(i)--)
#define FSG(i,a,b) for(lli (i)=(a);(i)<(b);(i)++)
#define FSGR(i,a,b) for(lli (i)=(b)-1;(i)>=(a);(i)--)
#define VAL(n) cout << n << endl;
#define VALD(n) cout << #n << ": " << n << endl;

int main(){
  int N;
  cin >> N;
  int a[N];
  F(i, N){
    cin >> a[i];
  }
  sort(a, a+N);
  int half = N / 2;
  int mina = a[half-1];
  int maxa = a[half];
  cout << maxa - mina << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

bool checker(string S){
  int n = S.size();
  bool flag = true;
  for(int i = 0; i < n/2; i++){
    if(S.at(i) != S.at(n-1-i)) flag = false;
  }
  return flag;
}

int main(){
  string S;
  cin >> S;
  int N = S.size();
  if(!checker(S)){
    cout << "No" << endl;
    return 0;
  }
  string S1 = S.substr(0, (N-1)/2);
  string S2 = S.substr((N+1)/2, (N-1)/2);
  if(!checker(S1) || !checker(S2)){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}

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

int main() {
  string s,t;
  cin >> s >> t;
  int n = s.size();
  vector<vector<bool>>ss(26,vector<bool>(26,false));
  vector<vector<bool>>tt(26,vector<bool>(26,false));
  rep(i,n){
    ss[s[i]-'a'][t[i]-'a'] = true;
    tt[t[i]-'a'][s[i]-'a'] = true;
  }
  rep(i,26){
    int sc = 0,tc = 0;
    rep(j,26){
      if(ss[i][j]) sc++;
      if(tt[i][j]) tc++;
    }
    if(sc >= 2 || tc >= 2){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<int,int> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

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

    map<int,int> mp;
    int x=0,y=0,z=0;

    REP(i,N){
        int a;
        cin >> a;

        if(x==0 && x != a) x = a;
        else if(y==0 && x!=a && y != a) y = a;
        else if(z==0 && x!=a && y != a && z != a) z = a;

        mp[a]++;
    }

    bool ans = false;

    if(mp[0]==N) ans = true;
    if(mp[0]*3==N && mp[x]*3==2*N) ans = true;
    if((x^y^z) == 0 && mp[x]*3==N && mp[y]*3==N && mp[z]*3==N)  ans = true;

    Yes(ans)

    return 0;
}

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

int dp[100010][3];
int a[100010][3];

int rec(int i, int j) {
    if(dp[i][j] != -1) return dp[i][j];
    if(i == 0) return 0;
    int res = 0;
    for(int k = 0; k < 3; ++k) {
        if(j == k) continue;
        res = max(res, rec(i-1, k) + a[i-1][k]);
    }
    return dp[i][j] = res;
}

int main() {
    int N; cin >> N;
    for(int i = 0; i < N; ++i) for(int j = 0; j < 3; ++j) cin >> a[i][j];
    for(int i = 0; i < 100010; ++i) for(int j = 0; j < 3; ++j) dp[i][j] = -1;
    
    int res = 0;
    for(int j = 0; j < 3; ++j) res = max(res, rec(N, j));
    
    cout << res << endl;
}


Measured memory_bytes: 8832
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

int main()
{
    int n;
    while (cin >> n && n != 0) {
        vector<int> row(n);
        vector<vector<int>> sheet(n);

        sheet.clear();
        for (auto i = 0; i < n; i++) {
            row.clear();
            for (auto j = 0; j < n; j++) {
                int in;
                cin >> in;
                row.push_back(in);
            }
            sheet.push_back(row);
        }

        vector<int> zero(n + 1, 0);
        sheet.resize(n + 1, zero);
        for (auto i = 0; i < n; i++) {
            sheet.at(i).resize(n + 1, 0);
            for (auto j = 0; j < n; j++) {
                sheet.at(n).at(i) += sheet.at(j).at(i);
                sheet.at(i).at(n) += sheet.at(i).at(j);
                sheet.at(n).at(n) += sheet.at(i).at(j);
            }
        }

        for (auto i = 0; i < n + 1; i++) {
            for (auto j = 0; j < n + 1; j++) {
                cout << setw(5) << sheet.at(i).at(j);
            }
            cout << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,q;
  cin>>n>>q;
  vector<int> a[n];
  rep(i,q){
    int num,t,x;
    cin>>num>>t;
    if(num==0){
      cin>>x;
      a[t].push_back(x);
    }else if(num==1){
      rep(j,a[t].size() ){
	if(j) cout<<" ";
	cout<<a[t][j];
      }
      cout<<endl;
    }else{
      a[t].clear();
    }
  }

  return 0;
}



Measured memory_bytes: 8960
/**
 *    author:  Saurav Paul 
 *    created: June 20, 2020 12:15 PM
 *    Problem Name : A - Multiplication 1
 *    Problem Url : https://atcoder.jp/contests/abc169/tasks/abc169_a
**/

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

int main(){

    long long int n , m;
    cin >> n >> m ;
    cout << n * m << endl ;    

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
#define MOD 1e9 + 7
#define fir first
#define sec second
#define all(x) x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
	IOS
	ll n,x;
	cin>>n>>x;
	ll i=0;
	ll a[n+1];
	ll cv[n+1];
	ll count=0;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	cv[0]=0;
	for(i=1;i<=n;i++)
	{
		cv[i]=cv[i-1]+a[i];
	}
	for(i=0;i<=n;i++)
	{
		if(cv[i]<=x)
			count++;
		else
			break;
	}
	cout<<count;
}

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

int main(){
  int i,j,k,cnt;
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  if((a[1]-a[0])%2==0)cout<<a[2]-(a[1]+a[0])/2;
  else cout<<a[2]-(a[1]+a[0]-3)/2;
}

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

int main() {
  int N, A, B, C, D;
  cin >> N;
  A = N / 1000;
  B = (N % 1000) / 100;
  C = (N % 100) / 10;
  D = N % 10;
    
    if (A == B && B == C) {
      cout << "Yes" << endl;
    }
  else if (B == C && C == D) {
      cout << "Yes" << endl;
  }  
   else {
     cout << "No" << endl;
   }  
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>
#include<cmath>
#include<queue>
#include <functional>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define PI 3.141592

using namespace std;

int main() {
	string A, B;
	cin >> A >> B;

	int count = 0;
	rep(i, 3)
	{
		if (A[i] == B[i])
		{
			++count;
		}
	}

	printf("%d", count);
}


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

using namespace std;

#define MAX 100

char A[MAX][MAX],B[MAX][MAX];

void compress(int &h,int &w){
  int a = w,b = h;
  bool use[MAX],use2[MAX];
  vector<string> res;

  fill(use,use+h,true);
  fill(use2,use2+w,true);

  for(int i = 0 ; i < h ; i++){
    int cnt = 0;
    for(int j = 0 ; j < w ; j++){
      if(A[i][j] != '.'){
        break;
      }
      cnt++;
    }
    if(cnt == w){ use[i] = false; a--; }
  }

  for(int i = 0 ; i < w ; i++){
    int cnt = 0;
    for(int j = 0 ; j < h ; j++){
      if(A[j][i] != '.'){
        break;
      }
      cnt++;
    }
    if(cnt == h){ use2[i] = false; b--; }
  }
  for(int i = 0 ; i < h ; i++){
    if(!use[i]){ continue; }
    string s;
    for(int j = 0 ; j < w ; j++){
      if(!use2[j]){ continue; }
      s += A[i][j];
    }
    if(s.size() > 0){
      res.push_back(s);
    }
  }
  h = res.size(); w = res[0].size();
  for(int i = 0 ; i < h ; i++){
    for(int j = 0 ; j < w ; j++){
      A[i][j] = res[i][j];
    }
  }
}

void rotate(int &h,int &w){
  char tmp[MAX][MAX];
  for(int i = 0 ; i < h ; i++){
    for(int j = 0 ; j < w ; j++){
      tmp[i][j] = A[i][j];
    }
  }
  for(int i = 0 ; i < h ; i++){
    for(int j = 0 ; j < w ; j++){
      A[w-j-1][i] = tmp[i][j];
    }
  }
  int nh = w,nw = h;
  h = nh; w = nw;
}

int getPoint(int H,int W){
  int res = 0;
  for(int i = 0 ; i < H ; i++){
    int cnt = 0;
    for(int j = 0 ; j < W ; j++,cnt++){
      if(B[i][j] != '#'){ break; }
    }
    if(cnt == W){ res++; }
  }
  return res;
}

int getMaxScore(int h,int w,int H,int W){
  int maxPoint = -1;
  char C[MAX][MAX];
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      for(int k = 0 ; k < 4 ; k++){
        rotate(h,w);
        for(int l = 0 ; l < H ; l++){
          for(int m = 0 ; m < W ; m++){
            C[l][m] = B[l][m];
          }
        }
        bool ok = true;
        if(i+h > H || j+w > W){ continue; }
        for(int l = i ; l < i+h ; l++){
          for(int m = j ; m < j+w ; m++){
            if(A[l-i][m-j] == '#' && B[l][m] == '#'){
              ok = false; break;
            }
            if(A[l-i][m-j] == '#' && B[l][m] == '.'){
              B[l][m] = A[l-i][m-j];
            }
          }
          if(!ok){ break; }
        }
        if(ok){
          maxPoint = max(maxPoint,getPoint(H,W));
        }
        for(int l = 0 ; l < H ; l++){
          for(int m = 0 ; m < W ; m++){
            B[l][m] = C[l][m];
          }
        }
      }
    }
  }
  return maxPoint;
}

int main(){
  int Tc,h,w,H,W;
  cin >> Tc;
  while(Tc--){
    cin >> h >> w;
    for(int i = 0 ; i < h ; i++){
      for(int j = 0 ; j < w ; j++){
        cin >> A[i][j];
      }
    }
    cin >> H >> W;
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
        cin >> B[i][j];
      }
    }
    compress(h,w);
    cout << getMaxScore(h,w,H,W) << endl;
  }
  return 0;
}

Measured memory_bytes: 1256
public class Hello{
    public static void Main(){
        // Your code here!
        int n=int.Parse(System.Console.ReadLine());
        string[] s=System.Console.ReadLine().Split(' ');
        long[] a=new long[3*n];
        for(int i=0;i<n*3;i++)
            a[i]=System.Int64.Parse(s[i]);
        System.Array.Sort(a);
        long ans=0;
        for(int i=0;i<n;i++){
            ans+=a[3*n-2-i*2];
        }
        System.Console.WriteLine(ans.ToString());
    }
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N-1);
    for (int i=0;i<N;i++) {
        cin >> A.at(i);
        }
    for (int i=0;i<N;i++) {
        cin >> B.at(i);
    }
    for (int i=0;i<N-1;i++) {
        cin >> C.at(i);
    }
    int base=0;//全ての料理を食べるので全ての基礎満足ポイントをえる
    for (int i=0;i<N;i++) {
        base +=B.at(i);
    }
    int add=0;
    for (int i=0;i<N-1;i++) {
        if (A.at(i)>0) {
        if (A.at(i) + 1 == A.at(i+1)) {
           add += C.at(A.at(i)-1);
        }
        }
    }
    cout << base + add << endl;
    return 0;
    }

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char S[10];
    gets(S);
    int d=strcmp(S, "ABC");
    if(d==0)
    {
        printf("ARC\n");
    }
    else
    {
        printf("ABC\n");
    }
    return 0;
}


Measured memory_bytes: 1496
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())
#define MN 16
int n;
int t[20][20];
int dp[1<<MN];
int rec(int S){
  if(dp[S]>=0) return dp[S];
  if(S==(1<<n)-1) return dp[S] = 0;
  int res = INF;
  REP(u,n){
    if(!(S >> u & 1)){
      REP(w,n+1){
        if(w==0||(S >> (w-1)) & 1){
          res = min(res, rec(S | 1 << u) + t[u][w]);
        }
      }
    }
  }
  return dp[S] = res;
}

int main(void){
  while(cin>>n,n){
    memset(t,0,sizeof(t));
    memset(dp,-1,sizeof(dp));
    REP(i,n)REP(j,n+1){
      cin>>t[i][j];
    }
    cout<<rec(0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1120
// AOJ 0092: Square Searching
// 2017.8.12 bal4u@uu
// 2017.11.1 retry

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int dp[1002][1002];
char map[1002][1005];

int main()
{
    int n, r, c, t, ans;
    char buf[10];

    while (fgets(buf, 10, stdin) && *buf != '0') {
		n = atoi(buf);
		for (r = 1; r <= n; r++) fgets(map[r]+1, 1005, stdin);

//		memset(dp, 0, sizeof(dp));
		for (ans = 0, r = 1; r <= n; r++) for (c = 1; c <= n; c++) {
			if (map[r][c] == '*') dp[r][c] = 0;
			else {
				t = dp[r-1][c-1];
				if (t > 0 && dp[r  ][c-1] < t) t = dp[r  ][c-1];
				if (t > 0 && dp[r-1][c  ] < t) t = dp[r-1][c  ];
				dp[r][c] = ++t;
				if (t > ans) ans = t;
			}
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 6544
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  cout << 48 - m << endl;


  
  return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
k_i=[]
S=[]
for i in range(M):
  l = list(map(int,input().split()))
  k_i.append(l[0])
  S.append(l[1:])
P=list(map(int,input().split()))
ans=0
for i in range(2**N):
  flag=1
  for j in range(M):
    res=0
    for k,x in enumerate(bin(i)[2:][::-1]):
      if x=="1" and k+1 in S[j]:
        res+=1
    if res%2 != P[j] :
      flag=0
      break
    
  if flag:
    ans+=1
print(ans)

Measured memory_bytes: 74108
using System;
using System.Collections.Generic;

namespace Airplane
{
    class Program
    {
        static void Main(string[] args)
        {
            int p, q, r;
            string a = Console.ReadLine();
            string[] aa = a.Split(' ');
            p = int.Parse(aa[0]);
            q = int.Parse(aa[1]);
            r = int.Parse(aa[2]);

            var list = new List<int>();
            list.Add(p);
            list.Add(q);
            list.Add(r);
            list.Sort();

            int sum = list[0] + list[1];

            Console.WriteLine(sum.ToString());
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

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

int main(){
  int n; cin>>n;
  ll a[n],l[n],r[n];
  
  cin>>a[0];l[0]=a[0];
  for(int i=1;i<n;i++){
  	cin>>a[i];
    l[i]=gcd(l[i-1],a[i]);
  }
  
  r[n-1]=a[n-1];
  for(int i=1;i<n;i++){
    r[n-1-i]=gcd(a[n-1-i],r[n-i]);
  }
  
  ll M=max(l[n-2],r[1]);
  for(int i=1;i<n-1;i++){
    M=max(gcd(l[i-1],r[i+1]),M);
  }
  
  cout<<M;
  
  return 0;
  
}

Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;

class Elem {
	Elem next;
	Elem prev;
	int key;
	
	Elem(int key) {
		this.key = key;
	}
}

class DoubleyLinkedList {
	Elem head;
	
	DoubleyLinkedList() {
		head = new Elem(-1);
		head.next = head;
		head.prev = head;
	}
	
	boolean isEmpty() {
		return head.prev == head;
	}
	
	void insert(int key) {
		Elem e = new Elem(key);
		e.next = head.next;
		e.prev = head;
		e.next.prev = e;
		head.next = e;
	}
	
	int delete(int key) {
		for (Elem e = head.next; e != head; e = e.next) {
			if (e.key == key) {
				e.prev.next = e.next;
				e.next.prev = e.prev;
				return e.key;
			}
		}
		return -1;
	}
	
	int deleteFirst() {
		Elem e = head.next;
		e.next.prev = head;
		head.next = e.next;
		return e.key;
	}
	
	int deleteLast() {
		Elem e = head.prev;
		e.prev.next = head;
		head.prev = e.prev;
		return e.key;
	}
	
	public String toString() {
		StringBuilder sb = new StringBuilder();
		for (Elem e = head.next; e != head; e = e.next) {
			sb.append(e.key);
			sb.append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		sb.append('\n');
		return sb.toString();
	}
}

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		// BufferedReader br = new BufferedReader(new FileReader("in2.txt"));
		int n = Integer.parseInt(br.readLine());

		DoubleyLinkedList list = new DoubleyLinkedList();
		for (int i = 0; i < n; i++) {
			String[] line = br.readLine().split(" ");
			if (line[0].equals("insert")) {
				list.insert(Integer.parseInt(line[1]));
			} else if (line[0].equals("delete")) {
				list.delete(Integer.parseInt(line[1]));
			} else if (line[0].equals("deleteFirst")) {
				list.deleteFirst();
			} else if (line[0].equals("deleteLast")) {
				list.deleteLast();
			}
		}
		System.out.print(list.toString());
	}
}

Measured memory_bytes: 562516
fun main(args: Array<String>) {

    fun isPalindrome(s: String): Boolean {
        return if (s.length % 2 == 1) {
            val mae = s.substring(0 until s.length / 2)
            val usiro = s.substring(s.length / 2 + 1 until s.length)
            return mae == usiro.reversed()
        } else {
            val mae = s.substring(0 until s.length / 2)
            val usiro = s.substring(s.length / 2 until s.length)
            return mae == usiro.reversed()
        }
    }

    val str = readLine()!!

    if (!isPalindrome(str)) {
        println("No")
        return
    }

    if (!isPalindrome(str.substring(0 until (str.length - 1) / 2))) {
        println("No")
        return
    }

    if (!isPalindrome(str.substring(((str.length + 3) / 2) - 1 until str.length))) {
        println("No")
        return
    }

    println("Yes")
}





Measured memory_bytes: 33872
#include<bits/stdc++.h>
#define ll long long
#define mod 838627288460106
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    fast_io
    ll a,b,c,d,s,t;
    cin>>a>>b>>c>>d;
    s=a+b;
    t=c+d;
    if(s<t)
        cout<<"Right"<<endl;
    else if(s>t)
        cout<<"Left"<<endl;
    else
        cout<<"Balanced"<<endl;

    return 0;
}





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

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a,a+n);
	int flag = 0;
	for(int i=0;i<n-1;i++){
		if(a[i]==a[i+1]){
			flag = 1;
			break;
		}
	}
	if(flag == 1){
		cout << "NO" << endl;
	}
	else cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
// const ll MOD=998244353;

int color[101010];
vector<vector<pair<int,int>>> G(101010);

void solve(int v,int P,int c){
  color[v]=c;
  for(auto p:G[v]){
    if(p.first==P) continue;
    solve(p.first,v,(c+p.second)%2);
  }
}

int main(){
  int N; cin>>N;
  rep(i,N-1){
    int a,b,w; cin>>a>>b>>w; a--,b--;
    G[a].push_back({b,w});
    G[b].push_back({a,w});
  }
  solve(0,-1,0);
  rep(i,N) cout<<color[i]<<endl;
  return 0;
}


Measured memory_bytes: 8448
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
INF = 500000
mod = 10**9+7

H, W = map(int, input().split())
if H % 2:
    a, b = H//2+1, H//2
else:
    a = b = H//2
if W % 2:
    ans = a*((W//2)+1)+b*(W//2)
else:
    ans = (a+b)*(W//2)
if H == 1 or W == 1:
    print(1)
else:
    print(ans)


# a, b, c = input(), input(), input()
# la, lb, lc = len(a), len(b), len(c)
# for i in range(1, min(la, lb)):
#     S = ''
#     for j in range(i):
#         if a[la-i+j] == b[j]:
#             S += b[j]
#             continue
#         elif a[la-i+j] == '?':
#             S += b[j]
#         elif b[j] == '?':
#             S += c[j]


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

int main()
{
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  long double AM = M * M_PI / 30;
  long double AH = (H * 60 + M) * M_PI / 360;
  long double Angle = AM - AH;
  long double ans = pow(A,2) + pow(B,2) - 2 * A * B * cos(Angle);
  ans = sqrt(ans);
  cout << fixed << setprecision(11) <<  ans << endl;
}

Measured memory_bytes: 4140
#include<algorithm>
#include<string.h>
#include<queue>
#include<math.h>
#include <iostream>
using namespace std;
///int a[1005];
int main()
{
   int n;
   cin>>n;
   long long sum=0;
   for(int i=1;i<=n;i++)
   {
    if(i%3==0||i%5==0)
        sum+=0;
    else
        sum+=i;
   }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3600
def INT():
    return int(input())

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

def MI():
    return map(int, input().split())

N = INT()
h = [0] + LI() + [0]
ans = 0

while not all([h[i] == 0 for i in range(len(h))]):
    min_idx = [idx for idx, flower in enumerate(h) if flower == 0]
    
    for i in range(len(min_idx) - 1):
        idx_1, idx_2 = min_idx[i], min_idx[i + 1]
        if idx_1 + 1 == idx_2:
            continue
        
        min_tall = min(h[idx_1 + 1 : idx_2])
        ans += min_tall
            
        for j in range(idx_1 + 1, idx_2):
            h[j] -= min_tall
        
print(ans)

Measured memory_bytes: 69468