akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INF (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define N 100005
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795


//vl a(1001);

ll powM(ll a,ll b, ll m)
{ 
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans%m;
}



//vl a(n+1);
ll ans(ll n,ll k)
{
   ll l=1,r=(ll)1e10,m;
    while(l<=r)
    {
      m=(l+r)/2;
     //  if(m%n==0&&m-m/n==k)return m+1;
       if(m-m/n<k)l=m+1;
      else r=m-1;
    }
    ll temp=m-m/n;
    if(temp==k)return m;
    else return m+(k-temp);
}
int main()
{
string s;cin>>s;
ll ans=0,cnt=0;
for(char x:s)
{
  if(x=='W')ans+=cnt;
  else cnt++;
}
cout<<ans<<"\n";

  return 0;




}

Measured memory_bytes: 640
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

int main()
{
    int s, w;
    std::cin >> s >> w;

    std::cout << (s <= w ? "unsafe" : "safe") << std::endl;
}


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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n,w;
  scanf("%d%d",&n,&w);
  int val[100];
  int weight[100];
  int i;
  for(i=0;i<n;i++){
    scanf("%d%d",val+i,weight+i);
  }
  int dp[10001];
  for(i=0;i<=w;i++) dp[i]=-1;
  dp[0]=0;
  for(i=0;i<n;i++){
    int j;
    for(j=0;j<=w-weight[i];j++){
      if(dp[j]>=0){
	int k=j+weight[i];
	dp[k]=MAX(dp[k],dp[j]+val[i]);
      }
    }
  }
  int ans=0;
  for(i=0;i<=w;i++){
    ans=MAX(ans,dp[i]);
  }
  printf("%d\n",ans);
  return;
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
typedef pair<int,int> P;
struct edge{int to, id;};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007
 
using graph = vector<vector<ll>>;

int main(){
    int n,x,t;
    cin >> n >> x >> t;
    int ans;
    //ans = t * (n/x+1);
    int time;
    if(n/x * x == n){
        time = n/x;
    }
    else{
        time = n/x+1;
    }
    ans = t * time;
    cout << ans << endl;
}

Measured memory_bytes: 3616
/*
Till the roof comes off, till the lights go out
Till my legs give out, can’t shut my mouth.
Till the smoke clears out. Am I high? Perhaps
I'ma rip this shit till my bones collapse.
*/
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string.h>
#include <map>
#include <vector>
#include <queue>
#include <math.h>
#include <stack>
#include <complex>

#define pb push_back
#define f first
#define s second
#define ll long long
#define sz(v)      ((int)((v).size()))
#define X real()
#define Y imag()
#define angle(a)                (atan2((a).imag(), (a).real()))
#define vec(a,b)                ((b)-(a))
#define same(p1,p2)             (dp(vec(p1,p2),vec(p1,p2)) < EPS)
#define dp(a,b)                 ( (conj(a)*(b)).real() )	// a*b cos(T), if zero -> prep
#define cp(a,b)                 ( (conj(a)*(b)).imag() )	// a*b sin(T), if zero -> parllel
#define len(a)               (hypot((a).imag(), (a).real()))
#define normalize(a)            (a)/length(a)

using namespace std;

typedef pair<int,ll>ii;
typedef pair<ii,int>node;
typedef complex<double>point;


const int N=1005;
const int M=101;
const double EPS = 1e-9;
const int INF =1e9;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
double getDist(point a,point b){return sqrt((a.X-b.X)*(a.X-b.X)+(a.Y-b.Y)*(a.Y-b.Y));}
int dcmp(double x, double y) {return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1;}

ll mod=1000000007;
ll power(ll base,int p){if(!p)return 1;ll ret=power(base,p/2);ret*=ret;ret%=mod;if(p&1)ret*=base,ret%=mod;return ret;}
ll modInverse(int a){return power(a,mod-2);}

vector<int>adj[N];
int x[N],n,idx[N];
ll dp[N],memo[N][N*5];
ll solve(int cur,int sum){
  if(sum<0)return 1e9;
  if(cur<0)return 0;
  if(memo[cur][sum]!=-1)return memo[cur][sum];
  ll ret=min(solve(cur-1,sum-dp[idx[cur]])+x[idx[cur]],solve(cur-1,sum-x[idx[cur]])+dp[idx[cur]]);
  return memo[cur][sum]=ret;
}
void dfs(int node){
    for(int i=0;i<adj[node].size();i++)
        dfs(adj[node][i]);
    for(int i=0;i<adj[node].size();i++){
        idx[i]=adj[node][i];
        for(int j=0;j<N*5;j++)
            memo[i][j]=-1;
    }
    /// assume node is Black and for each of my children i will try to
    /// color each of them either black or white in order to reach a sum<=x[node]
    /// and at the same time minimize the sum of the rest of the nodes
    dp[node]=solve(sz(adj[node])-1,x[node]);
    //cout<<node<<' '<<dp[node]<<endl;
}
int main()
{
    //freopen("test.in","r",stdin);
    // freopen("test.out","w",stdout);
   scanf("%d",&n);
   for(int i=2;i<=n;i++){
        int a;
        scanf("%d",&a);
        adj[a].pb(i);
   }
   for(int i=1;i<=n;i++)scanf("%d",&x[i]);
   memset(dp,0,sizeof(dp));
   dfs(1);
   if(dp[1]>=1e9)cout<<"IMPOSSIBLE";
   else cout<<"POSSIBLE";
  return 0;
}

/*
100% reason to Remember THE NAME
*/


Measured memory_bytes: 39552
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {

  int a,b,k;
  int i;
  int count = 0;

  cin >> a >> b >> k;

  i = min(a,b);
  
  while ( count != k ) {
    if ( a%i == 0 && b%i == 0 ) {
      ++count;
    }
    --i;
  }

  cout << i+1 << endl;

  return 0;

}


Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

template <typename T, long long K>
class Doubling {
	public:
	std::size_t n;
	std::size_t k;
	std::vector<std::vector<T>> doubling;

	template <typename F>
	Doubling(std::size_t n, F next)
		: n(n), k(([]() {
			  std::size_t k = 1;
			  while((1LL << k) < K) {
				  k++;
			  }
			  return k;
		  })()),
		  doubling(k + 1, std::vector<T>(n)) {
		for(int i = 0; i < this->n; i++) {
			this->doubling[0][i] = next(i);
		}
		for(int i = 0; i < this->k; i++) {
			for(int j = 0; j < this->n; j++) {
				this->doubling[i + 1][j] =
					this->doubling[i][this->doubling[i][j]];
			}
		}
	}

	T operator()(std::size_t x) {
		std::size_t p = 0;
		for(std::size_t i = 0; i < this->k; i++) {
			if(x & (1LL << i)) {
				p = this->doubling[i][p];
			}
		}
		return p;
	}
};

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	REP(i, n) {
		cin >> a[i];
		a[i]--;
	}

	auto doubling =
		Doubling<int, 1000000000000000000>(n, [&](int i) { return a[i]; });

	cout << doubling(k) + 1 << endl;
	return 0;
}


