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

long long cnt = 0;
void saveL(long long i, vector<long long> &a, vector<long long> &b) {
  if (a.at(i) >= b.at(i)) {
    cnt += b.at(i);
    a.at(i) -= b.at(i);
    b.at(i) = 0;
  }
  else if (a.at(i) + a.at(i + 1) >= b.at(i)) {
    cnt += b.at(i);
    b.at(i) -= a.at(i);
    a.at(i) = 0;
    a.at(i + 1) -= b.at(i);
    b.at(i) = 0;
  }
  else {
    cnt += a.at(i) + a.at(i + 1);
    b.at(i) -= a.at(i) + a.at(i + 1);
    a.at(i) = 0;
    a.at(i + 1) = 0;
  }
}
void saveR(long long i, vector<long long> &a, vector<long long> &b) {
  if (a.at(i + 1) >= b.at(i)) {
    cnt += b.at(i);
    a.at(i + 1) -= b.at(i);
    b.at(i) = 0;
  }
  else if (a.at(i) + a.at(i + 1) >= b.at(i)) {
    cnt += b.at(i);
    b.at(i) -= a.at(i + 1);
    a.at(i + 1) = 0;
    a.at(i) -= b.at(i);
    b.at(i) = 0;
  }
  else {
    cnt += a.at(i) + a.at(i + 1);
    b.at(i) -= a.at(i) + a.at(i + 1);
    a.at(i) = 0;
    a.at(i + 1) = 0;
  }
}

int main() {
  long long n;
  cin >> n;
  vector<long long> a(n + 1), b(n);
  for (long long i = 0; i < n + 1; i++) cin >> a.at(i);
  for (long long i = 0; i < n; i++) cin >> b.at(i);
  for (long long i = 0; i < n / 2; i++) saveL(i, a, b);
  for (long long i = 0; i < n / 2; i++) saveR(n - 1 - i, a, b);
  if (b.at(n / 2) <= a.at(n / 2) + a.at(n / 2 + 1))
    cnt += b.at(n / 2);
  else cnt += a.at(n / 2) + a.at(n / 2 + 1);
  cout << cnt << endl;
}


Measured memory_bytes: 1792
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

const MOD: i64 = 1000000007;

#[fastout]
pub fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let mut s = vec![0; n];
    s[0] = a[0];
    for i in 1..n {
        s[i] = s[i - 1] + a[i];
        s[i] %= MOD;
        if s[i] < 0 {
            s[i] += MOD;
        }
    }

    let mut p = 0;
    for i in 0..(n - 1) {
        let mut t = s[n - 1] - s[i];
        t %= MOD;
        t = a[i] * t;
        t %= MOD;
        p += t;
        p %= MOD;
        if p < 0 {
            p += MOD;
        }
    }
    println!("{}", p);
}


