akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
using namespace std;
int main() {
	int n, k;
	int a[100010];
	int dp[100010] = { 0 };
	int min = 1000000007;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	dp[1] = abs(a[1] - a[0]);
	for (int j = 2; j < n; j++) {
		for (int l = 1; l <= k; l++) {
			if (j-l< 0) {
				break;
			}
			if (abs(a[j] - a[j - l]) + dp[j - l] <= min) {
				min = abs(a[j] - a[j - l]) + dp[j - l];
			}
		}
		dp[j] = min;
		min = 1000000007;
	}
	cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
//const ll MOD = 998244353
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int n;
string s;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> s;
    int ans = 0;
    rep(i,10) {
        rep(j,10) {
            rep(k,10) {
                int a[3];
                a[0] = i; a[1] = j; a[2] = k;
                int pos = 0;
                rep(i,n) {
                    if (s[i]-'0' == a[pos]) pos++;
                    if (pos == 3) break;
                }
                if (pos == 3) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;
constexpr ll MOD = 1000000007;

int main()
{
  int n,m;
  cin>>n>>m;
  vector<bool> a(n+1);
  REP(i,m) {
    int pos;
    cin>>pos;
    a[pos] = true;
  }
  vector<ll> dp(n+1);
  dp[0] = 1;
  REP(i,n) {
    int j=i+1;
    if(!a[j]) {
      if (j >= 2) {
        dp[j] = dp[j-1] + dp[j-2];
      } else {
        dp[j] = dp[j-1];
      }
      dp[j] %= MOD;
    }
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 1024
C = [list(map(int, input().split())) for _ in range(3)]
ans = 1
for i in range(2):
  if C[i+1][0] - C[i][0] ==  C[i+1][1] - C[i][1]  and C[i+1][2] - C[i][2] ==  C[i+1][1] - C[i][1] :
    continue
  else: ans = 0
for i in range(2):
  if C[0][i+1] - C[0][i] ==  C[1][i+1] - C[1][i]  and C[2][i+1] - C[2][i] ==  C[1][i+1] - C[1][i]:
    continue
  else: ans = 0

if ans: print("Yes")
else: print("No")

Measured memory_bytes: 3192
private const val MOD = 1e9.toLong() + 7

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map {it.toLong()}

    var res = ModInt(0L, MOD)
    var p = ModInt(1L, MOD)

    for (i in 0 until 60) {
        val cnt0 = A.count { it and (1L shl i) == 0L }.toLong()
        res += (p * cnt0 * (N - cnt0))
        p *= 2L
    }

    println(res.value)
}

class ModInt (value: Long, val mod: Long) {
    init {
        if (mod <= 0) {
            throw IllegalArgumentException("ModInt cannot be created for non-positive modulus: $mod")
        }
    }

    val value = (value % mod + mod) % mod

    private fun assertSameMod(other: ModInt) {
        if (mod != other.mod) {
            throw IllegalArgumentException(
                "You cannot operate summation, subtraction and multiplication for ModInts with different moduli: $mod, ${other.mod}"
            )
        }
    }

    operator fun unaryMinus() = ModInt(mod - value, mod)

    operator fun plus(other: ModInt): ModInt {
        assertSameMod(other)

        return ModInt((value + other.value) % mod, mod)
    }

    operator fun plus(other: Long) = plus(ModInt(other, mod))

    operator fun minus(other: ModInt): ModInt {
        assertSameMod(other)

        return plus(-other)
    }

    operator fun minus(other: Long) = minus(ModInt(other, mod))

    operator fun times(other: ModInt): ModInt {
        assertSameMod(other)

        return ModInt((value * other.value) % mod, mod)
    }

    operator fun times(other: Long) = times(ModInt(other, mod))

    fun pow(k: Long): ModInt {
        var res = 1L
        var a = value
        var l = k

        while (l > 0) {
            if ((l and 1L) == 1L) {
                res = (res * a) % mod
            }

            a = a * a % mod
            l /= 2L
        }

        return ModInt(res, mod)
    }

    /**
     * Returns an inverse element of the value.
     * To ensure `m * m.inv() = 1`, the modulus should be prime, since it uses Fermat's little theorem.
     */
    fun inv() = pow(mod - 2)

    operator fun div(other: ModInt): ModInt {
        assertSameMod(other)
        if (other.value == 0L) {
            throw ArithmeticException()
        }

        return times(other.inv())
    }

    operator fun div(other: Long) = div(ModInt(other, mod))
}

class ModCombination(val n: Long, val mod: Long) {
    private val fact = Array(n.toInt() + 1) { ModInt(1, mod) }
    private val invfact = Array(n.toInt() + 1) { ModInt(1, mod) }

    init {
        for (i in 2..n.toInt()) {
            fact[i] = fact[i - 1] * i.toLong()
            invfact[i] = fact[i].inv()
        }
    }

    operator fun get(n: Long, m: Long): ModInt {
        if (m > n) {
            return ModInt(0, mod)
        }

        return fact[n.toInt()] * invfact[m.toInt()] * invfact[(n - m).toInt()]
    }

    fun calc(n: Long, m: Long): ModInt {
        return fact[(n * m).toInt()] * invfact[n.toInt()].pow(m) * invfact[m.toInt()]
    }
}


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

int main() {
  string N;
  cin >> N;
  
   if  (N[0] == N[1] && N[1] == N[2] || N[01] == N[2] && N[2] == N[3]) {
     cout << "Yes" << endl;
   }
  else {
    cout << "No" << endl;
  }
  
}

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

ll mod = 1e6+3;

ll modpower(ll a, ll r){ //a^r
    ll x = 1;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a){
    return modpower(a, mod-2);
}

int main(){
    vector<ll> fact(mod);
    fact[0] = 1;
    for (int i = 1; i < mod; i++) fact[i] = fact[i-1] * i % mod;
    int Q;
    cin >> Q;
    for (int z = 0; z < Q; z++) {
        ll x, d, n;
        cin >> x >> d >> n;
        if (x == 0) {
            printf("0\n");
            continue;
        }
        if (d == 0) {
            printf("%lld\n", modpower(x, n));
            continue;
        }
        x = x * modinv(d) % mod;
        if (x + (n-1) >= mod) printf("0\n");
        else printf("%lld\n", fact[x+n-1] * modinv(fact[x-1]) % mod * modpower(d, n) % mod);
    }
    return 0;
}


Measured memory_bytes: 8704
s = input()
seq = list(map(int, (s[:2], s[2:])))

ans = ["", ""]

for i in range(2):
    if 0 < seq[i] <= 12:
        ans[i] = "MM"
    else:
        ans[i] = "YY"

if "MM" not in ans:
    print("NA")
elif "YY" not in ans:
    print("AMBIGUOUS")
else:
    print("".join(ans))

Measured memory_bytes: 3064
#include <iostream>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
using namespace std;
typedef long long int LL;

int main() {
  LL a, b, c;
  cin >> a >> b >> c;
  if (a + b < c) {
    cout << a+b+1+b << endl;
  } else {
    cout << b + c << endl;
  }
  return 0;
}


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

using namespace std;


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

	vector<int> b(n - 1);
	for (int i = 0; i < n - 1; i++)
	{
		cin >> b[i];
	}

	vector<int> a(n);
	a[0] = b[0];

	for (int i = 1; i < n - 1; i++)
	{
		a[i] = min(b[i - 1], b[i]);
	}

	a[n - 1] = b[n - 2];

	cout << accumulate(a.begin(), a.end(), 0) << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int P = sc.nextInt();

		int pa = A*3+P;
		int a_pie = 0;

		if(pa<3){
			a_pie = 0;
		}else if(pa%2==0){
			a_pie = pa/2;
		} else if(pa%2==1){
			a_pie = (pa-1)/2;
		}

		System.out.println(a_pie);

	}

}


Measured memory_bytes: 21844
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;
using System.Runtime.InteropServices.ComTypes;

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, M) = Slice2<int>();
            var Ai = Sarray();
            int[] match = new int[] { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
            var dp = Enumerable.Repeat(-1, N + 10).ToArray();//マッチの数：作れる桁数
            dp[0] = 0;
            for (var i = 0; i < N; ++i)
                foreach (var a in Ai)
                    if (0 <= dp[i])
                        dp[i + match[a]] = Max(dp[i + match[a]], dp[i] + 1);

            var ans = new List<char>();
            Array.Sort(Ai); Array.Reverse(Ai);
            for (var i = N; 0 < i;)
                foreach (var a in Ai)
                    if (0 <= i - match[a] && dp[i] == dp[i - match[a]] + 1)
                    {
                        ans.Add((char)('0' + a));
                        i -= match[a];
                        break;
                    }
            WriteLine(string.Join("", ans));
        }

        static long Mod = 998244353;
        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)));
        }
        static public (T a, T b, T c, T d) Slice4<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)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

