akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
 
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
 

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int dp[k+1] = {};
    vector<int> v;
    for(int i=0;i<n;++i)
    {
      int tmp;
      cin >> tmp;
      v.push_back(tmp);
    }

    sort(v.begin(), v.end());
    for(int i=v[0];i<=k;++i)
    {
      bool isWinning = false;
      for(int j=0;j < v.size(); ++j)
      {
        if((i - v[j]) < 0) break;
        if(dp[i - v[j]] == 0)
        {
          isWinning = true;
        }
      }
      dp[i] = isWinning ? 1 : 0;
    }

    cout << (dp[k] == 1 ? "First" : "Second") << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <inttypes.h>

int N, x;
int a[200000];

int main(void) {
	int i;
	uint64_t answer = 0;
	if (scanf("%d%d", &N, &x)!=2)return 1;
	for(i=0;i<N;i++) {
		if(scanf("%d",&a[i])!=1)return 1;
	}
	for(i=1;i<N;i++) {
		int genzyou = a[i-1]+a[i];
		int diff = genzyou-x;
		if(diff>0) {
			int taberu=diff;
			if(a[i]<taberu)taberu=a[i];
			answer+=taberu;
			a[i]-=taberu;
		}
	}
	if(a[0]+a[1]>x) {
		int genzyou=a[0]+a[1];
		int diff=genzyou-x;
		if(diff>0) {
			int taberu=diff;
			if(a[0]<taberu)taberu=a[0];
			answer+=taberu;
			a[0]-=taberu;
		}
	}
	printf("%"PRIu64"\n", answer);
	return 0;
}


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

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

  bool exist = false;

  for (int i = 0; i <= (N / 4); i++) {
    for (int j = 0; j <= (N / 7); j++) {
      if (4 * i + 7 * j == N) {
        exist = true;
        break;
      }
    }
  }

  if (exist) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
string s;
LL cnt[30];
const int mod = 1e9 + 7;

int main(){
    INIT;
    cin >> n >> s;
    REP(i, n){
        cnt[s[i] - 'a']++;
    }
    LL ans = 1;
    REP(i, 26){
        if(!cnt[i])continue;
        ans *= (cnt[i] + 1);
        ans %= mod;
    }
    cout << (ans + mod - 1)%mod << endl;
}

Measured memory_bytes: 512
// parameter "input" gets all data
function Main(input) {
  var s = input.trim();

  var index_for_F = -1;
  var rev_index_for_F = s.split('').reverse().join('').indexOf('F');
  if (rev_index_for_F !== -1){
    index_for_F = s.length - rev_index_for_F - 1;
  }

  var index_for_C = -1;
  var rev_index_for_C = s.split('').reverse().join('').indexOf('C');
  if (rev_index_for_C !== -1){
    index_for_C = s.length - rev_index_for_C - 1;
  }

  if(index_for_C<index_for_F && (index_for_F !== -1) && (index_for_C !== -1)){
    console.log('Yes');
  }else{
    console.log('No');
  }
}
// Don't edit this line!
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 20724
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

s = arr_data[0][0]

#print(s)

print("Yes" if "a" in s and "b" in s and "c" in s else "No")

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

#define pb push_back
typedef long long int ll;
typedef vector<ll> vl;
typedef map<ll,ll> ii;
const ll mod = 1e9+7;
ll mod_mul(ll x,ll y){
    return ((x%mod)*(y%mod))%mod; 
}

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

ll fast_expo(ll x, ll y){
    
    ll res=1;
    while(y>0){
        if(y&1){
            res*=x;
        }
        x*=x;
        y>>=1;
    }
    return res;
}
//fast expo function
ll fast_expo(ll x, ll y, ll m){
    x%=m;
    ll res=1;
    while(y>0){
        if(y&1){
            res=((res%m)*(x%m))%m;
        }
        x=((x%m)*(x%m))%m;
        y>>=1;
    }
    return res;
}

