akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int d[10][10];
int cnt[10];
main()
{
    int h,w;scanf("%d%d",&h,&w);
    for(int i=0;i<10;i++)for(int j=0;j<10;j++)
        scanf("%d",&d[i][j]);
    for(int k=0;k<10;k++)
    {
        for(int i=0;i<10;i++)for(int j=0;j<10;j++)
            d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    }
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            int x;scanf("%d",&x);
            if(x>=0)cnt[x]++;
        }
    }
    int ans=0;
    for(int i=0;i<10;i++)ans+=cnt[i]*d[i][1];
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
// Best practice

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <functional> // for less 

#define int         long long
#define pb          emplace_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

#define fbo find_by_order
#define ook order_of_key


signed main() {
   tezz
    
    int n,m;
    cin >> n >> m;
    if(n>=10){
        cout << m << endl;
    }
    else{
        cout << m+(100*(10-n)) << endl;
    }
    
   return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
string a,b;
int t,q;
vector<int> p[26];
signed main(){
	cin>>a>>b;
	for(int i=0;i<a.size();++i)
	{
		p[a[i]-'a'].push_back(i+1);
	}
	if(!p[b[0]-'a'].size())
	{
		cout<<-1;
		return 0;
	}
	int ans=0;
	int k=p[b[0]-'a'][0];
	ans+=k;
	for(int i=1;i<b.size();++i)
	{
		t=b[i]-'a';
		if(!p[t].size())
		{
			cout<<-1;
			return 0;
		}
		q=upper_bound(p[t].begin(),p[t].end(),k)-p[t].begin();
		if(q==p[t].end()-p[t].begin())
		{
			ans+=p[t][0]+a.size()-k;
			k=p[t][0];
		}
		else
		{
			ans+=p[t][q]-k;
			k=p[t][q];
		}
	}
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 1724
n = int(input())
lis = [1]
i = 1
while 6 ** i <= n:
    lis.append(6 ** i)
    i += 1
i = 1
while 9 ** i <= n:
    lis.append(9 ** i)
    i += 1

dp = [[0] * (n+1) for i in range(len(lis))]
for i in range(n+1):
    dp[0][i] = i
#print(lis)
for i in range(1,len(lis)):
    for j in range(1, n+1):
        if j < lis[i]:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = min(dp[i-1][j], dp[i][j-lis[i]] + 1)
print(dp[len(lis)-1][n])


Measured memory_bytes: 23028
#include<bits/stdc++.h>
using namespace std;
#define fr(i,n) for(int i=0;i<n;i++)
int main(){
  string s;
  cin>>s;
  int n=s.length(),a=n;
  fr(i,n-1) if(s[i]!=s[i+1]) a=min(a,max(i+1,n-1-i));
  cout<<a<<endl;
}

Measured memory_bytes: 512
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;
#define int ll
using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) (x) * (x)
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ld, ld> pld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<pii> vpii;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))
#define prev asasdasd
#define next aasdasda
#define left asdasdasdasd
#define right asnabsdkasdl
#define rank asdasdknlasd
#define move asdasdas

