akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include <iomanip>
typedef long long int ll;
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 EREP(i,n) for (int i=1;i<=(n);i++)
#define EVEL 1
 
#ifndef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {X=X;}
#define TF(f) {f=f;}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 10000000000;
#define NMAX 50
#define MAX 10
		
		int A,B,C,N,M;
		char S;
		
	
int main(){
	cin>>A>>S>>B;
	if(S=='+'){
		cout<<A+B<<endl;
	}else{
		cout<<A-B;
	}
	
	
	
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1000000007;
int n,C[51][51],dp[51][101];
int main()
{
	for(int i=0;i<=50;++i)
	{
		C[i][0]=1;
		for(int j=1;j<=i;++j)(C[i][j]=C[i-1][j-1]+C[i-1][j])>=mod?C[i][j]-=mod:0;
	}
	scanf("%d",&n);
	dp[1][n]=n,dp[1][n-1]=n;
	for(int i=1;i<n;++i)
		for(int j=-n;j<=n;++j)
			if(dp[i][j+n])
				for(int k=max(1,abs(j));k<=n-i;++k)//num of 2^i
					if(!(j+k&1))
						for(int l=0;l<=k;++l)//negative
						{
							int t=(k-2*l+j)>>1;
							if(t>=-n&&t<=n)dp[i+k][t+n]=(dp[i+k][t+n]+1ll*C[n-i][k]*C[k][l]%mod*dp[i][j+n])%mod;
						}
	printf("%d",dp[n][n]);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

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

    ll r;
    cin >> r;
    cout << r*r << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>

using namespace std;

typedef long long int64;

int main(void){
        
    double W,H,x,y;
    cin>>W>>H>>x>>y;
    cout<<static_cast<double>(W*H/2.0)<<" ";
    
    if(x==W/2&&y==H/2) cout<<1<<endl;
    else cout<<0<<endl;


    return 0;
}

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

const int N = 205;
typedef long long LL;

char ch;
int a[N][N], n, clr[N], ok, dis[N][N], ans;

void Dfs(int u, int col) {
	clr[u] = col;
	for(int i = 1; i <= n; i++)
		if(a[u][i] == 1) {
			if(clr[i]) {
				if(clr[i] == col) ok = 1;   
				continue;
			}
			Dfs(i, 3 - col);
		}
}

int main() {
	cin>>n;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++) {
			cin>>ch;
			if(ch == '1') a[i][j] = 1;
			else {
				if(i == j) a[i][j] = 0;
				else a[i][j] = 1e9;
			}
		}
	Dfs(1, 1);
	if(ok) {
		cout<<-1<<endl;
		return 0;
	}
	for(int k = 1; k <= n; k++)
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= n; j++)
				if(a[i][k] + a[k][j] < a[i][j]) 
					a[i][j] = a[i][k] + a[k][j];
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			ans = max(ans, a[i][j]);
	cout<<ans + 1<<endl;
	return 0;
}

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

public class Main {
	int A[];
	void run() {
		Scanner sc = new Scanner(System.in);
		A = new int[3];
		for(int i = 0; i < 3; i++)
			A[i] = sc.nextInt();
		Arrays.sort(A);
		if(A[0]+A[1] == A[2]) System.out.println("Yes");
		else System.out.println("No");
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 21844
import sys
import random
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
s = input().rstrip()
n = len(s)
ans2 = 0
ans = 0
for i in range(n):
    if i%2 == 0 and s[i] != "0":
        ans +=1
    if i%2 == 1 and s[i] != "1":
        ans += 1
for i in range(n):
    if i%2 == 0 and s[i] != "1":
        ans2 +=1
    if i%2 == 1 and s[i] != "0":
        ans2 += 1
print(min(ans2,ans))

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

int main()
{
	REP(i, 10001){
		int x, y;
		cin >> x >> y;
		if(x == 0 && y == 0)
			break;
		
		if(x <= y){
			cout << x << " " << y << endl;
		}
		else{
			cout << y << " " << x << endl;
		}

	}

	return 0;
}




Measured memory_bytes: 3096
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include <functional>
#include <queue>
#include <regex>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;





/*for文でx,yを上下左右確認するやつだよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}
*/

/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}


*/

/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; i++) {
	for (int j = 0; j < w; j++) {

	}
}

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



char a[1001][1001];
int b[1001][1001];

int main(void) {
	int h, w; cin >> h >> w;
	queue<pair<int, int>> q;

	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			b[i][j] = INF;
		}
	}

	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> a[i][j];
			if (a[i][j] == '#') {
				q.push(make_pair(i, j));
			}
		}
	}

	int ans = INF;

	while (!q.empty()) {
		pair<int, int> d = q.front(); q.pop();

		for (int i = 0; i < 4; i++) {
			int ny = d.first + dy[i];
			int nx = d.second + dx[i];

			if (a[ny][nx] == '.' && b[ny][nx] == INF) {
				b[ny][nx] = b[d.first][d.second] + 1;
				q.push(make_pair(ny, nx));
			}
		}

	}

	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			ans = max(ans, b[i][j]);
		}
	}


	cout << ans-INF << endl;







}