//sieve function
void sieve(ll x,vl &v){
    bool sieve[x+1];
    memset(sieve,true,sizeof(sieve));
    int i=2;
    while(i*i<=x){
        if (sieve[i]==true){
            for(int j=i+i;j<=x;j+=i){
                sieve[j]=false;
            }
            
        }
    i++;    
    }
    
    for(int i=2;i<=x;i++){
        if(sieve[i])
            v.pb(i);
    }
    
}
//GCD function
int gcd(int x,int y){
    if(x==0)return y;
    return gcd(y%x,x);
}
//main code
int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    int t;cin>>t;
    vl a;
    for(int i=0;i<t;i++){
        ll k;cin>>k;
        a.push_back(k);
    }
    ii m;
    vl v;
    sieve(1001,v);
    
    
    for(ll i:a){
        int j=0;
        
        while(v[j]*v[j]<=i){
            ll k=v[j];
            ll c=0;
            if (i%k==0){
                while(i%k==0){
                    c++;
                    i/=k;
                }
            
                ll h=m[k];
                m[k]=max(c,h);
            }
            j++;
        }
        if (i>=2){
            ll c=1;
            m[i]=max(m[i],c);
        }
    }
    ll z=1;
    for(auto i:m){
        z=mod_mul(z,fast_expo(i.first,i.second));
    }
    ll y=0;
    for(ll i:a){
        y=mod_add(y,mod_mul(z,fast_expo(i,mod-2,mod)));
    }    
    
    cout<<y;
    return 0;
    
}
    

Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,k;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&k);
	if(b-a<=k && c-a<=k && d-a<=k && e-a<=k && c-b<=k && d-b<=k && e-b<=k && d-c<=k && e-c<=k && e-b<=k){
		printf("Yay!\n");
	}
	else{
		printf(":(\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n,t,q,a[100100],d[100100];
ll y[100100];
bool done[100100];
ll saiki(ll i){
    if(done[i])
        return y[i];

    if(i + d[i] < 0){
        done[i] = true;
        return y[i] = a[i] - t;
    }
    if(i + d[i] >= n){
        done[i] = true;
        return y[i] = a[i] + t;
    }

    if(d[i + d[i]] * d[i] == -1){
        done[i] = true;
        return y[i] = a[i] + d[i] * min(t,abs(a[i + d[i]] - a[i]) / 2);
    }
    y[i] = a[i] + d[i] * min(t,abs(saiki(i + d[i]) - a[i]));
    done[i] = true;
    return y[i];
}
int main(){
    cin >> n >> t >> q;
    REP(i,n){
        cin >> a[i] >> d[i];
        if(d[i] == 2)
            d[i] = -1;
    }
    REP(i,n)
        done[i] = false;
    REP(i,n){
        saiki(i);
    }
    REP(i,q){
        int x;
        cin >> x;
        x--;

        cout << y[x] << endl;
    }
    return 0;
}

Measured memory_bytes: 6972
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int x = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }

            long ans = 0;
            if (arr[0] > x) {
                int diff = arr[0] - x;
                ans += diff;
                arr[0] -= diff;
            }
            for (int i = 1; i < n; i++) {
                int diff  = arr[i] + arr[i - 1] - x;
                if (diff > 0) {
                    ans += diff;
                    arr[i] -= diff;
                }
            }
            out.println(ans);
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }

}

Measured memory_bytes: 46808
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	vector<int> d(3);
	cin >> n;
	rep(i,3) cin >> d[i];
	vector<P> q;
	rep(i,n){
		string s;
		cin >> s;
		int a = 0, b = 1;
		if(s == "AB") a = 0, b = 1;
		if(s == "BC") a = 1, b = 2;
		if(s == "AC") a = 0, b = 2;
		q.emplace_back(a, b);
	}
	string ans;
	auto add = [&](int a, int b){
		d[a]++;
		d[b]--;
		ans += 'A' + a;
	};
	q.emplace_back(0, 1);
	rep(i,n){
		int a = q[i].first;
		int b = q[i].second;
		if(!d[a] && !d[b]){
			cout << "No" << endl;
			return 0;
		}
		if(!d[a]){
			add(a, b);
		}
		else if(!d[b]){
			add(b, a);
		}
		else{
			int na = q[i+1].first;
			int nb = q[i+1].second;
			if(a == na || a == nb){
				add(a, b);
			}
			else{
				add(b, a);
			}
		}
	}
	cout << "Yes" << endl;
	rep(i,n) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 5348
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()

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

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    ll n, p; cin >> n >> p;
    string s; cin >> s;

    if(p == 2 || p == 5){
        ll ans = 0;
        rep(i,n) if((s[i]-'0')%p == 0) ans += i+1;
        cout << ans << endl;
        return 0;
    }

    ll sum = 0, count = 1;
    map<ll,ll> mp; mp[0]++;
    rrep(i,n){
        sum += count * (s[i]-'0'); sum %= p;
        mp[sum]++;
        count *= 10; count %= p;
    }
    ll ans = 0;
    for(auto v : mp) ans += v.second*(v.second-1)/2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4168
#include <stdlib.h>
#include <stdio.h>

int main(){
	int m, f, r;


	while(1){
		scanf("%d %d %d", &m, &f, &r);
		
		if((m == -1)&&(f == -1)&&(r==-1))
			break;
		else{
			if((m == -1)||(f == -1))
				printf("F\n");
			else if(m+f>=80)
				printf("A\n");
			else if(m+f>=65)
				printf("B\n");
			else if(m+f>=50)
				printf("C\n");
			else if(m+f>=30){
				if(r>=50)
					printf("C\n");
				else
					printf("D\n");
			}
			else
				printf("F\n");
		}
	}

	return 0;

}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); ++i)
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    if (n % 2 == 0)
        cout << n / 2 << endl;
    else
    {
        cout << n / 2 + 1 << endl;
    }

    return 0;
}

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

using namespace std;
typedef long long ll;
#define mp make_pair

ll Pow10[19];

ll solve(ll n, int k, bool fl) {
	if (k == 0) {
		if (n == 0)
			return 1;
		else
			return 0;
	}
	if (k == 1) {
		if (n == 0)
			return 10;
		else
			return 0;
	}
	int d = n % 10;
	d = -d + 10;
	if (d == 10)
		d = 0;
	n -= d * (Pow10[k - 1] - 1);
	n /= 10;
	//cout << d << " " << n << endl;
	if (n < 0)
		n = -n;
	ll res = solve(n, k - 2, true);
	ll coef = 9 - d;
	if (fl)
		coef++;
	return res * coef;
}

int main() {
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);	
	ll n;
	cin >> n;
	ll res = 0;
	Pow10[0] = 1;
	for (int i = 1; i < 19; i++)
		Pow10[i] = Pow10[i - 1] * 10;
	for (int i = 0; i <= 18; i++)
		res += solve(n, i, false);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
s = input()

diffBlackWhite = 0
diffWhiteBlack = 0
index = 0
for c in s:
  if index % 2 == 0:
    if c == '0':
      diffWhiteBlack += 1
    else:
      diffBlackWhite += 1
  else:
    if c == '0':
      diffBlackWhite += 1
    else:
      diffWhiteBlack += 1
  index += 1

