akhauriyash/Code-Regression huggingface dataset:
import numpy as np


def main(n, w, items):
    MAX_VALUE = 100100
    dp = np.ones((n + 1, MAX_VALUE), dtype=int)
    dp = dp * (1 << 30)
    dp[0][0] = 0
    for i in range(0, n):
        weight, value = items[i]
        dp[i + 1][:value] = np.minimum(dp[i][:value], dp[i + 1][:value])
        dp[i + 1][value:] = np.minimum(dp[i][value:], dp[i][:MAX_VALUE - value] + weight)

    result = 0
    for v in range(MAX_VALUE):
        if dp[-1][v] <= w:
            result = v
    return result


if __name__ == '__main__':
    N, W = map(int, input().split())
    I = []
    for _ in range(N):
        I.append(tuple(map(int, input().split())))
    print(main(N, W, I))


Measured memory_bytes: 170440
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
#include<string>
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p){ os << "(" << p.first << ", " <<  p.second << ")"; return os; }

using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx;
    int dy = ty - sy;
    string first = string(dy, 'U') + string(dx, 'R') + string(dy, 'D') + string(dx, 'L');
    string second ="L" + string(dy + 1, 'U') + string(dx + 1, 'R') + "DR" + string(dy + 1, 'D') + string(dx + 1, 'L') + "U";
    cout << first << second << endl;
}


Measured memory_bytes: 888
#include<iostream>
#include<cstring>
#include<vector>
#include<iomanip>
using namespace std;

double dp[3001][3001];

double coins(vector<double> &arr, int i, int x) {
    // Base Cases
    if(x == 0) return 1;
    if(i == 0) return 0;
    // Recursive Case
    if(dp[i][x] > -0.9) return dp[i][x]; // Look Up
    return (dp[i][x] = ((arr[i] * coins(arr, i - 1, x - 1)) + ((1- arr[i]) * coins(arr, i - 1, x))));    
}

int main() {
    int n;
    cin >> n;
    memset(dp, -1, sizeof(dp));
    vector<double> arr(n + 1);
    for(int i = 1; i <= n; i++) cin >> arr[i];
    cout << fixed << setprecision(10) << coins(arr, n, ((n + 1) / 2)) << endl;
    return 0;
}

Measured memory_bytes: 74356
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim N As Integer = CInt(NextString())
        Dim s As String = NextString()
        Dim t As String = NextString()

        Dim ans As Integer = N

        For i As Integer = 0 To N - 1
            Dim flg As Boolean = False
            For j As Integer = 0 To N - 1 - i
                If s(i + j) <> t(j) Then
                    ans += 1
                    flg = True
                    Exit For
                End If
            Next
            If Not flg Then Exit For
        Next

        WriteLine(ans)
    End Sub

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 20432
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;


int main(void) {
	ll n, a, b;
	cin >> n >> a >> b;
	cout << (min(n*a, b)) << endl;
	return 0;
}


Measured memory_bytes: 3636
def resolve():
    d = int(input())
    ci = list(map(int, input().split()))
    si = []
    for _ in range(d):
        si.append(list(map(int, input().split())))
    answers = [int(input()) for _ in range(d)]

    # 和の計算
    score_now = 0

    # コンテストごとの最後の実行日
    last_dates = [-1]*26
    for date in range(d):
        answer = answers[date]
        score_now += si[date][answer-1]

        last_dates[answer-1] = date
        for c, last_date in zip(ci, last_dates):
            score_now -= c*(date - last_date)
        print(score_now)
resolve()