Measured memory_bytes: 28564
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
char S[2048];
int n, fir[2048], nex[4096], tar[4096], cnt;
void Add(int u, int v)
{
	++cnt;
	tar[cnt] = v;
	nex[cnt] = fir[u];
	fir[u] = cnt;
}
int f[2048], g[2048], siz[2048];
void Dfs(int u, int fa)
{
	f[u] = g[u] = 0;
	siz[u] = S[u] - '0';
	for (int i = fir[u]; i; i = nex[i])
	{
		int v = tar[i];
		if (v == fa)
			continue;
		Dfs(v, u);
		siz[u] += siz[v];
		int l1 = f[v] + siz[v];
		int r1 = g[v] + siz[v];
		int l2 = f[u], r2 = g[u];
		g[u] = r1 + r2;
		if (l2 > r1)
			f[u] = l2 - r1;
		else
			if (l1 > r2)
				f[u] = l1 - r2;
			else
				f[u] = (g[u] & 1);
	}
}
int main()
{
	scanf("%d%s", &n, S + 1);
	for (int i = 1; i < n; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		Add(u, v), Add(v, u);
	}
	int ans = 1000000000;
	for (int i = 1; i <= n; i++)
	{
		Dfs(i, 0);
		if (f[i])
			continue;
		if (g[i] < ans)
			ans = g[i];
	}
	if (ans > 100000000)
	{
		puts("-1");
		return 0;
	}
	printf("%d\n", ans / 2);
}


