akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
	public static void main (String[] args) {
	   InputReader in = new InputReader(System.in);
	   int n = in.readInt();
	   int arr[] = new int[n]; 
	   int sum = 0; 
	   for(int i = 0; i<n; i++) {
		   arr[i] = in.readInt();
		   sum += arr[i]; 
	   }
	   Arrays.sort(arr);
	   if(sum % 10 != 0) {
		   System.out.println(sum); 
		   return; 
	   }
	   int result = 0; 
	   for(int i = 0; i<n; i++) {
		   if((sum - arr[i])%10 != 0) {
			   result = sum - arr[i];  
			   break;
		   }
	   }
	   System.out.println(result);
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vl p(a), q(b), r(c);
    rep(i, a) cin >> p[i];
    rep(i, b) cin >> q[i];
    rep(i, c) cin >> r[i];
    ll sum = 0;
    sort(rall(r));
    priority_queue<ll, vector<ll>, greater<ll> > que;
    rep(i, min(c, x+y)) {
        que.push(r[i]);
        sum += r[i];
    }
    ll ma = x + y;
    ll lim[2] = {x, y};
    ll cnt[2] = {};
    priority_queue<pii> que2;
    rep(i, a) que2.push({p[i], 0});
    rep(i, b) que2.push({q[i], 1});
    ll ans = sum;
    while(!que2.empty()) {
        auto p = que2.top(); que2.pop();
        if(cnt[0]+cnt[1]+(int)que.size() < ma) {
            if(cnt[p.se] <lim[p.se]) {
                cnt[p.se]++;
                ans += p.fi;
            }
        }
        else{
            if(cnt[p.se] < lim[p.se] && que.size() > 0 && que.top() < p.fi) {
                cnt[p.se]++;
                ans += p.fi - que.top();
                que.pop();
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 5620
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;

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

	vector < pair <int, pair <int, int > > > vp;

	for (int i = 0; i < N; ++i)
	{
		int s, t, x;
		cin >> s >> t >> x;

		vp.push_back(make_pair(x, make_pair(s, t)));
	}

	sort(vp.begin(), vp.end());

	vector <int> d(Q);
	map <int, int> hit;
	for (int i = 0; i < Q; ++i)
	{
		cin >> d[i];
		hit[d[i]] = NG;
	}


	for ( const auto& p : vp)
	{
		const int x = p.first;
		const int s = p.second.first;
		const int t = p.second.second;

		int lo = lower_bound(d.begin(), d.end(), s-x) - d.begin();
		int hi = lower_bound(d.begin(), d.end(), t-x) - d.begin();

		for (int i=lo;i<hi;++i)
		{
			if (hit[d[i]] == NG)
			{
				hit[d[i]] = x;
			}
		}

		d.erase(d.begin() + lo, d.begin() + hi);
	}

	for (const auto& a : hit)
	{
		cout << a.second << endl;
	}



	return 0;
}


Measured memory_bytes: 14704
#include<cstdio>
#include<algorithm>
using namespace std;
int gcd(int a,int b)
 {
     if(a==b) return a;
     if((a&1)==0)
     {
         if((b&1)==0)
             return gcd(a>>1,b>>1)<<1;
         else
             return gcd(a>>1,b);
     }
     else
     {
         if((b&1)==0)
             return gcd(a,b>>1);
         else
             return gcd(((a>b)?(a-b):(b-a))>>1,(a+b)>>1);
     }
  }
int main()
{
	int n, k, min1 = 1, flag = 0, max1;
	scanf("%d %d", &n, &k);
	int a[n];
	scanf("%d", &a[0]);
	max1 = min1 = a[0];
	for(int i = 1; i < n; i++)
	{
		scanf("%d", &a[i]);
		min1 = gcd(gcd(a[i], a[i - 1]), min1);
		max1 = max(max1, a[i]);
	}
	for(int i = 0; i < n; i++)
	{
		if(a[i] % min1 != 0)    min1 = 1;
	}
	if(max1 >= k && k % min1 == 0)  printf("POSSIBLE\n");
	else    printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 512
def main():
    M,D=map(int, input().split())
    ans=0
    for m in range(1, M+1):
        for d in range(20, D+1):
            sd = str(d)
            d1=int(sd[-1])
            d10=int(sd[-2])
            if d1>=2 and d10>=2 and d1 * d10 == m:
                ans+=1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 40432
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::min;
using std::max;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long

inline int nextInt()
{
    int x = 0;
    char c = getchar();
    int mi = (c == '-');
    if (c == '-') c = getchar();
    while ('0' <= c && c <= '9')
    {
        x = 10 * x + c - '0';
        c = getchar();
    }
    if (mi) return x * -1;
    return x;
}

int n, m, d, q;
int posi[100000], posj[100000];
ll summ[101000];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> d;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            int a;
            cin >> a;
            posi[a] = i;
            posj[a] = j;
        }
    }
    for (int i = d + 1; i <= n * m; i++)
    {
        summ[i] = summ[i - d] + abs(posi[i] - posi[i - d]) + abs(posj[i] - posj[i - d]);
    }
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int l, r;
        cin >> l >> r;
        //cout << summ[r] << " " << summ[l] << endl;
        cout << summ[r] - summ[l] << "\n";
    }
}

