akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,a,b;
	cin>>n>>a>>b;
	ll ans=n/(a+b)*a;
	n%=(a+b);
	ans+=min(n,a);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;
int main()
{
  ll x,k,d;
  cin>>x>>k>>d;

  x=abs(x);




  ll now=x/d;
  if(k<now){
    cout<<x-k*d<<endl;
    return 0;
  }

  ll place=x%d;
  if((k-now)%2==1)place=min(abs(place+d),abs(place-d));



  cout<<place<<endl;
  return 0;
}


Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,VI(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)

int main() {
  ll n, m, k, x, y , z = 0, h, ans=0, w, sum = 0, Max = -1, Min = 3e9+1;
  string u;
  bool ok=true;
  cin >> n;
  VL a(n);
  rep(i,n) { cin >> a[i]; sum += a[i]; }
  rep(i,n-1){
    z += a[i];
    sum -= a[i];
    chmin(Min,abs(z-sum));
  }
  pri(Min);
  return 0;
}


Measured memory_bytes: 1792
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)

#print(A)

if N%2 == 0:
    print(sum(A[:N//2]) * 2 - A[0])
if N%2 == 1:
    #print(A[:N//2+1],A[N//2+1])
    print(sum(A[:N//2+1]) * 2 - A[0] - A[N//2])
   

Measured memory_bytes: 105172
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]
from itertools import accumulate as acc
MOD = 10**9+7

def main():
    n, k = MII()
    cnt = 0
    dd = [i for i in range(n+1)]
    dd_a = list(acc(dd))
    dd_b = list(acc(dd[::-1]))
    for i in range(k-1,len(dd_a)):
        cnt += dd_b[i]-(dd_a[i]-1)
    print(cnt%MOD)

if __name__ == '__main__':
    main()


Measured memory_bytes: 39628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

struct query{
  ll type;//0=empty, 1=add-sum ,2=set-max
  ll value;
  query(ll a=0,ll b=0):type(a),value(b) {}
};

ll INF=(1LL<<60);

struct segtree{
  ll SIZE;
  vector<query> s;
  vector<ll> t;// sum-add
  vector<ll> u;// max-set

  segtree(ll n=1){
    SIZE=1;
    while(SIZE<n)SIZE*=2;
    s.clear();
    t.clear();
    u.clear();
    s.resize(SIZE*2, query());
    t.resize(SIZE*2, 0);
    u.resize(SIZE*2, 0);
  }
  
  void func(ll k,ll l,ll r,query q){
    if(q.type==1){
      if(s[k].type==0)s[k]=q;
      else s[k].value+=q.value;
      t[k]+=q.value*(r-l);
      u[k]+=q.value;
    }
    if(q.type==2){
      s[k]=q;
      t[k]=q.value*(r-l);
      u[k]=q.value;
    }
  }

  void compute(ll k,ll l,ll r){
    query q=s[k];
    s[k]=query();
    if(q.type==0||r-l==1)return;
    ll m=(l+r)/2;
    func(k*2+1,l,m,q);
    func(k*2+2,m,r,q);
  }

  void Update(ll a,ll b,query x,ll k,ll l,ll r){
    if(b<=l || r<=a)return;
    compute(k,l,r);
    if(a<=l && r<=b){
      func(k,l,r,x);
    }else{
      ll m=(l+r)/2;
      Update(a,b,x,k*2+1,l,m);
      Update(a,b,x,k*2+2,m,r);
      t[k]=t[k*2+1]+t[k*2+2];
      u[k]=max(u[k*2+1],u[k*2+2]);
    }
  }

  ll Dfs(ll type,ll a,ll b,ll k,ll l,ll r){
    if(b<=l || r<=a){
      if(type==1)return 0; //add
      if(type==2)return -INF; // max
    }
    compute(k,l,r);
    if(a<=l && r<=b){
      if(type==1)return t[k];
      if(type==2)return u[k];
    }else{
      ll m=(l+r)/2;
      ll lv=Dfs(type,a,b,k*2+1,l,m);
      ll rv=Dfs(type,a,b,k*2+2,m,r);
      if(type==1)return lv+rv; // add
      if(type==2)return max(lv,rv); // max
    }
  }

  void Add(ll a,ll b,ll x){
    Update(a,b,query(1,x), 0,0,SIZE);
  }
  void Set(ll a,ll b,ll x){
    Update(a,b,query(2,x), 0,0,SIZE);
  }
  ll Getsum(ll a,ll b){
    return Dfs(1,a,b, 0,0,SIZE);
  }

  ll Getmax(ll a,ll b){
    return Dfs(2,a,b, 0,0,SIZE);
  }
  
};

int main() {
  ll n;
  cin >> n;
  vec a(n),h(n);
  for(ll i=0;i<n;i++) cin >> h[i];
  for(ll i=0;i<n;i++) cin >> a[i];
  segtree T(n+1);
  T.Set(0,n+1,0);
  for(ll i=0;i<n;i++) {
    T.Set(h[i],h[i]+1,T.Getmax(0,h[i])+a[i]);
  }
  cout << T.Getmax(0,n+1) << endl;
}

Measured memory_bytes: 22760
h, w = map(int, input().split())
c = []
for i in range(h):#h:高さ
    c.append([str(m) for m in input().split()])
ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in range(h):
    for j in range(w):
        if c[i][j] == "snuke":
            print(ALPHA[j],i + 1,sep="")


Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
  
using namespace std;

#define pi 3.141592653589793

void koch(double sx, double sy, double ex, double ey, int n)
{
	if(n != 0){
		double x1, x2, x3, y1, y2, y3;
		double th = pi * 60.0 /180.0;
		x1 = (2 * sx + ex) / 3;
		y1 = (2 * sy + ey) / 3;
		x3 = (sx + 2 * ex) / 3;
		y3 = (sy + 2 * ey) / 3;
		x2 = (x3 - x1) * cos(th) - (y3 - y1) * sin(th) + x1;
		y2 = (x3 - x1) * sin(th) + (y3 - y1) * cos(th) + y1;
		koch(sx, sy, x1, y1, n - 1);
		printf("%f %f\n", x1, y1);
		koch(x1, y1, x2, y2, n - 1);
		printf("%f %f\n", x2, y2);
		koch(x2, y2, x3, y3, n - 1);
		printf("%f %f\n", x3, y3);
		koch(x3, y3, ex, ey, n - 1);
	}
	return;
}

int main()
{
	int n;
	cin >> n;
	printf("%f %f\n", 0.0, 0.0);
	koch(0.0, 0.0, 100.0, 0.0, n);
	printf("%f %f\n", 100.0, 0.0);
	return 0;
}

Measured memory_bytes: 1188
s = gets.to_s.chomp.bytes
n = s.size

l = 0
r = n - 1

# p "x".ord #=> 120
ans = 0
while l < r
  
  if s[l] == s[r]
    l += 1
    r -= 1
  elsif s[l] == 120
    l += 1
    ans += 1
  elsif s[r] == 120
    r -= 1
    ans += 1
  else
    puts "-1"
    exit
  end
end

puts ans

Measured memory_bytes: 2812
//#pragma comment(linker, "/STACK:102400000,102400000") 
#pragma warning(disable:4996)
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
#include <ctime>
typedef long long ll;
#define eps 1e-10
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)

const int maxn = 1e5 + 5;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	int res = n;
	while (n--)
	{
		int x;
		cin >> x;
		if (x >= a&&x < b)
		{
			res--;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<pair<int, int> > time(n);
        for(int i=0; i<n; ++i){
            cin >> time[i].second;
            time[i].first = 0;
            for(int j=0; j<4; ++j){
                int m, s;
                cin >> m >> s;
                time[i].first += m * 60 + s;
            }
        }
        sort(time.begin(), time.end());

        cout << time[0].second << endl;
        cout << time[1].second << endl;
        cout << time[n-2].second << endl;
    }
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void) {
	// your code goes here
	int a,b,m,ai[100000],bi[100000],i,t=100000,min;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&m);
	for(i=0;i<a;i++){
		scanf("%d",&ai[i]);
		if(t>ai[i]){
			t=ai[i];
		}
	}
	min=t;
	t=100000;
	for(i=0;i<b;i++){
		scanf("%d",&bi[i]);
		if(t>bi[i]){
			t=bi[i];
		}
	}
	min+=t;
	for(i=0;i<m;i++){
		scanf("%d",&a);
		scanf("%d",&b);
		scanf("%d",&t);
		if(min>(ai[a-1]+bi[b-1]-t)){
			min=ai[a-1]+bi[b-1]-t;
		}
	}
	printf("%d",min);
	return 0;
}


Measured memory_bytes: 896
def II(): return int(input())
def MI(): return map(int, input().split())
N=II()
a=[0]*N
x=[[0]*N for i in range(N)]
y=[[0]*N for i in range(N)]
for i in range(N):
  a[i]=II()
  for j in range(a[i]):
    x[i][j],y[i][j]=MI()
    x[i][j]-=1
def check(honest):
  for i in range(N):
    if not honest[i]:
      continue
    for j in range(a[i]):
      if y[i][j]==0 and honest[x[i][j]]:
        return False
      if y[i][j]==1 and not honest[x[i][j]]:
        return False
  return True
def dfs(honest):
  if len(honest)==N:
    if check(honest):
      return sum(honest)
    else:
      return 0
  return max(dfs(honest+[True]),dfs(honest+[False]))
print(dfs([]))

Measured memory_bytes: 9264
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

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


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 4e5 + 5;

int n;
ll a[maxn];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cin>>n;
  for (int i=0; i<n; i++) {
    cin>>a[i];
  }


  int neg=0;
  for (int i=0; i<n; i++) {
    if (a[i]<0) {
      a[i]=a[i]*-1;
      neg++;
    }
  }

  sort(a,a+n);

  ll tot = 0;
  for (int i=0; i<n; i++) {
    tot += a[i];
  }

  if (neg%2 == 1) {
    tot -= 2*a[0];
  }


  out(tot);
  

  return 0;
}


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

int main()
{
	char s; cin >> s;
	if (s == 'A') {
		cout << 'T' << endl;
	}
	else if (s == 'C') {
		cout << 'G' << endl;
	}
	else if (s == 'G') {
		cout << 'C' << endl;
	}
	else if (s == 'T') {
		cout << 'A' << endl;
	}
}


Measured memory_bytes: 256
n = io.read("*n", "*l")
s = io.read()
k = io.read("*n")
z = s:sub(k, k)
for i = 1, n do
  if z == s:sub(i, i) then
    io.write(z)
  else
    io.write("*")
  end
end
io.write("\n")


Measured memory_bytes: 2628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = INT_MAX;

int n,C;
int d[30][30];
int ct[3][30];
int cost[3][30];

bool used[30];
int dfs(int x){
    if(x==3) return 0;
    int ret = INF;
    rep(i,C)if(!used[i]){
        used[i] = true;
        ret = min(ret, dfs(x+1)+cost[x][i]);
        used[i] = false;
    }
    return ret;
}

int main(){
    cin >>n >>C;
    rep(i,C)rep(j,C) cin >>d[i][j];
    rep(i,n)rep(j,n){
        int c;
        cin >>c;
        --c;

        ++ct[(i+j)%3][c];
    }

    rep(i,3)rep(j,C){
        rep(k,C) cost[i][j] += d[k][j]*ct[i][k];
    }

    cout << dfs(0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) ((a+b-1)/(b))
using namespace std;

const int MAX = 100010;
const int MOD = 1000000007;
const int INF = 1e8;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;

// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
//

int main() {
    ll r, d, x2000;
    cin >> r >> d >> x2000;


    ll x = x2000;
    for(int i = 2001; i <= 2010; i++) {
        x = r*x -d;
        cout << x << endl;
    }

    return 0;
}


Measured memory_bytes: 256
using System;

namespace myApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] arr = Console.ReadLine().Split(' ');
            
            int n = int.Parse(arr[0]);
            int a = int.Parse(arr[1]);
            int b = int.Parse(arr[2]);
            int count = 0;
            int total;
            for(int i = 1; i < n + 1; i++)
            {
                int m1 = i % 10;
                int h1 = i / 10;
                if(h1 == 0)
                    total = m1;
                else
                {
                    int m2 = h1 % 10;
                    int h2 = h1 / 10;
                    if(h2 == 0)
                        total = m1 + m2;
                    else
                    {
                        int m3 = h2 % 10;
                        int h3 = h2 / 10;
                        if(h3 == 0)
                            total = m1 + m2 + m3;
                        else
                        {
                            int m4 = h3 % 10;
                            int h4 = h3 / 10;
                            if(h4 == 0)
                                total = m1 + m2 + m3 + m4;
                            else
                            {
                                int m5 = h4 % 10;
                                total = m1 + m2 + m3 + m4 + m5;
                            }
                        }
                    }
                }
                if(total >= a && total <= b)
                    count += i;
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

struct mint {
    const int mod = 1e9 + 7;
    long long x;
    
    mint (long long x = 0) : x((x % mod + mod) % mod) {
        
    }
    
    mint& operator=(const long long a) {
        x = a % mod;
        return *this;
    }
    
    mint& operator=(const mint a) {
        x = a.x % mod;
        return *this;
    }
    
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    
    mint& operator-=(const mint a) {
        if ((x += (mod - a.x)) >= mod) x -= mod;
        return *this;
    }
    
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    
    mint inv() const {
        return pow(mod - 2);
    }
    
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<ll> s(n), t(m);
    rep(i, n) cin >> s[i];
    rep(i, m) cin >> t[i];
    vector<vector<mint>> dp(n + 1, vector<mint>(m + 1, 0));
    rep(i, n + 1) dp[i][0] = 1;
    rep(ii, m + 1) dp[0][ii] = 1;
    reps(i, 1, n + 1) {
        reps(ii, 1, m + 1) {
            dp[i][ii] = dp[i - 1][ii] + dp[i][ii - 1] - dp[i - 1][ii - 1];
            if (s[i - 1] == t[ii - 1]) dp[i][ii] += dp[i - 1][ii - 1];
        }
    }
    cout << dp[n][m].x << endl;
    return 0;
}


Measured memory_bytes: 62976
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);

LL mod = 1e9 + 7;

int main() {
#ifdef LOCAL
  auto start_clock = clock();
  freopen("in", "r", stdin);
#endif

  int n;
  scanf("%d", &n);
  vector<int> a(4, 0);
  while (n--) {
    string s;
    cin >> s;
    if (s == "AC") a[0] += 1;
    else if (s == "WA") a[1] += 1;
    else if (s == "TLE") a[2] += 1;
    else a[3] += 1;
  }
  printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", a[0], a[1], a[2], a[3]);
  
#ifdef LOCAL
 auto end_clock = clock();
 cout << "Time:" << (end_clock - start_clock) / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

Measured memory_bytes: 3788
using System;

namespace ITP1_8_A
{
    class Program
    {
        static void Main()
        {
            string data = Console.ReadLine();
            char[] dataXD = data.ToCharArray();

            for (int i = 0; i < data.Length; i++)
            {
                if (char.IsUpper(data[i])) dataXD[i] = char.ToLower(data[i]);

                else if (char.IsLower(data[i])) dataXD[i] = char.ToUpper(data[i]);
            }
            Console.WriteLine(dataXD);
        }
    }
}

Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
#define double long double
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-6;
const int MOD=1000000007;

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

signed main(){
	int n,w[101],sum = 0,ans = INF,tmp = 0;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> w[i];
		sum += w[i];
	}
	for(int i = 0;i < n;i++){
		tmp += w[i];
		chmin(ans,abs(tmp - (sum - tmp)));
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	int N,L;
	String[] S;
	public void solve() {
		N = nextInt();
		L = nextInt();
		S = new String[N];
		for(int i = 0;i < N;i++){
			S[i] = next();
		}

		Arrays.sort(S);

		for(int i = 0;i < N;i++){
			out.print(S[i]);
		}
		out.println();


	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 8276
# -*- coding: utf-8 -*-
import numpy as np
N, M, C = map(int, input().split())
B = np.array(list(map(int, input().split())))
ans = 0
for i in range(N):
    A = np.array(list(map(int, input().split())))
    if sum(A*B)+C > 0:
        ans+=1

print(ans)


Measured memory_bytes: 12504
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())

using namespace std;
using ll = int64_t;

struct Range {
  ll begin, finish;
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int N;
  cin >> N;
  vector<Range> ranges(N);
  for (auto& range : ranges) {
    ll X, L;
    cin >> X >> L;
    range.begin = X - L;
    range.finish = X + L;
  }
  sort(all(ranges), [](auto lhs, auto rhs) {
    return lhs.finish < rhs.finish;
  });
  ll current_end = numeric_limits<ll>::min(), answer = 0;
  for (auto range : ranges) {
    if (range.begin >= current_end) {
      current_end = range.finish;
      ++answer;
    }
  }
  cout << answer << endl;


  return 0;
}


Measured memory_bytes: 1792
import java.util.*;
 
public class Main {
	public static void main(String args[] ) throws Exception {

		Scanner sc = new Scanner(System.in);
		int N = Integer.valueOf( sc.nextLine().trim() ) ;

		BitSet bs_prime = createPrimes ( 10000000 ) ;
		List<Integer> primes = new ArrayList<>();
		for ( int p=bs_prime.nextSetBit(0) ; p>=0 ; p=bs_prime.nextSetBit(p+1 ) )
			primes.add ( p  ) ;

		long[] t = new long[1] ; 
		func( 1 , 1 , 1 , -1 , primes , N , t ) ;
		System.out.println( t[0] ) ;
		

	}

	public static void func ( long v0 , long v1 , long v2 , int k00 , List<Integer> primes , long n , long[] t ) {
		if ( v0 > n ) return ; 
		t[0] += v0 * v1 * v2 ;
		int k0 = k00 < 0 ? 0 : k00 ;
		for ( int k=k0  ;k<primes.size() ; k++ ) {
			int prime = primes.get(k).intValue() ; 
			if ( v0 * prime > n ) break ; 
			
			if ( k == k00 ) {
				func ( v0 * prime , v1 , v2 + 1 , k , primes , n , t ) ;		


			} else  {
				func ( v0 * prime , v1 *  v2 , 2  , k , primes , n , t ) ;		
			}
		}
	}

	public static BitSet createPrimes( int n ){
		BitSet bs = new BitSet();
		bs.set( 2, n ) ;
		for ( int i=bs.nextSetBit(0) ; i>=0 ; i=bs.nextSetBit(i+1) ) {
			if ( (long) i *i > n ) break ;
			for ( int k=2 ; (long)k*i < bs.length() ; k++ )
				bs.clear(k*i);
		}
		return bs ;
	}
}

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

bool check(char c) {
  if ((c == 'A') || (c == 'T') || (c == 'G') || (c == 'C'))
    return true;
  else
    return false;
}

int main() {
  string s;
  cin >> s;
  int count = 0;
  int ans = 0;
  rep(i, s.length()) {
    if (check(s[i])) count++;
    if ((i == s.length() - 1) || (!check(s[i]))) {
      ans = max(ans, count);
      count = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[114514],b[114514];
int main(){
	ll n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	b[0]=a[0];
	for(int i=1;i<n;i++)b[i]=a[i]+b[i-1];
	ll ans=n;
	for(int i=0;i<n-1;i++){
		if(b[i]*2<a[i+1])ans=n-i-1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5160
A, B, X, Y = map(int, input().split())
P = X-A
Q = Y-B
print("R"*P+"U"*Q+"L"*P+"D"*Q+"L"+"U"*(Q+1)+"R"*(P+1)+"D"+\
"R"+"D"*(Q+1)+"L"*(P+1)+"U")

Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define ll long long
#define pb push_back
#define itr(it, a) for(auto i:a)
int main()
{
string s;
cin>>s;
if(s[s.size()-1]=='s')
 s+="es";
 else
 {
	 s+="s";
 }
 cout<<s<<endl;

return 0;
}


Measured memory_bytes: 3620
#define NODE 0
#define WEIGHT 1
#define COST_IDX 0
#define TIME_IDX 1
#define P_IDX 0
#define Q_IDX 1
#define R_IDX 2
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

int n, m, k;
map<int, map<int, int*> > weights;
int **requests;

bool read_input() {
  cin >> n >> m;
  if (n*m == 0) 
    return false;
  for (int i = 0; i < n; i++) {
    int a, b, c, t;
    cin >> a >> b >> c >> t;
    weights[a][b] = new int[2];
    weights[b][a] = new int[2];
    weights[a][b][COST_IDX] = weights[b][a][COST_IDX] = c;
    weights[a][b][TIME_IDX] = weights[b][a][TIME_IDX] = t;
  }
  cin >> k;
  requests = new int*[k];
  for (int i = 0; i < k; i++) {
    requests[i] = new int[3];
    cin >> requests[i][P_IDX] >> requests[i][Q_IDX] >> requests[i][R_IDX];
  }
  return true;
}

int resolve_request(int i_th) {
  int p, q, r;
  p = requests[i_th][P_IDX];
  q = requests[i_th][Q_IDX];
  r = requests[i_th][R_IDX];

  /* keep track of latest weight_sum of each node since values 
   * in priority queue might not be up to date (since STL prioroty 
   * queue does not support value change, ignore popped itmes
   * that does not match values in this map). */  
  map<int, int> weight_sum_map;
  
  /* starting node has weight_sum of 0 */
  weight_sum_map[p] = 0;

  /* create priority queue and push p into it as the initial element */
  auto cmp = [](int *a, int *b) { return a[WEIGHT] > b[WEIGHT]; };
  priority_queue<int*, vector<int*>, decltype(cmp)> pq(cmp); 
  int *itm = new int[2];
  itm[NODE] = p;
  itm[WEIGHT] = 0;
  pq.push(itm);

  while (!pq.empty()) {
    itm = pq.top(); 
    int weight_sum = itm[WEIGHT];
    int node = itm[NODE];

    /* release allocated mem and remove from priority queue*/
    delete[] itm;
    pq.pop();

    // if q was popped, release all allocated mem and break 
    if (node == q) {
      while (!pq.empty()) {
	itm = pq.top();
	delete[] itm;
	pq.pop();
      }
      break;
    }

    /* ignore if wight_sum value not up to date */
    if (weight_sum != weight_sum_map[node]) {
      continue;
    }
    auto connections = weights[node];
    for (auto itr = connections.begin(); itr != connections.end(); itr++) {
      int adj_node = itr->first;
      int w = itr->second[r]; // get the requested weight type r == 0(cost) or 1(time)
      int new_weight_sum = weight_sum + w;
      if (weight_sum_map.count(adj_node) == 0 || new_weight_sum < weight_sum_map[adj_node]) {
	weight_sum_map[adj_node] = new_weight_sum;
	itm = new int[2];
	itm[NODE] = adj_node;
	itm[WEIGHT] = new_weight_sum;
	pq.push(itm);
      }
    }
  }
  return weight_sum_map[q];
}

void solve() {
  for (int i = 0; i < k; i++)
    cout << resolve_request(i) << endl;
}

void cleanup() {
  for (int i = 0; i < k; i++) {
    delete[] requests[i];
  }
  delete[] requests;
  for (auto itr_a = weights.begin(); itr_a != weights.end(); itr_a++) {
    auto m = itr_a->second;
    for (auto itr_b = m.begin(); itr_b != m.end(); itr_b++) {
      delete[] itr_b->second;
    }
    m.clear();
  }
  weights.clear();
}

int main() {
  while(read_input()) {
    solve();
    cleanup();
  }
  return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#define maxn 200005
using namespace std;
typedef long long ll;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = getchar();c < '0' || c > '9';c = getchar()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = getchar()) res = res * 10 + (c - '0');
  return res * sig;
}
char s[maxn];
int n,bc[maxn];
int main(){
  scanf("%s",s + 1);
  n = strlen(s + 1);
  for(int i = n;i >= 1;i--){
    if(s[i] == 'B' && s[i + 1] == 'C') bc[i] = bc[i + 2] + 1;
    else bc[i] = 0;
  }
  int len = 0,num = 0;
  ll ans = 0;
  for(int i = n - 2;i >= 1;i--){
    if(s[i] == 'A'){
      ans += bc[i + 1];
      if(bc[i + 1] * 2 == len){
        ans += num;
        num += bc[i + 1];
      }else{
        num = bc[i + 1];
      }
      len = 0;
    }else{
      len++;
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 1280
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	REP(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	int mid = INF, ma = 0;
	REP(i, n)ma = max(a[i], ma);
	REP(i, n-1)if(a[i+1] != a[i]) mid = min(mid, a[i+1] - a[i]);
	bool an = false;
	REP(i, n) if(k%mid == a[i]%mid) an = true;
	if(k > ma) an = false;
	if (an) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	
	//cout << ans << endl;
}

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

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

  switch (b) {
    case 'A':
      ans = 'T';
      break;
    case 'T':
      ans = 'A';
      break;
    case 'C':
      ans = 'G';
      break;
    case 'G':
      ans = 'C';
      break;
  }

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

Measured memory_bytes: 256
#include<stdio.h>

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

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

        A[j + 1] = v;
        trace(A, N);

        
    }
}

int main(){
    int N, i, j;
    int A[100];
    scanf("%d", &N);
    for(i = 0; i < N; i++) scanf("%d", &A[i]);

    trace(A, N);
    insertionSort(A,N);

    return 0;
}


Measured memory_bytes: 1964
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール
template <class RandomAccessIterator>
vector<ll> common_prefix(RandomAccessIterator first, RandomAccessIterator last) {
    const size_t sz = last - first;
    vector<ll> prefix(sz, 0);
    for (ll i = 1, j = 0; i < sz; i++) {
        if (i + prefix[i-j] < j + prefix[j]) {
            prefix[i] = prefix[i-j];
        } else {
            ll k = max(0LL, j + prefix[j] - i);
            while (i + k < sz && *(first + k) == *(first + (i+k))) k++;
            prefix[i] = k;
            j = i;
        }
    }
    prefix[0] = sz;
    return prefix;
}

// 処理内容
int main() {

    ll n; cin >> n;
    string s; cin >> s;
    
    ll ans = 0;
    REP(k, n) {
        vector<ll> prefix = common_prefix(s.begin() + k, s.end());
        REP(i, prefix.size()) chmin(prefix[i], i);
        chmax(ans, *max_element(ALL_OF(prefix)));
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 384
import collections
import fractions
from functools import reduce
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    a = input_list()
    ac = collections.Counter(a)
    # 個数が少ない場合は空にする
    ans = 0
    for num, count in ac.items():
        if num < count:
            ans += count - num
        if num > count:
            ans += count
    print(ans)

def input_list():
    return list(map(int, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

if __name__ == "__main__":
    main()


Measured memory_bytes: 90020
S = list(input())

b = S.count("B")
# print(S, b)

ans = 0
n = len(S)
for i, s in enumerate(S):
    # print(i, s)
    if s == "B":
        ans += n - b - i
        b -= 1
        # print(ans, b)
print(ans)



Measured memory_bytes: 4840
import java.util.*;
 
// ABC 6-C
// http://abc006.contest.atcoder.jp/tasks/abc006_3
 
public class Main {
	
	public static void main (String[] args) throws java.lang.Exception {
	    Scanner in = new Scanner(System.in);

	    int n = in.nextInt();
	    int m = in.nextInt();
	    
	    int[][] students = new int[n][2];
	    int[][] checks = new int[m][2];
	    
	    for (int i = 0; i < n; i++) {
	    	students[i][0] = in.nextInt();
	    	students[i][1] = in.nextInt();
	    }
	    for (int i = 0; i < m; i++) {
	    	checks[i][0] = in.nextInt();
	    	checks[i][1] = in.nextInt();
	    }
	    
	    for (int i = 0; i < n; i++) {
	    	int check = -1;
	    	int d = Integer.MAX_VALUE;
	    	
	    	for (int j = 0; j < m; j++) {
	    		int tempd = Math.abs(students[i][0] - checks[j][0]) + Math.abs(students[i][1] - checks[j][1]);
	    		if (tempd < d) {
	    			check = j;
	    			d = tempd;
	    		}
	    	}
	    	System.out.println(check + 1);
	    }
	}
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n = 3;
  vector<vector<int>> c(n,vector<int>(n));
  rep(i,n){
    rep(j,n){
      cin >> c[i][j];
    }
  }
  
  bool ok = true;
  rep(i,n-1){
    if(c[i][1]-c[i][0] != c[i+1][1]-c[i+1][0]) ok = false;
    if(c[i][2]-c[i][1] != c[i+1][2]-c[i+1][1]) ok = false;
    if(c[1][i]-c[0][i] != c[1][i+1]-c[0][i+1]) ok = false;
    if(c[i][2]-c[i][1] != c[i+1][2]-c[i+1][1]) ok = false;
  }

  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3580
H, W = gets.split(' ').map(&:to_i)
str = $stdin.read
map = Array.new(H + 2) do |h|
  if h == 0 || h == H + 1
    Array.new(W+2, -2)
  else
    Array.new(W+2) do |w|
      (w == 0 || w == W + 1) ? -2 : -1
    end
  end
end
blacks = []
result = 0
# dxy = [[0,1],[1,0],[0,-1],[-1,0]]
BYTE_BLACK = "#".getbyte(0)
BYTE_DOT = ".".getbyte(0)
i = 0
str.bytes do |byte|
  if byte == BYTE_BLACK
    h = (i / W) + 1
    w = (i % W) + 1
    map[h][w] = 0
    blacks.push([h, w])
    i += 1
  elsif byte == BYTE_DOT
    i += 1
  end
end

while(q = blacks.shift) do
  h, w = q
  result = map[h][w]
  if map[h+1][w] == -1
    map[h+1][w] = map[h][w] + 1
    blacks.push([h+1,w])
  end
  if map[h-1][w] == -1
    map[h-1][w] = map[h][w] + 1
    blacks.push([h-1,w])
  end
  if map[h][w+1] == -1
    map[h][w+1] = map[h][w] + 1
    blacks.push([h,w+1])
  end
  if map[h][w-1] == -1
    map[h][w-1] = map[h][w] + 1
    blacks.push([h,w-1])
  end
  # この書き方だとだいぶ遅くなる
  # 4.times do |i|
  #   y, x = h + dxy[i][0], w + dxy[i][1]
  #   next unless map[y][x] == -1
  #   result = map[h][w] + 1 if result >= map[h][w]
  #   map[y][x] = result
  #   blacks.push [y,x]
  # end
end
puts result

Measured memory_bytes: 66044
A, B, C = map(int, input().split())
L = sorted([A,B,C])
Min = L[0]
Med = L[1]
Max = L[2]

cnt = 0
while Max-Min > 1:
    cnt += 1
    Min += 2
while Max-Med >1:
    cnt += 1
    Med += 2
if Min == Max and Max == Med:
    print(cnt)
elif Min+1 == Max and Med+1 == Max:
    print(cnt+1)
else:
    print(cnt+2)

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

int main()
{
	bool f=false;
	string str;
	stringstream ss;

	getline(cin,str);
	for(int i=0; i<str.size(); i++)
	{
		if(str[i]==',' || str[i]=='.') str[i]=' ';
	}
	ss << str;

	while(ss >> str)
	{
		if(3<=str.size() && str.size()<=6)
		{
			if(f) cout << " "; f=true;
			cout << str;
		}
	}
	cout << endl;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
#define endl "\n"
#define MOD 1000000007
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int 
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//               When something is important enough, you do it even if the odds are not in your favor.

int main(){   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      LLI a,b,c,k;cin>>a>>b>>c>>k;
      LLI sum=0;
      sum+=min(a,k);
      k-=min(a,k)+b;
      if(k>0) {sum-=min(c,k);}
      cout<<sum;
    }
    return 0;
}

Measured memory_bytes: 3160
a,b,c,x,y=map(int,input().split())
d={x:a,y:b}
if a+b >= 2*c:
    if d[max(x,y)] >= 2*c:
        print(max(x,y)*2*c)
    else:
        print(min(x,y)*2*c + abs(x-y)*d[max(x,y)])
else:
    print(a*x + b*y)

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD ((ll)1e9+7)
ll N,K;
ll C[2020][2020];
ll i,j,ans;
int main(){
    scanf("%lld%lld", &N,&K);

    C[0][0]=1;
    fornum(i,0,N){
        C[i + 1][0] = 1;
        fornum(j,0,N){
            C[i + 1][j + 1] = (C[i][j] + C[i][j + 1]) % MOD;
        }
    }
    fornum(i,1,K+1){
        j = 0;
        printf("%lld\n", C[N-K + 1][i] * C[K - 1][i - 1] % MOD);
    }
    
    return 0;
}

Measured memory_bytes: 31872
// abc124_b
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int n,maxH,h,cnt=1;
  cin>>n;
  cin>>maxH;
  rep(i,n-1){
    cin>>h;
    if (maxH<=h) {
      maxH=h;
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOZ
{
	class MainClass
	{
		static void Main(string[] args)
		{
			var n = Console.ReadLine();
			var source = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int min = 1000000, max = -1000000;long sum = 0;
			foreach (var i in source)
			{
				if (min > i) min = i;
				if (max < i) max = i;
				sum += i;
			}
			Console.WriteLine($"{min} {max} {sum}");
		}
	}
}



Measured memory_bytes: 20560
#include <stdio.h>
#include <math.h>

typedef struct Point{
    double x;
    double y;
} Point;

void koch(int d, Point p1, Point p2){
    if (d == 0) return;
    Point s, u, t;
    // [calc points]
    // --- s ---
    s.x = (2*p1.x + p2.x) / 3;
    s.y = (2*p1.y + p2.y) / 3;
    // --- t ---
    t.x = (p1.x + 2*p2.x) / 3;
    t.y = (p1.y + 2*p2.y) / 3;
    // --- u ---
    double th = M_PI * 60.0 / 180.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
    // 常に水平ではないため、下記はNG
    // u.x = (p1.x + p2.x) / 2;
    // u.y = p1.y + ((p2.x - p1.x) / 3.0) * sin(M_PI * 60.0 / 180.0);
    // [recursive]
    koch(d - 1, p1, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(d - 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(d - 1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(d - 1, t, p2);
}

int main(){
    int n;
    scanf("%d", &n);
    Point p1 = {0.0, 0.0};
    Point p2 = {100.0, 0.0};

    printf("%.8f %.8f\n", p1.x, p1.y);
    koch(n, p1, p2);
    printf("%.8f %.8f\n", p2.x, p2.y);

    return 0;
}




Measured memory_bytes: 2684
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N, T := nextInt(), nextInt()
	t := make([]int, N)
	for i := 0; i < N; i++ {
		t[i] = nextInt()
	}

	ans := 0

	for i := 0; i < N-1; i++ {
		if t[i+1] >= t[i]+T {
			ans += T
		} else {
			ans += t[i+1] - t[i]
		}
	}

	ans += T
	fmt.Println(ans)

}


Measured memory_bytes: 4608
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


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

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

	if (a > b) swap(a, b);
	REP(i, b) cout << a;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define forn(i,a,b) for(int i=a; i<=b; i++)
#define MOD 1000000007
using namespace std;
long long int n,m,w[101],v[101],dp[200][200001];
int main(){
	cin>>n>>m;
	forn(i,1,n) cin>>w[i]>>v[i];
	forn(i,1,n){
		forn(j,0,m){
			if(j>=w[i]) dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
			else dp[i][j]=dp[i-1][j];
		}
	}
	cout<<dp[n][m]<<"\n";
}

Measured memory_bytes: 156416