akhauriyash/Code-Regression huggingface dataset:
class Combination:
    def __init__(self, n, mod):
        fact = [0]*(n+1)
        ifact = [0]*(n+1)
        fact[0] = 1
        for i in range(1, n+1):
            fact[i] = (fact[i-1]*i) % mod
        # 1/n!を逆元で求める
        ifact[n] = pow(fact[n], mod-2, mod)
        for i in range(n, 0, -1):
            ifact[i-1] = (ifact[i]*i) % mod

        self.n = n
        self.mod = mod
        self.fact = fact
        self.ifact = ifact

    def choose(self, n, r):
        if r < 0 or r > n:
            return 0
        ret = (self.fact[n]*self.ifact[r]) % self.mod
        return (ret*self.ifact[n-r]) % self.mod


n = int(input())
*a, = map(int, input().split())
indices = [-1]*n
l, r = 0, 0
for i in range(n+1):
    if indices[a[i]-1] != -1:
        l = indices[a[i]-1]
        r = i
        break
    indices[a[i]-1] = i

MOD = 10**9+7
n += 1
c = Combination(n, MOD)
k = n-(r-l+1)
for i in range(1, n+1):
    ans = c.choose(n, i)
    if i == 1:
        ans -= 1
    elif k >= (i-1):
        ans -= c.choose(k, i-1)
    print((ans+MOD) % MOD)


Measured memory_bytes: 60524
import heapq
n,m= map(int,input().split())
feeindays = [[] for _ in range(m)]
for i in range(n):
    a,b= map(int,input().split())
    if a<=m:feeindays[a-1]+=[b]
q=[]
heapq.heapify(q)
pay=0
for l in feeindays:
    for c in l:heapq.heappush(q,-c)
    if len(q)!=0:pay+=-1 * heapq.heappop(q)
print(pay)

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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;
using Graph = vector<vector<int>>;
int main(){

int n;
cin>>n;
vector<string> s(n);

for(int i=0;i<n; i++){
    cin>>s[i];
}
sort(s.begin(),s.end());
int count=0;
for(int i=0;i<n-1;i++){
    if(s[i]==s[i+1]){
        count++;
    }
}
cout<<n-count<<endl;

}

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