Measured memory_bytes: 53416
import java.io.*;
import java.util.*;

// Solution class
class Solution {
    public Solution() { }
    private static final InputReader scan = new InputReader();
    // solve method
    public void solve() throws IOException {
        PrintWriter out = new PrintWriter(System.out);
        // code goes here...
        boolean bool = true;
        int c = 0;
        while (bool) {
			int x = scan.nextInt();
			if (x != 0) {
				c++;
				out.println("Case " + c + ": " + x);
			} else {
				bool = false;
			}
		}

        out.close();
    }
}

// InputReader class
class InputReader {
    private final BufferedReader br;
    private StringTokenizer st = new StringTokenizer("");
    public InputReader() { br = new BufferedReader(new InputStreamReader(System.in)); }
    public boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)  return false;
                st = new StringTokenizer(line);
            } catch (IOException ie) { throw new RuntimeException(ie); }
        }
        return true;
    }
    public String next() throws IOException {
        while (!st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException ie) { ie.printStackTrace(); }
        }
        return st.nextToken();
    }
    public String nextLine() throws IOException {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException ie) { ie.printStackTrace(); }
        return str;
    }
    public double nextDouble() throws IOException { return Double.parseDouble(next()); }
    public int nextInt() throws IOException { return Integer.parseInt(next()); }
    public long nextLong() throws IOException { return Long.parseLong(next()); }
}

// Main class
public class Main {
    public Main() { }
    // driver method
    public static void main(String[] args) throws IOException {
        new Solution().solve();
    }
}



Measured memory_bytes: 30440
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N, K;
int x[100], y[100];
Pii p[100];
Pii praw[100];

int csum[100][100];

int cntincluded(int top, int bottom, int right, int left) {
  int topy = p[top].second;
  int bottomy = p[bottom].second;
  int rightx = p[right].first;
  int leftx = p[left].first;

  return csum[rightx][topy] - csum[leftx - 1][topy] -
         csum[rightx][bottomy - 1] + csum[leftx - 1][bottomy - 1];
}