Measured memory_bytes: 7236
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int H,W;
    cin >> H >> W;
    vector<string>S(H);
    int sum = 0;
    for(int i = 0; i < H; i++) {
        cin >> S[i];
        for(int j = 0; j < W; j++) {
            if(S[i][j] == '#') {
                sum++;
            }
        }
    }
    vector<vector<int>>cnt(H,vector<int>(W,INF));
    cnt[0][0] = 0;
    queue<P>que;
    que.push({0,0});
    while(!que.empty()) {
        P X = que.front();
        que.pop();
        for(int i = 0; i < 4; i++) {
            int nx = X.first+dx[i];
            int ny = X.second+dy[i];
            if(nx >= 0 && nx < H && ny >= 0 && ny < W) {
                if(cnt[nx][ny] == INF && S[nx][ny] == '.') {
                    cnt[nx][ny] = cnt[X.first][X.second]+1;
                    que.push({nx,ny});
                }
            }
            if(nx == H-1 && ny == W-1) {
                cout << H*W-cnt[nx][ny]-sum-1 << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3620
import java.util.Scanner;

/**
 * Main
 */
public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        // 整数の入力
        final int N = sc.nextInt();
        int[] A = new int[N];
        int flag = 0;

        for (int i = 0; i < N; i++){
            A[i] = sc.nextInt();
            if(A[i] % 2 == 0){
                if(A[i] % 3 == 0 || A[i] % 5 == 0){

                }else{
                    flag = 1;
                }
            }
        }

        if(flag == 0){
            System.out.println("APPROVED");
        }else{
            System.out.println("DENIED");
        }
        
        
    }
}

Measured memory_bytes: 22100
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
int h,w;
int dx[]={0,0,-1,-1,-1,1,1,1};
int dy[]={1,-1,0,1,-1,1,-1,0};
bool inrange(int y,int x){return (0<=x&&x<w&&0<=y&&y<h);}
signed main(){
    cin>>h>>w;
    vector<vector<char>>v(h,vector<char>(w));
    rep(i,h)rep(j,w)cin>>v[i][j];
    vector<vector<int>>ans(h,vector<int>(w,INF));
    rep(i,h){
        rep(j,w){
            int hoge=0;
            if(v[i][j]=='#')continue;
            rep(k,8){
                int x=j+dx[k];
                int y=i+dy[k];
                if(!inrange(y,x))continue;
                if(v[y][x]=='#')hoge++;
            }
            ans[i][j]=hoge;
        }
    }
    rep(i,h){
        rep(j,w){
            if(ans[i][j]==INF)cout<<'#';
            else cout<<ans[i][j];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#define ll long long 
using namespace std;
int n, m, x, y;
char a[200005], b[200005];
int n1[26], n2[26];
int i = 0, j = 0;
int main()
{
	cin >> a;
	cin >> b;
	while (a[i] != '\0')
	{
		if (a[i] >= 'a'&&a[i] <= 'z')
			n1[a[i] - 'a']++;
		i++;
	}
	while (b[j] != '\0')
	{
		if (b[j] >= 'a'&&b[j] <= 'z')
			n2[b[j] - 'a']++;
		j++;
	}
	sort(n1, n1 + 26);
	sort(n2, n2 + 26);
	for (int k = 0; k < 26; k++)
	{
		if (n1[k] == n2[k])
			continue;
		else
		{
			cout << "No";
			goto here;
		}
	}
	cout << "Yes";
	here:
	return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

int main(void) {
  cout.precision(12);

  long N, X;
  cin >> N >> X;

  long result = 1;
  long current = 0;

  rep (i, N) {
    long L;
    cin >> L;
    current += L;
    if (current <= X) result ++;
    else break;
  }

  cout << result << endl;

  return 0;
}


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

using namespace std;

const int ms = 1e5 + 18;
int l[ms], r[ms], dp[ms];
bool prime[ms];

void fll(int n)
{
    for(int i = 2; i <= n; ++i)
        prime[i] = true;
    for(int i = 2; i <= n; ++i)
    {
        for(int j = 2; j * j <= i; ++j)
        {
            if(i % j == 0)
                prime[i] = false;
        }
    }
}


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

    int q;
    cin >> q;

    int rmax = 0;
    for(int i = 1; i <= q; ++i)
    {
        cin >> l[i] >> r[i];

        rmax = max(rmax, r[i]);
    }

    fll(rmax);

    dp[1] = 0;
    for(int i = 2; i <= rmax; ++i)
    {
        dp[i] += dp[i - 1];
        if((i % 2) == 1)
        {
             if(prime[i] && prime[(i + 1) / 2])
                ++dp[i];
        }

    }

    for(int i = 1; i <= q; ++i)
    {
        cout << dp[r[i]] - dp[l[i] - 1] << '\n';
    }


}


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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define ll  long long
#define ull unsigned long long

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

#define vi      vector<int>
#define pii     pair<int,int>
#define piii    pair<pair<int,int>,int>
#define all(v)  v.begin(), v.end()

int mod = 1000000007;
const int N = 100005;

// gcd
ll gcd(ll a , ll b)
{
    if ( b == 0)
    return a;
    return gcd( b, a % b);
}
int dist[N];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	priority_queue<pii> pq;
	cin >> n;
	for ( int i = 0; i < n; i++)
		dist[i] = mod;
	for ( int i = 1; i < 10; i++)

	{
		dist[i] = min(i,dist[i]);
		pq.push({-i,i % n});
	}
	while(!pq.empty())
	{
		int node = pq.top().se;
		int cost = -pq.top().fi;
		pq.pop();
		if ( cost > dist[node])
			continue;
		for ( int i = 0; i < 10; i++)
		{
			int next = (node*10 + i)%n;
			int p = cost + i;
			if ( p < dist[next])
			{
				dist[next] = p;
				pq.push({-p,next});
			}


		}
	}
	cout << dist[0] << endl;
	return 0;
}


Measured memory_bytes: 2804
S=str(input())
N=len(S)
dp=[[0 for _ in range(4)] for _ in range(N+1)]
dp[0][0]=1
mod=10**9+7
for i in range(N):
  if S[i]=='A':
    dp[i+1][0]+=dp[i][0]%mod
    dp[i+1][1]+=dp[i][1]%mod+dp[i][0]%mod
    dp[i+1][2]+=dp[i][2]%mod
    dp[i+1][3]+=dp[i][3]%mod
  if S[i]=='B':
    dp[i+1][0]+=dp[i][0]%mod
    dp[i+1][1]+=dp[i][1]%mod
    dp[i+1][2]+=dp[i][2]%mod+dp[i][1]%mod
    dp[i+1][3]+=dp[i][3]%mod
  if S[i]=='C':
    dp[i+1][0]+=dp[i][0]%mod
    dp[i+1][1]+=dp[i][1]%mod
    dp[i+1][2]+=dp[i][2]%mod
    dp[i+1][3]+=dp[i][3]%mod+dp[i][2]%mod
  if S[i]=='?':
    dp[i+1][0]+=3*dp[i][0]%mod
    dp[i+1][1]+=(3*dp[i][1])%mod+dp[i][0]%mod
    dp[i+1][2]+=(3*dp[i][2])%mod+dp[i][1]%mod
    dp[i+1][3]+=(3*dp[i][3])%mod+dp[i][2]%mod
print(dp[N][3]%mod)

Measured memory_bytes: 28644
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<time.h>
#include<vector>
using namespace std;
int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    int n;
    int ans = 0;
    char str[55];
    scanf("%d",&n);
    scanf(" %s",str);
    for(int i=0; i<n; ++i){
        if(str[i]=='A' && i<n-2){
            if(str[i+1]=='B')
                if(str[i+2]=='C')
                    ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 3784
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		short a = sc.nextShort();
		short b = sc.nextShort();
		short c = sc.nextShort();
		short d = sc.nextShort();

		System.out.println(Math.max(a * b, c * d));
	}
}

Measured memory_bytes: 35168
private fun readInts() = readLine()!!.split(" ").map { it.toInt() }

fun main(args: Array<String>) {
    val (A, B, C, D) = readLine()!!.toList().map { it.toString().toInt() }

    val plus: (Int, Int) -> Int = { left, right -> left + right }
    val minus: (Int, Int) -> Int = { left, right -> left - right }
    val opSet = setOf(plus, minus)

    fun ((Int, Int) -> Int).toSymbolText() = when (this) {
        plus -> "+"
        minus -> "-"
        else -> "?"
    }

    for (op1 in opSet) {
        for (op2 in opSet) {
            for (op3 in opSet) {
                val answer = op3(op2(op1(A, B), C), D)
                
                if (answer == 7) {
                    println("${A}${op1.toSymbolText()}${B}${op2.toSymbolText()}${C}${op3.toSymbolText()}${D}=7")
                    return
                }
            }
        }
    }
}

Measured memory_bytes: 38360
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),s=0,t,i,j;
		sc.close();
		for(i=1;i<=n;i+=2) {
			t=0;
			for(j=1;j<=i;j++) if(i%j==0) t++;
			if(t==8) s++;
		}
		System.out.print(s);
	}
}