int main(){
  int  a,b,k,count=0;
  cin >> a >> b >> k;
  for (int i =0; i<k;i++){
    if (a%2==1){
      b += (a-1)/2;
      a = (a-1)/2;
    }
    else{
      b+=a/2;
      a=a/2;
    }
   count +=1;
   if (count==k){break;}
    if (b%2==1){
      a += (b-1)/2;
      b = (b-1)/2;
    }
    else{
      a+=b/2;
      b=b/2;
    }
   count +=1;
   if (count==k){break;}
  }
  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
    int n, i, a[10000], min, max;
    long int sum; 
 
    scanf("%d", &n);
    for(i=0; i<n; i++) scanf("%d", &a[i]);
     
    min = a[0];
    max = a[0];
    sum = a[0];
 
    for(i=1; i<n; i++) {
        if(min > a[i]) min = a[i];
        if(max < a[i]) max = a[i];
        sum = sum + a[i];
    }
 
    printf("%d %d %ld\n", min, max, sum);
 
    return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    V< P<ll, ll> > ps, ms, zero;
    ll ttttt = 0;
    for (ll i = 0; i < n; i++) {
        string s; cin >> s;
        ll total = 0, mini = 0;
        for (ll j = 0; j < (ll)s.size(); j++) {
            if (s[j] == '(') total++;
            else total--;
            chmin(mini, total);
        }

        if (total < 0) {
            ms.emplace_back(make_pair(total, mini));
        } else if (total > 0) {
            ps.emplace_back(make_pair(total, mini));
        } else {
            zero.emplace_back(make_pair(total, mini));
        }
        ttttt += total;
    }
    cerr << ttttt << '\n';

    if (ttttt != 0) {
        cout << "No\n";
        return 0;
    }

    sort(ALL(ps), [&](P<ll, ll> i, P<ll, ll> j) {
        if (i.second == j.second) return i.first > j.first;
        return i.second > j.second;
    });

    ll tmp = 0;
    for (ll i = 0; i < (ll)ps.size(); i++) {
        if (tmp + ps[i].second < 0) {
            cout << "No\n";
            return 0;
        } else {
            tmp += ps[i].first;
        }
    }

    for (ll i = 0; i < (ll)zero.size(); i++) {
        if (tmp + zero[i].second < 0) {
            cout << "No\n";
            return 0;
        }
    }

    sort(ALL(ms), [&](P<ll, ll> i, P<ll, ll> j) {
        return i.second - i.first < j.second - j.first;
    });
    for (ll i = 0; i < (ll)ms.size(); i++) {
        if (tmp + ms[i].second < 0) {
            cout << "No\n";
            return 0;
        } else {
            tmp += ms[i].first;
        }
    }

    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 19068
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct zahyo{
  int x;
  int y;
}zahyo;

int combination(int n, int r)
  {
    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (combination(n - 1, r - 1) + combination(n - 1, r));
  }
  int kaijyo(int n){
    int ans=1;
    int i;
    for(i=2;i<=n;i++){
        ans*=i;
    }
    return ans;
  }
int main(){
  int N;
  double sum=0.0;
  zahyo buf[8];
  scanf("%d",&N);
  int i,j;
  for(i=0;i<N;i++){
    zahyo z;
    scanf("%d %d",&z.x,&z.y);
    buf[i]=z;
  }
  zahyo town1,town2;
  if(N>2){
  for(i=0;i<N-1;i++){
    for(j=i+1;j<N;j++){
      town1=buf[i];
      town2=buf[j];
      sum+=sqrt((town1.x-town2.x)*(town1.x-town2.x)+(town1.y-town2.y)*(town1.y-town2.y));
    }
  }
  double tmp;
  tmp=(2*sum)/N;
  printf("%lf",tmp);
  return 0;
}else if(N==2){
  town1=buf[0];
  town2=buf[1];
  sum=sqrt((town1.x-town2.x)*(town1.x-town2.x)+(town1.y-town2.y)*(town1.y-town2.y));
  printf("%lf",sum);
  return 0;
}
  return 0;
}

Measured memory_bytes: 128
n, m, c = map(int, input().split())
blst = list(map(int, input().split()))
alst = [list(map(int, input().split())) for _ in range(n)]

count = 0
for aseq in alst:
    amount = 0
    for a, b in zip(aseq, blst):
        amount += a*b
    if amount + c > 0:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ud(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, a, b) for (int i = a, i < b; ++i)
#define rep3(i, n) for (int i = n - 1; i >= 0; ++i)
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void solve(void) {
  string s;
  cin >> s;
  int len = s.length();
  int ans = 0;
  rep(i, len) {
    int indx = len - i;
    if (indx < len && !odd(indx)) {
      string x = s.substr(0, indx);
      string l = x.substr(0, indx / 2);
      string r = x.substr(indx / 2, indx / 2);
      if (l == r) ans = max(ans, indx);
    }
  }
  cout << ans << endl;
}
int main(void) { solve(); }


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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  vector<vector<int>> t;
  vector<int> d;
  Solver(LL n) : n(n), t(n), d(n){};

  void solve() {
    for (int i = 0; i < n - 1; ++i) {
      int a, b;
      cin >> a >> b;
      t[--a].push_back(--b);
      t[b].push_back(a);
    }
    dfs(0);
    int l = 0;
    for (int i = 0; i < n; ++i) {
      if (d[i] > d[l]) {
        l = i;
      }
    }
    DBG(d)
    for (int i = 0; i < n; ++i) {
      d[i] = 0;
    }
    DBG(d)
    dfs(l);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      ans = max(ans, d[i]);
    }
    DBG(ans)
    if (ans % 3 == 1) {
      cout << "Second" << endl;
    } else {
      cout << "First" << endl;
    }
  }
  void dfs(int c, int p = -1, int dep = 0) {
    DBG(c, p)
    d[c] = dep;
    for (auto x : t[c]) {
      if (x != p) {
        dfs(x, c, dep + 1);
      }
    }
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 17920
#include<iostream>
using namespace std;
int k, n, c;
int main() {
    while(cin >> k, k != 0) {
        int ans = 0;
        for (int i = 0; i < k * (k - 1) / 2; ++i) {
            cin >> c; ans += c;
        }
        cout << ans / (k - 1) << endl;
    }
}


Measured memory_bytes: 3108
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
using namespace std;

int main()
{
	char s[100];
	scanf("%s",s);
	for(int i = 0; i <= strlen(s)-9; i ++) printf("%c",s[i]);
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  int i,j=0,k=0,l=0;
  if(s[0]!='A') j++;
  for(i=2; i<s.size()-1; i++){
    if(s[i]=='C') k++;
  }
  for(i=1; i<s.size(); i++){
    if(s[i]-'a'>=0 && s[i]-'a'<=25) l++;
  }
  if(j==0 && k==1 && l==s.size()-2){
    cout << "AC";
  }else{
    cout << "WA";
  }
}



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

using ll = long long;

#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define clr(a, b) memset(a, b, sizeof(a))
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REPD(i, a, b) for(int i=(int)(a)-1; i>=(int)(b); --i)

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s, t;
    cin >> s >> t;
    map<int, vector<int>> mp;
    REP(i, 0, sz(s)) {
    	mp[s[i] - 'a'].pb(i);
    }
    int lst = -1;
    vector<int> ind;
    REP(i, 0, sz(t)) {
    	if(sz(mp[t[i] - 'a']) == 0) {
    		cout << -1 << "\n";
    		return 0;
    	}
    	int lo = upper_bound(all(mp[t[i] - 'a']), lst) - mp[t[i] - 'a'].begin();
    	if(lo == sz(mp[t[i] - 'a'])) {
    		lst = mp[t[i] - 'a'][0];
    	} else {
    		lst = mp[t[i] - 'a'][lo];
    	}
    	ind.pb(lst);
    }
    if(sz(ind) == 1) {
        cout << ind[0] + 1 << "\n";
    } else {
        ll res = 0;
        REP(i, 1, sz(ind)) {
            if(ind[i] <= ind[i-1]) {
                res += sz(s);
            } 
        }
        res += ind[sz(ind)-1];
        cout << res + 1 << "\n";
    }
    return 0;
}


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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 1; i <= (n); i++)
#define all(c) (c).begin, (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int main() {
  int H, N;
  cin >> H >> N;
  vector<int> A(N);
  vector<int> B(N);
  rep(i, N)
    cin >> A[i] >> B[i];
  int dp[10005];
  repto(i, H)
    dp[i] = INF;
  dp[0] = 0;
  repto(i, H) {
    rep(j, N) {
      if ((i - A[j]) >= 0) {
        if (dp[i] > dp[i-A[j]]+B[j])
          dp[i] = dp[i-A[j]]+B[j];
      }
      else {
        if (dp[i] > B[j])
          dp[i] = B[j];
      }
    }
  }
  cout << dp[H] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