print(min(diffBlackWhite, diffWhiteBlack))


Measured memory_bytes: 3316
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left
import random
from itertools import permutations, accumulate, combinations
import sys
import string


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 998244353



n, a, b, c, d = LI()
for add_cnt in range(n):
    subtract_cnt = n - 1 - add_cnt
    min_val = add_cnt * c - subtract_cnt * d
    max_val = add_cnt * d - subtract_cnt * c
    if min_val <= b - a <= max_val:
        print('YES')
        break
else:
    print('NO')



Measured memory_bytes: 41068
import std.stdio;
import std.conv;
import std.string;
import std.cstream;

void main(string args[]){
char[] inN;

while(true){

inN = din.readLine();
inN = chomp(inN);
int n = to!(int)(inN);

if(n == 0)break;

int val[5555];

for(int i;i<n;i++){
  inN = readln().dup;
  inN = chomp(inN);
  val[i] = to!(int)(inN);
}

auto sum=0;
int ans=-100000;

for(int i;i<n;i++){
  sum = 0;
  for(int j=i;j<n;j++){
    sum+=val[j];
    if(ans<=sum){
      ans=sum;
    }

    

  }
}

writeln(ans);

}

}

Measured memory_bytes: 1168
#include <stdio.h>
#include <stdlib.h>

int main()
{

    int i;
    long long m,n,t=0;
    scanf("%lld%lld",&n,&m);
    if(2*n>=m)
    {
        t+=m/2;
    }
    else
    {
        t+=n;
        m=m-2*n;
       t+=m/4;
    }
    printf("%lld\n",t);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a<b){
        
    }
    else{
        swap(a,b);
    }
    if(b<c){
        
    }
    else{
        swap(b,c);
    }
    if(a<b){
        
    }
    else{
        swap(a,b);
    }
    
    cout << a << " " << b << " " << c <<endl;
    
    return 0;
    
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int sum(int *,int);
bool check(int *,int);
int* next_add(int *,int,int);
int* next(int*,int);

int main() {
	int N = 0, a = 0, b = 0, c = 0;
	cin >> N >> a >> b >> c;
	int* l = new int[N];
	int* usefor = new int[N];
	for (int i = 0; i < N; i++)
	{
		cin >> l[i];
		usefor[i] = 1;
	}
	int output = INT32_MAX-1;

	while (true)
	{
		usefor = next(usefor,N);
		int summation = sum(usefor, N);
		if (summation == N * 4) break;
		if (check(usefor,N) == false) continue;

		int magic = 0;
		int A = 0, B = 0, C = 0;
		for (int i = 0; i < N; i++)
		{
			switch (usefor[i])
			{
			case 1:
				if (A != 0) magic = magic + 10;
				A += l[i];
				break;
			case 2:
				if (B != 0) magic = magic + 10;
				B += l[i];
				break;
			case 3:
				if (C != 0) magic=magic+10;
				C += l[i];
				break;

			}
		}
		magic += abs(A - a) + abs(B - b) + abs(C - c);
		if (magic < output) output = magic;



	}

	cout << output << endl;
	return 0;
}


int sum(int l[],int n)
{
	int len = n;
	int sum = 0;
	for (int i = 0; i < len; i++)
	{
		sum += l[i];
	}
	return sum;
}


bool check(int l[],int n)
{
	bool one = false, two = false, three = false;

	int len = n;
	
	for (int i = 0; i < len; i++)
	{
		switch (l[i])
		{
		case 1:
			one = true;
			break;
		case 2:
			two = true;
			break;
		case 3:
			three = true;
			break;
		}
	}
	return one && two && three;
}

int* next_add(int l[], int n)
{
	if (l[n] == 4) {
		l[n] = 1;
		return next_add(l, n - 1);
	}
	else
	{
		l[n] = l[n] + 1;
		return l;
	}
}

int* next(int l[],int n)
{
	int len = n;
	return next_add(l, len - 1);
}


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

const int N = 300004;
int cnth[N], cntw[N], x[N], y[N];
map <int, bool> mp[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int h, w, m;
    cin >> h >> w >> m;
    for (int i = 0; i < m; i++) {
        cin >> x[i] >> y[i];
        mp[x[i]][y[i]] = true;
        cnth[x[i]]++, cntw[y[i]]++;
    }
    int mxh = 0, mxw = 0;
    for (int i = 0; i < N; i++) {
        mxh = max(mxh, cnth[i]);
        mxw = max(mxw, cntw[i]);
    }
    vector <int> hall, wall;
    for (int i = 0; i < N; i++) {
        if (cnth[i] == mxh) {
            hall.push_back(i);
        }
        if (cntw[i] == mxw) {
            wall.push_back(i);
        }
    }
    int cnt = 0, mx = 0;
    for (int i = 0; i < hall.size(); i++) {
        for (int j = 0; j < wall.size(); j++) {
            cnt++;
            if (cnt > N * 2)
                break;
            mx = max(mx, mxh + mxw - mp[hall[i]][wall[j]]);
        }
        if (cnt > N * 2)
            break;
    }
    cout << mx;
}


Measured memory_bytes: 66616
const N: usize = 2e5 as usize;
const BIT: usize = 32;

