akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  int Left, Right;
  
  cin >> a >> b >> c >> d;
  Left = a + b;
  Right = c + d;
  
  if (Left > Right) {
    cout << "Left" << endl;
  }
  else if (Left < Right) {
    cout << "Right" << endl;
  }
  else
    cout << "Balanced" << endl;
}

Measured memory_bytes: 256
n = int(input())
arr = list(map(int, input().split()))
abs_arr = list(map(abs, arr))

if len(list(filter(lambda i: i < 0, arr))) % 2 == 1:
    print(sum(abs_arr) - min(abs_arr) * 2)
else:
    print(sum(abs_arr))


Measured memory_bytes: 14412
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//
constexpr ll MOD = 1e9 + 7;
/*/
const ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  vll p(n);
  rep(i, n){
    cin >> p[i];
  }
  vll q(n);
  rep(i, n){
    cin >> q[i];
  }
  vll x(n);
  iota(ALL(x), 1ll);
  ll a = -1, b = -1;
  ll c = 0;
  do{
    c++;
    if(x == p){
      a = c;
    }
    if(x == q){
      b = c;
    }
  }while(next_permutation(ALL(x)));
  print(abs(a-b));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=505;
int n,a[N][N];
ll S1[N][N],S2[N][N];
ll f[N][N];
int main(){
	scanf("%d",&n);
	For(i,1,n) For(j,1,n) if (i!=j) scanf("%d",&a[i][j]);
	For(i,1,n) For(j,1,n) S1[i][j]=(i>j?a[i][j]:0); 
	For(i,1,n) Rep(j,n,1) S1[i][j]+=S1[i][j+1];
	For(i,1,n) For(j,1,n) S2[i][j]=(i<j?a[i][j]:0); 
	For(i,1,n) For(j,1,n) S2[i][j]+=S2[i-1][j];
	memset(f,233,sizeof(f));
	f[0][0]=0;
	For(i,1,n) f[0][i]=f[0][i-1]+S1[i][1];
	For(i,0,n) For(j,i+1,n){
		ll vtr=f[i][j];
		For(k,j+1,n){
			vtr+=S1[k][i+1]+S2[j][k];
			f[j][k]=max(f[j][k],vtr);
		}
	}
	ll ans=0;
	For(i,0,n) ans=max(ans,f[i][n]);
	ans=-ans;
	For(i,1,n) For(j,1,n)
		ans+=a[i][j];
	printf("%lld\n",ans);
}

Measured memory_bytes: 7168
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int main(void) {
    ll n, c, k; cin>>n>>c>>k;
    vector<ll> t(n);
    rep(i,n) cin>>t[i];
    sort(all(t));
    ll i = 0;
    ll ret = 0;
    while (1) {
        ll first_i = i;
        ll tmp = 0;
        // ここでのiはバスに初めに載せる
        while (i < n && tmp < c && !(t[first_i]+k < t[i])) tmp++, i++;
        // ここでのiは次のバスの初めに載せる
        // 終了条件はwhileのnot
        // (0) i >= n、もうおわり
        // (1) バスが満タンになった -> ret++
        // (2) 重ならない->ret++
        ret++;
        if (i >= n) {
            cout << ret << endl;
            return 0;
        }
    }


    return 0;
}


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

int main(void){
	long long int A, B;
	cin >> A >> B;
	long long int sum = A + B;
	long long int sub = A - B;
	long long int mul = A * B;
	long long int max = 0;
	if(sum >= sub){
		max = sum;
	} else {
		max = sub;
	}
	if(mul >= max){
		max = mul;
	}

	cout << max << endl;
	return 0;
}

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

int main()
{
    unsigned long long N, M;
    std::cin >> N >> M;
    if (N == 1) {
        std::cout << M << std::endl;
        return 0;
    }

    std::vector<unsigned long long> big_yakusu{};
    for (unsigned long long i = 1; i <= std::floor(std::sqrt(M)) + 1; i++) {
        if (M % i == 0) {
            big_yakusu.emplace_back(M / i);
            if (i >= N) {
                std::cout << M / i << std::endl;
                return 0;
            }
        }
    }
    std::reverse(big_yakusu.begin(), big_yakusu.end());
    for (const auto& y : big_yakusu) {
        if (y >= N) {
            std::cout << M / y << std::endl;
            return 0;
        }
    }
    std::cout << 1 << std::endl;
    return 0;
}

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

using namespace std;
 
//#define int long long
using ll = long long;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,n) for(ll i=0;i<=n;i++)
#define PI 3.14159265358979323846264338327950L

ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
 
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(){
    ios_base::sync_with_stdio(false);
    long double a,b,h,m;
    cin >> a >> b >> h >> m;
    long double rad = 2*PI*((h/12.0+m/720.0)-(m/60.0));
    cout << fixed << setprecision(10) << sqrtl(a*a+b*b-2*a*b*cosl(rad)) << endl;
    return 0;
}


Measured memory_bytes: 4080
#include <stdio.h>

#define N 102

int n;
int a[N][N];

void Adj(int n){
  int i, j;
  
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      a[i][j] = 0;
    }
  }  
}

int b(int u, int k){
  int i;
  int v[N];
  for(i = 0; i < k; i++){
    scanf("%d", &v[i]);
    a[u][v[i]] = 1;
  }
  if(u == n) return 1;
  else return 0;
}

int main(){
  int u, k;
  int i, j;
  int flag;
  
  scanf("%d", &n);
  
  Adj(n);
  
  for(i = 0; i < n; i++){
    scanf("%d%d", &u, &k);
    
    if(k != 0) flag = b(u, k); 
  }
  
  if(flag == 1){
    for(i = 1; i <= n; i++){
      for(j = 1; j <= n; j++){
	printf("%d", a[i][j]); 
	if(j != n)printf(" ");
      }
      
      printf("\n");
    }
  }
  else printf("Too Large\n");
  
  return 0;
}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int X;
    cin >> X;
    cout << 1-X << endl;
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int d = Integer.parseInt(sa[1]);
		int a = Integer.parseInt(sa[2]);
		Obj[] arr = new Obj[n];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			Obj o = new Obj();
			o.x = Integer.parseInt(sa[0]);
			o.h = Integer.parseInt(sa[1]);
			arr[i] = o;
		}
		br.close();

		Arrays.parallelSort(arr, (o1, o2) -> o1.x - o2.x);

		long ans = 0;
		long now = 0;
		TreeMap<Integer, Long> map = new TreeMap<>();
		for (int i = 0; i < n; i++) {
			Obj o = arr[i];
			Map<Integer, Long> map2 = map.headMap(o.x - d);
			for (Long val : map2.values()) {
				now -= val;
			}
			map2.clear();
			long rem = Math.max(o.h - now, 0);
			long cnt = (rem + a - 1) / a;
			ans += cnt;
			rem = a * cnt;
			now += rem;
			map.put(o.x + d, rem);
		}
		System.out.println(ans);
	}

	static class Obj {
		int x, h;
	}
}


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

class TEdge;
struct TNode
{
	int TreeIndex;
	std::vector<const TEdge*> Connected;
	
	TNode();
	void SetIndex(int Index, const TEdge* Edge);
};

class TEdge
{
	std::pair<TNode*, TNode*> FEnds;
	int FWeight;
public:
	TEdge(TNode* EndA, TNode* EndB, int Weight);
	
	bool operator<(const TEdge& Other)const;
	int  Weight()const {return FWeight;}
	bool ToMekeCycle()const;
	
	void JoinTree(int TreeIndex)const;
};

TNode::TNode()
:TreeIndex(0)
{
}

void TNode::SetIndex(int Index, const TEdge* Edge)
{
	if(TreeIndex >= Index) return;
	TreeIndex = Index;
	for(std::vector<const TEdge*>::const_iterator It = Connected.begin(); It != Connected.end(); ++It){
		(*It)->JoinTree(Index);
	}
	Connected.push_back(Edge);
}

TEdge::TEdge(TNode* EndA, TNode* EndB, int Weight)
:FEnds(EndA, EndB), FWeight(Weight)
{
}

bool TEdge::operator<(const TEdge& Other)const
{
	return Weight() < Other.Weight();
}

bool TEdge::ToMekeCycle()const
{
	return FEnds.first->TreeIndex > 0 && FEnds.first->TreeIndex == FEnds.second->TreeIndex;
}

void TEdge::JoinTree(int TreeIndex)const
{
	FEnds.first->SetIndex(TreeIndex, this);
	FEnds.second->SetIndex(TreeIndex, this);
}

class TGraph
{
	std::vector<TNode> FNodes;
	std::vector<TEdge> FEdges;
public:
	TGraph(int NodeCount);
	
	void AddEdge(int NodeIndexA, int NodeIndexB, int Weight);
	int WeightMinimumSpanningTree();
};

TGraph::TGraph(int NodeCount)
:FNodes(NodeCount)
{
}

void TGraph::AddEdge(int NodeIndexA, int NodeIndexB, int Weight)
{
	if(NodeIndexA <= NodeIndexB || Weight < 0) return;
	FEdges.push_back(TEdge(&FNodes[NodeIndexA], &FNodes[NodeIndexB], Weight));
}

int TGraph::WeightMinimumSpanningTree()
{
	std::sort(FEdges.begin(), FEdges.end());
	unsigned int TreeCount = 0;
	int Weight = 0;
	for(std::vector<TEdge>::iterator It = FEdges.begin(); It != FEdges.end() && TreeCount < FNodes.size() - 1; ++It){
		if(It->ToMekeCycle()) continue;
		It->JoinTree(TreeCount + 1);
		Weight += It->Weight();
		++TreeCount;
	}
	return Weight;
}

int main()
{
	int NodeCount;
	std::cin >> NodeCount;
	TGraph Graph(NodeCount);
	
	for(int i = 0; i < NodeCount; ++i)
	{
		for(int j = 0; j < NodeCount; ++j){
			int Weight;
			std::cin >> Weight;
			Graph.AddEdge(i, j, Weight);
		}
	}
	
	std::cout << Graph.WeightMinimumSpanningTree() << std::endl;
	return 0;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define MAX 100005
#define endl "\n"
lli arr[MAX];
bool flag[MAX];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	lli X,Y;
	cin>>X>>Y;
	bool flag = false;
	for(lli i = 0; i<=X; i++){
		if(2*i + 4*(X-i) == Y){
			flag = true;
		}
	}
	if(flag){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No";
	}
}

Measured memory_bytes: 3636
n = int(input())
a = list(map(int, input().split()))
s = 0
c = 0
m = 10 ** 10

for x in a:
    if x < 0:
        c += 1
    
    s += abs(x)
    m = min(m, abs(x))
    
if c % 2 != 0:
    s -= 2 * m
    
print(s)

Measured memory_bytes: 14212
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
INIT_VAL = 0
def DD2(d1,d2): return [[INIT_VAL]*d2 for _ in range(d1)]
def DD3(d1,d2,d3): return [DD2(d2,d3) for _ in range(d1)]
## math ##
MOD=10**9+7
def divc(x,y): return -(-x//y)
def divf(x,y): return x//y
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers"""
    is_prime = [True] * MAX_NUM
    is_prime[0] = False
    is_prime[1] = False
    primes = []
    for i in range(MAX_NUM):
        if is_prime[i]:
            primes.append(i)
            for j in range(2*i, MAX_NUM, i):
                is_prime[j] = False
    return primes
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left

#======================================================#

def main():
    q = II()
    lr = [MII() for _ in range(q)]
    prims = set(get_primes(MAX_NUM=10**5))
    check_like_2017 = lambda x: x in prims and (x+1)//2 in prims
    like_2017 = [1 if check_like_2017(i) else 0 for i in range(10**5+1)]
    acc_like_2017 = list(acc(like_2017))
    for l,r in lr:
        print(acc_like_2017[r]-acc_like_2017[l-1])

if __name__ == '__main__':
    main()

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

#define N 100002
vector<ll> hurui(N);

void prepare() {
    repi2(i, 2, N) {
        for(ll j = i;j <= N;j += i) {
            if(hurui[j] == 0) hurui[j] = i;
        }
    }
}

int main(void) {
    prepare();
    vector<ll> A(N - 1);
    rep2(i, 1, N - 1) {
        A[i] = A[i - 1];
        if(hurui[i] == i && hurui[(i + 1) / 2] == (i + 1) / 2) {
            A[i] += 1;
        }
    }
    ll Q;
    cin >> Q;
    rep(i, Q) {
        ll l, r;
        cin >> l >> r;
        cout << A[r] - A[l - 1] << endl;
    }
    return 0;
}


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

using namespace std;

typedef pair<int,string> P;
vector<string> IN;
vector<P> V;
char c;

void make(string s){
  s += " ";
  string in = "";
  for(int i = 0; i < s.length(); i++){
    if(s[i] == ' '){
      IN.push_back(in);
      // cout << in << endl;
      in = "";
      continue;
    }
    in += s[i];
  }
}

string gets(char key){
  
  for(int i = 0; i < IN.size(); i++)
    if(IN[i][0] == key) return IN[i];

  return "Cannot find";
}
void solve(){

  IN.push_back("{{{}}}");
  sort(IN.begin(),IN.end());

   string a = "";
   a += c;
   string s = *lower_bound(IN.begin(),IN.end(),a);
  //string s = gets(c);
  if(s[0] != c){
    cout << "NA" << endl;
    return;
  }
  while(1){
    P p;
    p.first = -1*(upper_bound(IN.begin(),IN.end(),s)-lower_bound(IN.begin(),IN.end(),s));
    p.second = s;
    V.push_back(p);
    s = *upper_bound(IN.begin(),IN.end(),s);
    if(s[0] != c) break;
  }

  sort(V.begin(),V.end());
  
  for(int i = 0; i < min((int)V.size(),5); i++){
    if(i) cout << " ";
    cout << V[i].second;
  }
  cout << endl;
}


void init(){

  IN.clear();
  V.clear();
}

int main(){
  int n;
  while(cin >> n && n){
    init();
    string in;
    getline(cin,in);
    for(int i = 0; i < n; i++){
      getline(cin,in);
      make(in);
    }
    cin >> c;
    solve();
  }
  return 0;
}

Measured memory_bytes: 1264
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define MOD  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back
#define all(x) x.begin(),x.end()
double pi = 3.141592653589793;
using namespace std;
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; }
//ここから始めよう
signed main(){
    int n,a,b;cin>>n>>a>>b;
    if(b<a+2){
        cout<<1+n<<endl;
        return 0;
    }
    if(1+n<=a){
        cout<<1+n<<endl;
        return 0;
    }
    int k=n-a+1;int ans=a;
    ans+=(b-a)*(k/2);
    if(k%2)ans++;
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include <math.h>

#define LL long long
#define MOD 1000000007
#define rep(i,n) for(int i = 0;i < (n);i++)

using namespace std;

int main(){

    int K, N;

    cin >> K >> N;
    vector<int> A(N);

    rep(i,N) cin >> A[i];

    int sa = 0;

    for(int i = 0; i < N;i++){
        if(i == 0)
        {
            sa = K - A[N-1] + A[0];
        }
        else{
            sa = max(sa,A[i]-A[i-1]);
        }
    }

    cout << K - sa << endl;

    return 0;

}

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

int main() {
	while(1){
		int n, x; cin >> n >> x;
		if(n == 0 && x == 0) break;

		int cnt = 0;
		for(int i  =1; i <= n-2; i++){
			for(int j = i+1; j <= n-1; j++){
				for(int k = j+1; k<=n; k++){
					if(i+j+k==x) cnt++;
				}
			}
		}

		cout << cnt << endl;
	}
}


Measured memory_bytes: 3084
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,l,r) for (int i=l; i<=r; i++)
typedef long long ll;
using namespace std;

const int N=200010;
ll inf=100000000000000000;
int n,p1[N],p2[N];
ll ans,a[N],sm[N];
ll Abs(ll x){ return (x<0) ? -x : x; }

int main(){
	scanf("%d",&n); ans=inf;
	rep(i,1,n) scanf("%lld",&a[i]),sm[i]=sm[i-1]+a[i];
	//rep(i,1,n) printf("%lld ",sm[i]); puts("");
	int l=1;
	rep(i,1,n){
		p1[i]=l;
		while (l<i && Abs((sm[i]-sm[l])-sm[l])>Abs((sm[i]-sm[l+1])-sm[l+1])) p1[i]=++l;
	}
	int r=n;
	for (int i=n; i; i--){
		p2[i]=r;
		while (r>i && Abs((sm[n]-sm[r-1])-(sm[r-1]-sm[i-1]))>Abs((sm[n]-sm[r-2])-(sm[r-2]-sm[i-1]))) p2[i]=--r;
	}
	//rep(i,1,n) printf("%d ",p1[i]); puts("");
	//rep(i,1,n) printf("%d ",p2[i]); puts("");
	rep(i,1,n-1){
		ll l=p1[i],r=p2[i+1];
		ll a=sm[l],b=sm[i]-sm[l],c=sm[r-1]-sm[i],d=sm[n]-sm[r-1];
		//printf("%d %lld %lld %lld %lld\n",i,a,b,c,d);
		ll mx=max(max(a,b),max(c,d)),mn=min(min(a,b),min(c,d));
		ans=min(ans,mx-mn);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4864
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>

#define range(i, n) for (int i = 0; i < n; i++) 
#define rrange(i, n) for(int i = n-1; i>=0; i--)

typedef long long int ll;


using namespace std;

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

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

	ll N, M;

	cin >> N >> M;

	vector<pair<ll, ll>>AB(N);

	range(i, N) {
		cin >> AB[i].first >> AB[i].second;
	}

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

	ll money = 0;
	ll count = 0;

	range(i, N) {
		count += AB[i].second;
		money += AB[i].first * AB[i].second;

		if (count >= M) {
			money -= AB[i].first * (count - M);
			break;
		}
	}

	cout << dec << money;



	


	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
 
#define endl "\n"
 
#define ll long long
#define MOD 1000000007
 
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
 
const double PI = 3.1415926535897932238460;
 

const int mxN=40;
int main(){
int n = 6;
int a;
int i = 1;
for (; i<n; i++)
{
    cin >>a;
    if (a==0) break;
}    
cout << i << endl;
return 0;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int sum = 0;
		int max = 0;
		for(int i = 0;i < 3; ++i){
			int input = Integer.parseInt(scan.next());
			sum += input;
			max = Math.max(max,input);
		}
		int ans = 0;
		while(sum < max*3 || sum%3 != 0){
			sum += 2;
			++ans;
		}
		System.out.print(ans);
	}
}




Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include<sstream>
using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	if (N%K == 0)cout << 0 << endl;
	else cout << 1 << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return map(int, sys.stdin.readline().split())
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())


def FLIST(n):
    res = [1]
    for i in range(1, n+1):
        res.append(res[i-1]*i % DVSR)
    return res


N, D = LI()
D2 = D*D

res = 0
for i in range(N):
    p, q = LI()
    res += p*p + q*q <= D2

print(res)


Measured memory_bytes: 9256
/* ex3_3
        fmuacshai */
 
