akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<complex>
#include<algorithm>
#include<set>
#define rep(i,n) for(int i = 0;i < n ; ++i)

using namespace std;

using ll = long long;
using Point = complex<double>;
const double eps = 1e-7;

double dot(Point a, Point b){
    return real(conj(a)*b);
}

double cross(Point a, Point b){
    return imag(conj(a)*b);
}


struct Line{
    Point a,b;
};

bool isis_sp(Line s, Point p){
    return (abs(s.a-p)+abs(s.b-p)-abs(s.b-s.a)<eps);
}

Point proj(Line l, Point p){
    double t = dot(p-l.a,l.a-l.b)/norm(l.a-l.b);
    return l.a + t * (l.a-l.b);
}

double dist_sp(Line s, Point p){
    Point r = proj(s,p);
    return isis_sp(s,r) ? abs(p-r) : min(abs(p-s.a),abs(p-s.b));
}

bool solve(){
    Point p[3];
    rep(i,3){
        int x,y;
        cin>>x>>y;
        if(x==0&&y==0)return false;
        p[i]=Point(x,y);
    }
    Point c;
    int x,y;
    cin>>x>>y;
    c = Point(x,y);
    double r; cin>>r;
    int f = 0;
    rep(i,3)if(abs(p[i]-c)>=r+eps)++f;
    if(f==0){
        cout<<"b"<<endl;
        return true;
    }
    if(f<3){
        cout<<"c"<<endl;
        return true;
    }
    double sum = 0;
    rep(i,3){
        sum += arg((p[(i+1)%3]-c)/(p[i]-c));
    }
    bool in = (abs(sum)>3);
    if(in){
        bool cr = false;
        rep(i,3){
            Line l = Line{p[i],p[(i+1)%3]};
            if(dist_sp(l,c)<r-eps)cr = true;
        }
        if(cr)cout<<"c"<<endl;
        else cout<<"a"<<endl;
    }
    else {
        bool cr = false;
        rep(i,3){
            Line l = Line{p[i],p[(i+1)%3]};
            if(dist_sp(l,c)<r+eps)cr = true;
        }
        if(cr)cout<<"c"<<endl;
        else cout<<"d"<<endl;
    }
    return true;
}

int main(){
     while(solve());
}


Measured memory_bytes: 3440
n = int(input())
ss = []
ts = []
for _ in range(n):
	s, t = input().split()
	ss.append(s)
	ts.append(int(t))
x = input()

idx = ss.index(x)
ans = 0
for i in range(idx+1, n):
	ans += ts[i]
print(ans)

Measured memory_bytes: 3064
H, W, M = map(int, input().split())
bombs = []
rows = [[]for _ in range(H)]
cols = [[]for _ in range(W)]
for _ in range(M):
    h, w = map(lambda x: int(x)-1, input().split())
    bombs.append((h, w))
    rows[h].append(w)
    cols[w].append(h)

max_row = 0
row_idx = set()
for i, row in enumerate(rows):
    if max_row < len(row):
        max_row = len(row)
        row_idx = {i}
        continue
    elif max_row == len(row):
        row_idx.add(i)

max_col = 0
col_idx = set()
for i, col in enumerate(cols):
    if max_col < len(col):
        max_col = len(col)
        col_idx = {i}
        continue
    elif max_col == len(col):
        col_idx.add(i)

ans = max_row+max_col
points = len(row_idx)*len(col_idx)
if M < points:
    print(ans)
else:
    for i, j in bombs:
        if i in row_idx and j in col_idx:
            points -= 1
    if points == 0:
        print(ans-1)
    else:
        print(ans)


Measured memory_bytes: 218832
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    fin;
    int n;
    cin >> n;
    vi arr;
    fore(i, 0, n){
        int x;
        cin >> x;
        arr.pb(x);
    }
    sort(all(arr));
    reverse(all(arr));
    int mx = -1;
    int value = 0;
    int i = 1;
    while(i < n){
        int df = arr[0] - arr[i];
        if(mx < min(df, arr[i])){
            mx = min(df, arr[i]);
            value = arr[i]; 
        }
        i++;
    }
    cout << arr[0] << " " << value << '\n';
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}   

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

