akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define ll long long
#define pp pair<ll,ll>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
void _(ll&a , ll b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll k,n;cin >> k >> n;
    ll a[n];
    for (int i = 0; i < n; ++i)
    {
    	cin >> a[i];
    }
    vector<ll> v;
    for (int i = 0; i < n-1; ++i)
    {
    	v.push_back(a[i+1]-a[i]);
    }
    v.push_back(k-a[n-1]+a[0]);
    // for (int i = 0; i < n; ++i)
    // {
    // 	cout << v[i] << " ";
    // }
    cout << k-(*(max_element(v.begin(), v.end())));
    }

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  vector<vi> a(2, vi(n));
  rep(i, 2) rep(j, n) cin >> a[i][j];
  int ans = 0;
  rep(k, n) {
    int i = 0;
    int now = 0;
    rep(j, n) {
      now += a[i][j];
      if(j == k) {
        i++;
        now += a[i][j];
      }
    }
    ans = max(ans, now);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
    string s2;
    int q;
    cin >> s2 >> q;
    string s;
    int t, f;
    char c;
    rep(i, q) {
        cin >> t;
        if (t == 1) swap(s, s2);
        else {
            cin >> f >> c;
            if (f == 1) s += c;
            else s2 += c;
        }
    }
    reverse(s.begin(), s.end());
    s += s2;
    cout << s << endl;
}