fn main() {
    let mut s: Vec<String> = vec![];

    let mut memory = vec![0; N];
    memory[0] = 1;
    s.push_str("+ 0 1 3");
    s.push_str("+ 3 3 3");
    s.push_str("< 0 3 3");

    apply(&s, &mut memory);
    assert_eq!(memory[2], 0);
    assert_eq!(memory[3], 1);

    let prev = s.len();
    for i in 1..BIT {
        let k = i + 3;
        s.push(format!("+ {} {} {}", k - 1, k - 1, k));
    }
    apply(&s[prev..], &mut memory);
    assert_eq!(memory[4], 2);
    assert_eq!(memory[BIT + 2], 1u128 << (BIT - 1));

    for &(ab, offset) in [(0, BIT + 3), (1, BIT * 2 + 3)].iter() {
        let t1 = N - 1;
        let t2 = N - 2;
        let sum = N - 3;
        s.push(format!("< 3 2 {}", sum));
        for i in (0..BIT).rev() {
            let one = 3;
            let j = i + 3; // 2**i
            let pos = i + offset;
            s.push(format!("+ {} {} {}", ab, one, t1)); // t1 = a + 1
            s.push(format!("+ {} {} {}", sum, j, t2)); // t2 = sum + 2**i
            s.push(format!("< {} {} {}", t2, t1, pos)); // pos = (2**i < a-sum)

            for _ in 0..i {
                s.push(format!("+ {} {} {}", pos, pos, pos));
            }
            s.push(format!("+ {} {} {}", sum, pos, sum)); // sum += pos
            s.push(format!("< {} {} {}", t2, t1, pos)); // pos = (2**i < a-sum)
        }
    }

    // a:  74 ... 144
    // b: 145 ... 215

    for i in 0..BIT {
        for j in 0..BIT {
            let tmp = N - 1;
            let ans = 2;
            let bi = i + BIT + 3;
            let bj = j + BIT * 2 + 3;
            let one = 3;
            s.push(format!("+ {} {} {}", bi, bj, tmp)); // tmp = bit[i] + bit[j]
            s.push(format!("< {} {} {}", one, tmp, tmp)); // tmp = bit[i] & bit[j]

            for _ in 0..(i + j) {
                s.push(format!("+ {} {} {}", tmp, tmp, tmp));
            }
            s.push(format!("+ {} {} {}", ans, tmp, ans));
        }
    }

    validate(&s, 3, 4);
    println!("{}", s.len());
    for s in s.iter() {
        println!("{}", s);
    }
}

trait PushStr {
    fn push_str(&mut self, s: &str);
}

impl PushStr for Vec<String> {
    fn push_str(&mut self, s: &str) {
        self.push(s.to_string());
    }
}

fn apply(s: &[String], memory: &mut [u128]) {
    for s in s.iter() {
        let s = s.split(" ").collect::<Vec<_>>();
        let i = s[1].parse::<usize>().unwrap();
        let j = s[2].parse::<usize>().unwrap();
        let k = s[3].parse::<usize>().unwrap();
        match s[0] {
            "+" => {
                memory[k] = memory[i] + memory[j];
            }
            "<" => {
                if memory[i] < memory[j] {
                    memory[k] = 1;
                } else {
                    memory[k] = 0;
                }
            }
            _ => unreachable!(),
        }
    }
}

fn validate(s: &[String], a: u128, b: u128) {
    let mut memory = vec![0; N];
    memory[0] = a;
    memory[1] = b;

    apply(s, &mut memory);

    assert_eq!(memory[2], a * b, "{:?}", &memory[0..100]);
}


Measured memory_bytes: 4624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
typedef pair<int,int>pii;
const int mxN=1e5+10,M=1e9+7;
int n,m,ans,cnt;
int x,y,z;
vector<int>adj[mxN];
int vis[mxN];
bool comp(int a,int b){
    return sz(adj[a])>sz(adj[b]);
}
void bfs(int x){
    vis[x]=true;
    queue<int>fila;
    fila.push(x);
    while(!fila.empty()){
        int u=fila.front();
        fila.pop();
        //cout<<u<<"\n";
        for(int v:adj[u]){            
            if(!vis[v]){
                vis[v]=true;
                cnt++;
                fila.push(v);
            }
        }
    }
}
// LONG LONG CASE
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    vector<int>v;
    for(int i=0;i<m;i++){
        cin>>x>>y>>z;
        adj[x].pb(y);
        adj[y].pb(x);
    }    
    for(int i=1;i<=n;i++){
        v.pb(i);
    }
    sort(v.begin(),v.end(),comp);
    for(int i=0;i<n;i++){
        if(cnt>=n)break;
        if(!vis[v[i]])ans++;
        bfs(v[i]);

    }    
    cout<<ans;


}

Measured memory_bytes: 7288
# include <stdio.h>

int dfs(int n){
    int m_1, m_2;

    if (n == 0)
        return 1;
    else if (n < 0)
        return 0;

    m_1 = dfs(n-4);
    m_2 = dfs(n-7);

    if (m_1 == 1 || m_2 == 1)
        return 1;
    else
        return 0;
}

int main(){
    int N;

    scanf("%d", &N);

    if (dfs(N) == 1)
        printf("Yes");
    else
        printf("No");

    return 0;
}


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