int main(){
    int n, a;
    cin >> n;
    cin >> a;
    n -= ((int)(n/500))*500;
    if (n <= a){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    int a,b,n,w;
    cin>>n>>w;
    ll dp[n+1][w+1];
    for(int i=0;i<=w;i++){
        dp[0][i]=0;
    }
    for(int i=0;i<=n;i++){
        dp[i][0]=0;
    }
    for(int i=1;i<=n;i++){
        cin>>a>>b;
        for(int j=1;j<=w;j++){
            if(j-a>=0){
                dp[i][j]=max(b+dp[i-1][j-a],dp[i-1][j]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
            
        }
    }
    
    //for(int i=0;i<=n;i++){
    //    for(int j=0;j<=w;j++){
    //        cout<<dp[i][j]<<" ";
    //    }
    //    cout<<endl;
    //}

    cout<<dp[n][w];
    return 0;
}

Measured memory_bytes: 79232
import sys

def solve(a,b,c):
    li = [a,b,c]
    cf = 0
    cs = 0
    for i in li:
        if int(i) == 5:
            cf +=1
        if int(i) == 7:
            cs +=1
    if cf == 2 and cs ==1:
        return 'YES'
    else:
        return 'NO'
            
def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_a, str_b, str_c] = line.split(' ')
    return (int(str_a), int(str_b), int(str_c))

def main():
    a, b, c = readQuestion()
    answer = solve(a, b, c)
    print(answer)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

int main() {
  int N; cin >> N;
  int ans = 0;
  rep(i, 0, N) {
    int l, r;
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;
  return 0;
}


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

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

#define fr first
#define sc second
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)

const int INF=1000000000;

int main(){
	int h,w;
	char c[102][102];
	scanf("%d%d",&h,&w);
	for(int i=0;i<h;i++){
		scanf("\n");
		for(int j=0;j<w;j++){
			scanf("%c",&c[i][j]);
		}
	}
	
	int dp[102][102];
	for(int i=0;i<102;i++)for(int j=0;j<102;j++)dp[i][j]=INF;
	dp[0][0]=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(j>0)chmin(dp[i][j],dp[i][j-1]+((c[i][j]!=c[i][j-1])?1:0));
			if(i>0)chmin(dp[i][j],dp[i-1][j]+((c[i][j]!=c[i-1][j])?1:0));
		}
	}
	if(c[0][0]=='.')cout<<(dp[h-1][w-1]+1)/2<<endl;
	else cout<<(dp[h-1][w-1]+2)/2<<endl;
}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    ll x;
    cin >> x;
    ll ans = x / 11 * 2;
    int mod = x % 11;
    if (mod > 0 && mod <= 6){
        ans++;
    } else if (mod > 6) {
        ans += 2;
    }
    cout <<  ans << endl;



    return 0;
}


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string s; cin >> s;
    if(s[0] == s[1] && s[1] == s[2]) cout << "Yes" << endl;
    else if(s[1] == s[2] && s[2] == s[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main(void){
    
    int x,y;
    long int ans;
    scanf("%d %d",&x,&y);
    for(int i=0;i<=x;i++){
        if(2*i+4*(x-i) == y){
            printf("Yes");
            return 0;
        }
    }


    printf("No");

    return 0;
}

Measured memory_bytes: 1732
import java.util.*;
import java.math.*;

public class Main {
    void solve(){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt() + scan.nextInt();
        int b = scan.nextInt() + scan.nextInt();
        if(a == b) System.out.println("Balanced");
        else System.out.println(a > b ? "Left" : "Right");
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}


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

using namespace std;

const int INF = 1e9 + 5;

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

	int N, K;
	cin >> N >> K;

	vector<int> h(N);
	for (int i = 0; i < N; i++)
		cin >> h[i];
	
	vector<int> dp(N, INF);
	
	dp[0] = 0;

	for (int i = 0; i < N; i++) {
		int sum1 = INF, sum2 = INF;
		for (int j = i + 1; j <= i + K; j++) {
			if (j < N)
				dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]));
		}
	}

	cout << dp[N-1] << endl;
    return 0;
}


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

// Manhattan distance betweem (x1,y1) and (x2,y2)
double cmdis(double x1, double y1, double x2, double y2) {
  return abs(x1 - x2) + abs(y1 - y2);
}
int n, m;
vector<pair<int, int>> st, p;