const int INF = LLONG_MAX / 100;
int dp[105][100010];

signed main() {
    int N, W;
    cin >> N >> W;

    vector<int> w(N), v(N);
    rep(i, N) cin >> w[i] >> v[i];

    rep(i, N + 1) REP(j, 1, N * 1000 + 1) dp[i][j] = INF;

    REP(i, 1, N) {
        for (int j = N * 1000; j >= 0; j--) {
            dp[i][j] = min({dp[i][j], dp[i][j + 1], dp[i - 1][j]});
            if (j >= v[i - 1]) {
                dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
            }
        }
    }

    for (int j = N * 1000; j >= 0; j--) {
        if (dp[N][j] <= W) {
            cout << j << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 80256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) throws java.io.IOException{
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int square = h*w;
        int circuit = 2*(h+w);
        System.out.println(square+" "+circuit);
    }
}

Measured memory_bytes: 17164
#include <iostream>
using namespace std;
int N, M;
char Matrix[2005][2005];
bool X[2005][2005];
int Dif[2][2005][2005];
pair <int, int> Deq[5005];
int ans;
void Read()
{
    cin >> N >> M;
    cin.get();
    for(int i = 1; i <= N; i++)
        cin.getline(Matrix[i] + 1, 2005);
    for(int i = 1; i <= N; i++)
        for(int j = 1; j <= M; j++)
            if(Matrix[i][j] == '#')
                X[i][j] = 1;
}

void precalcDif()
{
    for(int i = 1; i <= N; i++)
        for(int j = 1; j <= M; j++)
        {
            if(Matrix[i][j] != Matrix[i][j - 1])
            {
                Dif[0][i][j] = 0;
                Dif[1][i][j] = Dif[1][i - 1][j] + 1;
            }
            else
            {
                Dif[1][i][j] = 0;
                Dif[0][i][j] = Dif[0][i - 1][j] + 1;
            }
        }
}

void Solve()
{
    ans = max(M, N);
    for(int i = 1; i <= N; i++)
    {
        for(int row = 0; row <= 1; row++)
        {
            int End = 0, Begin = 1;
            Deq[0].second = 1;
            Deq[++End] = make_pair(i, 1);
            for(int j = 2; j <= M; j++)
            {
                int val1 = X[i][j - 1], val2 = X[i][j];
                if(row == 1)
                    val1 = 1 - val1, val2 = 1 - val2;
                int x = 0, y = 0;
                if(val1 == 0)
                {
                    x = 1;
                }
                if(val2 == 0)
                    y = 1;
                x = (x ^ y);
                int pos = Dif[x][i - 1][j] + 1;
                while(Begin <= End && pos <= Deq[End].first)
                {
                    ans = max(ans, (j - Deq[End - 1].second) * Deq[End].first);
                    --End;
                }
                Deq[++End] = make_pair(pos, j);
            }
            while(Begin <= End)
            {
                ans = max(ans, (M + 1 - Deq[End - 1].second ) * Deq[End].first);
                --End;
            }
        }
    }
    cout << ans << "\n";
}
int main()
{
    Read();
    precalcDif();
    Solve();
    return 0;
}


Measured memory_bytes: 39552
import java.util.*

fun main(args: Array<String>) {
    val (N, M, V, P) = readLine()!!.split(" ").map{it.toInt()}
    val A = readLine()!!.split(" ").map{it.toLong()}.sorted()

    fun check(p: Int): Boolean {
        val v = A[p] + M

        var rest = M * (V - 1L)
        var cnt = 0L

        val b = ArrayList<Long>()

        for (i in A.indices) {
            if (i == p) continue

            if (A[i] > v) {
                rest -= M
                cnt++
            } else if (v - A[i] < M) {
                rest -= v - A[i]
                b.add(M - (v - A[i]))
            } else {
                rest -= M.toLong()
            }
        }

        b.sortDescending()

        for (t in b) {
            if (rest <= 0) break
            cnt++
            rest -= t
        }

        return cnt <= P - 1
    }

    var l = -1
    var u = N - 1

    while (u - l > 1) {
        val c = (l + u) / 2

        if (check(c)) {
            u = c
        } else {
            l = c
        }
    }

    println(N - u)
}


Measured memory_bytes: 80812
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(false); cin.tie(0);
    string s,t;
    cin >> s >> t;
    ll n = s.length(), m = t.length();

    vector<vector<ll>> smap(26);
    for(ll i=0;i<n;++i) {
        smap[int(s[i]-'a')].push_back(i+1);
    }

    ll ans = 0, idx = 0;
    for(ll i=0;i<m;++i) {
        int c = t[i] - 'a';
        if(!smap[c].size()) {
            ans = -1;
            break;
        }
        auto itr = upper_bound(smap[c].begin(), smap[c].end(), idx);
        ll j = 0;
        if(itr == smap[c].end()) {
            j = smap[c][0];
        } else {
            j = *itr;
        }

        if(idx >= j) {
            ans += (n-idx) + j;
        } else {
            ans += j-idx;
        }
        idx = j;
    }

    cout << ans << endl;
}


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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  int left = 200200;
  int right = 0;
  for (int i = 0; i < (n); ++i){
    if(s[i]=='A') left = min(left, i);
  }
  for (int j = n-1; 0 <= j; --j){
    if(s[j]=='Z') right = max(right, j);
  }
  cout << right - left + 1 << endl;
  return 0;
}