int main(){
  int X;
  scanf("%d", &X);
  if(X==3) printf("%s","YES");
  else if(X==5) printf("%s","YES");
    else if(X==7) printf("%s","YES");
      else printf("%s","NO");
  
    }


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<functional>
#include<cstring>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;
int main(void)
{
	int n,m,a[101];
	int i,j;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++) {
		scanf("%d",&a[i]);
	}
	for(i=1;i<=m;i++) {
		for(j=1;j<n;j++) {
			if(a[j]%i>a[j+1]%i) swap(a[j],a[j+1]);
		}
	}
	for(i=1;i<=n;i++) printf("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

void print(vector<int> &v){
    for(int i=1; i<v.size(); i++){
        if(i != 1) cout << " ";
        cout << v[i];
    }
    cout << endl;
}

int main(){
    int N; cin >> N;
    vector<int> p(N+1);
    for(int i=1; i<=N; i++) cin >> p[i];
    vector<int> a(N+1), b(N+1);
    int k = 50000;
    for(int i=1; i<=N; i++){
        a[i] = i*k;
        b[i] = (N+1-i)*k;
    }

    for(int i=1; i<=N; i++) b[p[i]] -= (N-i);

    print(a);
    print(b);
}

Measured memory_bytes: 896
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
  
#define mp make_pair
#define f first
#define s second
#define ll long long
#define pb push_back
#define popb pop_back
#define popf pop_front

using namespace std;

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int inf = 2e9+7, mod=1e9+7;
const int N = 1e6+321, E=14e5;

ll xx[8]={1, 1, -1, -1, 1, -1, 0, 0};
ll yy[8]={1, -1, 1, -1, 0, 0, 1, -1};

string s[10];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	int n, m;
	cin >> n >> m;
	if(n*2<=m && n*4>=m && m%2==0)
		cout << "Yes";
	else
		cout << "No";
    return 0;
}

Measured memory_bytes: 3660
#include<stdio.h>
 
int main(){
    int w,h,n;
    scanf("%d%d%d",&w,&h,&n);
    int right=w;
    int left=0;
    int up=h;
    int down=0;
    int x[n],y[n],a[n];
    for(int i=0;i<n;i++){
        scanf("%d%d%d",&x[i],&y[i],&a[i]);
        if(a[i]==1){
            if(x[i]>left){
                left=x[i];
            }
        }else if(a[i]==2){
            if(right>x[i]){
                right=x[i];
            }
        }else if(a[i]==3){
            if(y[i]>down){
                down=y[i];
            }
        }else if(a[i]==4){
            if(up>y[i]){ 
                up=y[i];
            }
        }
    }
    if(left>right||down>up){
        printf("0\n");
    }else{
        printf("%d\n",(right-left)*(up-down));
    }
    return 0;
}

Measured memory_bytes: 1732
n,m,q=map(int,input().split())
a,b=[],[]
c,d=[],[]
for i in range(q):
  aa,bb,cc,dd=map(int,input().split())
  a.append(aa-1)
  b.append(bb-1)
  c.append(cc)
  d.append(dd)
l=[int(i) for i in range(1,m+1)]
from itertools import combinations_with_replacement
ans=0
for ll in list(combinations_with_replacement(l,n)):
  t=0
  for i in range(q):
    if ll[b[i]]-ll[a[i]]==c[i]:
      t+=d[i]
  ans=max(ans,t)
print(ans)

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

typedef long long ll;

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  if((b-a)%2==1)cout<<"Borys"<<endl;
  else cout<<"Alice"<<endl;
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = Array.new(n){Array.new(n, 2)}
n.times do |i|
  m = gets.to_i
  m.times do
    x, y = gets.split.map(&:to_i)
    a[i][x - 1] = y
  end
end
max = 0
[0, 1].repeated_permutation(n) do |x|
  f = true
  n.times do |i|
    next if x[i] == 0
    n.times do |j|
      next if a[i][j] == 2
      if a[i][j] != x[j]
        f = false
        break
      end
    end
    break unless f
  end
  max = x.sum if f && max < x.sum
end
puts max

Measured memory_bytes: 14708
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    // 80*80*abs(80) = 512000
    int n, m;
    cin >> n >> m;
    vector<vector<int>> grid(n, vector<int>(m, 0));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++)
            cin >> grid[i][j];
    }
    int tmp;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> tmp;
            grid[i][j] = abs(grid[i][j] - tmp);
            // acc += grid[i][j];
        }
    }
    // calculate maxpath
    vector<vector<int>> dp0(n+1, vector<int>(m+1, 0));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            dp0[i+1][j+1] = max(dp0[i+1][j], dp0[i][j+1]) + grid[i][j];
        }
    }
    int acc = dp0[n][m];
    vector<vector<vector<bool>>> dp(n+1, vector<vector<bool>>(m+1, vector<bool>(acc+1, false)));
    // dp[1][1][grid[0][0]] = true;
    // printf("acc = %d\n", acc);
    dp[1][1][grid[0][0]] = true;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            for(int k = 0; k <= acc; k++) {
                for(int val: {k-grid[i][j], k+grid[i][j]}) {
                    if (val > acc) continue;
                    if (val < 0) val *= -1;
                    dp[i+1][j+1][val] = dp[i+1][j+1][val] | dp[i+1][j][k];
                    dp[i+1][j+1][val] = dp[i+1][j+1][val] | dp[i][j+1][k];
                }
            }
        }
    }
    for(int k = 0; k <= acc; k++) {
        if (dp[n][m][k] == true) {
            cout << k << endl;
            return 0;
        }
    }
    return 0;
}




Measured memory_bytes: 13056
from collections import defaultdict
import heapq

N,M = map(int,input().split())

l = defaultdict(list)
for i in range(N):
    A,B = map(int,input().split())
    l[A].append(-B)

h = []
ans = 0
for i in range(M):
    for B in l[i+1]:
        heapq.heappush(h,B)
    if len(h)!=0:
        ans += - heapq.heappop(h)
print(ans)