Measured memory_bytes: 384
#include<stdio.h>

int main(){
  int n,i,j,min,max,R[200000];
  
  scanf("%d",&n);
  for(j=0;j<n;j++){
    scanf("%d",&R[j]);
  }

  min=R[0];
  max=R[1]-R[0];

  for(i=1;i<n;i++){
    if(max<(R[i]-min)) max=R[i]-min;
    if(min>R[i]) min=R[i];
  }

  printf("%d\n",max);

  return 0;
}



Measured memory_bytes: 2496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    
    ll N, D, X;
    cin >> N >> D >> X;
    for(ll i = 0; i < N; i++){
        ll a;
        cin >> a;
        X += D / a;
        if(D % a)X++;
    }
    cout << X << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))

int n;
int dat[100005];

#define MOD (1000000007LL)


lli fact(int x){
	lli res=1;
	rep(i,x)res = (res * ((lli)(i+1))) % MOD;
	return res;
}

int main(void){
	//printf("%lld\n",(12LL*fact(12)) % MOD);
	lli ans=1;
	scanf("%d",&n);
	rep(i,n)scanf("%d",&dat[i]);
	
	lli nsr = 0;
	rep(i,n){
		if(dat[i]<nsr*2+1){
			ans = ((nsr+1) * ans) % MOD;
		}
		else nsr++;
	}
	ans = (ans * fact(nsr)) % MOD;
	printf("%lld\n",ans);
	
	return 0;
}






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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------
vector<long long> factor_array(long long n){
    vector<long long> res ;
    for(long long i=1;i*i<=n;i++){
        if(n%i==0){
            res.push_back(i) ;
            if(i*i!=n){
                res.push_back(n/i) ;
            }
        }
    }
    sort(res.begin(),res.end()) ;
    return res ;
}
//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();
    int n ;
    cin >> n ;
    vint a(n+1) ;
    vint b(n+1,0) ;
    REP(i,n){
        cin >> a[i+1] ;
    }
    queue<int> ans ;
    for(int i=n;i>0;i--){
        int cnt = 0 ;
        int j = 2*i ;
        while(j<=n){
            cnt += b[j] ;
            j += i ;
        }
        if(cnt%2!=a[i]){
            ans.push(i) ;
            b[i] += 1 ;
        }
    }
    cout << SZ(ans) <<endl;
    while(!ans.empty()){
        cout << ans.front() <<" ";
        ans.pop() ;
    }
    cout <<endl;




    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



Measured memory_bytes: 5308
#include <bits/stdc++.h>
#define Maxn 600007
using namespace std;
int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,cnt;
int last[Maxn],pre[Maxn],other[Maxn];
int size[Maxn];
bool f[Maxn];
//size[i] means the size of the tree with the root i
//f[i] means whether it is able to color the whole tree with the root i
void insert(int u, int v)
{
	other[++cnt]=v,pre[cnt]=last[u],last[u]=cnt;
}
void dfs(int u, int fa)
{
	int cnt=0;
	bool check=true;
	size[u]=1;
	for (int q=last[u];q;q=pre[q])
	{
		int v=other[q];
		if (v!=fa)
		{
			dfs(v,u);
			size[u]+=size[v];
			if (size[v]%2==1) ++cnt;
			if (!f[v]) check=false;
		}
	}
	if (cnt<=1&&check) f[u]=true; else f[u]=false;
}
int main()
{
	n=read(),cnt=0;
	for (int i=1;i<n;i++)
	{
		int u=read(),v=read();
		insert(u,v),insert(v,u);
	}
	memset(f,false,sizeof(f));
	dfs(1,0);
	if (f[1]&&size[1]%2==0) cout << "Second" << endl; else cout << "First" << endl;
	return 0;
}


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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> A(H);

    for (int i = 0; i < H; i++)
    {
        cin >> A.at(i);
    }

    for (int i = 0; i < A.at(0).size() + 2; i++)
    {
        cout << '#' << flush;
    }

    cout << endl;

    for (int i = 0; i < H; i++)
    {
        cout << '#' + A.at(i) + '#' << endl;
    }

    for (int i = 0; i < A.at(0).size() + 2; i++)
    {
        cout << '#' << flush;
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	for (long u = 0; u < 1000; u++)
	{
		int a[10001],b[10001],c[10001];
		long n;

		cin >> n;
		if (n == 0)
		{
			break;
		}

		for (int i = 0; i < n; i++)
		{
			cin >> a[i] >> b[i] >> c[i];
		}

		int p = 0;

		for (int i = 0; i < n; i++)
		{
			p = (a[i] + b[i] + c[i]) / 3;
			if (a[i] == 100 || b[i] == 100)
			{
				cout << 'A' << endl;
			}
			else if (c[i] == 100)
			{
				cout << 'A' << endl;
			}
			else if ((a[i] + b[i]) / 2 >= 90)
			{
				cout << 'A' << endl;
			}
			else if (p >= 80)
			{
				cout << 'A' << endl;
			}
			else if (p >= 70)
			{
				cout << 'B' << endl;
			}
			else if (p >= 50 && a[i] >= 80)
			{
				cout << 'B' << endl;
			}
			else if (p >= 50 && b[i] >= 80)
			{
				cout << 'B' << endl;
			}
			else
			{
				cout << 'C' << endl;
			}
		}
	}
}