Measured memory_bytes: 23892
from collections import deque

class task:
  
  def __init__(self,name,time):
    self.name = name
    self.time = time
    self.remain = time
  
  def getName(self):
    return self.name
  
  def getTime(self):
    return self.time
  
  def getRemain(self,wtime):
    self.remain -= wtime
    return self.remain

  

queue = deque()  

n, q = map(int,input().split())
for i in range(n):
  aN,aQ = input().split()
  aTask = task(aN,int(aQ))
  queue.append(aTask)

elapse = 0
remain = 0

while len(queue) > 0:
  aTask = queue.popleft()
  remain = aTask.getRemain(q)
  if remain <= 0 :
    elapse += remain + q
    print(aTask.getName() , elapse)
  else:
    elapse += q
    queue.append(aTask)


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

static int N, A, B, C;
static int LEN[8];

int min(int x, int y) {
  return (x < y) ? x : y;
}

int search(int i, int a, int b, int c) {
  if(i == N) {
    int cost = abs(a - A) + abs(b - B) + abs(c - C) - 30;
    if (a == 0 || b == 0 || c == 0) {
      return (int)100000000;
    } else {
      return (int)cost;
    }
  }
  
  int cost1 = search(i+1, a, b, c);
  int cost2 = search(i+1, a+LEN[i], b, c) + 10;
  int cost3 = search(i+1, a, b+LEN[i], c) + 10;
  int cost4 = search(i+1, a, b, c+LEN[i]) + 10;
  return min(min(cost1, cost2), min(cost3, cost4));
}

int main(void) {
  scanf("%d%d%d%d", &N, &A, &B, &C);
  for(int i = 0; i < N; i++) {
    scanf("%d", &LEN[i]);
  }
  printf("%d\n", search(0, 0, 0, 0));
  return 0;
}


Measured memory_bytes: 128
n, a, b, c = map(int, input().split())
s = [input() for i in range(n)]

ans = []
for i in range(n):
    if s[i] == "AB":
        if a == 0 and b == 0:
            print("No")
            exit()
        if a == 1 and b == 1:
            if i + 1 < n and s[i + 1] == "AC":
                a += 1
                b -= 1
                ans.append("A")
            else:
                a -= 1
                b += 1
                ans.append("B")
        elif a <= b:
            b -= 1
            a += 1
            ans.append("A")
        else:
            b += 1
            a -= 1
            ans.append("B")
            
    if s[i] == "BC":
        if b == 0 and c == 0:
            print("No")
            exit()
        if b == 1 and c == 1:
            if i + 1 < n and s[i + 1] == "AB":
                b += 1
                c -= 1
                ans.append("B")
            else:
                b -= 1
                c += 1
                ans.append("C")
        elif b <= c:
            c -= 1
            b += 1
            ans.append("B")
        else:
            c += 1
            b -= 1
            ans.append("C")
    if s[i] == "AC":
        if a == 0 and c == 0:
            print("No")
            exit()
        if a == 1 and c == 1:
            if i + 1 < n and s[i + 1] == "BC":
                c += 1
                a -= 1
                ans.append("C")
            else:
                c -= 1
                a += 1
                ans.append("A")
        elif a <= c:
            c -= 1
            a += 1
            ans.append("A")
        else:
            c += 1
            a -= 1
            ans.append("C")