Measured memory_bytes: 68640
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long LL;
const int N=2e5+10;
LL quickpow(LL x,LL k)
{
	LL res=1;
	while(k)
	{
		if(k&1)
		 res*=x;
		 k>>=1;
		 x*=x;
	}
	return res;
}
int main()
{
	ios::sync_with_stdio(0);
    LL n; cin>>n;
   // cout<<(int)log2(n)<<endl;
    cout<<quickpow(2,int(log2(n)))*2-1<<endl;

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int L[N];
  for(int i=0; i<N; i++){
    cin >> L[i];
  }
  int a, b, c, count;
  count = 0;
  sort(L, L + N, less<int>());
  for(int i=0; i<N-2; i++){
    for(int j=i+1; j<N-1; j++){
      for(int k=j+1; k<N; k++){
        a = L[i];
        b = L[j];
        c = L[k];
        if(a + b <= c){
          break;
        } else {
          count++;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
/**OOO**/
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    ll n,h;
    cin>>n>>h;
    ll a[n+5],b[n+5];

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

    sort(a,a+n);
    sort(b,b+n);

    //for(int i=n-1;i>=0;)cout<<b[i--]<<endl;
    //cout<<endl;

    ll cnt=0;

    int flag=0;
    ll sum=0;
    int i=n-1;
    while(sum<h)
    {   //if(sum==h){cout<<cnt-1<<endl;return 0;}
        if(b[i]<=a[n-1] || i<0){
            flag=1;
            break;
        }
        //cout<<" cum sum = "<<sum<<endl;
        sum+=b[i--];
        cnt++;
        //cout<<"sum = "<<sum<<" "<<"cnt = "<<cnt<<endl;
    }
    //if(sum==h){cout<<cnt-1<<endl;return 0;}
    //else{
        i=n-1;
        if(flag==1){
            h-=sum;
            int quotient=h/a[i];
            if(h%a[i]==0)cout<<cnt+quotient<<endl;
            else{
                cout<<cnt+quotient+1<<endl;
            }
        }
        else{
            cout<<cnt<<endl;
        }
    //}
return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
    int h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a << endl;
}


Measured memory_bytes: 256
a = []
b = []
min = 10
minutes = 0
min_index = 0

for i in range(5):
    a.append(int(input()))
    if 0 < a[i] % 10 < min:
        min = a[i] % 10
        min_index = i

a[4], a[min_index] = a[min_index], a[4]

for i in range(4):
    if a[i] % 10 != 0:
        minutes += (a[i] // 10 + 1) * 10
    else:
        minutes += a[i]

minutes += a[4]

print(minutes)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
char s[151];
int ans;
int main()
{
	scanf("%s",s+1);
	int len=strlen(s+1);
	for(int i=1;i<=len/2;i++)
		if(s[i]!=s[len-i+1])
			ans++;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int p, q, r;
    cin >> p >> q >> r;

    int ans = p + q;
    ans = min(ans, p + r);
    ans = min(ans, q + r);

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define SIZE 100005
#define MX 20
#define BT (1<<16)+5
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
 
int A[SIZE];
int dp[BT],rv[MX];
int nw[BT];
int nm[MX];
 
int main()
{
	cin.tie();
	cout.tie();
	int n;
	scanf("%d",&n);
	for(int i=0;i<n-1;i++)
	{
		int x,y,a;
		scanf("%d %d %d",&x,&y,&a);
		A[x]^=a;
		A[y]^=a;
	}
	for(int i=0;i<n;i++)
	{
		nm[A[i]]++;
	}
	int ret=nm[0];
	for(int i=1;i<MX;i++)
	{
		ret+=nm[i]/2;
		nm[i]%=2;
	}
	vector <int> vt;
	for(int i=1;i<MX;i++) if(nm[i]==1) vt.push_back(i);
	memset(dp,-1,sizeof(dp));
	memset(rv,-1,sizeof(rv));
	for(int i=0;i<vt.size();i++) rv[vt[i]]=i;
	dp[0]=0;
	for(int i=0;i<vt.size();i++)
	{
		memset(nw,-1,sizeof(nw));
		for(int S=0;S<1<<i;S++)
		{
			if(dp[S]==-1) continue;
			nw[S|1<<i]=max(nw[S|1<<i],dp[S]);
			for(int a=0;a<i;a++)
			{
				if(!(S>>a&1)) continue;
				for(int b=a+1;b<i;b++)
				{
					if(!(S>>b&1)) continue;
					if(vt[a]^vt[b]^vt[i]==0)
					{
						int T=S-(1<<a)-(1<<b);
						nw[T]=max(nw[T],dp[S]+1);
					}
					for(int c=b+1;c<i;c++)
					{
						if(!(S>>c&1)) continue;
						int t=vt[a]^vt[b]^vt[c]^vt[i];
						int T=S-(1<<a)-(1<<b)-(1<<c);
						if(t==0) nw[T]=max(nw[T],dp[S]+1);
						else if(rv[t]!=-1&&(T>>rv[t]&1))
						{
							int K=T-(1<<rv[t]);
							nw[K]=max(nw[K],dp[S]+1);
						}
					}
				}
			}
		}
		for(int S=0;S<1<<(i+1);S++) dp[S]=nw[S];
	}
	int mx=0;
	for(int i=0;i<BT;i++) mx=max(mx,dp[i]);
	printf("%d\n",n-ret-mx);
	return 0;
}
/*
a[x]为x的点权 
nw[S|(1<<i)]<- dp[S]
vt[a]*vt[b]*vt[i]=0
nw[S^(1<<a)^(1<<b)]<- dp[S]+1
*/ 

Measured memory_bytes: 1152
use std::io::{self, BufRead, BufWriter, Write};

fn solve<R, W>(reader: R, mut writer: W)
where
    R: BufRead,
    W: Write,
{
    let mut lines = reader.lines();
    let chars1 = lines.next().unwrap().unwrap();
    let chars2 = lines.next().unwrap().unwrap();

    let ans:i32 = chars1.as_bytes().iter().zip(chars2.as_bytes().iter())
        .map(|(c1, c2)| if c1 == c2 { 1 } else { 0 })
        .sum();

    writeln!(&mut writer, "{}", ans).unwrap();
}

fn main() {
    let stdio = io::stdin();
    let input = stdio.lock();

    let stdout = io::stdout();
    let output = BufWriter::new(stdout.lock());

    solve(input, output);
}

#[cfg(test)]
mod tests {
    use super::*;

    const TESTS: &'static [(&'static [u8], &'static [u8])] = &[
        (
            br"CSS
CSR", br"2
",
        ),
        (
            br"SSR
SSR", br"3
",
        ),
        (
            br"RRR
SSS", br"0
",
        ),
    ];

    #[test]
    fn test_a() {
        for &(input, expected) in TESTS {
            let mut output = Vec::new();
            solve(input, &mut output);
            let expected_str = String::from_utf8(expected.to_vec()).unwrap();
            let output_str = String::from_utf8(output).unwrap();
            assert_eq!(expected_str, output_str);
        }
    }
}


Measured memory_bytes: 4352
target = input()
for _ in range(int(input())):
    order = input().split()
    if order[0] == 'print':
        print(target[int(order[1]):int(order[2])+1])
    elif order[0] == 'reverse':
        new_sent = ''
        begin_num=int(order[1])
        end_num=int(order[2])+1
        for i in range(len(target)):
            if begin_num <= i < end_num:
                new_sent += target[begin_num + end_num-1 -i]
            else:
                new_sent += target[i]
        target = new_sent
    else:
        target = target[:int(order[1])] + order[3] + target[int(order[2])+1:]



Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  string S,T;
  cin >> S >> T;
  T+=T;
  int r1=0,r2=0;
  for (int i=0;i<S.size();i++) {
    r1=0;
    for (int j=i;j<i+S.size();j++) {
	  if (S.at(j-i)!=T.at(j)) {r1=1;}
	}
    if (r2==0 && r1==0) {r2++;}
  }
  if (r2==1) {cout << "Yes" << endl;} else {cout << "No" << endl;}
  
}


Measured memory_bytes: 256
N,D=map(int,input().split())
X=[]
for i in range(N):
  X.append(list(map(int, input().split())))

cnt=0
for j in range(N-1):
  for k in range(j+1,N):
    wa=0
    for l in range(D):
      wa += (X[j][l]-X[k][l])**2
    result=wa**(1/2)
    if result.is_integer():
      cnt+=1

print(cnt)

Measured memory_bytes: 3064
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353



S = sys.stdin.buffer.readline().decode().rstrip()

S = list(S)

S = np.array(S, dtype='U1')

ans = len(S) - abs((S == '0').sum() - (S == '1').sum())
print(ans)


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

int main() {
	int N;
	cin >> N;
	vector<int> List;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		auto itr = upper_bound(List.begin(), List.end(), -A);
		if (itr == List.end()) List.push_back(-A);
		else *itr = -A;
	}
	cout << List.size() << endl;
}


Measured memory_bytes: 3936
#include <stdio.h>

int main(){
    int a,b,c;
    scanf("%d %d %d", &a, &b, &c);
    
    int counter,divisor_num = 0;
    for(counter = a; counter <= b; counter++){
        if(c%counter == 0) divisor_num++;
    }
    printf("%d\n", divisor_num);
}


Measured memory_bytes: 2756
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int K = sc.nextInt();
		char[][] arr = new char[h][w];
		for(int i=0;i<h;i++){
			String s = sc.next();
			for(int j=0;j<s.length();j++){
				arr[i][j]=s.charAt(j);
			}
		}
		int ans=0;
		for(int i=0;i<(1<<h);i++){
			for(int j=0;j<(1<<w);j++){
				int black=0;
				for(int k=0;k<h;k++){
					for(int l=0;l<w;l++){
						if(((i>>k)&1)==0 && ((j>>l)&1)==0 && arr[k][l]=='#'){
							//System.out.println((i>>k)+" "+i+" "+k);
							black++;
						}
					}
				}
				if(black==K){
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 35576
S=set()

q=int(input())

for _ in range(q):
    query=[int(i) for i in input().split(" ")]
    if query[0]==0:
        S.add(query[1])
        print(len(S))
    else:
        if query[1] in S:
            print(1)
        else:
            print(0)



Measured memory_bytes: 23304
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

ll n;
int cnt;

void solve(ll x) {
    if(n < x) return;
    if(x) {
        bool c[10]{};
        int y = x;
        while(y) {
            c[y % 10] = 1;
            y /= 10;
        }
        if(c[3] && c[5] && c[7]) {
            cnt++;
        }
    }
    x *= 10;
    solve(x + 3);
    solve(x + 5);
    solve(x + 7);
}

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

    cin >> n;

    solve(0);

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3612
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")
import math


def main():
    A, B = input().split()
    A = int(A)
    B1, B2 = map(int, B.split("."))

    tot = A*B1
    tot += (A*B2)//100
    print(tot)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define Max(a,b) ((a) < (b) ? (b) : (a))
#define Min(a,b) ((a) > (b) ? (b) : (a))
#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i= 0; i <b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}

int main() {
	int i, j, k;

	int N, M, K;

	cin >> N;
	M = N;
	K = 0;
	while (M > 0) {
		K += M % 10;
		M /= 10;
	}
	if (N % K == 0) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
import sys
from itertools import starmap
readline = sys.stdin.readline
p0, p1 = starmap(complex, zip(*[map(int, readline().split())] * 2))
n = int(readline())
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
def norm(base):
    return base.real * base.real + base.imag * base.imag
def project(p0, p1, p2):
    base = p0 - p1
    r = dot(p2 - p0, base) / norm(base)
    return p0 + base * r
for _ in [0] * n:
    p2 = complex(*[int(i) for i in readline().split()])
    ap = project(p0, p1, p2)
    print(ap.real, ap.imag)

Measured memory_bytes: 7984
from fractions import gcd
n,m=map(int,input().split())
a=list(map(int,input().split()))
wa=[]
for i in range(n):
    p=a[i]
    f=0
    while p%2==0:
        p=p//2
        f+=1
    wa.append(f)
if max(wa)!=min(wa):
    print(0)
    exit()
ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // gcd(ans, a[i])
g=ans//2
kai=m//g
kai=-(-kai//2)
print(kai)


Measured memory_bytes: 16280
# -*- coding: utf-8 -*-


def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    # 標準入力の取得
    N, K = list(map(int, input().split()))
    p = list(map(int, input().split()))

    return N, K, p


def main(K: int, p: list) -> None:
    """
    求解処理.

    Args:
        K (int): 購入する果物の種類
        p (list): 各果物の価格
    """
    # 求解処理
    sorted_p = sorted(p)
    ans = sum(sorted_p[:K])

    # 結果出力
    print(ans)


if __name__ == "__main__":
    N, K, p = get_input()
    main(K, p)


Measured memory_bytes: 9148
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;

signed main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	long long n; cin >> n;
	long long ans = 1e12;
	for(int i = 1 ; i <= sqrt(n) ; i ++ ) {
		if(n % i == 0) {
			long long a = i , b = n / i;
			ans = min(ans , a + b - 2);
		}
	}
	cout << ans;
}
		


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  ll N, K; cin >> N >> K;

  ll left = (K + (K + 2*N-1)) * N;
  ll right = ((K + 2*N) + (K + 3*N-1)) * N / 2;
  
  if (left > right) {
    cout << -1 << endl;
    return 0;
  }

  int L = (N+1)/2;
  int a = K;
  int b = K + 2*N-1 - (L-1);
  int c = K + 2*N;
  rep(i,L) {
    cout << a << ' ' << b << ' ' << c << endl;
    a += 1;
    b += 1;
    c += 2;
  }

  int R = N/2;
  b = K + N;
  c = K + 2*N + 1;
  rep(i,R) {
    cout << a << ' ' << b << ' ' << c << endl;
    a += 1;
    b += 1;
    c += 2;
  }
  return 0;
}


Measured memory_bytes: 2304
/*....Abhilash's coding template....*/
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define pb push_back
#define pob pop_back
#define mp make_pair
#define in insert
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define vll vector<ll>
#define fl(i,a,b) for(ll i=a;i<=b;i++)
#define flr(i,a,b) for(ll i=a;i>=b;i--)
#define print(v) for(auto i=v.begin();i!=v.end();i++){cout<<*i<<" ";}cout<<"\n";
#define tr(c,i) for(decltype((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define test() ll te; cin >> te; while(te--)
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define PI 3.14159265
#define MOD 1000000007
#define M 998244353
#define node pair<ll , pair<ll,ll> >
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

int main()
{
    ll ans=0,n,m; cin>>n>>m;
    

    cout<<6-m-n<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a[300],b[300],i=0,z,c,d;
  while(i<300){
    scanf("%d%d",&a[i],&b[i]);
    if(a[i]==0 && b[i]==0)break;
    i++;
  }
  for(c=0;c<i;c++){
    for(z=0;z<a[c];z++){
      for(d=0;d<b[c];d++)printf("#");
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 576
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
typedef long long int LL;
using namespace std;
int main()
{
    int N,K,d,A[110],num[110]={0};
    scanf("%d%d",&N,&K);
    for(int i=0;i<K;i++)
    {
        scanf("%d",&d);
        for(int j=0;j<d;j++)
        {
            scanf("%d",&A[i]);
            num[A[i]-1]+=1;
        }
    }
    int ans=0;
    for(int i=0;i<N;i++)
    {
        if(num[i]==0)
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 501000
#define LL long long

int n, m;
int s[AC], d[AC], f[AC];

inline int read()
{
	int x = 0;char c = getchar();
	while(c > '9' || c < '0') c = getchar();
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x;
}

void pre()
{
	n = read(), d[0] = read();
	for(R i = 1; i <= n; i ++) 
	{
		s[i] = read(), d[i] = d[i - 1];
		if(d[i] >= s[i]) d[i] -= s[i]; 
		else if(s[i] - d[i] < d[i]) d[i] = s[i] - d[i];
	}
}

void work()//f[i]表示经过操作i ~ n,使得Alice无法到达终点的最小起始距离x
{
	f[n + 1] = 1;
	for(R i = n; i; i --)
		if(f[i + 1] <= s[i] / 2) f[i] = f[i + 1];
		else f[i] = f[i + 1] + s[i];
	m = read();
	for(R i = 1; i <= m; i ++)
	{
		int x = read();
		if(d[x - 1] >= f[x + 1]) printf("YES\n");
		else printf("NO\n");
	}	
}

int main()
{
	//freopen("in.in", "r", stdin);
	pre();
	work();
	//fclose(stdin);
	return 0;
}

Measured memory_bytes: 7808
n = int(input())
hap = []
for i in range(n):
    l = [int(x) for x in input().split()]
    hap += [l]
dp = [[0 for _ in range(3)] for _ in range(n)]
dp[0] = hap[0]
for i in range(1,n):
    for j in range(3):
        dp[i][j] = max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3])+hap[i][j]
print(max(dp[-1]))

Measured memory_bytes: 45684
#include <iostream>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)

int main(){
  int k, s, cnt = 0;
  cin >> k >> s; 

  rep(x, k+1) {
    rep(y, k+1) {
      int z = s - x - y;
      if (x + y + z == s && z >= 0 && z <= k) {
        ++cnt;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,m,u,v;
long long ans[100010],g[100010],S;
long long a[100010],b[100010];
long long fa[100010];

int find(int x){
	if(x==fa[x]) return x;
	return fa[x]=find(fa[x]);
}

int main(){
	scanf("%lld %lld",&n,&m);
	for(int i=1;i<=m;i++) scanf("%lld %lld",&a[i],&b[i]);
	for(int i=1;i<=n;i++) fa[i]=i,g[i]=1;
	S=n*(n-1)/2;
	for(int i=m;i;i--){
		u=find(a[i]),v=find(b[i]);
		if(u==v){
			ans[i]=ans[i+1];
			continue;
		}
		ans[i]=ans[i+1];
		ans[i]-=g[u]*(g[u]-1)/2;
		ans[i]-=g[v]*(g[v]-1)/2;
		if(u<v) fa[v]=u,g[u]+=g[v],g[v]=0,ans[i]+=g[u]*(g[u]-1)/2;
		else fa[u]=v,g[v]+=g[u],g[u]=0,ans[i]+=g[v]*(g[v]-1)/2;
	}
	for(int i=1;i<=m;i++){
		printf("%lld\n",S-ans[i+1]);
	}
	
	return 0;
}

Measured memory_bytes: 5248
import sys

N = int(input())
tLst = [list(map(int, input().split())) for i in range(N)]
tx = 0
ty = 0
t = 0
for i in range(N):
    tmp = (abs(tx - tLst[i][1]) + abs(ty - tLst[i][2]))
    ttmp = tLst[i][0] - t
    tt = ttmp - tmp
    if tt == 0 or\
            (tt + tmp == t and tt % 2 == 0):
        tx = tLst[i][1]
        ty = tLst[i][2]
        t = tLst[i][0]
        continue
    else:
        print('No')
        sys.exit()
print('Yes')

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

int main() {
  ll N;
  cin >> N;
  int count = 0;
  int ans = 0;
  while(N % 2 == 0){
    N = N / 2;
    count++;
  }
  for(ll i = 1;i < 70; i++) {
    if(count >= i) {
      ans++;
      count -= i;
    }
    else{
      break;
    }
  }
  count = 0;
//  cout << ans << endl;
  for( ll i = 3; i <= sqrt(N); i++){
    while(N % i == 0){
      N = N / i;
      count++;
    }
    for(ll j = 1;j < 70; j++) {
      if(count >= j) {
         ans++;
         count -= j;
      }
      else{
        break;
      }
    }
    i++;
    count = 0;
  }
  if(N != 1){
    ans++;
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 3620
import scala.io.StdIn
object Main extends App {
  val List(k, s) = StdIn.readLine().split(" ").map(_.toInt).toList
  var cnt = 0
  for {
    x <- 0 to k
    y <- 0 to k
    z = s - x - y
    if (0 <= z && z <= k)
  } cnt += 1;
  println(cnt)
}


Measured memory_bytes: 104872
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
    int i,N,Np=0,Nm=0,K,dMin,dtemp,dm,dp;
    scanf("%d %d",&N,&K);
    int arr[N];
    for(i=0;i<N;i++){
        scanf("%d",&arr[i]);
    }
    for(i=0;i<N;i++){
        if(arr[i]==0){
         K--;   
        }
        if(arr[i]>0){
            Np++;
        }
        if(arr[i]<0){
            Nm++;
        }
    }
    if(K==0){
        printf("%d",0);
        return 0;
    }
    int minus;
    int plus;
    /*右向き*/
    if(K<=Np){
        plus=K;
        minus=0;
    }
    else
    {
        plus=Np;
        minus=K-plus;
    }
    dMin=1000000000;
    while(plus>=0 && Nm>=minus){
        if(plus!=0){
            dp=arr[N-Np+plus-1];
        }
        else{
            dp=0;
        }
        if(minus!=0){
            dm=-arr[Nm-minus];
        }
        else{
            dm=0;
        }
        if(dp>=dm){
            dtemp=dp+2*dm;
        }
        else{
            dtemp=2*dp+dm;
        }
        
        if(dtemp<dMin){
            dMin=dtemp;
        }
        plus--;
        minus++;
    }
    printf("%d",dMin);

    return 0;
}

Measured memory_bytes: 512
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n = readline() |> parseInt
	h = readline() |> split |> parseMap
	f = 0
	m = 0
	for i in 1:n-1
		if h[i]-1>h[i+1]
			f = 1
			break
		elseif h[i]==h[i+1]+1
			if h[i]-1<m
				f = 1
				break
			else
				m = h[i]-1
			end
		else
			if h[i]<m
				f = 1
				break
			elseif h[i]-1<m
				m = h[i]
			else
				m = h[i]-1
			end
		end
	end
	if h[n]<m
		f = 1
	end
	println(f==0?"Yes":"No")
end

main()

Measured memory_bytes: 167324
n=int(input())
s=list(map(int,input().split()))
t=[0]*n
for i in range(n):
    if i==n-1-i:
        continue
    t[i]+=s[i]+s[n-1-i]
ans=0
for c in range(1,n//2):
    num=0
    s_max=0
    if (n-1)%c==0:
        for k in range((n//2)//c+1):
            if n//2<=c*k:
                break
            num+=t[c*k]
            s_max=max(s_max,num)
    else:
        for k in range((n-1)//c):
            num+=t[c*k]
            s_max=max(s_max,num)
    ans=max(ans,s_max)

print(ans)

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

int main() {
    char c;
    stack<char> S;
    while(cin >> c) {
        if(c != 'B') S.push(c);
        else if(c == 'B'){
            if(S.empty()) continue;
            else S.pop();
        }
    }
    vector<char> v;
    for(int i=0; i<10; i++) {
        if(S.empty()) break;
        v.push_back(S.top());
        S.pop();
    }
    for(int i=v.size()-1; i>=0; i--) {
        cout << v[i];
    }
    cout << endl;
}

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

l = list(map(int, input().split()))

ans = 0
if not abs(l[1] - l[2]) % 2:
    ans = abs(l[1] - l[2]) // 2
elif abs(l[1] - l[2]) == 1:
    if (l[1] - 1) < (l[0] - l[2]):
        ans = l[2] - 1
    else:
        ans = l[0] - l[1]
else:
    if (l[1] - 1) < (l[0] - l[2]):
        ans = l[1] + (l[2] - l[1] - 1) // 2
    else:
        ans = l[0] - l[2] + 1 + (l[2] - l[1] - 1) // 2

print(ans)


Measured memory_bytes: 3064
from sys import exit, stderr, stdin
input = stdin.readline
def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N,A, B = [int(n) for n in input().split()]
    print(min(A*N, B))
    # N = int(input())
    # a = [int(input()) for _ in range(N)]
    # S = str(input())[:-1]
    # print(S)
    # L = len(S)
    # INF = 10000000002
    # EPS = 1e-9
    # exit()



if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = (1e9)+7;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}

ll maxll(ll a,ll b){
	ll ans;
	a>b?ans=a:ans=b;
	return ans;
}
int main(){
  fastIO();
  ll n,a,b;
  cin>>n>>a>>b;
  cout<<maxll(((b*(n-1))+a)-((a*(n-1))+b)+1,0)<<endl;
}  



Measured memory_bytes: 256
public class Main {
  public static void main(String[] args) {
    java.util.Scanner sc = new java.util.Scanner(System.in);
    int n = sc.nextInt();
    int r0 = sc.nextInt();
    int r = sc.nextInt();
    int max = r - r0;
    int min = Math.min(r, r0);
    for(int i = 2; i < n; i++) {
      r = sc.nextInt();
      max = Math.max(max, r - min);
      min = Math.min(min, r);
    }
    System.out.println(max);
  }
}



Measured memory_bytes: 69780
s = input()
q = int(input())

for qi in range(q):
    command = input().split()

    a = int(command[1])
    b = int(command[2])

    if command[0] == 'print':
        print(s[a:b + 1])
    elif command[0] == 'reverse':
        s = s[:a] + s[a:b + 1][::-1] +  s[b + 1:]
    else:
        p = command[3]
        s = s[:a] + p + s[b + 1:]

Measured memory_bytes: 7692
//verma_ankit484

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
const int mod = (int) 1e9+7;

using namespace std;
//using namespace __gnu_pbds;

//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

bool chk(int n) {
  while (n) {
    int p = n % 10;
    if (p == 7) return true;
    n /= 10;
  }
  return false;
}

int32_t main() {
  IOS
  #ifdef AV
  freopen("input.txt", "r", stdin);
  #endif
  int n;
  cin >> n;
  if (chk(n)) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include<math.h>
#include <vector>
#include<bitset>
#include<map>
using namespace std;

int main() {
	int n, k; cin >> n >> k; int p[n];
	for (int i = 0; i < n; i++)cin >> p[i];
	sort(p, p + n);
	int ans = 0;
	for (int i = 0; i < k; i++)ans += p[i];
	cout << ans << endl;
}

Measured memory_bytes: 3628
N, M = [int(n) for n in input().split(' ')]
A = [int(n) for n in input().split(' ')]


A.sort(reverse=True)
total = sum(A)
j = 0
for i in range(N):
    if A[i]<(total/(4*M)):
        break
    else:
        j += 1
if j>=M:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define int ll
//#define endl "\n"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
template<class T> inline bool chmax(T & x, T const & y){ return x<y ? x=y,true : false; }
template<class T> inline bool chmin(T & x, T const & y){ return x>y ? x=y,true : false; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif
// ll const mod = 1000000007;
// ll const inf = 1LL<<60;

struct Trie {
    int val;
    unordered_map<char,Trie*> ch;
    Trie() : val(0) {}
    ~Trie(){
        for(auto & e : ch) delete e.second;
    }
};

void insert(char * s, Trie * t){
    Trie * cur = t;
    while(1){
        if(*s=='\0'){
            cur->val++;
            break;
        } else {
            Trie * &nxt = cur->ch[*s];
            if(nxt == nullptr) nxt = new Trie();
            cur = nxt;
            s++;
        }
    }
}

bool erase(char * s, Trie * t){
    Trie * cur = t;
    while(1){
        if(*s == '\0'){
            cur->val--;
            return true;
        } else {
            Trie * &nxt = cur->ch[*s];
            if(nxt == nullptr) return false;
            cur = nxt;
            s++;
        }
    }
}

bool find(char * s, Trie * t){
    Trie * cur = t;
    while(1){
        if(*s == '\0'){
            return cur->val > 0;
        } else {
            Trie * &nxt = cur->ch[*s];
            if(nxt == nullptr) return false;
            cur = nxt;
            s++;
        }
    }
}

int main(){
    int n;
    cin >> n;
    Trie * root = new Trie();
    rep(i,n){
        char com[15], str[15];
        cin >> com >> str;
        if(com[0] == 'i'){
            insert(str,root);
        } else {
            puts(find(str,root) ? "yes" : "no");
        }
    }
    delete root;
}

Measured memory_bytes: 79292
#include<stdio.h>
#include<string.h>

int main()
{
	int dice1[6], dice2[6];
	int n;
	for (n = 0; n < 6; n++)
	{
		scanf("%d", &dice1[n]);
	}
	for (n = 0; n < 6; n++)
	{
		scanf("%d", &dice2[n]);
	}
	int i = 18, tmp, j = 4;
	while (i--)
	{
		if (dice1[0] == dice2[0]
			&& dice1[1] == dice2[1]
			&& dice1[2] == dice2[2]
			&& dice1[3] == dice2[3]
			&& dice1[4] == dice2[4]
			&& dice1[5] == dice2[5])
		{
			printf("Yes\n");
			return 0;
		}
		while (j--)
		{
			tmp = dice1[1];
			dice1[1] = dice1[2];
			dice1[2] = dice1[4];
			dice1[4] = dice1[3];
			dice1[3] = tmp;
			if (dice1[0] == dice2[0]
				&& dice1[1] == dice2[1]
				&& dice1[2] == dice2[2]
				&& dice1[3] == dice2[3]
				&& dice1[4] == dice2[4]
				&& dice1[5] == dice2[5])
			{
				printf("Yes\n");
				return 0;
			}
		}
		j = 4;
		if (i % 2 == 0)
		{
			tmp = dice1[0];
			dice1[0] = dice1[1];
			dice1[1] = dice1[5];
			dice1[5] = dice1[4];
			dice1[4] = tmp;
			if (dice1[0] == dice2[0]
				&& dice1[1] == dice2[1]
				&& dice1[2] == dice2[2]
				&& dice1[3] == dice2[3]
				&& dice1[4] == dice2[4]
				&& dice1[5] == dice2[5])
			{
				printf("Yes\n");
				return 0;
			}
		}
		if (i % 2 == 1)
		{
			tmp = dice1[0];
			dice1[0] = dice1[2];
			dice1[2] = dice1[5];
			dice1[5] = dice1[3];
			dice1[3] = tmp;
			if (dice1[0] == dice2[0]
				&& dice1[1] == dice2[1]
				&& dice1[2] == dice2[2]
				&& dice1[3] == dice2[3]
				&& dice1[4] == dice2[4]
				&& dice1[5] == dice2[5])
			{
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 1012
#include <iostream>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
using namespace std;
int main()
{
	int n, i, y,
		x[100] = {};

	double d[4] = {},
		   diff[100] = {};

	cin >> n;
	for( i = 0; i < n; ++i ) cin >> x[i];
	for( i = 0; i < n; ++i ){
		cin >> y;
		diff[i] = (double)abs( x[i] - y );
	}
	for( i = 0; i < n; ++i ){
		d[0] += diff[i];
		d[1] += diff[i] * diff[i];
		d[2] += pow( diff[i], 3.0 );
		d[3] = max( d[3], diff[i] );
	}

	cout << fixed << setprecision(5) << d[0] << "\n";
	cout << fixed << setprecision(5) << sqrt(d[1]) << "\n";
	cout << fixed << setprecision(5) << pow( d[2], 1.0/3.0) << "\n";
	cout << fixed << setprecision(5) << d[3] << "\n";

	return 0;
}

Measured memory_bytes: 1308
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int A = sc.nextInt();
		int P = sc.nextInt();

		int pi = (A*3+P)/2 ;

		// 出力
		System.out.println(pi);

	}

}


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

using namespace std;

#define local
#ifdef local

template<class T>
void _E(T x) { cerr << x; }

void _E(double x) { cerr << fixed << setprecision(6) << x; }

void _E(string s) { cerr << "\"" << s << "\""; }

template<class A, class B>
void _E(pair<A, B> x) {
    cerr << '(';
    _E(x.first);
    cerr << ", ";
    _E(x.second);
    cerr << ")";
}

template<class T>
void _E(vector<T> x) {
    cerr << "[";
    for (auto it = x.begin(); it != x.end(); ++it) {
        if (it != x.begin()) cerr << ", ";
        _E(*it);
    }
    cerr << "]";
}

void ERR() {}

template<class A, class... B>
void ERR(A x, B... y) {
    _E(x);
    cerr << (sizeof...(y) ? ", " : " ");
    ERR(y...);
}

#define debug(x...) do { cerr << "{ "#x" } -> { "; ERR(x); cerr << "}" << endl; } while(false)
#else
#define debug(...) 114514.1919810
#endif
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db long double
#define eps 1e-3
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
#define endl "\n"
#define ls ch[now][0]
#define rs ch[now][1]
const ll mod = 998244353;
const ll maxn = 2e5 + 10;


ll qpow(ll a, ll b) {
    ll ret = 1;
    for (; b; a = a * a % mod, b >>= 1) {
        if (b & 1) {
            ret = ret * a % mod;
        }
    }
    return ret;
}

vector<ll> f(maxn), invf(maxn);

ll inv(ll a) {
    return qpow(a, mod - 2);
}

void prework() {
    f[0] = 1;
    _rep(i, 1, maxn - 1) {
        f[i] = f[i - 1] * i % mod;
    }
    invf[maxn - 1] = qpow(f[maxn - 1], mod - 2);
    for (ll i = maxn - 2; i >= 0; i--) {
        invf[i] = invf[i + 1] * (i + 1) % mod;
    }

}

ll C(ll n, ll m) {
    if (n > m || m < 0)return 0;
    if (n == 0 || m == n) return 1;
    ll res = (f[m] * invf[m - n] % mod * invf[n]) % mod;
    return res;
}

vector<ll> G[maxn];


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll k, x = 0;
    cin >> k;
    _rep(i, 1, 1e7) {
        x = (x * 10 + 7) % k;
        if(!x){
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}

Measured memory_bytes: 11040
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        int M = scan.nextInt();
        PriorityQueue<Integer> A = new PriorityQueue<Integer>(Collections.reverseOrder());
        for(int i = 0; i < N; i++) {
            A.add(scan.nextInt());
        }

        for(int i = 0; i < M; i++) {
            int temp = A.poll();
            A.add((int)Math.floor((double)temp / 2.0));
        }

        long sum = 0;
        for(int i = 0; i < N; i++) {
            sum += A.poll();
        }
        os.println(sum);
    }
}

Measured memory_bytes: 64532
H , W , A , B = map(int , input().split())
mat = [[1] * W for _ in range(H)]
for row in range(H):
    for col in range(W):
        if col < A and row < B or col >= A and row >= B:
            mat[row][col] = 0
for row in mat:
    print(*row,sep = "")
print()

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

using namespace std;

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

	if(s == "SUN") {
		cout << 7 << '\n';
	}

	if(s == "MON") {
		cout << 6 << '\n';
	}

	if(s == "TUE") {
		cout << 5 << '\n';
	}

	if(s == "WED") {
		cout << 4 << '\n';
	}

	if(s == "THU") {
		cout << 3 << '\n';
	}

	if(s == "FRI") {
		cout << 2 << '\n';
	}

	if(s == "SAT") {
		cout << 1 << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int solve(const string &a, const string &b){
	int n = a.size();
	if(!count(all(b), '1')) return a == b ? 0 : -1;
	
	vi right(n), left(n), sum(2 * n + 1);
	int pos = 0, ans = inf;
	rep(it, 2) rep(i, n){
		if(b[i] == '1') pos = i;
		left[i] = pos;
	}
	rep(it, 2) for(int i = n - 1; i >= 0; i--){
		if(b[i] == '1') pos = i;
		right[i] = pos;
	}
	rep(i, 2 * n) sum[i + 1] = sum[i] + (b[i % n] == '1');
	
	rep(k, n){
		int mn = inf, diff = 0;
		vi rshift(n + 1);
		rep(i, n){
			if(a[i] == b[(i + k) % n]) continue;
			diff++;
			if(sum[i + k + 1] - sum[i]) continue;
			int l = i - left[i], r = right[(i + k) % n] - (i + k) % n;
			if(l < 0) l += n;
			if(r < 0) r += n;
			rshift[l - 1] = max(rshift[l - 1], r);
		}
		for(int i = n - 1; i >= 0; i--){
			rshift[i] = max(rshift[i], rshift[i + 1]);
			mn = min(mn, i + rshift[i]);
		}
		ans = min(ans, 2 * mn + k + diff);
	}
	return ans;
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	string a, b; cin >> a >> b;
	int ans = solve(a, b);
	reverse(all(a)); reverse(all(b));
	ans = min(ans, solve(a, b));
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val (N, D, A) = readInputLine().split(" ").map { it.toLong() }
    val mons = Array(N.toInt()) { val (X, H) = readInputLine().split(" ").map { it.toLong() }; Pair(X, H)}
    mons.sortBy { it.first }

    val poses = mons.map { it.first }

    val damage = LongArray(N.toInt() + 1)

    var ans = 0L

    for ((i, m) in mons.withIndex()) {
        if (i != 0) {
            damage[i] += damage[i - 1]
        }

        if (damage[i] < m.second) {
            val cnt = (m.second - damage[i]) / A + if ((m.second - damage[i]) % A != 0L) 1L else 0L
            damage[i] += cnt * A
            damage[upperBound(poses, m.first + D * 2)] -= cnt * A
            ans += cnt
        }
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}

fun <T: Comparable<T>> upperBound(list: List<T>, value: T): Int {
    return Collections.binarySearch(list, value, {x, y -> if (x > y) 1 else -1}).inv()
}

Measured memory_bytes: 134504
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
using namespace std;

int N;
int K;
string s;

int main() {
	cin >> N >> K;
	cin >> s;
	s[K - 1] = tolower(s[K - 1]);
	cout << s << endl;
}

Measured memory_bytes: 256
#include<bits//stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main(){
		int a[26];
		for(int i=0;i<26;i++) a[i]=0;
		string s;
		cin>>s;
		for(int i=0;i<s.size();i++){
			a[(int)s[i]-'a']++;
		}
		for(int i=0;i<s.size();i++){
			if(a[i]>=2){
				cout<<"no\n";
				return 0;
			}
		}
		cout<<"yes\n";
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 9 * 1e18;
const ll MOD = 1e9 + 7;

void solve(long long N, long long x, std::vector<long long> a) {
  ll minTimeSum = INF;

  // t: 魔法を使う時間
  rep(t, 0, N) {

    vl orig(N);
    set<ll> aSet;
    rep(n, 0, t) { aSet.insert(a[n]); }
    rep(n, t, 2 * N) {
      ll i = n % N;
      aSet.insert(a[i]);
      orig[i] = *aSet.begin();

      ll j = (n - t) % N;
      aSet.erase(a[j]);
    }

    ll minTimeSumTmp = 0;
    rep(n, 0, N) { minTimeSumTmp += orig[n]; }
    minTimeSum = min(minTimeSum, minTimeSumTmp + t * x);
  }
  print(minTimeSum);
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long x;
  scanf("%lld", &x);
  std::vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &a[i]);
  }
  solve(N, x, std::move(a));
  return 0;
}


Measured memory_bytes: 384