int main() {
  cin >> N >> K;
  rep(i, 0, N) {
    cin >> x[i] >> y[i];
    p[i] = Pii(x[i], y[i]);
    praw[i] = Pii(x[i], y[i]);
  }

  sort(p, p + N);

  rep(i, 0, N) { p[i] = Pii(p[i].second, i + 1); }

  sort(p, p + N);

  rep(i, 0, N) { p[i] = Pii(p[i].second, i + 1); }

  sort(p, p + N);

  sort(praw, praw + N);

  repe(i, 1, N) {
    repe(j, 1, N) {
      int add = 0;
      if (p[i - 1].second == j) {
        add = 1;
      }
      csum[i][j] = csum[i - 1][j] + csum[i][j - 1] - csum[i - 1][j - 1] + add;
    }
  }

  ll ans = numeric_limits<ll>::max();
  rep(i, 0, N) {
    rep(j, 0, N) {
      rep(k, 0, N) {
        rep(l, k + 1, N) {
          ll top = praw[i].second;
          ll bottom = praw[j].second;
          if (bottom > top) continue;

          ll left = praw[k].first;
          ll right = praw[l].first;
          if (right < left) continue;

          if (cntincluded(i, j, l, k) >= K) {
            chmin(ans, (top - bottom) * (right - left));
          }
        }
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
#define endl '\n'
#define _ << ' '
#define min3(a, b, c) min(a, min(b, c))
#define min4(a, b, c, d) min(min(a, d), min(b, c))

using namespace std;
const ll mod = (ll)1e9+7;
const ll INF = (ll)1e9+1;

int n; ll ans=0;
ll m[100001];
ll h[100001];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("B.txt", "r", stdin);
    #endif
    cin >> n;
    for(int i=0; i<=n; i++)
    {
        cin >> m[i];
    }
    for(int i=0; i<n; i++)
    {
        cin >> h[i];
        if(h[i]>=m[i])
        {
            h[i]-=m[i];
            ans+=m[i];
            if(h[i]>=m[i+1])
            {
                ans+=m[i+1];
                m[i+1]=0;
            }
            else
            {
                ans+=h[i];
                m[i+1]-=h[i];
            }
        }
        else
        {
            ans+=h[i];
        }
    }
    cout << ans;
}


Measured memory_bytes: 1792
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		// 計算
		String result = "NO";
		if(b - a == c - b) result = "YES";
		
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 21844
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;
    
signed main(){
    int a,p;
    cin >> a >> p;
    p += a*3;
    cout << p/2 << endl;
    
    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc128.contest.atcoder.jp/tasks/abc128_a

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int fanc(int n)
{
    int r = 1,i;
    for (i = 1; i <= n; i++)
    {
        r *= i;
    }
    return r;
}

int con(int n,int k)
{
    int r;
    r = fanc(n) / fanc(k) / fanc(n - k);
    return r;
}
int main()
{
    int n,i,j;
    double r,x[8],y[8];
    double sum = 0;
    double ans;

    scanf("%d",&n);

    for (i = 0; i < n; i++)
    {
        scanf("%lf %lf",&x[i],&y[i]);
    }

    int c = 0;
    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            r = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
            r = sqrt(r);
            sum += r;
        }
    }
    ans = sum * (n - 1) / con(n,2);

    printf("%.12lf",ans);
}


Measured memory_bytes: 128
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define MAX 500015
#define NIL -1

typedef struct{ 
	int p, lc, rc, key;
}node;

node T[MAX];
int i, m, size=0, root;
char inst[8];

void insert(int z){
	int x,y;
	y = NIL; //parent of x
	x = root;
	size++;
	T[size].key = z;
		
	while (x != NIL){// || x != 0){
		y = x; //parent
		if (z < T[x].key)
			x = T[x].lc;
		else x= T[x].rc;
	}
	T[size].p = y;
	
	if (y == NIL)
		root = size;
	else if (z < T[y].key)
		T[y].lc = size;
	else T[y].rc = size;
}

void preOrder(int u){
	if (u == NIL)
		return;
	printf(" %d", T[u].key);
	preOrder(T[u].lc);
	preOrder(T[u].rc);
}

void inOrder(int u){
	if (u == NIL)
		return;
	inOrder(T[u].lc);
	printf(" %d", T[u].key);
	inOrder(T[u].rc);
}


int main(void) {
	int k;
	root = NIL;
	scanf("%d", &m);
	//initialize
	for (i=0; i<m; i++){
		T[i].p = T[i].lc = T[i].rc = T[i].key = NIL;
	}
	
	for(i=0; i<m; i++){
		scanf("%s", &inst);
		if (inst[0] == 'i'){
			scanf("%d", &k);
			insert(k);
		}
		else{
				inOrder(root);
				printf("\n");
				preOrder(root);
				printf("\n");
			
		}
	}

	return 0;
}



Measured memory_bytes: 9516
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int d;
    scanf("%d",&d);
    if(d==25) cout<<"Christmas"<<endl;
    else if(d==24) cout<<"Christmas Eve"<<endl;
    else if(d==23) cout<<"Christmas Eve Eve"<<endl;
    else cout<<"Christmas Eve Eve Eve"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>


using namespace std;


int main() {
	
	int n, k, x, y;
	int cnt = 0;
	cin >> n >> k >> x >> y;

	for (int i = 1; i <= n; i++) {
		if (i > k) {
			cnt += y;
			continue;
		}
		cnt += x;
	}

	cout << cnt << endl;
	
}



Measured memory_bytes: 256
import sys
from math import sqrt
from collections import Counter

input = sys.stdin.readline


def I():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    a = I()
    b = I()
    c = I()
    x = I()

    result = 0
    for i in range(a + 1):
        for j in range(b + 1):
            for k in range(c + 1):
                total = 500 * i + 100 * j + 50 * k
                if x == total:
                    result += 1
    print(result)
    pass


if __name__ == "__main__":
    main()


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

const int MAX = 2000005;
const int mod = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = 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;
    }
}
long long 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(){
COMinit();
 int i;
 int r1;
 int r2;
 int c1;
 int c2;
 long long int ans = 0;
 cin >> r1 >> c1 >> r2 >> c2;
 for(i=r1;i<r2+1;i++){
         ans += COM(i+c2+1,c2)+(mod-COM(i+c1,c1-1));
         ans %= mod;
 }
cout << ans << endl;
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
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; }