print("Yes")
for i in ans:
    print(i)


Measured memory_bytes: 85968
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = j; i < n; ++i)
template <class T>
using vt = vector<T>;
template <class T>
using vvt = vector<vector<T>>;

int main() {
  int n, m;
  cin >> n >> m;
  vt<int> k(m);
  vvt<int> s(m);
  rep(i, 0, m) {
    cin >> k[i];
    rep(j, 0, k[i]) {
      int tmp;
      cin >> tmp;
      tmp--;
      s[i].push_back(tmp);
    }
  }
  vt<int> p(m);
  rep(i, 0, m) cin >> p[i];

  int ans = 0;
  rep(bit, 0, (1 << n)) {
    bool ok = true;
    rep(i, 0, m) {
      int sum = 0;
      rep(j, 0, k[i]) {
        if (bit & (1 << s[i][j])) sum++;
      }
      if (sum % 2 != p[i]) ok = false;
    }
    if (ok) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)
// #define multicase
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int N = 1e5 + 5;

int n, k, q;
int a[N];

void solve() {
    int T = 1;
  #ifdef multicase
    cin >> T;
  #endif
    for(int tc = 1; tc <= T; tc++) {
        cin >> n >> k >> q;
        for(int i = 1; i <= n; i++) {
            a[i] = k;
        }
        for(int i = 1, x; i <= q; i++) {
            cin >> x;
            a[x]++;
        }
        for(int i = 1; i <= n; i++) {
            cout << (a[i] - q <= 0 ? "No\n" : "Yes\n");
        }
    }
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    solve();
    
}

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

int64_t abso(int64_t v)
{
    return (v < 0) ? -v : v;
}

uint64_t min(uint64_t a, uint64_t b)
{
    return (a < b) ? a : b;
}


int main(int argc, const char * argv[]) {
    uint64_t N, K;
    cin >> N;
    cin >> K;
    
    uint64_t ans = N % K;
    if (ans != 0) {
        ans = min(ans, abso(ans - K));
    }
    
    std::cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int N, sum[310][310], dp[310][310];

// [lx, rx), [ly, ry) (0-indexed)
int part_sum(int lx, int ly, int rx, int ry) {
    return sum[rx][ry] - sum[lx][ry] - sum[rx][ly] + sum[lx][ly];
}

signed main() {
    cin >> N;
    for(int i=1; i<=N; i++) {
        for(int j=1; j<=N; j++) {
            cin >> sum[i][j];
        }
    }
    for(int i=1; i<=N; i++) {
        for(int j=1; j<=N; j++) {
            sum[i][j] += sum[i][j-1];
        }
    }
    for(int j=1; j<=N; j++) {
        for(int i=1; i<=N; i++) {
            sum[i][j] += sum[i-1][j];
        }
    }

    int ans = -INF;
    for(int l=0; l<N; l++) {
        for(int r=l+1; r<=N; r++) {
            // 1 行だけの場合 (0 行目のみ)
            dp[l][r] = part_sum(0, l, 1, r);
            chmax(ans, dp[l][r]);
        }
    }

    for(int d=1; d<N; d++) {
        for(int l=0; l<N; l++) {
            for(int r=l+1; r<=N; r++) {
                // 1 行だけの場合
                chmax(ans, part_sum(d, l, d, r));

                // 複数行ある場合
                int cand1 = -INF, cand2 = -INF;
           
                // そのまま伸ばす場合 (d == 1 ならやらない)
                if(d > 1) {
                    cand1 = dp[l][r];
                    
                    // d-1 行目の内側の面積 (r - l >= 3 の場合のみ)
                    if(r - l >= 3) cand1 -= part_sum(d-1, l+1, d, r-1);

                    // d 行目の面積
                    cand1 += part_sum(d, l, d+1, r);
                }
                
                // 切って d-1 行目を上端にする場合
                {
                    cand2 = part_sum(d-1, l, d+1, r);
                }

                dp[l][r] = max(cand1, cand2);
                chmax(ans, dp[l][r]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pk(x) cout<<(x)<<" ";
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define p2d(v,n,m) rep(i,n){rep(j,m){pk(v[i][j]);}p("");}
#define fi first
#define se second
ll a[100001],b[100001],c[100001],d,n,m,x,y,z,h,w,k,sum,mi=inf,ma=-inf,ans,s,t,l,r,res,tmp,itr,p,q;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef map<ll, ll> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<ll,ll> > VP;
P pa;

ll dp[1010][20010];


int main(){
    cin>>h>>n;
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    rep(i,1001)rep(j,20010){
        dp[i][j]=inf;
    }
    dp[0][0]=0;
    rep(i,n+1)rep(j,h+1){
         dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
         dp[i+1][min(j+a[i],h)]=min(dp[i+1][min(j+a[i],h)],dp[i+1][j]+b[i]);
    }
    //p2d(dp,15,15);
    p(dp[n][h]);
    return 0;
}


Measured memory_bytes: 160000
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i + k < n; i++) {
		    if (arr[i] >= arr[i + k]) {
		        sb.append("No");
		    } else {
		        sb.append("Yes");
		    }
		    sb.append("\n");
		}
		System.out.print(sb);
	}
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;

int32_t main()
{
	IOS;
	priority_queue <int> p; 	
	int n,k;
	cin >> n >> k;
	rep(i,1,n)
	{
		int x;
		cin >> x;
		p.push(x);
	}
	while(k>0 && p.top()>0)
	{
		int x= p.top();
		p.pop();
		x=x/2;
		k--;
		p.push(x);
	}
	int ans=0;
	while(p.size()>0)
	{
		ans += p.top();
		p.pop();
	}
	cout << ans << endl;
}


Measured memory_bytes: 1400
/*
    JAI JAGANNATH!
*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<lli>
#define mii             map<lli,lli>
#define pqb             priority_queue<lli>
#define pqs             priority_queue<lli,vi,greater<lli> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            lli x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

void ss()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}
void solve() {
	lli n;
	cin >> n;
	lli k;
	cin >> k;
	vector <lli> v(n);
	for (lli i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());

	lli ret = 0;
	for (lli i = 0; i < k ; i++) {
		ret += v[i];
	}
	cout << ret << endl;
}
int main()
{
	ss();
	solve();
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define debug(x) cout << #x << " = " << x << endl
#define print(x) cout << x << endl;
const ll MOD = 1000000007;

int main()
{
    int N, K, R, S, P;
    cin >> N >> K >> R >> S >> P;
    string T;
    cin >> T;
    string myHand;

    int score = 0;
    rep(i, N)
    {
        if (T[i] == 'r')
        {
            if (i < K)
            {
                myHand.push_back('p');
                score += P;
            }

            else if (i - K >= 0 && myHand[i - K] != 'p')
            {
                myHand.push_back('p');
                score += P;
            }
            else
            {
                myHand.push_back('X');
            }
        }
        else if (T[i] == 'p')
        {

            if (i < K)
            {
                myHand.push_back('s');
                score += S;
            }

            else if (i - K >= 0 && myHand[i - K] != 's')
            {
                myHand.push_back('s');
                score += S;
            }
            else
            {
                myHand.push_back('X');
            }
        }

        else
        {
            if (i < K)
            {
                myHand.push_back('r');
                score += R;
            }

            else if (i - K >= 0 && myHand[i - K] != 'r')
            {
                myHand.push_back('r');
                score += R;
            }
            else
            {
                myHand.push_back('X');
            }
        }
    }

    cout << score << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  char c; cin >> c;
  if(c=='A')cout << 'T' << endl;
  if(c=='T')cout << 'A' << endl;
  if(c=='C')cout << 'G' << endl;
  if(c=='G')cout << 'C' << endl;

}

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

int main(){
	int n,x,y,h,w;
	long long int cnt;
	while(cin >> n,n){
		cnt = 0ll;
		for(int i = 0;i < n;i++){
		cin >> x >> y >> h >> w;
		if(x + y + h <= 60 && w <= 2) cnt += 600ll;
		else if(x + y + h <= 80 && w <= 5) cnt += 800ll;
		else if(x + y + h <= 100 && w <= 10) cnt += 1000ll;
		else if(x + y + h <= 120 && w <= 15) cnt += 1200ll;
		else if(x + y + h <= 140 && w <= 20) cnt += 1400ll;
		else if(x + y + h <= 160 && w <= 25) cnt += 1600ll;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int dp[21][100000];

signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];
    int l;
    cin >> l;

    rep(i,n){
        dp[0][i] = upper_bound(all(a), a[i] + l) - a.begin() - 1;
    }
    rep(k,20)rep(i,n){
        dp[k+1][i] = dp[k][dp[k][i]];
    }

    int q;
    cin >> q;
    rep(i, q){
        int a,b;
        cin >> a >> b;
        a--,b--;
        if (b<a) swap(a, b);
        int ans = 0;
        for (int k = 20; k >= 0; k--) if (dp[k][a] < b){
            a = dp[k][a];
            ans += 1 << k;
        }
        cout << ans + 1 << endl;
    }

}


Measured memory_bytes: 18048
N=int(input())
A=list(map(int,input().split()))
L=1
ans=0
for i in range(N):
  if A[i]!=L:
    ans+=1
  else:
    L+=1

if N==1 and A[0]==1:
  print(0)
elif 1 not in A:
  print(-1)
else:
  print(ans)
  
  

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

const long long modnum = 1000000007;

int main(){
	int n, k;
	long long ans = 0;
	long long mi = 0, ma = 0;

	cin >> n >> k;

	for(int j=0; j<k; j++){
		mi =  (mi + j) % modnum;
		ma = (ma + (n - j)) % modnum;
	}

	for(int i=k; i<=n+1; i++){
		ans = (ans + (ma - mi + 1)) % modnum;
		mi = (mi + i) % modnum;
		ma = (ma + n - i) % modnum;
	}

	while(ans < 0){
		ans += modnum;
	}

	cout << ans << endl;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e15;
typedef pair<int,int> ii;
typedef vector<int> vi;


const int max_item_cnt=100;
const int max_knapsack_size=1e5;
ll W[max_item_cnt],V[max_item_cnt];
ll dp[max_knapsack_size]; // dp[i] - max sum of values with i space
 
int main(){
	ll n,w;
	cin>>n>>w;
	for(int i=1;i<=n;i++){
		cin>>W[i]>>V[i];
	}
	
	for(int i=1;i<=n;i++){
		for(int j=w;j>=W[i];j--){//go backwards to not repeat items
			dp[j]=max(dp[j],dp[j-W[i]]+V[i]);
		}
	}
	ll best_solution=0;
	for(int i=1;i<=w;i++){
		best_solution=max(best_solution,dp[i]);
	}
	cout<<best_solution;
 
	return 0;
}

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

int main()
{
	int q, u1, f1, u2, f2, d[6];
	for (int i = 0; i < 6; i++)
		cin >> d[i];
	cin >> q;
	int *r = new int[q];
	for (int i = 0; i < q; i++) {
		cin >> u1 >> f1;
		for (int j = 0; j < 6; j++) {
			if (d[j] == u1)
			u2 = j;
		}
		for (int j = 0; j < 6; j++) {
			if (d[j] == f1)
			f2 = j;
		}
		if (u2 == 0) {
			if (f2 == 1)
				r[i] = d[2];
			else if (f2 == 2)
				r[i] = d[4];
			else if (f2 == 4)
				r[i] = d[3];
			else
				r[i] = d[1];
		}
		if (u2 == 1) {
			if (f2 == 0)
				r[i] = d[3];
			else if (f2 == 3)
				r[i] = d[5];
			else if (f2 == 5)
				r[i] = d[2];
			else
				r[i] = d[0];
		}
		if (u2 == 2) {
			if (f2 == 0)
				r[i] = d[1];
			else if (f2 == 1)
				r[i] = d[5];
			else if (f2 == 5)
				r[i] = d[4];
			else
				r[i] = d[0];
		}
		if (u2 == 3) {
			if (f2 == 0)
				r[i] = d[4];
			else if (f2 == 4)
				r[i] = d[5];
			else if (f2 == 5)
				r[i] = d[1];
			else
				r[i] = d[0];
		}
		if (u2 == 4) {
			if (f2 == 0)
				r[i] = d[2];
			else if (f2 == 2)
				r[i] = d[5];
			else if (f2 == 5)
				r[i] = d[3];
			else
				r[i] = d[0];
		}
		if (u2 == 5) {
			if (f2 == 1)
				r[i] = d[3];
			else if (f2 == 3)
				r[i] = d[4];
			else if (f2 == 4)
				r[i] = d[2];
			else
				r[i] = d[1];
		}
	}
	for (int i = 0; i < q; i++)
		cout << r[i] << endl;
	delete [] r;
	return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;

int main(){
    ll i,j;
    ll n;
    cin>>n;

    ll a[n+1],b[n+1];
    a[0]=0;
    b[0]=0;

    for(i=1;i<=n;i++){
        ll x;
        cin>>x;
        a[i]=a[i-1]+x;
    }
    for(i=1;i<=n;i++){
        ll x;
        cin>>x;
        b[i]=b[i-1]+x;
    }

    ll t=-1;
    for(i=1;i<=n;i++){
        ll ans=0;
        ans+=a[i]+b[n]-b[i-1];
        t=max(ans,t);
    }
    cout<<t<<endl;



    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>
 
using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
 
 
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
 
//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n;
	cin>>n;
	vector<double> a(n,0);
	REP(i,n) cin>> a[i];
	double mid=0;
	REP(i,n) mid+=a[i];

	mid/=(double)n;

	ll ans=0;
	double del=abs(mid-a[0]);
	ll ans_i=0;
	REP(i,n){
		if(del>abs(mid-a[i])){
			del=abs(mid-a[i]);
			ans_i=i;
		}
	}

	cout<<ans_i<<endl;

	return 0;
}


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

ll count(ll k) {
    return k == 1 ? 1 : 1 + count(k / 2) * 2;
}

int main() {
  ll h;
  cin >> h;
  cout << count(h) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

	int A;
	int B;
    int T;

	scanf("%d", &A);
	scanf("%d", &B);     
    scanf("%d", &T);
    
    int K = T / A * B;
    
    printf("%d",K);

      
  
	return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  re0 x=0,f=1;rec c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline void read(rel &x){
  x=0;re0 f=1;rec c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  x=f?x:-x;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  re0 bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  rec c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;

int main(){
puts(read()*read()&1?"Odd":"Even");
}

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

int n,k,i,j;
vector<int> d;

void dfs(int);

int main(){
    cin>>n>>k;
    d.resize(k);
    for(i=0;i<k;i++){cin>>d[i];}



    dfs(n);
    return 0;
}

void dfs(int x){
    int dis,div=1,keta=0,num=x;

    while(num>0){
        num/=10;
        keta++;
    }

    bool distin=true;//嫌いな数字がなければtrue あればfalse
    for(i=0;i<keta;i++){
        dis=x/div;dis%=10;
        for(j=0;j<k;j++){
            if(dis==d[j]){
                distin=false;
                break;break;
            }
        }
        div*=10;
    }

    
    if(distin && x>=n){
        cout<<x<<endl;
        return;
    }else{
        dfs(x+1);
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,ans=0,a[110],b[110],q;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int s=0;s<n;s++)
	{
		cin>>b[s];
	}
	for(int j=0;j<n;j++)
	{
		q=0;
		for(int k=0;k<=j;k++)
		{
			q+=a[k]; 
		}
		for(int m=j;m<n;m++)
		{
			q+=b[m];
		}
		if(q>ans)
		{
			ans=q;
		}
	}
	cout<<ans;
    return 0;	
} 	

Measured memory_bytes: 256
#include <cstdio>

const int MAXK = 1e5+5, MAXN = 1e2+2;


bool solved[MAXK], win[MAXK];
int a[MAXN];
int n, k;

bool dp(int t) {
  if (solved[t]) return win[t];

  solved[t] = 1;
  for (int i = 0; i < n; ++i) {
    if (t - a[i] < 0) continue;
    if (dp(t-a[i]) == 0) win[t] = 1;
  }

  return win[t];
}

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
  }

  printf("%s\n", dp(k) ? "First" : "Second");
  return 0;
}


Measured memory_bytes: 4992
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
inline 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; 
}
string s1,s2;
int main() {
	cin>>s1;s1=s1+s1;// cout<<s1;
	cin>>s2;int l=s2.size();
	int pos=s1.find(s2);
	for(int i=pos;i<pos+l;i++) if(s1[i]!=s2[i-pos])
		return puts("No"),0;
	puts("Yes");
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

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

  ll A , B ; cin >> A >> B ;
  ll N = A*B;
  if(N%2 == 1) cout << "Odd" << endl;
  else cout << "Even" << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = 100000
k = int(input())

ll_list = []

def ll(d, v):
  if d==10:
    return
  
  r = v%10
  v = v*10
  
  for i in (-1, 0, 1):
    if r+i>=0 and r+i<=9:
      ll(d+1, v+r+i)
      ll_list.append(v+r+i)
      
for i in range(1, 10):
  r = i%10
  v = i*10
    
  ll_list.append(i)
  for j in (-1, 0, 1):
    if r+j>=0 and r+j<=9:
      ll(1, v+r+j)
      ll_list.append(v+r+j)
      
      
ll_list.sort()
print(ll_list[k-1])

Measured memory_bytes: 29496
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};


int main() {

	string s; cin >> s;
	int ff = stoi(s.substr(0, 2));
	int ss = stoi(s.substr(2));

	if (((0 < ff) and (ff < 13)) and ((0 < ss) and (ss < 13))) cout << "AMBIGUOUS";
	else if ((ff >= 13 || ff == 0) and ((0 < ss) and (ss < 13))) cout << "YYMM";
	else if (((0 < ff) and (ff < 13))  and (ss >= 13 || ss== 0)) cout << "MMYY";
	else cout << "NA";


	return 0;
}

Measured memory_bytes: 3656
n,m = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
x = [x[i+1]-x[i] for i in range(n-1)]
y = [y[i+1]-y[i] for i in range(m-1)]
mod = 10**9+7
sumx = 0
sumy = 0
for i in range(n-1):
    sumx += x[i]*(i+1)*(n-1-i)%mod
for i in range(m-1):
    sumy += y[i]*(i+1)*(m-1-i)%mod
print(sumx*sumy%mod)

Measured memory_bytes: 18684
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstring>
#include<sstream>
#include<string>
using namespace std;
char a[10];int n;
struct node{
   long long zhi;
   node *left;
   node *right;
   node *parent;
   node():left(NULL),right(NULL),parent(NULL){};
};
node *root;
node *f(node *s,int k,node *p)
{
   if(s==NULL)
    {
        s=new node();
        s->zhi=k;
        s->parent=p;
        if(p==NULL) root=s;
    }
    else if(k<s->zhi)
    {
        s->left=f(s->left,k,s);
    }
    else
    {
        s->right=f(s->right,k,s);
    }
    return s;
}
bool flag;
node *myfind(node *p,long long k)
{
 /*   if(p->zhi==k)
    {
        flag=true;
    }
    if(p->left!=NULL&&k<p->zhi) myfind(p->left,k);
    if(p->right!=NULL&&k>p->zhi) myfind(p->right,k);
    return flag;*/
    while(p!=NULL&&p->zhi!=k)
    {
        if(k<p->zhi) p=p->left;
        else p=p->right;
    }
    return p;
}
node *minx(node *p)
{
    while(p->left!=NULL)
    {
        p=p->left;
    }
    return p;
}
node *xia(node *p)
{
    if(p->right!=NULL) return minx(p->right);
    node *y=p->parent;
    while(y!=NULL&&y->left!=p)
    {
        p=y;
        y=y->parent;
    }
    return y;
}
void mydelete(node *p)
{
    node *y,*x;
    if(p->left==NULL&&p->right==NULL)
    {
        y=p;
    }
    else y=xia(p);
    if(y->left!=NULL)
    {
        x=y->left;
    }else {
        x=y->right;
    }
    if(x!=NULL){
        x->parent=y->parent;
    }
    if(y->parent==NULL){
        root=x;
    }
    else {
        if(y==y->parent->left)
        {
            y->parent->left=x;
        }else{
            y->parent->right=x;
        }
    }
    if(y!=p){
        p->zhi=y->zhi;
    }
}
void f2(node *p)
{
    if(p==NULL) return;
    printf(" %d",p->zhi);
    f2(p->left);
    f2(p->right);
}
void f1(node *p)
{
    if(p==NULL) return ;
    f1(p->left);
    printf(" %d",p->zhi);
    f1(p->right);
}
int main()
{
    int h;
    scanf("%d",&h);
    for(int i=0;i<h;i++)
    {
        scanf("%s",a);
        if(!strcmp(a,"insert"))
        {
            scanf("%d",&n);
            f(root,n,NULL);
        }
        else if(!strcmp(a,"print"))
        {
            f1(root);
            printf("\n");
            f2(root);
            printf("\n");
        }
        else if(!strcmp(a,"find"))
        {
            scanf("%d",&n);
            flag=false;
            node *o=myfind(root,n);
            if(o!=NULL)
            {
                printf("yes\n");
            }
            else printf("no\n");
        }
        else if(!strcmp(a,"delete"))
        {
            scanf("%d",&n);
            mydelete(myfind(root,n));
        }
    }
    return 0;
}

Measured memory_bytes: 21904
#include <iostream>
using namespace std;
#define m  1000000007

int main()
{
  long long n, i;
  string s;
  long long a[26];
  long long ans = 1;

  cin >> n >> s;
  for (i = 0; i < 26; i++)
    a[i]= 1;
  for (i = 0; i < n; i++)
    a[s[i]-'a']++;
  for (i = 0; i < 26; i++) {
      ans *= a[i];
      ans %= m;
  }
  cout << ans-1 << endl;
  return 0;
}

Measured memory_bytes: 1020
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		StringBuilder sb = new StringBuilder("");

		String n = s.nextLine();
		int na = n.length();
		int i = 0;

		for (i = 0; i < na; i++) {
			String a = n.charAt(i) + "";
			if (a.equals("0")) {
				sb.append("0");
			} else if (a.equals("1")) {
				sb.append("1");
			} else if (a.equals("B")) {
				if (sb.length()==0) {
					sb.append("");
				} else {
					sb.deleteCharAt(sb.length() - 1);
				}
			}
		}

		System.out.println(sb);

	}

}

Measured memory_bytes: 21716
n = gets.to_i
x = []; y = []
n.times.map { |i| x[i], y[i] = gets.split.map(&:to_i) }
ans = 0.0
n.times do |i|
  n.times do |j|
    next if i == j

    ans += ((x[j] - x[i])**2 + (y[j] - y[i])**2)**0.5
  end
end
ans /= n
puts ans

Measured memory_bytes: 1916
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    string s;
    cin >> s;
    string res = "";
    for(int i=0; i<2; i++){
        for(int j=0; j<2; j++){
            for(int k=0; k<2; k++){
                int64_t f = (s.at(1)-'0') * (i==0?1:-1);
                int64_t snd = (s.at(2)-'0') * (j==0?1:-1);
                int64_t t = (s.at(3)-'0') * (k==0?1:-1);
                if(s.at(0) - '0' + f + snd + t == 7){
                    res = to_string(s.at(0) - '0');
                    res += f>0?"+":"-";
                    res += to_string(abs(f));
                    res += snd>0?"+":"-";
                    res += to_string(abs(snd));
                    res += t>0?"+":"-";
                    res += to_string(abs(t));
                    res += "=7";
                }
            }
            if(res != "") break;
        }
        if(res != "") break;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
void swap(int* x, int* y) {
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;    
}
int main(void) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if(a > b) swap(&a, &b);
    if(b > c) swap(&b, &c);
    if(a > b) swap(&a, &b);
    printf("%d %d %d\n", a, b, c);
    return 0;
}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,x,i,cnt=1;
    ll sum=0;
    cin>>n>>x;
    int l[n+10];
    for(i=1;i<=n;i++)
    {
        cin>>l[i];
        sum+=l[i];
        if(sum<=x)
        {
            cnt++;
        }
    }
cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
s = input()
w = int(input())

def split_str(s, n):
  length = len(s)
  return [s[i:i+n] for i in range(0, length, n)]

splited_list = split_str(s, w)
output_str = ''

for word in splited_list:
  output_str += str(word)[0]

print(output_str)


Measured memory_bytes: 3060