namespace IO {
    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
        return out;
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;


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

void solve() {
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    int s = 0;
    rep(i, 0, n) s ^= a[i];
    vi res(n);
    rep(i, 0, n) res[i] = (s^a[i]);
    put(res);
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
//    freopen("input.txt", "r", stdin);
    int q = 1;
//    cin >> q;

    while (q--) solve();
}





Measured memory_bytes: 7624
import copy
n = int(input())
l = []
for _ in range(n):
  l.append(int(input()))
m = max(l)
k = copy.copy(l)
k.remove(m)
m2 = max(k)
for i in range(0,n):
    if l[i] != m:
      print(m)
    else:
      print(m2)

Measured memory_bytes: 14560
#include <stdio.h>
#define N 100000000
#define NOT -1

int n,q,S[N],T[N];

int Linear(int key)
{
  int i = 0;

  while(S[i] != key)
    {
      i++;
      if(i == n) return NOT;
    }
  return i;
}

int main()
{
  int i,t = 0;

  scanf("%d",&n);
  for(i = 0;i < n;i++) scanf("%d",&S[i]);

  scanf("%d",&q);
  for(i = 0;i < q;i++) scanf("%d",&T[i]);

  for(i = 0;i < q;i++)
    {
      if(Linear(T[i]) != NOT) t++;
    }

  printf("%d\n",t);

  return 0;
}




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

int main(){
  int N,M; cin>>N>>M;
  vector<pair<int,int> > V(M);
  rep(i,M){
    int a,b; cin>>a>>b;
    V[i]={b,a};
  }
  sort(V.begin(),V.end());
  int ans=0, prev=-1;
  rep(i,M){
    int a=V[i].second, b=V[i].first;
    if(a<=prev&&prev<b) continue;
    ans++;
    prev=b-1;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
k,x = map(int,input().split())

lst = []
for i in range(0,k):
  lst.append(x+i)
  lst.append(x-i)

lst = list(set(lst))

lst = ([i for i in lst if i  <= 1000000 and i >= -1000000])
print(' '.join(map(str,sorted(lst))))


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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}


int main(int argc, char const* argv[])
{
    int n;
    cin >> n;

    vector<int> mochi(n);
    for (int i = 0; i < n; i++) {
        cin >> mochi[i];
    }

    unique(mochi);
    cout << (int)mochi.size() << endl;

    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


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

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

int main()
{
    double x; cin >> x;
    double tmp = 100;
    int ans = 0;
    while(x > tmp){
        tmp *= 1.01;
        tmp = floor(tmp);
        ans++;
    }   
    cout << ans << endl;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  int n;
  cin >> n;
  int out = n%10;
  string output;
  if(out == 2 || out == 4 || out == 5 || out == 7 || out == 9)
    output = "hon";
  else if(out == 0 || out ==1 || out==6 || out ==8)
    output = "pon";
  else
    output = "bon";
  cout << output;
}

Measured memory_bytes: 3624
n, a = map(int, input().split())
x = list(map(int, input().split()))

'''
辞書がめっちゃ書きやすい！ただし、3次元配列でdpやりたい時むずいかも。
x = [i-a for i in x]
dp = {0:1}
print(dp)
for item in x:
    print('--------for item:{}-----------'.format(item))
    for key, value in list(dp.items()):
        print('key:{},value:{}'.format(key,value))
        dp[item + key] = dp.get(item + key, 0) + value
        print(dp)
print(dp[0]-1)
'''

diff = [i-a for i in x]
ma = max(max(x),a)

dp = [[0 for j in range(2*n*ma+1)] for k in range(n+1)]
# 0を初期値として1からNまでやりたいので結果の箱は1+n回ループを回す準備をする。
# print(dp[1][71])
# この初期化をした時に添字はどっちがどっちみたいのはいい加減覚える。
# 0~2*n*naまでの列がn+1倍なのでそれがn+1個並んでいるイメージ。最初の添字ではn+1個並んでいるうちの一つを指定する。

dp[0][n*ma] = 1
# initialize

for l in range(0,n):
    # diff(入力の全てからaを引いたやつ)は0~n-1までしかないことに注意
    # 同様に後ろのdpの添字も注意
    for m in range(2*n*ma+1):
        if abs(m - diff[l]) > 2*n*ma:
            dp[l+1][m] = dp[l][m]
            #ループ回すまでもなく選んでも無理な時はそのまま 
        else:
            dp[l+1][m] = dp[l][m] + dp[l][m - diff[l]]
print(dp[n][n*ma]-1)



'''
countzero = len([i for i in diff if i == 0])
#print(countzero)
over = sorted([i for i in diff if i > 0])
under = sorted([i for i in diff if i < 0])
#print(over)
#print(under)
countover = [0 for i in range(50)]
countunder = [0 for i in range(50)]
for item in set(over):
    countover[item-1] = over.count(item)
for item in set(under):
    countunder[item] = under.count(item)
countunder = sorted(countunder)

valover = [countover[0]]
valunder = [countunder[0]]

for i in range(1,2500):
    plus = 0
    minus = 0
    if i%2 == 0:
        plus = countover[int(i/2)]*(countover[int(i/2)]-1)/2
        minus = countunder[int(i/2)]*(countunder[int(i/2)]-1)/2
    for j in range(int(i/2)):
        plus += countover[i]*countover[-i]
        minus += countunder[i]*countunder[-i]
    valover.append(plus)
    valunder.append(minus)

plusminus = 0
for i in range(2500):
    plusminus += valover[i]*valunder[i]

print((plusminus+1)*2**(countzero)-1)
'''

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

using namespace std;

#define int			long long
#define double 		long double
#define pb			push_back
#define in 			insert
#define mp			make_pair
#define f			first
#define s			second
#define x			first
#define y			second
#define all(el)		el.begin(), el.end()
#define allr(el)	el.rbegin(), el.rend()
#define sz(el)		(int)el.size()
 
template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1ll;} else {return 0ll;}}
template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1ll;} else {return 0ll;}}

signed main() {
	
	#ifdef BarkovBG
		freopen("input.txt", "r", stdin);
	#endif

	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int n;
	cin >> n;
	vector<int> a(n);
	for (int &now : a) {
		cin >> now;
	}

	unordered_map<int, int> hv;
	for (int &now : a) {
		hv[now]++;
	}
	int ans = 0;
	for (auto now : hv) {
		ans += max(0LL, now.s * (now.s - 1) / 2);
	}
	for (int &now : a) {
		if (hv[now] - 2 >= 0) {
			cout << ans - max(0LL, hv[now] * (hv[now] - 1) / 2) + max(0LL, (hv[now] - 1) * (hv[now] - 2) / 2) << "\n";
		} else {
			cout << ans - max(0LL, hv[now] * (hv[now] - 1) / 2) << "\n";
		}
	}

	return 0;
}