lli d;
lli c[26];
lli s[370][26];
lli t[370];
lli lastDay[26];
std::chrono::system_clock::time_point start;

lli score(){

	lli ans = 0;
	REP(i,0,26)lastDay[i]=0;

	REP(i,1,d+1){
		ans += s[i-1][t[i-1]];

		lastDay[t[i-1]] = i;
		REP(j,0,26){
			ans -= c[j]*(i-lastDay[j]);
		}
		//cout<<ans<<endl;
	}
	return ans;
}

void dummyDayInput(){

	REP(i,0,d){
		cin>>t[i];
		//t[i]=1;
		t[i]--;
	}

}

void input(){
	cin>>d;
	REP(i,0,26)cin>>c[i];
	REP(i,0,d){
		REP(j,0,26){
			cin>>s[i][j];
		}
	}
}

void dummyDayChangeInput(){
	lli m;
	cin>>m;

	REP(i,0,m){
		lli d,q;
		cin>>d>>q;
		d--,q--;
		t[d] = q;
		cout<<score()<<endl;
	}
}

void init(){
	REP(i,0,365){
		t[i]=i%26;
	}
}

void outputT(){
	REP(i,0,d){
		cout<<t[i]+1<<endl;
	}
}

int main(){

	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	start = std::chrono::system_clock::now();
	mt19937 mt{std::random_device{}()};

	const lli T = 1950*1000;

	input();
	init();

	uniform_int_distribution<int> contestDist(0,25);
	uniform_int_distribution<int> dayDist(0,d-1);

	lli prevScore=score();

	lli cnt = 0;
	
	while(1){
        std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
        double elapsed = std::chrono::duration_cast<std::chrono::microseconds>(now-start).count();
        if(elapsed > T)break;

        lli contestD = contestDist(mt);
        lli dayD     = dayDist(mt);

        LOG2(contestD,dayD);

        lli prevContest = t[dayD];
        t[dayD] = contestD;

        lli nowScore = score();
        if(cnt%1000==0)LOG3(cnt,nowScore,prevScore);
        if(prevScore>nowScore){
        	t[dayD] = prevContest;
        }
        else{
        	prevScore = nowScore;
        }
	}
	

	outputT();
	//dummyDayInput();
	//score();
	//dummyDayChangeInput();
 
	return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define rep(i, b) for (__typeof(b) i = 0; i < b; i++)
#define repo(i, a, b) for (__typeof(a) i = a; i <= b; i++)
const int MOD = 1e9 + 7;
const int INF = 1e9;
ll v[200005];
int main()
{
    string s;
    cin >> s;
    ll m = 1e9;
    rep(i, s.size() - 2)
    {
        string f = "";
        f += s[i];
        f += s[i + 1];
        f += s[i + 2];
        m = min(m, abs(stoll(f) - 753));
    }
    cout << m;
    return 0;
}

Measured memory_bytes: 256
//
// Created by watemus on 17.05.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second

using ll = long long;
using ld = long double;
#define int ll

constexpr ll INFL = 1'000'000'000'000'000'228;
constexpr int INFI = 1'000'000'228;

vector<pair<int, int>> DD = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

#ifdef LOCAL
#else
#endif


void run() {
    int k;
    string s;
    cin >> k >> s;
    if (s.size() > k) {
        for (int i = 0; i < k; i++) {
            cout << s[i];
        }
        cout << "...";
    } else {
        cout << s;
    }
}

signed main() {
#ifdef LOCAL
    std::freopen("input.txt", "r", stdin);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    int t = 1;
//    cin >> t;
    while (t--) {
        run();
    }
    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
#include<list>
using namespace std;

int main() {

	int A, B;
	cin >> A >> B;

	cout << A*B - A - B + 1 << endl;

	return 0;
}


Measured memory_bytes: 256
N_satsu, M_ko, X = map(int, input().split())

Books = []
min_money = float('inf')

for i in range(N_satsu):
    tmp = list(map(int, input().split()))
    Books.append(tmp)


for i in range(2 ** N_satsu):
    sum_money = 0
    sum_skill = [0 for k in range(M_ko)]
    
    for j in range(N_satsu):
        bitt = i >> j
        if (bitt & 1):
            sum_money += Books[j][0]
            
            for _ in range(M_ko):
                sum_skill[_] += Books[j][_ + 1]
    
    judge = [l >= X for l in sum_skill]
    if (all(judge)):
        min_money = min(min_money, sum_money)

if (min_money != float('inf')):
    print(min_money)
else:
    print(-1)


Measured memory_bytes: 9180
#include <iostream>
#include <string>
using namespace std;
int main(){
int H,A,N,f=0;
int a[1000020];
  cin>>H>>N;
for (int i = 0; i < N; ++i) cin >> a[i];
for(int i=0;H>0;i++){
 H-=a[i];
if(i>N-1){
f=1;
  break;}
}
if(f==1)cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr int64_t MIN = -1e18;

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

  int32_t H,W,Ch,Cw,Dh,Dw;
  cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
  vector<vector<char>> S(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }
  using p = pair<int, int>;
  queue<p> q;
  queue<p> mq;
  q.push(make_pair(Ch - 1,Cw - 1));
  int64_t res = 0;
  while (!q.empty() || !mq.empty()) {
    while (!q.empty()) {
      p cur = q.front();
      q.pop();
      int x = cur.first;
      int y = cur.second;
      if (S[x][y] == 'x') continue;
      S[x][y] = 'x';
      if (x == Dh - 1 && y == Dw - 1) break;
      // push q
      bool mq_push = false;
      // up
      if (x - 1 >= 0 && S[x-1][y] == '.') {
        q.push(make_pair(x-1, y));
      } else if (x - 1 >= 0 && S[x-1][y] == '#') {
        mq_push = true;
      }
      // down;
      if (x + 1 < H && S[x+1][y] == '.') {
        q.push(make_pair(x+1, y));
      } else if (x + 1 < H && S[x+1][y] == '#') {
        mq_push = true;
      }
      // left
      if (y - 1 >= 0 && S[x][y-1] == '.') {
        q.push(make_pair(x, y-1));
      } else if (y - 1 >= 0 && S[x][y-1] == '#') {
        mq_push = true;
      }
      // right
      if (y + 1 < W && S[x][y+1] == '.') {
        q.push(make_pair(x, y+1));
      } else if (y + 1 < W && S[x][y+1] == '#') {
        mq_push = true;
      }

      if (mq_push == true) {
        for (int i = -2; i <= 2; i++) {
          for (int j = -2; j <=2; j++) {
            if (x + i >= 0 && x + i < H && y + j >= 0 && y + j < W && S[x+i][y+j] == '.') {
              mq.push(make_pair(x+i, y+j));
            }
          }
        }
      }
    }
    if (S[Dh-1][Dw-1] == 'x') break;
    res++;
    // loop mq
    while (!mq.empty()) {
      p cur = mq.front();
      int x = cur.first;
      int y = cur.second;
      mq.pop();
      if (S[x][y] == '.') {
        q.push(make_pair(x,y));
      }
    }
  }

  if (S[Dh-1][Dw-1] == 'x') {
    cout << res << endl;
  } else {
    cout << -1 << endl;
  }
    

  return 0;
}


Measured memory_bytes: 5132
N = int(input())
S = list(input())
ans = ''
a = list('ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ')
for s in S:
    ind = a.index(s) + N
    # print(ind)
    ans = ans + a[ind]
print(''.join(ans))


Measured memory_bytes: 41324
#include <iostream>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  char A[50][50], B[50][50];
  for(int i=0; i<N; ++i) scanf("%s", &A[i][0]);
  for(int i=0; i<M; ++i) scanf("%s", &B[i][0]);
  auto check = [&](int x, int y){
    for(int i = 0; i < M; i++)
      for(int j = 0; j < M; j++)
        if(A[x+i][y+j] != B[i][j])
          return 0;
    return 1;
  };
  for(int Ay=0; Ay<=N-M; ++Ay)
    for(int Ax=0; Ax<=N-M; ++Ax)
      if(check(Ax, Ay))
      {
        cout << "Yes" << endl;
        return 0;
      }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int main() {
	int n,a;cin>>n>>a;
	cout<<n*n-a<<endl;
}


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var P = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var ans = 0;
            var min = int.MaxValue;

            for (int i = 0; i < N; i++)
            {
                if (P[i] <= min)
                {
                    ans++;
                    min = P[i];
                }
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 35676
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    temp=str((int(s[0])+1))*3
    ct=int(temp)-int(s)
    #print(ct)
    if 0<=ct<=110:
        print(temp)
    else:
        temp=s[0]*3
        print(temp)
    
    
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	ll n, k;
	scanf("%ld %ld", &n, &k);
	ll prev, now, ans = 0;
	scanf("%ld", &prev);
	if(prev>k){
		ans += prev-k;
		prev = k;
	}
	REP(i, 1, n){
		scanf("%ld", &now);
		if(prev+now>k){
			if(now>=prev+now-k){
				ans += prev+now-k;
				now -= prev+now-k;
			}else{
				ans += now;
				now = 0;
				ans += prev-k;
			}
		}
		prev = now;
	}
	printf("%ld\n", ans);
	return 0;
}



Measured memory_bytes: 256
a, b = [int(x) for x in input().split()]

if a >= b:
    if (a - b) % 2 != 0:
        print("IMPOSSIBLE")
    else:
        print(int(a - ((a - b) / 2)))
else:
    if (b - a) % 2 != 0:
        print("IMPOSSIBLE")
    else:
        print(int(b - ((b - a) / 2)))

Measured memory_bytes: 3060
//
//  main.cpp
//  C
//
//  Created by Yuto Murashita on 28/05/2017.
//  Copyright © 2017 ymch1905. All rights reserved.
//

#include <iostream>
#include <string>

using namespace std;

int N, M, Q;
char S[2001][2001];
int nodes[2001][2001];
int vedges[2001][2001];
int hedges[2001][2001];

void prepare(void){
    if(S[0][0]=='1') nodes[0][0]=1;
    for(int n=1; n<N; n++){
        nodes[n][0]=nodes[n-1][0];
        vedges[n][0]=vedges[n-1][0];
        if(S[n][0]=='1'){
            nodes[n][0]+=1;
            if(S[n-1][0]=='1') vedges[n][0]+=1;
        }
    }
    
    for(int m=1; m<M; m++){
        int tmpn[N], tmpve[N], tmphe[N];
        if(S[0][m]=='1') tmpn[0]=1; else tmpn[0]=0;
        if(S[0][m]=='1' && S[0][m-1]=='1') tmphe[0]=1; else tmphe[0]=0;
        nodes[0][m]=nodes[0][m-1]+tmpn[0];
        hedges[0][m]=hedges[0][m-1]+tmphe[0];
        vedges[0][m]=0; tmpve[0]=0;
        for(int n=1; n<N; n++){
            tmpn[n]=tmpn[n-1]; tmpve[n]=tmpve[n-1]; tmphe[n]=tmphe[n-1];
            if(S[n][m]=='1'){
                tmpn[n]+=1;
                if(S[n][m-1]=='1') tmphe[n]++;
                if(S[n-1][m]=='1') tmpve[n]++;
            }
            nodes[n][m]=nodes[n][m-1]+tmpn[n];
            hedges[n][m]=hedges[n][m-1]+tmphe[n];
            vedges[n][m]=vedges[n][m-1]+tmpve[n];
        }
    }
}

int main(){
    cin >> N >> M >> Q;
    for(int n=0; n<N; n++){
        cin >> S[n];
    }
    
    prepare();
    
    /*
    for(int n=0; n<N; n++){
        for(int m=0; m<M; m++){
            cout << hedges[n][m] << " ";
        }
        cout << endl;
    }
     */
    
    
    for(int q=0; q<Q; q++){
        int x1, x2, y1, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        x1--; y1--; x2--; y2--;
        int N, HE, VE;
        N = nodes[x2][y2]; HE=hedges[x2][y2]; VE=vedges[x2][y2];
        if(x1!=0){
            N -= nodes[x1-1][y2]; HE -= hedges[x1-1][y2]; VE -= vedges[x1][y2];
        }
        if(y1!=0){
            N -= nodes[x2][y1-1]; HE -= hedges[x2][y1]; VE -= vedges[x2][y1-1];
        }
        if(x1!=0 && y1!=0){
            N += nodes[x1-1][y1-1]; HE += hedges[x1-1][y1]; VE += vedges[x1][y1-1];
        }
        //cerr << N << " " << HE << " " << VE << endl;
        cout << N-HE-VE << endl;
    }
    
    return 0;
}


Measured memory_bytes: 52608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	public static ArrayList<String> s = new ArrayList<String>();
	public static void main(String[] args) throws IOException {
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n= in.nextInt();
		int [] a= new int[n];
		int [] f= new int[(int) (1e5+10)];
		int numneg=0;
		for (int i = 0; i < a.length; i++) {
			a[i]= in.nextInt();
			f[a[i]]++;
			f[a[i]+1]++;
			if(a[i]==0) numneg++;
			else f[a[i]-1]++;
		}
		int res= numneg;
		for (int i = 0; i < f.length; i++) {
			res= Math.max(res, f[i]);
		}
		System.out.println(res);

	}
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}

		public double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		public String next() throws IOException {
			if (!st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
				return next();
			}
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	}
}