#include<stdio.h>
//math関数を導入
#include<math.h>
int main(void){
    //整数number、進数base_number、桁数digitsを整数定義
    int number,base_number,digits;
    //numberの入力
    scanf("%d",&number);
    //base_numberの入力
    scanf("%d",&base_number);
    //digitsの初期設定
    digits=1;
    //(digits+1)桁の最小の数字以上であるかチェック
    while(number>=pow(base_number,digits)){
        digits=digits+1;
    }
    //求めた桁数digitsの出力
    printf("%d\n",digits);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define INFLL 0x3fffffffffffffffLL
#define INF 0x7fffffff
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define exist(s,e) (s.find(e)!=s.end())
#define ff first
#define ss second
#define EPS 1e-8
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const int MOD=100000007;
/////////////////// DEBUG MODE ///////////////////////////////////
#define D(x) cerr<<"DEBUG: "<<#x<<" is: "<<x<<'\n'
#define error(args...) {string _s=#args; replace(all(_s),',',' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string>) { cout<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
/////////////////// GLOBAL VARIABLES /////////////////////////////
vector<vector<int>> adj; vector<bool> vis;
/////////////////// FUNCTIONS ////////////////////////////////////
template<class T>
T maxx(T a, T b) {return a>b?a:b;}
template<typename T, typename... Args>
T maxx(T a, T b, Args... args){return maxx(a>b?a:b, args...);}
ll mexp(ll x, ll n, ll m){
  ll res=1;  while(n){if(n&1) res=(res*x)%m;n>>=1; x=((x%m)*(x%m))%m;}
  return res;
}
template<class T>
T minn(T a, T b) {return a<b?a:b;}
template<typename T, typename... Args>
T minn(T a, T b, Args... args){return minn(a>b?a:b, args...);}
bool ispow2(ll x){ return x && (!(x&(x-1))); }
ld pow(ld a, int n) {
  if(n == 0) return 1;if(n == 1) return a;
  double t = pow(a, n/2);return t * t * pow(a, n%2);
}

/////////////////// MAIN STARTS //////////////////////////////////
int main(){
  ios::sync_with_stdio(0);  cin.tie(0);   cout<<fixed; cerr<<fixed;
  cout<<setprecision(8); cerr<<setprecision(3);
  #ifdef DEBUG
  freopen("ip.txt","r",stdin); //freopen("op.txt","w",stdout);
  clock_t tStart = clock();
  #endif

	bool y=false;
	int n; cin>>n;
	for(int i=0;i<n;++i){
		char c; cin>>c; if(c=='Y') y=true;
	}
	if(y) cout<<"Four\n";
	else cout<<"Three\n";

	#ifdef DEBUG
	cerr<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)*1e3<<"ms.\n";
	#endif
  return 0;
}