Measured memory_bytes: 3200
import sys
fin = sys.stdin.readline

N = int(fin())
A_list = [int(elem) for elem in fin().split()]
B_list = [int(elem) for elem in fin().split()]

if sum(B_list) > sum(A_list):
    print(-1)
    exit(0)


surplus_list = []
debt_sum = 0
num_changed = 0
for i, (A, B) in enumerate(zip(A_list, B_list)):
    if A - B < 0:
        debt_sum += B - A
        num_changed += 1
    elif A - B > 0:
        surplus_list.append(A - B)

surplus_list.sort(reverse=True)
cur_sum_surplus = 0
for surplus in surplus_list:
    if cur_sum_surplus >= debt_sum:
        break
    else:
        cur_sum_surplus += surplus
        num_changed += 1
print(num_changed)


Measured memory_bytes: 74160
n = int(input())
xyh = [list(map(int, input().split())) for _ in range(n)]

for cx in range(101):
    for cy in range(101):
        for k in range(n):
            x, y, h = xyh[k]
            if h:
                H = h + abs(x - cx) + abs(y - cy)
                break

        ans = True
        for k in range(n):
            x, y, h = xyh[k]
            if h != max(H - abs(x - cx) - abs(y - cy), 0):
                ans = False
                break
        if ans:
            print(cx, cy, H)
            exit()


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>

#define ll long long
using namespace std;

vector<ll> a;
ll getDigit(ll n){
    
    if(n==0){
        return 0;
    }
    
    return getDigit(n/10)+1;
}

ll dfs(ll i,ll b,ll s){
    ll r1,r2;
    if(i==a.size()-1){
        //cout<<"s : "<<s+a[i]<<endl;
        return s+a[i];
    }else{
        r1=dfs(i+1,0,s+a[i]);
        r2=dfs(i+1,10*b+10*a[i],10*b+10*a[i]+s-b);

        //cout<<r1+r2<<endl;
        return r1+r2;        
    }
}

int main(){
    ll n,dig;
    cin>>n;

    dig=getDigit(n);
    //cout<<dig<<endl;
    a.resize(dig);
    for(ll i=0; i<dig; i++){
        a[i]=n%10;
        n/=10;
        //cout<<i<<endl;
    }
    reverse(a.begin(),a.end());
/*
    for(auto m: a){
        cout<<m<<" ";
    }cout<<endl;
*/
    cout<<dfs(0,0,0)<<endl;

    return 0;
    
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
#include <numeric>
#include <queue>
#include <sstream>
using namespace std;
using LLI = long long int;

#define Rep(i, N) for (int i = 0; i < N; i++)

int main(int argc, char *argv[])
{
    string S;
    cin >> S;

    int len = S.size();

    int a = 1000;
    for (int i=0; i<len-2; i++) {
        stringstream ss;
        ss << S.substr(i, 3);;
        int tmp;
        ss >> tmp;
        a = abs(tmp - 753) < a ? abs(tmp - 753) : a;
    }

    cout << a << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	while (1) {
		int M, Nmin, Nmax; cin >> M >> Nmin >> Nmax;
		if (!M)break;
		vector<int>vs(M);
		for (int i = 0; i < M; ++i)cin >> vs[i];
		sort(vs.begin(), vs.end(), greater<int>());
		int ans = 0;
		int num = -1;
		for (int i = Nmax-1; i >= Nmin-1; --i) {
			int n = vs[i] - vs[i + 1];
			if (n > num) {
				ans = i;
				num = n;
			}
		}
		cout << ans+1 << endl;
	}
	
	return 0;
}

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

    using namespace std;
    template <typename T>
    void debug(string t, T input) {
        cout<<t<<"-> "<<input<<"\n";
    }
    template <typename T>
    void debug(int i,string t, T input) {
        cout<<"Case#"<<i<<" "<<t<<"-> "<<input<<"\n";
    }


    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int n;
        cin>>n;
        string s;
        cin>>s;
        long long r=0,b=0,g=0;
        for(int i=0;i<n;i++){
            if(s[i]=='R')
                r++;
            if(s[i]=='G')
                g++;
            if(s[i]=='B')
                b++;
        }
        long long total=r*g*b;
        int rgb=(int)('R') + (int)('G') + (int)('B');
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                int k=2*j-i;
                if(k<n)
                    if((int)s[i]+(int)s[j]+(int)s[k] == rgb)
                    total--;
            }
        }
        cout<<total;
        return 0;
    }