Measured memory_bytes: 35420
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:108777216")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <bitset>
#include <queue>
#include <algorithm>
using namespace std;
 
int const MAX_N = 4 * 1024 * 1024;

bitset<MAX_N> bt;
int s[4 * 1024];

int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
 
    int n;
	cin>>n;
	for (int i=0; i<n; i++) cin>>s[i];

	int sum = 0;
	for (int i=0; i<n; i++) sum += s[i];

	bt.set(0);
	for (int i=0; i<n; i++)
		bt |= bt << s[i];

	for (int i=(sum+1)/2; i<MAX_N; i++)
		if (bt.test(i)) {
			cout<<i;
			break;
		}

    return 0;
}  


Measured memory_bytes: 1792
let () =
  Scanf.scanf "%s" @@ fun s ->
  let len = String.length s in
  let rec f a stk i =
    if i = len then 2*a
    else
      match stk, s.[i] with
      | [], c         -> f a [c] (i+1)
      | '0'::stk, '1' -> f (a+1) stk (i+1)
      | '1'::stk, '0' -> f (a+1) stk (i+1)
      | _, c  -> f a (c::stk) (i+1)
  in f 0 [] 0 |> Printf.printf "%d\n"

Measured memory_bytes: 5376
#include <iostream>
#include <set>
#include <atcoder/dsu>
#include <algorithm>