Measured memory_bytes: 3000
#include <iostream>

using namespace std;

int main()
    {
    int A;
    int B;
    cin >>A;
    cin >>B;
    if (A >= 13){
        cout<<B;

    }
    if ( A <=12 ){
            if (A>=6)
                cout<<B/2;
    }
    if ( A<=5){
        cout<< 0;
    }

return 0;

}

Measured memory_bytes: 256
import copy

n, k = map(int, input().split())
v = list(map(int, input().split()))

mx = 0
for num_out in range(k+1):
	if num_out > n:
		num_out = n
		num_ret = min(k-n, n)
		out = copy.copy(v)
		out.sort()
		ret_value = 0
		for ret_v in out[:num_ret]:
			if ret_v < 0:
				ret_value += ret_v
			else:
				break
		val = sum(out) - ret_value
		if val > mx:
			mx = val
		continue
	
	num_ret = k-num_out
	for num_out_l in range(num_out+1):
		num_out_r = num_out - num_out_l
		out = v[:num_out_l] + v[n-num_out_r:]
		out.sort()
		ret_value = 0
		for ret_v in out[:num_ret]:
			if ret_v < 0:
				ret_value += ret_v
			else:
				break
		val = sum(out) - ret_value
		if val > mx:
			mx = val
			# mx_out = out

print(mx)
# print(mx_out)


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/









int N, A[202], K[202];
//---------------------------------------------------------------------------------------------------
int f(int a, int k) {
    if (a % k != 0) {
        int d = a % k;
        int m = a / k + 1;

        if (d < m * 2) return f(a - m, k);
        else {
            int c = d / m;
            return f(a - m * c, k);
        }
    } else return a / k;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i] >> K[i];

    int g = 0;
    rep(i, 0, N) g ^= f(A[i], K[i]);
    if (g == 0) printf("Aoki\n");
    else printf("Takahashi\n");
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define REPR(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) \
  for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORR(i, a, b) \
  for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)