Measured memory_bytes: 9160
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
char X[2];
char Y[2];
int main(){
	scanf("%s%s",X,Y);
	if(X[0]<Y[0])printf("<\n");
	else if(X[0]>Y[0])printf(">\n");
	else printf("=\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int nil = -1;

struct Node{int parent,left,right;};
Node node_array[26];

void preorder(int node_number){
    if(node_number == nil) return;
    printf(" %d",node_number);
    preorder(node_array[node_number].left);
    preorder(node_array[node_number].right);
}

void inorder(int node_number){
    if(node_number == nil) return;
    inorder(node_array[node_number].left);
    printf(" %d",node_number);
    inorder(node_array[node_number].right);
}

void postorder(int node_number){
    if(node_number == nil) return;
    postorder(node_array[node_number].left);
    postorder(node_array[node_number].right);
    printf(" %d",node_number);
}

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        node_array[i].parent = nil;
    }
    for(int i=0;i<n;i++){
        int node_number,left,right;
        cin >> node_number >> left >> right;
        node_array[node_number].left = left;
        node_array[node_number].right = right;
        if(left != nil) node_array[left].parent = node_number;
        if(right != nil) node_array[right].parent = node_number;
    }
    int root;
    for(int i=0;i<n;i++){
        if(node_array[i].parent == nil) root = i;
    }
    cout << "Preorder" << endl;
    preorder(root);
    cout << endl;
    cout << "Inorder" << endl;
    inorder(root);
    cout << endl;
    cout << "Postorder" << endl;
    postorder(root);
    cout << endl;
}




Measured memory_bytes: 3260
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
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 PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

typedef pair<double, double> xy;

double getAreaOfTriangle(xy a, xy b, xy c) {
    double ab = sqrt(pow(a.first-b.first,2) + pow(a.second-b.second,2));
    double bc = sqrt(pow(b.first-c.first,2) + pow(b.second-c.second,2));
    double ca = sqrt(pow(c.first-a.first,2) + pow(c.second-a.second,2));
    double z = (ab+bc+ca)/2;
    return sqrt(z*(z-ab)*(z-bc)*(z-ca));
}

double getAreaOfPolygon(vector<xy> v) {
    double area = 0;
    REP(i,v.size()-2) {
        area += getAreaOfTriangle(v[0], v[i+1], v[i+2]);
    }
    return area;
}