Measured memory_bytes: 3668
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  using namespace chrono_literals;
  chrono::high_resolution_clock clock;
  auto be = clock.now();
  int D;
  cin >> D;
  array<int, 26> c;
  for (auto& e : c) cin >> e;
  vector<array<int, 26>> d(D);
  for (auto& r : d)
    for (auto& e : r) cin >> e;
  auto eval = [&](vector<int> t) {
    int S = 0;
    array<int, 26> last = {};
    for (int i = 0; i < D; ++i) {
      S += d[i][t[i]];
      last[t[i]] = i + 1;
      for (int j = 0; j < 26; ++j) S -= c[j] * (i + 1 - last[j]);
    }
    return S;
  };
  mt19937 mt(random_device{}());
  uniform_int_distribution<int> dist_type(0, 25), dist_day(0, D - 1);
  vector<int> t(D);
  for (int i = 0; i < D; ++i) t[i] = i % 26;
  int S = eval(t);
  while (clock.now() - be < 1950ms) {
    int day = dist_day(mt);
    int prv = t[day];
    t[day] = dist_type(mt);
    int score = eval(t);
    if (score > S) {
      S = score;
      continue;
    }
    t[day] = prv;
  }
  for (const auto& e : t) cout << (e + 1) << '\n';
}


Measured memory_bytes: 3660
n,a,b=map(int,input().split())
total=0
i=1
while i in range(1,n+1):
   l=list(str(i))
   ll=[int(s) for s in l]
   if a<=sum(ll)<=b:
        total+=i
        i+=1
   else:
           i=i+1
else:
    print(total)


Measured memory_bytes: 42732
local mfl = math.floor