Measured memory_bytes: 640
N = int(input())
ans = []

num = N-1
while(True):
  if num >= 26:
    ans.append(num%26)
    num = num//26-1
  else:
    ans.append(num)
    break
answer = ""
for n in ans[::-1]:
  answer += chr(97+n)
print(answer)

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

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  for (auto &e : b) {
    cin >> e;
  }
  int r = 0;
  for (; n > 0; n--) {
    vector<int> a(m);
    for (auto &e : a) {
      cin >> e;
    }
    int s = c;
    for (int i = 0; i < m; i++) {
      s += a[i] * b[i];
    }
    r += s > 0;
  }
  cout << r << endl;
}


Measured memory_bytes: 256
//#define _XCODE_DEBUG

#include <iostream>
#include <math.h>

#ifdef _XCODE_DEBUG
    #include <fstream>
#endif

int main() {
    #ifdef _XCODE_DEBUG
        std::ifstream in("input.txt");
        std::cin.rdbuf(in.rdbuf());
    #endif
    
    // input data
    int D, G, p[11], c[11];
    std::cin >> D >> G;
    for(int i = 0; i < D; ++i) std::cin >> p[i] >> c[i];
 
    int ans = 1e9;
    for (int mask=0; mask<(1<<D); ++mask){
        int s = 0, num = 0, rest_max = -1;
        for (int i=0; i<D; ++i) {
            if (mask & (1<<i)) {
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }else{
                rest_max = i;
            }
        }
        if (s < G){
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if (need >= p[rest_max]) continue;
            num += need;
        }
        ans = std::min(ans, num);
    }
    std::cout << ans << "\n";
}

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

#define MOD 1000000007

int main(){
  int N;
  cin >> N;
  ll ans = 1;
  vi R = {-1}, B = {-1}, G = {-1};
  for(int i = 0; i < N; i++){
    int A;
    cin >> A;
    int counter = 0;
    if(*(R.end()-1) == A - 1) counter++;
    if(*(B.end()-1) == A - 1) counter++;
    if(*(G.end()-1) == A - 1) counter++;

    if(*(R.end()-1) == A - 1) R.push_back(A);
    else if(*(B.end()-1) == A - 1) B.push_back(A);
    else if(*(G.end()-1) == A - 1) G.push_back(A);
    ans *= counter;
    ans %= MOD;
  }
  cout << ans << endl;

}

Measured memory_bytes: 896
import sys
sys.setrecursionlimit(10**9) #上限を１００万回に設定

N, K = map(int, input().split())
h = list(map(int, input().split()))
f_INF = float('inf')
dp = [f_INF]*N
dp[0] = 0
for i in range(N):
    for j in range(1,min(K+1, N-i)):
        dp[i+j] = min(dp[i+j],dp[i] + abs(h[i]-h[i+j]))
print(dp[N-1])

Measured memory_bytes: 55136
N = gets.to_i
h = gets.split.map &:to_i

def rec(h)
	#p h
	if h.size == 1 then
		return h.first
	else
		# 最小値を持つ花で分割
		min = h.min

		i = 0
		new_hs = []
		ps = []
		while i < h.size do
			if h[i] != min then
				ps << h[i] - min
			elsif ps.size > 0 then
				new_hs << Marshal.load(Marshal.dump(ps))
				ps = []
			end
			i += 1
		end
		if ps.size > 0 then
			new_hs << Marshal.load(Marshal.dump(ps))
		end

		# 分割した全ての部分について水やり回数を合計
		#p "new_hs: #{new_hs}"
		result = new_hs.map{|n_h| rec(n_h)}
		#p "result: #{result}"
		return min + result.inject(0, :+)
	end
end

p rec(h)


Measured memory_bytes: 2044
N = int(input())
a = [int(i) for i in input().split()]
id = []

now = 1
br = 0
for j, i in enumerate(a):
  if i == now:
    now += 1
    id.append(j)
  else:
    br += 1

#a = [a[i] for i in id]
if len(id) == 0:
  print(-1)
else:
  print(br)

Measured memory_bytes: 24744
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    calc = c
    a = list(map(int, input().split()))
    for j in range(m):
        calc += a[j] * b[j]
    if calc > 0:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int H, W, K;
int xx1, yy1, xx2, yy2;
string arr[1100000];

int dy[] = { 0, 0, -1, 1 };
int dx[] = { -1, 1, 0, 0 };