using namespace std;
using namespace atcoder;

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

    int xtoy[N], ytoi[N];
    for(int i=0;i<N;i++) {
        int x,y;
        cin >> x >> y;
        xtoy[x-1] = y;
        ytoi[y-1] = i;
    }
    set<int> s;
    for(int i=0;i<N;i++) {
        auto itr = s.begin();
        auto end = s.upper_bound(xtoy[i]);
        if(itr == end) {
            s.insert(xtoy[i]);
            continue;
        }
        int first = *itr;
        for(;itr!=end;itr=s.erase(itr)) {
            d.merge(ytoi[xtoy[i]-1], ytoi[*itr-1]);
        }
        s.insert(first);
    }

    for(int i=0;i<N;i++) {
        cout << d.size(i) << endl;
    }
}

Measured memory_bytes: 10132
import sys
input = sys.stdin.readline
import math
a, b, c = [int(x) for x in input().split()]

c -= (a + b)
if c <= 0:
    print("No")
    sys.exit()

c = c ** 2 - 4 * a * b

if c > 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
program prob2
    implicit none
    character(len=100045)::S
    character(len=1),allocatable::S1(:),S2(:)
    integer::i,j, l, cnt, n, ans1, ans2
    integer::v(1000)
    read(*,*) S
    l = len_trim(S)
    allocate(S1(l),S2(l))

    do i = 1, l
        if(mod(i,2) == 0)then
            S1(i) = "1"
            S2(i) = "0"
        else
            S1(i) = "0"
            S2(i) = "1"
        end if
    end do

    ans1 = 0
    ans2 = 0
    do i = 1, l
        if(S(i:i) .ne. S1(i))then
            ans1 = ans1 + 1
        end if
        if(S(i:i) .ne. S2(i))then
            ans2 = ans2 + 1
        end if
    end do
    if(ans1 > ans2)then
        write(*,*) ans2
    else
        write(*,*) ans1

    end if






    stop