Measured memory_bytes: 1128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,ans=0; cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++) {
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i=0; i<N; i++) {
    if(i%2==0) ans +=a[i];
    else ans -=a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  string s;cin >> s;
  int ans =0;
  for(auto &i:s) if(i=='1') ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
void arraypPrint(int[], int);
void insertionSort(int[], int);
int main(){
  int N, i;
  int A[100]; 
  scanf("%d",&N);
  for( i = 0 ; i < N ; i++ ){
    scanf("%d",&A[i]);
  }

  arraypPrint(A, N);
  insertionSort(A, N);
  
  return 0;
}

void insertionSort(int A[], int N){
  int i, j, v;
  for( i = 1 ; i < N ; i++ ){
    v = A[i];
    j = i - 1;
    while( j >= 0 && A[j] > v ){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    arraypPrint(A, N);
  }
}

void arraypPrint(int A[], int N){
  int i;
  for( i = 0 ; i < N ; i++ ){
    if( i > 0 ) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}



Measured memory_bytes: 2064
s = input()
t = input()
n, m = len(s), len(t)

ans = 0
for i in range(n):
    if n < i+m:
        break
    x = s[i:i+m]
    cnt = 0
    for a, b in zip(x, t):
        if a == b:
            cnt += 1
    if ans < cnt:
        ans = cnt

print(m-ans)


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

int main(){
  int a,b;cin>>a>>b;
  if(a<0&&0<=b)cout<<"Zero";
  else if(a<0&&b<0&&(b-a)%2==0)cout<<"Negative";
  else if(a<0&&b<0&&(b-a)%2!=0)cout<<"Positive";
  else if(a==0&&b==0)cout<<"Zero";
  else cout<<"Positive";
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		int N, K;
		cin >> N >> K;
		vector<int> A( N );
		for( int i = 0; i < N; ++i ) { cin >> A[i]; }

		for( int i = K; i < N; ++i ) {
			if( A[i] > A[i-K] ) {
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 4044
import java.util.*;

class Main{
	static String[] checkArr = {"dreamer","dream","eraser","erase"};
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String in = scan.next();

		int last = in.length();

		LABEL:while(true) {
			//System.out.print(last);
			//System.out.println(in.substring(0,last));
			if(last==0) {
				System.out.println("YES");
				return;
			}

			for(String com : checkArr) {
				int dum = in.lastIndexOf(com,last-1);
				//System.out.println(dum+",");
				if(dum>=0 && last-dum==com.length()) {
					last -= com.length();
					continue LABEL;
				}
			}

			System.out.println("NO");
			return;
		}
	}
}


Measured memory_bytes: 13108
n = int(input())
d = list()
while len(d) < n:
    d.extend(list(map(int, input().split())))

appear = set()
for i in range(n):
    for j in range(0, min(3, n - i)):
        appear.add(int("".join(map(str, d[i:i + j + 1]))))

for i in range(1000):
    if not i in appear:
        print(i)
        break


Measured memory_bytes: 5636
/*
    In the name of
        "ALLAH"
    And say "AL-HAMD-U-LILLAH"
*/

#include<bits/stdc++.h>
#define ll long long
#define llu unsigned long long
#define _  printf("\n")
int take() {
    int n;
    scanf("%d",&n);
    return n;

}
double ttake() {
    double n;
    scanf("%lf",&n);
    return n;
}
ll takes() {
    ll n;
    scanf("%lld",&n);
    return n;

}

#define Int take()
#define Dnt ttake()
#define LL takes()
#define done {return 0;}
#define fr(i,x,n,a) for(int i=x;i<=n;i+=a)
#define FR(a,b,x) for(int i=(a);i<=(b);i+=(x))
#define rfr(i,x,n,a) for(int i=x;i>=n;i--)
int cas;
#define print printf("Case %d:",++cas)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pii pair<int,int>
#define vii vector<pii>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mk  make_pair
#define fill(x,v) memset(x,v,sizeof x)

using namespace std;

bool approximatelyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool essentiallyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyGreaterThan(float a, float b, float epsilon) {
    return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyLessThan(float a, float b, float epsilon) {
    return (b - a) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
#define STR {struct info}
#define dbg(x) {cout<<"ekhane"<<x<<endl;}
#define  SS second
#define  FF first
#define PQ priority_queue
#define great greatest
#define less lesser
#define mii map<int,int>
#define mil map<int,ll>
#define mll map<ll,ll>
#define msb map<string,bool>
#define V vector
#define M 100005
#define pf printf
//////////////////////////////////////////


int main(){

    int arr[ 4 ] , ans = 0 ;
    fr( i , 1 , 3 , 1 ) arr[ i ] = Int ;

    sort( arr + 1 , arr+ 1+ 3 ) ;

    int u = arr[ 3 ] - arr[ 1 ] , v = arr[ 3 ] - arr[ 2 ] ;

    if( u % 2 == 0 && v % 2 == 0 ){
        ans += ( u / 2 ) + ( v / 2 ) ;
    }else if( u % 2 && v % 2 ){
        ans++ ; u-- , v-- ;
        ans += ( u / 2 ) + ( v / 2 ) ;
    }else{
        ans += ( u / 2 ) + ( v / 2 ) + 2 ;
    }

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

    done;
}



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

#define ll long long
#define sz(x) (int)x.size();

using namespace std;

ll n,k;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>k;
	ll ans=k;
	ll x=n-1;
	while(x--){
		ans*=k-1;
	}
	cout<<ans;
	
}

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

using ll=long long;
using int64=int64_t;
const int inf=100000000;

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) xの絶対値

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

int fib(int x){
  if (x <= 2) return x;
  int a[x];
  a[0]=1;
  a[1]=2;
  for (int i=2;i<x;i++){
    a[i]=a[i-1]+a[i-2];
  }
  return a[x-1];
}//(x) フィボナッチ数列のx番目

int div1(ll x){
  return x%1000000007;
}

main(){
    int abcd=in(),a[4],ans;
    a[3]=abcd%10,a[2]=(abcd%100-a[3])/10,a[1]=(abcd%1000-abcd%100)/100,a[0]=abcd/1000;
    for(int i=0;i<(1 << 3)-1;i++) {
        bitset<3> pl(i);
        ans=a[0];
        for (int i2=0;i2<3;i2++){
            if (pl[i2]==false) ans+=a[i2+1];
            else ans-=a[i2+1];
        }
        if (ans==7) {
            printf("%d",a[0]);
            if (pl[0]==false) printf("+");
            else printf("-");
            printf("%d",a[1]);
            if (pl[1]==false) printf("+");
            else printf("-");
            printf("%d",a[2]);
            if (pl[2]==false) printf("+");
            else printf("-");
            printf("%d=7\n",a[3]);
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
using namespace std;
typedef long long llong;

int N, K;
char S[20];
char a;
int main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> S[i];
	cin >> K;

	a = S[K - 1];
	for (int i = 0; i < N; i++)
	{
		if (S[i] == a)
		{
			cout << a;
		}

		else
		{
			cout << '*';
		}
	}
}

Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
absss = 100000
ans = 0
for i,h in enumerate(H):
    if abs((T - h * 0.006) - A) < absss:
        ans = i + 1
        absss = abs((T - h * 0.006) - A)
print(ans)

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

int main(){

    int n,m,k;cin>>n>>m>>k;
    vector<vector<char>> g(n, vector<char>(m));
    for(int i=0;i<n;i++){
    	for(int j=0;j<m;j++){
    		cin>>g[i][j];
    	}
    }
    int bitn = (1 << n), bitm = (1 << m), ans = 0;
    for(int i=0;i<bitn;i++){
		set<int> dr;
		for(int r=0;r<n;r++){
			if((i >> r) & 1){
				dr.insert(r);
			}
		}
    	for(int j=0;j<bitm;j++){
    		auto t = g;
    		set<int> dc;
    		for(int c=0;c<m;c++){
    			if((j >> c) & 1){
    				dc.insert(c);
    			}
    		}
    		int c = 0;
    		for(int i=0;i<n;i++){
		    	for(int j=0;j<m;j++){
		    		if(dr.count(i) || dc.count(j)){
		    			t[i][j] = '.';
		    		}
		    		if(t[i][j] == '#'){
		    			c++;
		    		}
		    	}
		    }
		    if(c == k){
		    	ans++;
		    }
    	}
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 3580
N, M = map(int, input().split())
ab = [[int(i) for i in input().split()] for i in range(N)]
cd = [[int(i) for i in input().split()] for i in range(M)]
ans = []


for a, b in ab:
    num = float('inf')
    for i in range(M):
        if num > abs(a - cd[i][0]) + abs(b - cd[i][1]):
            num = abs(a - cd[i][0]) + abs(b - cd[i][1])
            check = i + 1
    ans.append(check)

for i in ans:
    print(i)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()

using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
vi hog(100010);
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e;
  string s,ss,sss;
  cin>>a>>b;
  if((a+1)/2>=b)
  cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)

template <class T, class U> ostream& operator<< (ostream &out, pair<T,U> c) { out << "(" << c.first << " "; out << c.second << ")"; return out; }
template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
const double PI  = 3.141592653589793238463;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> s(n);
    vector<pair<int,int>> p(m);
    int a, b;
    FOR(i,0,n){
        cin >> a >> b;
        s[i] = MP(a,b);
    }
    FOR(i,0,m){
        cin >> a >> b;
        p[i] = MP(a,b);
    }
    FOR(i,0,n){
        int ind;
        int mini = 1e9;
        FOR(j,0,m){
            int distance = abs(s[i].first - p[j].first) + abs(s[i].second - p[j].second);
            if (distance < mini){
                mini = distance;
                ind = j + 1;
            }
        }
        cout << ind << endl;
    }
}


Measured memory_bytes: 256
n=int(input())
s=str(n)
if s[-1]=="2" or s[-1]=="4" or s[-1]=="5" or s[-1]=="7" or s[-1]=="9":
    print("hon")
elif s[-1]=="0" or s[-1]=="1" or s[-1]=="6" or s[-1]=="8":
    print("pon")
elif s[-1]=="3":
    print("bon")

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

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

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

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

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

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

  string S; cin >> S;
  int b=0;
  int ans=0;
  rep(i,0,S.size()){
    if(S[i]=='B'){
      b++;
    }
    else{
      ans+=b;
    }
  }
  cout<<ans<<endl;
  

    return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll n;cin>>n;
    ll x;cin>>x;
    if(n*500>=x) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
int main(){
     Main();
     return 0;
}

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

int cost[101][101], n;

int main()
{
    cin>>n;
    for(int i=0;i<n;++i) for(int j=0;j<n;++j) cin>>cost[i][j];
    long long res=0;
    for(int i=0;i<n;++i) for(int j=i+1;j<n;++j)
        res+=min(cost[i][j], cost[j][i]);
    cout<<res<<endl;
}

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

#define int long long
#define MAXN 100005
#define MOD 1000000007
int n;
vector<int> adj[MAXN];
int dp[MAXN][2];

void dfs (int x, int p){
	for(int i : adj[x]){
		if(i==p) continue;
		dfs(i,x);
	}
	int sm0=1,sm1=1;
	for(int i : adj[x]){
		if(i==p) continue;
		sm0 *= (dp[i][0]+dp[i][1]);
		sm0 %= MOD;
		sm1 *= dp[i][0];
		sm1 %= MOD;
	}
	dp[x][0] = sm0; dp[x][1]=sm1;
}

int32_t main(){
	cin>>n;
	for(int i=0; i<n-1; i++){
		int u,v; cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	memset(dp,-1,sizeof(dp));
	dfs(1,-1);
	int t = dp[1][0] + dp[1][1];
	t%=MOD;
	cout<<t;
}

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

int main(){
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  priority_queue<int>Q;
  Q.push(abs(a2-a1));
  Q.push(abs(a3-a2));
  Q.push(abs(a1-a3));
  int ret=0;
  Q.pop();
  ret += Q.top();
  Q.pop();
  ret += Q.top();
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>
#include <cmath>
#include <map>
using namespace std;

typedef complex<int> P;
bool G[5001][5001];
vector<P> v;

int solve() {
  int res = 0;
  for(int i = 0; i < v.size(); ++i) {
    for(int j = i+1; j < v.size(); ++j) {
      P p1 = v[i];
      P p2 = v[j];
      P ve[2];
      ve[0] = ve[1] = p2 - p1;
      ve[0] = P(-ve[0].imag(), ve[0].real());
      ve[1] = -ve[0];
      for(int k = 0; k < 2; ++k) {
	P p1d = p1 + ve[k];
	P p2d = p2 + ve[k];
	if(p1d.real() < 0 || p1d.real() > 5000) continue;
	if(p1d.imag() < 0 || p1d.imag() > 5000) continue;
	if(p2d.real() < 0 || p2d.real() > 5000) continue;
	if(p2d.imag() < 0 || p2d.imag() > 5000) continue;
	if(G[p1d.imag()][p1d.real()] && G[p2d.imag()][p2d.real()]) {
	  res = max(res, ve[k].real()*ve[k].real() + ve[k].imag()*ve[k].imag());
	  break;
	}
      }
    }
  }
  return res;
}

int main() {
  int n;
  while(cin >> n && n) {
    fill(G[0],G[5001],false);
    v.clear();
    for(int i = 0; i < n; ++i) {
      int x, y;
      cin >> x >> y;
      v.push_back(P(x,y));
      G[y][x] = true;
    }
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 24000
use std::io::Read;

fn main() {
    let mut buf = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();

    // 行ごとのiterが取れる
    let mut iter = buf.split_whitespace();
    let item_count: usize = iter.next().unwrap().parse().unwrap();
    let max_weight: usize = iter.next().unwrap().parse().unwrap();
    let napsack: Vec<(u64, u64)> = (0..item_count)
        .map(|_| {
            (
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap(),
            )
        })
        .collect();
    let mut dp = vec![vec![0; max_weight + 1]; item_count + 1];

    for i in 0..item_count {
        for w in 0..max_weight + 1 {
            let weight = napsack[i].0 as usize;
            let value = napsack[i].1;
            if w >= weight {
                let current_value = dp[i][w - weight] + value;
                ch_max(&mut dp[i + 1][w], current_value);
            }

            let current_value = dp[i][w];
            ch_max(&mut dp[i + 1][w], current_value);
        }
    }
    println!("{}", dp[item_count][max_weight]);
}

fn ch_max(a: &mut u64, b: u64) -> bool {
    if *a < b {
        *a = b;
        return true;
    }
    return false;
}


Measured memory_bytes: 106748
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
#define N 4010
typedef pair<int,int> P;
typedef pair<int,pair<int,int> >PP;

ll primsum=0;
vector<P> v[N],u[N];
priority_queue<PP,vector<PP>,greater<PP> >Q;
void Qpush(int cost,int now,int from){
    Q.push(make_pair(cost,make_pair(now,from)));
}
void Prim(){
    bool vis[N]={0};
    Qpush(0,0,-1);
    while(!Q.empty()){
	int cost=Q.top().first;
	int x=Q.top().second.first;
	int from=Q.top().second.second;
	Q.pop();
	if(vis[x]==true)continue;
	vis[x]=true;
	if(from!=-1){
	    u[x].push_back(make_pair(cost,from));
	    u[from].push_back(make_pair(cost,x));
	    primsum+=cost;
	}
	lol(i,v[x].size()){
	    if(v[x][i].second==from)continue;
	    Qpush(v[x][i].first,v[x][i].second,x);
	}
    }
}

ll ans[N][N];
void DFS(int x,int maxi,int root,int from){
    ans[root][x]=maxi;
    lol(i,u[x].size()){
	if(u[x][i].second==from)continue;
	int cost=u[x][i].first;
	DFS(u[x][i].second,max(maxi,cost),root,x);
    }
}

int main(){
    int n,m,q;cin>>n>>m;
    lol(i,m){
	int a,b,c;cin>>a>>b>>c;a--,b--;
	v[a].push_back(make_pair(c,b));
	v[b].push_back(make_pair(c,a));
    }
    Prim();
    lol(i,n)DFS(i,0,i,-1);
    cin>>q;
    lol(i,q){
	int a,b;cin>>a>>b;a--,b--;
	cout<<primsum-ans[a][b]<<endl;
    }
    return 0;
}


Measured memory_bytes: 146412
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

const int MOD = 1000000007;

int main()
{
    long long n;
    cin >> n;

    vector<int> dp(4, 0);
    dp[0] = 1;
    for(int i=0; i<63; ++i){
        vector<int> nextDp(4, 0);
        for(int a=0; a<4; ++a){
            for(int j=0; j<3; ++j){
                int sum = (a & 1) + j;
                int b = sum / 2;
                if((sum & 1) > ((n>>i)&1) || ((sum & 1) == ((n>>i)&1) && (a & 2)))
                    b |= 2;
                nextDp[b] += dp[a];
                nextDp[b] %= MOD;
            }
        }
        dp.swap(nextDp);
    }
    cout << dp[0] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;


int a[9];
bool eval() {
	if (a[6] * 100 + a[7] * 10 + a[8] == a[0] + a[1] * 10 + a[2] + a[3] * 100 + a[4] * 10 + a[5])
		return true;
	else return false;
}

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

	int ans = 0;
	VI tmp,noot,no;
	REP(i, 9) {
		cin >> a[i];
		if (a[i] != -1)tmp.push_back(a[i]);
		else no.push_back(i);
	}
	eFOR(i, 1, 9) {
		bool f = false;
		REP(j, tmp.size()) {
			if (tmp[j] == i)f = true;
		}
		if (!f)noot.push_back(i);
	}
	//REP(i, not.size())cout << not[i] << " ";
	do {
		REP(i, noot.size()) {
			//cout << not[i] << " ";
			a[no[i]] = noot[i];
		}
		//cout << endl;
		if (eval())ans++;
	} while (next_permutation(noot.begin(),noot.end()));

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 3220
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int X = sc.nextInt();
    int T = sc.nextInt();
    if(N%X==0){
      System.out.println((N/X)*T);
    } else {
      System.out.println(((N/X)+1)*T);
    }
  }
}

Measured memory_bytes: 35472
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> List = new ArrayList<>();
        for(int i=0;i<3;i++) List.add(sc.nextInt());
        Collections.sort(List);
        int opt = List.get(0)+List.get(1);
        System.out.println(opt);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, a, b, ans = 0;
	cin >> n >> a >> b;
	for(int i = 1; i <= n; i++) {
		int add = 0, num = i;
		while(0 != num) {
			add += num % 10;
			num /= 10;
		}
		if((a <= add)&&(add <= b)) ans += i;
		
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1LL<<60;
long double pi=3.14159265358979323846L;
double eps=1e-12;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
int sum[2001][2001];
ll f(int x1,int y1,int x2,int y2){
    return sum[x2][y2]-sum[x1-1][y2]-sum[x2][y1-1]+sum[x1-1][y1-1];
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    string s,t;cin>>s>>t;
    int a,b;cin>>a>>b;
    string u;cin>>u;
    if(s==u)a--;
    else b--;
    cout<<a<<" "<<b<<endl;
}


Measured memory_bytes: 256
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = scan_lines n "%d" id
let arr = Array.make n (-1)

let rec solve n = function
  | [] -> n
  | v::rest ->
    if n = 0 || arr.(n-1) >= v then
      (arr.(n) <- v; solve (succ n) rest)
    else
      let i = lower_bound n (fun i -> arr.(i) < v) in
      arr.(i) <- v; solve n rest

let () =
  Printf.printf "%d\n" @@ solve 0 ls


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

int main() {
    int N,M;
    long X;
    cin>>N>>M>>X;
    long C[N];
    long A[N][M];
    for(int i=0; i<N; i++){
        cin>>C[i];
        for(int j=0;j<M;j++){
            cin>>A[i][j];
        }
    }

    vector<long long> z(M, 0);
    for(int i=0; i<N; i++){
        for(int j=0;j<M;j++){
            z[j] += A[i][j];
        }
    }
    
    int n = N;
    long ans = -1;
    for (int bit = 0; bit < (1<<n); ++bit) {
        vector<long> skills(M, 0);
        long money = 0;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                for(int j=0; j<M; j++){
                    skills[j] += A[i][j];
                }
                money += C[i];
            }
        }
        bool ok = true;
        for(int i=0; i<M; i++){
            if(skills[i] < X){
                ok = false;
                break;
            }
        }
        if(ok){
            if(ans == -1) ans = money;
            else ans = min(money, ans);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

//#define _USE_MATH_DEFINES
//#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

//const i64 mod = 1000000007ll;
const i64 smod = 11; //  998244353ll;
//const i64 inf = 1000000007; // 10000000000000007ll;

const double eps = 1e-8;

const i64 MAXN = 4 * 1'000'000 + 6;

i64 T;

i64 n, m;
i64 a[MAXN];

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> m;
    for (i64 i = 0; i < n; i++) {
        cin >> a[i];
    }

    sort(a, a + n, greater<i64>());

    i64 s = 0;
    for (i64 i = 0; i < n; i++) {
        s += a[i];
    }

    bool R = a[m - 1] * 4 * m >= s;
    if (R) {
        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;
  vector<int> l(n);
  for(int i=0; i<n; ++i){
    cin >> l.at(i);   
  }
  int sum = 0;
  for(int i=0; i<n; ++i){
    sum+=l.at(i);
  }
  sort(l.begin(), l.end());
  int max = l.at(n-1);
 if(sum-max >max ) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N,K;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>K;

	int64_t res = 0;
	for (int32_t b = K+1; b <= N; b++)
	{
		int32_t addnum = (N / b);
		res += addnum * (b - K);
		if (K == 0) { res -= 1; }
		auto tmp = N % b;
		res += std::max(0, tmp+1 - K);
	}
	
	out << res << endl;
	return 0;
}
#endif


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

#define all(a) (a).begin(), (a).end()

int main(){
   int n;
   cin>>n;
   vector<int> a(n),b(n),c(n);

   for (int i = 0; i < n; ++i){
      cin>>a[i];
   }
   for (int i = 0; i < n; ++i){
      cin>>b[i];
   }
   for (int i = 0; i < n; ++i){
      cin>>c[i];
   }
   sort(all(a));
   sort(all(b));
   sort(all(c));

   long long atb=0,btc=0,ans=0;
   for (int i = 0; i < n; ++i){
      atb=lower_bound(all(a),b[i])-a.begin();
      btc=n-(lower_bound(all(c),b[i]+1)-c.begin());
      ans+=atb*btc;
   }

   cout<<ans<<endl;

}


Measured memory_bytes: 1408
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    Scanner sc = new Scanner(System.in);

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

    void run(){

        for(;;){
            int n =sc.nextInt();
            int m =sc.nextInt();
            int t =sc.nextInt();
            int p =sc.nextInt();

            if((n | m | t | p) ==0){
                break;
            }

            int map[][] = new int[n][m];

            for(int i =0; i < n;i++){
                Arrays.fill(map[i],1);
            }

            for(int i = 0; i < t; i++){
                int next[][] = new int[n][m];

                int d = sc.nextInt();
                int c = sc.nextInt();

                for(int j = 0; j < n; j++){
                    for(int k = 0 ;k<m ; k++){

                        int jj = j ;
                        int kk = k;
                        if(d == 1){
                            jj = jj -c;
                            if(jj < 0){
                                jj = -jj-1 ;
                            }
                        }
                        if(d == 2){
                            kk = kk - c;
                            if(kk < 0){
                                kk = - kk -1;
                            }
                        }

                        next[jj][kk] += map[j][k];
                    }
                }

//                debug(next);

                map = next;
            }

            for(int i = 0;i < p;i++){
                int x = sc.nextInt();
                int y = sc.nextInt();

                System.out.println(map[x][y]);
            }
        }
    }

    void debug(int[][] a){
        System.out.println();
        for(int i =0 ;i < a.length ; i++){
            for(int j = 0 ;j < a[i].length; j++){
                System.out.print("\t"+a[i][j]);
            }
            System.out.println();
        }
    }
}




Measured memory_bytes: 41808
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int h,w,s;
int rem;
int u[35][35];
int rui[35][35];
P dp[35][35][35][35];
inline int sum(int t,int b,int l,int r){
    return rui[b][r]-rui[t-1][r]-rui[b][l-1]+rui[t-1][l-1];
}
P rec(int t,int b,int l,int r){
    if(dp[t][b][l][r]!=P(-1,-1))return dp[t][b][l][r];
    if(sum(t,b,l,r)<rem)return dp[t][b][l][r]=P(-INF,-INF);
    P ret = P(1,sum(t,b,l,r));
    for(int i=t;i<b;i++){
        rec(t,i,l,r);
        rec(i+1,b,l,r);
        int num = dp[t][i][l][r].fi+dp[i+1][b][l][r].fi;
        int smallest = min(dp[t][i][l][r].sec,dp[i+1][b][l][r].sec);
        if(num<0)continue;
        if(num>ret.fi){
            ret.fi = num;
            ret.sec = smallest;
        }else if(num==ret.fi){
            if(ret.sec<smallest)ret.sec = smallest;  
        }
    }
    for(int i=l;i<r;i++){
        rec(t,b,l,i);
        rec(t,b,i+1,r);
        int num = dp[t][b][l][i].fi+dp[t][b][i+1][r].fi;
        int smallest = min(dp[t][b][l][i].sec,dp[t][b][i+1][r].sec);
        if(num<0)continue;
        if(num>ret.fi){
            ret.fi = num;
            ret.sec = smallest;
        }else if(num==ret.fi){
            if(ret.sec<smallest)ret.sec = smallest;  
        }
    }
    //printf("t:%d b:%d l:%d r:%d number:%d smallest:%d\n",t,b,l,r,ret.fi,ret.sec);
    return dp[t][b][l][r]=ret;
}   
int solve(){
    scanf("%d %d %d",&h,&w,&s);
    if(h+w+s==0)return 1;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            scanf("%d",&u[i][j]);
            rui[i][j]=u[i][j];
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            rui[i][j]+=rui[i][j-1];
        }
    }
    for(int j=1;j<=w;j++){
        for(int i=1;i<=h;i++){
            rui[i][j]+=rui[i-1][j];
        }
    }
    rem = sum(1,h,1,w)-s;
    for(int i=0;i<35;i++){
        for(int j=0;j<35;j++){
            for(int k=0;k<35;k++){
                for(int l=0;l<35;l++){
                    dp[i][j][k][l]=P(-1,-1);
                }
            }
        }
    }
    /*while(1){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        cout << sum(a,b,c,d) << endl;
    }*/
    P ans = rec(1,h,1,w);
    printf("%d %d\n",ans.fi,s-(sum(1,h,1,w)-ans.sec));
    return 0;
}
int main(){
    while(!solve()){}
    return 0;
}

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

typedef long long ll;

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

      string s; cin >> s;
      ll ans = 0;
      ll z = 0;
      for (char c: s) {
            if (c == 'B') z++;
            else ans += z;
      }
      cout << ans;

      return 0;
}


Measured memory_bytes: 720
from fractions import *

N, K = [int(i) for i in input().split()]


a = Fraction(0, 1)
for t in range(1, N + 1):
    c = 0
    while t < K:
        t *= 2
        c += 1
    a += Fraction(1, 2 ** c)

print("{:.12f}".format(a.numerator / (N * a.denominator)))

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

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

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: i32,
        r: i32,
    }
    println!("{}", if n >= 10 { r } else { r + 100 * (10 - n) });
}


Measured memory_bytes: 4352
N,K = gets.split.map(&:to_i)
a = []
b = []
c = []
for i in 0..N-1
    a[i],b[i] = gets.split.map(&:to_i)
    c[i] = []
    c[i][0] = a[i]
    c[i][1] = b[i]
end

c.sort!{|a,b| a[0] <=> b[0]}
d = []
e = []

for i in 0..N-1

    d[i] = c[i][0]
    e[i] = c[i][1]

end

puts d[(0..N).bsearch{|n| e.slice(0..n).inject(:+) >= K}]

Measured memory_bytes: 15744
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  if(abs(a-b)<=k&&abs(a-c)<=k&&(a-d)<=k&&abs(a-e)<=k&&abs(b-c)<=k&&abs(b-d)<=k&&(b-e)<=k&&abs(c-d)<=k&&abs(c-e)<=k&&abs(d-e)<=k){
	cout<<"Yay!"<<endl; 
   }
   else{
	cout<<":("<<endl;  
   }
}


Measured memory_bytes: 256
class dice:
    def __init__(self, X):
        self.x = [0] * 6
        self.x[0] = X[0]
        self.x[1] = X[1]
        self.x[2] = X[2]
        self.x[3] = X[3]
        self.x[4] = X[4]
        self.x[5] = X[5]

    def roll(self, d):
        if d == 'S':
            self.x[0], self.x[1], self.x[4], self.x[5] = \
            self.x[4], self.x[0], self.x[5], self.x[1]
        elif d == 'E':
            self.x[0], self.x[2], self.x[3], self.x[5] = \
            self.x[3], self.x[0], self.x[5], self.x[2]
        elif d == 'W':
            self.x[0], self.x[2], self.x[3], self.x[5] = \
            self.x[2], self.x[5], self.x[0], self.x[3]
        elif d == 'N':
            self.x[0], self.x[1], self.x[4], self.x[5] = \
            self.x[1], self.x[5], self.x[0], self.x[4]

X1 = list(map(int, input().split()))
X2 = list(map(int, input().split()))
d1 = dice(X1)
d2 = dice(X2)
distances = list('NNNNWNNNWNNNENNNENNNWNNN')
b = False
for d in distances:
    d2.roll(d)
    if d1.x[0] == d2.x[0] and d1.x[1] == d2.x[1] and d1.x[2] == d2.x[2] and \
       d1.x[3] == d2.x[3] and d1.x[4] == d2.x[4] and d1.x[5] == d2.x[5]:
        b = True
        break
if b == False:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 5616
def main():
    K = int(input())
    even = 0
    odd = 0
    if K % 2 == 0:
        even = K // 2
        odd = K // 2
    else:
        even = (K - 1) // 2
        odd = K - even
    print(even * odd)


if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
# E - Yutori
N,K,C = map(int,input().split())
S = input()
L = [0]*K
R = [0]*K

i = 0
for j in range(K):
    while S[i]!='o':
        i += 1
    L[j] = i
    i += C+1

i = N-1
for j in range(K-1,-1,-1):
    while S[i]!='o':
        i -= 1
    R[j] = i
    i -= C+1
    
for j in range(K):
    if L[j]==R[j]:
        print(L[j]+1)

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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    int is[n][n];
    bool used[n][n];
    for(int i=0;i<n;++i)
    {
        for(int j=0;j<n;++j)
        {
            used[i][j]=true;
            is[i][j]=min(min(i,n-i-1),min(j,n-j-1));
        }
    }
    int ans=0;
    for(int t=0;t<n*n;++t)
    {
        int a;
        cin>>a;
        a--;
        int x=(a/n);int y=(a%n);
        used[x][y]=false;
        //cout<<is[x][y]<<" + "<<endl;
        ans+=is[x][y];
        deque <pair<int,int> > v;
        v.push_back({x,y});
        while(!v.empty())
        {
            deque <pair<int,int> > v1;
            while(!v.empty())
            {
                pair <int,int> h=v.front();
                v.pop_front();
                int x1=h.first;int y1=h.second;
                int o=0;
                if(used[x1][y1]) o=1;
                if(x1>=1 && is[x1-1][y1]>(is[x1][y1]+o))
                {
                    is[x1-1][y1]=is[x1][y1]+o;
                    v1.push_back({x1-1,y1});
                }
                if(x1<(n-1) && is[x1+1][y1]>(is[x1][y1]+o))
                {
                    is[x1+1][y1]=is[x1][y1]+o;
                    v1.push_back({x1+1,y1});
                }
                if(y1>=1 && is[x1][y1-1]>(is[x1][y1]+o))
                {
                    is[x1][y1-1]=is[x1][y1]+o;
                    v1.push_back({x1,y1-1});
                }
                if(y1<(n-1) && is[x1][y1+1]>(is[x1][y1]+o))
                {
                    is[x1][y1+1]=is[x1][y1]+o;
                    v1.push_back({x1,y1+1});
                }
            }
            v=v1;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 5812
#include <map>
#include <set>
#include <unordered_set>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <climits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>
#include <atomic>
#include <thread>

using namespace std;
typedef long long ll;
#define ln '\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define drep(i,n) int i = 0;for(;i<(n);++i)
#define FOR(i,s,e) for(int i=s;i<=(e);++i)
#define DFOR(i,s,e) int i = s;for(;i<=(e);++i)
#define FORR(i,s,e) for(int i=s;i>=(e);--i)
#define DFORR(i,s,e) int i = s;for(;i>=(e);--i)
#define fore(a, x) for(auto& a : x)
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ft first
#define sd second
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define Fill(a,b) memset(a,b,sizeof(a))
template<typename T1, typename T2> bool Max(T1& a, T2 b) { return a<b ? a = b, 1 : 0; }
template<typename T1, typename T2> bool Min(T1& a, T2 b) { return a>b ? a = b, 1 : 0; }



const int N = 200001, inf = 10000;
int d[10][10];

void solve() {
  int h, w, v;
  cin >> h >> w;
  rep(i, 10)rep(j, 10)cin >> d[i][j];
  rep(k, 10)rep(j, 10)rep(i, 10)Min(d[i][j], d[i][k] + d[k][j]);
  int ans = 0;
  rep(i, h)rep(j, w) {
    cin >> v;
    if (v != -1) {
      ans += d[v][1];
    }
  }
  cout << ans << ln;
    
}


void init() {
  
}

int main(void) {
  ios::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
  //freopen("C:\\Users\\LENOVO\\Documents\\Visual Studio 2015\\Projects\\Test\\Input\\in.in", "r", stdin);

  init();
  int TC = 1;
#if 0
  cin >> TC; cin.get();
#endif
  FOR(TI, 1, TC) {
    //cout << "Case #" << TI << ": ";
    solve();
  }
  
  
  return 0;
}



Measured memory_bytes: 256