#define ALL(f, x, ...) \
  ([&](auto& y) { return (f)(begin(y), end(y), ##__VA_ARGS__); })(x)
auto INDEX = [](auto& x, auto& xs) { return &x - &xs[0]; };
void async_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
const auto inf = INT_MAX / 3;
const auto pi = 2 * std::acos(0.0);
const auto eps = 1e-14;
using ll = signed long long;
using ull = unsigned long long;

signed main() {
  async_io();
  int n;
  while (true) {
    cin >> n;
    if (n == 0) return 0;
    auto sum = 0;
    for (int i = 2;; i++) {
      auto base = i * (i + 1) / 2;
      if (base > n) break;
      if ((base - n) % i == 0) sum++;
    }
    cout << sum << "\n";
  }
}

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

int main(void) {
   int N;
   cin>>N;
   bool flag = false;
   for (int i = 1; i < 10; i++) {
      if (N%i == 0 && N/i <10) {
         flag = true;
      }
   }
   if (flag) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                long n = sc.nextLong();
                long k = sc.nextLong();
                System.out.println(Math.min(n % k , -1 * (n % k - k)));
                sc.close();
        }
}
//おやつ食べました
//昔解けなかった問題が解けるようになっていて感動しました
//こんなこと言ってWAが出たら鳴くのでACを出せ

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

int main() {
    // input
    int n, m; scanf("%d%d", &n, &m);
    vector<vector<pair<int, int> > > g(n);
    REP (i, m) {
        int l, r, d; scanf("%d%d%d", &l, &r, &d);
        -- l;
        -- r;
        g[l].emplace_back(r, + d);
        g[r].emplace_back(l, - d);
    }
    // solve
    vector<ll> x(n, LLONG_MAX);
    function<void (int)> go = [&](int i) {
        for (auto edge : g[i]) {
            int j, dist; tie(j, dist) = edge;
            if (x[j] == LLONG_MAX) {
                x[j] = x[i] + dist;
                go(j);
            }
            if (x[j] != x[i] + dist) {
                throw (void *)nullptr;
            }
        }
    };
    bool result = true;
    try {
        REP (i, n) {
            if (x[i] == LLONG_MAX) {
                x[i] = 0;
                go(i);
            }
        }
    } catch (void *) {
        result = false;
    }
    // output
    printf("%s\n", result ? "Yes" : "No");
    return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF 1000000000 //
#define LINF (ll)4000000000000000000 //
#define MOD (ll)1000000007
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    int MaxW = -1;
    int MaxS = -1;
    double MaxR = -1;

    rep3(a, 100) {

        rep3(b, 100) {

            rep3(c, 100) {

                rep3(d, 100) {
                    int water = 100 * A * a + 100 * B * b;
                    int sugar = C * c + D * d;
                    if (E * water >= sugar * 100 && water + sugar <= F) {
                        double rate = (double) (100 * sugar) / (double) (water + sugar);
                        if (rate > MaxR) {
                            MaxW = water;
                            MaxS = sugar;
                            MaxR = rate;
                        }
                    }
                }
            }
        }
    }

    cout << MaxW + MaxS << " " << MaxS << endl;

    return 0;
}

Measured memory_bytes: 256
///////////////////// author : TrEbLeCleF /////////////////////
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;

#define pb(x) push_back(x)
#define deb(x) cerr <<#x<<" = "<<x<<"\n"
#define print(v,s,e) for(int i = s; i < e; i++)cout << v[i]<<" ";cout<<"\n";
#define INF 1e17
#define PI 3.14159265358979323846 
int del_x[4] = {-1, 1, 0, 0};
int del_y[4] = {0, 0, 1, -1};
int XX[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int YY[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
/////////////////////////// GLOBAL ///////////////////////////



/////////////////////////// GLOBAL ///////////////////////////
void solve(){
	string ans = "";
	ll n;cin >> n;
	while(n>0){
		n-=1;
		ans += ('a' + n%26);
		n=n/26;
	}
	reverse(ans.begin(), ans.end());
	cout << ans <<"\n";

}


int main(){ 
	#ifndef ONLINE_JUDGE
		clock_t tStart = clock();
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
		freopen("error.txt", "w", stderr);
	#endif 
    ios_base:: sync_with_stdio(false); 
   	cin.tie(0); 
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
	/* #ifndef ONLINE_JUDGE
    printf("\nRun Time -> %.10fs\n", (double)(clock()-tStart) / CLOCKS_PER_SEC);
    #endif  */
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long cnt1 = 0;
		long carry = 0;
		long[] A1 = (long[]) A.Clone();
		for(int i=0;i<=N;i++){
			var t1 = Math.Min(A1[i], carry);
			cnt1 += t1;
			A1[i] -= t1;
			if(i < N){
				var t2 = Math.Min(A1[i], B[i]);
				cnt1 += t2;
				carry = B[i] - t2;
			}
		}
		
		long cnt2 = 0;
		carry = 0;
		long[] A2 = (long[]) A.Clone();
		for(int i=N;i>=0;i--){
			var t1 = Math.Min(A2[i], carry);
			cnt2 += t1;
			A2[i] -= t1;
			if(i - 1 >= 0){
				var t2 = Math.Min(A2[i], B[i - 1]);
				cnt2 += t2;
				carry = B[i - 1] - t2;
			}
		}
		
		
		Console.WriteLine(Math.Max(cnt2, cnt1));
	}
	int N;
	long[] A;
	long[] B;
	public Sol(){
		N = ri();
		A = rla();
		B = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 31964
#include <iostream>
using
namespace std;
int main(void){
  int n,b,f,r,v,i,j,k,count[4][3][10]={{{0}}};
  cin >> n;
  for(i=0;i<n;i++){
  cin >> b >> f >> r >> v;
  count[b-1][f-1][r-1]=count[b-1][f-1][r-1]+v;
  }
  for(j=0;j<3;j++){
      for(k=0;k<10;k++){
          if(count[0][j][k]<0){
              count[0][j][k]=0;
          }else if(count[0][j][k]>9){
              count[0][j][k]=9;
          }
          cout << " ";
          cout << count[0][j][k];
      }
      cout << endl;
  }
  for(i=1;i<4;i++){
      cout << "####################";
      cout << endl;
      for(j=0;j<3;j++){
          for(k=0;k<10;k++){
              if(count[i][j][k]<0){
                  count[i][j][k]=0;
              }else if(count[i][j][k]>9){
                  count[i][j][k]=9;
              }
              cout << " ";
              cout << count[i][j][k];
          }
          cout << endl;
      }
  }
}


Measured memory_bytes: 3112
import java.util.Scanner;
import java.util.PriorityQueue;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        PriorityQueue<Job> que1 = new PriorityQueue<>( (x, y) -> x.day - y.day );
        PriorityQueue<Job> selectableJob = new PriorityQueue<>( (x, y) -> y.payment - x.payment );
        
        for ( int i = 0; i < N; i++){
            int A = sc.nextInt();
            int B = sc.nextInt();
            que1.add(new Job(A, B));
        }
        
        int totalPayment = 0;
        
        for( int i = 1; i <= M; i++ ){
            while ( !que1.isEmpty() ) {
                
                if ( que1.peek().day == i ) {
                    selectableJob.add( que1.poll() );
                } else {
                    break;
                }
            }
            
            if ( !selectableJob.isEmpty()){
                totalPayment += selectableJob.poll().payment;
            }
        }
        
        System.out.println(totalPayment);
    }
}

class Job {
    int day;
    int payment;
    
    public Job (int day, int payment){
        this.day = day;
        this.payment = payment;
    }
}

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

int main() {
	int fiv = 0;
    int sev = 0;
  
    vector<int> vec(3);
  
    for (int i = 0; i < 3; i++){
      cin >> vec.at(i);
    }
  	for (int j = 0; j < 3; j++){
      if (vec.at(j) == 5){
        fiv++;
      }
      else if (vec.at(j) == 7){
        sev++;
      }
    }
    if (fiv == 2 && sev == 1){
      cout << "YES" << endl;
    }
    else 
      cout << "NO" << endl;
      
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()

using namespace std;

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/

int main() {
	long long A,B,K,ans=1; cin >> A>>B>>K;
	for (int i = A;;i--) {
		if (A % i == 0 && B % i == 0) {
			if (ans == K) {
				cout << i << endl;
				break;
			}
			ans++;
		}
	}
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
        	arr[i] = sc.nextInt();
        Arrays.sort(arr);
        System.out.println(arr[n/2] - arr[n/2-1]);
    }
}


Measured memory_bytes: 50712
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
	int i,k;
	i=0; k=0;
	
	char W[12],T[20];
	
	scanf("%s",W);
	

	while(1){
		scanf("%s",&T);
		if(strcmp(T,"END_OF_TEXT") == 0)break;
	
		for(i = 0; T[i] != '\0'; i++){
    		T[i] = tolower(T[i]);
  		}
	
		if(strcmp(W,T) == 0)
			k++;
	}
	
	printf("%d\n", k);
	
	return 0;
	
}


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

const int mod = 1e9 + 7;
ll dp[2007];
int N;
ll go (int n) {
    if (n == 1 || n == 2) return  0;
    if (dp[n] != -1) return dp[n];
    return dp[n] = (go(n - 1) + go (n - 3)) % mod;
}
int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
 
    cin >> N;
    memset(dp, -1, sizeof dp);
    dp[0] = 1;
    cout << go(N) % mod << " ";
}



Measured memory_bytes: 3664
# B
a,b,k = list(map(int, input().split()))

def eat(a,b):
    a-= a%2
    b=int(b+a/2)
    a= int(a/2)
    return a,b

for i in range(k):
    if i%2==0:
        a,b = eat(a,b)
    else:
        b,a = eat(b,a)
print(a,b)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define mod 1000000007
#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a;i<b;i++)

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main(){
    FASTIO
    ll a,ans,b,d;
    char c;
    cin>>a>>b>>c>>d;
    b=100*b+d;
    ans=a*b/100;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#define NMAX 1005
using namespace std;
int n,m,i,j;
const long long MOD=1000000007;
long long d[NMAX][NMAX];
char c;
int main()
{
    cin>>n>>m;
    d[1][1]=1;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            cin>>c;
            if(i==1 && j==1)
                continue;
            if(c=='.')
                d[i][j]=(d[i-1][j]+d[i][j-1])%MOD;
        }
    }
    cout<<d[n][m];
    return 0;
}