end program
             

Measured memory_bytes: 3280
# coding: utf-8

n = int(input())
lst = list(map(int, input().split()))
cnt = 0
ans = 0
lstg = []
for i in lst:
    if (i % 2) == 0:
        lstg.append(i)

for i in lstg:
    if (i % 3) == 0 or (i % 5) == 0:
        cnt += 1

if len(lstg) == cnt or len(lstg) == 0:
    ans = 1
if ans > 0:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 3064
#if 0



#endif // 0

#include<cstdlib>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<cstring>
#include<cmath>
using namespace std;
const int MAXN = (int) 35;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;
int H,W,S;
int f[MAXN][MAXN][MAXN][MAXN];
int g[MAXN][MAXN][MAXN][MAXN];
int a[MAXN][MAXN];
int TOTAL;
int MI;

int get_sum(int i,int j,int k,int t){
    return a[k][t]-a[k][j-1]-a[i-1][t]+a[i-1][j-1];
}

void DFS(int I,int J,int K,int T){
    f[I][J][K][T]=1;
    g[I][J][K][T]=get_sum(I,J,K,T);
    if(I==K&&J==T) return;
    if(g[I][J][K][T]<MI) return;
    for(int i=I;i<K;i++){
        if(f[I][J][i][T]==-1) DFS(I,J,i,T);
        if(f[i+1][J][K][T]==-1) DFS(i+1,J,K,T);
        if(g[I][J][i][T]>=MI&&g[i+1][J][K][T]>=MI){
            if(f[I][J][i][T]+f[i+1][J][K][T]>f[I][J][K][T]){
                f[I][J][K][T]=f[I][J][i][T]+f[i+1][J][K][T];
                g[I][J][K][T]=min(g[I][J][i][T],g[i+1][J][K][T]);
            }
            else if(f[I][J][i][T]+f[i+1][J][K][T]==f[I][J][K][T]){
                int cur_mi=min(g[I][J][i][T],g[i+1][J][K][T]);
                g[I][J][K][T]=max(g[I][J][K][T],cur_mi);
            }
        }
    }
    for(int j=J;j<T;j++){
        if(f[I][J][K][j]==-1) DFS(I,J,K,j);
        if(f[I][j+1][K][T]==-1) DFS(I,j+1,K,T);
        if(g[I][J][K][j]>=MI&&g[I][j+1][K][T]>=MI){
            if(f[I][J][K][j]+f[I][j+1][K][T]>f[I][J][K][T]){
                f[I][J][K][T]=f[I][J][K][j]+f[I][j+1][K][T];
                g[I][J][K][T]=min(g[I][J][K][j],g[I][j+1][K][T]);
            }
            else if(f[I][J][K][j]+f[I][j+1][K][T]==f[I][J][K][T]){
                int cur_mi=min(g[I][J][K][j],g[I][j+1][K][T]);
                g[I][J][K][T]=max(g[I][J][K][T],cur_mi);
            }
        }
    }
}

