akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
const int dx[4]={0,0,1,-1};
const int dy[4]={1,-1,0,0};
int main(){
    int h,w;cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    ll ans=0;
    vector<vector<bool>> ok(h,vector<bool>(w,false));
    rep(i,h){
        rep(j,w){
            if(!ok[i][j]){
                ll W=0,B=0;
                queue<P> q;
                q.push({i,j});
                ok[i][j]=true;
                B+=(s[i][j]=='#');
                W+=(s[i][j]!='#');
                while(q.size()){
                    int nowx=q.front().fi;
                    int nowy=q.front().se;
                    char nowm=s[nowx][nowy];
                    q.pop();
                    for(int i=0;i<4;i++){
                        int Nextx=nowx+dx[i];
                        int Nexty=nowy+dy[i];
                        if(Nextx>=0&&Nextx<h&&Nexty>=0&&Nexty<w){
                                //cout << "通過" << Nextx << " " << Nexty << endl;
                                if(!ok[Nextx][Nexty]&&nowm!=s[Nextx][Nexty]){
                                    ok[Nextx][Nexty]=true;
                                    B+=(s[Nextx][Nexty]=='#');
                                    W+=(s[Nextx][Nexty]!='#');
                                    q.push({Nextx,Nexty});
                                }
                            
                        }
                    }
                }
                ans+=W*B;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
a, b, c, x, y = map(int, input().split())
if x == y:
    print(min(2 * c, a + b) * x)
elif x < y:
    print(x * min(2 * c, a + b) + (y - x) * min(b, 2 * c))
else:
    print(y * min(2 * c, a + b) + (x - y) * min(a, 2 * c))


Measured memory_bytes: 3060
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<bitset>
#include<random>
#include<cstdint>
#include<math.h>
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
#define shosu setprecision(17)
#define hayai cin.tie(0);ios::sync_with_stdio(false);
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<char,P> Q;
ll longinf=(1ll<<60);
ll inf=1ll<<29;
ll mod=998244353;

int main(){
    hayai
    ll a,b,c;
    cin>>a>>b>>c;
    ll ans=0;
    ans=2*b;
    ans+=min(c-b,a+1);
    cout<<ans<<endl;
      return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

ll dp[4][46];

int main() {
    ll N, K;
    cin >> N >> K;
    ll A[N];
    ll num[45];
    fill(num, num + 45, 0);
    REP(i, 0, N) {
        cin >> A[i];
        REP(j, 0, 45) {
            if (A[i] & ((ll)1 << j)) {
                num[j]++;
            }
        }
    }
    REP(i, 0, 4) {
        fill(dp[i], dp[i] + 46, 0);
    }
    REP(i, 0, 45) {
        ll po = (ll)1 << (44 - i);
        if (K & po) {
            dp[0][i + 1] = max(dp[0][i], dp[1][i]) + (N - num[44 - i]) * po;
            dp[3][i + 1] = max(dp[0][i], dp[1][i]) + num[44 - i] * po;
            if (dp[2][i] != 0) {
                dp[2][i + 1] = max(dp[2][i + 1], dp[2][i] + (N - num[44 - i]) * po);
                dp[3][i + 1] = max(dp[3][i + 1], dp[2][i] + num[44 - i] * po);
            }
            if (dp[3][i] != 0) {
                dp[2][i + 1] = max(dp[2][i + 1], dp[3][i] + (N - num[44 - i]) * po);
                dp[3][i + 1] = max(dp[3][i + 1], dp[3][i] + num[44 - i] * po);
            }
        } else {
            dp[1][i + 1] = max(dp[0][i], dp[1][i]) + num[44 - i] * po;
            if (dp[2][i] != 0) {
                dp[2][i + 1] = max(dp[2][i + 1], dp[2][i] + (N - num[44 - i]) * po);
                dp[3][i + 1] = max(dp[3][i + 1], dp[2][i] + num[44 - i] * po);
            }
            if (dp[3][i] != 0) {
                dp[2][i + 1] = max(dp[2][i + 1], dp[3][i] + (N - num[44 - i]) * po);
                dp[3][i + 1] = max(dp[3][i + 1], dp[3][i] + num[44 - i] * po);
            }
        }
    }
    ll ans = 0;
    REP(i, 0, 4) {
        ans = max(ans, dp[i][45]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 52;
const int M = 2450;

int n, m, s;
int dist[N][M+10];
bool vis[N][M+10];
   
vector<vector<int>> convert;
vector<vector<int>> v[N];

int32_t main(){_
   
   cin>>n>>m>>s;
   
   for (int i = 0; i < m; ++i)
   {
      int x, y, silver, time;
      cin >> x >> y >> silver >> time;
      v[x].push_back({y, silver, time});
      v[y].push_back({x, silver, time});
   }

   convert.resize(n+1);
   for (int i = 1; i <= n; ++i)
   {
      int c, d;
      cin >> c >> d;
      convert[i] = {c, d};
   }

   for (int i = 0; i < N; ++i)
   {
      for (int j = 0; j <= M; ++j)
      {
         dist[i][j] = inf;
      }
   }

   s = min(s, M);
   dist[1][s] = 0;

   set<vector<int>> ms;//function of time
   ms.insert({0, s, 1}); // inserted time, silver coins, vertex

   vector<int> ans(n+1, inf);
   while(!ms.empty()){
      vector<int> f = *ms.begin();
      ms.erase(ms.begin());

      int time = f[0], vertex = f[2], silvers = f[1];

      if (vis[vertex][silvers]){
         continue;
      }

      vis[vertex][silvers] = 1;
      smin(ans[vertex], time);

      int i = silvers + convert[vertex][0];
      if (i <= M){
         if (dist[vertex][i] > time + convert[vertex][1]){
            dist[vertex][i] = time + convert[vertex][1];
            ms.insert({time + convert[vertex][1], i, vertex});
         }
      }

      for(auto it: v[vertex]){
         int nxt_vertex = it[0];
         int required_silver = it[1];
         int update_time = it[2];
         if (silvers >= required_silver){
            if (dist[nxt_vertex][silvers - required_silver] > dist[vertex][silvers] + update_time){
               dist[nxt_vertex][silvers - required_silver] = dist[vertex][silvers] + update_time;
               ms.insert({dist[vertex][silvers] + update_time, silvers - required_silver, nxt_vertex});
            }
         }
      }

   }

   for (int i = 2; i <= n; ++i)
   {
      cout<<ans[i]<<endl;
   }

   return 0;
}

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

int main(){
  int A,B,C,X,i,j,k;
  cin >> A >> B >> C >> X;
  int cnt = 0;

  for(i=0;i<=A;i++){
    for(j=0;j<=B;j++){
      for(k=0;k<=C;k++){
        if(i*500+j*100+k*50 == X)
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SZ(v) (int((v).size()))
#define ALL(vec) (vec).begin(),(vec).end()
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
using namespace std;
 
template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; // find_by_order(), order_of_key()

using ll = long long int;
using i64 = long long int;
template <typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template <typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}

void err(__attribute__((unused)) istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << a << endl;
  err(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& os, const pair<T1, T2>& buf) {
  return os << "(" << buf.first << ": " << buf.second << ")";
}
template<typename T>
inline ostream &operator << (ostream & os,const vector<T>& v) {
  bool first = true;
  os << "[";
  for(unsigned int i = 0; i < v.size(); i++) {
    if(!first) os << ", ";
    os << v[i];
    first = false;
  }
  return os << "]";
}
template<typename T>
inline ostream &operator << (ostream & os,const set<T>& v) {
  bool first = true;
  os << "{";
  for (auto ii = v.begin(); ii != v.end(); ++ii) {
    if(!first) os << ", ";
    os << *ii;
    first = false;
  }
  return os << "}";
}
inline ostream &operator << (ostream & os,const multiset<int>& v) {
  bool first = true;
  os << "{";
  for (auto x: v) {
    if(!first) os << ", ";
    os << x;
    first = false;
  }
  return os << "}";
}
template<typename T1, typename T2>
inline ostream &operator << (ostream & os,const map<T1, T2>& v) {
  bool first = true;
  os << "{";
  for (typename map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
    if(!first) os << ", ";
    os << *ii ;
    first = false;
  }
  return os << "}";
}
template<typename T>
ostream &operator << (ostream & os,const vector<vector<T>>& v) {
  for (auto &u: v) os << '\n' << u;
  return os;
}
template<typename T>
void finish(T ans) {cout << ans << '\n'; exit(0);}
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const double EPS = 1e-6;
#define PI 3.14159265358979323846
/***********************************************************************/

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

  int n, m;
  cin >> n >> m;
  vector<pair<i64,i64>> a(n);
  for (auto &e: a) {
    cin >> e.first >> e.second;
  }
  sort(ALL(a));
  i64 ans = 0;
  int ptr = 0;
  while (m > 0) {
    if (a[ptr].second >= m) {
      ans += m * a[ptr].first;
      break;
    }
    ans += a[ptr].first * a[ptr].second;
    m -= a[ptr].second;
    ptr++;
  }
  cout << ans << '\n';
  
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    int N, M;
    cin >> N >> M;
    if (N > M)
        swap(N, M);

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

        cout << M - 2 << endl;
        return;
    }

    // N > 1

    lint ret = (N - 2) * 1LL * (M - 2);


    // count the corners.
    int corner = 0;
    FOR(i, 0, 2)
        FOR(j, 0, 2)
            if (i < N && j < M)
                corner++;

    if (corner % 2 == 1) {
        int numCorners = 0;
        if (N == 1 && M == 1)
            numCorners = 1;
        else if (N == 1 || M == 1)
            numCorners = 2;
        else
            numCorners = 4;
        ret += numCorners;
    }

    cout << ret << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 256
// "include" {{{
#include <deque>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,a,b;
	cin >> n >> a >> b;
	if(abs(a - b)  % 2 == 1) cout << "Borys\n";
	else cout << "Alice\n";
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<string>
#include<vector>
#include<queue>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int MAXN=2e5+10;

int a[MAXN];

typedef struct{
	int v,num;
}point;
point b[MAXN];

bool cmp(point a,point b)
{
	return a.num>b.num;
}

int main()
{
	int i,j,k;
	int n;
	
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	sort(a,a+n);
	
	int cnt=1;
	int tot=0;
	for(i=1;i<n;i++)
	{
		if(a[i]==a[i-1])
		{
			cnt++;
		}
		else 
		{
			b[tot].v=a[i-1];
			b[tot].num=cnt;
			tot++;
			cnt=1;
		}
	}
	b[tot].v=a[i-1];
			b[tot].num=cnt;
			tot++;
			cnt=1;
	sort(b,b+tot,cmp);
	
	int sum=0;
	for(i=0;i<k&&i<tot;i++)
	{
		sum+=b[i].num;
	}
	
	printf("%d\n",n-sum);
	
} 

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ll x, y; cin >> x >> y;
    if (x % y == 0)cout << "-1\n";
    else cout << x << "\n";
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr= input.trim().split("\n");
var [h,w]=arr[0].split(" ").map(Number);
var [a,b]=arr[1].split(" ").map(Number);
var x=Math.floor(h/a);
var y=Math.floor(w/b);
console.log(h*w-x*a*y*b);


Measured memory_bytes: 17192
# 17
# ALDS_13_A-8 クイーン問題

import itertools
import copy

k = int(input())
q_l = [[int(x) for x in input().split()] for y in range(k)]

x_l = list(range(8))
y_l = list(range(8))
plus_l = []
minus_l = []
for i in range(k):
    x_l.remove(q_l[i][1])
    y_l.remove(q_l[i][0])
    plus_l.append(q_l[i][0] + q_l[i][1])
    minus_l.append(q_l[i][0] - q_l[i][1])
    
per = itertools.permutations(x_l)
per2 = itertools.permutations(x_l)

for order in per:
    _p_l = copy.deepcopy(plus_l)
    _m_l = copy.deepcopy(minus_l)
    _x_l = list(order)
    for i,_y in enumerate(y_l):
        _p_l.append(_y + _x_l[i])
        _m_l.append(_y - _x_l[i])
    if len(set(_p_l)) == 8 and len(set(_m_l)) == 8:
        ans_l = [["."]*8 for j in range(8)]
        for j in range(k):
            ans_l[q_l[j][0]][q_l[j][1]] = "Q"
        for j in range(8-k):
            ans_l[y_l[j]][_x_l[j]] = "Q"
        for j in range(8):
            print(*(ans_l[j]), sep="")


Measured memory_bytes: 6320
ns = [int(n) for n in input().split()]
ans = 0
while True:
    ns = sorted(ns)
    a = ns[0]
    b = ns[1]
    c = ns[2]
    if a == b and b == c:
        break
    elif a == b:
        if abs(a - c) >= 2:
            ns[1] = a + 2
        else:
            ns[0] = a + 1
            ns[1] = a + 1
        ans = ans + 1
    elif b == c:
        if abs(a - b) == 1:
            ans = ans + 2
            break
        else:
            ns[0] = a + 2
            ans = ans + 1
    else:
        ns[0] = a + 2
        ans = ans + 1
print(ans)

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

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

int main(){
    int n,a;
    vector<ll> x;
    cin>>n;
    REP(i,n){
        cin>>a;
        x.push_back(a);
    }
    ll min=1000000000000;
    int mp=-1;
    for(int i=0; i<=100;i++){
        ll sum=0;
        for(auto j : x)sum+=(j-i)*(j-i);
        if(min>sum){
            min=sum;
            mp=i;
        }
    }
    cout<<min<<endl;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns        #-}
{-# LANGUAGE FlexibleContexts    #-}
{-# LANGUAGE MultiWayIf          #-}
{-# LANGUAGE RankNTypes          #-}
{-# LANGUAGE ScopedTypeVariables #-}
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State
import           Control.Monad.Trans.State
import           Data.Array.IArray
import           Data.Array.ST
import           Data.Array.Unboxed
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Int                    (Int64)
import           Data.List
import           Data.Maybe
import           Data.Proxy
import           Data.Sequence               (Seq ((:<|), (:|>)), ViewL ((:<)),
                                              ViewR ((:>)), viewl, viewr, (<|),
                                              (><), (|>))
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as S
import           Data.STRef
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import           Numeric

main :: IO ()
main = do
  [d,t,s] <- readLnAsListWith unconsInt
  putStrLn $ if (d + s - 1) `div` s <= t then "Yes" else "No"



-- converter
unconsChar :: StateT BS.ByteString Maybe Char
unconsChar = StateT BS.uncons

unconsInt :: StateT BS.ByteString Maybe Int
unconsInt = StateT $ BS.readInt . BS.dropWhile isSpace

unconsInteger :: StateT BS.ByteString Maybe Integer
unconsInteger = StateT $ BS.readInteger . BS.dropWhile isSpace

-- 1D Data
-- for list
readLnAsListWith :: StateT BS.ByteString Maybe a -> IO [a]
readLnAsListWith !st = unfoldr (runStateT st) <$> BS.getLine

-- for array (boxed or unboxed)
readLnAsArrayWith :: IArray a e => StateT BS.ByteString Maybe e -> Int -> IO (a Int e)
readLnAsArrayWith !st !n = listArray (1,n) <$> readLnAsListWith st

-- for boxed vector
readLnAsVecWith :: StateT BS.ByteString Maybe a -> Int -> IO (V.Vector a)
readLnAsVecWith !st !n = V.unfoldrN n (runStateT st) <$> BS.getLine

-- for unboxed vector
readLnAsUVecWith :: VU.Unbox a => StateT BS.ByteString Maybe a -> Int -> IO (VU.Vector a)
readLnAsUVecWith !st !n = VU.unfoldrN n (runStateT st) <$> BS.getLine

-- example: 1D tuple vector
readLnAsUVecWith2Tuple :: VU.Unbox a => StateT BS.ByteString Maybe a -> Int -> IO (VU.Vector (a,a))
readLnAsUVecWith2Tuple !st !n = VU.replicateM n $ (\vec -> (vec VU.! 0, vec VU.! 1)) <$> readLnAsUVecWith st 2


-- 2D Data
-- n: number of lines
-- m: number of values per a line

-- for boxed vector
readLnAs2DVecWith :: StateT BS.ByteString Maybe a -> Int -> Int -> IO (V.Vector a)
readLnAs2DVecWith !st !n !m = V.unfoldrN (n * m) (runStateT st) . BS.concat <$> replicateM n BS.getLine

readLnAs2DUVecWith :: VU.Unbox a => StateT BS.ByteString Maybe a -> Int -> Int -> IO (VU.Vector a)
readLnAs2DUVecWith !st !n !m = VU.unfoldrN (n * m) (runStateT st) . BS.concat <$> replicateM n BS.getLine


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  char a,b;
  cin >> a >> b;
  if(a<b) pr("<");
  else if(a>b) pr(">");
  else pr("=");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

typedef long long ll;
typedef pair<int, int> pii;

int main() {
    string s[3];
    cin >> s[0] >> s[1] >> s[2];
    
    int turn = 0;
    while (true) {
        if (s[turn][0] == 'a') {
            s[turn] = s[turn].substr(1, s[turn].size() - 1);
            turn = 0;
        } else if (s[turn][0] == 'b') {
            s[turn] = s[turn].substr(1, s[turn].size() - 1);
            turn = 1;
        } else {
            s[turn] = s[turn].substr(1, s[turn].size() - 1);
            turn = 2;
        }
        if (s[turn].size() == 0) {
            cout << (char)('A' + turn) << endl;
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	days := []string{"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"}
	var s string
	fmt.Scanf("%s", &s)
	var sIndex int
	for i, v := range days {
		if v == s {
			sIndex = i
			break
		}
	}

	fmt.Printf("%d\n", sIndex+1)
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>

#define Rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())

#define eb emplace_back
#define ef emplace_front
#define dbg(x) cout<<#x" = "<<((x))<<endl
#define fs first
#define sc second
     
using namespace std;
     
     
typedef long long ll;
typedef pair<ll, ll> P;
     
     
int main(){
  int N, K;

  cin >> N >> K;

  vector< vector<int> > jobs(K);
  for(int i = 0; i < N; ++i){
    int a, b;
    cin >> a >> b;
    if(a > K) continue;
    jobs[K-a].push_back(b);
  }

  ll ans = 0;
  priority_queue<int> que;
  for(int i = K-1; i >= 0; i--){
    for(int b : jobs[i]){
      que.push(b);
    }
    if(!que.empty()){
      ans += que.top(); que.pop();
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5504
"""
                            pppppppppppppppppppp
                         ppppp  ppppppppppppppppppp
                      ppppppp    ppppppppppppppppppppp
                      pppppppp  pppppppppppppppppppppp
                      pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
       ppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppp
      pppppppppppppppppppppppppppppppppppppppppppppppp  ppppppppppppppppppppp
     ppppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppppp
    ppppppppppppppppppppppppppppppppppppppppppppppp    pppppppppppppppppppppppp
   pppppppppppppppppppppppppppppppppppppppppppppp     pppppppppppppppppppppppppp
  ppppppppppppppppppppppppppppppppppppppppppppp      pppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppppppp               pppppppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppp     pppppppppppppppppppppppppppppppppppppppppppppp
  ppppppppppppppppppppppppppp    pppppppppppppppppppppppppppppppppppppppppppppppp
    pppppppppppppppppppppppp  pppppppppppppppppppppppppppppppppppppppppppppppppp
     ppppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppppp
      pppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppp
       ppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
                              pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppp  pppppppp
                              ppppppppppppppppppppp    ppppppp
                                 ppppppppppppppppppp  ppppp
                                    pppppppppppppppppppp
"""


import sys
from functools import lru_cache, cmp_to_key
from collections import defaultdict as dd, deque, Counter as C
from bisect import bisect_left as bl, bisect_right as br, bisect
from heapq import heapify, heappop, heappush
from math import ceil, log, floor, sqrt
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var, end="\n"): sys.stdout.write(str(var)+end)
def outa(*var, end="\n"): sys.stdout.write(' '.join(map(str, var)) + end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


x, k, d = sp()
if x < 0:
    neg = True
else:
    neg = False
x = abs(x)
mv = x // d
t1, t2 = x - mv * d, x - (mv + 1) * d
if k <= mv:
    out(abs(x - k * d))
    exit()
if mv & 1:
    if k & 1:
        out(abs(t1))
    else:
        out(abs(t2))
    exit()
if k & 1:
    out(abs(t2))
else:
    out(abs(t1))


Measured memory_bytes: 68156
#include <bits/stdc++.h>
using namespace std;
//using lint = long long;

struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x)
              return x>a.x;
        return y>a.y;
    }

};

vector<int> v[111111],v1;

//bitset<4001000> b;
int i,n,d,m,k,a,b,c,h;

int o[111111][5];
int l[111115][4][4];
int j[111115];
int e[111111];


//int dx[10]={2,2,-2,-2,1,1,-1,-1},dy[10]={1,-1,1,-1,2,-2,2,-2};

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[311111];
stack<int> s;
//set<int> s[222][22];
//priority_queue<P> q;
queue<int> q;
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
/*
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> safe_map;
*/
//list<int> l;

string r;
//char r[2];
//deque<int> de;
//srand((int)time(NULL));
/*bool as(P a,P b)
{
    if(a.x!=b.x)
    return a.x<b.x;
    return a.y<b.y;
}*/

int f(int n,int m,int c)
{
    if(n>a) return 0;
    if(l[n][m][c]) return l[n][m][c];
    //l[n][m][c]=1987654321;
    for(int t=1;t<=3;t++)
    if(m!=c||c!=t||m!=t)
    {
        l[n][m][c]=max(l[n][m][c],f(n+1,t,t)+o[n][t]);
    }
    return l[n][m][c];
}

bool as(P a,P b)
{
    if(a.x!=b.x)
        return a.x<b.x;
    return a.y<b.y;

}



int main()
{
    scanf("%d",&a);
    for(int t=1;t<=a;t++)
        for(int w=1;w<=3;w++)
        scanf("%d",&o[t][w]);
    printf("%d",f(1,0,0));
}





Measured memory_bytes: 22656
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};
 
 



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;
    

    ll n;
    ll ans=0;
    string s;
    // unordered_map<string,ll> mp;
    map<pair<string,string>,ll> mp;
    cin>>n>>s;
    rep(bit,(1<<n)){
        string u="",t="";
        rep(i,n){
            if(bit&(1<<i)){
                u+=s[i];
            }
            else t+=s[i];
        }
        ++mp[make_pair(u,t)];
        // cout<<u+'0'+t<<endl;
    }
    rep(bit,(1<<n)){
        string u="",t="";
        rep(i,n){
            if(bit&(1<<i)){
                u=s[i+n]+u;
            }
            else t=s[i+n]+t;
        }
        ans+=mp[make_pair(t,u)];
    }
    cout<<ans<<endl;

    
    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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 vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

const int MAX = 1000010;
const int MOD = pow(10, 9) + 7;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = 1;
    fac[1] = 1;
    finv[0] = 1;
    finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int X, Y; cin >> X >> Y;
  ll ans = 0;
  COMinit();
  ll n = (2 * Y - X) / 3;
  ll m = (2 * X - Y) / 3;
  if((X + Y) % 3 != 0) {
    ans = 0;
  } else {
    ans = COM(n + m, n);
  }
  cout << ans << endl;
}


Measured memory_bytes: 23680
k,a,b=map(int,input().split())
import sys
if k<=a:
    print(k+1)
    sys.exit()
ans=a
k-=a-1
if k%2==1:
    k-=1
    ans+=1

if b-a>=2:
    ans+=(b-a)*(k//2)
else:
    ans+=k

print(ans)
    

Measured memory_bytes: 3060
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;

static class MainClass
{
    public static void Main(string[] args)
    {
        var N = Console.ReadLine().ToInt32();

        var AB = Console.ReadLine().SplittedStringToInt32List();
        var A = AB[0];
        var B = AB[1];
        var Pn = Console.ReadLine().SplittedStringToInt32List();
        var dic = new Dictionary<string, int>();
        dic.Add("A", 0);
        dic.Add("B", 0);
        dic.Add("C", 0);
        foreach (var item in Pn)
        {
            if (item <= A)
            {
                dic["A"]++;
            }
            else if (item <= B && item > A)
            {
                dic["B"]++;
            }
            else
            {
                dic["C"]++;
            }
        }
        var min = INF;
        foreach (var item in dic)
        {
            min = Math.Min(item.Value,min);
        }
        if (min != INF)
            Console.WriteLine(min);
        else
            Console.WriteLine(0);

        Console.ReadLine();
    }
   

    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<long> SplittedStringToInt64List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    public const int INF = int.MaxValue / 2;
    public const long LONGINF = long.MaxValue / 2;

    public static int Max(params int[] values)
    {
        var maxes = -1;
        for (int i = 0; i < values.Length; i++)
        {
            maxes = Math.Max(values[i], maxes);
        }
        return maxes;
    }

    #endregion
}



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

int main()
{
    string s;
    cin >> s;

    for (int i = 0; i < s.size();i++)
    {
        if(s[i]== '7')
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}


Measured memory_bytes: 3592
H, W = map(int, input().split())
ans = float('inf')
for h in range(1,H):
    Sa = h * W
    w = W // 2
    Sb = (H-h) * w
    Sc = (H-h) * (W-w)
    ans = min(ans,max([Sa,Sb,Sc])-min([Sa,Sb,Sc]))

for h in range(1,H):
    Sa = h * W
    hb = (H-h) // 2
    Sb = hb * W
    Sc = (H-h-hb) * W
    ans = min(ans,max([Sa,Sb,Sc])-min([Sa,Sb,Sc]))

for w in range(1,W):
    Sa = H * w
    h = H // 2
    Sb = h * (W-w)
    Sc = (H-h) * (W-w)
    ans = min(ans,max([Sa,Sb,Sc])-min([Sa,Sb,Sc]))

for w in range(1,W):
    Sa = w * H
    wb = (W-w) // 2
    Sb = wb * H
    Sc = (W-w-wb) * H
    ans = min(ans,max([Sa,Sb,Sc])-min([Sa,Sb,Sc]))

print(ans)

Measured memory_bytes: 9284
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <list>
#include <queue>
using namespace std;

int inf = (1 << 30);
int mod = 1e9 + 7;
int64_t inf64 = (1LL << 60);

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

bool check(vector<int> a, int index, int key){
    if(a[index] >= key) return true;
    else return false;
}

int lower_bound(vector<int> a, int key){
    int left = -1, right = a.size();
    while(right - left > 1){
        int mid = left + (left + right) / 2;
        if(check(a, mid, key)) right = mid;
        else left = mid;
    }
    return right;
}

int main(){

    int N, T;
    cin >> N >> T;
    vector<int> t(N);
    for(int i = 0; i < N; i++) cin >> t[i];

    int64_t ans = T;
    int64_t on = 0, off = 0;
    for(int i = 0; i < N - 1; i++){
        on = t[i];
        if(t[i + 1] - on > T) ans += T;
        else ans += t[i + 1] - on;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int N, K;
int x,y;
char c;

int field[2005][2005];
int sum[2005][2005];

int cnt_req(int x1, int y1, int x2, int y2){
	//if(x2 < x1 || y2 < y1) return 0;
	//cout << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
	int a,b,c;
	if(x1 == 0 || y1 == 0) a = 0;
	else a = sum[y1-1][x1-1];
	if(x1 == 0) b = 0;
	else b = sum[y2][x1-1];
	if(y1 == 0) c = 0;
	else c = sum[y1-1][x2];
	return sum[y2][x2]-b-c+a;
}

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

	cin >> N >> K;

	for (int i = 0;i < N;i++){
		cin >> x >> y >> c;
		if(c == 'W') x += K;
		field[y%(2*K)][x%(2*K)]++;
	}


	for (int i = 0;i < 2*K;i++){
		for (int j = 0;j < 2*K;j++){
			int a,b,c;
			if(i-1 < 0 || j-1 < 0) a = 0;
			else a = sum[i-1][j-1];
			if(i-1 < 0) b = 0;
			else b = sum[i-1][j];
			if(j-1 < 0) c = 0;
			else c = sum[i][j-1];
			sum[i][j] = field[i][j]+c+b-a;
		}
	}

	int ans = 0;

	for (int i = 0;i < 2*K;i++){
		for (int j = 0;j < 2*K;j++){
			int ax = i, ay = j, bx = i+K-1, by = j+K-1;
			int cnt = 0;
			for (int ii = -3;ii <= 3;ii++){
				for (int jj = -3;jj <= 3;jj++){
					int sx = ax+K*ii+K*jj, sy = ay+K*ii-K*jj;
					int tx = bx+K*ii+K*jj, ty = by+K*ii-K*jj;
					if((sx < 2*K && sy < 2*K && sx >= 0 && sy >= 0) || (tx >= 0 && ty >= 0 && tx < 2*K && ty < 2*K) 
							|| (tx >= 0 && sy >= 0 && tx < 2*K && sy < 2*K) || (sx >= 0 && ty >= 0 && sx < 2*K && ty < 2*K))  {
						cnt += cnt_req(max(0,sx), max(0,sy), min(2*K-1,tx), min(2*K-1,ty));
					}
				}
			}
			ans = max(ans,cnt);

		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 31616
a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

p=min(a)+min(b)

for i in range(m):
 x,y,c=map(int,input().split())
 z=a[x-1]+b[y-1]-c
 p=min(p,z)

print(p)

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll int, null_type,less<ll int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  200005
ll n,l,r;
vi a(N),seg(4*N);
void build(ll cur,ll st,ll end)
{
    if(st==end)
    {
        seg[cur]=a[st];
        return;
    }
    ll mid=(st+end)>>1;
    build(2*cur,st,mid);
    build(2*cur+1,mid+1,end);
    seg[cur]=max(seg[2*cur],seg[2*cur+1]);    /*  1-change here  */
}
ll query(ll cur,ll st,ll end,ll l,ll r)
{
    if(l<=st&&r>=end)
    return seg[cur];
    if(r<st||l>end)
    return 0;                           /*  2-change here  */
    ll mid=(st+end)>>1;
    ll ans1=query(2*cur,st,mid,l,r);
    ll ans2=query(2*cur+1,mid+1,end,l,r);
    return max(ans1,ans2);                 /*  3-change here  */
}
void update(ll cur,ll st,ll end,ll pos,ll upd)
{
    if(st==end)
    {
        a[pos]=upd;                    /*  4-change here  */
        seg[cur]=upd;                    /*  5-change here  */
        return;
    }
    ll mid=(st+end)>>1;
    if(st<=pos&&pos<=mid)
        update(2*cur,st,mid,pos,upd);
    else
        update(2*cur+1,mid+1,end,pos,upd);
    seg[cur]=max(seg[2*cur],seg[2*cur+1]);    /*  6-change here  */
}
int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
        ll i,j,k,l,m,n;
        cin>>n;
        vi h(n),ai(n);
        cin>>h>>ai;
        for(i=0;i<=n;i++)
            a[i]=0;
        build(1,0,n);
        ll ans=0;
        for(i=0;i<n;i++)
        {
            ll x=query(1,0,n,0,h[i]-1);
            ll y=x+ai[i];
            ans=max(y,ans);
            update(1,0,n,h[i],y);
        }
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 11264
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
	static final int MAX = 2_147_483_646; // intMax 
	static final int INF = 1_000_000_000; // 10^9  
	public static void main(String[] args) throws Exception{
		hayami saori = new hayami();
		
		String ans = saori.nextHayami();
		String[] s = ans.split("");
		if(s[s.length-1].equals("s")){
			ans += "es";
		} else {
			ans += "s";
		}
		System.out.println(ans);
		saori.close();
	}
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}


Measured memory_bytes: 36552