akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979

//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
const int64_t MOD = 1000000007;
//const int64_t INF = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
//#define P pair<int, int>
typedef pair<int, int> P;

int64_t powmod(int64_t x, int64_t n){
    //pow(x, n) % MOD
    int64_t ret = 1;
    while(n > 0){
        if(n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

int64_t nikou(int64_t A, int64_t B){
    //B Combination A
    int64_t x = 1, y = 1;
    rep(i, 0, A){
        x *= (B - i);
        y *= (i + 1);
        x %= MOD;
        y %= MOD;
    }
    y = powmod(y, MOD - 2);
    return x * y % MOD;
}

int main(){
    int X, Y;
    cin >> X >> Y;
    int64_t A, B;
    if((2 * Y - X) % 3 == 0 && (2 * X - Y) % 3 == 0){
        A = (2 * Y - X) / 3;
        B = (2 * X - Y) / 3;
        if (A < 0 || B < 0){
            cout << 0 << endl;
            return 0;
        }
    }
    else{
        cout << 0 << endl;
        return 0;
    }
    if(A > B) swap(A, B);
    cout << nikou(A, A + B)<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
char S[maxn];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> S + 1;
	int n = strlen(S + 1);
	// (sum[r] - sum[l - 1]) * 2 > r - l + 1
	// 2 * sum[r] - r - (2 * sum[l - 1] - (l - 1)) > 0
	for(int j = 0; j < 26; ++j) {
		multiset<pair<int, int> > s;
		vector<int> sum(n + 5, 0);
		for(int i = 1; i <= n; ++i) {
			sum[i] = sum[i - 1] + (S[i] - 'a' == j);
			auto it = s.lower_bound({2 * sum[i] - i, -n});
			if(it != s.begin()) {
				cout << s.begin() -> second + 1 << ' ' << i << '\n';
				return 0;
			}
			s.emplace(2 * sum[i - 1] - (i - 1), i - 1);
		}
	}
	cout << -1 << ' ' << -1 << '\n';
	return 0;
}

Measured memory_bytes: 5496
#include<bits/stdc++.h>
using namespace std;
char a[100010];
int b,c;
int main()
{
    ios::sync_with_stdio(0);
    cin>>a;
    for(int i=0;i<strlen(a);i++){
        if(a[i]=='0')
            b++;
        else c++;
    }
    cout<<2*min(b,c)<<endl;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using lint=long long;
using namespace std;

const int mod=1e9+7;

#include<map>
template<typename T> 
void factP(map<T,T> &m,T n)
{
	T x=n;
	for(T i=2;i*i<=n;i++)
	{
		while(x%i==0)
		{
			m[i]++;
			x/=i;
		}
	}
	if(x!=1)m[x]++;
	return;
}

int64_t pow(int64_t a,int64_t b,int64_t mod)
{
	if(b==0)return 1;
	if(b%2==0)
	{
		int64_t d=pow(a,b/2,mod);
		return (d*d)%mod;
	}else//if(b%2==1)
	{
		return (a*pow(a,b-1,mod))%mod;
	}
}

int64_t comb(int64_t n,int64_t r,int64_t p)
{
	int64_t ret=1;
	for(int64_t i=0;i<r;i++)
	{
		ret*=(n-i);
		ret%=p;
	}
	for(int64_t i=2;i<=r;i++)
	{
		ret*=pow(i,p-2,p);
		ret%=p;
	}
	return ret;
}

int64_t rcomb(int64_t n,int64_t r,int64_t p)
{
	return comb(n+r-1,r,p);
}

int main()
{
	int N,M;
	
	cin >> N >> M;
	
	map<int,int> m;
	factP(m,M);
	
	lint ans=1;
	for(auto&& i:m)
	{
		ans*=comb(N+i.second-1,N-1,mod);
		ans%=mod;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n = input()
N = int(n)

SP = {}
SPset = set()
S = []
P = []
R = []
for i in range(N):
    s, p = input().split()
    SPset.add(s)
    P.append(int(p))
    S.append(s)


SPset = list(SPset)
SPset.sort()

for spset in SPset:
    tmp = [i for i, x in enumerate(S) if x == spset]
    Plist = []
    for t in tmp:
        Plist.append(P[t])
    Plist.sort()
    for p in Plist[::-1]:
        R.append(P.index(p) + 1)
        
for r in R:
    print(r)


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

#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()

const int NAX = 2e5 + 5, MOD = 1000000007;

class Solution
{
private:
public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        int n;
        cin >> n;
        vector<int> a(n);
        int xorsum = 0;
        for (auto &x : a)
        {
            cin >> x;
            xorsum ^= x;
        }
        for (auto &x : a)
        {
            cout << (xorsum ^ x) << ' ';
        }
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
    // cin >> t;
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef LOCAL
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}


Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
using ll=long long;
#include <set>
#include <queue>
using namespace std;
ll gcd(ll x,ll y){
    if(y==0){
        return x;
    }else{
        return gcd(y,x%y);
    }
}
int main(){
    ll n;
    cin >> n;
    vector<pair<ll,ll>> vec1(1e5+5);
    vector<pair<ll,ll>> vec2(1e5+5);
    for(ll i=0;i<n;i++){
        ll x;cin>> x;
        if(i%2==0){
            vec1[x].first++;
            vec1[x].second=x;
          //  cout<<x<<endl;
        }else{
            vec2[x].first++;
            vec2[x].second=x;
          //  cout<<x<<endl;
        }
    }
    sort(vec1.begin(),vec1.end(),greater<pair<ll,ll>>());
    sort(vec2.begin(),vec2.end(),greater<pair<ll,ll>>());
   // cout<<vec2[0].first<<endl;
    if(vec1[0].second==vec2[0].second){
        if(vec2[0].first==vec1[0].first){
            cout<<n-vec1[0].first-max(vec2[1].first,vec1[1].first)<<endl;
        }else if(vec2[0].first>vec1[0].first){
            cout<<n-vec1[1].first-vec2[0].first<<endl;
        }else{
            cout<<n-vec1[0].first-vec2[1].first<<endl;
        }
    }else{
       cout<<n-vec1[0].first-vec2[0].first<<endl;
     //  cout<<vec1[0].first<<" "<<vec2[0].first<<endl;
    }
}

Measured memory_bytes: 3328
S=int(input())

if S>=3600:
    h=int(S/3600)
else:
    h=0

if (S-h*3600)>=60:
    m=int((S-h*3600)/60)
else:
    m=0

s=S-(h*3600+m*60)

print(h,m,s,sep=":")


Measured memory_bytes: 5592
/*
    author : Divyansh Gupta
*/

#include <iostream>
#include <iomanip>
#include <cstring>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include<climits>

using namespace std;

void print_err() {
	cerr<<"\n";
}

template <class T,class... Arg>
void print_err(T x,Arg&&... args) {
	cerr<<x<<" ";
	print_err(args...);
}

#ifdef local
#define debug(...) print_err(__VA_ARGS__)
#else
#define debug(...)
#endif

#define test_case int test_cases;\
                cin>>test_cases;\
                while(test_cases--)
#define lu(var,l,r) for(var=l;var<r;var++)
#define ld(var,r,l) for(var=r;var>=l;var--)
#define ll long long
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int> >
#define vll vector<ll>
#define vvll vector<vector<ll> >;               	
#define pii pair<int,int>                	
#define br cout<<"\n"
#define sp cout<<" "
#define pr cout<<
#define in cin>>
#define f first
#define s second                    
#define mod 1000000007
            
void solve(){
	int n,i,j,k;
	ll A[401],ans;

	ll dp[401][401];

	A[0] = 0;

	in n;

	lu(i , 1 , n + 1) {
		in A[i];
	}

	//Taking prefix sum
	lu(i , 2 , n + 1) {
		A[i] = A[i - 1] + A[i];
	}

	//Setting diagonals of dp as 0
	lu(i , 1 , n + 1) {
		dp[i][i] = 0;
	}

	//Filling up dp
	lu(i , 2 , n + 1) {
		ld(j , i - 1 , 1) {
			ans = LLONG_MAX;
			lu(k , j , i) {
				ans = min(ans , 0ll + A[i] - A[j - 1] + dp[j][k] + dp[k + 1][i]);
			}
			dp[j][i] = ans;
		}
	}
	pr dp[1][n];
	br;
}

int main(){
    // test_case
    solve();
    return 0;
}

Measured memory_bytes: 1536
import math

N = int(input())

def log_ceil(x):
    return math.ceil(math.log2(x))

edges = [[None for _ in range(N+1)] for _ in range(N+1)]

def solve(lo, hi):
    if lo == hi:
        return
    mid_connect = log_ceil(hi-lo+1)
    mid = (lo+hi)//2
    for l_it in range(lo,mid+1):
        for r_it in range(mid+1, hi+1):
            edges[l_it][r_it] = mid_connect
    solve(lo, mid)
    solve(mid+1,hi)

solve(1,N)

for i,x in enumerate(edges[1:-1]):
    print(" ".join(map(str, x[i+2:])))

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

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans=0;
    int x=0;
    for (int i=0;i<n;i++) {
        if (s[i]=='I') x++;
        else if (s[i]=='D') x--;
        ans=max(ans,x);
    }
    cout << ans << endl;
}

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

int main(){
	int n,tmp,cnt=0;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> tmp;
		if(tmp%2==1)
			cnt++;
	}
	cnt%2==0?(cout<<"YES"<<endl)
			:(cout<<"NO"<<endl);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define repa(X,A,Y) for (int (X) = A;(X) <= (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_M = 100000;
int N, M;
ll X[MAX_M];
ll between[MAX_M];

int main() {
  std::ios::sync_with_stdio(false);std::cin.tie(0);
  cin >> N >> M;
  rep(i, M) cin >> X[i];
  sort(X, X+M);

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

  for (int i = 0; i < M-1; ++i) between[i] = X[i+1] - X[i];
  sort(between, between+M-1);

  ll ans = 0;
  for (int i = 0; i < M-N; ++i) ans += between[i];

  cout << ans << endl;

  return 0;
}


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

int main(){
	int N;
	cin >> N;
	int countAB = 0;
	int countA = 0;
	int countB = 0;
	int countBA = 0;

	for (int i = 0; i < N; i++)
	{
		string s;
		cin >> s;
		for (int j = 1; j < s.length(); j++)
		{
			if( s[j - 1] == 'A' && s[j] == 'B' ) countAB++;
		}
		if(s[0] == 'B' && s[s.length() - 1] == 'A')
		{
			countBA++;
		} else {
			if(s[0] == 'B'){
				countB++;
			}
			if(s[s.length()-1] =='A')
			{
				countA++;
			}
		}
	}

	if(countBA == 0){
		cout << (countAB + min(countA, countB)) << endl;
	} else if(countA == 0 && countB == 0)
	{
		cout << (countAB + countBA - 1) << endl;
	} else {
		countA++;
		countB++;
		cout << (countAB + countBA - 1 + min(countA, countB)) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, char const *argv[])
{

	int time,h,m,s;
	std::cin>>time;
	h=time/3600;
	m=time%3600/60;
	s=time%60;
	std::cout<<h<<":"<<m<<":"<<s<<std::endl;
	return 0;
}

Measured memory_bytes: 1168
#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() {
	// A - Kyu in AtCoder
	int x;
	cin >> x;

	if (400 <= x && x < 600)
		cout << 8 << endl;

	else if (600 <= x && x < 800)
		cout << 7 << endl;

	else if (800 <= x && x < 1000)
		cout << 6 << endl;

	else if (1000 <= x && x < 1200)
		cout << 5 << endl;

	else if (1200 <= x && x < 1400)
		cout << 4 << endl;

	else if (1400 <= x && x < 1600)
		cout << 3 << endl;

	else if (1600 <= x && x < 1800)
		cout << 2 << endl;

	else if (1800 <= x && x < 2000)
		cout << 1 << endl;

	system("pause");
	return 0;
}

Measured memory_bytes: 3692
l = []
for i in range(5):
  x = input()
  l.append([int(x[-1]), int(x)])

l.sort()

ans = 0
flag = True
for l1, l2 in l:
  if l1 == 0:
    ans += l2
  elif flag:
    ans += l2
    flag = False
  else:
    ans += ((l2//10) + 1) * 10

print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;

public static class Solution
{
    public static void Main()
    {
        var N = Console.ReadLine();
        long sum = 0;
        foreach (var c in N)
        {
            sum += c - '0';
        }

        if (sum % 9 == 0)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 26376
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;cin >> n >> q;
    vector<pair<int,pair<int,int>>> v;
    for(int i=0;i<n;i++){
        int s,t,x;cin >> s >> t >> x;
        v.push_back({s-x,{-1,x}});
        v.push_back({t-x,{0,x}});
    }
    for(int i=0;i<q;i++){
        int d;cin >> d;
        v.push_back({d,{1,i}});
    }
    vector<int> ans(q);
    sort(v.begin(),v.end());
    multiset<int> st;
    for(auto x:v){
        int a=x.first,b=x.second.first,c=x.second.second;
        if(b==-1){
            st.insert(c);
        }
        else if(b==0){
            st.erase(st.lower_bound(c));
        }
        else{
            if(st.empty()){
                ans[c]=-1;
            }
            else{
                ans[c]=*st.begin();
            }
        }
    }
    for(int i=0;i<q;i++){
        cout << ans[i] << endl;
    }
}

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

string to_string(string s) {
    return '"' + s + '"';
}
string to_string(char ch) {
    string s(1, ch);
    return '\'' + s + '\'';
}
string to_string(const char *s) {
    return to_string((string)s);
}
string to_string(bool b) {
    return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
 
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long int ll;
#define int ll
#define pb          push_back
#define pll         pair<int,int>
#define mll	        map<int,int>
#define F           first
#define S           second
#define lbnd(v,val) lower_bound(v.begin(),v.end(),val)
#define ubnd(v,val) upper_bound(v.begin(),v.end(),val)
#define bs(v,val)   binary_search(v.begin(),v.end(),val)
#define mp          make_pair
#define f(i,x,n)    for(int i=x;i<n;i++)
#define isup		isupper
#define islow 		islower
#define max3(a,b,c)	max(a,max(b,c))
#define endl        "\n"
#define countbits(n)	 __builtin_popcountll(n)
#define all(ar) ar.begin(), ar.end()
#define rall(ar) (ar).rbegin(), (ar).rend()
const ll mod = 1e9 + 7;
const ll inf = LLONG_MAX;
const ll N = 2e5 + 10;

typedef vector<vector<ll>> matrix;
typedef vector<ll> vll;


void solve(){
	int n;
	cin>>n;
	double v[n+1];
	f(i,1,n+1){
		cin>>v[i];
	}
	double dp[n+1][n+1];
	f(i,0,n+1){
		f(j,0,n+1){
			dp[i][j]=0;
		}
	}
	// f(i,0,n+1){
	// 	f(j,0,n+1){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	dp[1][0] = 1-v[1];
	f(i,2,n+1){
		dp[i][0]=dp[i-1][0]*(1-v[i]);
	}
	dp[1][1] = v[1];
	f(i,2,n+1){
		dp[i][i] = dp[i-1][i-1]*v[i];
	}
	f(i,1,n+1){
		f(j,1,i){
			dp[i][j] = dp[i-1][j-1]*(v[i]) + dp[i-1][j]*(1-v[i]);
		}
	}
	// f(i,0,n+1){
	// 	f(j,0,n+1){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	double ans=0;
	for(int i=n/2+1;i<=n;i++){
		ans+= dp[n][i];
	}
	cout<<fixed<<setprecision(10)<<ans<<endl;
}

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

    

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


Measured memory_bytes: 70656
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
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, L;
  cin >> N >> L;
  vector<string> S(N);
  for (int i = 0; i < (int)N; ++i) cin >> S[i];
  sort((S).begin(), (S).end());
  for (int i = 0; i < (int)N; ++i) cout << S[i];
  cout << endl;
  return 0;
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(N);
  vector< int > d(N);
  REP(i, N) {
    cin >> d[i];
  }
  sort(ALL(d));

  int ans = 1;
  REP(i, N - 1) {
    if (d[i] != d[i + 1]) ans++;
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


int main(){
  int N;cin>>N;
  vector<pair<ll,int> > X(2*N);
  ll case1=0,case2=0;
  repeat(i,N){
    cin>>X[2*i].first>>X[2*i+1].first;
    X[2*i].second=X[2*i+1].second=i;
      case1 += X[2*i].first;
      case2 += X[2*i+1].first;
  }
  ll ans = min(case1,case2);
  //debug(ans);
  sort(X.begin(),X.end());
  ll sum=0;
  vector<bool> used(N);
  bool dupl=false;
  repeat(i,N){
    sum += X[i].first;
    if(used[X[i].second])dupl=true;
    used[X[i].second]=true;
  }
  if(dupl){
    ans = min(ans,sum);
  }else{
    repeat(i,N){
      ans = min(ans,sum-X[i].first+(X[i].second!=X[N].second?X[N].first:X[N+1].first));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
n = int(input())
data = list(map(int, input().split(' ')))

if n < 3:
    print(0)
else:
    import itertools
    cnt = 0
    for d in itertools.combinations(data, 3):
        if d[0] != d[1] and d[1] != d[2] and d[2] != d[0]:
            mx = max(d)
            if mx * 2 - sum(d) < 0:
                cnt += 1
    print(cnt)

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

int main() {
  int set[3];
  cin >> set[0] >> set[1] >> set[2] ;

  int five = 0, seven = 0;
  for (int i = 0 ; i < 3; i++) {
    if (set[i] == 5) {
      five++;
    } else if (set[i] ==7) {
      seven++;
    }
  }

  string ans;
  if (five == 2 && seven == 1) {
    ans = "YES";
  } else {
    ans = "NO";
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int solve(void);

int main(void){
  int n;
  scanf("%d",&n);
  while(n--) solve();
  return 0;
}

int solve(void){
  /*ここに答えを書く*/
  int a,b,tmp;
  scanf("%d:%d",&a,&b);
  
  tmp=a*60+b-b*12;
  if(tmp<0){
    tmp*=-1;
  }
  if(tmp>360){
    tmp=720-tmp;
  }
  
  if(tmp<60){
    puts("alert");
  }else if(tmp>=180){
    puts("safe");
  }else{
    puts("warning");
  }
  
  return 0;
}

Measured memory_bytes: 576
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
	cin>>a>>b>>c;
	for (int i=0;i<1000;i++){
		if (b<=a*i&&a*i<=c){
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;
	return 0;
}

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int r;
  cin >> r;
  if (r < 1200){
    cout << "ABC\n";
    return 0;
  }
  if ( r >= 1200 && r < 2800){
    cout << "ARC\n";
    return 0;
  }
  cout << "AGC\n";
  return 0;
}

Measured memory_bytes: 256
# Author: cr4zjh0bp
# Created: Thu Mar 12 19:37:38 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

A, B = na()

ans = 0
for i in range(A, B + 1):
    s = str(i)
    if s == s[::-1]:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std ;
#define int long long
const int N=1e5+5, M = 1e5, OO = 0x3f3f3f3f;
int mem[101][N], n, k;
pair<int , int > t[N];
int knapsack(int i = n-1, int rem = k)
{
    if(rem < 0)
        return -OO;
    if(i < 0 )
        return 0;
    int &ret = mem[i][rem];
    if (ret != -1)
        return ret;
    ret = max(knapsack(i - 1, rem), knapsack(i - 1, rem - t[i].first) + t[i].second);
    return	ret;
}
main()
{
    scanf("%d %d", &n, &k);
    memset(mem, -1, sizeof mem);
    for(int i = 0 ; i < n ; ++i)
        scanf("%d %d", &t[i].first, &t[i].second);
    sort(t , t + n);
    cout<<knapsack();

}


Measured memory_bytes: 79104
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long N, K;
  cin >> N >> K;
  long ans = K;
  rep (i, N-1) ans *= K-1;
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = 200000;
typedef long long LL;
int n;
LL a[maxn + 5];
LL res;
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)scanf("%lld", &a[i]);
	if(a[1] != 0)printf("-1\n");
	else {
		for(int i = n - 1; i >= 1; i--) {
			LL d = a[i + 1] - a[i];
			if(d > 1) {
				printf("-1\n");
				return 0;
			}
			else {
				if(d == 0LL)res += a[i];
				else if(d == 1LL)res++;
				else res += a[i + 1];
			}
		}
		printf("%lld\n", res);
	}
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,p=0,index;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	int b[n];
	for(int i=0;i<n;i++) b[i]=a[i];
	for(int i=0;i<n;i++)
	{
		int c=b[i];
		for(int j=i+1;j<n;j++)
	{
    	if(a[j]<a[i])
		{
		c=a[j]; index=j;
	}}
	if(c!=b[i])
	{
	p++;

	{
		int c=a[i];
		a[i]=a[index];
		a[index]=c;	}
	}}
	if(p<=1)
	cout<<"YES";
	else
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > a(55);
vector<pair<int,int> > b(55);

int n,m;
int main(){
	cin>>n>>m;
	int x,y,min1=1e9+7,k;
	for(int i=1;i<=n;i++)
	  {
	   cin>>a[i].first>>a[i].second;
	  } 
	for(int i=1;i<=m;i++)
	  {
	   cin>>b[i].first>>b[i].second;
	  } 

	   for(int i=1;i<=n;i++)
	   {min1=1e9+7;
	   	for(int j=1;j<=m;j++)
	   {
	      if((abs(a[i].first-b[j].first)+abs(a[i].second-b[j].second))<min1)
	         min1=abs(a[i].first-b[j].first)+abs(a[i].second-b[j].second),k=j;
	   }   
	   cout<<k<<endl;
	  	}
	return 0;
}

Measured memory_bytes: 256
open Printf
open Scanf

module L =
  struct
    include List
  
    let init n f =
      let rec loop x =
        if x = n then []
        else let y = f x in y :: loop (x + 1)
      in loop 0
  end

let id x = x

let solve n m =
  let l = L.init n @@ fun _ -> scanf "%d " id in
  let w = L.fold_left (+) 0 l in
  if m <= L.length (L.filter (fun x -> 4 * m * x >= w) l) then "Yes" else "No"

let () =
  scanf "%d %d " solve |> printf "%s\n"


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define rep(N) for(int i=0;i<N;i++)
#define repj(N) for(int j=0;j<N;j++)
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define For(I,N) for(int I=0;I<N;I++)
#define cinone(N) int N;cin>>N;
#define scanfone(N) int N;cin>>N;
#define cinng(N,M) int N[M];for(int yiuytvnm=0;yiuytvnm<M;yiuytvnm++) cin>>N[yiuytvnm];
#define scanfng(N,M) int N[M];for(int qrwuoiq=0;qrwuoiq<M;qrwuoiq++) scanf("%d",&N[qrwuoiq]);
#define over(A) {cout<<A<<endl;exit(0);}
typedef unsigned long long ull;
const int inf=103974182;
const int mod=998244353;
using namespace std;
ll n,a,b;
ll k;
ll e[300005];
ll ny[300005];
 
ll C(int a,int b)
{
	return (((e[a]*ny[a-b])%mod)*ny[b])%mod;
}

int lenof(ll a)
{
	int res=0;
	while(a)
	{
		a/=10;
		res++;
	}
	return res;
}
 
ll cal(int x)
{
//	cout<<x<<endl;
	ll basic=x;
	int tm=mod-2;
	ll res=1;
	while(tm)
	{
		if(tm&1)
		{
			res=res*basic;
//			cout<<res<<endl;
//			cout<<lenof(res)<<endl;
			res=res%998244353LL;
		}
		tm>>=1;
		basic=basic*basic;
		basic=basic%998244353LL;
	}
	return res;
}
 
int main()
{
//	freopen("input.txt","r",stdin);
	e[1]=1;
	e[0]=1;
	ny[1]=cal(1);
	ny[0]=1;
	for(int i=2;i<300004;i++)
	{
		e[i]=1LL*e[i-1]*i;
		e[i]%=998244353LL;
		ny[i]=cal(e[i]);
//		cout<<ny[i]<<endl;
	}
	cin>>n>>a>>b>>k;
	if((a+b)*n<k) over("0\n");
	ll res=0;
//	cout<<C(5,2)<<endl;
	for(int i=0;i<=n;i++)
	{
		if((k-1LL*i*a)%b) continue;
		int x=(k-1LL*i*a)/b;
		if(x<0 || x>n) continue;
		res+=C(n,i)*C(n,x);
		res%=mod;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  string S;
  cin >> S;
    char N = S.size();
  char c = (S.size())/2;
    int j = 0;
    rep(i,c){
        if(S[i] == S[N-i-1]){
            continue;
        }
        else j++;
    }
    cout << j << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int l, n;
    cin >> l >> n;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    int ans = x[n - 1], tmp = x[n - 1];
    repr(i, n - 2)
    {
        tmp += (x[i] - x[i + 1]);
        if ((n + i) & 1)
        {
            tmp -= x[i + 1] - x[i];
            tmp -= 2 * (x[(n + i) / 2] - x[i + 1]);
            tmp += l - (x[(n + i) / 2 + 1] - x[(n + i) / 2]);
        }
        else
        {
            tmp -= x[i + 1] - x[i];
            tmp -= 2 * (x[(n + i + 1) / 2] - x[i + 1]);
            tmp += l;
        }
        ans = max(ans, tmp);
    }
    rep(i, n) x[i] = l - x[i];
    reverse(all(x));
    tmp = x[n - 1];
    repr(i, n - 2)
    {
        tmp += (x[i] - x[i + 1]);
        if ((n + i) & 1)
        {
            tmp -= x[i + 1] - x[i];
            tmp -= 2 * (x[(n + i) / 2] - x[i + 1]);
            tmp += l - (x[(n + i) / 2 + 1] - x[(n + i) / 2]);
        }
        else
        {
            tmp -= x[i + 1] - x[i];
            tmp -= 2 * (x[(n + i + 1) / 2] - x[i + 1]);
            tmp += l;
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin >> a;
  int min = 1000000,max = 0;
  for(int i=0;i<a;i++){
    int b;
    cin >> b;
    if(min > b)
      min = b;
    if(max < b)
      max = b;
  }
  cout << max - min << endl;
}

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

def f(a: int, b: int, c: int, d: int) -> int:
    """
    >>> f(-2, -1, -2, -1)
    4
    >>> f(-2, -1, 1, 2)
    -1
    >>> f(1, 2, 1, 2)
    4
    >>> f(1, 2, -2, -1)
    -1
    """
    return max(a * c, a * d, b * c, b * d)


if __name__ == '__main__':
    a, b, c, d = map(lambda x: int(x), input().split())
    print(f(a, b, c, d))

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define upb upper_bound
#define lwb lower_bound
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

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

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y){
    if(y<=0) return 1;
    ll ans = 1;
    x %= mod;
    while(y){
        if(y&1)
            ans = (x * ans) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = (a - b); if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = (a + b); if(c >= mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

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

//const ll N = 2e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(10);

	ll x;
	cin>>x;
	if(x>=30)cout<<"Yes";
	else cout<<"No";


    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
   
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
        ll n,k;cin>>n>>k;
        ll a[n];
        rep(i,n){
        	cin>>a[i];a[i]--;
        }
        ll ans=0;
        if(k<=(2*n+5)){
        	while(k--){
        		ans=a[ans];
        	}
        }
        else{
        	map<ll,ll> m;
        	ll cur=0;ll s=0;
        	m[0]=1;
        	while(1){
        		cur=a[cur];
        		// dbg(cur);
        		s++;
        		if(m.find(cur)!=m.end()){
        			break;
        		}
        		m[cur]=1;
        	}
        	k=k-s;
        	s=1;ll r=cur;
        	cur=a[cur];
        	while(r!=cur){
        		cur=a[cur];s++;
        	}
        	k=k%s;
        	ans=cur;
        	while(k--){
        		ans=a[ans];
        	}
        }
        cout<<ans+1;
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 15168
// AOJ 1316: The Sorcerer's Donut
// 2017.12.4 bal4u@uu

#include <stdio.h>
#include <string.h>

#define HASHSIZ 500009
typedef struct { unsigned long long x1; unsigned x2; int w; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash+HASHSIZ;			// Hash table
char ans[500]; int len;

void lookup(unsigned long long x1, unsigned x2, char *s, int w)
{
	int i = (int)(x1 % HASHSIZ);
	HASH *tp = hash + i;

	while (tp->x1) {
		if (w == tp->w && x1 == tp->x1 && x2 == tp->x2) {
			if (w > len || (w == len && memcmp(s, ans, w) < 0))
				memcpy(ans, s, w), len = w;
			return;
		}
		if (++tp == hashend) tp = hash;
	}
	tp->x1 = x1, tp->x2 = x2, tp->w = w;
}

#define M 4294967291
int h, w;
char m[10][22];
int mv[8][2] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
char buf[1000];

void rec(int sr, int sc, int r, int c, int dir, char *s,
		 unsigned long long x1, unsigned x2, int len)
{
	int r2, c2, cc;

	s[len++] = m[r][c];
	cc = m[r][c] - ('A'-1);
	x1 = (x1 << 5) | cc;
	x2 = (((long long)x2 << 5) | cc) % M;
	lookup(x1, x2, s, len);

	r2 = r + mv[dir][0]; if (r2 < 0) r2 = h-1; else if (r2 >= h) r2 = 0;
	c2 = c + mv[dir][1]; if (c2 < 0) c2 = w-1; else if (c2 >= w) c2 = 0;

	if (r2 == sr && c2 == sc) return;
	rec(sr, sc, r2, c2, dir, s, x1, x2, len);
}

int main()
{
	int r, c, d;

	while (scanf("%d%d", &h, &w) && h > 0) {
		memset(hash, 0, sizeof(hash));
		for (r = 0; r < h; r++) scanf("%s", m[r]);

		len = 0, ans[0] = 0;
		for (r = 0; r < h; r++) for (c = 0; c < w; c++) for (d = 0; d < 8; d++) {
			rec(r, c, r, c, d, buf, 0, 0, 0);
		}

		if (len < 2) puts("0");
		else {
			ans[len] = 0;
			puts(ans);
		}
	}
	return 0;
}

Measured memory_bytes: 9480
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime>
#include <bitset>

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};

int main() {
  int r,c,kk; cin>>r>>c>>kk;
  ll a[r][c]; fill(a[0],a[r],0);
  
  for(int i=0;i<kk;i++) {
    ll f,g,h; cin>>f>>g>>h; f--; g--;
    a[f][g] = h;
  }
  /*
  for(int i=0;i<r;i++) {
    for(int j=0;j<c;j++) {
      cin>>a[i][j];
    }
  }*/

  ll dp[2][c][4]; fill(dp[0][0], dp[2][0], -LINF);
  dp[0][0][0] = 0; dp[0][0][1] = a[0][0];

  for(int i=0;i<r;i++) {
    int nw = i%2, nx = (i+1)%2;
    for(int j=0;j<c;j++) {
      for(int k=0;k<4;k++) {
        if (dp[nw][j][k] == -LINF) continue;
          chmax(dp[nx][j][0], dp[nw][j][k]); // 下の行に移る
        if (i+1 < r) {
          chmax(dp[nx][j][1], dp[nw][j][k] + a[i+1][j]); // 下の行に移る
        }
        if (j+1 < c) {
          chmax(dp[nw][j+1][k], dp[nw][j][k]); // 右に移る
          if (k + 1 < 4) chmax(dp[nw][j+1][k+1], dp[nw][j][k] + a[i][j+1]);
        }
      }
    }
    /*
    cout<<i<<" : \n";
    for(int j=0;j<c;j++) {
      cout<<dp[nw][j][0]<<" ";
    } cout<<endl;
    for(int j=0;j<c;j++) {
      cout<<dp[nx][j][0]<<" ";
    } cout<<endl;*/
    for(int j=0;j<c;j++) {
      for(int k=0;k<4;k++) {
        dp[nw][j][k] = -LINF;
      }
    }
    fill(dp[nw][0],dp[nw+1][0],-LINF);
  }

  /*
  for(int k=0;k<4;k++) {
    for(int i=0;i<r;i++) {
      for(int j=0;j<c;j++) {
        cout<<dp[i][j][k]<<" ";
      } cout<<endl;
    } cout<<endl;
  }*/

  ll an = 0;
  for(int i=0;i<4;i++) {
    an = max(an, dp[r%2][c-1][i]);
  }
  cout<<an<<endl;
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


Measured memory_bytes: 73924
n, m = map(int, input().split())
fune = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    fune[a-1].append(b-1)
    fune[b-1].append(a-1)
res = "IMPOSSIBLE"
for i in fune[0]:
    if n-1 in fune[i]:
        res = "POSSIBLE"
        break
print(res)

Measured memory_bytes: 38296
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

int a[10];
int p[10];
int q[10];
int n;

int check(int arr[]) {
    for (int i = 0; i < n; i++) {
        if (a[i] != arr[i]) return 0;
    }
    return 1;
}

inline int Abs(int x) {
    return x < 0 ? -x : x;
}

int main() {
    int x, y, cnt = 1;
    cin >> n;
    for (int i = 0; i < n; i++) scanf("%d", p + i);
    for (int i = 0; i < n; i++) scanf("%d", q + i);
    for (int i = 0; i < n; i++) {
        a[i] = i + 1;
    }
    do {
        if (check(p)) x = cnt;
        if (check(q)) y = cnt;
        cnt++;
    } while (next_permutation(a, a + n));
    cout << Abs(y - x) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

signed main(){
	int M1,D1,M2,D2;
	cin>>M1>>D1>>M2>>D2;
	if(M1!=M2){
		cout<<1<<endl;
	}
	else{
		cout<<0<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main ( )
{
	int A,B,x=0,y=0,z=0,max=0;
	scanf("%d%d",&A,&B);
	
	x=A+B;
	y=A-B;
	z=A*B;
	
	if(x>=y && x>=z)
	{
		max=x;
	}
	else if(y>=x && y>=z)
	{
		max=y;
	}
	
	else
	{
		max=z;
	}
	
	printf("%d\n",max);
	
	return 0;
	
}
	
	

Measured memory_bytes: 1728
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef long long int keytype;

//quicksort(<#keytype *a#>, <#int first#>, <#int last#>)

void quicksort(keytype a[], long long int first, long long int last){
    long long int i, j;
    keytype x, t;
    
    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int main() {
    long long int n,x[100],i,j,ans=0,min=10000000;
    scanf("%lld",&n);
    for (i=0; i<n; i++) {
        scanf("%lld",&x[i]);
    }
    for (j=1;j<=1000000;j++) {
        ans=0;
        for (i=0; i<n; i++) {
            ans+=((x[i]-j)*(x[i]-j));
        }
        if(ans<min){
            min=ans;
        }
        
    }
    printf("%lld",min);
    return 0;
}


Measured memory_bytes: 128
use proconio::input;

fn main() {
    input! {
        mut n: u64,
    }

    let mut ans:Vec<char> = Vec::new();

    while n != 0 {
        n -= 1;
        ans.push(('a' as u8 + (n % 26) as u8) as char);
        n /= 26;
    }

    println!("{}", ans.iter().rev().collect::<String>());
}


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


class Program
{


    static void Main(string[] args)
    {
        Solve();
    }

    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();

        int a =sc.intarr[0];
        int b = sc.intarr[0];
        int c = sc.intarr[0];
        int d = sc.intarr[0];




        wr.wri(Math.Min(a, b) + Math.Min(c, d));



    }


}
    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => strarr.Select(char.Parse).ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


Measured memory_bytes: 13396
#include<stdio.h>
int d[1000000];
int main(){
  int n,i,j,ans;
  while(scanf("%d",&n)!=EOF){
    for(i=2;i*i<=n;i++){
      if(d[i]==0){
	for(j=i+i;j<=n;j+=i){
	  d[j]=1;
	}
      }
    }
    ans=0;
    for(i=2;i<=n;i++){
      if(d[i]==0){
	ans++;
      }
    }
    printf("%d\n",ans);
  }
  return (0);
}

Measured memory_bytes: 4496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); 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 ALL(n) begin(n), end(n)
#define IN(a, x, b) (a <= x && x < b)
#define INIT                        \
  std::ios::sync_with_stdio(false); \
  std::cin.tie(0);
template <class T>
inline T CHMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T>
inline T CHMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main() {
  INIT;

  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  vector<int> b(m);
  REP(i, n) cin >> a[i];
  REP(i, m) cin >> b[i];

  ll t = 0;
  REP(i, m) t += b[i];

  int j = m;
  int ans = 0;
  REP(i, n + 1) {
    while (j > 0 && t > k) {
      --j;
      t -= b[j];
    }
    if (t > k) break;
    ans = max(ans, i + j);
    if (i == n) break;
    t += a[i];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4732
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  998244353;
const int  Inv2 = (MOD+1)/2;

     signed main(){
  int n;
  cin>>n;
  int a[(1<<n)],b[(1<<n)]={},c[(1<<n)]={},p[4];
  for(int i=0;i<(1<<n);i++)cin>>a[i];
  for(int i=0;i<(1<<n);i++){
     b[i]=i;c[i]=-1;
     for(int j=0;j<n;j++){
        if(i&(1<<j)){
           if(b[i]!=b[i^(1<<j)]&&c[i]!=b[i^(1<<j)]){
           if(a[b[i]]<a[b[i^(1<<j)]]){
              c[i]=b[i];
            
              b[i]=b[i^(1<<j)];
           }else{
              if(c[i]==-1||a[c[i]]<a[b[i^(1<<j)]])c[i]=b[i^(1<<j)];
           }
           }
           if(c[i^(1<<j)]==-1||c[i]==c[i^(1<<j)]||b[i]==c[i^(1<<j)])continue;
           if(a[b[i]]<a[c[i^(1<<j)]]){
              c[i]=b[i];
              b[i]=c[i^(1<<j)];
           }else{
              if(c[i]==-1||a[c[i]]<a[c[i^(1<<j)]])c[i]=c[i^(1<<j)];
           }
           //cerr<<b[i]<<' '<<c[i]<<' '<<i<<endl;
        }
          
     }
  //   cerr<<b[i]<<' '<<c[i]<<' '<<i<<endl;
  }
 
  int ans=0;
  for(int i=1;i<(1<<n);i++){
     ans=max(ans,a[b[i]]+a[c[i]]);
     cout<<ans<<endl;
  }
      }

        


Measured memory_bytes: 9216
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(),(x).end()
#define Graph vector<vector<int>>;
#define iterG(next_v, G, v) for(auto next_v : G[v]
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    vector<string> s;
    string sinput;
    int ans = 0;
    set<string> pool;
    cin >> n;
    
    rep(i, n){
        cin >> sinput;
        s.push_back(sinput);
    }
    rep(i, n){
        if(pool.find(s[i]) == pool.end()){
            ans++;
            pool.insert(s[i]);
        }
    }
    cout << ans << endl;

    return 0;
}



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

int main() {
  int N, K, b = 0;
  cin >> N >> K;
  for (vector<int> A(K); cin >> N; b %= K) {
    if (A.at(b)) if (N > A.at(b)) cout << "Yes" << endl;
    else cout << "No" << endl;
    A.at(b++) = N;
  }
}

Measured memory_bytes: 4044