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

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

  long long count = 0;

  for (int b = 1; b <= n; b++) {
    int r = n % b;
    count += n / b * max(0, (b - k)) + max(0, r - k + 1);
  }
  if (k == 0) count -= n;

  cout << count;
}

Measured memory_bytes: 256
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////

int tab[10000];

///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
	int n;
	cin >> n;
	
	LL suma = 0;
	LL suma2 = 0;
	
	for(int i = 1; i <= n; i++){
		cin >> tab[i];
		suma += tab[i];
	}
	
	//cout << "beggining suma: " << suma << endl;
	int j = n;
	LL wynik = INF;
	while(j > 0){
		suma -= tab[j];
		suma2 += tab[j];
		LL temp = abs(suma - suma2);
		wynik = min(wynik, temp);
		j--;
	}
	
	cout << wynik << endl;
	
	
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (l, r) = readLine()!!.split(' ').map { it.toInt() }
    val xs = (l .. Math.min(r, l + 2018)).map { it % 2019 }
    var ans = 2019
    for (i in 0 until xs.size - 1) {
        for (j in i + 1 until xs.size) {
            ans = Math.min(ans, xs[i] * xs[j] % 2019)
        }
    }
    println(ans)
}


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

int main() {
    int N;
  	cin >> N;
  	vector<int> vec(N);
    for(int i = 0;i<N;i++)
    {
      cin >> vec.at(i);
    }
	sort(vec.begin(),vec.end());
  	reverse(vec.begin(),vec.end());
  	int apoint=0,bpoint=0;
  	for(int i=0;i<N;i++)
    {
      if(i%2==0)
        apoint += vec.at(i);
      else 
        bpoint += vec.at(i);
    }
  	cout << apoint - bpoint << endl;
}


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

int gd(long long m){
int cnt=0;
for(long long i=2;i*i<=m;i++){
    if(m%i==0){
        //cout<<i<<' '<<m/i<<endl;
        cnt+=2;
    if(i*i==m)
        cnt--;
    if(n==m){
        long long m1=m;
        while(m1%i==0){
            m1=m1/i;
        }
        long long m2=m1/i;
        if(m1-m2*i!=1)
            cnt--;
        if(m/i!=1&&i*i!=m)
            cnt--;
    }
    }
}
return cnt;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    int c1=gd(n-1);
    //cout<<c1<<endl;
    int c2=gd(n);
    //cout<<c2<<endl;
    if(n==2)
    cout<<'1'<<endl;
    else
    cout<<c1+c2+2<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <random>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;
constexpr ll INF = 1LL << 60;

ll n, k;

int main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> n >> k;
  
  n %= k;
  cout << min(n, abs(n - k));

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string S;
    cin >> S;
    if (S.size() <= 1) {
        cout << 0 << endl;
        return 0;
    }
    int c = 0;
    int i = 0;
    while (1) {
        if (i >= S.size() - 1) break;
        int a = S.at(i) - '0';
        int b = S.at(i+1) - '0';
        if (a ^ b) {
            S.erase(i, 1);
            S.erase(i, 1); // i+1 slides
            c += 2;
            if (S.empty() || S.size() == 1) break;
            if (i != 0) i--;
            continue;
        }
        ++i;
    }
    cout << c << endl;
}

Measured memory_bytes: 512
// Written By NewbieChd
#include <cstdio>
using namespace std;

const int maxN = 100003;