Measured memory_bytes: 27676
#include <bits/stdc++.h>
using namespace std;
# define ll long long
struct node
{
    int a,b,c;
};
node arr[100005];
int n;
vector <vector<int> > v(4,vector<int> (100005,-1));
int calc(int i,int last)
{
    if(last!=-1){
    if(v[last][i]!=-1)
        return v[last][i];}
    if(i>=n)
        return 0;
    int z1,z2,z3;
    z1=z3=z2=INT_MIN;
    if(last!=0)
        z1=arr[i].a+calc(i+1,0);
    if(last!=1)
        z2=arr[i].b+calc(i+1,1);
    if(last!=2)
        z3=arr[i].c+calc(i+1,2);
    z1=max(z1,max(z2,z3));
    if(last!=-1)
        v[last][i]=z1;
    //ans[i]=z1;
    return z1;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr[i].a>>arr[i].b>>arr[i].c;
//    memset(ans,-1,sizeof(ans));
    cout<<calc(0,-1);
    //code goes here
	return 0;
}



Measured memory_bytes: 9208
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let m: usize = sc.read();
    let x: usize = sc.read();
    let a: Vec<usize> = sc.vec::<usize>(m);


    let mut result = 1 << 30;
    {
        //for zero
        let mut pos = x;
        let mut sum = 0;
        while pos != 0 {
            pos = pos - 1;
            for v in &a {
                if pos == *v {
                    sum += 1;
                }
            }
        }
        result = std::cmp::min(result, sum);
    }
    {
        //for N
        let mut pos = x;
        let mut sum = 0;
        while pos != n{
            pos = pos + 1;
            for v in &a {
                if pos == *v {
                    sum += 1;
                }
            }
        }
        result = std::cmp::min(result, sum);
    }
    println!("{}", result);
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
// JOI2017年予選５　尾根
// http://j...content-available-to-author-only...c.jp/onlinejudge/description.jsp?id=0634
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    int H,W;
    cin >> H >>W;
    int map[H+2][W+2];
    int onecheck[H+2][W+2];
    for(int i=0;i<H+2;i++){
        for(int j=0;j<W+2;j++){
            map[i][j]=H*W+1;
            onecheck[i][j]=0;
        }
    }
    for(int i=1;i<H+1;i++){
        for(int j=1;j<W+1;j++){
            cin >> map[i][j];
        }
    }
    // 水たまりを探す
    vector<pair<int,int> > mizutamari;
    for(int i=1;i<H+1;i++){
        for(int j=1;j<W+1;j++){
            if(map[i][j]<map[i+1][j] && map[i][j]<map[i-1][j] && map[i][j]<map[i][j+1] && map[i][j]<map[i][j-1])mizutamari.push_back(make_pair(i,j));
        }
    }
    // 各水たまりに流れ込むエリアを探す
    for(int k=0;k<mizutamari.size();k++){
        queue<pair<int, int> >q;// キュー q を定義
        q.push(make_pair(mizutamari[k].first,mizutamari[k].second));//スタート地点をqにプッシュ
        int step[H+2][W+2];
        for(int i=0;i<H+2;i++){
            for(int j=0;j<W+2;j++){
                step[i][j]=0;
            }
        }
        while(q.empty()==false){// q が空になるまでループを回す
            pair<int, int> point=q.front();
            q.pop();
            int i=point.first;
            int j=point.second;
            //onecheck[][]<2 のチェックを入れておかないと、余計な計算がかなり増えて、AOJで「Runtime Error」がでる。
            if(map[i][j]<map[i+1][j] && step[i+1][j]==0 && onecheck[i+1][j]<2){step[i+1][j]=1;onecheck[i+1][j]++;q.push(make_pair(i+1,j));}
            if(map[i][j]<map[i-1][j] && step[i-1][j]==0 && onecheck[i-1][j]<2){step[i-1][j]=1;onecheck[i-1][j]++;q.push(make_pair(i-1,j));}
            if(map[i][j]<map[i][j+1] && step[i][j+1]==0 && onecheck[i][j+1]<2){step[i][j+1]=1;onecheck[i][j+1]++;q.push(make_pair(i,j+1));}
            if(map[i][j]<map[i][j-1] && step[i][j-1]==0 && onecheck[i][j-1]<2){step[i][j-1]=1;onecheck[i][j-1]++;q.push(make_pair(i,j-1));}
        }
    }
    int count=0;
    for(int i=1;i<H+1;i++){
        for(int j=1;j<W+1;j++){
            if(onecheck[i][j]>1)count++;
        }
    }
    cout << count << endl;
    return 0;
}


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