Measured memory_bytes: 256
N = int(input())
T = [int(input()) for _ in range(N)]

def gcd(a, b):
    if b == 0:
        return(a)
    else:
        return(gcd(b, a % b))

def lcm(a, b):
    return(a * b // gcd(a, b))

ans = T[0]
for i in range(N):
    ans = lcm(ans, T[i])

print(ans)





Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int r[15];
int main(){
        string S;
        cin>>S;
        r[0]=1;
        r[1]=1;
        for(int i=2;i<15;i++){
            r[i]=r[i-1]*2;
        }
        long long ans=0;
	for(int i=0;i<S.size();i++){
	    for(int j=0;j<S.size()-i;j++){
	        long long a=(S[i]-'0')*r[S.size()-1-i-j]*r[i+1];
	        REP(k,j){
	            a*=10;
	        }
	        //cout<<a<<endl;
	        ans+=a;
	    }
	}
	cout<<ans<<endl;
	return(0);
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int W,H,N;
int xs[2][100*1000];
int ys[2][100*1000];
int main() {
	scanf("%d%d%d",&W,&H,&N);
	for(int i=0;i<N;i++){
		scanf("%d%d",xs[0]+i,ys[0]+i);
		xs[1][i]=xs[0][i];
		ys[1][i]=ys[0][i];
	}
	LL ret=1LL<<60;
	int rx=0,ry=0;
	for(int i=0;i<=(N+1)%2;i++){
		for(int j=0;j<=(N+1)%2;j++){
			int x;
			if(i==0){
				nth_element(xs[1],xs[1]+(N+i-1)/2,xs[1]+N);
				x=xs[1][(N+i-1)/2];
			}
			else
			{
				x=*min_element(xs[1]+N/2,xs[1]+N);
			}
			int y;
			if(j==0){
				nth_element(ys[1],ys[1]+(N+j-1)/2,ys[1]+N);
				y=ys[1][(N+j-1)/2];
			}
			else
			{
				y=*min_element(ys[1]+N/2,ys[1]+N);

			}
			LL m=0;
			LL sum=0;
			for(int i=0;i<N;i++){
				LL d=abs(xs[0][i]-x);
				d+=abs(ys[0][i]-y);
				m=max(m,d);
				sum+=2*d;
			}
			sum-=m;
			if(sum<ret){
				ret=sum;
				rx=x;
				ry=y;
			}
		}
	}
	printf("%lld\n%d %d\n",ret,rx,ry);
}

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

int main() {
    int num,x;
    cin >> num;
    x = num;
    int dig, f;

    while(num) {
        dig = num % 10;
        f += dig;
        num /= 10;
    }
    cout << ((x % f == 0)?  "Yes":"No") << endl;
}


Measured memory_bytes: 3596
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::cmp::max;
use std::cmp::min;

fn calc_gcd(x: i32, y: i32) -> i32 {
    if y == 0 {
        return x;
    }

    return calc_gcd(y, x % y);
}

fn main() {
    input! {
        K: i32,
    }

    // 内側のcalc_gc(b,c)をメモ化して高速化することもできるがおそらく不要
    // let mut gcd_memo : HashMap<(i32, i32), i32> = HashMap::new()

    let mut ans = 0;
    for a in 1..=K {
        for b in 1..=K {
            for c in 1..=K {
                let bc = calc_gcd(b, c);
                let abc = calc_gcd(a, bc);
                ans += abc;
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
char s[4005];
ll ans;
int main(){
	int n,a[3]={};
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++){
		if(s[i]=='R') a[0]++;
		else if(s[i]=='G') a[1]++;
		else a[2]++;
	} 
	ans=(ll)a[0]*a[1]*a[2];
	for(int i=1;i<n;i++)
		for(int d=1;i+d+d<=n;d++)
			if((s[i]^s[i+d]^s[i+d+d])==('R'^'G'^'B')) --ans;
	printf("%lld\n",ans);
	return 0;
}
	

Measured memory_bytes: 3800
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 
int SumOfIntegers(int n, int s){
  if(n<0||s<0) return 0;
  if(n==1) return ((s<10)?1:0);
  int a[10],count=0,sum;
  REP(i,10) a[i] = i;
  do{
    sum = 0;
    REP(i,n) sum+=a[i];
    if(sum == s) count++;
  }while(next_permutation(a, a+sizeof(a)/sizeof(a[0])));
  int d=1;
  for(int i=10-n;i>0;i--) d*=i;
  for(int i=2; i<=n; i++) d*=i;
  return (count/d);
}

int main(void){
  int n,s;
  while(cin>>n>>s,n){
    cout << SumOfIntegers(n,s) << endl;
  }
  return 0;
}

Measured memory_bytes: 864
package main

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - Sum of product of pairs
	var N int
	fmt.Scanf("%d", &N)

	sc.Split(bufio.ScanWords)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = nextInt()
	}

	var S int
	sum := make([]int, N)
	for i := N - 1; 0 <= i; i-- {
		S += A[i]
		S = S % (int(math.Pow10(9)) + 7)
		sum[i] = S
	}

	var ans int
	for i := 0; i < N-1; i++ {
		ans += A[i] * sum[i+1]
		ans = ans % (int(math.Pow10(9)) + 7)
	}

	fmt.Println(ans)

}


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

#define int long long 
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(),a.end()
#define inf INT_MAX
#define minf INT_MIN
#define dd double
#define fori(x,n) for(ll i=x;i<n;i++)

ll fun(vi adj[],ll dp[],ll i){
    if(adj[i].size()==0)return dp[i]=0;
    if(dp[i]!=-1)return dp[i];
    ll maxa=0;
    for(auto x:adj[i]){
          maxa=max(maxa,fun(adj,dp,x));
    }
    return dp[i]=1+maxa;
}

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

    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    
    ll n,m;
    cin>>n>>m;
    vi adj[n];
    while(m--){
        ll x,y;
        cin>>x>>y;
        x--;y--;
        adj[x].pb(y);
    }
    ll dp[n];
    memset(dp,-1,sizeof dp);

    ll maxa=0;

    for(int i=0;i<n;i++)
        if(dp[i]==-1)maxa=max(maxa,fun(adj,dp,i));


    cout<<maxa<<"\n";

    
    return 0;  
}
    

Measured memory_bytes: 12644
n=int(input())
a=list(map(int,input().split()))
ans=0
step=0
for i in range(n-1):
  if a[i]+step<=a[i+1]:
    step=0
  else:
    ans+=a[i]+step-a[i+1]
    step=a[i]+step-a[i+1]
print(ans)

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

int main(){
	int N;

	while(1){
		cin >> N;
		int count = 0;
		if(N==0){
			break;
		}

		for (int i = 0; i <= N; i++){
			int sum = 0;
			for (int j = i+1; j <= N; j++){
				if (sum < N){
					sum += j;
				}
				else if ((sum == N)&&(j >= i+2)){
					count += 1;
					break;
				}
				else if (sum > N){
					break;
				}

			}
		}
		cout << count << endl;

	}
}

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

int main() {

    string S, T;
    cin >> S >> T;

    int ans = 0;
    for(int i = 0; i < S.size(); i++){
        if(S[i] != T[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3920
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long Gcd(long x,long y)
        {
            if (x < y) Gcd(y, x);
            while (y > 0)
            {
                long z = x;
                x = y;
                y = z % y;
            }
            return x;
        }
        public static long Lcm(long x,long y)
        {
            return x * y / Gcd(x, y);
        }
        public static long keta(long x)
        {
            var z = 1;
            while (x > 0)
            {
                x /= 10;
                z++;
            }
            return z;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            var abc = Reads();
            var a = abc[0];
            var b = abc[1];
            var c = abc[2];
            var d = abc[3];
            var s = b / c + b / d - b / Lcm(c, d) - (a - 1) / c - (a - 1) / d + (a - 1) / Lcm(c, d);
            WriteLine(b-a+1-s);
            
            Console.Out.Flush();
        }
    }
}



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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, m, v, p;
  cin >> n >> m >> v >> p;
  
  vector<ll> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  sort(a.rbegin(), a.rend());
  
  ll left = 0, right = n, mid;
  while(left + 1 < right){
    mid = (left + right) / 2;
    if(mid + 1 <= p){
      left = mid;
      continue;
    }
    if(a.at(mid) + m < a.at(p - 1)){
      right = mid;
      continue;
    }
    ll count = 0;
    count += (n - mid + p - 1) * m;
    for(ll i = p - 1; i < mid; i++){
      count += min(m, a.at(mid) + m - a.at(i));
    }
    if(count >= m * v) left = mid;
    else right = mid;
  }
  
  cout << left + 1 << '\n';
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define _ << " " <<

typedef long long ll;
typedef pair<int, int> P;
#define X first
#define Y second

const int MAX = 1<<17;

ll p[MAX];
ll pref_poz[MAX];
ll pref[MAX];

int main()
{
  int n, k;
  scanf("%d%d", &n, &k);

  FOR(i, 1, n+1) {
    scanf("%lld", &p[i]);
    pref[i] = pref[i-1] + p[i];
    pref_poz[i] = pref_poz[i-1] + max(0ll, p[i]);
  }
  pref[n+1] = pref[n];
  pref_poz[n+1] = pref_poz[n];
  
  ll rje = 0;
  FOR(i, 1, n-k+2) {
    int l = i, r = i + k - 1;
    rje = max(rje, pref_poz[l-1] + pref_poz[n] - pref_poz[r] + max(0ll, pref[r] - pref[l-1]));
  }

  printf("%lld\n", rje);

  return 0;
}


Measured memory_bytes: 2560
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = int(input())
mod = 10**9+7

pos = {0: 1}
neg = {0: 1}
for i in range(1, 10**4):
    pos[i] = (pos[i-1]*i)%mod
    neg[i] = pow(pos[i], mod-2, mod)

cnt = 1
ans = 0
while 3*cnt<=S:
    rest = S-3*cnt
    ans += pos[rest+cnt-1]*neg[rest]*neg[cnt-1]
    ans %= mod
    cnt += 1

print(ans)

Measured memory_bytes: 69064
n,t=map(int,input().split())
ct=[list(map(int,input().split())) for i in range(n)]
l=[]
count=0
for i in range(n):
    if ct[i][1]<=t:
        l+=[ct[i][0]]
        count+=1
print(min(l) if count>0 else 'TLE')

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

long long int n,sum=0;
long long int w[105],v[105];
long long int memo[100001][101];
long long int call(int i,int s)
{
	if(i==n)
		return 0;
	if(s==0)
		return 0;
	if(memo[s][i]!=-1)
		return memo[s][i];
	
	long long int ans;
	ans=call(i+1,s);
	if(w[i]<=s)
		ans=max(ans,call(i+1,s-w[i])+v[i]);
	memo[s][i]=ans;
	return memo[s][i];
}
int main()
{
	long long int W,wg,pf;
	cin>>n>>W;
	for(long long int i=0;i<n;i++)
	{
		cin>>wg>>pf;
		w[i]=wg;
		v[i]=pf;
	}
	memset(memo,-1,sizeof(memo));
	cout<<call(0,W);
	return 0;
}

Measured memory_bytes: 79104
import math
import collections
#X=int(input())
N,K=map(int,input().split())
# S=[[]for i in range(Q)]
# for i in range(Q):
#     a=list(map(int,input().split()))
#     S[i]=a
# ans=0
# print()
ans=0
b=list()
for i in range(K):
    X = int(input())
    a = list(map(int, input().split()))
    b+=a
for i in range(1,N+1):
    if not i in b:
        ans+=1
print(ans)


Measured memory_bytes: 68040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}

void deb_p(pii p) { printf("pair = %d %d\n", p.fi, p.se); }
void deb_i(int i) { printf("i = %d\n", i); }
void deb_v(vector<int> v) {
  printf("v = ");
  for (auto i : v) printf("%d ", i);
  printf("\n");
}
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int x = 87;
  unsigned long long luca[x];
  luca[0] = 2;
  luca[1] = 1;
  rep(i, x - 2) luca[i + 2] = luca[i] + luca[i + 1];
  ll n;
  cin >> n;
  out(luca[n]);
}
int main(void) { solve(); }


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

int memo[100005];
vector <pair<int, int>> tree[100005];

int main () {
	
	int n=0, x=0, y=0, w=0, i=0;

	cin >> n;

	for (i=0; i<n-1; i++) {
		cin >> x >> y >> w;

		if (w%2 == 0) {
			tree[x].push_back(make_pair(y, 0));
			tree[y].push_back(make_pair(x, 0));
		}
		else {
			tree[x].push_back(make_pair(y, 1));
			tree[y].push_back(make_pair(x, 1));	
		}
	}

	queue <int> q;
	q.push(1);
	memo[1] = 1;

	while (!q.empty()) {
		x = q.front();
		q.pop();
		for (i=0; i<tree[x].size(); i++) {
			y = tree[x][i].first;
			w = tree[x][i].second;
			if (memo[y]==0) {
				if (w == 0) memo[y] = memo[x];
				else memo[y] = memo[x]+1;
				q.push(y);
			}
		}

	}

	for (i=1; i<=n; i++) cout << memo[i]%2 << endl;

	return 0;
}

Measured memory_bytes: 6784
import sys
import math
h, n = map(int, input().split())
INF = 10 ** 20
masics = []
for i in range(n):
  a, b = map(int, input().split())
  masics.append([a, b])
dp = [0] + [INF] * h

for masic in masics:
  for j in range(h):
    k = min(j+masic[0], h)
    dp[k] = min(dp[k], dp[j] + masic[1])

print(dp[h])

Measured memory_bytes: 50012
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/detail/ceil_and_floor.hpp
#ifndef DETAIL_CEIL_AND_FLOOR_HPP
#define DETAIL_CEIL_AND_FLOOR_HPP

namespace tools {
  template <typename T>
  constexpr T floor(T lhs, T rhs);

  template <typename T>
  constexpr T ceil(T lhs, T rhs);

  template <typename T>
  constexpr T floor(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        lhs / rhs :
      lhs < 0 && rhs >= 0 ?
        -ceil<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -ceil<T>(lhs, -rhs) :
        floor<T>(-lhs, -rhs);
  }

  template <typename T>
  constexpr T ceil(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        (lhs - 1 + rhs) / rhs :
      lhs < 0 && rhs >= 0 ?
        -floor<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -floor<T>(lhs, -rhs) :
        ceil<T>(-lhs, -rhs);
  }
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// lib/floor.hpp
#ifndef FLOOR_HPP
#define FLOOR_HPP


/*
usage:

tools::floor(5, 3) // => 1 (i.e., floor(5 / 3))
*/

#endif

// lib/ceil.hpp
#ifndef CEIL_HPP
#define CEIL_HPP


/*
usage:

tools::ceil(5, 3) // => 2 (i.e., ceil(5 / 3))
*/

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  std::vector<i64> X;
  tools::read(X, N);

  const i64 sum = std::accumulate(X.begin(), X.end(), static_cast<i64>(0));
  const i64 P1 = tools::floor(sum, N);
  const i64 P2 = tools::ceil(sum, N);
  i64 answer1 = 0;
  i64 answer2 = 0;
  for (const i64& X_i : X) {
    answer1 += (X_i - P1) * (X_i - P1);
    answer2 += (X_i - P2) * (X_i - P2);
  }
  std::cout << std::min(answer1, answer2) << std::endl;
  return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

ll rep_square(ll a, ll b) {
    // return a^b
    ll ans = 1;
    ll base = a;
    while (b != 0) {
        if (b & 1) {
            ans *= base;
            ans %= mod;
        }
        base *= base;
        base %= mod;
        b >>= 1;
    }
    return ans;
}

int main() {
source:
    ll m, k;
    cin >> m >> k;
    ll num = rep_square(2, m);
    if (m == 0) {
        if (k == 0) {
            cout << 0 << " " << 0 << endl;
        } else {
            cout << -1 << endl;
        }
    } else if (m == 1) {
        if (k == 0) {
            ll ans[] = {0, 0, 1, 1};
            rep(i, 4) { cout << ans[i] << " "; }
            cout << endl;
        } else {
            cout << -1 << endl;
        }
    } else {
        if (k >= num) {
            cout << -1 << endl;
            return 0;
        }
        rep(i, num) {
            if (i != k) {
                cout << i << " ";
            }
        }
        cout << k << " ";
        repb(i, num) {
            if (i != k) {
                cout << i << " ";
            }
        }
        cout << k << endl;
    }
    return 0;
}



Measured memory_bytes: 1920
N,K=map(int,input().split())

array=map(int,input().split())

A=list(array)
A.insert(0,0)

visit=0
root=[]
visited=1
once=0
while True:
    if visit & (0b1<<visited):
        break
    root.append(visited)
    visit|=0b1<<visited
    once+=1
    visited=A[visited]

roop=root[root.index(visited):]
if K<once:
    print(root[K])
else:
    order=K-once
    print(roop[order%len(roop)])

Measured memory_bytes: 32328