int bfs() {
	vector<vector<int>> dist(H, vector<int>(W, 1e9));
	queue<pll> q;
	dist[xx1][yy1] = 0;
	q.push({ xx1, yy1 });

	int cnt = 0;
	while (q.size()) {
		int qsz = q.size();
		while (qsz--) {
			int y, x;
			tie(x, y) = q.front();
			q.pop();

			if (y == yy2 && x == xx2) return dist[x][y];

			for (int i = 0; i < 4; i++) {
				for (int j = 1; j <= K; j++) {
					int ny = y + dy[i] * j;
					int nx = x + dx[i] * j;
					if (ny < 0 || nx < 0 || ny >= W || nx >= H) break;
					if (arr[nx][ny] == '@') break;
					if (dist[nx][ny] <= dist[x][y]) break;
					if (dist[nx][ny] != 1e9) continue;
					q.push({ nx, ny });
					dist[nx][ny] = cnt + 1;
				}
			}
		}
		cnt++;
	}
	return -1;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> H >> W >> K;
	cin >> xx1 >> yy1 >> xx2 >> yy2;
	xx1--, yy1--, xx2--, yy2--;
	for (int i = 0; i < H; i++) cin >> arr[i];

	cout << bfs() << '\n';
	return 0;
}

Measured memory_bytes: 46484
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

string s;
int n;
long long ans;

long long fun(char c, char cl, char cr, int cur)
{
	int sl = 0, sr = 0;
	long long ret = 0;
	for (int i = 0; i < cur; i++) {
		if (s[i] == cl) sl++;
	}
	for (int i = cur + 1; i < n; i++) {
		if (s[i] == cr) sr++;
	}
	ret = sl * 1LL * sr;
	for (int i = 0; i < cur; i++) {
		if (cur + cur - i < n && s[i] == cl && s[cur + cur - i] == cr) ret--;
	}
	return ret;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> s;
	char tmp[3] = { 'R', 'G', 'B' };
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			if (s[i] == tmp[j]) {
				ans += fun(s[i], tmp[(j + 2) % 3], tmp[(j + 1) % 3], i);
				ans += fun(s[i], tmp[(j + 1) % 3], tmp[(j + 2) % 3], i);
			}
		}
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 3644
/*
AizuOnline A1276
Title Prime Gap
*/
#include <stdio.h>
#define PRIME_10MANTH 1299709
#define SQRT_PRIME_10MANTH 1140
#define SQRT_SQRT_PRIME_10MANTH 31

int N;

char prime_f[1299709];

//

int prime_table[]={2,3,5,7,11,13,17,19,23,29,31};
// up to sqrt(sqrt(PRIME_10MANTH))

int isprime(int n)
{
  return(prime_f[n]);
}



void make_furui()
{
  int i,j,p;

  prime_f[0]=prime_f[1]=0;
  for(i=0;i<=SQRT_PRIME_10MANTH;i++)
    prime_f[i]=1;
  for(i=0;i<sizeof(prime_table)/sizeof(int);i++)
    {
      p = prime_table[i];
      prime_f[p]=1;
      for(j=2;prime_table[i]*j<SQRT_PRIME_10MANTH;j++)
	prime_f[p*j]=0;
    }
  //printf("*\n");
}
int next_prime(int x,int limit)
{
        for(++x;x<=limit;x++)
                if(isprime(x))
                        return(x);
        return(0);  // no more prime number
}
void make_furui2()
{
  int i,j,p;

  for(i=SQRT_PRIME_10MANTH;i<=PRIME_10MANTH;i++)
          prime_f[i]=1;
  p=1;
  while(p=next_prime(p,SQRT_PRIME_10MANTH))
  {
          //printf("*%d\n",p);

          prime_f[p]=1;
          for(j=2;p*j<PRIME_10MANTH;j++)
                  prime_f[p*j]=0;
  }
  //printf("*\n");
}

int solve(int N)
{
        int i,j;

        if(isprime(N))
                return(0);
        i=N;
        while(!isprime(i))
                i++;
        j=N;
        while(!isprime(j))
                j--;
        return(i-j);
}
main()
{
        int ret;

        make_furui();
        make_furui2();

        while(EOF!=scanf("%d",&N) && N)
        {
                ret=solve(N);
                printf("%d\n",ret);
        }

return(0);
}

Measured memory_bytes: 1868
n = int(input())

a = list(input().split())

e = []
o = []

for i in range(n):
    if i%2 == 0:
        e.append(a[i])
    else:
        o.append(a[i])

if n%2 == 0:
    o = o[::-1]
    ans = o + e
    print(" ".join(ans))
else:
    e = e[::-1]
    ans = e + o
    print(" ".join(ans))

Measured memory_bytes: 27972
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

using namespace std;

int main()
{
  ll A;
  long double B;
  cin >> A >> B;
  long double ans = A * B;
  cout << fixed << setprecision(0) << floor(ans) << endl;
}

Measured memory_bytes: 3792
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)

const int inf = 1<<29;
int n;
int dp[2][2][5010];
int cut[10010];

/*
  dp[next][0][k+1] = min(dp[cur][0][k])
  dp[next][1][k+1] = min(dp[cur][0][k] + cut[i]);

  dp[next][1][k]   = min(dp[cur][1][k])
  dp[next][0][k]   = min(dp[cur][1][k] + cut[i])
 */