int main()
{

	int N;
	int A[100];
	int key;
	int j;
	cin >> N;
	if (N <= 0 || N > 100)return 0;
	for (int i = 0; i<N; i++) {
		cin >> A[i];
	}
	for (int i = 1; i <= N - 1; i++) {
		for (int m = 0; m<N-1; m++) {
			cout << A[m] << " ";
		}
		cout<<A[N-1]<< endl;
		key = A[i];
		j = i - 1;
		while (j >= 0 && A[j]>key) {
			A[j + 1] = A[j];
			A[j] = key;
			j--;
		}
	}
	for (int m = 0; m<N - 1; m++) {
		cout << A[m] << " ";
	}
	cout << A[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 1160
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)
ar=a.dup.reverse
br=b.dup.reverse
def solve(a,b,n)
  ans = 0
  n.times do |i|
    if a[i] > b[i]
      ans += b[i]
    else
      ans += a[i]
      b[i] -= a[i]
      if a[i+1] > b[i]
        ans += b[i]
        a[i+1] -= b[i]
      else
        ans += a[i+1]
        a[i+1] = 0
      end
    end
  end
  ans
end

puts [solve(a,b,n), solve(ar, br, n)].max
#puts solve(a,b,n)


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

using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> l(n*2);
  for (int i = 0; i < n*2; i++){
    cin >> l[i];
  }
  sort(l.begin(), l.end());
  int sum = 0;
  for (int i = 0; i < n; i++){
    sum += l[i*2];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> a(n + 1, x), b(m + 1, y);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for(int i = 1; i <= m; i++) {
        cin >> b[i];
    }
    cout << (*max_element(a.begin(), a.end()) < *min_element(b.begin(), b.end()) ? "No War" : "War") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.rbegin(), a.rend());
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      ans += a[i];
    } else {
      ans -= a[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
n,m = map(int,input().split())
if n == 1:
    if m == 1:
        print(0)
    else:
        print(int(m*(m-1)/2))
else:
    if m == 1:
        print(int(n*(n-1)/2))
    else:
        print(int((n*(n-1)+m*(m-1))/2))
    

Measured memory_bytes: 2940
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

#define loop(lp) for(int lp2 = 0; lp2 < lp; lp2 ++) 
#define ascent(i,a,b) for(int i = a; i < b; i ++)

#define pb push_back

using namespace std;

string list = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  int n;
  while(cin >> n, n) {
    vector<int> k;
    loop(n) {
      int tmp;
      cin >> tmp;
      k.pb(tmp);
    }

    string s;
    cin >> s;

    // A = 65,Z =  91
    // a = 97,z = 123;
    
    int cnt = 0;
    ascent(i, 0, s.length()) {
      int c;
      if('A' <= s[i] && s[i] <= 'Z') {
	c = 26 + s[i] - 'A';
      }
      else if('a' <= s[i] && s[i] <= 'z') {
	c = s[i] - 'a';
      }
    
      //   cout << " " << c << " " << k[cnt%n] << " " << list[(52 + c-k[cnt%n])%52] << endl;
      s[i] = list[(52 + c-k[cnt%n])%52];
      cnt ++;
    }

    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 1232
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;

#define fi first
#define se second
#define mp make_pair

int w, h, n;

class Node
{public:
	int st, ed;
	int mx;
	int laz;
	Node *l, *r;
	
	Node(){}
	Node(int st, int ed, Node *l, Node *r):st(st), ed(ed), l(l), r(r), mx(-10101010), laz(0){}
	
	
	void change(int v)
	{
		laz += v;
		mx += v;
	}
	void down()
	{
		if(laz)
		{
			l->change(laz);
			r->change(laz);
			laz = 0;
		}
	}
	void update()
	{
		mx = max(l->mx, r->mx);
	}
};

Node *build(int st, int ed)
{
	if(st == ed)
		return new Node(st, ed, 0, 0);
	int mid = st + ed;
	mid>>=1;
	Node *l = build(st, mid);
	Node *r = build(mid + 1, ed);
	return new Node(st, ed, l, r);
}

void change(Node *now, int st, int ed, int v)
{
	if(now->st >= st && now->ed <= ed)
	{
		now->mx += v;
		now->laz += v;
		return;
	}
	now->down();
	if(now->l->ed >= st)
		change(now->l, st, ed, v);
	if(now->r->st <= ed)
		change(now->r, st, ed, v);
	now->update();
}

void set(Node *now, int st, int ed, int v)
{
	if(now->st >= st && now->ed <= ed)
	{
		now->mx = v;
		now->laz = 0;
		return;
	}
	now->down();
	if(now->l->ed >= st)
		set(now->l, st, ed, v);
	if(now->r->st <= ed)
		set(now->r, st, ed, v);
	now->update();
}

class Point
{public:
	int x, y;
}a[301010];

bool cmpx(const Point &a, const Point &b)
{
	if(a.y != b.y)
		return a.y < b.y;	
	return a.x < b.x;
}

int ans;
pair<pair<int,int>,int> stk1[301010], stk2[301010];

void solve()
{
	Node *root = build(1, n);
	int t1, t2 = t1 = 0;
	for(int i = 1; i <= n; ++i)
	{
		if(i > 1)
			ans = max(ans, root->mx + a[i].y);
		if(a[i].x <= w>>1)
		{
			int cur = (w>>1) - a[i].x, low = -1;
			while(t1 && stk1[t1].se > cur)
			{
				change(root, stk1[t1].fi.fi, stk1[t1].fi.se, -(stk1[t1].se - cur));
				low = stk1[t1].fi.fi;
				--t1;
			}
			if(low > -1)
			{
				stk1[++t1] = mp(mp(low, i - 1), cur);
			}
		}
		if(a[i].x >= w>>1)
		{
			int cur = a[i].x - (w>>1), low = -1;
			while(t2 && stk2[t2].se > cur)
			{
				change(root, stk2[t2].fi.fi, stk2[t2].fi.se, -(stk2[t2].se - cur));
				low = stk2[t2].fi.fi;
				--t2;
			}
			if(low > -1)
			{
				stk2[++t2] = mp(mp(low, i - 1), cur);
			}
		}
		stk1[++t1] = mp(mp(i, i), w / 2);
		stk2[++t2] = mp(mp(i, i), w - w / 2);
		set(root, i, i, w - a[i].y);
	}
}

int main()
{
	scanf("%d%d%d", &w, &h, &n);
	ans = max(w, h) + 1;
	for(int i = 1; i <= n; ++i)
		scanf("%d%d", &a[i].x, &a[i].y);
	a[++n].x = a[n].y = 0;
	a[++n].x = w;
	a[n].y = 0;
	a[++n].x = 0;
	a[n].y =h;
	a[++n].x = w;
	a[n].y = h;
	sort(a + 1, a + n + 1, cmpx);
	solve();
	for(int i = 1; i <= n; ++i)
		swap(a[i].x, a[i].y);
	sort(a + 1, a + n + 1, cmpx);
	swap(w, h);
	solve();
	printf("%d\n", ans<<1);
	
	return 0;
}


Measured memory_bytes: 65280
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<vector<int>> A(2, vector<int>(N));
	for (int i = 0; i < 2; ++ i) for (int j = 0; j < N; ++ j) {
		cin >> A[i][j];
	}
	int r = 0;
	for (int k = 0; k < N; ++ k) {
		int rr = 0;
		for (int j = 0; j <= k; ++ j) rr += A[0][j];
		for (int j = k; j < N; ++ j) rr += A[1][j];
		r = max(r, rr);
	}
	cout << r << endl;
}


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

int gcd(int a, int b)
{
  if(a < b) return gcd(b, a);

  if(b == 0) return a;

  return gcd(b, a%b);
}

int main()
{
  int n, x[100001];
  cin >> n >> x[0];
  for(int i = 1; i <= n; i++){
    cin >> x[i];
  }

  sort(x, x+n+1);

  int d[100000];
  for(int i = 0; i < n; i++){
    d[i] = x[i+1] - x[i];
  }
   
  int ans = d[0];
  for(int i = 1; i < n; i++){
    ans = gcd(d[i], ans);
  }

  cout << ans << endl;

  return 0;
}


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

int main()
{
	string n;

	cin >> n;

	if( n[0] == '9' || n[1] == '9' ) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
BIG = 10**9 + 7

def sumpp(n,a):
    acc = 0
    tmp = 0
    sumv = sum(a)
    for i in range(n):
        tmp += a[i]
        acc += a[i] * (sumv - tmp)
    return acc % BIG

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    print(sumpp(n,a))


Measured memory_bytes: 31532
# coding: utf-8
H,W,K=map(int,input().split())

ans=0

M=[]

yoko=[0 for i in range(H)]
tate=[0 for i in range(W)]

for i in range(H):
    l=list(input())
    cnt=0
    for j in range(W):
        if l[j]=="#":
            cnt+=1
    M.append(l)
    yoko[i]=cnt

for i in range(W):
    cnt=0
    for j in range(H):
        if M[j][i]=="#":
            cnt+=1
    tate[i]=cnt

B=sum(yoko)

for i in range(2**H):
    for j in range(2**W):
        num=B
        y=[]
        t=[]
        for a in range(H):
            if i>>a&1:
                num-=yoko[a]
                y.append(a)
                
        for b in range(W):
            if j>>b&1:
                num-=tate[b]
                t.append(b)
        
        for a in range(len(y)):
            for b in range(len(t)):
                if M[y[a]][t[b]]=="#":
                    num+=1
        if num==K:
            ans+=1

print(ans)

Measured memory_bytes: 9188
import java.util.Scanner;

public class Main {

	public static int computeMaxProfit(int n, int[] rates) {
		int maxProfit = -100000;
		for (int i = 0; i < n-1; i++) {
			for (int j = i+1; j < n; j++) {
				if (rates[j] -rates[i] > maxProfit) {
					maxProfit = rates[j] -rates[i];
				}
			}
		}
		return maxProfit;
	}
	
	public static int computeMaxProfitDP(int[] rates) {
		int min = rates[0];
		
		
		int maxProfit[] = new int [rates.length];
//		maxProfit[0] = rates[0];
		maxProfit[1] = rates[1] -min;
		if (min> rates[1]) {
			min = rates[1];
		}
		for (int i = 2; i< rates.length; i++) {
			maxProfit[i] = Math.max(maxProfit[i-1], rates[i] - min);
			
			if (min >rates[i]) {
				min = rates[i];
			}
		}
		return maxProfit[rates.length-1];
			
				
//			if (rates[i] < min[i]) {
//				min[i] = rates[i];
//				maxProfit[i] = rates[i]- min[i];
//			}
//		
//			
//			
//			maxProfit[i] = Math.max(maxProfit[i-1], rates[i]-min);
		
	}
	public static void main(String[] args) {
//		int rates[] = {5,3,1,3,4,3};
//		System.out.println(computeMaxProfit(6, rates));	
//		System.out.println(computeMaxProfitDP(rates));
		
		
		
		Scanner scan = new Scanner(System.in);
		int count = scan.nextInt();
		int arr[] = new int [count];

		for(int i = 0; i<count; i++) {
			arr[i] = scan.nextInt();
		}

		System.out.println(computeMaxProfitDP(arr));
	}

}



Measured memory_bytes: 101128
#include <stdio.h>

int main(void)
{
	char a[8], b[8];

	while (scanf("%s %s", a, b), atoi(a) + atoi(b)){
		int i, j;
		int ab[16] = {}, bb[16] = {};
		int hit, blow;

		hit = blow = 0;
		for (i = 0; i < 4; i++){
			ab[a[i] - '0'] = bb[b[i] - '0'] = 1;
			if (a[i] == b[i]) hit++;
		}
		for (i = 0; i <= 9; i++){
			ab[i] + bb[i] == 2 && blow++;
		}
		blow -= hit;

		printf("%d %d\n", hit, blow);
	}

	return (0);
}

Measured memory_bytes: 548