Measured memory_bytes: 13328
#include <stdio.h>
#include <algorithm>

#define LIM_S 200002
#define LIM_N 100001

char str[LIM_S];

int N;
int H[LIM_N];

void receive_input() {
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d", &N);

	for (size_t i = 0; i < N; i++) {
		scanf("%d", &H[i]);
	}
}

void initialize() {
}

int solve() {
	int count = 0;
	int max = H[0];

	for (size_t i = 0; i < N; i++) {
		if (max <= H[i]) {
			count++;
			max = H[i];
		}
	}

	return count;
}

int main(void) {
	receive_input();
	initialize();

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

	return 0;
}


Measured memory_bytes: 128
/*
मनस्वी म्रियते कामं कार्पण्यं न तु गच्छति ।
अपि निर्वाणमायाति नानलो याति शीतताम् ॥
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
#define test3(x,y,z) cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define test4(w,x,y,z) cout << #w " = " << w << " " << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

ll sum(ll n)
{
    return (n*(n+1))/2;
}


int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
    ll n;
    cin>>n;

    ll total = 0;

    for(ll i = 1; i <= n; i++)
    {
        total += i*sum(n/i);
    }
        
    cout<<total;


    return 0;
}       

Measured memory_bytes: 3464
# C - management
from collections import Counter


def main():
    N, *A = map(int, open(0).read().split())
    cnt_subordinates = Counter(A)
    ans = [cnt_subordinates[i] for i in range(1, N + 1)]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 43788
# import bisect
from collections import Counter, deque # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    L=[]
    for _ in range(3):
        a,b=map(int,input().split())
        L.append(a-1)
        L.append(b-1)
    LL=Counter(L).most_common()
    if LL[0][1]!=2:
        print('NO')
    else:
        print('YES')
    
    



resolve()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

const ll INF = 1LL<<60;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  vector<vector<ll>> dp(n+5, vector<ll>(n+5,-INF));
  rep(i,n+5) dp[i][i] = 0;
  for (int w = 1; w <= n; ++w) {
    for (int l = 0; l <= n-w; ++l) {
      int r = l + w;
      if (w == 1) dp[l][r] = a[l];
      else {
        dp[l][r] = max(a[r-1] - dp[l][r-1], a[l] - dp[l+1][r]);
      }
    }
  }
  cout << dp[0][n] << endl;
  return 0;
}

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

using namespace std;

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

	int n, k;
	cin >> n >> k;

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

	for(int i = k; i < n; ++i) {
		if(a[i] > a[i - k]) {
			cout << "Yes" << '\n';
		} else {
			cout << "No" << '\n';
		}
	}

	return 0;
}


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

int main()
{
	string s;
	cin >> s;
	for(int i = 1; i <= s.size(); i++){
		if(i%2){
			if(s[i - 1] != 'R' && s[i - 1] != 'U' && s[i - 1] != 'D'){
				cout << "No" << endl;
//				cout << i << endl;
				return 0;
			}
		}else{
			if(s[i - 1] != 'L' && s[i - 1] != 'U' && s[i - 1] != 'D'){
				cout << "No" << endl;
//				cout << i << endl;
				return 0;
			}
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);

	class Comp{
		boolean overflow;
		int r;
		int i;

		public boolean isOverflow(double r){
			return Math.abs(r)>10000;
		}

		Comp(double r,double i,boolean overflow){
			this.r=(int)r;
			this.i=(int)i;
			this.overflow=isOverflow(r) ||isOverflow(i) ||overflow;
		}
		public Comp a(Comp c){
			return new Comp(1.0*r+c.r,1.0*i+c.i, overflow || c.overflow);
		}
		public Comp s(Comp c){
			return new Comp(1.0*r-c.r,1.0*i-c.i,overflow || c.overflow);
		}
		public Comp m(Comp c){
			return new Comp(1.0*r*c.r-1.0*i*c.i,1.0*r*c.i+1.0*i*c.r,overflow || c.overflow);
		}
		public String toString(){
			if(overflow)return "overflow";

			StringBuilder res=new StringBuilder();

			if(r!=0)res.append(r);
			if(r!=0 && i>0)res.append("+");
			if(i!=0)res.append(i+"i");
			if(r==0 && i==0)res.append(0);
			return res.toString();
		}
	}
	public int index=0;

	public Comp factor(char[] f){
		Comp r=term(f);
		while(f.length>index && f[index]=='*'){
			++index;
			Comp _r=term(f);
			r=r.m(_r);
		}
		return r;
	}
	public Comp equation(char[] f){
		Comp r=factor(f);
		while(f.length>index && (f[index]=='+' || f[index]=='-')){
			char op=f[index];
			++index;
			Comp _r=factor(f);
			if(op=='+')r=r.a(_r);
			else r=r.s(_r);
		}
		return r;
	}
	public Comp term(char[] f){
		if(f[index]=='('){
			++index;
			Comp r=equation(f);
			++index;// )skip
			return r;
		}else{
			boolean isminus=false;
			if(f[index]=='-'){
				isminus=true;
				index++;
			}else if(f[index]=='+'){
				index++;
			}
			double val=0;
			while(f.length>index && Character.isDigit(f[index])){
				val=val*10+(f[index]- '0');
				index++;
			}
			if(index<f.length && f[index]=='i'){
				if(val==0)val=1;
				index++;
				return new Comp(0,isminus?-val:val,false);
			}else{
				return new Comp(isminus?-val:val,0,false);
			}
		}
	}

	public void run() {
		while(sc.hasNextLine()){
			index=0;
			char[] f=sc.nextLine().toCharArray();
			ln(equation(f));
		}
	}


	public static void main(String[] args) {
		new Main().run();
	}
	public static void pr(Object o) {
		System.out.print(o);
	}
	public static void ln(Object o) {
		System.out.println(o);
	}
	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
//51
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int n,a,b,c;
  cin>>n>>a>>b>>c;
  int d[10000];
  for(int i=0;i<n;i++){
    cin>>d[i];
  }
  sort(d,d+n,greater<int>());
  int s=c;
  int p=a;
  for(int i=0;i<n;i++){
    if((s+d[i])*1./(p+b)>s*1./p){
      s+=d[i];
      p+=b;
    }else{
      break;
    }
  }
  cout<<s/p<<endl;
  return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define bit(n) (1LL << (n))
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    string S;
    cin >> N >> Q >> S;
    vector<int> l(N), r(N);
    REP(i, Q)
    {
        cin >> l[i] >> r[i];
        l[i]--;
        r[i]--;
    }
    vector<int> ACList;
    REP(i, N - 1)
    {
        if (S[i] == 'A' && S[i + 1] == 'C')
        {
            ACList.push_back(i);
        }
    }
    // ACList.push_back((int)1e6);
    //lowerbound upperboundを使う？
    //l<=x<r だから単純に引くだけ！
    REP(i, (int)ACList.size())
    {
        // cout << "l " << ACList[i] << "\n";
    }
    REP(i, Q)
    {
        cout << lower_bound(ALL(ACList), r[i]) - lower_bound(ALL(ACList), l[i]) << "\n";
    }
}

Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	string s;
	ll n; cin >> n >> s;


	vl len_r(n, 0), len_l(n, 0);
	REP(i, n) {
		if (i == 0) len_l[i] = s[i] - '0';
		else {
			if (s[i] == '1') len_l[i] = len_l[i - 1] + 1;
			else len_l[i] = 0;
		}
	}
	for(ll i = n - 1; i >= 0; --i) {
		if (i == n - 1) len_r[i] = s[i] - '0';
		else {
			if (s[i] == '1') len_r[i] = len_r[i + 1] + 1;
			else len_r[i] = 0;
		}
	}

	// dp[n][0:利用しなかった, 1: 左に利用した, 2: 右に利用した, 3: 右を全部利用した][クールタイム]
	vector<vvl> dp(n, vvl(4, vl(3, -1)));
	dp[1][0][0] = 0;
	FOR(i, 2, n) REP(j, 4) REP(k, 3) if (dp[i - 1][j][k] != -1){
		if (s.substr(i - 2, 3) == "101") {
			// 左
			if (j == 0) MAXC(dp[i][1][2], dp[i - 1][j][k] + len_l[i - 2]);
			if (j <= 1 && k == 0) MAXC(dp[i][1][2], dp[i - 1][j][k] + len_l[i - 2] - 1);
			if (j <= 2 && k == 0) MAXC(dp[i][1][2], dp[i - 1][j][k] + 1);
			// 右
			if (j != 3 && k == 0) MAXC(dp[i][2][2], dp[i - 1][j][k] + len_r[i] - 1);
			if (j != 3 && k == 0) MAXC(dp[i][3][2], dp[i - 1][j][k] + len_r[i]);
			MAXC(dp[i][0][0], dp[i - 1][j][k]);
		} else {
			MAXC(dp[i][j][max(0, k - 1)], dp[i - 1][j][k]);
			if (s.substr(i - 1, 2) == "00")	MAXC(dp[i][0][0], dp[i - 1][j][k]);
		}
	}
	ll ans = 0;
	REP(i, n) REP(j, 4) REP(b, 3) ans = max(ans, dp[i][j][b]);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 137500
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		List<String> gradingResult = new ArrayList<>();
		while (true) {
			int m = s.nextInt();
			int f = s.nextInt();
			int r = s.nextInt();
			s.nextLine();
			if (m == -1 && f == -1 && r == -1) {
				break;
			}
			if ((m == -1 || f == -1)) {
				gradingResult.add("F");
			} else if ((m + f) >= 80) {
				gradingResult.add("A");
			} else if (((m + f) < 80) && ((m + f) >= 65)) {
				gradingResult.add("B");
			} else if (((m + f) < 65) && ((m + f) >= 50)) {
				gradingResult.add("C");
			} else if (((m + f) < 50) && ((m + f) >= 30)) {

				if (r >= 50) {
					gradingResult.add("C");
				} else {
					gradingResult.add("D");
				}
			} else if ((m + f) < 30) {
				gradingResult.add("F");
			}

		}
		for (int i = 0; i < gradingResult.size(); i++) {
			System.out.println(gradingResult.get(i));
		}
	}

}

Measured memory_bytes: 26376
#include <bits/stdc++.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 main(){
    int n; cin >> n;
    string s; cin >> s;

    // int c = 1;
    // string S = "1000";
    // if(S[0] == ('0' + c)) cout << "yes" << endl;
    // else cout << "no" << endl;

    int cnt = 0;
    rep (i, 1000){
        int c[3] = {i / 100, (i / 10) % 10, i % 10};
        int f = 0;

        // cout << c[0] << c[1] << c[2] << endl;

        rep (j, n){
            if (s[j] == ('0' + c[f])) f++;
            if (f == 3) break;
        }
        if (f == 3) cnt++;
    }
    cout << cnt << endl;
}

// int N;
// string S;
// int cnt;

// int main() {
//     int N; cin >> N;
//     string S; cin >> S;
//     int cnt;

// 	// cin >> N >> S;
// 	for (int i = 0; i < 1000; i++) {
// 		int c[3] = {i / 100, (i / 10) % 10, i % 10};
// 		int f = 0;
// 		for (int j = 0; j < N; j++) {
// 			if (S[j] == ('0' + c[f])) f++;
// 			if (f == 3) break;
// 		}
// 		if (f == 3) cnt++;
// 	}
// 	cout << cnt << endl;
// 	return 0;
// }

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
int n,m;string s;vector<int> run;ll ans,k;
int main()
{
    fastio;
    cin>>s>>k;n=s.size();
    int len=1;
    rap(i,1,n){
        if(s[i]!=s[i-1]) run.pb(len),len=1;
        else len++;
    }
    run.pb(len);m=run.size();
    if(m==1) {cout<<(ll)n*k/2;return 0;}
    rap(i,0,m) ans+=run[i]/2*k;
    if(s[0]==s.back()&&(run[0]+run[m-1])%2==0) ans+=k-1;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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;

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

  set<string> arares;
  string arare;
  rep(i, N) {
    cin >> arare;
    arares.insert(arare);
  }

  switch (arares.size()) {
    case 3:
      cout << "Three" << endl;
      break;
    case 4:
      cout << "Four" << endl;
      break;
  }
}


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

using namespace std;

const int N = 200005;

int a[N], n;

int main(){
    scanf("%d",&n);
    int s=0;
    for(int i=1;i<=n;++i){
        scanf("%d",a+i);
        s^=a[i];
    }

    for(int i=1;i<=n;++i){
        printf("%d ",s^a[i]);
    }

    return 0;
}


Measured memory_bytes: 4592
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int E = sc.nextInt();
        int F = sc.nextInt();

        Set<Integer> waterSet = new HashSet<>();
        Set<Integer> sugarSet = new HashSet<>();
        createSugar(sugarSet, C, D, F);
        createWater(waterSet, A, B, F);

        double maxRatio = -1;
        int resultSugar = -1;
        int resultWater = -1;

        for (int water : waterSet) {
            for (int sugar : sugarSet) {
                if ((water + sugar) <= F && sugar <= (water / 100) * E) {

                    double ratio = ((double) (100 * sugar)) / (water + sugar);
                    if (ratio > maxRatio) {
                        maxRatio = ((double)(100 * sugar)) / (water + sugar);
                        resultSugar = sugar;
                        resultWater = water;
                    }
                }
            }
        }

        System.out.println(resultSugar + resultWater + " " + resultSugar);


    }

    private static void createWater (Set<Integer> waterSet, int A, int B, int F) {
        for (int i = 0; i < F ; i++) {
            for (int j = 0; j < F; j++) {
                int water = A * 100 * i + B * 100 * j;
                if (water != 0 && water < F) waterSet.add(water);
            }
        }
    }

    private static void createSugar(Set<Integer> sugarSet, int C, int D, int F) {
         for (int i = 0; i < F; i++) {
            for (int j = 0; j < F; j++) {
                int sugar = C * i + D * j;
                if (sugar < F) sugarSet.add(sugar);
            }
        }
    }

}


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

using namespace std;

typedef long long ll;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x, y, z;
    cin >> x >> y >> z;
    cout << (x - z) / (y + z) << endl;
    return 0;
}

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

#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint>PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;
int dx[]={0,0,1,-1};
int dy[]={-1,1,0,0};

int N;
int a[100010],b[100010];
int asum=0,bsum=0;

signed main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin>>N;
    rep(i,0,N){
        cin>>a[i];
        asum+=a[i];
    }
    rep(i,0,N){
        cin>>b[i];
        bsum+=b[i];
    }
    int csum=bsum-asum;
    if(csum<0){
        cout<<"No"<<"\n";
        return 0;
    }
    
    int cnta=0,cntb=0;
    rep(i,0,N){
        if(a[i]<b[i]){
            cntb+=(b[i]-a[i]+1)/2;
        }else{
            cnta+=a[i]-b[i];
        }
    }
    if(cntb<=csum&&cnta<=csum){
        cout<<"Yes"<<"\n";
    }else{
        cout<<"No"<<"\n";
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str;
            str = Console.ReadLine ().Split (' ');

            int N = int.Parse (str[0]);
            int[] a = new int[N];

            str = Console.ReadLine ().Split (' ');
            for (int i = 0; i < N; i++)
            {
                a[i] = int.Parse (str[i]);
            }

            int ans = 0;
            for (int i = 0; i < N; i += 2)
            {
                if (a[i] % 2 == 1) ans++;
            }

            Console.Write (ans);

        }
    }

    class MyLibrary
    {
        public static int GCD (int a, int b)
        {
            if (a % b == 0) return b;
            return GCD (b, a % b);
        }
    }
}

Measured memory_bytes: 27176
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MOD 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define forr(i,p,n) for(ll i=p;i<n;i++)
#define MAXN 500003
typedef long long ll;
inline ll mod(ll x,ll n)
{
    if(x<n)
    {
        return x;
    }
    return x-n;
}
using namespace std;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n%p; n = n * n%p;} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll 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;}



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

vector<ll>v;
 ll sum=0,act=0,k,n,q,f;
cin>>n>>k;
ll arr[n];
ll dp[n+1];
forr(i,0,n){cin>>arr[i];
dp[i]=1e9;}
dp[0]=0;
if(k>n)k=n;
forr(i,1,k)
{
    dp[i]=abs(arr[i]-arr[0]);
}

forr(i,k,n)
{
    ll x=1e9,y=1e9;
    forr(j,i-k,i)
    {
        x=min(x,abs(arr[j]-arr[i])+dp[j]);
    }
    dp[i]=x;
}
cout<<dp[n-1]<<endl;

return 0;
}


Measured memory_bytes: 5188
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <utility>
#include <limits.h>
using namespace std;
typedef vector<vector<int>> matrix;

void bfs(matrix G)
{
    int N = G.size() - 1;

    // node[i] = pair<is_visited, int depth>
    vector<pair<bool, int>> node(N + 1, make_pair(false, 0));
    queue<int> Q;

    // initial step
    Q.push(1);
    node[1] = make_pair(true, 0);

    // BFS
    while (!Q.empty())
    {
        int n = Q.front();
        Q.pop();

        int depth = node[n].second;

        for (int i = 1; i <= N; i++)
        {
            bool is_visited = node[i].first;
            bool can_visit = G[n][i];

            if (!is_visited && can_visit)
            {
                Q.push(i);
                node[i] = make_pair(true, depth + 1);
            }
        }
    }

    for (int i = 1; i <= N; i++)
    {
        if (node[i].first == false)
        {
            cout << i << " " << -1 << endl;
        }
        else
        {
            cout << i << " " << node[i].second << endl;
        }
    }
    return;
}

int main()
{
    // 入力
    int N;
    cin >> N;
    matrix G(N + 1, vector<int>(N + 1, 0));

    for (int i = 0; i < N; i++)
    {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            G[u][v] = 1;
        }
    }

    bfs(G);
    return 0;
}



Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a, b) memset((a), (b), sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define pii pair<int, int>
#define pb push_back
const int INF = 0x3f3f3f3f;
const double eps = 1e-10;
const int maxn = 1e5 + 7;
const int maxm = 5e5 + 10;
ll a[maxn];
ll dp[maxn];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    mst(dp, INF);
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    dp[0] = 0;
    dp[1] = 0;
    for (int i = 2; i <= n; ++i)
    {
        for (int j = i - 1; j >= max(1, i - m); --j)
        {
            dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
        }
    }
    cout << dp[n] << endl;
    return 0;
}

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

long long N, K;
long long H[100];
vector<long long> L;
long long P[60];
long long D[101][101];
#define MOD 1000000007LL
long long R;

long long pow(long long x) {
  long long r = 1;
  for(long long b = 0; b < 60; ++b) {
    if((1LL << b) & x) (r *= P[b]) %= MOD;
  }
  return r;
}
int main() {
  P[0] = 2LL;
  for(long long i = 1; i < 60; ++i) {
    P[i] = P[i - 1] * P[i - 1] % MOD;
  }
  cin >> N;
  L.push_back(0);
  for(long long i = 0; i < N; ++i) {
    cin >> H[i]; L.push_back(H[i]);
  }
  sort(L.begin(), L.end());
  L.erase(unique(L.begin(), L.end()), L.end());
  K = L.size();
  /*for(long long k = 0; k < K; ++k) {
    cout << "L[" << k << "] : " << L[k] << endl;
  }*/
  long long prev_l = 0; D[0][0] = 1;
  for(long long i = 0; i < N; ++i) {
    long long l = lower_bound(L.begin(), L.end(), H[i]) - L.begin();
    /*cout << "i=" << i
      << " l=" << l << " prev_l=" << prev_l << endl;*/
    if(prev_l >= l) {
      (D[i + 1][0] += 2 * D[i][0] % MOD) %= MOD;
      for(long long k = 1; k <= l; ++k) {
        (D[i + 1][k] += D[i][k]) %= MOD;
      }
      for(long long k = l + 1; k <= prev_l; ++k) {
        (D[i + 1][0] += 2 * D[i][k] % MOD) %= MOD;
      }
    } else {
      (D[i + 1][0] += 2 * D[i][0] % MOD) %= MOD;
      for(long long k = prev_l + 1; k <= l; ++k) {
        (D[i + 1][k] +=
          2
          * (pow(L[k] - L[k - 1] - (k - 1 == 0 ? 1 : 0)) + MOD - 1) % MOD
          * pow(L[l] - L[k]) % MOD
          * D[i][0]) %= MOD;
      }
      long long C = pow(L[l] - L[prev_l]);
      for(long long k = 1; k <= prev_l; ++k) {
        (D[i + 1][k] += C * D[i][k] % MOD) %= MOD;
      }
    }
    /*for(long long k = 0; k <= l; ++k) {
      cout << "  " << "D[][" << k << "]="
        << D[i + 1][k] << endl;
    }*/
    prev_l = l;
  }
  for(long long k = 0; k < K; ++k) {
    (R += D[N][k]) %= MOD;
  }
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>