int main(){
    int i,j,k;

    scanf("%d",&n);
    // init
    rep(i,2)rep(j,2)rep(k,5010) dp[i][j][k] = inf;

    // input
    rep(i,n-1) scanf("%d",&cut[i]);

    dp[0][0][0] = 0;
    rep(i,n){
        int cur = i%2, next = (i+1)%2;
        rep(k,5001){
            if( dp[cur][0][k] != inf ){
                dp[next][0][k+1] = min(dp[next][0][k+1], dp[cur][0][k]);
                if( i < n-1 ) dp[next][1][k+1] = min(dp[next][1][k+1], dp[cur][0][k] + cut[i]);
                //printf("dp[%d][1][%d] = %d, dp[cur][0][%d] = %d\n",next,k+1,dp[next][1][k+1],k,dp[cur][0][k]);
            }
            if( dp[cur][1][k] != inf ){
                dp[next][1][k] = min(dp[next][1][k], dp[cur][1][k]);
                if( i < n-1 ) dp[next][0][k] = min(dp[next][0][k], dp[cur][1][k] + cut[i]);
            }
        }
        /*
          rep(j,2)rep(k,4){
          printf("dp[%d][%d][%d] = %d\n",next,j,k,dp[next][j][k]);
          }
          puts("");
        */
        rep(j,2)rep(k,5010) dp[cur][j][k] = inf;
    }

    printf("%d\n",min(dp[n%2][0][n/2],dp[n%2][1][n/2]));

    return 0;
}

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

int main(){
  string s;
  for(int i = 0 ; i < 3 ; i++){
    cin >> s;
    transform(s.begin(), s.begin()+1, s.begin(), ::toupper);
    cout << s[0];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N, K;
	cin >> N >> K;
	vector<char>S(N);

	rep(i, N) {
		cin >> S[i];
	}
	int cnt = 0;
	rep(i, N - 1) {
		if (S[i] == '1' && S[i + 1] == '0') {
			cnt++;
		}
	}
	if (S[N - 1] == '1') {
		cnt++;
	}
	cnt += 2;
	vector<P>V(cnt);
	V[0] = P(0, 0);
	V[cnt-1] = P(N - 1, N - 1);

	int cnt2 = 1;
	rep(i, N-1) {
		if (S[i] == '1' && S[i + 1] == '0') {
			V[cnt2].second = i;
			cnt2++;
		}
	}
	if (S[N - 1] == '1') {
		V[cnt2].second = N - 1;
	}

	cnt2 = 1;
	for (int i = N - 1; i > 0; i--) {
		if (S[i] == '1' && S[i - 1] == '0') {
			V[cnt - cnt2 - 1].first = i;
			cnt2++;
		}
	}
	int ans = 0;

	/*rep(i, cnt) {
		cout << V[i].first << ' ' << V[i].second << endl;
	}*/
	rep(i, cnt) {
		if (i + K < cnt) {
			ans = max(ans, V[i + K].second - V[i].first);
		}
	}
	if (ans == 0&&N>1) {
		cout << N << endl;
		return 0;
	}
	cout << ans+1 << endl;
}


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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

int main(void)
{
  ll a, b;
  cin >> a >> b;
  
  ll g = gcd(a, b);
  //  cout << g << endl;

  set<ll> cd;

  for(ll i = 1; i * i <= g; i++) {
    if(g % i == 0) {
      cd.insert(i);
      cd.insert(g/i);
    }
  }
  
  /*
  for(auto v : cd) {
    cout  << v << " ";
  }
  cout << endl;
  */
  vector<ll> ans;
  
  for(auto itr = cd.begin(); itr != cd.end(); itr++) {
    bool ok = true;
    for(auto itr2 = cd.begin(); itr2 != itr; itr2++) {
      if(gcd(*itr, *itr2) != 1) {
	ok = false;
      }
    }
    if(ok) ans.push_back(*itr);
  }
  /*
  for(auto v : ans) {
    cout << v << " ";
  }
  cout << endl;
  */
  cout << ans.size() << endl;
}


Measured memory_bytes: 512
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, core.bitop;

alias P = Tuple!(int, "s", int, "t");

void main()
{
    auto nc = readln.split.to!(int[]);
    auto N = nc[0];
    auto C = nc[1];
    P[][] cc;
    cc.length = C;
    foreach (_; 0..N) {
        auto stc = readln.split.to!(int[]);
        auto s = stc[0];
        auto t = stc[1];
        auto c = stc[2]-1;
        cc[c] ~= P(s, t);
    }
    foreach (ref c; cc) sort!"a.s < b.s"(c);
    P[] ps;
    foreach (c; cc) {
        foreach (i, p; c) {
            if (i == 0 || c[i-1].t != p.s) {
                ps ~= P(p.s-1, p.t);
            } else {
                ps[$-1].t = p.t;
            }
        }
    }
    auto ts = new int[](10^^5+1);
    foreach (p; ps) {
        ++ts[p.s];
        --ts[p.t];
    }
    int r;
    foreach (i, t; ts[0..$-1]) {
        r = max(r, t);
        ts[i+1] += t;
    }
    writeln(r);
}

Measured memory_bytes: 5116
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
	ll a,b;
	cin >> a >> b;
	if(a%b == 0)
	{
	    cout << 0;
	}
	else
	{
	    if(a > b)
	    {
	        ll c = a%b;
	        if(c <= abs(b-c))
	        {
	            cout << c;
	        }
	        else
	        {
	            cout << abs(b-c);
	        }
	    }
	    else
	    {
	        ll d = a%b ;
	        if(d <= abs(d-b))
	        {
	            cout << d; 
	        }
	        else
	        {
	            cout << abs(d-b);
	        }
	    }
	}
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const int N=3e5+5;
const int mod=1e9+7;

char str[N];
int n,ans,dp[N][3][3];

int main() {
	scanf("%s",str+1),n=strlen(str+1);
	dp[0][0][0]=1;
	for(int i=0;i<n;++i)
		for(int _0=0;_0<3;++_0) for(int _1=0;_1<3;++_1) {
			if(str[i+1]!='0')
				if(_0) (dp[i+1][_0-1][_1]+=dp[i][_0][_1])%=mod;
				else (dp[i+1][_0][min(_1+1,2)]+=dp[i][_0][_1])%=mod;
			if(str[i+1]!='1')
				if(_0>1) (dp[i+1][_0-1][_1]+=dp[i][_0][_1])%=mod;
				else (dp[i+1][_0+1][_1]+=dp[i][_0][_1])%=mod;
		}
	for(int _1=0;_1<3;++_1) for(int _0=0;_0<=_1;++_0) (ans+=dp[n][_0][_1])%=mod;
	printf("%d\n",ans%=mod);
}

Measured memory_bytes: 11136
h,w = map(int, input().split())
power = [list(map(int,input().split())) for i in range(10)]

#ワーシャルフロイド法
for i in range(10):
    for j in range(10):
        for k in range(10):
            power[j][k] = min(power[j][k], power[j][i] + power[i][k])

ans = 0
for i in range(h):
    wall = list(map(int, input().split()))
    for item in wall:
        if item < 0:
            continue
        ans += power[item][1]

print(ans)



Measured memory_bytes: 3064
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

class comb {
private:
  static const long long MAX = 1000000 + 1;    // limit<n>::max()
  static const long long MOD = 1000000000 + 7; // 10**9 + 7

  std::vector<long long> fac, finv, inv;

public:
  comb() : fac(MAX, 0), finv(MAX, 0), inv(MAX, 0) {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < MAX; i++) {
      fac[i] = fac[i - 1] * i % MOD;
      inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
      finv[i] = finv[i - 1] * inv[i] % MOD;
    }
  }

  long long calc(long long n, long long k) {
    if (k < n) {
      return 0;
    }
    if (n < 0 || k < 0) {
      return 0;
    }

    return fac[k] * (finv[n] * finv[k - n] % MOD) % MOD;
  }
};
using ll = long long;
using namespace std;