int main() {
    vector<xy> v;
    double x,y;
    char c;
    while(cin >> x >> c >> y) {
        v.push_back(make_pair(x,y));
    }
    double area = getAreaOfPolygon(v);
    printf("%.6f\n", area);
    return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int cnt[26];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = (int)s.size();
    ll sm = (ll)n*(n-1)/2;
    rep(i,n){
        cnt[s[i] - 'a']++;
    }
    ll hoge = 0;
    rep(i,26){
        hoge += (ll)cnt[i]*(cnt[i]-1)/2;
    }
    cout << sm - hoge + 1 << endl;
    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main() {
  int n;
  string s;
  int ans=0;
  
  cin >> n >> s;
  
  for(int i=0; i<1000; i++){
    int x=i/100;        int y=(i%100)/10;            int z=i%10;
    for(int j=0; j<n-2; j++){ if(s[j]-'0'==x){
        for(j=j+1; j<n-1; j++){ if(s[j]-'0'==y){
            for(j=j+1; j<n; j++){ if(s[j]-'0'==z){ ans++; j=n;} }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000

int main(){
  char buf[1024];
  int A, B, T;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d %d %d", &A, &B, &T);

  int ans=T/A*B;

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

  return 0;


}


Measured memory_bytes: 128
void main() {
    int[] a = new int[5], b = new int[5];
    foreach (i; 0 .. 5) {
        int tmp = readln.chomp.to!int - 1;
        a[i] = tmp / 10 * 10, b[i] = tmp % 10 + 1;
    }
    zip(b, a).sort!((t1, t2) => t1[0] > t2[0]);
    int time;
    foreach (i; 0 .. 5) {
        if (i == 4) {
            time += a[i] + b[i];
        } else {
            time += a[i] + 10;
        }
    }
    time.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
import math
# stdin = open("sample.txt")

s = stdin.readline().rstrip()

v = [s[i] for i in range(0, len(s))]

g = v.count('g')
p = v.count('p')

print((g-p)//2)

Measured memory_bytes: 4096
#include<stdio.h>
#define M 10000000
#define N 100
#define C 100
#define R 100
void matrixChainOrder(int);
int m[C][R],p[N];

int main(){
  int i,n,c;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d%d",&p[i],&c);
    p[i+1] = c;
  }
  matrixChainOrder(n);
  printf("%d\n",m[1][n]);

  return 0;
}
 
void matrixChainOrder(n){
  int i,j,l,k,q;
   
  for(i = 1;i <= n;i++)
    m[i][i]=0;

  for(l = 2;l <= n;l++){
    for(i = 1;i <= n-l+1; i++){
      j = i + l - 1;
      m[i][j] = M;     
      for(k = i;k <= j-1;k++){
    q = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];
    if(q < m[i][j]) m[i][j] = q;
      }
    }
  }
}
      

Measured memory_bytes: 636
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#define xxx 100100
using namespace std;
struct lian{
	int pre,nex;
}xx[xxx],yy[xxx];
struct haha{
	int p,w;
}tem;
struct cmp{
	bool operator()(haha &a,haha &b){
		return a.w>b.w;
	}
};
priority_queue<haha,vector<haha>,cmp>q;
struct node{
	int x,y,pos;
}p[xxx];
bool cmpxx(node p1,node p2)
{
	return p1.x<p2.x;
}
bool cmpyy(node p1,node p2)
{
	return p1.y<p2.y;
}
int n,used[xxx],ans;
bool cmppp(node p1,node p2)
{
	return p1.pos<p2.pos;
}

int dis(int u,int v)
{
	return min((int)abs(p[u].x-p[v].x),(int)abs(p[u].y-p[v].y));
}

void doxx(int pp)
{
	if (xx[pp].pre!=0) q.push((haha){xx[pp].pre,dis(pp,xx[pp].pre)});
	if (xx[pp].nex!=0) q.push((haha){xx[pp].nex,dis(pp,xx[pp].nex)});
	xx[xx[pp].nex].pre=xx[pp].pre;
	xx[xx[pp].pre].nex=xx[pp].nex;
}

void doyy(int pp)
{
	if (yy[pp].pre!=0) q.push((haha){yy[pp].pre,dis(pp,yy[pp].pre)});
	if (yy[pp].nex!=0) q.push((haha){yy[pp].nex,dis(pp,yy[pp].nex)});
	yy[yy[pp].nex].pre=yy[pp].pre;
	yy[yy[pp].pre].nex=yy[pp].nex;	
}

int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>p[i].x>>p[i].y;
		p[i].pos=i;
	}
	sort(p+1,p+n+1,cmpxx);
	p[0].pos=p[n+1].pos=0;
	for (int i=1;i<=n;i++)
	{
		xx[p[i].pos].pre=p[i-1].pos;
		xx[p[i].pos].nex=p[i+1].pos;
	}
	sort(p+1,p+n+1,cmpyy);
	p[0].pos=p[n+1].pos=0;
	for (int i=1;i<=n;i++)
	{
		yy[p[i].pos].pre=p[i-1].pos;
		yy[p[i].pos].nex=p[i+1].pos;
	}
	sort(p+1,p+n+1,cmppp);
	ans=0;
	q.push((haha){1,0});
	while (!q.empty())
	{
		tem=q.top();
		q.pop();
		if (used[tem.p]) continue;
		ans+=tem.w;
		used[tem.p]=1;
		doxx(tem.p);
		doyy(tem.p);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 9072
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int v[1000000];
int main()
{

  ios::sync_with_stdio(0);
  cin.tie(0);
  int k,sum=0;
  cin>>k;
  for(int i=1; i<=1000000; i++){
    sum=sum*10+7;
    sum=sum%k;
    if(sum==0){cout<<i; return 0;}
    else if(v[sum]){
        cout<<-1;
        return 0;
    }
    v[sum]=1;
  }
  cout<<-1;

    return 0;
}

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

#include <utility>
using namespace std;

#define REP(i, n) for ( int i = 0; i < (n); i++ )
const int INF = 1e9;
using Pii = pair<int, int>;

const int con_type = 26;
int D = 365;
int C[con_type];
int S[365][con_type];
vector<int> ans;
int last[con_type];

struct State {
  int cost;
  vector<int> ans;
  vector<int> last;

  State() {
    cost = 0;
    last = vector<int>(26, -1);
  }

  State(int cost, vector<int> ans, vector<int> last):
    cost(cost), ans(ans), last(last) {};

  bool operator<( const State& s ) const {
    return cost < s.cost;
  }

  bool operator>( const State& s ) const {
    return cost > s.cost;
  }
};

void solve() {
  priority_queue<State> Q;
  Q.push(State());
  REP(d, D) {
    priority_queue<State> nQ;
    while ( !Q.empty() ) {
      State now = Q.top(); Q.pop();
      vector<Pii> add_cost;
      int sum = 0;
      int type_cost[26];
      REP(i, con_type) {
        sum += (d-now.last[i])*C[i];
        type_cost[i] = (d-now.last[i])*C[i];
      }
      REP(i, con_type) {
        add_cost.emplace_back(Pii(S[d][i]+(d-now.last[i])*C[i]-sum, i));
      }
      sort(add_cost.begin(), add_cost.end(), greater<Pii>());
      REP(i, 12) {
        int id = add_cost[i].second;
        State next = now;
        next.cost += S[d][id];
        next.cost -= sum;
        next.cost += type_cost[id];
        next.ans.emplace_back(id);
        next.last[id] = d;
        nQ.push(next);
      }
    }
    Q = priority_queue<State>();
    REP(i, min(800, (int)nQ.size())) {
      Q.push(nQ.top()); nQ.pop();
    }
  }

  ans = Q.top().ans;
}

void input() {
  cin >> D;
  REP(i, con_type) {
    cin >> C[i];
    last[i] = -1;
  }
  REP(i, D) REP(j, con_type) cin >> S[i][j];
}

void output() {
  REP(i, D) cout << ans[i]+1 << endl;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  input();
  solve();
  output();

  return 0;
}


Measured memory_bytes: 20132
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const double pi=3.14159265358979323846;
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b){
    if (a % b == 0){
        return(b);
    }else{
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
bool isprime(int n){
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;

    for (int i = 3; i <= sqrt(n); i += 2){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}
void sayYes(bool f) {
    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
void sayYES(bool f) {
    if (f) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

int main() {
  char c;
  cin >> c;
  if('a'<=c&&c<='z'){
    cout << 'a' << endl;
  }else{
    cout << 'A' << endl;
  }
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <stdlib.h>
#define ALP 26
int dcm(const void *a,const void *b){
  return *(int *)b-*(int *)a;
}
int main(){
  int i,ok=1,alp1[ALP],alp2[ALP];
  for(i=0;i<ALP;i++){
    alp1[i]=0;
    alp2[i]=0;
  }
  char s;
  while(scanf("%c",&s)!=EOF&&s!='\n')alp1[s-97]++;
  while(scanf("%c",&s)!=EOF&&s!='\n')alp2[s-97]++;
  qsort(alp1,ALP,sizeof(int),dcm);
  qsort(alp2,ALP,sizeof(int),dcm);
  for(i=0;i<ALP;i++){
    if(alp1[i]==alp2[i])ok*=1;
    else ok*=0;
  }
  if(ok==1)printf("Yes");
  else printf("No");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;
  int pre = -1;
  long long ans = 1;
  map<int, long long> mp;
  for(int i = 0; i < N; ++i){
    int x; cin >> x;
    if(x == pre)continue;
    pre = x;
    mp[x] += ans % 1000000007;
    ans = mp[x] % 1000000007;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

bool func(int N) {
  string n = to_string(N);
  int size = (int)(n.size());
  bool flag = true;
  for(int i=0; i<size/2; ++i) {
    if(n[i]!=n[size-i-1]) {
      flag = false;
      break;
    }
  }

  return flag;
}

int main() {
  int A, B, res = 0;
  cin >> A >> B;

  for(int i=A; i<=B; ++i) {
      if(func(i)) ++res;
  }

  cout << res << endl;

  return 0;
}



Measured memory_bytes: 256
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

//#include "sort/bsearch.h"

//find largest x in [s,t) which check(x) is true
template<class T>
T bsearch_largest(T s, T t, int check(T)) {
	s--;
	while (t-s>1) {
		T m = (s+t)/2;
		if (check(m)) s = m;
		else t = m;
	}
	return s;
}

//find smallest x in [s,t) which check(x) is true
template<class T>
T bsearch_smallest(T s, T t, int check(T)) {
	s--;
	while (t-s>1) {
		T m = (s+t)/2;
		if (check(m)) t = m;
		else s = m;
	}
	return t;
}

//#include "sort/merge.h"

template<class I, class N=long>
N merge(I a, I ea, I b, I eb, I &c) {
	N inv = 0;
	N n = std::distance(a, ea);
	while (a != ea && b != eb) {
		if (*b < *a) {
			*c++ = *b++;
			inv += n;
		}
		else {
			*c++ = *a++;
			n -= 1;
		}
	}
	while (a != ea) *c++ = *a++;
	while (b != eb) *c++ = *b++;
	return inv;
}


//return reverse pair count
template<class I, class N=long>
N merge_sort(const I &a, const I &e, I tmp) {
	int n = std::distance(a, e);
	if (n<2) return 0;
	auto m = std::next(a, n/2);
	auto t = tmp;
	N left  = merge_sort(a, m, t);
	N right = merge_sort(m, e, t);
	N both  = merge(a, m, m, e, t);
	copy(tmp, t, a);
	return left + right + both;
}

template<class C, class N=long>
N merge_sort(C &a) {
	int n = a.size();
	if (n<2) return 0;
	C t;
	//TODO
	auto i = back_inserter(t);
	return merge_sort(a.ebgin(), a.end(), i);
}
//#include "seq/psum.h"

//b[i] = sum:a[0,i), b can be a-1
template<class I>
void psum_create_z(I a, I e, I b) {
	*b = 0;
	while (a != e) {
		auto x = (*b++) + (*a++);
		*b = x;
	}
}

template<class I>
void psum_create(I a, I e) {
	if (a==e) return;
	auto s = *a++;
	while (a != e) {
		s = s + *a;
		*a++ = s;
	}
}


#define MAXN 100000

int n;
int a[MAXN], b[MAXN+1], c[MAXN+1];

int input() {
	if (scanf("%d", &n) < 0) return 0;
	for (int i=0; i<n; i++) scanf("%d", &a[i]);
	return 1;
}

void init() {
}

int is_median(int x) {
	for (int i=0; i<n; i++)
		b[i+1] = (a[i]>=x) ? 1: -1;
	//printa(a, n); printa(b+1, n);
	psum_create_z(b+1, b+n+1, b);
	//printa(b, n+1);

	long inv = merge_sort(b+0, b+n+1, c+0);

	/*
	long inv = 0;
	for (int i=0; i<=n; i++)
		for (int j=i+1; j<=n; j++)
			if (b[i]>b[j]) inv++;
	*/

	long m = long(n)*(n+1)/2;
	long cnt = m-inv;
	int ok = cnt >= (m+1)/2;
	//p(x, 'i', inv, 'c', cnt, 'm', m, ok);
	return ok;
}

long solve() {
	int ma = *max_element(a, a+n), mi = *min_element(a, a+n);
	return bsearch_largest(mi, ma+1, is_median);
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 1280
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int MAXN = 1000000+9;
char s[MAXN];
int len;
vector<int> vec;
int cntx;
deque<char> que;

bool check(){
	int i;
	for(i=1;i<=len;i++){
		if(s[i]!='x')
			vec.push_back(i);
	}
	int cnt=0;
	for(i=len;i>=1;i--){
		if(s[i]=='x')continue;
		if(s[i]!=s[vec[cnt]])
			return false;
		cnt++;
	}
	return true;
}

int reverse(int x){
	return vec.size()-x-1;
}

int oneside(){
	int i;
	int re=0;
	for(i=1;i<=len;i++){
		if(s[i]!='x'){
			re+=i-1;
			break;
		}
	}
	for(i=len;i>=1;i--){
		if(s[i]!='x'){
			re+=len-i;
			break;
		}
	}
	if(re>len)re=len;
	return re;
}

void solve(){
	int ans=0;
	if(check()){
		for(int i=1;i<=len;i++)
			que.push_back(s[i]);
		while(que.size()){
			while(que.front()!='x' && que.back()=='x'){
				++ans;
				que.pop_back();
			}
			while(que.back()!='x' && que.front()=='x'){
				++ans;
				que.pop_front();
			}
			que.pop_front();
			if(que.size()) que.pop_back();
		}
		printf("%d\n",ans);
	}
	else{
		puts("-1");
	}
}

int main(){
	scanf("%s",s+1);
	len=strlen(s+1);
	solve();
}


Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<int, int> ii;


int main(){
  int A, B, T;cin>>A>>B>>T;
  
  cout << (T/A)*B << endl;
  return 0;
}

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

int main(){
int h,b;
char r[5];
char a[5];
 cin >> r >> a;
while(r[0]!=0&&r[1]!='\0'&&a[0]!=0&&a[1]!='\0'){
 h=0;b=0;
 for(int i=0;i<4;i++){
 	 if(r[i]==a[i]){
           h++;
	 }
 }
 for(int i=0;i<4;i++){
  for(int j=0;j<4;j++){
   if(r[i]==a[j]){
      b++;
    }
  }
}
 b=b-h;
 cout << h << ' ' << b << endl;
 cin >> r >> a;
}
return 0;
}

Measured memory_bytes: 1144
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	double[] d;
	P[] ps;
	int n;

	void run(){
		d=new double[3];
		for(int t=sc.nextInt(); t>0; t--){
			for(int i=0; i<3; i++){
				d[i]=sc.nextDouble();
			}
			n=sc.nextInt();
			ps=new P[n];
			for(int i=0; i<n; i++){
				double x=sc.nextDouble();
				double y=sc.nextDouble();
				double z=sc.nextDouble();
				ps[i]=new P(x, y, z);
			}
			solve();
		}
	}

	void solve(){
		double[] len={0, 0, 0};
		for(int c=0; c<n; c++){
			for(int b=0; b<n; b++){
				if(b==c){
					continue;
				}
				for(int a=0; a<n; a++){
					if(a==b||a==c){
						continue;
					}
					len[0]=ps[b].sub(ps[c]).abs()/d[0];
					len[1]=ps[c].sub(ps[a]).abs()/d[1];
					len[2]=ps[a].sub(ps[b]).abs()/d[2];
					boolean error=false;
					for(int i=0; i<3; i++){
						int p=i;
						int q=(i+1)%3;
						error|=abs(len[p]-len[q])/len[p]+EPS>=0.001;
					}
					if(!error){
						// debug(len);
						// debug(a,b,c);
						println((a+1)+" "+(b+1)+" "+(c+1));
					}
				}
			}
		}
	}

	class P{
		double x, y, z;

		P(){
			this(0, 0, 0);
		}

		P(double x, double y, double z){
			this.x=x;
			this.y=y;
			this.z=z;
		}

		P add(P p){
			return new P(x+p.x, y+p.y, z+p.y);
		}

		P sub(P p){
			return new P(x-p.x, y-p.y, z-p.z);
		}

		P mul(double m){
			return new P(x*m, y*m, z*m);
		}

		P div(double d){
			return new P(x/d, y/d, z/d);
		}

		double abs(){
			return Math.sqrt(abs2());
		}

		double abs2(){
			return x*x+y*y+z*z;
		}

		// inner product
		double dot(P p){
			return x*p.x+y*p.y+z*p.y;
		}

		// outer product
		P det(P p){
			return new P(y*p.z-z*p.y, z*p.x-x*p.z, x*p.y-y*p.x);
		}

		@Override
		public String toString(){
			return x+", "+y+", "+z;
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
import sys

N = int(input())
A = list(map(int, input().split()))

if(0 in A):
    print(0)
    sys.exit(0)

prod = 1
for a in A:
    prod *= a
    if prod > 1000000000000000000:
        print(-1)
        sys.exit(0)

print(prod)

Measured memory_bytes: 87880
# include <bits/stdc++.h>
using namespace std;
# define eps 1e-8
# define INF 1e20
# define pi  acos(-1.0)
# define MX  1005

int main()
{
    double a,b;
    scanf("%lf%lf",&a,&b);
    printf("%.0f\n",b*2-a);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N, K;
    cin >> N >> K;
    //余りはK以上
    //aはN以下 bはKより大きくN未満
    ll counter = 0;
    /*
    for(ll i=K;i<=N;i++)
    {
        // a = i として、
        //余りがKの時のありうる組み合わせが
        //bがK+1, K+2, ... , の時なので
        // N - i が商が0のときの割ることのできる数
        // min が iで maxが N
        counter += N - i;
        //割ったときの商が１以上の時の処理
        // min が 1 で maxが i-1
        // 割った余りがK以上であればよい
        for(size_t j=1;j<i; j++)
        {
            if(i % j >= K) counter++;
        }
        //cerr << i << ":" << counter << endl;

    }
    */
    for(ll b=1;b<=N;b++)
    {
        //bを固定してaを自由にする
        //bがK以上のときN/b回条件に一致するものが存在し、あまりの部分にいくつあるかをカウントすればよい
        counter+= (N/b)*max((b-K), 0ll) + max(N%b -K +1, 0ll);
        //cerr << b << ":" << counter << endl;
    }
    if(K==0) counter = N*N;
    cout << counter << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int N, T;
  while(cin>>N>>T && N){
    vector<int> v(N);
    REP(i, N) cin>>v[i];
    sort(v.begin(), v.end());
    ll ans = 1;
    FOR(i, 1, N){
      int idx = lower_bound(v.begin(), v.end(), v[i] - T) - v.begin();
      int cnt = i - idx;
      ans *= cnt + 1;
      ans %= MOD;
    }
    cout<<ans<<endl;
  }

  return 0;
}

Measured memory_bytes: 1536
#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 EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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

using P = pair<int, int>;

int dist(P a, P b)
{
    return abs(a.first - b.first) + abs(a.second - b.second);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<string> grid(h);
    for (int i = 0; i < h; i++)
    {
        cin >> grid[i];
    }
    vector<P> rec;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (grid[i][j] == 'B')
            {
                rec.push_back(P(j, i));
            }
        }
    }
    int n = rec.size();
    int ans = 0;
    int x_mn = INF;
    int x_mx = -INF;
    int y_mn = INF;
    int y_mx = -INF;
    for (int i = 0; i < n; i++)
    {
        chmin(x_mn, rec[i].first);
        chmin(y_mn, rec[i].second);
        chmax(x_mx, rec[i].first);
        chmax(y_mx, rec[i].second);
    }
    vector<P> kouho;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (grid[i][j] == 'B')
            {
                if (i == y_mn || i == y_mx || j == x_mn || j == x_mx)
                {
                    kouho.push_back(P(j, i));
                }
            }
        }
    }
    int sz = kouho.size();
    for (int i = 0; i < sz; i++)
    {
        for (int j = i + 1; j < sz; j++)
        {
            chmax(ans, dist(kouho[i], kouho[j]));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 11736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5005,p=1000000007;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int qpow(int x,int k){
	int t=1;
	for (;k;k>>=1){
		if (k&1) t=(ll)t*x%p;
		x=(ll)x*x%p;
	}
	return t;
}
int n,f[N][N],siz[N],g[N],b[N];
vector<int> e[N];
void check(int &x,int y){if ((x+=y)>=p) x-=p;}
void merge(int x,int y){
	for (int i=0;i<=siz[x]+siz[y];i++) g[i]=0;
	for (int i=0;i<=siz[x];i++)
	for (int j=0;j<=siz[y];j++)
	g[i+j]=(g[i+j]+(ll)f[x][i]*f[y][j])%p;
	for (int i=0;i<=siz[x]+siz[y];i++) f[x][i]=g[i];
	siz[x]+=siz[y];
}
void work(int x,int fa){
	f[x][1]=1;siz[x]=1;
	for (auto y : e[x])
	if (y!=fa){
		work(y,x);
		merge(x,y);
	}
	for (int i=2;i<=siz[x];i+=2) check(f[x][0],p-(ll)f[x][i]*b[i]%p);
}
int main(){
	n=read();
	for (int i=1;i<n;i++){
		int u=read(),v=read();
		e[u].push_back(v);
		e[v].push_back(u);
	}
	b[0]=1;
	for (int i=2;i<=n;i+=2) b[i]=(ll)b[i-2]*(i-1)%p;
	work(1,0);
	printf("%d\n",(p-f[1][0])%p);
	return 0;
}

Measured memory_bytes: 97280
import heapq  # heapqライブラリのimport
N,K=map(int,input().split())
V=list(map(int,input().split()))
ans=0
for i in range(1,min(N,K)+1):
 for t in range(i+1):
  B=V[0:i-t]+V[N-t:N] 
  total=sum(B)
  cut=0
  for j in  range(min(i,K-i)):
   heapq.heapify(B)
   cut=min(cut,cut+heapq.heappop(B))
  ans=max(ans,total-cut)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){
    int n;
    cin >>n;
    vector<int> a(n);
    deque<int> q;
    rep(i,n) cin >>a[i];
    rep(i,n) q.push_back(a[i]);
    int cnt=0;
    int i=1;
    while(q.size()>0){
        if(q.front()==i) i++;
        else cnt++;
        q.pop_front();
    }
    if (i==1)cout <<"-1";
    else cout << cnt;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define LEN 100005

using namespace std;

struct P
{
    string name;
    int t;
};

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b){
    return a < b ? a : b;
}

int main(){
    int elaps = 0, c;
    int i, q;
    P u;
    cin >> n;
    cin >> q;

    for(i=1; i<=n; i++){
        cin >> Q[i].name;
        cin >> Q[i].t;
    }
    head = 1;
    tail = n+1;

    while(head != tail){
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0){
            enqueue(u);
        }else{
            cout << u.name << " " << elaps << endl;
        }
    }
}


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

//define ll long long;
//define ar array;

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

    int a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    for (int i = a; i <= b; i++){
        if (i%c == 0){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 24 22:36:54 2019

@author: yuta
"""

def match(s):
    count = 0
    for i in s:
        if i == '1':
            count += 1
    print(count)    

x = input()
match(x)    
"""    
    count = 0
    for i in "Hello":
        if i == 'l':
            count = count + 1
    print(count)
"""

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

int p[6] = {500, 100, 50, 10, 5, 1};

int main(){
	int n;
	while(cin >> n, n){
		int ans = 0;
		n = 1000 - n;

		for(int i=0; i < 6; i++){
			ans += n / p[i];
			n -= n / p[i] * p[i];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <math.h>
using namespace std;

int main() {
	int n;
	cin>>n;
	
	long long sum = 1;
	long long prim = pow(10,9)+7;
    for(int i=1;i<=n;i++)
    {
        sum*=i;
        sum = sum%prim;
    }
    cout<<sum;
	return 0;
}


Measured memory_bytes: 256
while True:
	try:
		xA,yA,xB,yB,xC,yC,xD,yD = map(float,raw_input().split())
	except EOFError:
		break
	
	if abs((xA - xB) * (xC - xD) + (yA - yB) * (yC - yD)) < 1e-10:
		print "YES"
	else:
		print "NO"

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

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

    if(a<=k){
        cout<<0<<" "<<max(0ll,b-(k-a))<<endl;
    }

    else cout<<a-k<<" "<<b<<endl;

    return 0;
}

Measured memory_bytes: 256
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-02-02 14:29:25
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#include<iostream>
#include<string.h>
#define i64 long long
const int N=1010;
int n,x[N],y[N],d[N],m;
std::string ans[N];
i64 calc(i64 a,i64 b){ return std::abs(a)+std::abs(b); }
int main()
{
	n=read();
	fr(i,1,n){ x[i]=read(); y[i]=read(); }
	fr(i,2,n) if((x[i]+y[i]+x[1]+y[1])%2){ printf("-1\n"); return 0; }
	if((x[1]+y[1])%2)
	{
		d[++m]=1;
		fr(i,1,n){ ans[i]+='U'; y[i]--; }
	}
	d[++m]=1; d[++m]=1;
	fd(i,30,0) d[++m]=1<<i;
	d[++m]=1;
	fr(i,1,n)
	{
		ans[i]+='U'; y[i]--;
		if(y[i]&1){ ans[i]+='U'; y[i]--; }
		else{ ans[i]+='R'; x[i]--; }
		fd(j,30,0)
		{
			if(calc(x[i]+(1<<j),y[i])<=(1<<j)){ x[i]+=(1<<j); ans[i]+='L'; }
			else if(calc(x[i]-(1<<j),y[i])<=(1<<j)){ x[i]-=(1<<j); ans[i]+='R'; }
			else if(calc(x[i],y[i]+(1<<j))<=(1<<j)){ y[i]+=(1<<j); ans[i]+='D'; }
			else if(calc(x[i],y[i]-(1<<j))<=(1<<j)){ y[i]-=(1<<j); ans[i]+='U'; }
		}
		if(x[i]==1) ans[i]+='R';
		else if(x[i]==-1) ans[i]+='L';
		else if(y[i]==1) ans[i]+='U';
		else if(y[i]==-1) ans[i]+='D';
//		printf("%d %d\n",x[i],y[i]);
	}
	printf("%d\n",m);
	fr(i,1,m) printf("%d%c",d[i],i==m?'\n':' ');
	fr(i,1,n) std::cout<<ans[i]<<std::endl;
	return 0;
}

Measured memory_bytes: 384
// Problem : F - LIS on Tree
// Contest : AtCoder - AtCoder Beginner Contest 165
// URL : https://atcoder.jp/contests/abc165/tasks/abc165_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

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

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const int inf = 1e9 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

int n, len = 1;
int val[maxN], ans[maxN];
vi dp;
vi graph[maxN];

void DFS(int u, int par) {
	ans[u] = len;
	for (auto x: graph[u]) {
		if (x != par) {
			int pos = lower_bound(dp.begin(), dp.end(), val[x]) - dp.begin();
			int prv = dp[pos];
			if (dp[pos] >= inf) {
				len++;
			}
			dp[pos] = val[x];
			DFS(x, u);
			dp[pos] = prv;
			if (dp[pos] >= inf) len--;
		}
	}
}

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	RI(i, n) {
		cin >> val[i];
	}
	dp.resize(n + 1);
	RI(i, n) {
		dp[i] = inf + i;
	}
	dp[1] = val[1];
	REP(_, n - 1) {
		int a, b;
		cin >> a >> b;
		graph[a].pb(b);
		graph[b].pb(a);
	}
	DFS(1, -1);
	RI(i, n) cout << ans[i] << "\n";
	return 0;
}
 


Measured memory_bytes: 46792