akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <iostream>
using namespace std;
int main(void)
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (a > 0 && c > 0)
    {
        a -= d, c -= b;
    }
    if (a > 0 || (a <= 0 && c <= 0))
        cout << "Yes";
    else
        cout << "No";

    return 0;
}


Measured memory_bytes: 3676
from fractions import gcd

n = int(input())
a = [int(v) for v in input().split(" ")]

L = [0]
R = [0]

for i in range(0, n):
    L.append(gcd(L[-1], a[i]))
    R.append(gcd(R[-1], a[-i - 1]))
R.reverse()

ans = 0
for i in range(0, n):
    ans = max(ans, gcd(L[i], R[i + 1]))

print(ans)


Measured memory_bytes: 16136
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#ifdef DEBUG
std::ostream& dout = cout;
#else
stringstream dout;
#endif
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    int n;
    cin>>n;
    cout<<(n-1)/2+1<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;




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

	int n, i, j, k, a, b, c, ct;
	cin >> n >> k;
	vector<int> v(n);
	for (i = 0; i < n; i++) cin >> v[i];

	a = 1; b = 1000000000;
	while (a < b) {
		c = (a + b) / 2;

		ct = 0;
		for (auto p : v) {
			if (p % c == 0) ct += (p / c) - 1;
			else ct += p / c;
		}

		if (ct <= k) b = c;
		else a = c + 1; 
	}

	cout << a << "\n";


	return 0;
}


Measured memory_bytes: 3556
N = int(input())
ans = float('inf')
print(0)
s = input()
if s == "Male":
	pre = 1
elif s == "Female":
	pre = 0
else:
	ans = 0

if ans == 0:
	exit(0)

ran = [0,N-1]
for i in range(19):	
	n = (ran[1] - ran[0]) // 2
	print(ran[0] + n)
	s = input()
	if s == "Male":
		flg = 1
	elif s == "Female":
		flg = 0
	else:
		exit(0)

	if (pre + n) % 2 != flg:
		ran[1] = ran[0] + n - 1
	else:
		ran[0] = ran[0] + n + 1
		pre = (flg + 1) % 2

Measured memory_bytes: 3660
from math import gcd
K = int(input())
ans = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      ans1 = gcd(a, b)
      ans1 = gcd(ans1, c)
      ans += ans1
print(ans)

Measured memory_bytes: 67808
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll K = 1000000000;