void solve() {
  ll X, Y;
  cin >> X >> Y;

  ll b = (2 * Y - X) / 3;
  ll a = Y - 2 * b;

  if ((2 * Y - X) % 3 != 0 || b < 0 || a < 0) {
    cout << 0 << endl;
    return;
  }

  comb comb;
  cout << comb.calc(a, a + b) << endl;
}

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


Measured memory_bytes: 23680
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define INF 2000000000
#define PI 3.1415926535897932384626
const ll MOD=1e9+7;
int a[200005];
bool choose[200005];//don't break brick i
int main(){
        int n;
        while(~getI(n)){
                F(i,0,n) getI(a[i]);
                F(i,0,n) choose[i]=0;
                bool impossible=1;
                F(i,0,n) if(a[i]==1) impossible=0;
                if(impossible){
                        puts("-1");
                        continue;
                }
                //greedy?
                int now=1;
                F(i,0,n){
                        if(a[i]==now){
                                choose[i]=1;
                                now++;
                        }
                }
                int ans=0;
                F(i,0,n) if(!choose[i]) ans++;
                printf("%d\n",ans);
        }
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define FLASH cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define FILEIO freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin); freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);

using namespace std;

int h, w;

char s[2001][2001];
int vlas[2001][2001], hlas[2001][2001];
int vnex[2001][2001], hnex[2001][2001];