int main() {
    int n, i;
    
    scanf("%d", &n);
    if ((n & -n) == n) {
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    
    printf("1 2\n2 3\n3 %d\n%d %d\n%d %d\n", n + 1, n + 1, n + 2, n + 2, n + 3);
    for (i = 4; i < n; i += 2)
        printf("%d %d\n%d %d\n%d %d\n%d %d\n", n + 1, i + 1, i + 1, i, n + 1, n + i, n + i, n + i + 1);
    if (!(n & 1)) {
        int x, y;
        x = n & -n, y = n ^ x ^ 1;
        printf("%d %d\n", n + x, n);
        printf("%d %d\n", y, n << 1);
    }
    return 0;
}


Measured memory_bytes: 2688
#include <cstdio>
using namespace std;
#define abs(_x) ((_x) >= 0 ? (_x) : -(_x))
int a[100008];
int main(){
	register int n, i, sum;
	scanf("%d", &n);
	for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
	sum = 0;
	for (i = 0; i <= n; ++i) sum += abs(a[i + 1] - a[i]);
	for (i = 1; i <= n; ++i) printf("%d\n", sum - abs(a[i + 1] - a[i]) - abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i - 1]));
	return 0;
}

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

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

	int l = 0, r = s.size() - 1;
	bool can = true;
	ll res = 0;
	ll cnt = 0;
	while ((r > l) || (cnt++ > 1e8)) {
		if (s[l] == s[r]) {
			++l;
			--r;
		} else if (s[l] == 'x') {
			++l;
			++res;
		} else if (s[r] == 'x') {
			--r;
			++res;
		} else {
			can = false;
			break;
		}
	}

	if (can) { cout << res << endl; }
	else { cout << -1 << endl; }

	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> P;
typedef unsigned long long int ull;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;