int main() {
  cin >> n >> m;
  for(int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    st.push_back(make_pair(x, y));
  }
  for(int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    p.push_back(make_pair(x, y));
  }
  for(int i = 0; i < n; ++i) {
    double nd = 10000000000;
    int np = 0;
    for(int j = 0; j < m; ++j) {
      double d =
          cmdis((double)st[i].first, (double)st[i].second,
                (double)p[j].first, (double)p[j].second);
      if(d < nd) {
        nd = d;
        np = j;
      }
    }
    cout << np + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define NMAX 200005
using namespace std;
int n,pos,start,finish,h[NMAX];
long long a[NMAX],value;
long long aint[4*NMAX],dp[NMAX],sol,maxim;
void update(int nod,int st,int dr)
{
    if(st==dr)
    {
        aint[nod]=value;
        return;
    }
    int mid=(st+dr)/2;
    if(pos<=mid)
        update(2*nod,st,mid);
    else
        update(2*nod+1,mid+1,dr);
    aint[nod]=max(aint[2*nod],aint[2*nod+1]);
}
void query(int nod,int st,int dr)
{
    if(start<=st && dr<=finish)
    {
        maxim=max(maxim,aint[nod]);
        return;
    }
    int mid=(st+dr)/2;
    if(start<=mid)
        query(2*nod,st,mid);
    if(mid<finish)
        query(2*nod+1,mid+1,dr);
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>h[i];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
    {
        start=1;
        finish=max(h[i]-1,1);
        maxim=0;
        query(1,1,n);
        dp[h[i]]=a[i]+maxim;
        pos=h[i];
        value=dp[h[i]];
        update(1,1,n);
        sol=max(sol,dp[h[i]]);
    }
    cout<<sol;
    return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main(){
  int N, D;
  cin >> N >> D;
  int s = 2 * D + 1;
  cout << (N + s - 1) / s << endl;
}

Measured memory_bytes: 256
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

struct Range {
    large min = 0;
    large max = 0;
};

static large solve(const int n, const vector<large> &a) {
    if (a.empty() || a[n] == 0)
        return -1;

    auto count_ranges = vector<Range>(n + 1);
    count_ranges[n].min = a[n];
    count_ranges[n].max = a[n];
    if (n < 44 + 10) {
        auto limit = 1LL << n;
        if (count_ranges[n].max > limit)
            count_ranges[n].max = limit;
    }
    if (count_ranges[n].min > count_ranges[n].max) {
        return -1;
    }

    for (auto d = n - 1; d >= 0; --d) {
        count_ranges[d].max = a[d] + count_ranges[d + 1].max;
        count_ranges[d].min = a[d] + ((count_ranges[d + 1].min + 1) / 2);

        assert(count_ranges[d].max <= 10'000'000'000'000LL);
        assert(count_ranges[d].min <= count_ranges[d].max);
        assert(0 <= count_ranges[d].min);

        // SUM a[i] <= 10'000'000'000'000 < 2^44
        if (d < 44 + 10) { // +10 for safety margin
            auto limit = 1LL << d;
            if (count_ranges[d].max > limit) {
                count_ranges[d].max = limit;
            }
        }

        // requires too much
        if (count_ranges[d].min > count_ranges[d].max)
            return -1;
    }

    auto cnt = 0ULL;
    for (auto d = 0; d < n; ++d) {
        cnt += count_ranges[d].max;
        auto inner_nodes = count_ranges[d].max - a[d];
        auto max_children = 2 * inner_nodes;
        if (max_children < count_ranges[d + 1].min) {
            // cerr << "Cannot have enough children.\n";
            return -1;
        }
        if (count_ranges[d + 1].max > max_children)
            count_ranges[d + 1].max = max_children;
    }

    if (count_ranges[n].min > count_ranges[n].max)
        return -1;
    cnt += count_ranges[n].max;
    return cnt;
}

int main() {
    int n;
    cin >> n;
    auto a = vector<large>(n + 1);
    for (auto &a_i : a)
        cin >> a_i;

    cout << solve(n, a);
    return 0;
}


Measured memory_bytes: 5616
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1e9 + 7;

ll add(ll x, ll y){
    return (x+y)%mod;
}

ll mul(ll x, ll y){
    return (x%mod)*(y%mod)%mod;
}

ll powll(ll x, ll y){
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    return (x * powll(y,mod-2)) % mod;
}

ll gcd(ll x, ll y){
    if (y == 0) return x;
    return gcd(y, x % y);
}

ll calc(ll x, ll y, ll s, ll cx, ll cy){
    ll d = gcd(x, y);
    if (s % d) return 0;
    ll p = min(cy, s / y);
    ll m = s - p * y;
    while (m % x != 0 || m == 0){
        m += y;
    }
    ll mi = m / x;
    if (mi > cx) return 0;
    p = min(cx, s / x);
    m = s - p * x;
    while (m % y != 0 || m == 0){
        m += x;
    }
    ll ma = min(cx, (s - m) / x);
    // cout << x << " " << y << " " << s << endl;
    // cout << mi << " " << ma << endl;
    // cout << (ma - mi) / (y / d) + 1 << endl;
    if (mi > ma) return 0;
    return (ma - mi) / (y / d) + 1;
}

int main() {
    ll s = in();
    ll m = 15;
    VL cnt(m);
    cnt[1] = 9;
    FOR(i,1,m-2){
        cnt[i + 1] = (10 * cnt[i]);
    }

    ll ans = 0;
    for (ll x = 1; x * x <= s; x++){
        if (s % x != 0) continue;
        ll y = s / x;
        if (x >= m || y <= cnt[x]){
            ll tmp = 9 * powll(10, x - 1);
            ans = (ans + (tmp - y + 1) + mod) % mod;
        }
        if (y > x && (y >= m || x <= cnt[y])){
            ll tmp = 9 * powll(10, y - 1);
            ans = (ans + (tmp - x + 1) + mod) % mod;
        }
    }
    FOR(x,2,s){
        if (s % x == 0) continue;
        ll p = s / x;
        ll c1 = s % x, c0 = x - c1;
        if (p == 1 && x > 100) break;
        if ((p < m && c0 > cnt[p]) || (p + 1 < m && c1 > cnt[p + 1])) continue;
        ans++;
    }
    ll tmp = ans;
    FOR(x,1,8){
        ll ss = s;
        FOR(y,x+1,10){
            ss -= y * cnt[y];
            if (ss <= 0) break;
            ans = (ans + calc(x, y + 1, ss, cnt[x], cnt[y + 1] - 1)) % mod;
        }
    }

    cout << ans << endl;
    // cout << ans - tmp << endl;

    return 0;
}


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


int main(){
    long long m,n;
    long long mod = 1;
    scanf("%lld %lld",&m,&n);
    
    while(n>0){
        if(n%2){
            mod = mod * m % 1000000007;
            n--;
        }else{
        m = m * m % 1000000007;
        n /= 2 ;
        }
    }
    // mod = mod * m %1000000007;
    printf("%lld\n",mod);
    
    return 0;
}


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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1000000007;
const int N = 150555;
const int M = 1155;

int a[N];
void solve() {
    int n;
    cin >> n;

    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }

    for (int i = 1; i <= n; i++){
        if (a[i] % 2 == 1) continue;
        if (a[i] % 5 != 0 && a[i] % 3 != 0){
            cout << "DENIED";
            return;
        }
    }

    cout << "APPROVED";

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <map>
#include <algorithm>
#include <stack>
#include <cstring>
 
#define ll long long
#define MP make_pair
#define PB push_back
#define P push
#define f first
#define se second
#define S size()
#define B begin()
#define E end()
#define rB rbegin()
#define rE rend()
#define PI acos(-1)

 
const int N = 1e5 + 100;
const int M = 1e6 + 100;
const ll oo = 1e18;
 
ll n, m, k, t, q, h, a, b, d, c, e, w, x, y, z;
using namespace std;


int ai[N], bi[N], ci[N], dp[N][3];


int calc(int n, int las) {

	if(n == m) return 0;

	int &r = dp[n][max(las, 0)];

	if(r != -1) return r;


	int x = -1, y = -1, f = -1;

	if(las != 0){
		x = calc(n + 1, 0) + ai[n];
	}
	if(las != 1){
		y = calc(n + 1, 1) + bi[n];
	}
	if(las != 2){
		f = calc(n + 1, 2) + ci[n];
	}

	return r = max({x, y, f});
}


int main() {

	memset(dp, -1, sizeof dp);

	cin >> m;
	for(int i = 0; i < m; i++) {
		cin >> ai[i] >> bi[i] >> ci[i];
	}
	
	cout << calc(0, -1);



    
    return 0;
}




Measured memory_bytes: 10368
use proconio::{fastout, input};

use proconio::marker::Chars;
use std::cmp::max;

#[fastout]
fn main() {
    input! {
        s: Chars,
    }
    let mut ans = 0;
    let mut acc = 0;
    for c in s {
        match c {
            'A' | 'C' | 'G' | 'T' => acc += 1,
            _ => acc = 0,
        }
        ans = max(ans, acc);
    }
    println!("{}", ans);
}


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

int main(){
  int N;
  cin >> N;
  
  char c;
  bool ans = false;
  for (int i = 0; i < N; i++){
    cin >> c;
    if (c == 'Y') ans = true;
  }
  
  if (ans){
    cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }
}

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

int main(){
  int N,K,Q;
  cin>>N>>K>>Q;
  vector<int> A(N);
  for(int i=0;i<Q;i++){
    int j;
    cin>>j;
    A[j-1]++;
  }
  for(int i:A){
    if(K+i-Q>0)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }
}

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

static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim(){
    int u, minv;
    int d[MAX], p[MAX], color[MAX];

    for(int i = 0; i < n; i++){
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }

    d[0] = 0;

    while(1){
        u = -1;
        minv = INFTY;

        //到達可能で最も近いものを探索
        for(int i = 0; i < n; i++){
            if(color[i] != BLACK && d[i] < minv){
                u = i;
                minv = d[i];
            }
        }
        
        //全て到達したらbreak
        if(u == -1) break;

        //1接点を確定
        color[u] = BLACK;

        //到達可能な接点との距離を更新
        for(int v = 0; v < n; v++){
            if(color[v] != BLACK && M[u][v] != INFTY){
                if(M[u][v] < d[v]){
                    d[v] = M[u][v];
                    color[v] = GRAY; //この行はなくても機能しそう
                    p[v] = u;
                }
            }
        }

    }
    //MSTのコストを計算
    int sum = 0; 
    for(int v = 0; v < n; v++){
        if(p[v] != -1) sum += M[p[v]][v];
    }
    return sum;
}

int main(){
    cin >> n;

    rep(i,n)rep(j,n){
        int e;
        cin >> e;
        M[i][j] = (e == -1) ? INFTY : e;
    }

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


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
#define faf ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define ll long long
#define pb push_back
#define mp make_pair
#define nt _int128
 
long double PI =3.14159265358979323846;
 
 
ll modo=1e9+7;
const ll inf=1e13;
const ll ms=1e5 +5;

double ar[3005];
double dp[3005][3005]={0};

int main()
{
    faf;
    int n;
    cin>>n;
    int i;int j;
    for(i=1;i<=n;i++)cin>>ar[i];
    dp[0][0]=1;
    double pp;
    double kk;
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=n;j++)
        {
            if(dp[i-1][j]>0)
            {
              pp=dp[i-1][j]*(1-ar[i]);
              kk=dp[i-1][j]*ar[i];
              dp[i][j]+=pp;
              dp[i][j+1]+=kk;
            }
        }
    }
    double ans=0.0;
    int mid=(n/2)+1;
    
    for(i=mid;i<=n;i++)ans+=dp[n][i];
    cout<<fixed;
    cout<<setprecision(10)<<ans;
    
    
    return 0;
}

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

#define ll long long

void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


int gcd(int a, int b){
  int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

int upll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;
}

int downll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;
}

void sortup(ll*a,int n){
  qsort(a,n,sizeof(ll),upll);
}

void sortdown(ll*a,int n){
  qsort(a,n,sizeof(ll),downll);
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int n;
  scanf("%d",&n);
  int ans=0;

  int A[200000];
  for(int i=0;i<200000;i++){
    A[i]=0;
  }

  for(int i=0;i<n;i++){
    int a;
    scanf("%d",&a);
    if(a>100000){
      ans++;
      continue;
    }
    A[a]++;
  }

  for(int i=1;i<=100000;i++){
    if(A[i]>=i){
      ans+=A[i]-i;
    }
    else{
      ans+=A[i];
    }
  }

  printf("%d\n",ans);

  return 0;
}

Measured memory_bytes: 2516
H, W = gets.split.map(&:to_i)
Ss = Array.new(H) { gets.chomp }

def search(i, j)
  boms = 0
  
  for k in (i-1)..(i+1) do
    for l in (j-1)..(j+1) do
      if ((k >= 0 && l >= 0) && (k < H && l < W)) then
        if (Ss[k][l] == "#") then
          boms += 1
        end
      end
    end
  end
  boms.to_s
end

H.times{ |i|
  W.times{ |j|
    if (Ss[i][j] == "." || (/[0-9]/ === Ss[i][j].to_s)) then
      Ss[i][j] = search(i, j)
    end
  }
}

puts Ss


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

int main() {
  string s, t;
  cin >> s >> t;
  short int c = 0;
  for (short int i = 0; i < 3; ++i) {
    if (s[i] == t[i]) ++c;
  }
  cout << c << '\n';
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()

    def divisors(n):
        res = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n//i)

        return res

    ans = 0
    ans += len(divisors(N-1)) - 1

    for k in divisors(N)[1:]:
        n = N
        while n % k == 0:
            n //= k
        if n % k == 1:
            ans += 1
    
    print(ans)




if __name__ == "__main__":
    main()

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

using namespace std;

int main() {
    std::ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    int N;
    cin >> N;
    vector<vector<int>> act(N, vector<int>(3));
    for (int i = 0; i < N; ++i) {
        cin >> act[i][0] >> act[i][1] >> act[i][2];
    }
    vector<vector<int>> dp(N + 1, vector<int>(3, 0));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (k != j) {
                    dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + act[i][k]);
                }
            }
        }
    }
    cout << *max_element(begin(dp[N]), end(dp[N])) << "\n";
    return 0;
}