signed main()
{

 	FLASH

 	cin>>h>>w;

 	fr(i, 1, h + 1){
 		fr(j, 1, w + 1){
 			cin>>s[i][j];
 		}
 	}


 	fr(i, 1, h + 1){
 		int las = 0;
 		fr(j, 1, w + 1){
 			if(s[i][j] == '#') las = j;
 			hlas[i][j] = las;
 		}
 	}
 	

 	fr(i, 1, h + 1){
 		int las = w + 1;
 		for(int j = w; j >= 1; j--){
 			if(s[i][j] == '#') las = j;
 			hnex[i][j] = las;
 		}
 	}


 	for(int j = 1; j <= w; j++){
 		int las = 0;
 		fr(i, 1, h + 1){
 			if(s[i][j] == '#') las =i;
 			vlas[i][j] = las;
 		}
 	}

	fr(j, 1, w + 1){
 		int las = h + 1;
 		for(int i = h; i >= 1; i--){
 			if(s[i][j] == '#') las = i;
 			vnex[i][j] = las;
 		}
 	}

 	int ans = 0;

 	fr(i, 1, h + 1){
 		fr(j, 1, w + 1){
 			if(s[i][j] == '#') continue;
 			ans = max(ans, hnex[i][j] - hlas[i][j] - 1 + vnex[i][j] - vlas[i][j] - 1 - 1);
 		}
 	}


 	cout<<ans;

}

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

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

    string s;
    cin >> s;
    string res = "Yes";
    rep (i, s.size()) {
        if (i % 2 == 0 && s[i] == 'L') res = "No";
        else if (i % 2 == 1 && s[i] == 'R') res = "No";
    }
    cout << res << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a %2 != 0 && b %2 != 0){
		printf("Odd\n");
	}
	else{
		printf("Even\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h> 
#define INF INT_MAX/2;
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long ;

vector<ll>x;

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

   int N,K;
   cin>>N>>K;
   x.resize(N);
   bool flg_left = false,flg_right = false;
   for(int i=0;i<N;i++){
      cin>>x[i];
      if(x[i] < 0)flg_left = true;
      else if(x[i] > 0)flg_right = true;
      else K=-1;
   }
   int left=0,right=0;
   for(int i=0;i<N-1;i++){
      if(x[i] < 0){
         if(0 < x[i+1])
         left = i;
         right = i+1;
      }
   }

   if(flg_right&&!flg_left){
      ll right;
      for(int i=0;i<N;i++){
         if(x[i] > 0){
            right = i;
            break;
         }
      }
      cout<<x[right+K-1]<<endl;
      return 0;
   }

   if(flg_left&&!flg_right){
      ll left;
      for(int i=N-1;i>=0;i--){
         if(x[i] < 0){
            left = i;
            break;
         }
      }
      cout<<-x[left-K+1]<<endl;
      return 0;
   }


   if(K <= 0){
      cout<<0<<endl;
      return 0;
   }

   ll ans = INF;
   //正側にとりあえず行く方
   for(int i=0;i<K-1;i++){
      if(right+i>N-1)continue;
      ll a = 2*x[right+i];
      if(left-(K-(i+1)+1) < 0)continue;
      a += -x[left-(K-(i+1))+1];
      ans = min(a,ans);
   }
   //負側
   for(int i=0;i<K-1;i++){
      if(left-i<0)continue;
      ll a = -2*x[left-i];
      if(right+(K-(i+1)-1) > N-1)continue;
      a += x[right+(K-(i+1))-1];
      ans = min(a,ans);
   }  
   cout<<ans<<endl;
   return 0; 
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cmath>

#define mst(a,b)memset(a, b, sizeof(a))
#define repi(a,b)for(ll i = a; i < b; i++)
#define repj(a,b)for(ll j = a; j < b; j++)
#define pii pair<int,int>

#ifdef LOCAL
#define fre()freopen("in.txt","r",stdin)
#endif
#ifndef LOCAL
#define fre()
#endif

//static int x = []() {
//	std::ios::sync_with_stdio(false);
//	std::cin.tie(NULL);
//	return 0;
//}();

#define FASTIO
#ifdef FASTIO
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//#define scanf abcabc
//#define printf abcabc
#endif
//#ifndef FASTIO
//#define cin abcabc
//#define cout abcabc
//#endif

typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;

using namespace std;


int main() {
	int a, p; cin >> a >> p;
	cout << (a * 3 + p) / 2 << endl;
	return 0;
}

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

#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>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  if(s == "a" || s == "i" || s == "u" || s == "e" || s == "o") cout << "vowel" << endl;
  else cout << "consonant" << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))
#define MAX3(x, y, z) ( (x) > (y)  ? ( (x) > (z) ? (x) : (z)  ) : ( (y) > (z) ? (y) : (z) )  )
#define MIN3(x, y, z) ( (x) < (y)  ? ( (x) < (z) ? (x) : (z)  ) : ( (y) < (z) ? (y) : (z) )  )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))


#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 987654321
#define IINF 987654321987654321

int N,M,K,T;

vector<int> E[100500];

int dfs(int x){
	if( E[x].size() == 0 ) return 0;
	vector<int> v;
	for(auto e : E[x]){
		v.pb(dfs(e));
	}
	sort(all(v));
	int cur = 1; int ret = 0;
	for(int i=v.size()-1;i>=0;i--){
		ret = max(v[i]+cur,ret);
		cur++;
	}
	return ret;
}

int main(void){
	geti(N);

	for(int i=2;i<=N;i++){
		int x; geti(x); E[x].pb(i);
	}

	cout << dfs(1);

}

Measured memory_bytes: 13568
#include <stdio.h>

int parent(int i){
return i / 2;	
}
int left(int i){
return i * 2;	
}
int right(int i){
return i  *2 + 1;	
}

int main(){

    int i, jumlah, H[255];
    scanf("%d", &jumlah);
    for(i = 1; i <= jumlah; i++){
    	scanf("%d", &H[i]);
	}
    
    for(i = 1 ; i <= jumlah ; i++) {
        printf("node %d: key = %d, ", i, H[i]);
        if(parent(i) >= 1) printf("parent key = %d, ", H[i / 2]);
        if(left(i) <= jumlah) printf("left key = %d, ", H[i * 2]);
        if(right(i) <= jumlah) printf("right key = %d, ", H[i * 2 + 1]);
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2092
#include <stdio.h>
#define max(a,b) ((a)>(b)?(a):(b)) //if (a > b) então x = a, senão x = b
#define max3(a,b,c) (max(a,max(b,c))) //if (a)>=(b e c) retorna a, senao maior entre b e c

int main(void)
{
	int n;
	scanf("%d",&n);
	int vc[n][3];
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			scanf("%d",&vc[i][j]);
		}
	}
	
	for(int i=1;i<n;i++)
	{
		for (int j = 0; j < 3; ++j)
		{
			if(j==0)
			{
				vc[i][0]+=max(vc[i-1][1],vc[i-1][2]);
			}
			else if(j==1)
			{
				vc[i][1]+=max(vc[i-1][0],vc[i-1][2]);
			}
			else if(j==2)
			{
				vc[i][2]+=max(vc[i-1][0],vc[i-1][1]);
			}
		}
	}
	printf("%d\n",max3(vc[n-1][0],vc[n-1][1],vc[n-1][2]));
}

Measured memory_bytes: 1408