int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    ll N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    B -= A;
    A = 0;
    REP(i,N){
        ll Cx = C*i;ll Dx = D*i;
        Cx -= (N - 1 -i) * D;
        Dx -= (N - 1 -i) * C;
        if(Cx <= B && B <= Dx){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<long long>v,vc;
multiset<pair<long long,long long> >st,stt;
multiset<pair<long long,long long> >::iterator it,jt;
long long vis[100005];
int main()
{
    long long a,b,c,d,i,j,n,k,tm,mx=0,f,g=0,ans;
    cin>>n>>k;
    for(i=0; i<n; i++)
    {
        cin>>a>>b;
        v.push_back(b);
        vc.push_back(a);
        st.insert({-1*b,a});

    }
    a=0;
    f=0;
    g=0;
    while(a<k)
    {
        it=st.begin();
        d=it->second;
        f=it->first;
        if(!vis[d])
        {
            vis[d]=1;
            mx+=-1*f;
            g++;
        }
        else
        {
            mx+=-1*f;
            stt.insert({-1*f,d});

        }
        a++;
        st.erase(it);
    }
    ans=mx+g*g;
    it=st.begin();
    while(it!=st.end()){
        d=it->second;
        f=it->first;
        if(!vis[d]&&stt.size()){
            jt=stt.begin();
            c=jt->first;
            mx-=c;
            stt.erase(jt);
            mx+=-1*f;
            g++;
            vis[d]=1;
        }
        it++;
        ans=max(ans,g*g+mx);
    }
    cout<<ans<<'\n';


    return 0;



}


Measured memory_bytes: 8808
from collections import Counter
N=int(input())
A=[int(a) for a in input().split()]
MOD=10**9+7

C=Counter(A)
i=1+(N&1)
while i<=N-1:
    if C[i]!=2:
        print(0)
        exit()
    i+=2

print(pow(2,N//2,MOD))


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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int ans = 0;
  if(A < C){
	if(C < B && B <= D){
      ans = B - C;
    }else if(D < B){
      ans = D - C;
    }
  }else if(C < A){
    if(A < D && D<= B){
	  ans = D - A;
    }else if(B < D){
	  ans = B - A;
    }
  }else{
    if(B <= D){
      ans = B - A;
    }else{
      ans = D - C;
    }
  }
  
  cout << ans << endl;
}

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

int a[105];

int main(){
#ifdef LOCAL
	freopen("inp.txt", "r", stdin );
	freopen("ans.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	n *= 2;
	for(int i=0; i<n; i++) cin >> a[i];
	sort(a, a+n);
	int s = 0;
	for(int i=0; i<n-1; i+=2) s += a[i];
	cout << s << '\n';
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll A, B;
  cin >> A >> B;
  ll ans = 0;
  ans = A / gcd(A, B) * B;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
def examA():
    N = I()
    ans = N//3
    print(ans)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examA()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

//Template by yosupo
template <uint MD>
struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(_v % MD + MD); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(ull(v) * r.v % MD); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1)
                r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<MOD>;

int N, x[101010];

Mint t[101010];
Mint y[101010];
Mint S[101010];
Mint one = 1;
Mint d[101010];

void solve() {
    Mint ans = 0;
    Mint SUM = 1;
    FOR(i, 1, N)
    SUM *= i;
    FOR(N + 1) {
        Mint I = i;
        S[i] = S[i - 1] + one / I;
    }
    FOR(i, 1, N) {
        d[i] = x[i] - x[i - 1];
    }
    FOR(i, 1, N) {
        Mint tmp = one * (S[i]);
        //cout << tmp * SUM << endl;
        ans += tmp * d[i];
    }
    FOR(i, 1, N) {
        ans *= i;
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(N)
    cin >> x[i];
    solve();
    return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;

  cout << (char)(s1[0] - 'a' + 'A') << (char)(s2[0] - 'a' + 'A') << (char)(s3[0] - 'a' + 'A') << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define endl "\n"
#define fr(i, n) for (int i = 0; i < n; i++)
#define frf(i, j, n) for (int i = j; i <= n; i++)
#define frd(i, n) for (int i = n; i >= 0; i--)
#define mp(i, j) make_pair(i, j)
#define pb(x) push_back(x)
#define PRIME 1000000007
#define max 200006
// bool a[max];
using namespace std;
typedef vector<vector<ll>> matrix;
// ll e[max], f[max];
int main()
{
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    // int t;
    // cin >> t;
    // while (t--)
    // {

    // }
    // int k;
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double ah = 0.5 * (60 * h + m);
    double am = 6 * (m);
    double ac = 0;
    if (ah > am)
        ac = ah - am;
    else
        ac = am - ah;
    double ans = sqrt(double(a * a) + double(b * b) - double(double(2 * a * b) * cos(double(ac) * (3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095)/180)));
    printf("%.11f", ans);
}

Measured memory_bytes: 4148
#include <iostream>
#include <stdio.h>
#include <cmath>

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

typedef long long ll;

using namespace std;

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

  double ans = 0;
  for(int i=1;i<=N;i++){
    int x = ceil(log2(1.*K/i));
    if(i>=K){
      ans+=1./N;
      continue;
    }
    ans += 1. / (N*pow(2,x));
  }
  printf("%.10f", ans);
}


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

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    ll n; cin >> n;
    vector<vector<ll>> dist(n,vector<ll>(n));
    rep(i,n) rep(j,n) cin >> dist[i][j];

    ll ans = 0;
    bool check = true;
    rep(i,n) rep(j,n) rep(k,n) {
        if(i == j) continue;
        if(dist[i][j] > dist[i][k] + dist[k][j]){ cout << -1 << endl; return 0; }
        if( !( i == k || k == j || dist[i][j] < dist[i][k] + dist[k][j] ) ) check = false;
        if(k == n-1 && check) ans += dist[i][j];
        if(k == n-1) check = true;
    }
    cout << ans/2 << endl;
    return 0;
}

Measured memory_bytes: 4328
/**
*    created: 23.05.2020 02:43:28
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<int> ch(m);
    rep(i,n) {
        int k;
        cin >> k;
        rep(j,k) {
            int a;
            cin >> a;
            ch[a-1]++;
        }
    }
    int cnt = 0;
    rep(i,m) {
        if (ch[i] == n) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main() {
  int N, K, T, U, V, L;
  scanf("%d %d %d %d %d %d", &N, &K, &T, &U, &V, &L);

  std::vector<int> D(N+1, -1);
  for (int i=0; i<N; ++i)
    scanf("%d", &D[i]);

  std::vector<int> C(L+1);
  int num_carrot=0, carrot_index=0, turbo=0;
  for (int i=1; i<=L; ++i) {
    if (i == D[carrot_index]) {
      ++num_carrot;
      ++carrot_index;
      if (num_carrot > K) {
        --num_carrot;
        turbo = T * V;
      }
    }

    if (num_carrot && !turbo) {
      --num_carrot;
      turbo = T * V;
    }

    if (turbo) {
      --turbo;
      C[i] = 1;
    }
  }

  int v=std::count(C.begin(), C.end()-1, 1), u=L-v;
  printf("%.12f\n", u*1.0/U+v*1.0/V);
  return 0;
}   

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

int main(){
    int n;
    std::string s;
    std::cin>>n;
    std::cin>>s;
    std::size_t tmp=0;
    for(int i=0;i<n;++i){
        for(int k=i+1;k<n;++k){
            int t = k+k-i;
            if(t < n && s[i]!=s[k] && s[i]!=s[t] && s[k]!=s[t] ){
                tmp+=1;
            }
        }
    }
    std::size_t c1 = std::count(s.begin(),s.end(),'R') ;
    std::size_t c2 = std::count(s.begin(),s.end(),'G') ;
    std::size_t c3 = std::count(s.begin(),s.end(),'B') ;

    std::cout<<(c1*c2*c3)-tmp;
}

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

using namespace std;

int main()
{
    int k, x, i;
    cin >> k >> x;
    for(i = k - 1; i >= 1 ; i--)
    {
        cout << x - i << " ";
    }
    for(i = 0; i < k ; i++)
    {
        if(i == k - 1){
        cout << x + i << " ";
        }else{
        cout << x + i << " ";
        }
    }
    return 0;
}


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

int main()
{
    int n, m;
    static int deg[100000 + 10];
    std::cin >> n >> m;
    for (int i = 1; i <= m; ++ i) {
        int u, v;
        std::cin >> u >> v;
        deg[u] ^= 1;
        deg[v] ^= 1;
    }
    for (int i = 1; i <= n; ++ i) if (deg[i]) return puts("NO"), 0;
    puts("YES");
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 200000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long int

struct edge {int to, cost; };
vector<edge> G[200010];
int L[200010];

void dfs(int V, int prev, int cost) {
    L[V] = cost;
    //cout << "L[" << V << "] = " << L[V] << endl;
    rep(i, G[V].size()) {
        if (L[G[V][i].to] != INF) continue;
        dfs(G[V][i].to, V, cost + G[V][i].cost);
    }
}
 
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    if(M == 0) {
        cout << "Yes" << endl;
        return 0;
    }
    int a[M], b[M], c[M];
    rep(i, M) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        G[a[i]].push_back({b[i], c[i]});
        G[b[i]].push_back({a[i], -c[i]});
    }
    rep(i, 200010) L[i] = INF;
    rep(i, M) {
        if (L[b[i]] == INF) dfs(a[i], -1, 0);
    }
    rep(i, M) {
        //cout << "L[" << i << "] = " << L[i] << endl;
    }
    rep (i, M){
        //dump(L[a[i]]); dump(L[b[i]]); 
        if (L[b[i]] - L[a[i]] != c[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 24320
def judge(s):
    N = len(s)
    if s != s[::-1]:
        return False
    s1 = s[:N // 2]
    if s1 != s1[::-1]:
        return False
    s2 = s[(N + 1) // 2:]
    if s2 != s2[::-1]:
        return False
    return True


S = input()
print('Yes' if judge(S) else 'No')

Measured memory_bytes: 38384
#include<stdio.h>
int main(void)
{
	int x,y,z,n,i;
	scanf("%d %d",&x,&y);
	n=0;
	for(i=1;i<=x;i++){
		z=i*y%x;
		if(z==0){
			n++;
		}
	}
	z=x+1+y-n;
	printf("%d\n",z);
	return 0;
}


Measured memory_bytes: 2740
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.14159265359
using namespace std;


ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

//const string k = "enterstringtobechecked";



int main()
{
    SYNC
    //clock_t tStart = clock();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n; in(n);
    vl v(n);
    l(i,0,n)
    {
        in(v[i]);
    }
    ll ans=0,sum=0;
    ll MOD = 1e9 + 7;
    l(i,0,n)
    {
        ans+= (ll)(v[i]*sum);
        ans %= MOD;
        sum+= v[i];
        sum %=MOD;
    }
    o(ans)<<endl;








   // printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);   
}


Measured memory_bytes: 4784
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

Query = raw_input()
Query = Query.split('.')[1:]

lst = []
m = {}

for line in sys.stdin:
    key, value = line[:-1].split(":")
    rank = key.count(' ')
    key = key[rank:]
    index = len(lst)
    for i in range(len(lst)):
        if rank == lst[i][0]:
            index = i
            break
    lst = lst[:index]
    ms = m
    for p in lst:
        ms = ms[p[1]]
    if value == '':
        ms[key] = {}
    else:
        ms[key] = value
    lst.append((rank, key))

try:
    ms = m
    for key in Query:
        ms = ms[key]
    if type(ms) == type(''):
        print 'string "' + ms[1:] + '"'
    else:
        print 'object'
except:
    print 'no such property'


Measured memory_bytes: 5200
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int p = 0;

        int max = 0;
        int total = 0;
        for (int i = 0; i < n; i++) {
            p = sc.nextInt();
            total += p;
            max = Math.max(max, p);
        }

        total -= max / 2;
        System.out.println(total);
    }
}


Measured memory_bytes: 23252
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int x=sc.nextInt();
		int a[]=new int[n];
		for (int i = 0; i < n; i++) {
			a[i]=sc.nextInt();
		}
		long ans=0;
		if(a[0]>x){
			ans+=a[0]-x;
			a[0]-=ans;
		}
		for (int i = 0; i < n-1; i++) {
			if(a[i]+a[i+1]>x){
				ans+=Math.min(a[i]+a[i+1]-x,a[i+1]);
				a[i+1]-=Math.min(a[i]+a[i+1]-x,a[i+1]);;
			}
		}
		System.out.println(ans);
		
	
	}
	
}

Measured memory_bytes: 33224
#include "bits/stdc++.h"
using namespace std;

int N, W;
long long w[100005], v[100005];
long long dp[105][100005];

// dp[i][j] = max val from 0 to i with weight j

long long rec(int d, int wght)
{
    if (wght < 0)
        return LLONG_MIN;

    // if d == 0, then it compulsarily takes v[0]
    if (d == -1)
    {
        if (wght >= 0)
            return 0;
        else
            return LLONG_MIN;
    }

    if (dp[d][wght] != -1)
        return dp[d][wght];

    long long val1 = rec(d - 1, wght - w[d]) + v[d];
    long long val2 = rec(d - 1, wght);
    dp[d][wght] = max(val1, val2);
    return dp[d][wght];
}

int main()
{
    cin >> N >> W;
    for (int i = 0; i < N; i++)
        cin >> w[i] >> v[i];

    for (int i = 0; i < N; i++)
        for (int j = 0; j <= W; j++)
            dp[i][j] = -1;

    long long ans = rec(N - 1, W);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 80128
#include <cstdio>
#include <algorithm>
using std::sort;

int main(void)
{
  int *a,N;
  scanf("%d",&N);
  a=new int [N];
  for(int i=0;i<N;i++)
    scanf("%d",&a[i]);
 sort(a,a+N);
  printf("%d\n",a[N-1]-a[0]);

  return 0;
}

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

int findSumOfDigits(int n){
  int sum = 0;
	while(n>0){
      sum += n%10;
      n /= 10;
    }
	return sum;
}

int main() {
  int N;
  cin >> N;
  int min = 1000;

  for(int i=1; i<=N/2; i++){
    int sum = findSumOfDigits(i) + findSumOfDigits(N-i);
    if (sum < min){
      min = sum;
    }
  }
  
  cout << min << endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef unsigned long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

int main(){
    int H1,M1,H2,M2,K;
    cin>>H1>>M1>>H2>>M2>>K;
    cout<<H2*60+M2-H1*60-M1-K<<endl;
    return 0;
}

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

int main()
{
    int n, l;
    vector<string> s;
    cin >> n >> l;
    s.resize(n);
    for(auto it = s.begin(); it != s.end(); ++it)   cin >> *it;
    ::sort(s.begin(), s.end());
    for(auto it = s.begin(); it != s.end(); ++it)   cout << *it;
    cout << endl;
    return 0;
}


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

int main(){
    int D,G;
    cin >> D >> G;
    vector<int> p(D);
    vector<int> c(D);
    for(int i=0;i<D;i++){
        cin >> p[i] >> c[i];
    }

    int ans=1e9;
    for(int mask=0;mask<(1<<D);mask++){
        int sum=0;
        int num=0;
        int rest_max=-1;
        for(int i=0;i<D;i++){
            if(mask & (1<<i)){
                sum += 100*(i+1)*p[i] + c[i];
                num += p[i];
            }else{
                rest_max=i;
            }
        }
        if(sum<G){
            int sum1 = 100*(rest_max+1);
            int need = (G-sum+sum1-1)/sum1;
            if(need>=p[rest_max]) continue;
            num += need;
        }
        ans = min(ans,num);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    s=sum(A)

    while(max(A)>=n):
        k=sum(a//n for a in A)
        for i in range(n):
            A[i]+=(k-A[i]//n)-n*(A[i]//n)

    print(s-sum(A))
resolve()

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

#define int long long
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); i++)  
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rap(i,a,n) for (int i = a; i < (n); i++) 
#define rrap(i,n,a) for (int i = (n)-1; i >= a; i--) 
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807

typedef vector<int> vi;  
typedef pair<int,int> ii;  
typedef vector<ii> vii;  
typedef list<int> li;  
typedef unordered_map<int,int> mii;

//N coins are given, each with a probability of rolling heads equal to p_i.
//N is odd. Calculate the probability that in the end, heads are more than tails.

vector<double> dp,dp2;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    double p;

    dp.assign(3000,0);
    dp2.assign(3000,0);
    dp[0] = 1;
    dp2[0] = 1;

    rep(i,n) {
        cin >> p;
        dp2[0] = dp[0] * (1-p);
        dp2[i+1] = dp[i] * p; 
        rap(j,1,i+1) {
            dp2[j] = dp[j]*(1-p) + dp[j-1]*p;
        }
        dp = dp2;
    }

    double count = 0;
    rap(i,n/2 + 1, n+1) {
        count += dp[i];
    }
    cout << setprecision(10);
    cout << count << '\n';


    return 0;
    //compile: g++ -std=c++14 -O2 -Wall NAME.cpp -o NAME
}

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


int main(){

    int a,b,c;
    cin >> a >> b >> c;
    if(a == b){
        cout << c << endl;
    }
    if(b == c){
        cout << a << endl;
    }
    if(a == c){
        cout << b << endl;
    }
   


   

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<int> x(N);
  vector<int> y(N);
  vector<int> h(N);
  rep(i, N)
  {
    cin >> x[i] >> y[i] >> h[i];
  }

  rep(i, 101)
  {
    rep(j, 101)
    {
      int diff = -1;

      bool found = true;
      rep(k, N)
      {
        if (h[k] == 0)
        {
          continue;
        }
        int tmp = h[k] + std::abs(i - x[k]) + std::abs(j - y[k]);
        if (diff == -1)
          diff = tmp;
        if (diff != tmp)
        {
          found = false;
          break;
        }
      }

      if (found)
      {
        int X = i;
        int Y = j;
        int H;
        bool correct = true;
        rep(k, N)
        {
          if (h[k] != 0)
          {
            H = h[k] + std::abs(X - x[k]) + std::abs(Y - y[k]);
            break;
          }
        }
        rep(k, N)
        {
          if (h[k] != std::max(0, H - std::abs(X - x[k]) - std::abs(Y - y[k])))
          {
            correct = false;
            break;
          }
        }
        if (correct)
        {
          cout << X << " " << Y << " " << H << endl;
          return 0;
        }
      }
    }
  }

  return 0;
}


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

ll sum(int n,ll arr[],ll v[]){
	if(n==1)return 0;
	if(n<1)return 1000000000;
	ll nun=10000000000;
	if(v[n]<0){
		for (int i = 1; i <= k; ++i)
		{
nun=min(nun,sum(n-i,arr,v)+abs(arr[n]-arr[n-i]));
		}
	 v[n]=nun;
	}
	return v[n];
}

int main() {

ll n;
cin>>n>>k;
k=min(n,k);
ll arr[n+1];
ll v[n+1]={-1};
memset(v,-1,sizeof(v[0])*(n+1));
for (int i = 1; i <=n; ++i)
{
	cin>>arr[i];
}
cout<<sum(n,arr,v);

}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    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;
    }

    // for prime mod
    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;
    }
};


ll dfs(ll from, ll parent, vector<vector<ll>> &tos, vector<ll> &child_count) {

    ll total = 1;
    for (ll next : tos[from]) {
        if (next == parent) continue;
        ll count = dfs(next, from, tos, child_count);
        total += count;
    }
    child_count[from] = total;
    return total;
}

int main() {
    ll n;
    cin >> n;
    vector<P> edges;

    vector<vector<ll>> tos(n);
    rep(i, n - 1) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        edges.emplace_back(a, b);
        tos[a].push_back(b);
        tos[b].push_back(a);
    }

    vector<ll> child_count(n);
    dfs(0, -1, tos, child_count);

    vector<mint> pow(n + 1), inv(n + 1);
    pow[0] = 1;
    inv[0] = 1;
    rep(i, n) {
        pow[i + 1] = pow[i] * 2;
        inv[i + 1] = pow[i + 1].inv();
    }

    mint ev = 1;
    for (P p : edges) {
        ll a = p.first;
        ll b = p.second;

        ll na = min(child_count[a], child_count[b]);
        ll nb = n - na;

        ev += (mint(1) - inv[na]) * (mint(1) - inv[nb]);

    }

    mint ans = ev - inv[1] * n - inv[n];
    cout << ans.x << endl;
}


Measured memory_bytes: 30444
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef int64_t ll;

void solve() {
    ll s, w;
    cin >> s >> w;
    if(w >= s) {cout << "unsafe";}
    else cout << "safe";
}    

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

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

int main(void)
{
	char s[3][11];
	
	scanf("%s %s %s", s[0], s[1], s[2]);
	
	if( (s[0][strlen(s[0])-1]==s[1][0]) && (s[1][strlen(s[1])-1]==s[2][0]) )
		printf("YES\n");
	else
		printf("NO\n");
	
	
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;
string s;

int main() {
  ll n,m;cin >> n >> m;
  ll out;
  if(n==1){
    if(m==1){
      out = 1;
    } else if(m==2){
      out ==0;
    } else {
      out = m-2;
    }
  } else if(n==2) {
    out =0;
  } else {
    if(m==1){
      out = n-2;
    } else if(m==2){
      out =0;
    } else {
      out = (n-2)*(m-2);
    }
  }
  cout << out << endl;
  return 0;
}


Measured memory_bytes: 256
a = input()
str = str(a)

if str[-1]=='2' or str[-1]=='4' or str[-1]=='5' or str[-1]=='7' or str[-1]=='9':
  print("hon")
elif str[-1]=='0' or str[-1]=='1' or str[-1]=='6' or str[-1]=='8':
  print("pon")
elif str[-1]=='3':
  print("bon")
else:
  print("ERROR")



Measured memory_bytes: 9060
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

vector<int> G[100009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, K;
    cin>>N;
    
    rep(i,N-1){
        int a,b; cin>>a>>b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    vector<int> d(N,-1);
    priority_queue< pii, vector<pii>, greater<pii> > que;
    cin>>K;
    rep(i,K){
        int v,p; cin>>v>>p;
        v--;
        d[v]=p;
        que.push({p,v});
    }
    
    while(!que.empty()){
        int u = que.top().second; que.pop();
        for(int v:G[u]){
            if(d[v]==-1){
                d[v] = d[u]+1;
                que.push({d[v],v});
            }else{
                if(abs(d[v]-d[u])!=1){
                    cout1("No");
                    return 0;
                }
            }
        }
    }
    
    cout1("Yes");
    rep(i,N) cout1(d[i]);
    
}

Measured memory_bytes: 7924
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int N;
cin>>N;
for(int i=N;;i++){
    if(i%2==0&&i%N==0){
        cout<<i;
        return 0;
    }
}
  return 0;
}

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

int main(){
    string a,b,c;
    cin>>a>>b>>c;
    if (a[a.size()-1]==b[0]&&b[b.size()-1]==c[0])
    {
        /* code */
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    
    
    }


Measured memory_bytes: 256
using System;
using System.Linq;

namespace aizu
{
    public class OnlineJudge
    {
        static void Main()
        {
            int total;
            while((total = int.Parse(Console.ReadLine())) != 0) {
                Console.WriteLine(total - Enumerable.Range(1, 9).Select(p => int.Parse(Console.ReadLine())).Sum());
            }
        }
    }
}

Measured memory_bytes: 5812
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct bian{
	int next,point;
}b[210000];
int p[110000],len,n,w[110000],f[110000],d[110000];
void ade(int k1,int k2){
	b[++len]=(bian){p[k1],k2}; p[k1]=len; d[k1]++;
}
void add(int k1,int k2){
	ade(k1,k2); ade(k2,k1);
}
void check(int k1,int k2){
	if (d[k1]==1){
		f[k1]=w[k1]; return;
	}
	long long totrem=0; int ma=0;
	for (int i=p[k1];i;i=b[i].next){
		int j=b[i].point;
		if (j!=k2){
			check(j,k1); totrem+=f[j]; ma=max(ma,f[j]);
		}
	}
	//cout<<totrem<<" "<<ma<<" "<<w[k1]<<endl;
	long long k=totrem-w[k1];
	if (k<0||totrem-2*k<0||totrem-ma<k){
		printf("NO\n"); exit(0);
	}
	f[k1]=totrem-k*2;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&w[i]);
	for (int i=1;i<n;i++){
		int k1,k2; scanf("%d%d",&k1,&k2); add(k1,k2);
	}
	if (n==2){
		if (w[1]==w[2]) printf("YES\n"); else printf("NO\n");
		return 0;
	}
	int root=0;
	for (int i=1;i<=n;i++) if (d[i]!=1) root=i;
	check(root,0);
	if (f[root]){
		printf("NO\n"); return 0;
	}
	printf("YES\n"); return 0;
}

Measured memory_bytes: 10496
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<deque>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int a, b;
	cin >> a >> b;
	if (a > b) {
		a--;
	}
	cout << a << endl;
	return 0;
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    int L,R; cin >> L >> R;
    int d; cin >> d;
    int ans = 0;
    FORq(i,L,R){
        if (i % d == 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#define RMAX 1000000000
using namespace std;

int main()
{
    int temp = 0;
    int n = 0;
    cin >> n;
    int minv = 0;
    int maxv = -1.01 * RMAX;
    for(int i = 0 ; i < n ; i++)
    {
	cin >> temp;
	if(i == 0)
	{
	    minv = temp;
	}
	else
	{
	    maxv = max(maxv, temp - minv);
	    minv = min(minv, temp);
        }
    }
    cout << maxv << endl;
    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

ll table[3005][3005];
ll dp[3005][3005][4];

int main2() {

  CLR(table, 0);
  CLR(dp, 0);

  int R = nextLong();
  int C = nextLong();
  int K = nextLong();
  REP(i, K) {
    int r = nextLong() - 1;
    int c = nextLong() - 1;
    table[r][c] = nextLong();
  }

  dp[0][0][0] = 0;
  dp[0][0][1] = table[0][0];
  REP(r, R) REP(c, C) {
    if (r == 0 && c == 0) continue;
    REP(k, 4) {
      if (r-1 >= 0) chmax(dp[r][c][0], dp[r-1][c][k]);
      if (c-1 >= 0) chmax(dp[r][c][k], dp[r][c-1][k]);

      if (k-1 >= 0) {
        if (c-1 >= 0) chmax(dp[r][c][k], dp[r][c-1][k-1] + table[r][c]);
      }
    }
    if (r-1 >= 0) chmax(dp[r][c][1], dp[r-1][c][0] + table[r][c]);
    if (r-1 >= 0) chmax(dp[r][c][1], dp[r-1][c][1] + table[r][c]);
    if (r-1 >= 0) chmax(dp[r][c][1], dp[r-1][c][2] + table[r][c]);
    if (r-1 >= 0) chmax(dp[r][c][1], dp[r-1][c][3] + table[r][c]);
  }

  ll ans = max({
    dp[R-1][C-1][0],
    dp[R-1][C-1][1],
    dp[R-1][C-1][2],
    dp[R-1][C-1][3]
  });
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 356416
n=int(input())
a=[0]*4
b=""
for i in range(n):
    b=input()
    if b=="AC":
        a[0]+=1
    elif b=="WA":
        a[1]+=1
    elif b=="TLE":
        a[2]+=1
    elif b=="RE":
        a[3]+=1

print("AC","x",a[0])
print("WA","x",a[1])
print("TLE","x",a[2])
print("RE","x",a[3])

Measured memory_bytes: 9220
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};
 

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b < c + d) {
    cout << "Right" << endl;
  } else if (a + b > c + d) {
    cout << "Left" << endl;
  } else {
    cout << "Balanced" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int INF = 2e9 + 5;

int main () {
  int x, y;
  cin >> x >> y;

  int ans = INF;

  // neither flip
  if (x <= y) {
    ans = min(ans, y - x);
  }

  // initial flip
  if (-x <= y) {
    ans = min(ans, 1 + y - (-x));
  }

  // final flip
  if (x <= -y) {
    ans = min(ans, 1 - y - x);
  }

  // both flips
  if (-x <= -y) {
    ans = min(ans, 2 - y - (-x));
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int a[3][3];
int b;
string ans = "No";
int N;

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

	for (int i = 0; i < N; i++) {
		cin >> b;
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (a[j][k] == b)a[j][k] = 0;
			}
		}


	}
	for (int i = 0; i < 3; i++) {
		if (a[i][0] == 0 && a[i][1] == 0 && a[i][2] == 0) {
			ans = "Yes";
		}
	}
	for (int i = 0; i < 3; i++) {
		if (a[0][i] == 0 && a[1][i] == 0 && a[2][i] == 0) {
			ans = "Yes";
		}
	}
	if (a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0) {
		ans = "Yes";
	}
	if (a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0) {
		ans = "Yes";
	}

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

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

int main() {
  int n;
  string s;
  int flag = 0;
  cin >> n;
  for (int i=0;i<n;i++){
    cin >> s;
    if (s == "Y"){
      flag = 1;
    }
  }
  if (flag == 1)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define M 25
int main(){//3 673
	int L,R;
	cin>>L>>R;
	if(R-L+1>=673)puts("0");
	else{
		LL ans=1e9;
		for(int i=L;i<=R;i++)
			for(int j=i+1;j<=R;j++)
				ans=min(ans,1LL*i*j%2019);
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll x, y;
    cin >> x >> y;
    vel A, B;
    A = {1, 3, 5, 7, 8, 10, 12}, B = {4, 6, 9, 11};
    ll cnt = 0;
    rep(i, 7) {
        if (x == A[i]) {
            rep (j, 7) {
                if (y == A[j]) {
                    cout << "Yes" << endl;
                    cnt++;
                    break;
                }
            }
        }
    }
    rep (i, 4) {
        if (x == B[i]) {
            rep(j, 4) {
                if (y == B[j]) {
                    cout << "Yes" << endl;
                    cnt++;
                    break;
                }
            }
        }
    }
    if (cnt == 0) {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
const long long int modi = 998244353;



int main(){
	long long int n,m,k;
	cin >> n >> m >> k;
	lli fact[n+1],factinv[n+1],inv[n+1];
	fact[0] = fact[1] = 1;
	factinv[0] = factinv[1] = 1;
	inv[1] = 1;
	for(lli i =2;i<=n;i++){
		fact[i] = fact[i-1]*i%modi;
		inv[i] = (modi  - modi/i*inv[modi%i]%modi)%modi;
		factinv[i] = factinv[i-1]*inv[i]%modi;
	}
	auto C = [&](lli n, lli r){
		return fact[n]*(factinv[r]*factinv[n-r]%modi)%modi;
	};

	auto binpow = [](lli a, lli b){
		lli res = 1;
		while(b>0)
		{
			if(b&1)
				res = res*a%modi;
			a = a*a%modi;
			b>>=1;
		}return res;
	};
	long long int ans = 0;
	for(lli i =0;i<=k;i++){
		lli same = m*C(n-1,i)%modi;
		lli diff = binpow(m-1,n-i-1);
		ans = (ans+(same*diff%modi))%modi;
	}
	cout << ans << endl;
}

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

#define int long long 

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

#define yes return puts("Yes"),void()
#define no return puts("No"),void()

void solve() {
    int a,b,c,d;read(a),read(b),read(c),read(d);
    if(d<b) no;
    if(a<b) no;
    int t=__gcd(b,d);
    if((a-c-1)/t-(a-b)/t>0) no;
    else yes;
}

signed main() {
    int t;read(t);while(t--) solve();
    return 0;
}


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

bool CheckChar(char c){
    switch(c){
        case 'A':
        case 'C':
        case 'G':
        case 'T':
            return true;
        default:
            return false;
    }
}

int main()
{
    string s;
    cin >> s;
    int ans = 0, cnt = 0;
    for(int i=0; i<s.length(); i++){
        if (CheckChar(s[i]) == true) cnt++;
        else{
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256