akhauriyash/Code-Regression huggingface dataset:
/*
          Life before Death
          Strength before Weakness
          Journey before Destination
    */
    
    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define rep(i,a,n) for(ll i=a;i<n;i++)
    #define per(i,n,a) for (ll i=n;i>a;i--)
    #define te ll t; std::cin >> t; while(t--)
    #define SZ 100011
    //#define M_PI  3.141592653589793238462643383279502884L
    /*------Just DO IT--------------------------------------*/

    ll vis[500][500], a, b, n, m;
    string s[500];

    void dfs(ll x, ll y){
      vis[x][y] = 1;
      if(s[x][y] == '#') a++; else b++;
      if(x > 0 && !vis[x-1][y] && s[x][y]!=s[x-1][y]) dfs(x-1,y);
      if(x < n-1 && !vis[x+1][y] && s[x][y]!=s[x+1][y]) dfs(x+1,y);
      if(y < m-1 && !vis[x][y+1] && s[x][y]!=s[x][y+1]) dfs(x,y+1);
      if(y > 0 && !vis[x][y-1] && s[x][y]!=s[x][y-1]) dfs(x,y-1);
    }

    int solve(){
      ll ans = 0;
      cin >> n >> m;
      rep(i, 0, n) cin >> s[i];
      rep(i, 0, n) rep(j, 0, m) if(!vis[i][j]) {
        a = 0; b = 0;
        dfs(i,j);
        ans+=a*b;
      }
      cout << ans << endl;
    } 
    
   int main() {
       fastio
       solve();
    }

Measured memory_bytes: 17024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

typedef long long lint;

using namespace std;
int main(){
	int s[14]={0,14,1,2,3,4,5,6,7,8,9,10,11,12};
	int a,b;
	cin>>a>>b;
	cout<<(s[a]<s[b]?"Bob":(s[a]==s[b]?"Draw":"Alice"))<<endl;
}


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

int N,C,X;
int D[30][39];
int t[3][30];