struct UnionFindTree{
    vector<int> par,rank;
    UnionFindTree(int n):par(n),rank(n,0){
        for(int i=0;i<n;i++) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[rx]<rank[ry]) par[rx]=ry;
        else par[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

ll power(ll a,ll x){
    ll res=1;
    while(x>0){
        if(x&1) res*=a;
        a*=a;
        x>>=1;
    }
    return res;
}

int main(){
    string s;cin>>s;
    int a[3];
    for(int i=0;i<3;i++) a[i]=0;
    for(int i=0;i<(int)s.size();i++){
        if(s[i]=='a') a[0]++;
        else if(s[i]=='b') a[1]++;
        else a[2]++;
    }
    sort(a,a+3);
    if((a[0]==a[1]&&a[1]==a[2])
    ||(a[0]==a[1]&&a[1]+1==a[2])
    ||(a[0]+1==a[1]&&a[1]==a[2])){
        cout<<"YES"<<endl;
    }else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 3756
class Heap
  def initialize
    @heap = [nil] # 1-origin
  end

  def push(n)
    @heap << n
    i = @heap.size - 1
    while i > 1 && @heap[parent(i)] < @heap[i]
      @heap[parent(i)], @heap[i] = @heap[i], @heap[parent(i)]
      i = parent(i)
    end
  end

  def pop
    return nil if @heap.size <= 1
    max = @heap[1]
    tmp = @heap.pop
    return max if @heap.size == 1
    @heap[1] = tmp
    max_heapify(1)
    max
  end

  def empty?
    @heap.size == 1
  end

  def inspect
    @heap
  end

  private

  def left(i)
    2 * i
  end

  def right(i)
    2 * i + 1
  end

  def parent(i)
    i / 2
  end

  def max_heapify(i)
    l = left(i)
    r = right(i)
    largest = i
    largest = l if l < @heap.size && @heap[l] > @heap[i]
    largest = r if r < @heap.size && @heap[r] > @heap[largest]
    if largest != i
      @heap[i], @heap[largest] = @heap[largest], @heap[i]
      max_heapify(largest)
    end
  end
end

def summer_vacation(m, ab)
  heap = Heap.new
  ans = 0
  1.upto(m) do |i|
    ab[i].each { |c| heap.push(c) } if ab[i]
    top = heap.pop()
    ans += top if top
  end
  ans
end

n, m = gets.split.map!(&:to_i)
ab = {}
n.times.map do
  a, b = gets.split.map(&:to_i)
  ab[a] ||= []
  ab[a] << b
end

puts summer_vacation(m, ab)


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

int main(){

  int N;
  string str;
  cin >> N >> str;
  N = N %26;
  for(int i=0; i<str.size(); i++){
    str[i] = str[i] + N;
    if(str[i] -'A' >= 26){str[i] = str[i] - 'Z' + 'A'-1;}
  }
  cout << str << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            var CSF = new (long C, long S, long F)[N - 1];
            for (var i = 0; i < N - 1; ++i)
                CSF[i] = Slice3<long>();
            var time = new long[N];
            for (var s = 0; s < N - 1; ++s)
            {
                for (var i = s; i < N - 1; ++i)
                {
                    if (time[s] < CSF[i].S)
                        time[s] = CSF[i].S;
                    time[s] = (time[s] + CSF[i].F - 1) / CSF[i].F * CSF[i].F;
                    time[s] += CSF[i].C;
                }
            }
            foreach (var t in time)
                WriteLine(t);
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28392
#include<bits/stdc++.h>
 
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

using namespace std;

int32_t main()
{
	IOS;
	string s;
	cin>>s;
	if(s == "ABC")
		cout<<"ARC";
	else
		cout<<"ABC";
	cout<<endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;

int f[20][20];
int v[1<<16];

struct State
{
	int cost,item;
	State(int c, int i)
	{
		cost=c; item=i;
	}
	bool operator<(const State& s) const
	{
		return cost>s.cost;
	}
};

int main()
{
	int N;
	while(cin >> N, N)
	{
		for(int s=0; s<N; s++)
		{
			cin >> f[s][N];
			for(int i=0; i<N; i++)
			{
				cin >> f[s][i];
			}
		}

		memset(v, 0, sizeof(v));
		priority_queue<State> q;
		q.push(State(0,0));
		while(!q.empty())
		{
			State t=q.top(); q.pop();

			if(t.item == (1<<N)-1)
			{
				cout << t.cost << endl;
				break;
			}

			if(v[t.item]) continue;
			v[t.item] = 1;

			for(int s=0; s<N; s++)
			{
				int nc = f[s][N];
				for(int i=0; i<N; i++)
				{
					if(t.item&(1<<i))
					{
						nc = min(nc, f[s][i]);
					}
				}
				q.push(State(t.cost+nc, t.item|(1<<s)));
			}
		}
	}
}	

Measured memory_bytes: 3208
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  cin>>n;
  if(n>=400 && n<=599)
  cout<<8<<endl;
 else if(n>=600 && n<=799)
  cout<<7<<endl;
  else if(n>=800 && n<=999)
  cout<<6<<endl;
  else if(n>=1000 && n<=1199)
  cout<<5<<endl;
  else if(n>=1200 && n<=1399)
  cout<<4<<endl;
  else if(n>=1400 && n<=1599)
  cout<<3<<endl;
  else if(n>=1600 && n<=1799)
  cout<<2<<endl;
  else if(n>=1800 && n<=1999)
  cout<<1<<endl;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
   //cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N,M,X,Y;
  cin >> N >> M>> X >> Y;
  
  vector<int> x(N);
  for(int i = 0; i<N ;i++){
    cin >> x.at(i);
  }
  
  vector<int> y(M);
  for(int i = 0; i<M ;i++){
    cin >> y.at(i);
  }
  sort(x.begin(), x.end());
  
  sort(y.begin(), y.end());
  int maxX = x.at(N-1);
  int minY = y.at(0);

  bool flag = true;
  for(int Z= X+1; Z<=Y;Z++){
    if(maxX < Z && Z <= minY){
      cout << "No War" <<endl;
      flag = false;
      break;
    }
  }
  if(flag) cout << "War" << endl;
}
     

Measured memory_bytes: 256
#import 
#=input()
n=int(input())
#=map(int,input().split())
a=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

l = [[a[0]]]
for i in range(n-1):
    if a[i] > a[i+1]:
        if a[i] != l[-1][0]:
            l[-1] += [a[i]]
        else:
            del l[-1]
        l += [[a[i+1]]]
if a[-1] != l[-1][0]:
    l[-1] += [a[-1]]
else:
    del l[-1]

m = 1000
for i in range(len(l)):
    k = m // l[i][0]
    m %= l[i][0]
    m += k * l[i][1]
print(m)

Measured memory_bytes: 9156
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N, Q; cin >> N >> Q;
    vector<PiP> p(N);
    int S, T, X;
    REP(i, N){
        cin >> S >> T >> X;
        p[i] = PiP(X, Pii(S, T));
    }
    Sort(p);

    vec D(Q); cin >> D;
    set<int> s;
    REP(i, Q) s.insert(D[i]);
    map<int, int> ans;

    REP(i, N){
        int x = p[i].f, t1 = p[i].s.f, t2 = p[i].s.s;
        t1 -= x;
        t2 -= x;
        auto it1 = s.lower_bound(t1);
        auto it2 = it1;
        while(it2 != s.end() && (*it2) < t2){
            ans[*it2] = x;
            it2++;
        }
        s.erase(it1, it2);
    }
    for(int i: s) ans[i] = -1;
    REP(i, Q) Out(ans[D[i]]);

    return 0;
}


Measured memory_bytes: 30464
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

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

    vi cnt(30,100);

    rep(i,n){
        string s; cin >> s;
        vi cnt2(30,0);
        rep(j,s.size()){
            int c = s[j] - 'a';
            cnt2[c]++;
        }
        for(int j=0;j<='z'-'a';j++){
            cnt[j] = min(cnt[j],cnt2[j]); 
        }
    }

    for(int i=0;i<='z'-'a';i++){
        rep(j,cnt[i]){
            cout << (char)(i+'a');
        }
    }
    cout << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
n, k, *x = map(int, open(0).read().split())
ans = 10**18
neg = []
pos = [0]
for i in x:
    if i < 0:
        neg.append(i)
    else:
        pos.append(i)
neg.append(0)
k += 1
c = len(neg)
c -= k -min(k, len(pos))
k = min(k, len(pos))
while c > 0 and k > 0:
    c -= 1
    k -= 1
    ans = min(ans, -neg[c] * 2 + pos[k], -neg[c] + pos[k] * 2)
print(ans)


Measured memory_bytes: 20000
#include <stdio.h>

main ()
{
    char buf1[101], buf2[101];
    int n;

    scanf("%d\n", &n);
    for (int i = 0; i < n; i++) buf1[i] = getchar();
    getchar();
    for (int i = 0; i < n; i++) buf2[i] = getchar();

    for (int i = 0; i < n; i++) putchar(buf1[i]), putchar(buf2[i]);
}


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

ll num[1000010], prime[1000010], n_prime=0;

ll Prime()
{
    ll i, j;
    for(i=0; i<1000010; i++)
        prime[i]=1;
    prime[0]=prime[1]=0;
    for(i=2; i<1000010; i++)
    {
        if(prime[i])
        {
            num[++n_prime]=i;
            for(j=2*i; j<1000010; j=j+i)
                prime[j]=0;
        }
    }
}

int main()
{
    ll n, i, j;
    Prime();
    while(scanf("%lld", &n)!=EOF)
    {
        printf("%lld:", n);
        for(i=1; i<n_prime && num[i]<=sqrt(n); i++)
        {
            if(n<num[i])
                break;
            if(n%num[i]==0)
            {
                while(n%num[i]==0)
                {
                    n=n/num[i];
                    printf(" %lld", num[i]);
                }
            }
        }
        if(n>1)
            printf(" %lld", n);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 11428
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;

int main() {
    string S;
    cin >> S;
    int red = 0, blue = 0;
    rep(i, S.size()) {
        if (S[i] == '0') red++;
        else blue++;
    }
    cout << min(red, blue) * 2 << "\n";
}

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

int main(){
  int n, m; cin >> n >> m;
  vector<int> x(m), y(m);
  for(int i=0; i<m; ++i) cin >> x[i] >> y[i];
  
  vector<int> red(n, 0);
  red[0] = 1;
  vector<int> ball(n, 1);
  for(int i=0; i<m; ++i){
    int prev = x[i]-1, aftr = y[i]-1;
    if(red[prev]) red[aftr] = 1;
    --ball[prev];
    ++ball[aftr];
    if(ball[prev] == 0) red[prev] = 0;
  }
  ll res = 0;
  for(auto x : red) res += x;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1792
s = int(input())
memo = [-1]
memo.append(s)
def a(n):
    if memo[n-1] % 2 == 0:
        pre = memo[n-1]/2
        for i in memo:
            if i == pre:
                return n
        memo.append(pre)
        return a(n+1)
    else:
        pre = 3 * memo[n-1] + 1
        for i in memo:
            if i == pre:
                return n
        memo.append(pre)
        return a(n+1)

print(a(2))

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

bool str(string t) {
  bool ans = false;
  istringstream tt;
  int n;
  tt = istringstream(t);
  tt >> n;
    if(1<= n and n <= 12)
      ans = true;
  return ans;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  string s1, s2;
  s1 += s.at(0);
  s1 += s.at(1);
  s2 += s.at(2);
  s2 += s.at(3);
  
  if(!(str(s1)) and !(str(s2)))  cout << "NA" << "\n";
  else if(str(s1) and !(str(s2)))  cout << "MMYY" << "\n";
  else if(!(str(s1)) and str(s2))  cout << "YYMM" << "\n";
  else if(str(s1) and str(s2))  cout << "AMBIGUOUS" << "\n";

}


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

struct cardchange{
    long B;
    long C;
    cardchange(int B2, int C2)
    {
        B=B2;
        C=C2;
    }

    bool operator < (const cardchange & another) const
    {
        return C < another.C;
    }
};

int main()
{
    long N,M;
    std::cin >> N >> M;
    std::vector<long> A;
    for(long i=0; i<N; i++){
        long temp;
        std::cin >> temp;
        A.push_back(temp);
    }
    std::sort(A.begin(),A.end());

    std::vector<cardchange> changes;
    for(long i=0; i<M; i++){
        long tempb,tempc;
        std::cin >> tempb >> tempc;
        changes.push_back(cardchange(tempb,tempc));
    }
    std::sort(changes.begin(),changes.end());

    long vs=M-1;
    long changed_num=0;
    for(long i=0; i<N; i++){
        if(vs>=0){
            if(A[i]<changes[vs].C){
                A[i]=changes[vs].C;
                changed_num++;
            }
            if(changed_num==changes[vs].B){
                vs--;
                changed_num=0;
            }
        }
    }

    long sum=0;
    for(long i=0; i<N; i++){

        sum+=A[i];
    }
    std::cout << sum << std::endl;
    return 0;
}

Measured memory_bytes: 3188
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')
# ----------------------------------------------------------- #

b = S()
if b == 'A':
    print('T')
elif b == 'T':
    print('A')
elif b == 'G':
    print('C')
else:
    print('G')


Measured memory_bytes: 63852
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, e) for (int i = 0, _##i = (e); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
#define ARR(...) vector<int>({__VA_ARGS__})
#define ARS(...) vector<string>({__VA_ARGS__})
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef complex<double> base;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    for (auto p : v) cout << p << ",";
    cout << "]";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const set<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int N;
int H[200000], A[200000];

namespace SEG {
    const int N = 1<<18;
    ll tree[N*2];

    void update(int p, ll v) {
        tree[p+=N] = v;
        for (p >>= 1; p; p >>= 1) tree[p] = max(tree[p<<1], tree[p<<1|1]);
    }

    ll query(int l, int r) {
        l += N, r += N;
        ll res = 0;
        while(l <= r) {
            if (l&1)  get_max(res, tree[l++]);
            if (~r&1) get_max(res, tree[r--]);
            l >>= 1;
            r >>= 1;
        }
        return res;
    }
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> N;
    rep(i, N) cin >> H[i];
    rep(i, N) cin >> A[i];

    ll res = 0;
    rep(i, N) {
        ll v = SEG::query(1, H[i]);
        SEG::update(H[i], v+A[i]);
        get_max(res, v+A[i]);
    }

    cout << res << endl;
}

Measured memory_bytes: 5504
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define MOD 998244353
//#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,x;
ll dp1[3010][6010];//dp[n][s]=0,1,2をn個でs
ll dp2[3010][6010];//dp[n][s]=1,2をn個でs
ll choose[3010][3010];
int main(){
	scanf("%lld %lld",&n,&x);
	dp1[0][0]=1;
	dp2[0][0]=1;
	for(int i=0;i<n;i++)for(int j=0;j<=2*i;j++){
		for(int k=0;k<3;k++)dp1[i+1][j+k]=(dp1[i+1][j+k]+dp1[i][j])%MOD;
		for(int k=1;k<3;k++)dp2[i+1][j+k]=(dp2[i+1][j+k]+dp2[i][j])%MOD;
	}
	
	choose[0][0]=1;
	for(int i=1;i<3005;i++){
		choose[i][0]=1;
		for(int j=1;j<=i;j++)choose[i][j]=(choose[i-1][j-1]+choose[i-1][j])%MOD;
	}
	
	ll ans=0;
	for(int i=0;i<x;i++)ans=(ans+dp1[n][i])%MOD;
//	printf("%lld\n",ans);
	
	//x-1-iをn-i個以下の1,2で埋める
	for(int i=2;;i+=2){
		if(x-i-1<0||n-i<0)break;
		for(int j=0;j<=n-i;j++)ans=(ans+dp2[j][x-i-1]*choose[n][n-i-j])%MOD;
	}
	
	if(x%2==1){
		for(int i=x;i<=n;i++)ans=(ans+choose[n][i])%MOD;
	}
	
	printf("%lld",ans);
}

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

using namespace std;

signed main(){
	string s;
	cin>>s;
	int sum=0;
	int ans=0;
	s[s.size()]='$';
	for(int i=0;i<=s.size();i++){
		if(s[i]=='R') sum++;
		else{
			ans=max(ans,sum);
			sum=0;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt(),b=s.nextInt();
        b*=2;
        if(a>=b) System.out.println(a-b);
        else System.out.println(0);

    }




}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

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

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

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

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25336
#include<iostream>//AT2523
#include<cstdio>
#include<cstring>
#include<string>
#include<iomanip>
#include <algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
using namespace std;
int main()
{
	long long n,i,j;
	char s[12],t[12];
	cin>>n;
	for(i=sqrt(n);i>=1;i--)
	 if(n%i==0)
	 {
	 	j=n/i;
	 	sprintf(s,"%d",i);
	 	sprintf(t,"%d",j);
	 	cout<<max(strlen(s),strlen(t))<<endl;
	 	return 0;
	 }
	return 0;
}

Measured memory_bytes: 256
inf = float('inf')

h, w = map(int, input().split())
n = int(input())
li = list(map(int, input().split()))
fi = [[inf for _ in range(w)] for _ in range(h)]

x = 0
y = 0

for color, count in enumerate(li):
     color = color + 1
     while count != 0:
        fi[x][y] = color
        count -= 1

        if x % 2 == 0:
            nexty = y+1
        else:
            nexty = y-1
        
        if nexty == -1 or nexty == w:
            x = x+1
        elif fi[x][nexty] == inf:
            y = nexty

for row in fi:
    print(*row)

Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll amount[400040];
ll coun = -1;
ll n, k;
vector<ll> ans;
ll memo[400010];
ll calcam(ll upto)
{
	if (memo[upto]) return memo[upto];
	if (upto == n) return 1;
	for (int i = 1; i <= k; i++)
	{
		memo[upto]+=calcam(upto+1);
	}
	memo[upto]++;
	return memo[upto];
}
void make(ll upto, ll making)
{
	coun++;
	if (coun == making || upto == n)
	{
		return;
	}
	for (int i = 1; i <= k; i++)
	{
		if (coun+calcam(upto+1) < making)
		{
			//printf("%lld\n", coun);
			coun+=calcam(upto+1);
			continue;
		}
		make(upto+1, making);
		if (coun == making)
		{
			ans.push_back(i);
			return;
		}
	}
}
int main()
{
	scanf("%lld%lld", &k, &n);
	for (int i = n-1; i >= 0; i--)
	{
		if (amount[i+1] >= 300000000000010)
		{
			amount[i] = 300000000000010;
		}
		else if (i == n-1) amount[i] = k;
		else
		{
			amount[i] = amount[i+1]*k + k;
		}
	}
	if (k %2 == 0)
	{
		printf("%lld ", (k+1)/2);
		for (int i = 1; i < n; i++) printf("%lld ", k);
	}
	else if (k == 1)
	{
		for (int i = 0; i < (n+1)/2; i++) printf("%lld ", k);
	}
	else
	{
		ll mid = (k+1)/2;
		for (int i = 0; i < n; i++)
		{
			if (amount[i] >= 300000000000010)
			{
				printf("%lld ", mid);
			}
			else
			{
				amount[i]-=i-1;
				//printf("%lld\n", amount[i]);
				amount[i]/=2;
				assert(amount[i] > 0);
	
				make(i, amount[i]);
				break;
			}
		}
		reverse(ans.begin(), ans.end());
		for (int i = 0; i < ans.size(); i++) printf("%lld ", ans[i]);
	}
	printf("\n");
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int m=998244353;
    int n,k;
    cin>>n>>k;
    set <pair<int,int>> s;
    int l,r;
    for (int i=0;i<k;i++){
        cin>>l>>r;
        s.insert(make_pair(l,r));
    }
    long long int dp[n];
    long long int prefix[n];
    dp[0]=1;
    prefix[0]=1;
    for (int i=1;i<n;i++){
        dp[i]=0;
        // cout<<i<<"\n";
        for (auto p : s){
            if(i-p.first<0) continue;
            l=max(i-p.second,0);
            r=i-p.first;
            // cout<<l<<" "<<r<<"\n";
            if(l==0) dp[i]+=prefix[r];
            else dp[i]+=prefix[r]-prefix[l-1];
            dp[i]+=m;
            dp[i]%=m;
        }
        prefix[i]=(prefix[i-1]+dp[i])%m;
    }
    cout<<dp[n-1]<<"\n";
	return 0;
}

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

int main(void){
    ll l,r;
    cin >> l >> r;
    if (r-l > 2020) {
        cout << 0 << endl;
    } else {
        ll res = INF;
        for (ll i = l; i < r; i++) {
            for (ll j = l+1; j <= r; j++) {
                res = min(res, (i*j)%2019);
            }
        }
        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111




	void solve(){


		ini(n);
		vi morty(n+1);
		vi pos(n+1);
		int rick = 0;
		FOR(i,1,n+1){
			in(morty[i]);
			pos[morty[i]] = i;
		}
		set<int>set1;
		set1.insert(0);
		set1.insert(n+1);
		FOR(i,1,n+1){
			auto pos1 = set1.upper_bound(pos[i]);
			int rr = *pos1;
			pos1--;
			int ll = *pos1;
			rick+= (1ll*i)*(rr-pos[i])*(pos[i]-ll);
			set1.insert(pos[i]);
		}
		out(rick);
		


	}























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a,b;scanf("%d%d%d",&n,&a,&b);
	if ((a==1)&&(b==2)) {printf("Borys\n");return 0;}
	b-=a-1;a-=a-1;
	if (b%2) printf("Alice\n");
	else printf("Borys\n");
}

Measured memory_bytes: 256
/*
dp[u][col] = No. of ways to color subtree of u such that color of u is col.
*/

#include <bits/stdc++.h>

#define pb push_back

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

vector<int> adj[100005];
ull dp[100005][2];

const ull MOD = 1000000007;

ull dfs(int u, int par, int col){
	if(dp[u][col] != 0)
		return dp[u][col];
	dp[u][col] = 1;
	for(int i=0;i<adj[u].size();i++){
		int v = adj[u][i];
		if(v==par)
			continue;
		ull sum = 0;
		if(col==0)
			sum = (dfs(v, u, 1) + dfs(v, u, 0))%MOD;
		else
			sum = dfs(v, u, 0);
		dp[u][col] = (dp[u][col]*sum)%MOD;
	}
	return dp[u][col];
}

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a, b;
		cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	adj[1].pb(0);
	adj[0].pb(1);
	memset(dp, 0, sizeof dp);
	ull ans = (dfs(1, 0, 0) + dfs(1, 0, 1))%MOD;
	cout<<ans<<"\n";
	return 0;
}

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

typedef vector<int> vi;

int N, M, K, num;

int main() {
	while(cin>>N>>M, N | M) {
		// read data
		vi v(N+1);
		for(int t=0; t<3; t++) {
			cin >> K;
			for(int k=0; k<K; k++) {
				cin >> num;
				v[num] = t;
			}
		}

		vi a(N+1), c(N+1), p(N+1);
		p[N] = 2;			// required steps to move A->C or C->A
		a[N] = v[N];
		c[N] = 2 - v[N];
		for(int n=N; n>1; n--) {
			p[n-1] = 3 * p[n] + 2;
			switch(v[n-1]) {
			case 0:
				a[n-1] = a[n];
				c[n-1] = c[n] + 2 * p[n] + 2;
				break;
			case 1:
				a[n-1] = c[n] + p[n] + 1;
				c[n-1] = a[n] + p[n] + 1;
				break;
			case 2:
				a[n-1] = a[n] + 2 * p[n] + 2;
				c[n-1] = c[n];
				break;
			}
		}
		int res = min(a[1], c[1]);
		if(M < res) res = -1;
		cout << res << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int main(){
	
	int t = 1;
	//cin >> t;
	while(t--){
		int l, r, d;
		cin >> l >> r >> d;
		int x = (l - 1) / d;
		int y = r / d;
		cout << y - x;
	}
	return 0;
}

Measured memory_bytes: 3592
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;
  if (y == NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node *u) {
  if (u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node *u) {
  if (u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n, i, x;
  string com;

  scanf("%d", &n);

  for (i = 0; i < n; i ++) {
    cin >> com;
    if (com == "insert") {
      scanf("%d", &x);
      insert(x);
    } else if (com == "print") {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 26808
#include <stdio.h>
 
int main ()
{
	int a,min,max,jawab;	
	scanf("%d", &a);
	scanf("%d %d", &min, &max);
		for (min;min<=max;min++)
		{
			if(min%a==0)
			{
			jawab++;
			}	
		}
	if(jawab!=0)
	{
		printf("OK");
	}
	else
	{
		printf("NG");
	}
	return 0;
}

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

int main()
{
    int n,m;
    cin >> n >> m;
    char a[n][n];
    char b[m][m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < m; i++){
        for(int j = 0; j < m; j++){
            cin >> b[i][j];
        }
    }
    int x = n - m + 1;
    
    for(int i = 0; i < x; i++){
        for(int j = 0; j < x; j++){
            int t = 1;
            for(int k = 0; k < m; k++){
                for(int l = 0; l < m; l++){
                    if(a[i+k][j+l] != b[k][l]){
                        t = 0;
                    }
                }
            }
            if(t == 1){
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
}

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;
using li=list<int>;
using lil=list<ll>;
using lis=list<string>;
using fli=forward_list<int>;
using fll=forward_list<ll>;
using fls=forward_list<string>;
using si=stack<int>;
using sl=stack<ll>;
using ss=stack<string>;
using qi=queue<int>;
using ql=queue<ll>;
using qs=queue<string>;
using pqi=priority_queue<int>;
using pql=priority_queue<ll>;
using pqs=priority_queue<string>;
using dqi=deque<int>;
using dql=deque<ll>;
using dqs=deque<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)
#define repr(i, n) for(int i = (n); i >= 0; i--)
#define repr2(i, a, n) for(int i = (n); i >= (a); i--)

template<typename T,typename U>
void Inparray(T &f,U n){for(int i=0;i<n;i++) cin>>f[i];}

template<typename T,typename U>
void Printarray(T f,U n){for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];}
template<typename T,typename U>
void Printarray2(T f,U n){for(int i=0;i<n;i++) cout<<f[i]<<endl;}
template<typename T,typename U,typename V>
void Printarray3(T f,U a,V b){
  rep(i,a){
    rep(j,b){
      cout<<f[i][j];
    }
    cout<<endl;
  }
}
template<typename T,typename U>
void Printarray4(T f,U n){
  rep(i,n){
    rep(j,n){
      cout<<f[i][j];
    }
    cout<<endl;
  }
}

void flagfunc(bool flag,string A,string B){flag ? cout<<A<<endl : cout<<B<<endl;}
void flag2func(bool flag){flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;}
void flag3func(bool flag){flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int a[3][3];rep(i,3)rep(j,3)cin>>a[i][j];
  vector<vector<bool>> b(3,vector<bool>(3,false));
  //vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));
  int n,c;cin>>n;
  rep(i,n){
    cin>>c;
    rep(j,3){
      rep(k,3){
        if(a[j][k]==c){b[j][k]=true;}
      }
    }
  }
  bool flag=false;
  int cnt;

  //讓ｪ蛻､螳・
  //陦・
  rep(i,3){
    cnt=0;
    //蛻・
    rep(j,3){
      if(b[i][j]==true)cnt++;
    }
    if(cnt==3){flag=true;break;}
  }

  //邵ｦ蛻､螳・
  //蛻・
  for(int i=0;i<3 && flag==false;i++){
    cnt=0;
    //陦・
    for(int j=0;j<3;j++){
      if(b[j][i]==true)cnt++;
    }
    if(cnt==3){flag=true;break;}
  }

  //譁懊ａ蛻､螳・
  if(b[0][0]==true &&b[1][1]==true &&b[2][2]==true&&flag==false)flag=true;
  if(b[0][2]==true &&b[1][1]==true &&b[2][0]==true&&flag==false)flag=true;

  flag2func(flag);
}


Measured memory_bytes: 256