Measured memory_bytes: 11136
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <vector>
#include <list>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <climits>
#include <map>
#include <math.h>

using namespace std;

int main(){
	string a, b, c;
	cin >> a >> b >> c;
	map<char, string> m;
	m['a'] = a;
	m['b'] = b;
	m['c'] = c;

	char tmp = m['a'][0];
	m['a'].erase(m['a'].begin());
	//cout << m['a'] << endl;
	while (1){
		if (m[tmp].empty()){ cout << (char)(tmp - 0x20) << endl; break; }
		char tt = m[tmp][0];m[tmp].erase(m[tmp].begin());
		tmp = tt; 

	}
	

	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

typedef long long ll;
const int N = 1e5 + 7;
const ll MOD = 1e9 + 7;

ll inv[N], s[N], a[N];
ll ans, n;

int main() {
#ifdef WYXLOCAL
    freopen("tmp.in", "r", stdin);
    freopen("tmp.out", "w", stdout);
#endif // WYXLOCAL
    scanf("%lld", &n);
    inv[1] = 1;
    for (int i = 1; i <= n; ++i) {
        scanf("%lld", &a[i]);
        if (i != 1) inv[i] = (-inv[MOD%i] * (MOD / i) % MOD + MOD) % MOD;
        // printf("%lld ", inv[i]);
        s[i] = (s[i-1] + inv[i]) % MOD; // 算前缀和的时候也要取模啊。
    }
    for (int i = 1; i <= n; ++i) {
        ans = (ans + a[i] * (s[i] + s[n-i+1] - 1) % MOD) % MOD;
    }
    for (int i = 1; i <= n; ++i) {
        ans = 1ll * ans * i % MOD; // 我们算的是期望，但是题目要求算期望的分子。
    }
    std::cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 2560
from collections import deque

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

ans = 0

for startx in range(w):
    for starty in range(h):
        if grid[starty][startx] == "#":
            continue

        dist = [[10000]*w for _ in range(h)]
        dist[starty][startx] = 0
        maxDist = 0

        q = deque([(startx, starty)])

        while q:
            curx, cury = q.popleft()

            adj = [(1, 0), (-1, 0), (0, 1), (0, -1)]

            for xo, yo in adj:
                x, y = curx + xo, cury + yo

                if x < 0 or x >= w or y < 0 or y >= h:
                    continue
                if grid[y][x] == "#":
                    continue

                newDist = dist[cury][curx] + 1
                if newDist < dist[y][x]:
                    dist[y][x] = newDist
                    q.append((x, y))

                    maxDist = max(maxDist, newDist)

        ans = max(ans, maxDist)

print(ans)

Measured memory_bytes: 9476
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    ll x[100010], y[100010];
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];
    ll x_sum = 0, y_sum = 0;

    rep(i, n - 1) {
        x_sum += (x[i + 1] - x[i]) * (i + 1) % MOD * (n - (i + 1)) % MOD;
        x_sum %= MOD;
    }

    rep(i, m - 1) {
        y_sum += (y[i + 1] - y[i]) * (i + 1) % MOD * (m - (i + 1)) % MOD;
        y_sum %= MOD;
    }
    cout << x_sum * y_sum % MOD << endl;

    return 0;
}


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

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main()
{
	ll i, j, k;
	ll N;
	cin >> N;
	vector<vll> X, Y;
	for (i = 0; i < N; i++)
	{
		ll a;
		cin >> a;
		vll xi, yi;
		for (j = 0; j < a; j++)
		{
			ll xij, yij;
			cin >> xij >> yij;
			xij--;
			xi.push_back(xij);
			yi.push_back(yij);
		}
		X.push_back(xi);
		Y.push_back(yi);
	}
	ll ans = 0;
	ll honest = 0;
	for (honest = 0; honest < (1 << N); honest++)
	{
		// cout << bitset<3>(honest) << endl;
		bool ok = true;
		for (i = 0; i < N; i++)
		{
			if (honest & 1 << i)
			{
				for (j = 0; j < X[i].size(); j++)
				{
					ll x = X[i][j], y = Y[i][j];
					if (y)
					{
						if (!(honest & 1 << x))
						{
							ok = false;
						}
					}
					else
					{
						if (honest & 1 << x)
						{
							ok = false;
						}
					}
				}
			}
		}
		if (!ok)
		{
			continue;
		}
		else
		{
			ans = max(ans, (ll)__builtin_popcountll(honest));
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
/*
    [Gnana Deepak]
    [August 01, 2020 7:44 PM]
    [F - LCS]
    [https://atcoder.jp/contests/dp/tasks/dp_f]
    [2000 ms]
    [1024 MB]
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
using ld = long double;
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define F first
#define S second
#define orderKey order_of_key
#define findOrder find_by_order
#define s(x) set<x>
#define um(x, y) unordered_map<x, y>
#define m(x, y) map<x, y>
#define p(x, y) pair<x, y>
#define v(x) vector<x>
#define min_heap(t) priority_queue<t, vector<t>, greater<t>>
#define max_heap(t) priority_queue<t>
#define ordered_set(x) tree<x, null_type, less<x>, rb_tree_tag, tree_order_statistics_node_update>
#define eb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define ss(v) stable_sort(all(v))
#define fori(i, a, b) for (int i = a; i <= b; i++)
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define stprs(x) cout << fixed << setprecision(x);
#define FILE_READ_IN freopen("input.txt", "r", stdin);
#define FILE_READ_OUT freopen("output.txt", "w", stdout);
#define bs binary_search
#define deb(x) cout << #x << "=" << x << '\n';
#define scn(v1)        \
    for (auto &x : v1) \
        cin >> x;
#define R(x) reverse(all(x));
#define lb lower_bound
#define ub upper_bound
const char nl = '\n';
const int mod1 = 1e9 + 7;
const int mod2 = 998244353;
const ld PI = acos(-1);
const int N = 3000;
const int imx = LLONG_MAX;
int DP[N + 1][N + 1];
void accio_ac(void)
{
    string S, T;
    cin >> S >> T;
    int s = S.length();
    int t = T.length();
    fori(i, 0, s) fori(j, 0, t)
    {
        if (i == 0 or j == 0)
        {
            DP[i][j] = 0;
        }
        else
        {
            if (S[i - 1] == T[j - 1])
            {
                DP[i][j] = 1 + DP[i - 1][j - 1];
            }
            else
            {
                DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]);
            }
        }
    }
    stack<char> Stack;
    int i = s - 1;
    int j = t - 1;
    while (i >= 0 and j >= 0)
    {
        if (S[i] == T[j])
        {
            Stack.push(S[i]);
            --i;
            --j;
        }
        else
        {
            if (DP[i][j + 1] > DP[i + 1][j])
            {
                --i;
            }
            else
            {
                --j;
            }
        }
    }
    while (!Stack.empty())
    {
        cout << Stack.top();
        Stack.pop();
    }
    cout << endl;
}
int32_t main(void)
{
    fastio;
    int __ = 1;
    // cin >> __;
    while (__--)
    {
        accio_ac();
    }
    return 0;
}


Measured memory_bytes: 73972
function main(input) {
  const args = input
  if (args[0] === args[1] || args[1] === args[2] || args[2] === args[3]) {
    console.log('Bad')
  } else {
    console.log('Good')
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 100005
bool sheep[MAXN];  
int main() {
    int n;
    string s;
    cin >> n >> s;
    bool p1[4] = {true, false, true, false};
    bool p2[4] = {true, true, false, false};
    for (int p = 0; p < 4; p++) {
    sheep[1] = p1[p];
    sheep[2] = p2[p];
    for (int i = 2; i <= n; i++) {
        char ans = s[i - 1];
        if (ans == 'o') {
            if (sheep[i]) {
                if (sheep[i - 1]) {
                    sheep[i + 1] = true;
                }
                else {
                    sheep[i + 1] = false;
                }
            }
            else {
                if (sheep[i - 1]) {
                    sheep[i + 1] = false;
                }
                else {
                    sheep[i + 1] = true;;
                }
            }
        }
        else {
            if (sheep[i]) {
                if (sheep[i - 1]) {
                    sheep[i + 1] = false;
                }
                else {
                    sheep[i + 1] = true;
                }
            }
            else {
                if (sheep[i - 1]) {
                    sheep[i + 1] = true;
                }
                else {
                    sheep[i + 1] = false;
                }
            }
        }
    }
    bool ok = true;
    if (sheep[1]) {
    if (s[0] == 'o') {
        if (sheep[n] != sheep[2]) {
            ok = false;
        }
    }
    else {
        if (sheep[n] == sheep[2]) {
            ok = false;
        }
    }
    }
    else {
       if (s[0] == 'o') {
        if (sheep[n] == sheep[2]) {
            ok = false;
        }
    }
    else {
        if (sheep[n] != sheep[2]) {
            ok = false;
        }
    } 
    }
    if (sheep[n + 1] != sheep[1]) {
        ok = false;
    }
    if (ok) {
        for (int i = 1; i <= n; i++) {
            if (sheep[i]) {
                cout << 'S';
            }
            else {
                cout << 'W';
            }
        }
        cout << endl;
        return 0;
    }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3820
/*****************************************************
 *     created by: nayakashutosh9
 * "Winners Never Quit and Quitters Never Win".
*****************************************************/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define endl '\n'
#define mod 1000000007
#define inf 1e18
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const int N = 300005;
/**********************************************************************************************/

void solve() {
	int x, k, d; cin >> x >> k >> d;
	if(x<0) x*=-1;
	int f = x / d;
	if (k <= f) {
		cout << (x - k * d) << endl;
		return;
	}
	k -= f; x -= f * d;
	if (k % 2) cout << abs(x - d) << endl;
	else cout << x << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1, z = 1;
	// cin >> t; cin.ignore();
	while (t--) {
		// cout << "Case #" << (z++) << ": ";
		// clock_t start = clock();
		solve();
		// clock_t end = clock();
		// cout << (end-start) << endl;
		//print execution time in ms
	}

	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>

using namespace std;

#define lli long long unsigned int
#define REP(i,n) for(int i=0;i<n;i++)
#define DEBUG 0


int main(){

	lli n,m;
	map<lli,vector<lli>> a;

	cin>>n>>m;
	REP(i,m){
		lli tmpA,tmpB;
		cin>>tmpA>>tmpB;
		a[tmpA].push_back(tmpB);
		a[tmpB].push_back(tmpA);
	}

	queue<lli> q;
	queue<lli> d;
	set<lli> s;

	s.insert(1);
	q.push(1);
	d.push(0);

	while(q.size()){
		lli top = q.front();
		lli nowDepth = d.front();
		if(DEBUG)cout<<"top="<<top<<" depth"<<nowDepth<<endl;
		d.pop();
		q.pop();
		if(top == n){
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
		if(nowDepth >=2)continue;
		for(auto& e:a[top]){
			if(DEBUG)cout<<"e="<<e<<endl;
			if(s.find(e) == s.end()){
				q.push(e);
				d.push(nowDepth+1);
				s.insert(e);
			}
		}
	}

	cout<<"IMPOSSIBLE"<<endl;

	return 0;
}

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

int arr[100005][4];
int dp[100005][4], n;

int solve(int day, int flag)
{
    if(day==n)
        return 0;
    if(dp[day][flag] != -1)
        return dp[day][flag];

    int maxo = 0;

    if(flag == 0)
    {
        maxo = max(maxo, arr[day][1] + solve(day+1, 1));
        maxo = max(maxo, arr[day][2] + solve(day+1, 2));
        maxo = max(maxo, arr[day][3] + solve(day+1, 3));
    }
    else if(flag == 1)
    {
        maxo = max(maxo, arr[day][3] + solve(day+1, 3));
        maxo = max(maxo, arr[day][2] + solve(day+1, 2));
    }
    else if(flag == 2)
    {
        maxo = max( maxo , arr[day][1] + solve(day+1, 1));
        maxo = max(maxo , arr[day][3] + solve(day+1, 3));
    }
    else
    {
        maxo = max(maxo, arr[day][1] + solve(day+ 1, 1));
        maxo = max(maxo , arr[day][2] + solve(day+1, 2));
    }

    return dp[day][flag] = maxo;
}


int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    
    cin>>n;

    memset(dp, -1, sizeof dp);

    for(int i = 0; i < n; i++)
        for(int j = 1; j<=3; j++)
            cin>>arr[i][j];


    cout<<solve(0 , 0)<<endl;


    return 0;
}


Measured memory_bytes: 14476
abcd = list(input())
abcd = [int(i) for i in abcd]

for i in range(2**3):
  bag=["+"]*3
  #print("pattern {}: ".format(i), end="")
  for j in range(3):
    if ((i>>j) & 1):
      bag[j]="-"
  #print(bag)
  s=abcd[0]
  for ii in range(len(bag)):
    if bag[ii] == "+":
      s+=abcd[ii+1]
    else:
      s-=abcd[ii+1]
    #print(s)
    
  if s == 7:
    print("{}{}{}{}{}{}{}={}".format(abcd[0],bag[0],abcd[1],bag[1],abcd[2],bag[2],abcd[3],s))
    exit()


Measured memory_bytes: 3064
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

const long long int MOD = 1000000007;

long long int fact(long long int k) {
	long long int sum = 1;
	for (long long int i = 2; i <= k; i++)
		sum *= i;

	return sum;
}

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

long long int pow_mod(int a, int b) {
	long long int  ans = 1;
	for (int i = 0; i < b; i++)
		ans = (ans * a) % MOD;

	return ans;
}

struct Box {
	int no;
	bool isFact;
};

int main()
{
	long long int n, total_cnt = 0;

	cin >> n;

	vector<long long int> a(n);

	vector<int> cnt(61);

	for (int i = 0; i < n; i++)
		cin >> a[i];

	for (int i = 0; i < n; i++) {
		long long int _m = (long long int)powl(2, 60);
		for (int j = 60; j >= 0; j--) {
			if (a[i] >= _m) {
				a[i] -= _m;
				cnt[j]++;
				if (a[i] == 0)
					break;
			}
			_m /= 2;
		}
	}

	for (int i = 0; i <= 60; i++) {
		total_cnt += (((cnt[i] * (n - cnt[i])) % MOD) * pow_mod(2, i)) % MOD;
		total_cnt %= MOD;
	}

	cout << total_cnt << endl;

	return 0;
}

Measured memory_bytes: 2560
N, A, B = map(int, input().split())

if (A - B)% 2 == 0:
    print((B - A) // 2)
else:
#     ans = B - 1
#     ans = min(ans, N - A)
    ans = min(A + (B - A - 1) // 2, N - B + 1 + (-A + B - 1) // 2)
#     ans = min(ans, A + (1 + B - A) // 2)
    
    print(ans)

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

int read() {
    int x = 0, f = 1; char ch = getchar();
    while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
    while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f; 
}

const int Max = 100033;
int n, a[Max];
int gcd(int a, int b) {
    return !b ? a : gcd(b, a % b);
}

bool solve() {
    for (int i = 1; i <= n; i++) {
        if (a[i] & 1) {
            if (a[i] == 1) return 0;
            else { a[i]--; break; }
        }
    }
    int d = a[1];
    for (int i = 2; i <= n; i++) d = gcd(d, a[i]);
    for (int i = 1; i <= n; i++) a[i] /= d;
    int odd = 0, even = 0;
    for (int i = 1; i <= n; i++) {
    	if (a[i] & 1) odd++;
    	else even ^= 1;
    }
    if (!even && odd == 1) return solve() ^ 1;
    else return (even ? 0 : 1);
}

int main() {
    n = read();
    for (int i = 1; i <= n; i++) a[i] = read();
    int odd = 0, even = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] & 1) odd++;
        else even ^= 1;
    }
    if (!even && odd == 1)
        puts(solve() ? "First" : "Second");
    else puts(even ? "First" : "Second");
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,p,j,n,k,q,m;
    int x=0;
    int a,b;
    cin>>a>>b;
   for(i=a;i<=b;i++)
   {

       n=i;m=i;q=0;
       while(n>0)
       {
           p=n%10;
           q=q*10+p;
           n=n/10;
       }
       if(n>0)
       {
           q=q*10+n;
       }

       if(q==m)
        x++;

    }
    cout<<x<<endl;

 return 0;
}


Measured memory_bytes: 256
N=int(input())
flag1=False
flag2=False
ans='No'
for i in range(N):
    a,b=map(int,input().split())
    if a==b:
        if flag1:
            if flag2:
                ans='Yes'
            else:
                flag2=True
        else:
            flag1=True
    else:
        flag1=False
        flag2=False
print(ans)

Measured memory_bytes: 9180
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions
void get_isprimes(vb& isPrime, const int PMAX) {
    isPrime = vb(PMAX + 1, true);
    isPrime[0] = false;
    isPrime[1] = false;

    for(int i=2; i*i<=PMAX; i++) {
        for(int j= i*2; j <=PMAX; j+=i) {
            isPrime[j] = false;
        }
    }
}

void get_primes(vi& prime, const int PMAX) {
    vb isPrime;
    get_isprimes(isPrime, PMAX);

    for(int i=2; i<=PMAX; i++) {
        prime.push_back(i);
    }
}

void prime_factorize(map<ll,ll>& fac, ll n, vi& prime) {
    for(int p : prime) {
        while(n > 0) {
            if (n%p == 0){
                fac[p]++;
                n /= p;
            } else {
                break;
            }
        }
    }
}
#endif 


vi e;
vvl dp;
ll dfs(int n, ll cnt) {
    if (n >= e.size()) {        
        if (cnt == 75) return 1;
        else return 0;
    }

    if (cnt > 75) return 0;

    if (dp[n][cnt] > 0) return dp[n][cnt];

    ll res = 0;
    REP(j, e[n]+1) {
        res += dfs(n + 1, cnt*(j + 1));
    }

    dp[n][cnt] = res;

    return res;
}

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

    int N; cin >> N;

    vi pm;
    get_primes(pm, N + 1);

    map<ll, ll> mp;
    FOR(i,2,N+1){
        prime_factorize(mp, i, pm);
    }

    ll eMax = 0;
    for(auto p : mp) {
        e.push_back(p.second);
        eMax = max(eMax, p.second);
    }

    dp = vvl(e.size() + MGN, vl(75 + MGN, 0));
    ll ans = dfs(0, 1);
    
    cout << ans << endl;
    e.clear();
    dp.clear();

    return 0;
}

Measured memory_bytes: 256