int main(){
    cin>>N>>C;
    for(int i=0;i<C;i++){
        for(int j=0;j<C;j++){
            cin>>D[i][j];
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin>>X;
            t[(i+j)%3][X-1]++;
        }
    }
    int res=1<<30;
    for(int i=0;i<C;i++){
        for(int j=0;j<C;j++){
            if(i!=j){
                for(int k=0;k<C;k++){
                    if(i!=k && j!=k){
                        int tt=0;
                        for(int l=0;l<C;l++) tt+=D[l][i]*t[0][l];
                        for(int l=0;l<C;l++) tt+=D[l][j]*t[1][l];
                        for(int l=0;l<C;l++) tt+=D[l][k]*t[2][l];
                        if(tt<res) res=tt;
                    }
                }
            }
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 char str[3];
 int rain=1,sun=0;
 cin>>str;
 int len = strlen(str);
 for(int i = 0;i<len;i++)
 {
     if(str[i]=='R' && str[i+1]=='R')
     {
         rain++;
     }
     if(str[i]=='S')
     {
         sun++;
     }

 }
 if(rain>1)
 {
 cout<<rain<<endl;
 }
else if(sun==len)
{
    cout<<0<<endl;
}
else
{
    cout<<rain<<endl;
}
    return 0;
}



Measured memory_bytes: 3628
/* ~ CoderMehraJ ~ */
#include <bits/stdc++.h>
using namespace std;

#define show(x) cout << #x << " = " << x << '\n';

int hehe(int a){
    if(a<2) return 0;
    a*=(a-1);
    a/=2;
    return a;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    cout<<hehe(a)+hehe(b)<<endl;
    return 0;
}
//fixed<<setprecision(1)


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<vector>
#include<cstddef>
#include<algorithm>
#include<cmath>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
vector<usize> enum_divisors(usize N) {
    vector<usize> res;
    for (usize i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            if (N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i32 n;
cin >> n;
i32 ans = 0;
for(i32 i = 1; i <= n; i++){
    for(i32 j = 1; i * j < n; j++){
        ans++;
    }
}
cout << ans << endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

int main()
{
  string s;
  ll ans;

  cin >> s;

  ans = 0;
  if (s[0] == 'R') ans = 1;
  for (int i=1; i<3; i++) {
    if (s[i] == 'R') {
      if (s[i-1] == 'R') ans++;
      else ans = 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int[] v = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        int[] c = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        int ans = 0;
        for (int i = 0; i < n; i++)
        {
            if (0 < v[i] - c[i]) ans += (v[i] - c[i]);
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13268
#include<bits//stdc++.h>
using namespace std;
int n,i,x,c;
map<string,int>S;
int main()
{
  cin>>n;
  for(i=0;i<n;i++)
  {
    string s;cin>>c>>s;
    if(c==0){
      cin>>x;S[s]=x;
    }
    else cout<<S[s]<<endl;
  }
}


Measured memory_bytes: 27840
import numpy as np
from scipy.ndimage.morphology import distance_transform_cdt

h, w = map(int, input().split())
a = [input() for _ in range(h)]

a = np.array([[(ai[j] != "#") for j in range(w)] for ai in a])
d = distance_transform_cdt(a, metric="taxicab").max()
print(d)


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

class Combination{
	private:
		const static long long MOD = 1e9+7;
		const static long long MAX = 1110000;
		vector<long long> fact;
		vector<long long> finv;
		vector<long long> inv;
	public:
		Combination() : fact(MAX),finv(MAX),inv(MAX){
			fact[0] = fact[1] = 1;
			finv[0] = finv[1] = 1;
			inv[1] = 1;
			for(int i=2;i<MAX;i++){
				fact[i] = fact[i-1] * i % MOD;
				inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
				finv[i] = finv[i-1] * inv[i] % MOD;
			}
		}

		long long nCk(long long n,long long k){
			if(n<k) return 0;
			if(n<0 || k<0) return 0;
			return fact[n] * (finv[k] * finv[n-k] % MOD) % MOD;
		}
};


long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
const int mod = 1e9+7;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x,y;
    cin >> x >> y;
    if(x<y) swap(x,y); //xが大きい
    int tx = x;
    int ty = y;
    ll total_mov = (x+y)/3;
    if((x+y)%3 != 0){
        cout << 0 << endl;
        return 0;
    }
    ll cnt = 0; //yが2の方の数
    while(tx != 2*ty && ty >= 0){
        tx--; ty-=2;
        cnt++;
    }
    if(ty<0){
        cout << 0 << endl;
        return 0;
    }
    Combination c;
    cout << c.nCk(total_mov,cnt) << endl;
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int k, n;
  cin >> k >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  int mx = 0;
  int len;
  rep(i, n - 1) {
    len = a[i + 1] - a[i];
    maxs(mx, len);
  }
  len = a[0] + (k - a[n - 1]);
  maxs(mx, len);
  cout << k - mx << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

int main(){
	string str_input;
	int num_str_input;
	
	cin >> str_input;
	num_str_input = str_input.size();
	
	for(int i=0;i<num_str_input;i++){
		cout << "x";
	}
	cout << endl;
	
	return 0;
}

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

using namespace std;
using ll = long long;

int init();
int solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#define MOD 1000000007
#define PI 3.141592653589793238462643383

signed main()
{
	init();
	solve();
}

string s;

int init()
{
	cin >> s;
}

bool ch(string st)
{
	rep(i, st.length()) {
		if (st[i] != st[0]) return false;
	}
	return true;
}

int culc(string st, char c)
{
	string res = "";
	if (ch(st)) return 0;
	rep(i, st.length()-1) {
		res += st[i] == c || st[i+1] == c ? c : st[i];
	}
	return culc(res, c) + 1;
}

int solve()
{
	string t = s;
	UNIQUE(t);
	int res = 10000;
	for (char c : t) {
		res = min(res, culc(s, c));
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

	int x, y;
	scanf("%d %d", &x, &y);

	if (x < y)
		swap(x, y);

	while (y > 0) {
		int r = x % y;
		x = y;
		y = r;
	}
	cout << x << endl;

	return 0;
}

Measured memory_bytes: 3204
N = int(input())
n = list(map(int,input().split()))
costlist = []
for i in range(min(n)-1,max(n)+1):
    cost = 0
    for j in range(N):
        cost += (n[j] - i )**2
    costlist.append(cost)
ans = min(costlist)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include<iomanip>
using namespace std;

long long N, K;

int main() {
    cin >> N >> K;
    
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    
    long long left = A[0] > 0 ? A[0] * A[1] : A[0] * A[N - 1], right = max(A[0] * A[1], A[N - 2] * A[N - 1]) + 1;
    while(right - left > 1) {
        long long mid = (left + right) / 2;
        long long count = 0;
        for (int i = 0; i < N; i++) {
            if (A[i] > 0) {
                long long l = -1, r = N;
                while (r - l > 1) {
                    long long m = (r + l) / 2;
                    A[i] * A[m] < mid ? l = m : r = m;
                }
                count += l + 1;
                if (l >= i) count--;
            } else if (A[i] < 0) {
                long long l = -1, r = N;
                while (r - l > 1) {
                    long long m = (r + l) / 2;
                    A[i] * A[m] < mid ? r = m : l = m;
                }
                count += N - r;
                if (r <= i) count--;
            } else {
                count += 0 < mid ? N - 1 : 0;
            }
        }
        count /= 2;
        count < K ? left = mid : right = mid;
    }
    cout << left << endl;
}


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

lint a[2000010],n;

int main(){
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	lint result=0,cur=0,r=0;
	for(int i=0;i<n;i++){
		while(r<n&&(cur&a[r])==0){
			cur^=a[r];r++;
		}
		cur^=a[i];
		result+=r-i;
	}
	cout<<result<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int a,b,c;
  cin >> a>>b>>c;
  cout << max({a,b,c})*9+a+b+c << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    int n;cin>>n;
    vi h(n);
    int m=0;
    rep(i,n){
        cin>>h[i];
        m=max(h[i],m);
    }
    int cnt=0;
    for(int i=1;i<=m;++i){
        bool a=false;
        rep(j,n){
            if(h[j]>=i){
                a=true;          
            }
            if(a&&h[j]<i){
                cnt++;
                a=false;
            }
        }
        if(a)cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
N = parseInt(readline())
A = parseMap(split(readline()))
sort!(A)
res = 1
if A[1] == 0
    println(0)
else
    for a in A
        if a > (10^18 ÷ res)
            res = -1
            break   
        else
            res *= a
        end
    end
    println(res)    
end

end

main()

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

constexpr int inf = 0x3f3f3f3f;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  vector<int> ij;
  int sij, tij;
  for (int i = 0; i < h; ++i) {
    cin >> s[i];
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == 'a') {
        ij.push_back(i * w + j);
      }
      if (s[i][j] == 's') {
        sij = i * w + j;
      }
      if (s[i][j] == 'e') {
        tij = i * w + j;
      }
    }
  }
  int m = ij.size();
  vector< vector<int> > dist(m, vector<int>(h * w, inf));
  for (int t = 0; t < m; ++t) {
    int si = ij[t] / w, sj = ij[t] % w;
    queue< pair<int, int> > que;
    dist[t][ij[t]] = 0;
    que.emplace(si, sj);
    while (not que.empty()) {
      int i, j;
      tie(i, j) = que.front();
      que.pop();
      for (int di : {-1, 0, 1}) {
        for (int dj : {-1, 0, 1}) {
          if (abs(di) + abs(dj) == 1) {
            int ni = i + di, nj = j + dj;
            if (ni < 0 or ni >= h or nj < 0 or nj >= w or s[ni][nj] == '#') {
              continue;
            }
            if (dist[t][ni * w + nj] == inf) {
              dist[t][ni * w + nj] = dist[t][i * w + j] + 1;
              que.emplace(ni, nj);
            }
          }
        }
      }
    }
  }
  vector< vector<int> > dp(m, vector<int>(1 << m, inf));
  for (int t = 0; t < m; ++t) {
    dp[t][1 << t] = dist[t][sij];
  }
  auto chmin = [](auto&& l, auto r) { l = min(l, r); };
  for (int x = 0; x < 1 << m; ++x) {
    for (int t = 0; t < m; ++t) {
      if (dp[t][x] == inf) {
        continue;
      }
      for (int to = 0; to < m; ++to) {
        if (x >> to & 1) {
          continue;
        }
        chmin(dp[to][x | 1 << to], dp[t][x] + dist[t][ij[to]]);
      }
    }
  }
  int res = inf;
  for (int t = 0; t < m; ++t) {
    for (int x = 0; x < 1 << m; ++x) {
      if (__builtin_popcount(x) >= k) {
        res = min(res, dp[t][x] + dist[t][tij]);
      }
    }
  }
  cout << (res < inf ? res : -1) << '\n';
}



Measured memory_bytes: 168208
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

struct edge {
    int v;
    double w;
    edge() {}
    edge(int v, double w) : v(v), w(w) {};
};

vector<double> dijkstra(int n, vector<vector<edge> >& G, int s) {
    vector<double> d(n, 1e18); d[s] = 0;
    priority_queue<pair<ll, int> > que;
    que.push(make_pair(0ll, s));
    while (!que.empty()) {
        auto p = que.top(); que.pop();
        int u = p.second;
        ll dist = -p.first;
        if (dist > d[u]) continue;
        for (edge e : G[u]) {
            if (d[e.v] > d[u]+e.w) {
                d[e.v] = d[u] + e.w;
                que.push(make_pair(-d[e.v], e.v));
            }
        }
    }
    return d;
}

const int MAXN = 1010;
int X[MAXN], Y[MAXN], R[MAXN];

int main() {
	int xs, ys, xt, yt;
	cin >> xs >> ys >> xt >> yt;
	int N;
	cin >> N;
	X[0] = xs;
	Y[0] = ys;
	X[N+1] = xt;
	Y[N+1] = yt;
	for (int i = 1; i <= N; i++) {
		cin >> X[i] >> Y[i] >> R[i];
	}
	N += 2;
	vector<vector<edge> > G(N);
	for (int i = 0; i < N; i++) {
		for (int j = i+1; j < N; j++) {
			double dx = X[i]-X[j];
			double dy = Y[i]-Y[j];
			double d = sqrt(dx*dx+dy*dy);
			if (d < R[i] + R[j]) {
				G[i].emplace_back(j, 0);
				G[j].emplace_back(i, 0);
			} else {
				G[i].emplace_back(j, d-R[i]-R[j]);
				G[j].emplace_back(i, d-R[i]-R[j]);
			}
		}
	}
	auto d = dijkstra(N, G, 0);
	printf("%.10lf\n", d[N-1]);
	return 0;
}


Measured memory_bytes: 20720
#include <bits/stdc++.h>
#include <ctime>
#include <unordered_map>
#include <stdlib.h>
using namespace std;
#define ll  long long int
#define mod 1000000007
#define modd 998244353
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// #include<boost/multiprecision/cpp_int.hpp>
// using boost ::multiprecision::cpp_int;
/*__builtin_clz();
__builtin_ctz();
__builtin_popcount();*/
ll n;
ll a[100001],b[100001],c[100001];
ll dp[100002][4];
ll fun(ll cnt ,char x)
{
    if(cnt == n+1)
    {
        return 0;
    }
    ll k;
    if(x=='A') k=1;
    else if(x=='B') k=2;
    else k=3;
    if(dp[cnt][k] != -1)
    {
        return dp[cnt][k];
    }
    ll z,y;
    if(x=='A')
    {
       z= a[cnt]+ fun(cnt+1,'B');
       y= a[cnt] + fun(cnt+1,'C');
    }
    if(x=='B')
    {
        z= b[cnt] + fun(cnt+1,'C');
        y= b[cnt] + fun(cnt+1,'A');
    }
    if(x=='C')
    {
        z = c[cnt] + fun(cnt+1,'A');
        y= c[cnt] + fun(cnt+1,'B');
    }
    return dp[cnt][k] =  max(z,y);
}
int main()
{
    boost;
    memset(dp,-1,sizeof dp); 
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
   ll x =  fun(1,'A');
   ll y = fun(1,'B');
   ll z =  fun(1,'C');
   cout<<max(x,max(y,z))<<"\n";
    cerr << "\nTime elapsed: " << 1000 * clock()/CLOCKS_PER_SEC << "ms\n";
}
/* AnsHuman_7 || Anshuman Gaur */


Measured memory_bytes: 10368
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

int main()
{
	int N;
	while (cin >> N, N)
	{
		vector<vector<int>>data;
		data.resize(N + 1);
		for (size_t i = 0; i < N+1; i++)
		{
				data[i].resize(N + 1);
			if (i != N)
			{
				for (size_t j = 0; j < N; j++)
				{
					cin >> data[i][j];
					data[i][N] += data[i][j];
				}
			} else
			{
				for (size_t j = 0; j < N+1; j++)
				{
					for (size_t k = 0; k < N; k++)
					{
						data[i][j] += data[k][j];
					}
				}
			}
		}
		for (auto x : data)
		{
			for (auto y : x)
			{
				cout << setw(5) << y;
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1228
#include <stdio.h>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int,int>  pi;
#define F first
#define S second
#define PB push_back
const int N=1e3+10;
const int INF=1e9+10;
int main(){
    int n,m,s,l,r,c,cnt=0,dis[N];
    bool went[N];
    vector<pi> graph[N];
    pi nxt;
    queue<pi> q;
    scanf("%d%d%d",&n,&m,&s);
    for(int i=0;i<n;i++){
        went[i]=false;
        dis[i]=INF;
    }
    dis[s]=0;
    while(m--){
        scanf("%d%d%d",&l,&r,&c);
        graph[l].PB({r,c});
    }
    q.push({s,0});
    while(!q.empty()){
        if(cnt>N*N){
            printf("NEGATIVE CYCLE\n");
            return 0;
        }
        cnt++;
        nxt=q.front();
        q.pop();
        if(nxt.S>dis[nxt.F]||went[nxt.F])continue;
        went[nxt.F]=true;
        for(pi i:graph[nxt.F])if(nxt.S+i.S<dis[i.F]){
            dis[i.F]=nxt.S+i.S;
            went[i.F]=false;
            q.push({i.F,dis[i.F]});
        }
    }
    for(int i=0;i<n;i++){
        if(dis[i]==INF)printf("INF\n");
        else printf("%d\n",dis[i]);
    }
}


Measured memory_bytes: 2784
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    int n, m;
    cin >> n >> m;
    vector< vi > g(n);
    vi sign(n, -1);
    sign[0] = 0;
    for(int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    // bfs
    queue<int> q;
    q.push(0);
    while(!q.empty()) {
        int f = q.front();
        q.pop();
        for(const auto& viz : g[f]) {
            if(sign[viz] == -1) {
                sign[viz] = f + 1;
                q.push(viz);
            }
        }
    }
    bool ok = true;
    for(int i = 1; i < n; ++i) if(sign[i] == -1) ok = false;
    if(!ok) cout << "No\n";
    else {
        cout << "Yes\n";
        for(int i = 1; i < n; ++i) cout << sign[i] << '\n';
    }
    return 0;
}



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

int main() {
  int n, k;
  cin >> n >> k;
  int a[10] = {0};
  for (int i = 0; i < k; i++) {
    int x;
    cin >> x;
    a[x] = 1;
  }

  int i = n;
  while (true) {
    int x = i;
    bool flag = true;
    while (x) {
      int d;
      d = x % 10;
      if (a[d] == 1) {
        flag = false;
        break;
      }
      x /= 10;
    }
    if (flag) {
      cout << i << endl;
      break;
    }
    i++;
  }

  return 0;

}


Measured memory_bytes: 256
///スマホコーディング
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
typedef long long ll;
const int inf=1e9;
int main(){
  int n,i; cin>>n>>i;
  cout<<n-i+1<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int[][] a = new int[n][2];
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt(), l = sc.nextInt();
			a[i][0] = x - l;
			a[i][1] = x + l;
		}
		Arrays.sort(a, (x, y) -> Integer.compare(x[0], y[0]));
		int ans = 0;
		int last = Integer.MIN_VALUE;
		for (int[] interval : a) {
			int l = interval[0], r = interval[1];
			if (l >= last) {
				last = r;
			}else {
				ans++;
				last=Math.min(last, r);
			}
		}
		out.println(n-ans);
		out.close();

	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		boolean ready() throws IOException {
			return br.ready();
		}

	}

	static void sort(int[] a) {
		shuffle(a);
		Arrays.sort(a);
	}

	static void shuffle(int[] a) {
		int n = a.length;
		Random rand = new Random();
		for (int i = 0; i < n; i++) {
			int tmpIdx = rand.nextInt(n);
			int tmp = a[i];
			a[i] = a[tmpIdx];
			a[tmpIdx] = tmp;
		}
	}

}

Measured memory_bytes: 46124
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define add(a,b) if ((a+=b)>=998244353)a-=998244353

int main() {
    ll N, S, ans = 0; cin >> N >> S;
    vl dp(3001, 0);
    rep(i,N) {
        ll a; scanf("%ld",&a);
        vl ndp(3001, 0);
        ndp[0] = ndp[a] = 1;
        rep(j,3001) {
            add(ndp[j], dp[j]);
            if (j+a > S) continue;
            add(ndp[j+a], dp[j]);
        }
        add(ans, ndp[S]);
        dp = ndp;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main (){
  int a,b;
  while(1){
    scanf("%d",&a);
    if(a == 0)break;
    scanf("%d",&b);
     for(int i=1;i<=a;i++){
       for(int h=1;h<=b;h++){
	 if(i%2==1 ){
	   if(h%2==1)printf("#");
	   else printf(".");
	 }
	 if(i%2==0){
	   if(h%2==0)printf("#");
	 else printf(".");
	 }
       }
       printf("\n");
     }
     printf("\n");
  }
  return 0;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

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

    for (int x = 0; x <= N; ++x)
    {
        for (int y = 0; y <= N - x; ++y)
        {
            int z = N - x - y;
            int sum = 10000 * x + 5000 * y + 1000 * z;
            if (sum == Y)
            {
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int dp[105][105]={};
  int n,a,b,c;
  cin >> n >> a >> b >> c;
  int i,j,k;
  int cal[n];
  for(i=0;i<n;i++) cin >> cal[i];
  dp[0][0]=c;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(dp[i][j]==0) continue;
      dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
      dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+cal[i]);
    }
  }
  int ans=0;
  for(i=0;i<n;i++){
    ans=max(ans,dp[n][i]/(a+b*i));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
#include <queue>
#include <deque>
#define int long long
using namespace std;
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, ai;
    cin >> n;
    vector<int> data;
    for (int i=0; i < n; i++){
        cin >> ai;
        data.push_back(ai);
    }
    int num = 0;
    int ans = 0;
    while (num < n){
        if (data[num] != num + 1){
            num++;
        }
        else{
            ans++;
            num += 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
input = readlines()

n, m, x = input.shift.chomp.split("\s").map{|x| x.to_i}

list = [] #[book][arg]
price = {}
(1..n).each do |i|
  vals = input.shift.chomp.split("\s").map{|x| x.to_i}
  list[i] = [] if list[i].nil?
  vals.each_with_index do |v, i2|
    if i2 == 0
      price[i] = v
      next
    end
    list[i][i2] = v
  end
end

def addBook(current)
  res = []
  current.each do |c|
    c1 = c.clone.push(0)
    c2 = c.clone.push(1)
    res.push(c1)
    res.push(c2)
  end

  res
end

book_patterns = [[0], [1]]
(2..n).each do |i|
  book_patterns = addBook(book_patterns)
end

min = nil
book_patterns.each do |pat|
  total = 0
  args = Array.new(m)
  pat.each_with_index do |tf, i|
    next if tf == 0
    total += price[i + 1]
    list[i + 1].each_with_index do |v, i2|
      next if v.nil?
      args[i2] = 0 if args[i2].nil?
      args[i2] += v
    end
  end
  is_ok = true
  (1..m).each do |i3|
    is_ok = false if args[i3].nil? || args[i3] < x
  end
  next unless is_ok
  min = total if min.nil? || min > total
end

puts min.nil? ? '-1' : min


Measured memory_bytes: 16960
/*
  AtCoder Beginner Contest 105
  D - Candy Distribution
*/

#include<iostream>
#include<unordered_map>
using namespace std;

long long N, M, A;
unordered_map<long long, long long> hm; // mod Mが同じになる累積和の数

int main() {
  scanf("%lld %lld", &N, &M);

  long long buf = 0;
  hm[0] = 1;
  for (int i = 0; i < N; ++i) {
    scanf("%lld", &A);
    
    long long mod = (buf + A) % M;

    auto itr = hm.find(mod);
    if (itr != hm.end()) itr->second += 1;
    else hm[mod] = 1;  

    buf += A;
  }

  long long cnt = 0;
  for (auto itr = hm.begin(); itr != hm.end(); ++itr) {
    cnt += itr->second * (itr->second - 1) / 2LL;
  }

  printf("%lld\n", cnt);
  return 0;
}

Measured memory_bytes: 3596
import java.util.*;
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long a[]=new long[n];
    for(int i=0;i<n;i++){
      a[i]=sc.nextLong();
    }
    int c =0;int ans=0;
    for(int i=0;i<n-1;i++){
      if(a[i]>=a[i+1]){
        
        c++;
        if(c>ans) ans=c;
      }
      else
        c=0;
    }
    System.out.println(ans);
  }
}
    


Measured memory_bytes: 62168
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int t,k,n,sum=0;
   cin>>t>>k;
   int ar[t];
   for(int i=0;i<t;i++){
     cin>>ar[i];
   }
	n = sizeof(ar)/sizeof(ar[0]);
    sort(ar,ar+n);
   for(int j=0;j<k;j++){
     sum = sum + ar[j];
   }
   cout << sum <<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	string s;
	cin >> s;
	while(!s.empty()){
//cout << s << endl;
//cout << s.length() << endl;
		if(s.substr(s.length()-3,3)=="eam"){
			if(s.substr(s.length()-5,5)!="dream"){
				cout << "NO" << endl;
				return 0;
			}
			s.erase(s.begin()+s.length()-5,s.end());
		}else if(s.substr(s.length()-3,3)=="mer"){
			if(s.substr(s.length()-7,7)!="dreamer"){
				cout << "NO" << endl;
				return 0;
			}
			s.erase(s.begin()+s.length()-7,s.end());
		}else if(s.substr(s.length()-3,3)=="ase"){
			if(s.substr(s.length()-5,5)!="erase"){
				cout << "NO" << endl;
				return 0;
			}
			s.erase(s.begin()+s.length()-5,s.end());
		}else if(s.substr(s.length()-3,3)=="ser"){
			if(s.substr(s.length()-6,6)!="eraser"){
				cout << "NO" << endl;
				return 0;
			}
			s.erase(s.begin()+s.length()-6,s.end());
		}else{
			cout << "NO" << endl;
			return 0;
		}

	}
	cout << "YES" << endl;
}

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

int main()
{
	while (true)
	{
		int h, w;
		cin >> h >> w;
		if (h == 0 && w == 0)
		{
			break;
		}

		for (int i = 0; i < h; i++)
		{
			bool flag = (i % 2 == 0) ? true : false;
			for (int j = 0; j < w; j++)
			{
				string s = (flag) ? "#" : ".";
				cout << s;
				flag = !flag;
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3120
N = int(input())
A = list(map(int,input().split()))
ans = "Yes"
if N % 3 != 0:
  if len(set(A)) != 1 or list(set(A))[0] != 0:
    ans = "No"
  print(ans)
else:
  if len(set(A)) == 1:
    if list(set(A))[0] != 0:
      ans = "No"
  elif len(set(A)) == 2:
    if A.count(0) != N // 3:
      ans = "No"
  elif len(set(A)) == 3:
    A_s = list(set(A))
    for a in A_s:
      if A.count(a) != N // 3:
        ans = "No"
      elif A_s[0] ^ A_s[1] ^ A_s[2] != 0:
        ans = "No"
  else:
    ans = "No"
  print(ans)

Measured memory_bytes: 14116
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int num[1000];
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		scanf("%d",num+i);
	}
	int cost=1000000;	
	for(int i=-200;i<=200;i++)
	{
		int be=0;
		for(int j=0;j<n;j++)
		{
			be+=(i-num[j])*(i-num[j]);
		}
		cost=min(cost,be);
	 }
	 cout<<cost;
 } 

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<int> d;
    vector<char> ans;
    for (int q = 0; q < n; q++){
        string s;
        cin >> s;
        if (s == "AB"){
            d.push_back(0);
        }else if (s == "AC"){
            d.push_back(1);
        }else{
            d.push_back(2);
        }
    }
    for (int q = 0; q < n; q++){
        if (d[q] == 0){
            if (a > b){
                a--, b++;
                ans.push_back('B');
            }else if (a < b){
                a++, b--;
                ans.push_back('A');
            }else{
                if (a == 0){
                    cout << "No" << endl;
                    return 0;
                }
                if (q == n-1 || d[q+1] != 2){
                    ans.push_back('A');
                    a++, b--;
                }else{
                    ans.push_back('B');
                    a--, b++;
                }
            }
        }else if (d[q] == 1){
            if (a > c){
                a--, c++;
                ans.push_back('C');
            }else if (a < c){
                a++, c--;
                ans.push_back('A');
            }else{
                if (a == 0){
                    cout << "No" << endl;
                    return 0;
                }
                if (q == n-1 || d[q+1] != 2){
                    ans.push_back('A');
                    a++, c--;
                }else{
                    ans.push_back('C');
                    a--, c++;
                }
            }
        }else{
            if (c > b){
                c--, b++;
                ans.push_back('B');
            }else if (c < b){
                c++, b--;
                ans.push_back('C');
            }else{
                if (b == 0){
                    cout << "No" << endl;
                    return 0;
                }
                if (q == n-1 || d[q+1] != 1){
                    ans.push_back('B');
                    b++, c--;
                }else{
                    ans.push_back('C');
                    b--, c++;
                }
            }
        }
    }
    cout << "Yes" << endl;
    for (char w: ans){
        cout << w << endl;
    }
    return 0;
}


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

using namespace std;

const int MAXN = 2 * 1e3 + 1;

int d[MAXN][MAXN];

int x, y;

bool used[MAXN];

vector <int> g[MAXN];

void bfs(int s)
{
    queue<int> q;
q.push (s);
used[s] = true;
while (!q.empty()) {
	int v = q.front();
	q.pop();
	for (size_t i=0; i<g[v].size(); ++i) {
		int to = g[v][i];
		if (!used[to]) {
			used[to] = true;
			q.push (to);
			d[s][to] = d[s][v] + 1;
		}
	}
}
}

int main()
{
    int n, x, y;
    cin >> n >> x >> y;
    for(int i = 2; i <= n; i++)
    {
        g[i].push_back(i - 1);
        g[i - 1].push_back(i);
    }
    g[x].push_back(y);
    g[y].push_back(x);
    for(int i = 1; i <= n; i++)
            d[i][i] = 0;
    for(int i = 1; i <= n; i++)
    {
        bfs(i);
        fill(used, used + n + 1, false);
    }
    int ans[n + 1];
    fill(ans, ans + n + 1, 0);
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            ans[d[i][j]]++;
        }
    }
    for(int i = 1; i <= n - 1; i++)
    {
        cout << ans[i] / 2 << "\n";
    }
    return 0;
}


Measured memory_bytes: 16000
# -*- coding: utf-8 -*-
x = int(input())
ans = 0
"""
tmp = 0
tmp2 = 0
for i in [6,5,4,3,2,1]:
    tmp = int(x/i)
    if tmp < 0:
        continue
    else:
        ans = tmp
        x -= i*tmp
        tmp2 = i - 1
        break
"""

if x%11 == 0:
    ans = int(x/11)*2
elif x%11 <= 6:  
    ans = int(x/11)*2 + 1
else:
    ans = int(x/11)*2 + 2
    
print(ans)

Measured memory_bytes: 3192
module AOJ_Volume0103;

import std.stdio,std.string,std.conv;

int main()
{
	int n = readln.chomp.to!int;
	while(n--)
	{
		int _out = 0;
		int home[4];
		foreach(i;0..4) home[i] = 0;

		while(_out != 3)
		{
			string s = readln.chomp;

			if(s == "OUT")
			{
				_out++;
			}
			else if(s == "HIT")
			{
				if(home[2] == 1)
				{
					home[2]--;
					home[3]++;
				}
				if(home[1] == 1)
				{
					home[1]--;
					home[2]++;
				}
				if(home[0] == 1)
				{
					home[0]--;
					home[1]++;
				}
				
				home[0]++;
			}
			else if(s == "HOMERUN")
			{
				foreach(i;0..3)
				{
					if(home[i] == 1)
					{
						home[i]--;
						home[3]++;
					}
				}
				home[3]++;
			}
		}
		home[3].writeln;
	}
	return 0;
}

Measured memory_bytes: 1052
#include<iostream>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>

using coord = std::pair<int, int>;

double distance(coord x, coord y){
    int dist = (x.first - y.first) * (x.first - y.first);
    dist += (x.second - y.second) * (x.second - y.second);
    return std::sqrt(dist);
}

int main(){
    int N;
    std::cin >> N;
    std::vector<coord> xy(N);
    for(int i = 0; i < N; i++) std::cin >> xy[i].first >> xy[i].second;

    std::vector<int> order(N);
    for(int i = 0; i < N; i++) order[i] = i;

    double length = 0.0;
    int cnt = 0;
    do{
        cnt++;
        for(int i = 0; i < N - 1; i++){
            length += distance(xy[order[i]], xy[order[i + 1]]);
        }
    }while(std::next_permutation(order.begin(), order.end()));


    printf("%.7f\n", length / cnt);
    return 0;
}

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

using namespace std;

int main() {
	int v[4], v2[4];


	for (int i = 0; i < 3; ++i) {
		scanf("%d", &v[i]);
	}

	int cnt = 0;
	if (v[0] == v[1] && v[1] == v[2]) {
		if (v[0] % 2 == 1) {
			puts("0");
		} else {
			puts("-1");
		}
	}
	else {
	 	while(1) {
			sort(v, v+3);
			int ok = 0;
			for (int i = 0; i < 3; ++i) {
				if	(v[i] % 2 == 1) {
					ok = 1;
				}
			}
			if (ok) break;
			for (int i = 0; i < 3; ++i) {
				v2[i] = (v[(i+1)%3] + v[(i+2)%3])/ 2;
			}

			for (int i = 0; i < 3; ++i) {
				v[i] = v2[i];
			}
			cnt++;
		}
		printf("%d\n", cnt);
	}



}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<int,vector<int>,greater<int>> que;


llint a,b;

void solve(){
	cin >> a >> b;
	if(a>0 && b>0)cout << "Positive" << endl;
	else if(a<=0 && b>=0)cout << "Zero" << endl;
	else{
		if(abs(a-b)%2==0)cout << "Negative" << endl;
		else cout << "Positive" << endl;
	}
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
/*
	@author: cheerioskun
*/
#pragma GCC target("popcnt")
#include "bits/stdc++.h"
#define f first
#define sc second
#define pb push_back
#define MOD 1000000007L
#define inf 0x3f3f3f3f
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long int ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
using namespace std;

int a[102], dp[100005];

int main(){
	fast_io
	int N, K;
	cin>>N>>K;
	set<int> present;
	for(int i = 0;i < N; ++i){
		cin>>a[i];
		present.insert(a[i]);
	}
	// DP[i] holds 'Does player 0 lose when i stones are left'
	for(int i = 0;i <= K; ++i){
		dp[i] = 1;
	}
	for(int i = 1;i <= K; ++i){
		bool flag = false;
		for(int j = 0;j < N && a[j] <= i && !flag; ++j){
			if(dp[i - a[j]] == 1){
				dp[i] = 0;
				flag = true;
			}
		}
	}
	cout<<(dp[K]?"Second":"First")<<endl;
	#ifndef ONLINE_JUDGE
    	cout<<"Time Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}



Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = INT_MAX;
  vi wh(n+1,0),bl(n+1,0);
  int sumw = 0;
  REP(i,n){
    if(s[i]=='.')sumw++;
    wh[i+1] = sumw;
    bl[i+1] = i+1-sumw;
  }
  REP(i,n+1){
    int tm = wh[n]-wh[i]+bl[i]-bl[0];
    mins(ans, tm);
  }
  cout << ans << endl;
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

int main(){
    long long n;
    cin>>n;
    long long a[n];
    rep(i,n)cin>>a[i];
    /*
    long long s[n+1];
    s[0]=0;
    rep(i,n)s[i+1]=s[i]+a[i];
    */

    int right=0;

    long long sum=0;
    long long ans=0;
    long long tmp=0;
    for(int left=0;left<n;left++){
        while((sum+a[right]==(sum^a[right])) &&right<n){
            sum+=a[right];
            right++;
        }
        ans+=right-left;
        //cout<<left<<" "<<right<<" "<<ans<<endl;
        sum-=a[left];
        //ans++;
    }

    cout<<ans<<endl;
    return 0;

}
/*


*/


Measured memory_bytes: 1792
#include <stdio.h>
int tmp;
int gcd(int a, int b){
  int r = a%b;
  if(r==0)return b;
  else return gcd(b, r);
}

int main(){
  int k,t;
  scanf("%d", &k);
  int ans=0;
  int i,j,l;
  for(i=1;i<k+1;i++){
    for(j=1;j<k+1;j++){
      for(l=1;l<k+1;l++){
        t=gcd(i, j);
        ans+=gcd(t, l);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1724
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

int main() {
    int a, b,c;
    cin >> a >> b >> c;
    priority_queue<int, vector<int>, greater<int> > q;
    q.push(a);
    q.push(b);
    q.push(c);

    int s= q.top(); q.pop();
    int x = q.top(); q.pop();
    int y = q.top(); q.pop();
    cout << abs(s-x) + abs(y-x) << endl;


    return 0;
}


Measured memory_bytes: 256
#import sys
#input=sys.stdin.readline()
#print(input)

#import pprint
h,w = map(int,input().split())
s = [list(input())for i in range(h)]
#print("s")
#pprint.pprint(s,width=w*10)

visited = [[0 for i in range(w)] for j in range(h)]#sと同じ形に0を配置した表
quene = []#移動元Nowとなることができる座標のリスト
ans = 0

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            quene.append([i,j])#スタート地点をQueneに追加
            visited[i][j]=1#スタート地点を1にする
#            print("visited")
#            pprint.pprint(visited,width=w*10)
#            print(quene)

            dy_dx=[[1,0],[-1,0],[0,1],[0,-1]]#１回に移動出来る量

            while len(quene)>=1:
                now=quene.pop(0)#queneの左端の項を取り出す
#                print(now)
                for k in range(4):
                    y=now[0]+dy_dx[k][0]#nowから移動先[x,y]へのy軸方向の移動量
                    x=now[1]+dy_dx[k][1]#nowから移動先[x,y]へのx軸方向の移動量
                    if 0<=y<h and 0<=x<w:#移動先が表を飛び出していなければOK
                        if s[y][x]!="#" and visited[y][x]==0:#移動先が壁でない、かつ行ったことがなければOK
                            visited[y][x]=visited[now[0]][now[1]]+1#移動先の値をNowの値+1にする
                            quene.append([y,x])#Queneに移動先座標を追加
#                           pprint.pprint(visited,width=w*10)
#       一つのスタート地点から幅優先探索を終わらせたら、移動量の最大値を求める
        for l in range(h):
            for m in range(w):
                ans = max(ans,visited[l][m])#これまでの最大値と今回得られた移動量の最大値を比較し、大きいほうを新しい答えにする
        visited = [[0 for i in range(w)] for j in range(h)]#visited初期化
print(ans-1)

Measured memory_bytes: 9228