local n, k = io.read("*n", "*n", "*l")
local t = {}
local str = io.read()
for s in str:gmatch("(-?%d+)") do
  table.insert(t, tonumber(s))
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local mmi = math.min
  local function solve(x)
    x = -x
    local cnt = 0
    local right = #plus
    local curj = #plus
    for i = 1, #minus do
      local dst = x / minus[i]
      if x % minus[i] ~= 0 then dst = dst + 1 end
      local z = #plus + 1
      for j = curj, 1, -1 do
        if dst <= plus[j] then
          z = j
        else break end
      end
      curj = mmi(#plus, z)
      cnt = cnt + (#plus + 1 - z)
      if z == 1 then
        cnt = cnt + (#minus - i) * #plus
        break
      else
        right = mmi(z, #plus)
      end
    end
    return cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    local r = solve(mid)
    if k <= r then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    local right = #minus
    local curj = #minus
    for i = 1, #minus - 1 do
      local dst = x / minus[i]
      local z = curj + 1
      for j = curj, i + 1, -1 do
        if dst < minus[j] then
          z = j
        else
          break
        end
      end
      curj = mmi(#minus, z)
      z = z - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
    end
    right = #plus
    curj = #plus
    for i = 1, #plus - 1 do
      local z = 0
      if plus[i] == 0 then
        if x < 0 then
          z = i
        else
          z = right
        end
      else
        local dst = x / plus[i]
        z = curj + 1
        for j = curj, i + 1, -1 do
          if dst < plus[j] then
            z = j
          else
            break
          end
        end
        curj = mmi(#plus, z)
        z = z - 1
      end
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    local r = solveA(mid)
    if k <= r then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


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

typedef long long ll;
const ll M = 1e9 + 7;

ll n, m, ans = 0, fac[2000010];
string s;

ll mpow(ll a, ll n) {
    int ret = 1;
    for(ll i = n; i; i >>= 1, a = a * a % M)
        if(i & 1) ret = ret * a % M;
    return ret;
}

int main() {
    cin >> n >> s;
    m = s.size();
    fac[0] = 1;
    for(int i = 1; i < m + n; i++) fac[i] = (fac[i - 1] * i) % M;
    for(int i = 0; i <= n; i++) {
        ll c = (fac[m + n - i - 1] * mpow((fac[m - 1] * fac[n - i]) % M, M - 2)) % M;
        ans = (ans + (mpow(26, i) * c) % M * mpow(25, n - i)) % M;
    }
    cout << ans;
}


Measured memory_bytes: 19984
#include <iostream>
#include <map>
#include <algorithm>

int main() {
  int n;
  std::cin >> n;
  std::map<int, int> dist;
  for (int i = 0; i < n; i++) {
    int a;
    std::cin >> a;
    if (dist.find(a - 1) != dist.end()) {
      dist[a - 1]++;
    } else {
      dist[a - 1] = 1;
    }
    if (dist.find(a) != dist.end()) {
      dist[a]++;
    } else {
      dist[a] = 1;
    }
    if (dist.find(a + 1) != dist.end()) {
      dist[a + 1]++;
    } else {
      dist[a + 1] = 1;
    }
  }
  int x = 0;
  for (auto it = dist.begin(); it != dist.end(); ++it) {
    x = std::max(it->second, x);
  }
  std::cout << x << "\n";
  return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
#define mod 1000000007
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define forr(c, n) for (int i = c; i < n; i++)
#define forli(n) for (lli i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())

//FUNCTONS
lli llipower(lli x, lli y)
{
    lli res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}
lli llipowerp(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
    if (!a)
        return b;
    return gcd(b % a, a);
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
template <typename T>
void printvec(vector<T> inp)
{
    for (int i = 0; i < inp.size(); i++)
    {
        cout << inp[i] << " ";
    }
    cout << endl;
}
template <typename T>
T ceildiv(T x, T y) { return 1 + ((x - 1) / y); }
lli modInverse(lli a, lli m)
{
    lli g = gcd(a, m);
    if (g != 1)
        return -1;
    else
        return llipowerp(a, m - 2, m);
}

int main()
{
    lli k,n;
    cin>>k>>n;
    vector<lli> dist(n);
    forli(n) cin>>dist[i];
    vector<lli> diffs;
    dist.pb(k+dist[0]);
    fori(n) diffs.pb(dist[i+1]-dist[i]);
    sortvec(diffs);
    reverse(diffs.begin(),diffs.end());
    // printvec(diffs);
    lli ans=0;
    forr(1,diffs.size()){
        ans+=diffs[i];
        //cout<<i<<endl;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6884
package main

import (
	"fmt"
	"strconv"
	"os"
	"bufio"
	"strings"
)

// template start
var sc = bufio.NewScanner(os.Stdin)

func input2int() int{
	sc.Scan()
	num , _ := strconv.Atoi(sc.Text())
	return num
}

func input2intarr(n int) []int{
	sc.Scan()
	in := strings.Split(sc.Text(), " ")
	out := make([]int, n)
	for i:=0; i<n; i++{
		out[i], _ = strconv.Atoi(in[i])
	}
	return out
}
// template end

func convert(n int) int{
	if n == 9{
		return 1
	} else if n == 1{
		return 9
	}
	return n
}
func main(){
	var n = input2int()
	a := n/100
	b := (n-100*a)/10
	c := n-(100*a+10*b)
	a = convert(a)
	b = convert(b)
	c = convert(c)
	fmt.Println(100*a + 10*b + c)
}

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

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  if (A < C && C < B)
    cout << "Yes" << endl;
  else if (B < C && C < A)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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


int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll ans = 0;
    rep(i,n){
        cin >> a[i];
        while(a[i]%2==0){
            ans++;
            a[i] /= 2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
int n,r;
int main(){
  cin>>n>>r;
  if(n<=10 && n>0){
    cout<<r+100*(10-n);
    return 0;
  }
  else if(n>10){
    cout<<r;
    return 0;
  } 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ROCK ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f first
#define sec second
using namespace std;
using namespace __gnu_pbds ;
const long long int infl = (long long)1e18 + 1e6;
const int inf = (int)1e9 + 1e3;
const int dx[4] = {0, 0, 1, -1},dy[4] = {1, -1, 0, 0};
typedef long long int ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


int main()
{
    ROCK;
  int a,b,c;cin>>a>>b>>c;
  swap(a,b),swap(a,c);
  cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000007
using namespace std;
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // Educational DP Contest D - Knapsack1
  // N個の品物、重さwi、価値vi、ナップサックの容量W
  // dp[w][i]:i番目まで選択したとき、重さw以下となる最大価値
  // 状態遷移
  // dp[w][i]=dp[w][i-1]
  // dp[w][i]=dp[w-w[i]][i-1] + v[i] (ただし、w>=w[i])
  int N, W;
  cin >> N >> W;
  vector<ll> w(N+1);
  vector<ll> v(N+1);
  REP(i, N){
    cin >> w.at(i+1) >> v.at(i+1);
  }
  vector<vector<ll> > dp(W+1, vector<ll>(N+1, 0));
  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= W; j++){
      if(j >= w.at(i)){
        dp[j][i] = max(dp[j][i-1], dp[j-w[i]][i-1] + v[i]);
      }else{
        dp[j][i] = dp[j][i-1]; // i番目が入れらない場合はi-1番目までの価値を引き継ぐ
      }
    }
  }
  cout << dp[W][N] << endl;
}

Measured memory_bytes: 83840
/// Kazuki Hoshino


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define endl '\n'
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

ll n, ans , cur, pre;
string s[5];

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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);



cin >> n;

cin >> s[0] >> s[1];

if(s[0][0]==s[1][0]){
    cur = 1;
    ans = 3;
    pre = 1;
}

else {
    cur = 2;
    ans = 6;
    pre = 0;
}

while(cur<n){

    if(s[0][cur]==s[1][cur]){

        if(pre){
            ans = ans*2%mod;
        }
        pre = 1;
        cur++;
    }
    else {

        if(pre){
            ans = ans*2%mod;
        }
        else {
            ans = ans*3%mod;
        }
        cur+=2;
        pre = 0;

    }

}

cout << ans%mod << endl;


return 0;}
///....


Measured memory_bytes: 256
n, k = map(int, input().split())
*p, = map(int, input().split())

*e, = map(lambda x: (x*(x+1)//2)/x, p)

cusum = [0]*(n+1)
for i in range(n):
    cusum[i+1] = cusum[i]+e[i]

ans = 0
for i in range(n-k+1):
    ans = max(ans, cusum[i+k] - cusum[i])

print(ans)


Measured memory_bytes: 25060
#include <stdio.h>
#include <math.h>
int main(void){
    int i,j,weight,a[10]={};
    
    while(scanf("%d",&weight)!=EOF){
        for(i=9,j=0;i>=0;i--){
            if(weight>=pow(2,i)){
                weight-=pow(2,i);
                a[j++]=pow(2,i);
            }
        }
        
        for(i=j-1;i>=0;i--){
            printf("%d",a[i]);
            if(i==0)puts("");
            else printf(" ");
        }
    }
    return 0;
}

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

long long int N,X;

long long int a,b,c;
long long int sum;


int main(){

    cin>>N>>X;

    a=min(X,N-X);
    b=max(X,N-X);
    sum=N;


while(b%a!=0){
    sum+=(b/a)*2*a;
    c=a;
    a=b%a;
    b=c;
    
}

sum+=((b/a-1)*2+1)*a;

cout<<sum<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    string s;
    ll k;
    cin>>s>>k;
    int cnt=0;
    while(s[cnt]==1+'0'){
        cnt++;
    }
    if((ll)cnt>=k) cout<<1<<endl;
    else{
        int ans=s[cnt]-'0';
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main 
{
	public static void main(String[] args) throws IOException 
	{
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long N = Long.parseLong(br.readLine());
		int i = 10000000;
		long O = 0;
		long T = 0;
		int o = 0;
		int t = 0;
		for(long l = 1; l < (long)Math.sqrt(N) + 10; l++)
		{
			if(N % l == 0)
			{
				O = l;
				T = N / l;
				o = (int) Math.log10(O) + 1;
				t = (int) Math.log10(T) + 1;
				if(i > (o > t ? o : t)) i = (o > t ? o : t);
			}
		}
		System.out.println(i);
	}
}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    intl t[n];
    cin(i,t);
    intl ans = 1;
    rep(i,n){
        ans = lcm(ans,t[i]);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  long long h, w, t;
  cin >> h >> w;
  t = h*w;
  if (h == 1 || w == 1)
  {
    cout << 1 << endl;
  }else if (t%2 == 0)
  {
    cout << t/2 << endl;
  }else
  {
    cout << t/2+1 << endl;
  }
  
  
  
  return 0;
  

}


Measured memory_bytes: 3600
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

int main()
{
	long long int ai,ao,at,aj,al,as,az;
  scanf("%lld %lld %lld %lld %lld %lld %lld", &ai, &ao, &at, &aj, &al, &as, &az);
  long long int ans=ao;
  if(ai%2==aj%2 && aj%2==al%2){
    ans=ans+ai+aj+al;
  }else if(ai%2!=aj%2 && ai%2!=al%2){
    if(ai==0){
      ans=ans+(aj-aj%2)+(al-al%2);
    }else{
      ans=ans+(ai+aj+al-1);
    }
  }else if(aj%2!=ai%2 && aj%2!=al%2){
    if(aj==0){
      ans=ans+(ai-ai%2)+(al-al%2);
    }else{
      ans=ans+(ai+aj+al-1);
    }
  }else{
    if(al==0){
      ans=ans+(ai-ai%2)+(aj-aj%2);
    }else{
      ans=ans+(ai+aj+al-1);
    }
  }
  printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define fr first
#define sc second
#define eps 1e-9
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define sni(x) scanf("%d",&x)
#define snl(x) scanf("%lld", &x)
#define snc(x) scanf("%c", &c);
#define rep(n) for(int i = 0 ; i < n ;i ++)
#define repc(i, n) for(int i = 0 ; i < n ; i ++)
#define FOR(i, x, y) for(int i = x ; i < y ; i ++)
#define DEC(i, x, y) for(int i = x ; i >= y ; i --)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b,c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a+n
using namespace std;
#define ll long long
 vector<pair<ll,ll>>v;
 ll n,k,p;
 ll go(ll i,ll p)
 {
     if(p==0)
     {
         return 0;
     }
     if(p<0)
     {
         return INT_MIN;
     }
     ll res=INT_MIN;
     res=max(go(i+1,p-v[i].second)+v[i].first,go(i+1,p));
     return res;
 }
int main() {
    ll n,m;
    cin>>n>>m;
    ll res=((n*(n-1))/2)+(m*(m-1)/2);
    cout<<res;
}


Measured memory_bytes: 256
import math
def main(n):
    for i in range(int((1 + math.sqrt(1 + 8 * n)) // 2) + 1, 0, -1):
        if float.is_integer(n / i - (i - 1) / 2) and n / i - (i - 1) / 2 > 0:
            print(int(n / i - (i - 1) / 2), i)
            return

while 1:
    n = int(input())
    if n == 0:
        break
    main(n)


Measured memory_bytes: 5672
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#include <cmath>
#include <set>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <assert.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}
 
#define maxn 200005

int n, k, ans = 0, M = 1e9+7, lsum = 0, rsum = 0;

void mod(int &x){
    if (x>=M) x-=M;
    if (x<0) x+=M;
}
int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
        
    cin>>n>>k;

    for (int i = 0; i < k; i++){
        lsum += i;
        mod(lsum);
        rsum += n-i;
        mod(rsum);
    }
    ans = (rsum-lsum+1);
    mod(ans);
    for (int i = k; i < n + 1; i++){
        lsum += i;
        mod(lsum);
        rsum += n-i;
        mod(rsum);
        int add = rsum-lsum+1;
        mod(add);
        ans+=add;
        mod(ans);
    }
    cout<<ans<<"\n";

    return 0;
}
 

Measured memory_bytes: 3196
#include<bits/stdc++.h>
#define ll long long
#define P pair<ll, ll>
using namespace std;

int main(){
    string s;
    cin >> s;
    int ans = 0, sum = 0;
    for(int i=0;i<3;i++){
        if(s[i] == 'R')sum++;
        ans = max(ans, sum);
        if(s[i] == 'S')sum=0;
    }

    cout << ans << endl;
}


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

int func(int num){
    int k = 0;
    while(num != 0){
        num /= 10;
        k++;
    }
    return k;
}

int main(){
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 1; i <= N; i++){
        if(func(i) % 2 == 1){
            ans++;
        }
        else{
            continue;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		int x = Integer.parseInt(sb.append(a).append(b).toString());
		boolean flag = false;
		for (int i = 1; i * i <= x; i++ ) {
			if (i * i == x) {
				flag = true;
				break;
			}
		}
		if (flag) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void){

    int N,p[50],Original_p[50],i,dif=0;

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

    qsort(p,N,sizeof(int), compare_int);

    for(i = 0;i < N;i++){
        if(p[i] != Original_p[i]){
            dif++;
        }
    }

    if(dif == 0 || dif == 2){
        printf("YES");
    }else{
        printf("NO");
    }
    return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

INF = 10 ** 9 + 7
N = int(input())
a = list(map(int, input().split()))
cnt = [0] * 60
for i in a:
    for j in range(60):
        tmp = i >> j
        if tmp != 0:
            cnt[j] += tmp % 2
        else:
            break
ans = 0
for b in range(60):
    ans += cnt[b] * (N - cnt[b]) << b
    ans %= INF
print(ans)

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

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

    bool ok = (S[0] =='A');
    int cnt = 0, N = S.size();
    for (int i = 1; i < N; i++) {
        if (2 <= i && i <= N - 2 && S[i] == 'C') cnt++;
        else if (S[i] < 'a' || 'z' < S[i]) ok = false;
    }

    if (ok && cnt == 1) cout << "AC" << endl;
    else cout << "WA" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		ArrayList<ArrayList<Integer>> al = new ArrayList<ArrayList<Integer>>();
		int size = 0;

		for(int i=0;sc.hasNext();i++){
			String[] s = sc.next().split(",");
			ArrayList<Integer> tmp = new ArrayList<Integer>();
			for(int j=0;j<s.length;j++){
				tmp.add(Integer.parseInt(s[j]));
			}
			size = Math.max(size,s.length);
			al.add(tmp);
		}

		int[] sum = new int[size];
		sum[0] = al.get(0).get(0);
		for(int i=0;i<size-1;i++){
			int[] next = new int[size];
			for(int j=0;j<al.get(i).size();j++){
				next[j] = Math.max(sum[j]+al.get(i+1).get(j), next[j]);
				next[j+1] = Math.max(sum[j]+al.get(i+1).get(j+1), next[j+1]);
			}
			for(int j=0;j<size;j++) sum[j] = next[j];
		}

		for(int i=size;i<size*2-1;i++){
			int[] next = new int[size];
			for(int j=0;j<al.get(i).size();j++){
				next[j] = al.get(i).get(j) + Math.max(sum[j],sum[j+1]);
			}
			for(int j=0;j<size;j++) sum[j] = next[j];
		}

		System.out.println(sum[0]);
	}
}

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

int main(){
    int N,x;
    cin>>N>>x;
    vector<int> data(N);
    
    for(int i=0;i<N;i++){
        cin>>data[i];
    }

   sort(data.begin(),data.end());
    int count=0;
    int ans=0;
    for(int i=0;i<N;i++){
      ans+=data[i];
      if(ans<=x)count++;
      else break;
     if(ans==x)break;
     if(i==N-1&&ans!=x)count--;  
    }

 cout<<count<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();

        var half = (int)n / 2;
        if (s.Take(half).SequenceEqual(s.Skip(half)))
        {
            Console.WriteLine("Yes");
        }else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
int a,b=0,c=0,aa[100];
signed main()
{
	cin>>a;
	rep(i,a){
		cin>>aa[i];
		if(c<=aa[i]){
			b++;
			c=aa[i];
		}
	}
	cout<<b;
}

Measured memory_bytes: 256
def solve(N, P):
    c = 0
    for i in range(1,N-1):
        if P[i-1] < P[i] < P[i+1]:
            c += 1
        if P[i+1] < P[i] < P[i-1]:
            c += 1
    return c

N = int(input())
P = [int(x) for x in input().split()]
print(solve(N, P))


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

int main(void){
    int h, w;
    cin>>h>>w;
    vector<string> v(h);
    rep(i, h) cin>>v[i];
    vector<vector<pair<int, int> > > dp(h+1, vector<pair<int, int> >(w+1));
    if(v[0][0]=='.') dp[0][0]=make_pair(0, 1);//1の時障害物なしの方
    else dp[0][0]=make_pair(1, 0);
    rep(i, h-1){
        if(v[i+1][0]=='.') dp[i+1][0]=make_pair(dp[i][0].first, 1);
        else {
            if(dp[i][0].second==0) dp[i+1][0]=dp[i][0];
            else dp[i+1][0]=make_pair(dp[i][0].first+1, 0);
        }
    }
    rep(j, w-1){
        if(v[0][j+1]=='.') dp[0][j+1]=make_pair(dp[0][j].first, 1);
        else {
            if(dp[0][j].second==0) dp[0][j+1]=dp[0][j];
            else dp[0][j+1]=make_pair(dp[0][j].first+1, 0);
        }
    }
    for(int i=1;i<=h-1;i++){
        for(int j=1;j<=w-1;j++){
            if(v[i][j]=='.') dp[i][j]=make_pair(min(dp[i-1][j].first, dp[i][j-1].first), 1);
            else {
                dp[i][j]=make_pair(min(dp[i-1][j].first+(1&dp[i-1][j].second), dp[i][j-1].first+(1&dp[i][j-1].second)), 0);
            }
        }
    }
    /*rep(i, h){
        rep(j, w){
            cout<<dp[i][j].first<<" "<<dp[i][j].second<<", ";
        }
        cout<<endl;
    }*/
    cout<<dp[h-1][w-1].first<<endl;
    return 0;
}

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

int main(){
	int n; cin >> n;
	vector<int> v;
	for(int i = 0; i < n; ++i){
		int a; cin >> a;
		v.push_back(a);
	}
	sort(v.begin(), v.end());
	cout << v[v.size() - 1] - v[0] << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

#define p(x) cout << x << endl
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    int k, x;
    cin >> k >> x;

    rep(i, 2 * k - 1) {
        int t = x - k + 1 + i;
        if(t < -1000000) {
            continue;
        }
        if(t > 1000000) {
            continue;
        }
        cout << t << " ";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>

using std::string;
using std::vector;
using std::map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char VECTOR_SEPARATOR = ' ';
constexpr char CRLF = '\n';

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  string s{}, t{}; cin >> s >> t;
  vector<vector<ui>> dp(s.size() + 1, vector<ui>(t.size() + 1, (ui)0));

  for(ui indx_s = 1; indx_s < dp.size(); ++indx_s)
  {
    for(ui indx_t = 1; indx_t < dp[indx_s].size(); ++indx_t)
    {
      if(s[indx_s - 1] == t[indx_t - 1])
        chmax(dp[indx_s][indx_t], dp[indx_s - 1][indx_t - 1] + 1);

      chmax(dp[indx_s][indx_t], dp[indx_s][indx_t - 1]);
      chmax(dp[indx_s][indx_t], dp[indx_s - 1][indx_t]);
    }
  }

  string ans{};
  ui i = s.size();
  ui j = t.size();
  while(i && j)
  {
    if(dp[i][j] == dp[i - 1][j]) { --i; continue; }
    if(dp[i][j] == dp[i][j - 1]) { --j; continue; }

    if(dp[i][j] == dp[i - 1][j - 1] + 1)
    {
      --i; --j;
      ans = s[i] + ans;
      continue;
    }
    assert(false);    
  }
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 35584
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int h,w;
	cin >> h >> w;
	ll ans = -1;
	for(int t=0;t<2;t++) {
		for(int i=1;i<h;i++) {
			ll u = (ll)i * w;
			int d = h - i;
			ll l = (ll)d * (w / 2) , r = (ll)d * (w - w / 2);
			if(i != h-1) {
				ll a = (ll)(d / 2) * w , b = (ll)(d - d/2) * w;
				if(r - l > b - a)	l = a , r = b;
			}
			if(ans == -1 || ans > max({u,l,r}) - min({u,l,r}))
				ans = max({u,l,r}) - min({u,l,r});
		}
		swap(h,w);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    int white = 0 ,black = 0;
    REP(i, S.size()) {
        if(S[i] == '.') white++;
    }
    black = N - white;
    int ans = min(black, white);
    int right_white = white;
    int left_black = 0;
    REP(i, S.size()) {
        ans = min(ans, right_white + left_black);
        if(S[i] == '#') left_black++;
        else right_white--;
    }
    cout << ans << "\n";
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;
long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
      cin>>s;
      rep(i,Size(s)){
        if(s[i]=='+')cnt++;
        else cnt--;
      }
      Cout(cnt);
    
       
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200001],l,r,n,flag;
int main(){
	cin>>n;
	l=n/2-1;
	r=n/2+1;
	flag=n%2;
	cin>>a[n/2];
	for(int i=1;i<n;i++){
		if(flag==0) cin>>a[l],l--;
		else cin>>a[r],r++;
		flag=!flag;
	}
	for(int i=0;i<n;i++) cout<<a[i]<<" ";
	return 0;
}

Measured memory_bytes: 2944
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define NIL NULL

struct node{
  int key;
  struct node *p,*l,*r;
};

typedef struct node * Node;

Node root;

void pre(Node u){
  if (u == NIL) return;
  printf(" %d",u->key);
  pre(u->l);
  pre(u->r);
}

void in(Node u){
  if (u == NIL) return;
  in(u->l);
  printf(" %d",u->key);
  in(u->r);
}

void insert(int c){
  Node z,y,x;

  z = (struct node *)malloc(sizeof(struct node));
  z->key = c;
  z->l = NIL;
  z->r = NIL;

  y = NIL;
  x = root;
  while(x  != NIL){
    y = x;
    if (z->key < x->key) x = x->l;
    else x = x->r;
  }
  z->p = y;

  if (y == NIL) root = z;
  else if (z->key < y->key) y->l = z;
  else y->r = z;
}

int main(){
  int n,c;
  char word[7];
  int i;

  scanf("%d",&n);

  for (i=0; i<n; i++){
    scanf("%s",word);
    if (strcmp(word,"insert") == 0){
      scanf("%d",&c);
      insert(c);
    }
    else if (strcmp(word,"print") == 0){
      in(root);
      printf("\n");
      pre(root);
      printf("\n");
    }
  }

  return 0;
}


Measured memory_bytes: 25164
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
if sum(a) <= sum(b):
    ans = -1
else:
    ans = 0
    
    d = [a[i]-b[i] for i in range(n)]
    plus = []
    minus = []
    for i in range(n):
        if d[i] > 0:
            plus.append(d[i])
        elif d[i] < 0:
            minus.append(d[i])

    sum_minus = -sum(minus)
    ans = len(minus)
    plus.sort(reverse=True)
    while sum_minus > 0:
        num_plus = plus.pop(0)
        sum_minus -= num_plus
        ans += 1
print(ans)

Measured memory_bytes: 84400