akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    int ans = 0;
    int times = min(N, K);
    for (int t = 1; t <= times; t++) {
        for (int l = 0; l <= t; l++) {
            int r = t - l;
            vector<int> onHand;
            onHand.insert(onHand.end(), a.begin(), a.begin() + l);
            onHand.insert(onHand.end(), a.rbegin(), a.rbegin() + r);
            sort(onHand.begin(), onHand.end());
            int sum = 0;
            int remainingTimes = K - t;
            for (int i = 0; i < onHand.size(); i++) {
                if (i < remainingTimes && onHand[i] < 0) continue;
                sum += onHand[i];
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>

using namespace std;
int n;
unsigned long long ans;
bool p[5][5];
bool visited[5];
int visited_cnt = 1;

bool can(int v) {
  if (visited_cnt == 4) {
    return true;
  }

  visited[v] = true;
  bool good = false;
  for (int i = 1; (i <= 4) && !good; i++) {
    if (!visited[i] && p[v][i]) {
      visited_cnt++;
      good = can(i);
      visited_cnt--;
    }
  }
  visited[v] = false;
  return good;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int x,y;
  for (int i = 0; i < 3; i++) {
    cin >> x >> y;
    p[x][y] = p[y][x] = true;
  }

  if (can(1) || can(2) || can(3) || can(4)) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}


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

int N, a[110];

int main()
{
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		std::cin >> a[i];
	}

	int ans = 100000000;
	int temp;
	for (int ave = -100; ave <= 100; ave++) {
		temp = 0;
		for (int i = 0; i < N; i++)
			temp += (ave - a[i])*(ave - a[i]);
		ans = std::min(temp, ans);
	}

	std::cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#define llint long long
#define mod 1000000007

using namespace std;

llint n, x, y, z;
llint s, S;
llint memo[45][1<<16];
bool ng_state[1<<16][15];
llint next_state[1<<16][15];

string parse(llint state)
{
	string ret;
	int cnt = 0;
	for(int i = 0; i < s; i++){
		cnt++;
		if(state & (1LL<<i)){
			ret += cnt + '0';
			cnt = 0;
		}
	}
	return ret;
}

llint rparse(string str)
{
	llint ret = 0;
	llint sum = 0;
	for(int i = 0; i < str.size(); i++){
		sum += str[i] - '0';
		ret |= (1<<(sum-1));
	}
	return ret;
}

string trunc(string str)
{
	llint sum = 0;
	for(int i = str.size()-1; i >= 0; i--){
		sum += str[i] - '0';
		if(sum > s) return str.substr(i+1);
	}
	return str;
}

bool check(string str)
{
	int st = 0;
	int sum = 0;
	for(int i = str.size()-1; i >= 0; i--){
		int nx;
		if(st == 0) nx = z;
		if(st == 1) nx = y;
		if(st == 2) nx = x;
		sum += str[i] - '0';
		if(sum == nx){
			st++;
			if(st == 3) return true;
			sum = 0;
		}
	}
	return false;
}

llint calc(llint rem, llint state)
{
	if(rem == 0) return 1;
	if(memo[rem][state] != -1) return memo[rem][state];
	
	llint ret = 0;
	for(int i = 1; i <= 10; i++){
		if(ng_state[state][i]) continue;
		llint nstate = next_state[state][i];
		ret += calc(rem-1, nstate); 
		ret %= mod;
	}
	return memo[rem][state] = ret;
}

int main(void)
{
	cin >> n >> x >> y >> z;
	s = x+y+z-1;
	S = 1<<s;
	
	llint beki = 1;
	for(int i = 0; i < n; i++) beki *= 10, beki %= mod;
	
	for(int i = 0; i <= n; i++){
		for(int j = 0; j < S; j++){
			memo[i][j] = -1;
		}
	}
	
	for(int i = 0; i < S; i++){
		for(int j = 1; j <= 10; j++){
			string nstate = parse(i) + (char)(j+'0');
			ng_state[i][j] = check(nstate);
			if(!ng_state[i][j]) next_state[i][j] = rparse(trunc(nstate));
		}
	}
	
	cout << (beki + mod - calc(n, 0)) % mod << endl;
	return 0;
}

Measured memory_bytes: 30976
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>

#define f first
#define s second
#define MAX_N 155
#define INF 1000000000

using namespace std;

typedef pair<int,int> P;

int main(void){

  int n,m,k,a,b;

  while(cin >> n >> m,n|m){
    vector<P>v[MAX_N];
    
    for(int i=1;i<=n;i++){
      cin >> k;
      for(int j=0;j<k;j++){
	cin >> a >> b;
	v[i].push_back(make_pair(a,b));
      }
    }

    int dp[MAX_N][11][80];

    for(int i=0;i<MAX_N;i++)
      for(int j=0;j<11;j++)
	for(int k=0;k<80;k++)
	  dp[i][j][k]=INF;

    for(int i=0;i<11;i++)
      for(int j=0;j<80;j++)
	dp[0][i][j]=dp[1][i][j]=0;

    for(int i=2;i<=n;i++){
      for(int j=0;j<v[i].size();j++){
	for(int l=m;l>=0;l--){
	  for(int k=0;k<v[i-1].size();k++){
	    dp[i][j][l]=min(dp[i][j][l],dp[i-1][k][l]+(v[i][j].s+v[i-1][k].s)*abs(v[i][j].f-v[i-1][k].f));
	  }
	  if(l<m){
	    if(i==2)dp[i][j][l]=0;
	    for(int p=0;p<v[i-2].size();p++)
	      dp[i][j][l]=min(dp[i][j][l],dp[i-2][p][l+1]+(v[i][j].s+v[i-2][p].s)*abs(v[i][j].f-v[i-2][p].f));
	  }
	}
      }
    }
    
    int ans=INF;
    for(int i=0;i<v[n].size();i++)ans=min(ans,dp[n][i][0]);
    if(m>=1)for(int i=0;i<v[n-1].size();i++)ans=min(ans,dp[n-1][i][1]);

    cout << ans << endl;
  }

  return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n;
    cin >> n;
    vector<vpii> xy(n);
    rep(i, n) {
        int a;
        cin >> a;
        xy[i] = vpii(a);
        rep(j, a) {
            int x, y;
            cin >> x >> y;
            --x;
            xy[i][j] = { x, y };
        }
    }
    int ans = 0;
    rep(i, 1<<n) {
        bool ok = true;
        rep(j, n) {
            if (!(i&(1<<j))) continue;
            for (auto k : xy[j]) {
                int x = k.first, y = k.second;
                if (((i>>x)&1) ^ y) ok = false;
            }
        }
        if (ok) ans = max(ans, __builtin_popcount(i));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3568
import sys

sys.setrecursionlimit(10**6)


def get_distance(v):              
    distance = [0] * n
    visited = [0] * n
    visited[v] = 1
    dfs(v, 0, distance, visited)
    return distance


def dfs(v, d, distance, visited):
    distance[v] = d
    for u in adj[v]:
        if not visited[u]:
            visited[u] = 1
            dfs(u, d + 1, distance, visited)


n, u, v = map(int, input().split())

adj = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = (int(i) - 1 for i in input().split()) 
    adj[a].append(b)
    adj[b].append(a)

u_distance = get_distance(u - 1)
v_distance = get_distance(v - 1)

ans = 0
for u, v in zip(u_distance, v_distance):
    if u < v and v - 1 > ans:
        ans = v - 1

print(ans)

Measured memory_bytes: 102424
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=s;i<t;i++)
typedef long long ll;
#define MAXNUM 111111
ll num[MAXNUM],sum[MAXNUM];int n,m,v,p;
int main()
{
    scanf("%d%d%d%d",&n,&m,&v,&p);
    rep(i,1,n+1)scanf("%lld",&num[i]);
    sort(num+1,num+n+1,greater<ll>());
    rep(i,1,n+1)sum[i]=sum[i-1]+num[i];
    int res=0,bef=1;num[0]=-1;
    rep(i,1,n+1)
    {
        if(num[i]!=num[i-1])bef=i;
        if(num[i]+m<num[p])continue;
        if(bef<=p)res++;
        else if(n-bef+1>=v)res++;
        else{
            ll k=v-(n-bef+1)-(p-1),xx=(num[i]+m)*(bef-p)-(sum[bef-1]-sum[p-1]);
            if(xx>=k*m)res++;
        }
    }
    printf("%d\n",res);
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define vint vector<int>
#define INF 1e9
#define PI 3.14159265359

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;
typedef long long  ll;

const long long MOD = 1e9+7;


int main(){

    ll n;
    cin >> n;

    vector<vector<ll>> points(n, vector<ll>(3));

    ll tmp_a, tmp_b, tmp_c;
    REP(i, 0, n){
        cin >> tmp_a >> tmp_b >> tmp_c;
        points[i][0] = tmp_a;
        points[i][1] = tmp_b;
        points[i][2] = tmp_c;
    }

//    vint dp(n+1, 0);
    vector<vector<ll>> dp(n+1, vector<ll>(3,0));
//    ll dp[n+1][3];

    REP(i, 0, n){
        REP(j, 0, 3){
            REP(k, 0, 3){
                if(j == k) continue;
                chmax(dp[i+1][k], dp[i][j] + points[i][k]);
            }
        }
    }

    ll ans = *max_element(dp[n].begin(), dp[n].end());
    p(ans);
}


Measured memory_bytes: 14328
import math
sta,stb=[str(i) for i in input().split()]
a = int(sta)
b = int(stb[0])*100
if stb[1] == '.':
  #小数
  if len(stb) >= 3:
    b+=int(stb[2])*10
  if len(stb) == 4:
    b+=int(stb[3])
print(a*b//100)

Measured memory_bytes: 9036
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

int main(){
  int N,ans=0;
  cin >> N;
  vector<pair<int,int>> ab(N),cd(N);
  FOR(i,0,N)cin >> ab[i].first >> ab[i].second;
  FOR(i,0,N)cin >> cd[i].first >> cd[i].second;
  sort(ALL(cd));
  for(auto p:cd){
    int x = p.first;
    int y = p.second;
    int MAX = -1;
    FOR(i,0,ab.size()){
      if(ab[i].first < x && ab[i].second < y)MAX = max(MAX,ab[i].second);
    }
    if(MAX == -1)continue;
    FOR(i,0,ab.size()){
      if(ab[i].second == MAX){
        ans++;
        ab.erase(ab.begin()+i,ab.begin()+i+1);
        break;
      }
    }
  }
  cout << ans << endl;
}


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

ll gcd(ll a, ll b){
    while (b>0){
        ll tempB = b;
        b = a % b;
        a = tempB;
    }
    return a;
}

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

int main(){
    int N;
    cin >> N;
    ll T[N];
    ll ans = 1;
    for (ll i=0; i<N; i++){
        cin >> T[i];
        ans = lcm(ans, T[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 2e5 + 50;
int n,tot,cnt,a[maxn];
int main(){
	cin >> n;
	getchar();
	for(int i = 1; i <= n; i ++) a[i] = (getchar() == 'R'),tot += a[i];
//	for(int i = 1; i <= n; i ++) cout << a[i] << ' ';
//	cout << endl;
	for(int i = 1; i <= tot; i ++) cnt += a[i];
	printf("%d\n",tot - cnt);
	return 0;
}

Measured memory_bytes: 4540
#include<stdio.h>
#include<string.h>
int main(){
	char c[5000];
	int x=0,i,j,l;
	scanf("%s",c);
	l=strlen(c);
	for(i=0;i<l;i++){
		if(x==0&&c[i]=='C'){
			x++;
		}
		if(x==1&&c[i]=='F'){
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int L;
  cin >> L;
  int N = 1;
  int tmp = 1;
  while(tmp <= L) {
    N++;
    tmp *= 2;
  }
  N--;
  tmp /= 2;
  L -= tmp;
  int now = tmp;
  tmp /= 2;
  vector<int> u;
  vector<int> v;
  vector<int> c;
  REP(i, N-1) {
    u.push_back(i+1);
    v.push_back(i+2);
    c.push_back(0);
    u.push_back(i+1);
    v.push_back(i+2);
    c.push_back(tmp);
    if(L >= tmp) {
      u.push_back(1);
      v.push_back(i+2);
      c.push_back(now);
      now += tmp;
      L -= tmp;
    }
    tmp /= 2;
  }
  cout << N << " " << u.size() << "\n";
  REP(i, u.size()) cout << u[i] << " " << v[i] << " " << c[i] << "\n";
}

Measured memory_bytes: 256
// 簡易競プロテンプレ
#include <bits/stdc++.h>
using namespace std;
string s[8];

int main(void){
 int h, w; cin >> h >> w;
 for(int i=0;i<h;i++) cin >> s[i];
 int cnt = 0;
 for(int i=0;i<h;i++)for(int j=0;j<w;j++) if (s[i][j]=='#') cnt++;  
 cout << ((cnt==h+w-1) ? "Possible" : "Impossible") << endl;
 return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A_list = list(map(int, input().split()))

t_list = [1]
t_table = { 1: 0 }
t = 1
loop = None
while True:
	t = A_list[t - 1]
	if t in t_table:
		loop = t_table[t]
		break
	t_table[t] = len(t_list)
	t_list.append(t)

t_head = t_list[:loop]
t_loop = t_list[loop:]

if K < loop:
	print(t_head[K])
else:
	print(t_loop[(K - loop) % len(t_loop)])


Measured memory_bytes: 38912
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll int n;
		cin>>n;
		ll int dp[n+1],h[n+1];
		for(ll int i=1;i<=n;i++)
		{
			cin>>h[i];
		}
		dp[1]=0;
		dp[2]=abs(h[1]-h[2]);
		for(ll int i=3;i<=n;i++)
		{
			dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
		}
		cout<<dp[n];
	}
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <bits/stdc++.h>
#include <sstream>
#define PI 3.14159265358979323846264338327950L
using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    if(s == "ARC"){
        cout << "ABC";
    }else{
        cout << "ARC";
    }
}

Measured memory_bytes: 3612
sx,sy,tx,ty = map(int,input().split())


ans = ''
x = tx-sx
y = ty-sy

ans += 'R' * x
ans += 'U' * y
ans += 'L' * x
ans += 'D' * (y+1)
ans += 'R' * (x+1)
ans += 'U' * (y+1)
ans += 'L'
ans += 'U'
ans += 'L' * (x+1)
ans += 'D' * (y+1)
ans += 'R'

print(ans)


Measured memory_bytes: 3064
h,w = map(int,input().split())
L = []
L.append(["#"]*(w+2))
for i in range(h):
    l=["#"]
    l.append(input())
    l.append("#")
    L.append(l)
L.append(["#"]*(w+2))
for i in range(h+2):
    print("".join(L[i]))

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

int main() {
  int H,W;
  cin>>H>>W;
  vector<char> p(H*W);
  for(int i=0;i<H;i++){
    string S;
    cin>>S;
    for(int j=0;j<W;j++){
      p.at(i*W+j)=S.at(j);
    }
  }
  vector<vector<int>>d(H*W,vector<int>(H*W,401));
  for(int i=0;i<H;i++){
    for(int j=1;j<W;j++){
      if(p.at(i*W+j)=='.'&&p.at(i*W+j-1)=='.'){
        d.at(i*W+j).at(i*W+j-1)=1;
        d.at(i*W+j-1).at(i*W+j)=1;
      }
    }
  }
  for(int i=1;i<H;i++){
    for(int j=0;j<W;j++){
      if(p.at(i*W+j)=='.'&&p.at((i-1)*W+j)=='.'){
        d.at(i*W+j).at((i-1)*W+j)=1;
        d.at((i-1)*W+j).at(i*W+j)=1;
      }
    }
  }
  for(int i=0;i<H*W;i++){
    d.at(i).at(i)=0;
  }
  int n=H*W;
  for (int k = 0; k < n; k++){       // 経由する頂点
    for (int i = 0; i < n; i++) {    // 始点
      for (int j = 0; j < n; j++) {  // 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int Z=0;
  for(int i=0;i<H*W;i++){
    for(int j=i;j<H*W;j++){
      if(p.at(i)=='.'&&p.at(j)=='.'){
        Z=max(Z,d.at(i).at(j));
      }
    }
  }
  cout<<Z<<endl;  
}





Measured memory_bytes: 896
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
        c: i32,
        s: Bytes,
    }

    /*
        d0[i] = (j,k) : today + i 日目以前に、j日働ける。最後に働いたのは today+k 日目
        d1[i] = (j,k) : today + i 日目以降に、j日働ける。次に働くのは、遅くとも today+k日目
    */

    let mut d0 = vec![(0usize, 0); n];
    let mut d1 = vec![(0usize, 0); n];

    {
        let mut last_work_i = -c - 1;
        let mut ct = 0;
        for i in 0..n {
            if last_work_i + c < i as i32 && s[i] == b'o' {
                ct += 1;
                last_work_i = i as i32;
            }
            d0[i] = (ct, last_work_i);
        }
    }

    {
        let mut last_work_i = n as i32 + c;
        let mut ct = 0;
        for i in (0..n).rev() {
            if i as i32 + c < last_work_i && s[i] == b'o' {
                ct += 1;
                last_work_i = i as i32;
            }
            d1[i] = (ct, last_work_i);
        }
    }

    for i in 0..n {
        let (work0, last_work) = if i == 0 { (0, -c - 1) } else { d0[i - 1] };
        let (work1, next_work) = if i == n - 1 {
            (0, n as i32 + c)
        } else {
            d1[i + 1]
        };

        if work0 + work1 < k || work0 + work1 == k && last_work + c >= next_work {
            println!("{}", i + 1);
        }
    }
}


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

using namespace std;

long MOD = 1000000007;

int main(){
    int N;
    cin>>N;
    vector<int> B(N-1);
    for(int i=0; i<N-1; ++i){
        cin>>B[i];
    }

    int ans = B[0]+B[N-2];
    for(int i=1; i<N-1; ++i){
        ans += min(B[i-1], B[i]);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  auto n = readln.chomp.to!int;
  auto a = readln.chomp.split.to!(int[]);
  auto b = readln.chomp.split.to!(int[]);
  long cnt;
  foreach (i; 0..n) {
    auto t = min(a[i], b[i]);
    a[i] -= t;
    b[i] -= t;
    
    auto t2 = min(a[i+1], b[i]);
    a[i+1] -= t2;

    cnt += t + t2;
  }
  cnt.writeln;
}


Measured memory_bytes: 9416
use std::mem::swap;
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n:usize = read();
    let mut a:Vec<u32> = (0..n).map(|_| read()).collect();
    println!("{}", a.clone().into_iter().map(|x| x.to_string()).collect::<Vec<String>>().join(" "));
    for i in 1..n {
        let mut j = i;
        while j > 0 && a[j-1] > a[j] {
            a.swap(j-1, j);
            j -= 1;
        }
        println!("{}", a.clone().into_iter().map(|x| x.to_string()).collect::<Vec<String>>().join(" "));
    }
}


Measured memory_bytes: 5052
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}
		br.close();

		TreeMap<Integer, Integer> map = new TreeMap<>();
		for (int i = 0; i < n; i++) {
			Integer l = map.lowerKey(a[i]);
			if (map.containsKey(a[i])) {
				map.put(a[i], map.get(a[i]) + 1);
			} else {
				map.put(a[i], 1);
			}
			if (l != null) {
				int v = map.get(l);
				if (v == 1) {
					map.remove(l);
				} else {
					map.put(l, v - 1);
				}
			}
		}
		int ans = 0;
		for (Integer k : map.keySet()) {
			ans += map.get(k);
		}
		System.out.println(ans);
	}
}


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

int main()
{
    int n,cnt;
    long double l,ans;

    cin >> n;
    vector<int> x(n), y(n), v(n);
    rep(i, n)
        cin >> x[i] >> y[i];

    iota(v.begin(), v.end(),0);
    l = cnt = 0;
    do {
        double t=0;
        rep(i, n-1) {
            int j1 = v[i];
            int j2 = v[i + 1];
            t += sqrt(pow(x[j1] - x[j2], 2) + pow(y[j1] - y[j2], 2));
        }
        l += t;
        ++cnt;
    } while (next_permutation(v.begin(), v.end()));
    ans = l / cnt;
    std::cout << fixed << setprecision(10) <<  ans << endl;

    return 0;
}

Measured memory_bytes: 3792
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

bool p(int n) {
  string s = to_string(n);

  for (int i = 0; i < s.size()/2; ++i) {
    if (s.at(i) != s.at(s.size()-1-i)) {
      return false;
    }
  }

  return true;
}

int main() {
  int count = 0;

  int a, b;
  cin >> a >> b;

  for (int i = a; i <= b; ++i) {
    if (p(i)) {
      count++;
    }
  }
  
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N, Ma, Mb;
    std::cin >> N >> Ma >> Mb;

    struct D {
        int64_t a;
        int64_t b;
        int64_t c;
    };

    std::vector<D> d;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t a, b, c;
        std::cin >> a >> b >> c;
        d.push_back({a, b, c});
    }

    // dp[aの総量][bの総量][i個まで(i含む)]
    boost::multi_array<int64_t, 3> dp(boost::extents[N+1][10*N+1][10*N+1]);

    const int64_t INF = 40*N+1;
    std::fill(dp.data(), dp.data() + dp.num_elements(), INF);

    // 配るDP
    dp[0][0][0] = 0;

    #if 0
    for (int64_t i = 0; i < N; ++i) {
        for (int64_t a = 0; a <= 10*N; ++a) {
            for (int64_t b = 0; b <= 10*N; ++b) {
                if (dp[i][a][b] == INF) {
                    // 原点から届かない部分からは次に配らない
                    // この枝切りを入れないと、
                    // すでに a, b がmaxになっているところから先に配ろうとして、
                    // 範囲外アクセスとなる。
                    continue;
                }

                // 自分をいれる
                dp[i+1][a+d[i].a][b+d[i].b] = std::min(dp[i+1][a+d[i].a][b+d[i].b],
                                                       dp[i][a][b] + d[i].c);
                // 自分をいれない
                dp[i+1][a][b] = std::min(dp[i+1][a][b], dp[i][a][b]);
            }
        }
    }
    #endif
    #if 1
    // もらうDP
    for (int64_t i = 0; i < N; ++i) {
        for (int64_t a = 0; a <= 10*N; ++a) {
            for (int64_t b = 0; b <= 10*N; ++b) {
                if (a - d[i].a >= 0 && b - d[i].b >= 0) {
                    dp[i+1][a][b] = std::min(dp[i][a][b], dp[i][a - d[i].a][b - d[i].b] + d[i].c);
                }
                else {
                    dp[i+1][a][b] = dp[i][a][b];
                }
            }
        }
    }
    #endif
    int64_t ans = INF;
    for (int64_t a = 1; a <= 10*N; ++a) {
        for (int64_t b = 1; b <= 10*N; ++b) {
            if (Ma*b == Mb*a) {
                ans = min(ans, dp[N][a][b]);
            }
        }
    }
    if (ans == INF) {
        ans = -1;
    }
    std::cout << ans << std::endl;

    return 0;
}






Measured memory_bytes: 51712
a=gets.chomp.to_i
b=gets.chomp.to_i
c=gets.chomp.to_i
x=gets.chomp.to_i
ans=0
(a+1).times do |anum|
  (b+1).times do |bnum|
    (c+1).times do |cnum|
      ans+=1 if x==500*anum+100*bnum+50*cnum
    end
  end
end
puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int ans = 0;
  rep(i, n-2) {
    for(int j=i+1; j<n-1; j++) {
      for(int k=j+1; k<n; k++) {
        if(a[i] == a[j] || a[j] == a[k] || a[k] == a[i]) continue;
        if(a[i] + a[j] > a[k] && a[j] + a[k] > a[i] && a[k] + a[i] > a[j]) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main(){
    int A, B, sum = 0;
    cin >> A >> B;
    for(int i=0; i<2; i++){
        if(A>=B){
            sum+=A;
            A--;
        }
        else{
            sum+=B;
            B--;
        }
    }
    cout << sum;
    return 0;
}


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

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let k: usize = it.next().unwrap().parse().unwrap();
    let mut a: Vec<usize> = it.map(|s| s.parse().unwrap()).collect();
    a.sort();
    if k >= n {
        println!("0");
        return;
    }
    let mut ans = 0;
    for h in a[..(n - k)].iter() {
        ans += *h;
    }
    println!("{}", ans);
}

fn main() {
    run();
}

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

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 998244353
#define inf 100000000000010
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pi;

bool prime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}

struct CustomCompare
{
    bool operator()(const int& lhs, const int& rhs)
    {
        return lhs < rhs;
    }
};

bool comp(pair<ll, pi>a,pair<ll,pi>b)
{
    if(a.se.fi==b.se.fi)return a.se.se>b.se.se;
    return a.se.fi>b.se.fi;
}

ll builtin_popcount(ll x)
{
    ll cnt = 0;
    for(ll i=60;i>=0;i--)
    {
        if((1LL<<i)&x)cnt++;
    }
    return cnt;
}


int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll n; cin>>n;
vi arr(n);
vi t(1e6+1);
rep(i,0,n)cin>>arr[i],t[arr[i]]++;
sort(all(arr));

//map<ll,ll>mp;
vi fact(1e6+1);
ll cnt = 0;
rep(i,0,n)
{
    bool flag = true;
    for(ll j = 1;j*j<=arr[i];j++)
    {
        if(arr[i]%j==0)
        {
            if(fact[j]||fact[arr[i]/j])flag = false;
        }

    }
    fact[arr[i]]++;
    if(flag&&t[arr[i]]==1)cnt++;
}
cout<<cnt<<endl;
return 0;
}
/*
50 25
39 99 70 24 49 13 86 43 88 74 45 92 72 71 90 32 19 76 84 46 63 15 87 1 39 58 17 65 99 43 83 29 64 67 100 14 17 100 81 26 45 40 95 94 86 2 89 57 52 91 45
1221 360 459 651 958 584 345 181 536 116 1310 403 669 1044 1281 711 222 280 1255 257 811 409 698 74 838
*/


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

int main() {
  int N;
  cin >> N;
  vector<int> p;
  for (int i = 0; i < N; ++i) {
    int tmp;
    cin >> tmp;
    p.push_back(tmp);
  }
  sort(p.begin(), p.end());
  reverse(p.begin(), p.end());
  int sum = p[0] / 2;
  for (int i = 1; i < N; ++i) {
    sum += p[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
import std.datetime;

void main()
{
	while (1) {
		auto n = readln.chomp.to!int;
		if (!n) break;
		auto m = new int[][](n);
		foreach (i; 0..n) {
			auto x = readln.chomp.split.map!(to!int).array;
			if (x[0] == 0) continue;
			m[i] ~= x[1..$];
		}
		auto y = readln.chomp.split.map!(to!int).array[1..$];
		int[] res;
		foreach (i; 0..n) {
			int cnt;
			foreach (e; y) {
				foreach (me; m[i]) {
					if (me == e) cnt++;
				}
			}
			if (cnt == y.length) {
				res ~= i + 1;
			}
		}
		if (res.length == 1) {
			res[0].writeln;
		} else {
			writeln(-1);
		}
	}
}

Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define fillarray(array, value, begin, end) fill((array) + (begin), (array) + (end) + 1, value)
#define fillvector(v, value) fill((v).begin(), (v).end(), value)
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
#define vecfirst (*vec.begin())
#define veclast (*vec.rbegin())
#define vecall(v) (v).begin(), (v).end()
#define vecupsort(v) (sort((v).begin(), (v).end()))
#define vecdownsort(v, type) (sort(vecall(v), greater<type>()))
#define veccmpsort(v, cmp) (sort(vecall(v), cmp))
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME__END - TIME__START) / 1000);
    system("pause");
#endif
}
char s[N];
ll ans;

inline void solve()
{
    cin >> s;
    for (int i = 0; s[i];++i)
    {
        ans += s[i] - '0';
    }
    puts((ans % 9) ? "No" : "Yes");
}

int main()
{
    TIME__START = clock();
    int Test = 1;
    // scanf("%d", &Test);
    while (Test--)
        solve();
    TIME__END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 3844
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int p[N],disc[N],low[N],vis[N],ap[N],wmy,n,m;
vector<int> g[N];
void dfs(int u) {
    int children = 0;
    vis[u] = true;
    disc[u] = low[u] = ++wmy;
    for(int &v: g[u]) {
        if(!vis[v]) {
            children++;p[v] = u;
            dfs(v);
            low[u] = min(low[u],low[v]);
            if(p[u] == -1 && children > 1) ap[u] = true;
            else if(p[u]!=-1 && low[v] >= disc[u]) ap[u] = true;

        }
        else if(v != p[u]) low[u] = min(low[u],disc[v]);
    }
}
int main() {
    scanf("%d%d",&n,&m);
    memset(vis,0,sizeof(vis));
    memset(low,0,sizeof(low));
    memset(ap,0,sizeof(ap));
    memset(p,0,sizeof(p));
    wmy = 0;
    for(int i = 0;i < N;i++) g[i].clear();
    for(int i = 1;i <= m;i++) {
        int u,v;
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    p[0] = -1;
    dfs(0);
    for(int i = 0;i < n;i++) if(ap[i]) printf("%d\n",i);
} 


Measured memory_bytes: 8300
from itertools import product

H, W = [int(i) for i in input().split()]
grid = [list(input()) for _ in range(H)]

for y, x in product(range(H), range(W)):
    if grid[y][x] == "#":
        continue
    n_bomb = 0
    for dy, dx in product([-1, 0, 1], repeat=2):
        if dy == 0 and dx == 0:
            continue
        ny, nx = y + dy, x + dx
        if not (0 <= ny < H and 0 <= nx < W):
            continue
        if grid[ny][nx] == "#":
            n_bomb += 1
    grid[y][x] = n_bomb
for l in grid:
    print(*l, sep="")


Measured memory_bytes: 46448
// abc129_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;


int main() {
#ifdef LOCAL
    ifstream in("../arg.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int H, W;
    cin >> H >> W;
    vector<vector<bool>> G;
    G.assign(H+2, vector<bool>(W+2, false));

    REPN(i, 1, H+1) {
        string s;
        cin >> s;
        REPN(j, 1, W+1){
            if (s[j-1] == '.') G[i][j] = true;
        }
    }

    struct D {int l,u,r,d;};
    vector<vector<D>> X;
    X.assign(H+2, vector<D>(W+2, {-1,-1,-1,-1}));

    int ans = 0;
    REPN(i, 1, H+1) REPN(j, 1, W+1){

        if (G[i][j] == false) continue;

        if (X[i][j].l == -1){

            int tmp = 0;
            while (G[i][j+tmp]) {
                tmp++;
            }

            REP(k, tmp){
                X[i][j+k].l = k;
                X[i][j+k].r = tmp - k - 1;
            }
        }

        if (X[i][j].u == -1){

            int tmp = 0;
            while (G[i+tmp][j]) {
                tmp++;
            }

            REP(k, tmp){
                X[i+k][j].u = k;
                X[i+k][j].d = tmp - k - 1;

            }
        }

        ans = max(ans, X[i][j].l + X[i][j].r + X[i][j].u + X[i][j].d + 1);

    }

    print(ans);

    return 0;
}


Measured memory_bytes: 63616
#include<cstdio>
char s[10];

int main(){
    scanf("%s",s+1);
    int n = 3;
    int p = 1, ans = 0;
    while(p<=n){
        if(s[p]=='S') p++;
        else{
            int np = p;
            while(np+1<=n && s[np+1]==s[p]) np++;
            int len = np-p+1;
            if(len>ans) ans = len;
            p = np+1;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1688
// C - 怪文書

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

string S[50];

int count_char(char c, string S) {
	int result = 0;
	for (int i=0; i<S.size(); i++) {
		if (S[i] == c) result++;
	}
	return result;
}

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

	for (int i=0; i<n; i++) {
		cin >> S[i];
		sort(S[i].begin(), S[i].end());
	}

	string ans = "";
	for (char c = 'a'; c <= 'z'; c++) {
		int cnt = INF;
		for (int i=0; i<n; i++) {
			cnt = min(cnt, count_char(c, S[i]));
		}
		for (int i=0; i<cnt; i++) {
			ans += c;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
	string s;
  	cin >> s;
  	cout << s[0] << to_string(s.size()-2) << s.back() << endl;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
p = list(list(map(int,input().split()))for _ in range(N))

for i in range(N):
    if p[i][2]:
        tmp = i
        break

for Cx in range(101):
    for Cy in range(101):
        H = p[tmp][2] + abs(Cx-p[tmp][0]) + abs(Cy-p[tmp][1])
        flag = True
        for x,y,h in p:
            if h != max(H -abs(Cx-x) - abs(Cy-y), 0):
                flag = False
                break
        if flag:
            print(Cx,Cy,H)
    


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

int main(){
  ll n,k;cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);

  // ll now = 1;
  // rep(i,k) now *= a.at(i);
  // for(ll i=k;i<n;++i){
  //   ll pre = now;
  //   now = now/a.at(i-k)*a.at(i);
  //   if( now > pre ){
  //     cout << "Yes"  << '\n';
  //   }else{
  //     cout << "No"  << '\n';
  //   }
  // }
  for(ll i=k;i<n;++i){
    if( a.at(i-k) < a.at(i) ){
      cout << "Yes" << '\n';
    }else{
      cout << "No" << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 4840
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>

using namespace std;
using ll = long long;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI = 4.0 * atan(1.0);

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

int main() {
    string S; cin >> S;
    string T; cin >> T;

    int ans = 0;
    if (S[0] == T[0]) ans++;
    if (S[1] == T[1]) ans++;
    if (S[2] == T[2]) ans++;

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


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


public class Main {
	public static void main(String[] args) {
		new Main().solve();
	}
	
	void solve(){
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			double d = Double.parseDouble(sc.next());
			String s = "";
			
			if(d > 91.00){
				s = "heavy";
			}else if(d > 81.00){
				s = "light heavy";
			}else if(d > 75.00){
				s = "middle";
			}else if(d > 69.00){
				s = "light middle";
			}else if(d > 64.00){
				s = "welter";
			}else if(d > 60.00){
				s = "light welter";
			}else if(d > 57.00){
				s = "light";
			}else if(d > 54.00){
				s = "feather";
			}else if(d > 51.00){
				s = "bantam";
			}else if(d > 48.00){
				s = "fly";
			}else{
				s = "light fly";
			}
			
			System.out.println(s);
		}
		
		sc.close();
	}
	
	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;

class Main {
    public static void main(String[] av) {
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();

	if (a < b) {
	    int tmp = a;
	    a = b;
	    b = tmp;
	}

	int r = a%b;
	while (r != 0) {
	    a = b;
	    b = r;
	    r = a%b;
	}
	System.out.println(b);
    }
}


Measured memory_bytes: 26260
#include<stdio.h>
#define N 100
int G[N][N];
int x[N],y[N];

int min(int);

int main(){
  int a,i,j,n;
  scanf("%d", &n);

  for(i = 0;i < n; i++){
    for(j = 0; j < n; j++){
      scanf("%d", &G[i][j]);
    }
  }

  a = min(n);
  printf("%d\n", a);
  return 0;
}

int min(int n){
  int i,j,k=1;
  int m1,m2,sum=0;

  x[0]=0;
  y[0] = 1;
  for(i = 1;i<n;i++){
    y[i] = 0;
  }
  while(1){
    m1 = 2001;
    for(i = 0;i<k;i++){
      for(j = 0;j < n;j++){
	if(G[x[i]][j]<m1 && G[x[i]][j] != -1 && y[j] != 1){
	  m1 = G[x[i]][j];
	  m2 = j;
	}

      }
    }
    if(k == n)break;
    x[k] = m2;
    y[m2] = 1;
    sum+=m1;
    k++;
  }
  return sum;
}

Measured memory_bytes: 640
import Control.Monad
import Control.Monad.State

type Stat = ([[Int]], Int, Int, Int)

main :: IO ()
main = do
  n <- readLn
  ass <- replicateM n readInts
  putStr $ solve ass

readInts :: IO [Int]
readInts = map read . words <$> getLine

solve :: [[Int]] -> String
solve ass = evalState solve' (ass, 0, 0, 0)

solve' :: State Stat String
solve' = do
  (ass, s, u, v) <- get
  case ass of
    [] -> return "Yes"
    ([t, x, y]:bss)
      | p -> put (bss, t, x, y) >> solve'
      | otherwise -> return "No"
      where  
        d = (abs (x - u)) + (abs (y - v))
        p = d <= t - s && even (t - s - d)





Measured memory_bytes: 81276
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    string S;
    cin >> S;
    ll DP[S.size()][13] = {};
    if (S[0] == '?') {
        FOR(i, 0, 10) {
            DP[0][i] = 1;
        }
    } else {
        DP[0][S[0] - '0'] = 1;
    }
    FOR(i, 0, S.size() - 1) {
        FOR(j, 0, 13) {
            DP[i][j] %= INF;
            if (S[i + 1] == '?') {
                FOR(k, 0, 10) {
                    DP[i + 1][(j * 10 + k) % 13] += DP[i][j];
                }
            } else {
                DP[i + 1][(j * 10 + S[i + 1] - '0') % 13] += DP[i][j];
            }
        }
    }
    cout << DP[S.size() - 1][5] % INF << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(3*N);
    for(int i=0; i<3*N; ++i) cin >> A[i];
    sort(A.begin(), A.end());

    long long res = 0;
    for(int i=N; i<3*N; i += 2) res += A[i];
    cout << res << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
ll ans[55555];
int main()
{

	int n,x,y; cin>>n>>x>>y;
	x--; y--;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			int dist=j-i;
			dist=min(dist,abs(i-x)+1+abs(y-j));
			dist=min(dist,abs(i-y)+1+abs(x-j));
			ans[dist]++;
		}
	}
	for(int i=1;i<=n-1;i++)
		cout<<ans[i]<<"\n";
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
int const MOD=1e9+7;
int X, Y;

int power(long long a, long long b, long long c){
    long long res = 1;
    a = a % c;
    while (b > 0) {
        if (b % 2 == 1)
            res = (res*a) % c;
        b = b / 2;
        a = (a*a) % c;  
    }
    return res;
}
int main(){
	cin>>X>>Y;
	if((X+Y)%3)
		return cout<<0, 0;
	int moves=(X+Y)/3;
	X-=moves;
	Y-=moves;
	if(X<0 || Y<0)
		return cout<<0, 0;
	vector<long long> fact(X+Y+1);
	fact[0]=1;
	for(int i=1;i<=X+Y;i++)
		fact[i]=(i*fact[i-1])%MOD;
	//(X+Y)!/X!Y!
	long long num=fact[X+Y];
	long long den=(fact[X]*fact[Y])%MOD;
	//den^(mod-2)mod mod
 	den=power(den,1e9+5,1e9+7);
	cout<<(num*den)%MOD;
}

Measured memory_bytes: 5504
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<sstream>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;


int main()
{
	int a,b;
	cin >> a >> b;
	if(a >= 1 && a <= 9 && b >= 1 && b <= 9)
		cout << a*b<<endl;
	else	
		cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int x[51];
ll dp[51][2501][51];
int main(){
    int n,a;
    cin>>n>>a;
    rep(i,n) cin>>x[i];
    dp[0][0][0]=1;
    rep(i,n){
        for(int j=(i+1)*50;j>=0;--j){
            FOR(k,0,n+1){
                if(j>=x[i]&&k>0){
                    dp[i+1][j][k]+=dp[i][j-x[i]][k-1]+dp[i][j][k];
                }
                else dp[i+1][j][k]+=dp[i][j][k];
            }
        }
    }
    ll cnt=0;
    FOR(i,1,n+1) cnt+=dp[n][i*a][i];
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 49024