using namespace std;

vector<int> ans;
bool isPrime(int num);

int main(){
	while(1){
		int a,b,n;
		cin >> a >> b >> n;
		if(a + b + n == 0) break;
		
		int count = 0;
		int nn = a;
		if(isPrime(nn)) count++;
		while(count < n){
			nn += b;
			if(isPrime(nn))count++;
		}
		ans.push_back(nn);
	}
	for(int i = 0;i < ans.size();i++) cout << ans[i] << endl;
	
	return 0;
}

bool isPrime(int num){
	bool p = true;
	if(num == 1) return false;
	for(int i = 2;i < num;i++){
		if(num > 5 && i*i > num) break;
		if(num % i == 0){ p = false; break;}
	}
	return p;
}

Measured memory_bytes: 3008
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
using datas=pair<ll,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}

int main(){
  ll i,j,N,x,ans=0,sum=0;
  cin>>N;
  vector<ll> a(N),b(N),p,m;
  rep(i,N){
    cin>>a[i];
  }
  rep(i,N){
    cin>>b[i];
    x=a[i]-b[i];
    sum+=x;
    if(x<0){
      m.push_back(-x);
      ans++;
    }else{
      p.push_back(x);
    }
  }
  if(sum<0){cout<<-1<<endl;return 0;}
  vrsort(p);

  j=0;
  if(m.size())ans++;
  rep(i,(ll)m.size()){
    if(m[i]<=p[j]){
      p[j]-=m[i];
    }else{
      m[i]-=p[j];
      j++;
      ans++;
      i--;
      continue;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 2936
if __name__ == "__main__":
    inst_num = int(input())
    dictionary = {}

    for _ in range(inst_num):
        operation, value = input().split()
        if "insert" == operation:
            dictionary[value] = 1
        elif "find" == operation:
            if dictionary.get(value):
                print("yes")
            else:
                print("no")
        else:
            pass



Measured memory_bytes: 33112
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
    int N, Q;
    cin >> N >> Q;
    vector<P> v;
    for(int i = 0; i < N; i++){
        long long int S, T, X;
        cin >> S >> T >> X;
        v.push_back(P(S - X, X));
        v.push_back(P(T - X, X));
    }
    sort(v.begin(), v.end());
    map<long long int, int> m;
    int pos = 0;
    for(int loop = 0; loop < Q; loop++){
        long long int D;
        cin >> D;
        while(pos < v.size() && v[pos].first <= D){
            if(m.find(v[pos].second) != m.end()){
                m.erase(v[pos].second);
            }else{
                m[v[pos].second] = 1;
            }
            pos += 1;
        }
        if(m.size() == 0){
            cout << -1 << endl;
        }else{
            cout << m.begin()->first << endl;
        }
    }
    return 0;
}

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

int main() {
    vector<char> vec(3);
    for(int i = 0; i < 3; i++){
        cin >> vec.at(i);
    }
    if(vec.at(0) != vec.at(1) && vec.at(1) != vec.at(2) && vec.at(2) != vec.at(0)){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
n, q = gets.chomp.split(' ').map(&:to_i)
array = []
n.times do |i|
  array[i] = gets.chomp.split(' ').map(&:to_s)
end
time = 0
while array.length != 0
  tmp = array.shift
  tmp[1] = tmp[1].to_i
  if tmp[1] <= q
    time += tmp[1]
    puts tmp[0] << ' ' << time.to_s
  else
    time += q
    tmp[1] -= q
    array.push(tmp)
  end
end

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

char s[200010] ;

int num[30] ;

int main(){
	#define NAME "arc019b"
	//freopen( NAME".inp" , "r" , stdin ) ; freopen( NAME".out" , "w" , stdout ) ;

	scanf("%s", s + 1) ;

	int len = strlen(s + 1) ;

	long long ans = 1ll ;

	for (int i = 1; i <= len; ++ i){
		ans += 1ll * (i - 1 - num[s[i] - 'a']) ;
		num[s[i] - 'a'] ++ ;
	}

	printf("%lld", ans) ;

	return 0 ;
}

Measured memory_bytes: 384
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 3005;

int i,j,k,R,C,K,a[N][N],dp[N][N][5];

void solve()
{
    fill(dp,0);
    cin>>R>>C>>K;
    for(i=1;i<=K;i++)
    {
        int r,c,v;
        cin>>r>>c>>v;
        a[r][c]=v;
    }
    if(a[1][1])
        dp[1][1][1]=a[1][1];
    for(i=1;i<=R;i++)
    {
        for(j=1;j<=C;j++)
        {
            for(k=0;k<4;k++)
            {
                if(a[i+1][j])
                    dp[i+1][j][1]=max(dp[i+1][j][1],dp[i][j][k]+a[i+1][j]);
                else
                    dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
                if(a[i][j+1])
                {
                    dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
                    dp[i][j+1][k+1]=max(dp[i][j+1][k+1],dp[i][j][k]+a[i][j+1]);
                }
                else
                    dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
            }
        }
    }
    int ans=0;
    for(i=0;i<4;i++)
    {
        ans=max(ans,dp[R][C][i]);
    }
    cout<<ans;
}

signed main()
{
    fastio;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

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

    map <int,pair<int,int>> d;

    rep(i,n){
        int tmp,x,y;
        cin >> tmp >> x >> y;
        d[tmp] = make_pair(x,y);
    }

    int pt,px,py;
    int first = 0;
    for(auto nx = d.begin(); nx != d.end(); ++nx){

        int ty = abs(pt - nx->first);
        int dx = abs(px - nx->second.first);
        int dy = abs(py - nx->second.second);
        if(ty < dx + dy){
            cout << "No" << endl;
            return 0;
        }else{

            if( (ty - (dx + dy )) % 2 == 0){
                continue;
            }else{
                cout << "No" << endl;
                return 0;
            }
        }

        pt = nx->first;
        px = nx->second.first;
        py = nx->second.second;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 6528
N, X = map(int, input().split())

P = [1]
B = [1]
for i in range(N):
  P.append(P[i] * 2 + 3)
  B.append(B[i] * 2 + 1)

def rec(N, X):
  if N == 0:
    if X <= 0:
      return 0
    else:
      return 1
  elif X <= 1 + P[N - 1]:
    return rec(N - 1, X - 1)
  else:
    return B[N - 1] + 1 + rec(N - 1, X - 2 - P[N - 1])

print(rec(N, X))

Measured memory_bytes: 3064
N, K = map(int, input().split())
P = list(map(int, input().split()))

a = [0] * (N - K + 1)
a[0] = sum(P[:K])
for i in range(1, N - K + 1):
    a[i] = a[i - 1] - P[i - 1] + P[i + K - 1]
    
print((max(a) + K) / 2)

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int mINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(){
    int n,m;cin >> n >> m;
    vii G(10,vi(10));

    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        G[a][b] = G[b][a] = 1;
    }

    int ans = 0;
    vi ord(n);
    iota(ALL(ord),0);
    do{
        if(ord[0]!=0)break;
        int exist = true;
        for(int i=0;i<n-1;i++){
            int from = ord[i];
            int to = ord[i+1];
            if(G[from][to]!=1)exist = false;
        }
        if(exist)ans++;
    }while(next_permutation(ALL(ord)));

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

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

int main(){
    long long n,K;
    cin>>n>>K;
    long long s[n+1];
    s[0]=0;
    rep(i,n){
        long long a;
        cin>>a;
        s[i+1]=s[i]+a;
    }
    vector<long long>beauty((n*(n+1))/2);
    long long cur=0;
    for(int i=0;i<n;i++){
        for(int k=i+1;k<=n;k++){
            beauty[cur]=(s[k]-s[i]);
            cur++;
        }
    }
    long long int second[45];
    int p=0;
    second[0]=1;
    rep(i,44){
        second[i+1]=second[i]*2;
        if(second[i]<0)break;
        
    }
    
    
    long long ans=0;
    
    long long  all=beauty.size();

    for(int i=44;i>-1;i--){
        
        long long  cnt=0;
        for(int k=0;k<all;k++){
            if(beauty[k]<0)continue;
            
            if(((second[i]+ans)&beauty[k])==(ans+second[i])){
                cnt++;
            }
        }
        
        if(cnt>=K){
            ans|=second[i];
        }
    }
    //cout<<endl;
    
    cout<<ans<<endl;
    
    return 0;

}
/*
4 2
2 5 2 5

12


*/


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

int main(void){

  int map[10][10] = {{0,0}};

  int x,y,s,white = 0,maxi = 0;
  char c1,c2;

  while(cin >> x >> c1 >> y >> c2 >> s){

    if(s == 1){
      map[x][y]++;
      (x+1 <= 9) ? map[x+1][y]++ : map[x+1][y]+=0;
      (y+1 <= 9) ? map[x][y+1]++ : map[x][y+1]+=0;
      (x-1 >= 0) ? map[x-1][y]++ : map[x-1][y]+=0;
      (y-1 >= 0) ? map[x][y-1]++ : map[x][y-1]+=0;
    }

    if(s == 2){
      map[x][y]++;
      (x+1 <= 9) ? map[x+1][y]++ : map[x+1][y]+=0;
      (y+1 <= 9) ? map[x][y+1]++ : map[x][y+1]+=0;
      (x-1 >= 0) ? map[x-1][y]++ : map[x-1][y]+=0;
      (y-1 >= 0) ? map[x][y-1]++ : map[x][y-1]+=0;
      (x+1 <= 9 && y+1 <= 9) ? map[x+1][y+1]++ : map[x+1][y+1]+=0;
      (x-1 >= 0 && y+1 <= 9) ? map[x-1][y+1]++ : map[x-1][y+1]+=0;
      (x+1 <= 9 && y-1 >= 0) ? map[x+1][y-1]++ : map[x+1][y-1]+=0;
      (x-1 >= 0 && y-1 >= 0) ? map[x-1][y-1]++ : map[x-1][y-1]+=0;

    }

    if(s == 3){
      map[x][y]++;
      (x+1 <= 9) ? map[x+1][y]++ : map[x+1][y]+=0;
      (y+1 <= 9) ? map[x][y+1]++ : map[x][y+1]+=0;
      (x-1 >= 0) ? map[x-1][y]++ : map[x-1][y]+=0;
      (y-1 >= 0) ? map[x][y-1]++ : map[x][y-1]+=0;
      (x+1 <= 9 && y+1 <= 9) ? map[x+1][y+1]++ : map[x+1][y+1]+=0;
      (x-1 >= 0 && y+1 <= 9) ? map[x-1][y+1]++ : map[x-1][y+1]+=0;
      (x+1 <= 9 && y-1 >= 0) ? map[x+1][y-1]++ : map[x+1][y-1]+=0;
      (x-1 >= 0 && y-1 >= 0) ? map[x-1][y-1]++ : map[x-1][y-1]+=0;
      (x+2 <= 9) ? map[x+2][y]++ : map[x+2][y]+=0;
      (y+2 <= 9) ? map[x][y+2]++ : map[x][y+2]+=0;
      (x-2 >= 0) ? map[x-2][y]++ : map[x-2][y]+=0;
      (y-2 >= 0) ? map[x][y-2]++ : map[x][y-2]+=0;
    }    
  }
  maxi = map[0][0];
  for(int i = 0;i < 10;i++){
    for(int j = 0;j < 10;j++){
      if(map[i][j] == 0){
        white++;
      }
      if(maxi < map[i][j]){
        maxi = map[i][j];
      }
    }
  }
  cout << white << endl << maxi << endl;
  return 0;
}

Measured memory_bytes: 3020
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint s[100100];
vector<lint> sum[100100],rsum[100100];
int n;
/*lint cal(int A,int x){
	if(A==x) return 0;
	if(A%x==0){
		if(A*2<=n-1) return 0;
	}
	return sum[x][(n-1-A)/x]+rsum[x][(n-1-A)/x];
}*/
int main()
{
	lint out=0;
	cin>>n;
	rep(i,n) cin>>s[i];
	REP(i,1,100050){
		lint su=0,r=n-1,l=0;
		while(1){
			r-=i;
			if(r<=0 || r==l) break;
			su+=s[r];
			l+=i;
			if(l>=n-1 || r==l) break;
			su+=s[l];
			if(r>i) out=max(out,su);
		}
	}
	/*REP(A,2,n-1){
		for(int i=1;i*i<=(n-1-A);i++){
			if((n-1-A)%i==0){
				out=max(out,cal(A,i));
				out=max(out,cal(A,(n-1-A)/i));
			}
		}
	}*/
	cout<<out<<endl;
}


Measured memory_bytes: 5760