Measured memory_bytes: 8064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		sc.close();

		int[] dp = new int[n];
		dp[1] = Math.abs(h[0] - h[1]);
		for (int i = 2; i < n; i++) {
			dp[i] = Math.min(
					dp[i - 2] + Math.abs(h[i] - h[i - 2]),
					dp[i - 1] + Math.abs(h[i] - h[i - 1]));
		}
		System.out.println(dp[n - 1]);
	}
}


Measured memory_bytes: 50856
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

    int n; cin >> n;

    string s, t; cin >> s >> t;

    int n_overlap = n;
    while(s.size() != 0){
        if(s == t){
            break;
        }
        else{
            n_overlap -= 1;
            s.erase(s.begin());
            t.pop_back();
        }
    }

    cout << 2*(n-n_overlap) + n_overlap << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<utility>
#include<algorithm>
using namespace std;
int n,ans[251000];
pair<int,int> e[510];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&e[i].first); e[i].second=i;
		ans[e[i].first]=i;
	}
	sort(e+1,e+n+1);
	int l=1,r=n*n;
	for (int i=1;i<=n;i++)
		for (int j=1;j<e[i].second;j++){
			while (ans[l]) l++;
			if (l>=e[i].first){
				puts("No");
				return 0;
			}
			ans[l++]=e[i].second;
		}
	for (int i=n;i>=1;i--)
		for (int j=e[i].second+1;j<=n;j++){
			while (ans[r]) r--;
			if (r<=e[i].first){
				puts("No");
				return 0;
			}
			ans[r--]=e[i].second;
		}
	puts("Yes");
	for (int i=1;i<n*n;i++) printf("%d ",ans[i]);
	printf("%d\n",ans[n*n]);
	return 0;
}


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