void work(){
    while(~scanf("%d%d%d",&H,&W,&S)){
        if(H==0&&W==0&&S==0) break;
        TOTAL=0;
        for(int i=1;i<=H;i++){
            for(int j=1;j<=W;j++){
                scanf("%d",&a[i][j]);
                TOTAL+=a[i][j];
                a[i][j]+=a[i][j-1];
            }
        }
        for(int i=1;i<=H;i++){
            for(int j=1;j<=W;j++){
                a[i][j]+=a[i-1][j];
            }
        }
//        for(int i=1;i<=H;i++){
//            for(int j=1;j<=W;j++){
//                printf("%d ",a[i][j]);
//            }
//            printf("\n");
//        }
        MI=TOTAL-S;
        memset(f,-1,sizeof(f));
        memset(g,-1,sizeof(g));
        DFS(1,1,H,W);
        printf("%d %d\n",f[1][1][H][W],g[1][1][H][W]-MI);
    }
}

int main(){
    work();
    return 0;
}



Measured memory_bytes: 14940
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	b , c = tin()
	#s = input()
	ret = max(b+c,b+b-1, c+c-1)
	print(ret)
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

int main(){
    int n;
    int m;
    cin >> n >> m;
    vector<bool> a(n,false);
    bool ans = false;
    for(int i=0;i<m;i++){
        int tmp1 ,tmp2;
        cin >> tmp1>>tmp2;
        if(tmp1 ==1){
            if(a[tmp2-1]){
                ans = true;
            } 
            a[tmp2-1]= true;
        }

        if(tmp2 ==1){
            if(a[tmp1-1]){
                ans = true;
            } 
            a[tmp1-1]= true;
        }
        if(tmp1 ==n){
            if(a[tmp2-1]){
                ans = true;
            } 
            a[tmp2-1]= true;
        }

        if(tmp2 ==n){
            if(a[tmp1-1]){
                ans = true;
            } 
            a[tmp1-1]= true;
        }
    }

    if(ans){
        cout << "POSSIBLE" << endl;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
  #pragma GCC target("avx,avx2,fma")
  #include <bits/stdc++.h>
  using namespace std;
  //---------------------------------//
  void __print(int x) {cerr << x;}
  void __print(long x) {cerr << x;}
  void __print(long long x) {cerr << x;}
  void __print(unsigned x) {cerr << x;}
  void __print(unsigned long x) {cerr << x;}
  void __print(unsigned long long x) {cerr << x;}
  void __print(float x) {cerr << x;}
  void __print(double x) {cerr << x;}
  void __print(long double x) {cerr << x;}
  void __print(char x) {cerr << '\'' << x << '\'';}
  void __print(const char *x) {cerr << '\"' << x << '\"';}
  void __print(const string &x) {cerr << '\"' << x << '\"';}
  void __print(bool x) {cerr << (x ? "true" : "false");}

  template<typename T, typename V>
  void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
  template<typename T>
  void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
  void _print() {cerr << "]\n";}
  template <typename T, typename... V>
  void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
  #ifndef ONLINE_JUDGE
  #define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
  #else
  #define deb(x...)
  #endif
 //------------------------------//

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff           first
  #define  ss           second
  #define  pb           push_back
  #define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  all(x)       (x).begin(), (x).end()
  #define  ps(x,y)      fixed<<setprecision(y)<<x
  #define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 1e6 + 4;


  void solve(){
    ll ans=INF;
    ll n,m;
    cin >> n >> m; 
    ans = min({ans,((n+2)/3 - n/3)*m,((m+2)/3 - m/3)*n});
    // n
    for(ll i=1;i<=n-1;i++){
      ans = min(ans,max({i*m,(n-i)*(m/2),(n-i)*((m+1)/2)})-min({i*m,(n-i)*(m/2),(n-i)*((m+1)/2)})); 
    }
    swap(n,m);
    for(ll i=1;i<=n-1;i++){
      ans = min(ans,max({i*m,(n-i)*(m/2),(n-i)*((m+1)/2)})-min({i*m,(n-i)*(m/2),(n-i)*((m+1)/2)})); 
    }
      cout << ans;
  }

  int main(){
    IOS
    	solve();
    //cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

// integer overflow

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(n) for(ll i=0;i<n;i++)
#define fr(n) for(ll i=n-1;i>=0;i--)
int main()
{
	
	
	ll a,b;
	cin>>a>>b;
	if(a==b)
	{
		cout<<"0";
	}
	else if((a+b)%2==0)
		cout<<(a+b)/2;
	else
		cout<<"IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 256
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = [int(_) for _ in input().split()]
    for i in range(100):
        if x-i not in p:
            print(x-i)
            break
        if x+i not in p:
            print(x+i)
            break

Measured memory_bytes: 9184
#include <stdio.h>
int main(void)
{
	int H;
	int W;
	int i,j = 0;
	while(1){
		scanf("%d %d",&H,&W);
		if ((H==0)||(W==0))break;
		
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
		i++;
	}
	
	return 0;
}


Measured memory_bytes: 2124