/**
 *
 * @author k16069kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        int n = 0;
        int m = 0;
        int l = 0;

        int matrix_A[][] = new int[100][100];
        int matrix_B[][] = new int[100][100];

        int a = 0;
        int b = 0;

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = br.readLine()) != null) {
            java.util.StringTokenizer st = new StringTokenizer(line, " ");
            while (st.hasMoreTokens()) {
                if (n == 0 && m == 0 && l == 0) {
                    n = Integer.parseInt(st.nextToken());
                    m = Integer.parseInt(st.nextToken());
                    l = Integer.parseInt(st.nextToken());
                } else {
                    if (a != n) {
                        for (int i = 0; i < m; i++) {
                            matrix_A[a][i] = Integer.parseInt(st.nextToken());
                        }
                        a++;
                    } else {
                        for (int i = 0; i < l; i++) {
                            matrix_B[b][i] = Integer.parseInt(st.nextToken());
                        }
                        b++;
                    }
                }
            }
            if (a == n && b == m) {
                break;
            }
        }

        long matrix_C[][] = new long[n][l];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < l; j++) {
                for (int k = 0; k < m; k++) {
                    matrix_C[i][j] += (matrix_A[i][k] * matrix_B[k][j]);
                }
            }
        }

        for (int i = 0; i < matrix_C.length; i++) {
            for (int j = 0; j < matrix_C[i].length; j++) {
                System.out.print(matrix_C[i][j]);
                if(!(j == l-1))System.out.print(" ");
            }
            System.out.println("");
        }

    }

}



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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    long long re = 0;
    cin >> n;
    int a[n + 1], b[n];
    for(int i = 0; i < n + 1; ++i) cin >> a[i];
    for(int i = 0; i < n; ++i) cin >> b[i];
    for(int i = 0; i < n; ++i){
        if(a[i] >= b[i]){
            re += b[i];
        }else{
            b[i] -= a[i];
            re += a[i];
            if(a[i + 1] < b[i]){
                re += a[i + 1];
                a[i + 1] = 0;
            }else{
                a[i + 1] -= b[i];
                re += b[i];
            }
        }
    }
    cout << re << endl;
    return 0;
}

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

using namespace std;

int n,v[110000],memo[2][110000],hoge[2][2],huga[2][2],x,z,maxx;

int main() {
    cin >> n;
    for (x=0 ; x<n ; x++) {
        cin >> v[x];
        memo[ x%2 ][ v[x] ]++;
        if (maxx < v[x]) maxx = v[x];
    }

    for (z = 0 ; z < 2 ; z++) {
        for (x = 0; x <= maxx; x++) {
            if (hoge[z][0] < memo[z][x]) {
                hoge[z][1] = hoge[z][0];
                hoge[z][0] = memo[z][x];
                huga[z][1] = huga[1][0];
                huga[z][0] = x;
            }
            else if(hoge[z][1] < memo[z][x]){
                hoge[z][1] = memo[z][x];
                huga[z][1] = x;
            }
        }
    }

    if(huga[0][0] != huga[1][0]) cout << n-hoge[0][0]-hoge[1][0] << "\n";
    else
        if(hoge[0][0]+hoge[1][1] > hoge[0][1]+hoge[1][0]) cout << n-hoge[0][0]-hoge[1][1] << "\n";
        else cout << n-hoge[0][1]-hoge[1][0] << "\n";
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
int main()
{
	lli a, b, c; cin >> a >> b >> c;
	lli arr1[a + 50], arr2[b + 50];
	lli pre1[a + 50] = {0}, pre2[b + 50] = {0};
	for(int i=1; i<=a; i++)
	{
		pre1[i] = pre1[i - 1];
		cin >> arr1[i];
		pre1[i] += arr1[i];
	}
	for(int i=1; i<=b; i++)
	{
		pre2[i] = pre2[i - 1];
		cin >> arr2[i];
		pre2[i] += arr2[i];
	}
	lli ans = 0;
	for(int i=0; i<=a; i++)
	{
		lli can = c - pre1[i];
		if(can < 0) break;
		lli left = 0, right = b, res;
		while(left <= right)
		{
			lli mid = (left + right) >> 1;
			if(pre2[mid] <= can)
			{
				res = mid;
				left = mid + 1;
			}
			else
			{
				right = mid - 1;
			}
		}
		ans = max(ans, i + res);
	}
	cout << ans << '\n';
}

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int cys=1000000007,N=50;
int n;
ll a[250005],b[250005],pw[250005],ipw[250005],ans[250005];
unordered_map<ll,ll> bk;
char s[250005];

ll mod(ll x){return x>=cys?x-cys:x;}

ll qpow(ll x,ll p){
	ll ret=1;
	for(;p;p>>=1,x=x*x%cys) if(p&1) ret=ret*x%cys;
	return ret;
}

int main(){
	n=readint();
	scanf("%s",s+1);
	for(int i=1;i<=n;i++) b[i]=b[i-1]+(s[i]=='>')-(s[i]=='<');
	memset(ans,0x3f,sizeof(ans));
	for(int ct=1;ct<=N;ct++){
		ll ax=(1ll*rand()*RAND_MAX+rand())%cys,bx=qpow(ax,cys-2),p=1,now=0;
		pw[0]=ipw[0]=1;
		for(int i=1;i<=n;i++) pw[i]=pw[i-1]*ax%cys;
		for(int i=1;i<=n;i++) ipw[i]=ipw[i-1]*bx%cys;
		for(int i=1;i<=n;i++){
			if(s[i]=='+') now=mod(now+p);
			else if(s[i]=='-') now=mod(now+cys-p);
			else if(s[i]=='<') p=p*bx%cys;
			else if(s[i]=='>') p=p*ax%cys;
		}
		a[n+1]=0;
		for(int i=n;i>=1;i--){
			if(s[i]=='+') a[i]=mod(a[i+1]+1);
			else if(s[i]=='-') a[i]=mod(a[i+1]+cys-1);
			else if(s[i]=='<') a[i]=a[i+1]*bx%cys;
			else if(s[i]=='>') a[i]=a[i+1]*ax%cys;
		}
		for(int i=1;i<=n;i++) a[i]=a[i]*(b[i-1]>0?pw[b[i-1]]:ipw[-b[i-1]])%cys;
		bk.clear();
		bk[0]++;
		for(int i=n;i>=1;i--){
			chkmin(ans[i],bk[mod(a[i]+cys-now*(b[i-1]>0?pw[b[i-1]]:ipw[-b[i-1]])%cys)]);
			bk[a[i]]++;
		}
		if(1.0*clock()/CLOCKS_PER_SEC>1.9) break;
	}
	ll res=0;
	for(int i=1;i<=n;i++) res+=ans[i];
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 31220
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long p = sc.nextLong();
        if (n >= 40) {
            System.out.println(1);
        } else if (n == 1) {
            System.out.println(p);
        } else {
            for (int i = (int)Math.sqrt(p); i > 0; i--) {
                if (p % (Math.pow(i, n)) == 0) {
                    System.out.println(i);
                    break;
                }
            }
        }
    }
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}

int n;
ll *a;
ll *b;
ll h;
int main(){
	startTime=clock();
	cin >> n >> h;
	a=new ll[n];
	b=new ll[n];
	FOR(i,n){
		cin >> a[i] >> b[i];
	}
	ll ans=0;
	sort(b,b+n);
	ll maxx=0;
	FOR(i,n){
		maxx=max(maxx,a[i]);
	}
	//ll sum=0;
	int i=n-1;
	int j=0;
	while(b[j]<= maxx) j++;
	while(h>0 && i >j-1){
		h-=b[i];
		i--;
		ans++;	
	}
	//error(ans,j,h);
	if(h > 0){
		ans+= h/maxx ;
	}
	if(h/maxx * maxx < h) ans++;
	cout << ans;

	return 0;
}


Measured memory_bytes: 5180
import itertools
N = int(input())
Nketa = len(str(N))

range_count = [[0 for j in range(10)]for i in range(10)]


for p in range(1,N+1):
    mae = int(str(p)[0])
    ato = int(str(p)[-1])
    range_count[mae][ato] += 1

    

count = 0
for j in range(1,N+1):
    a_mae = int(str(j)[0])
    a_ato = int(str(j)[-1])
    
    b_mae = a_ato
    b_ato = a_mae
    
    if b_mae == 0:
        continue
    else:
        count += range_count[b_mae][b_ato]
print(count)
  

Measured memory_bytes: 3064
from collections import deque

s = deque(input())
q = int(input())
reversed_flag = False

for i in range(q):
    query = input()
    if query == "1":
        reversed_flag = not reversed_flag
    else:
        t, f, c = query.split()
        if f == "1":
            if reversed_flag:
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if reversed_flag:
                s.appendleft(c)
            else:
                s.append(c)

if reversed_flag:
    s.reverse()

print("".join(s))

Measured memory_bytes: 8436
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>





using namespace std;


int main()
{
	double S, L, h, a, b ,C;
	double pi = 3.14159265359;

	cin >> a >> b >> C;

	h = b * sin(C * pi / 180.00);
	L = sqrt(pow(a, 2.0) + pow(b, 2.0) - 2 * a * b * cos(C * pi / 180)) + a + b;
	S = a * h / 2;

	cout << fixed << S << endl <<  L << endl << h << endl;
	

	
}

Measured memory_bytes: 3436
#include<stdio.h>

int main() {
	int a,b,i;
	while(1) {
		scanf("%d %d", &a, &b);
		if(a ==0 && b == 0) break;
		for(; a > 0; a--) {
			for(i = 0; i < b; i++) {
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 572