akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    if (a * b) % 2:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = II()
    w = SR(n)
    d = []
    for i in w:
        d.append("".join(i))
    if len(set(d)) != n:
        print("No")
        return
    for i in range(n - 1):
        if w[i][-1] != w[i + 1][0]:
            print("No")
            return
    print("Yes")
    return

#C
def C():
    def gcd(a, b):
        a, b = max(a, b), min(a, b)
        while b:
            a, b = b, a % b
        return a
    n, x = LI()
    xn = LI()+[x]
    xn.sort()
    ans = xn[1] - xn[0]
    for i in range(1, n):
        ans = gcd(ans, xn[i + 1] - xn[i])
    print(ans)
    return

#D
def D():
    h, w = LI()
    d = []
    for y in range(h):
        a = LI()
        tmp = []
        for x in range(w):
            if a[x] & 1:
                tmp.append((y,x))
        for t in tmp[::-1 if y & 1 else 1]:
            d.append(t)
    ans = []
    for i in range(0, len(d) - 1, 2):
        y, x = d[i]
        next_y, next_x = d[i + 1]
        for ny in range(y, next_y + 1):
            for nx in range(x, -1 if ny & 1 else w, -1 if ny & 1 else 1):
                if y == ny and x == nx:
                    continue
                ans.append((y+1, x+1, ny+1, nx+1))
                if ny == next_y and nx == next_x:
                    break
                y = ny
                x = nx
    print(len(ans))
    for a in ans:
        print(*a)
    return

#Solve
if __name__ == '__main__':
    D()



Measured memory_bytes: 92640
def f(n, m)
  (1900 * m + 100 * (n - m)) * (2 ** m)
end

def main(argv)
  (n, m) = gets.chomp.split(' ').map(&:to_i)
  puts f(n, m).to_s
end

if self.to_s == 'main'
  main(ARGV)
end

Measured memory_bytes: 1788
#include "algorithm"
#include "iostream"
#include "set"
#include "vector"

using namespace std;

vector< int> v;
int n, k;

int check(int d) {
	int best = 0;

	for (int l = 0; l <= d; ++l) {
		multiset < int> st;
		for (int i = 0; i < l; ++i) {
			st.insert(v[i]);
		}
		int r = d - l;
		for (int i = 0; i < r; ++i) {
			st.insert(v[n - 1 - i]);
		}
		int x = k - d;
		while (!st.empty() and x > 0) {
			x --;
			if (*st.begin() > 0) continue;
			st.erase(st.begin());
		}

		int sum = 0;
		for (int x : st) sum += x;
		best = max(best, sum);
	}
	return best;
}

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

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

	int d = min(k, n);
	int best = 0;
	for (int i = 1; i <= d; ++i) {
		best = max(best, check(i));
	}
	cout << best << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
	"sort"
)

var N int
var ans, res int = 1, 1
var mod int = pow(10, 9) + 7

func main() {
	fmt.Scan(&N)
	m := make(map[int]int)
	A := make([]int, N)

	for i := 0; i < N; i++ {
		var t int
		fmt.Scan(&t)
		if m[t] == 0 {
			A[i] = (-1) * t
		} else {
			A[i] = t
		}
		m[t]++
	}

	sort.Ints(A)

	var j int
	for i := (-1) * (N - 1); i <= (N - 1); i = i + 2 {
		if A[j] != i {
			fmt.Println(0)
			return
		}
		j++
	}

	for i := 1; i <= N/2; i++ {
		ans *= 2
		ans %= mod
	}
	fmt.Println(ans)
}

/*  ----------------------------------------  */

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	return a[i][1] < a[j][1]
}


Measured memory_bytes: 7808
sx,sy,tx,ty = map(int,input().split(' '))

output_txt = ''

#1st txt
x1 = tx -sx
if x1 >0:
    txt_x1 = 'R' * x1
else:
    txt_x1 = 'L' * x1
y1 = ty -sy
if y1 >0:
    txt_y1 = 'U' * y1
else:
    txt_y1 = 'D' * y1

#2nd txt
if x1 >0:
    txt_x2 = 'L' * x1
else:
    txt_x2 = 'R' * x1
if y1 >0:
    txt_y2 = 'D' * y1
else:
    txt_y2 = 'U' * y1

#3rd txt
if y1 >0:
    txt_3 = 'D' 
else:
    txt_3 = 'U'

if x1 >0:
    txt_3 += 'R' * x1 + 'R'
else:
    txt_3 += 'L' * x1 + 'L'

if y1 >0:
    txt_3 += 'U' * y1 + 'U'
else:
    txt_3 += 'D' * y1 + 'D'

if x1 >0:
    txt_3 += 'L'
else:
    txt_3 += 'R'


#4th txt
if y1 >0:
    txt_4 = 'U' 
else:
    txt_4 = 'D'

if x1 >0:
    txt_4 += 'L' * x1 + 'L'
else:
    txt_4 += 'R' * x1 + 'R'

if y1 >0:
    txt_4 += 'D' * y1 + 'D'
else:
    txt_4 += 'U' * y1 + 'U'

if x1 >0:
    txt_4 += 'R'
else:
    txt_4 += 'L'

output_txt = txt_x1 + txt_y1 + txt_x2 + txt_y2
print(output_txt+txt_3+txt_4)

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int main(){
    long long N;
    cin>>N;
    long long Div=1000000007;
    long long ans=1;
    for(long long i=1;i<=N;i++){
        ans=(ans*i)%Div;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int i;
    string s;
    cin>>s;
    for(i=0;i<=3;i++)
        cout<<s[i];
    cout<<' ';
    for(i=4;i<s.size();i++)
    cout<<s[i];
    cout<<endl;
    return 0;
}

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

int main() {
    int K;
    string S;
    cin >> K;
    cin >> S;
    if (S.size() <= K) {
        cout << S << endl;
        return 0;
    }
    for (int i = 0; i < K; i++) {
        cout << S.at(i);
    }
    cout << "..." << endl;
}

Measured memory_bytes: 3600
/*

i<j

j-i=A[i]+A[j]

A[i]+i=-A[j]+j

1 1
4 2


i=1 A[i]=1
j=4 A[j]=2

A[i]+i=2
-A[j]+j=2

-A[i]+i=0
A[j]+j=6
*/
#include <bits/stdc++.h>
using namespace std;

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

	int N;
	scanf("%d", &N);

	vector<int> A(N + 1);      // A[0]は欠番
	vector<int> A_add(N + 1);  // A[0]は欠番
	vector<int> A_sub(N + 1);  // A[0]は欠番

	for (int i = 1; i <= N; i++) {
		scanf("%d", &A[i]);
		A_add[i] = A[i] + i;
		A_sub[i] = -A[i] + i;
	}

	long long result = 0;

	sort(A_add.begin(), A_add.end());
	sort(A_sub.begin(), A_sub.end());

	// for (int i = 1; i <= N; i++) {
	// 	cout << A[i] << " " << A_add[i] << " " << A_sub[i] << "\n";
	// }
	int a = 1;
	int s = 1;
	long a_count = 0;
	long s_count = 0;
	while (true) {
		a_count = 1;
		// cout << "A_add=" << A_add[a] << "\n";
		while (true) {
			if (A_add[a + 1] == A_add[a]) {
				a_count++;
				a++;
				if (a > N) {
					goto a_fin;
				}
			} else {
				break;
			}
		}
	a_fin:
		s_count = 0;
		while (true) {
			if (A_sub[s] == A_add[a]) {
				// cout << "A_sub[s] == A_add[a]\n";
				s_count++;
				s++;
				if (s > N) {
					goto s_fin;
				}
			} else if (A_sub[s] < A_add[a]) {
				// cout << "A_sub[s] < A_add[a]\n";
				s++;
				if (s > N) {
					goto s_fin;
				}
			} else {
				// cout << "A_sub[s] > A_add[a]\n";
				break;
			}
		}
	s_fin:
		// cout << A_add[a] << " " << a_count << " " << s_count << "\n";
		result += a_count * s_count;
		// cout << "result =" << result << "\n";
		a++;
		if (a > N || s > N) {
			break;
		}
	}
	cout << result;
	return 0;
}

Measured memory_bytes: 5644
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

vector<string> V;
void dfs(string W) {
	if (W.size() == 3) {
		V.push_back(W);
		return;
	}
	for (int i = 0; i <= 9; i++) {
		dfs(W + (char)('0' + i));
	}
}
int main()
{
	int N;
	string S;
	cin >> N >> S;
	int ans = 0;
	dfs("");
	for (string T : V) {
		//cout << T << endl;
		int k = 0;
		for (int j = 0; j < N; j++) {
			if (S[j] == T[k]) {
				k++;
			}
			if (k == 3) break;
		}
		if (k == 3) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int R = sc.nextInt();
    if(N>=10){
      System.out.println(R);
    }else{
      System.out.println(R+(100*(10-N)));
    }
  }
  

  
}

Measured memory_bytes: 22996
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n =sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		if(a%2==b%2) {
			long c = (b-a)/2;
			System.out.println(c);
		}
		else {
			
			long ans1 = a+(b-a-1)/2;
			long ans2 = n-b+1+(b-a-1)/2;
			System.out.println(Math.min(ans1,ans2));
		
			
		}
	}
}


Measured memory_bytes: 22612
from collections import defaultdict, deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def main():
    N, M, K = map(int, input().split())
    gf = [[] for _ in range(N)]
    gb = []
    for _ in range(M):
        a, b = [int(i) - 1 for i in input().split()]
        gf[a].append(b)
        gf[b].append(a)
    for _ in range(K):
        c, d = [int(i) - 1 for i in input().split()]
        gb.append((c, d))
    friend = defaultdict(int)
    ans = [0] * N
    par = [None] * N
    
    def dfs(v):
        if par[v] is None:  # 孤立している時は自分が親になる
            par[v] = v
            friend[par[v]] += 1
        for u in gf[v]:  # 隣接頂点の探索
            if par[u] is None:  # 孤立していたら親を一緒にする
                par[u] = par[v]
                friend[par[v]] += 1
                dfs(u)  # 再度探索する
    
    for i in range(N):
        if par[i] is None:
            dfs(i)
    for i in range(N):  # グラフサイズ - 隣接頂点数 - 自分自身
        ans[i] += friend[par[i]] - len(gf[i]) - 1
    for c, d in gb:
        if par[c] == par[d]:  # 「ブロック関係」で親が一緒の時は-1
            ans[c] -= 1
            ans[d] -= 1
    print(*ans)


if __name__ == '__main__':
    main()

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

Module Program
    Sub Main()
        Dim x1 As Integer = NextInt()
        Dim y1 As Integer = NextInt()
        Dim x2 As Integer = NextInt()
        Dim y2 As Integer = NextInt()

        Dim a As Integer = x2 - x1
        Dim b As Integer = y2 - y1

        Dim x3 As Integer = x2 - b
        Dim y3 As Integer = y2 + a
        Dim x4 As Integer = x3 - a
        Dim y4 As Integer = y3 - b

        Dim i As Integer = 0
        For Each j As Integer In New Integer() {x3, y3, x4, y4}
            If i <> 0 Then Write(" ")
            Write(j)
            i += 1
        Next
        WriteLine()
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    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: 19920
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<int> gr[2525],ed[2525];
bool sumi[2525];
priority_queue<int> p;
int a[2525],num[2525];
int gcd( int m, int n )
{
	int a=max(m,n),b=min(m,n);
	if(m==0) return n;if(n==0) return m;
	if(a%b==0) return b;
	return gcd(b,a-b*(a/b));
}
void cal(int v){
	//if(sumi[v]) return;
	sumi[v]=true;
	rep(i,gr[v].size()){
		int w=gr[v][i];
		if(sumi[w]) continue;
		ed[v].pb(w);
		num[w]++;
		cal(w);
	}
}
int main()
{
	int n;
	cin>>n;
	rep(i,n) cin>>a[i];
	sort(a,a+n);
	rep(i,n) rep(j,n){
		if(i!=j && gcd(a[i],a[j])>1) gr[i].pb(j),gr[j].pb(i);
	}
	memset(sumi,false,sizeof(sumi));
	memset(num,0,sizeof(num));
	rep(i,n){
		if(!sumi[i]){
			cal(i);p.push(i);
		}
	}
	vector<int> out;
	rep(i,n){
		int q=p.top();p.pop();
		out.pb(q);
		rep(j,ed[q].size()){
			int w=ed[q][j];
			num[w]--;
			if(num[w]<1) p.push(w);
		}
	}
	rep(i,n){
		cout<<a[out[i]];
		if(i<n-1) cout<<' ';else cout<<endl;
	}
}


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

int main() {
    int a;
    cin >> a;
    int ans = 0;
    ans += a;
    ans += a*a;
    ans += a*a*a;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
def main():
    n = int(input())
    A = list(map(int, input().split()))

    for a in A:
        if a % 2 == 0:
            if not (a % 3 == 0 or a % 5 == 0):
                print('DENIED')
                return
    print('APPROVED')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9080
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	for(int n;cin>>n;){
		pair<int,int> p[20];
		for(int i=0;i<n;i++) cin>>p[i].second>>p[i].first,p[i].first*=-1;
		sort(p,p+n);
		cout<<p[0].second<<' '<<p[0].first*-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
/* 	* In the name of GOD 
 	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define int long long

int32_t main(){
	int n;
	cin >> n;
	string s;
	while (n){
		s += ('a' + ((n - 1) % 26));
		n = (n - 1) / 26;
	}
	reverse (s.begin(), s.end());
	cout << s;
}


Measured memory_bytes: 3620
($n, $k, $q) = split/ /, <>;
@list = ();
for($i=0; $i<$n; $i++){
	$list[$i] = $k-$q;
}
while (my $line = <>){
	$list[$line-1]++;
}

foreach (@list){
	if($_ <= 0){
    	print "No"."\n";
    }else{
    	print "Yes"."\n";
    }
}

Measured memory_bytes: 4096
#include <iostream>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll t[100001] = {};
ll x[100001] = {};
ll y[100001] = {};
int main()
{
	ll N; cin >> N;
	rep(i, 1, N + 1) {
		cin >> t[i] >> x[i] >> y[i];
	}
	repe(i, 1, N) {
		ll T = t[i] - t[i - 1];
		ll X = x[i] - x[i - 1];
		ll Y = y[i] - y[i - 1];

		X = ((X < 0) ? -X : X);
		Y = ((Y < 0) ? -Y : Y);
		if (T < X + Y) {
			cout << "No" << endl;
			return 0;
		}
		else if ((T - (X + Y)) % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
using namespace std;

void solve()
{
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    solve();
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<'\n';
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define maxn 100010
using namespace std;
int a[maxn], res[maxn];
int main()
{
	int n;
	scanf("%d", &n);
	int yuan = n;
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for (int i = n; i >= 1; i--)
	{
		int flag = 0;
		for (int j = n; j >= 1; j--)
			if (a[j] == j)
			{
				res[i] = j;
				for (int k = j; k <= n - 1; k++)
					a[k] = a[k + 1];
				n--;
				flag = 1;
				break;
			}
		if (flag == 0) {puts("-1"); return 0;}
	}
	for (int i = 1; i <= yuan; i++)
		printf("%d\n", res[i]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1000;
const LL INF = 1e9;

void print_a(VI v)
{
    if(v.size()) cout<<v[0];
    loop(i,1,v.size()) cout<<' '<<v[i];
    cout<<'\n';
}

VVI init_vvi(int n, int m, int val)
{
    return VVI(n,VI(m,val));
}

VVL init_vvl(int n, int m, LL val)
{
    return VVL(n,VL(m,val));
}

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n,k;
    LL a;
    cin>>n>>k;
    VL po, ng;

    loop(i,0,n)
    {
        cin>>a;
        if(a > 0) po.PB(a);
        else if(a < 0) ng.PB(-a);
    }

    LL ans, n1 = po.size(), n2 = ng.size(), c2 = (n2/2) * 2;

    if((n1 + n2 != n) && ((k%2 == 1 && n1 == 0) || (n1 + c2 < k))) ans = 0;
    else if((k%2 == 1 && n1 == 0) || (n1 + c2 < k))
    {
        sort(all(ng));sort(all(po));
        ans = 1;
        int i1 = 0, i2 = 0;
        loop(i,0,k)
        {
            if(i1 == n1) {ans = (ans * ng[i2]) % MOD; ++i2;}
            else if(i2 == n2) {ans = (ans * po[i1]) % MOD; ++i1;}
            else if(po[i1] < ng[i2]) {ans = (ans * po[i1]) % MOD; ++i1;}
            else {ans = (ans * ng[i2]) % MOD; ++i2;}
        }
        ans = (MOD - ans) % MOD;
    }
    else
    {
        sort(all(po),greater<int>()); sort(all(ng),greater<int>());
        ans = 1;
        int i1 = 0, i2 = 0;
        while(k)
        {
            if(k == 1 || i2 >= n2 - 1) {ans = (ans * po[i1]) % MOD; --k; ++i1;}
            else if(i1 >= n1 - 1)
            {
                ans = (ans * ng[i2]) % MOD; --k; ++i2;
                ans = (ans * ng[i2]) % MOD; --k; ++i2;
            }
            else if(po[i1] * po[i1+1] <= ng[i2] * ng[i2+1])
            {
                ans = (ans * ng[i2]) % MOD; --k; ++i2;
                ans = (ans * ng[i2]) % MOD; --k; ++i2;
            }
            else
            {
                ans = (ans * po[i1]) % MOD; --k; ++i1;
            }
        }
    }

    cout<<ans<<'\n';

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n)
        {
            cin>>a[i];
        }
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n)
    {
        cin>>a[i];
    }
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


Measured memory_bytes: 5524
n = int(input())
s = [input() for i in range(n)]
ans = 0
for i in range(n):
    for j in range(len(s[i])-1):
        if s[i][j] == "A" and s[i][j+1] == "B":
            ans += 1

cnt_A = 0
cnt_B = 0
cnt_BA = 0

for i in range(n):
    if s[i][0] == "B" and s[i][-1] == "A":
        cnt_BA += 1
    elif s[i][0] == "B" and s[i][-1] != "A":
        cnt_B += 1
    elif s[i][0] != "B" and s[i][-1] == "A":
        cnt_A += 1 
ans += max(cnt_BA - 1, 0)
if cnt_BA > 0 and cnt_A > 0:
    ans += 1
    cnt_A -= 1
if cnt_BA > 0 and cnt_B > 0:
    ans += 1
    cnt_B -= 1
ans += min(cnt_A, cnt_B)
print(ans)

Measured memory_bytes: 45784
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;



ll X,A,ans;
ll L[105];

string S;


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	
	
	cin >> X >> A;

	if (X < A)cout << 0 << endl;
	else cout << 10 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) { cout << ", "; first = false; }
    cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) {}
#define debug_array(a) {}
#endif
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n);
  for (lli i=0; i<n; ++i) cin >> v[i];
}

lli n, k;
vector<lli> v;
int main() {
  cin >> n >> k;
  for (int i=0; i<n; ++i) {
    lli x; cin >> x;
    v.push_back(x);
  }
  lli ans = 1e9;
  for (int i=0; i<=n-k; ++i) {
    lli p = v[i], q = v[i+k-1];
    lli y;
    if (p>=0 && q>=0) y = q;
    else if (p<0 && q<0) y = -p;
    else y = q - p + min(-p, q);
    ans = min(ans, y);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
int main(){
  int64_t N;
  cin >> N;
  
  //10^N,9^N,8^Nをそれぞれmod d で個別に計算する．
  int64_t d = 1000000000+7;
  
  int64_t ten = 1;
  int64_t nine = 1;
  int64_t eight = 1;
  
  for(int i=0;i<N;i++){
    ten = (ten*10)%d;
    nine = (nine*9)%d;
    eight = (eight*8)%d;
  }
  
  int64_t ans = (ten -2*nine + eight+2*d)%d;
  
  cout << ans << endl;
}

Measured memory_bytes: 3628
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr ll INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld PI = acos(-1);
constexpr ld EPS = 1e-11;

int main(void){
	ll h, w, k;
	cin >> h >> w >> k;
	VecS s(h);
	rep(i, h) cin >> s[i];

	ll ans = LINF;
	rep(bit, pow2(h - 1)){
		bitset<10> bits(bit);
		ll m = bits.count();
		Vec2<ll> cntA(m + 1);
		rep(j, w){
			ll pos = 0;
			ll a = 0;
			rep(i, h){
				if(s[i][j] == '1') a++;
				if(bits[i] || i == h - 1){
					cntA[pos].pb(a);
					pos++;
					a = 0;
				}
			}
		}

		ll cnt = m;
		Vec sumA(m + 1);
		rep(j, w){
			bool flg = true;
			rep(i, m + 1){
				if(cntA[i][j] > k){
					cnt += INF;
				}
				flg &= (sumA[i] + cntA[i][j] <= k);
			}
			if(flg){
				rep(i, m + 1){
					sumA[i] += cntA[i][j];
				}
			}else{
				cnt++;
				rep(i, m + 1){
					sumA[i] = cntA[i][j];
				}
			}
		}
		chmin(ans, cnt);
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#define o(x) cout << x << '\n'
#define on() cout << '\n'
#define os(x) cout << x << ' '

#define i(x) cin >> x
#define i2(x, y) cin >> x >> y

#define DBG = 1

using ll = long long;


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

    int n, k;
    i2(n, k);

    vector<int> h(n);
    vector<int> dp(n, pow(2, 31) - 1);

    for (auto &x: h) {
        i(x);
    }

    dp[0] = 0;
    for (int from = 0; from < n; ++from) {
        for (int i = 1; i <= k; ++i) {
            int to = from + i;
            int cost = abs(h[from] - h[to]);

            dp[to] = min(dp[to], dp[from] + cost);
        }
    }

    o(dp[n - 1]);

    return 0;
}

Measured memory_bytes: 1024
n = gets.to_i
a = gets.split.map(&:to_i).sort
b = Array.new(10 ** 6 + 1, true)
for i in 0...(n - 1) do
  next if b[a[i]] == false
  v = a[i] * 2
  while v <= 10 ** 6 do
    b[v] = false
    v += a[i]
  end
  b[a[i]] = false if a[i] == a[i + 1]
end
count = 0
a.each do |v|
  count += 1 if b[v] == true
end
puts count


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

// i think we could use at most 2 nested brackets, more than 2 is unneccessary
// dp[i][j] = max answer [i..n-1] if we've opened j brackets before

const int N=1e5+5;
ll n,dp[N][3];
vector<ll> a;

ll go(int i,int br){
	if(i==n) return 0;
	ll& res=dp[i][br];
	if(~res) return res;
	res=0;
	ll val=(br&1)?-a[i]:a[i];
	res=max(res,go(i+1,br)+val);
	if(a[i]<0&&br<2) res=max(res,go(i+1,br+1)+val);
	if(br>0) res=max(res,go(i+1,br-1)+val);
	return res;
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	bool neg=false;
	for(int i=0;i<n+n-1;++i){
		if(i&1){
			char sign;
			cin>>sign;
			neg=sign=='-';
		}
		else{
			ll x;
			cin>>x;
			a.push_back(neg?-x:x);
			neg=false;
		}
	}
	memset(dp,-1,sizeof(dp));
	cout<<go(0,0);
}



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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;

template<typename T>
T modPow(T x, T n, const T &mod){
    T res = 1;
    while(n > 0){
        if(n & 1) (res *= x) %= mod;
        (x *= x) %= mod;
        n >>= 1; // nを1bit左にずらす
    }
    return res;
}

int main() {
    int n; cin >> n;
    string s1, s2; cin >> s1 >> s2;

    ll sum = 0;
    bool x = false, y = false;
    for(int i = 0; i < n; i++){
        if(i == 0){
            if(s1[i] == s1[i + 1]){
                sum += 6;
                y = true;
                i++;
            }
            if(s1[i] == s2[i]){
                sum += 3;
                x = true;
            }
        }else{
            if(s1[i] == s1[i + 1]){
                if(x) (sum *= 2) %= MOD;
                else if(y) (sum *= 3) %= MOD;
                y = true;
                x = false;
                i++;
            }else if(s1[i] == s2[i]){
                if(x) (sum *= 2) %= MOD;
                x = true;
                y = false;
            }
        }
    }

    cout << sum % MOD << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    ll n;
    cin >> n;
    if (n%2 == 0) cout << n << endl;
    else cout << n*2 << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>

int n, A[2000];

int solve (int i, int m)
{
  if (m == 0) {
    return 1;
  }
  if (i >= n) {
    return 0;
  }
  int res = solve (i + 1, m) || solve (i + 1, m - A[i]);
  return res;
}

int main()
{
  int q, i, M;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &M);
    if(solve (0, M)) {
      printf("yes\n");
    } else {
      printf("no\n");
    }
  }

  return 0;
}



Measured memory_bytes: 1916
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(vec) vec.begin(), vec.end()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define repc(bit, k, n) for (ll bit = (1 << k) - 1; bit < (1 << n); bit = next_combination(bit))
#define repi(itr, vec) for (auto itr = vec.begin(); itr != vec.end(); ++itr)
using namespace std;

int factorize(ll n)
{
  int ret = 1;
  for (int i = 2; i * i <= n; i++)
  {
    int temp = 0;
    while (n % i == 0)
    {
      temp++;
      n /= i;
    }
    if (temp != 0)
      ret *= (temp + 1);
  }
  if (n > 1)
    ret *= 2;
  return ret;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  int ans = 0;
  rep(i, n - 1)
  {
    ans += factorize(i + 1);
  }
  cout << ans << endl;

  return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int MAX_N = 50100;
int n;
int prime[MAX_N];
bool isPrime[MAX_N+1];
int ptr;
int pos;

int main()
{
  prime[ptr++] = 2;
  for(int i=2; i<=MAX_N; i+=2) isPrime[i] = true;
  for(int i=3; i<=MAX_N; i+=2){
    if(!isPrime[i]){
      prime[ptr++] = i;
      for(int j=2*i; j<=MAX_N; j+=i){
        isPrime[j] = true;
      }
    }
  }

  while((cin >> n) && n){
    pos = upper_bound(prime, prime+ptr, n) - prime;
    cout << (prime[pos-1]==n ? prime[pos-2] : prime[pos-1]) << " " << prime[pos] << endl;
  }

  return 0;
}

Measured memory_bytes: 1232
# 素因数分解
def prime_decomposition(n):
	i = 2
	table = []
	while i * i <= n:
		while n % i == 0:
			n //= i
			table.append(i)
		i += 1
	if n > 1:
		table.append(n)
	return table

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

# nCr mod m
def combination(n, r, mod=10**9+7):
	r = min(r, n-r)
	res = 1
	for i in range(r):
		res = res * (n - i) * modinv(i+1, mod) % mod
	return res

# nHr mod m
def H(n, r, mod=10**9+7):
	return combination(n+r-1, r, mod)

from collections import defaultdict
N, M = map(int, input().split())
prime_table = prime_decomposition(M)
dic = defaultdict(int) #指数のリスト
for p in prime_table:
    dic[p] += 1

ans=1
for p, b in dic.items():
	ans *= H(N, b, mod=10**9+7)
print(ans%(10**9+7))

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

using namespace std;

typedef long long ll;
const  int INF =1e9+1;

int main(){
    int N,W;
    cin>>N>>W;

    vector<ll> value(N),weight(N);
    for(int i=0; i<N; i++){
        cin>>weight[i]>>value[i];
    }

    vector<vector<ll>> dp(N+1,vector<ll>(N*1010+1,INF));
    dp[0][0]=0;

    for(int n=0; n<N; n++){
        for(ll v=0; v<=N*1010; v++){
            if(v>=value[n]){
                dp[n+1][v]=min(dp[n][v-value[n]]+weight[n],dp[n][v]);
            }else{
                dp[n+1][v]=dp[n][v];
            }
        }
    }

    ll best_score=0;

    for(ll j=0; j<=N*1010; j++){
        if(dp[N][j]<=W){
            //cout<<dp[N][j]<<" ";
            best_score=max(best_score,j);
        }
    }
    
    cout<<best_score<<endl;

    return 0;
}

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

int main()
{
  int n,i,c=0,t=0;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  
  for(i=1;i<n;i++)
  {
    if(a[i]<=a[i-1])
    {
      t++;
      c=max(t,c);
    }
    else{
      c=max(c,t);
      t=0;
    }
  }
  cout<<c;
  return 0;
}


Measured memory_bytes: 640
/*
  Author : Vikram Singh
  Goal   : Want to become RED on codeforces
  from   : Bharat
*/

#include<bits/stdc++.h>

using namespace std;


typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld > vd;
typedef vector<ll > vl;
typedef vector<pi >  vpi;
typedef vector<pl > vpl;
typedef vector<cd > vcd;


#define FOR(i, a, b) for(int i = (a); i< (b);i++)
#define F0R(i, a)    for(int i=0;i<(a);i++)
#define FORd(i, a, b) for(int i = (b) - 1; i>=(a);--i)
#define F0Rd(i, a)   for(int i = (a) - 1;i>=0;--i)
#define trav(p, x)  for(auto& p : x)

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 205;
const int MAX = 500 * 1000 + 11; 
const ld PI = 4*atan((ld)1);


int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    
    int z = 0,o = 0;
    int ans = 0;
    vector<pair<int, int> >a;
    for(int i=0;i<n;i++){
    	if(s[i] == '0') z++;
    	else o++;
    	
    	if(z != 0 && o != 0){
    		if(s[i-1] == '0'){
    			a.push_back({z,0});
    		}
    		else{
    			a.push_back({o,1});
    			ans = max(ans, o);
    		}
    		z = o = 0;
    		--i;
    	}
    }
    if(z != 0) a.push_back({z, 0});
    if(o != 0) a.push_back({o, 1});
    ans = max(ans, o);
     
    vector<int >zero;
    for(int i=0;i<a.size();i++){
    	if(a[i].se == 0) zero.push_back(i);
    }
    
    vector<int > pre;
    int sum = 0;
    for(int i=0;i<a.size();i++){
    	sum += a[i].fi;
    	pre.push_back(sum);
    }
    
    for(int i=0;i<zero.size();i++){
    	int start  = zero[i];
    	int end;
    	if(i+k-1 > zero.size()-1) end = zero[zero.size()-1];
    	else end = zero[i+k-1];
    	if(start > 0) start--;
    	if(end < (int)a.size()-1) end++;
    //	cout<<"start and end is : "<<start <<" "<<end<<"\n";
    	int cnt = pre[end] - pre[start] + a[start].fi;
    	ans = max(ans, cnt);
    }
    
    cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 2244
N,K = [int(x) for x in input().split()]
 
result = 0
 
if (K%2) == 1:
    kouho = N//K
    result+=kouho*kouho*kouho
 
else:
    kouho1 = N//K
    kouho2 = N//(K/2) - kouho1
    result+=kouho1*kouho1*kouho1
    result+=kouho2*kouho2*kouho2
 
print(int(result))
 

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


int main(){
  int n;
  cin>>n;
  int ans=0;
  for(int i=1;i<=n;i++){
    int tmp=floor(log10(i)+1);
    if(tmp%2!=0){
      ans++;
    }
  }
  cout<<ans<<endl;
}


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

function main()
	n,k = readline() |> split |> parseMap
	s = chomp(readline())
	a = Int[]
	b = Int[0]
	f = s[1]=='0'?0:1
	t = 1
	for i in 2:n
		if s[i-1] != s[i]
			push!(a,f)
			f = f==0?1:0
			push!(b,t)
			b[length(b)] += b[length(b)-1]
			t = 1
		else
			t += 1
		end
	end
	if t != 0
		push!(a,f)
		push!(b,t)
		b[length(b)] += b[length(b)-1]
	end
	l = length(a)
	if l == 1
		println(n)
	else
		m = 0
		if k%2 == 0
			for i in 1:l
				if a[i] == 1
					x = b[min(i+k+1,l+1)]-b[max(i-k,1)]
					m = max(m,x)
				end
			end
		else
			for i in 1:l
				if a[i] == 0
					x = b[min(i+k+1,l+1)]-b[max(i-k,1)]
					m = max(m,x)
				end
			end
		end
		println(m)
	end
end
main()


Measured memory_bytes: 118668
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int N =sc.nextInt();
        int x =sc.nextInt();
        int a[] = new int[N];
        int count=0;
        int sw=0;
        
        
        
        for(int i=0;i<N;i++){
            a[i] =sc.nextInt();
        }
        
        Arrays.sort(a);
        
        for(int i=0;i<N;i++){
            if(a[i]<=x){
                x -= a[i];
                count++;
            }else{
                sw=1;
                break;
            }
        }
        if(x>0 && sw==0){
            count--;
        }
        System.out.println(count);
        
        
        
        
        
        
        
    }
}


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


int main(void){
    // Your code here!
    long long x;
   
    cin>>x;
    
    //bool end=false;
    //int a,b;
    for(int i=0;i<=1000;i++){
      for(int j=-1000;j<=1000;j++){
        if(pow(i,5) - pow(j,5)==x){
          cout<<i<<" "<<j<<endl;
          return 0;
        }
      }
    }
    
}


Measured memory_bytes: 3936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

ll n, a, sum, mod = 1e9+7, ans;

int main() {
	fastio; cin >> n;
	FOR(i, 1, n) {
		cin >> a;
		ll cur = (sum * a) % mod;
		ans = (ans + cur) % mod;
		sum = (sum + a) % mod;
	}
	cout << ans;
}


Measured memory_bytes: 3676
n = int(input())
s = input().rstrip().split(" ")
min = 1000000
max = -1000000
sum = 0
for i in s:
    x = int(i)
    if x < min:
        min = x
    if x > max:
        max = x
    sum += x
print("%d %d %d" % (min,max,sum))

Measured memory_bytes: 8408
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	if((a*b)%2==0)
		printf("Even\n");
		else
			printf("Odd\n");
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    a,b,c = inputMap()
    
    if b-a == c-b:
        print("YES")
    else:
        print("NO")
    
    
if __name__ == "__main__":
	main()


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

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

  string WB;
  for(int i=0;i<S.size();++i){
    if(i%2==0){
      WB=WB+'1';
    }
    else{
      WB=WB+'0';
    }
  }
  
  int sum1=0,sum2=0;
  for(int i=0;i<S.size();++i){
    if(S.at(i)==WB.at(i)){
      ++sum1;
    }
    else{
      ++sum2;
    }
  }
  
  cout<<min(sum1,sum2)<<endl;
}

Measured memory_bytes: 696
#include <cstdio>
#include <algorithm>
#include <utility>
#include <queue>
#include <vector>
#include <functional>
#include <climits>
#include <cmath>

using std::min;
using std::pair;
using std::priority_queue;
using std::vector;
using std::greater;

typedef pair<int,int> range;
typedef pair<int,int> number;
typedef pair<number,range> sub_qry;

const int MAXN=2e5+5,MAXLOG=(int)(log(MAXN)/log(2)+0.5);
int p[MAXN];

class SparseTab{
	private:
		int log_tab[MAXN];
		number c[MAXLOG][MAXN];
	public:
		//number min(number &a,number &b){
		//	return a.first<b.first ? a:b;
		//}
		void build(int n,int a[],bool type){
			log_tab[0]=-1;
			for(int i=1;i<=n;++i){
				c[0][i]=number((i&1)==type ? a[i]:INT_MAX,i);
				log_tab[i]= i&(i-1) ? log_tab[i-1]:log_tab[i-1]+1;
			}
			for(int i=1;i<=log_tab[n];++i){
				for(int j=1;j+(1<<i)-1<=n;++j)
					c[i][j]=min(c[i-1][j],c[i-1][j+(1<<i-1)]);
			}
		}
		number qry(int l,int r){
			int k=log_tab[r-l+1];
			return min(c[k][l],c[k][r-(1<<k)+1]);
		}
}odd,even;

inline void solve(int n){
	static priority_queue<sub_qry,vector<sub_qry>,greater<sub_qry> > hp;
	number tmp1=odd.qry(1,n),tmp2=even.qry(tmp1.second,n);
	printf("%d %d ",tmp1.first,tmp2.first);
	if(1<=tmp1.second-1)
		hp.push(sub_qry(odd.qry(1,tmp1.second-1),range(1,tmp1.second-1)));
	if(tmp1.second+1<=tmp2.second-1)
		hp.push(sub_qry(even.qry(tmp1.second+1,tmp2.second-1),range(tmp1.second+1,tmp2.second-1)));
	if(tmp2.second+1<=n)
		hp.push(sub_qry(odd.qry(tmp2.second+1,n),range(tmp2.second+1,n)));
	sub_qry now;
	number that;
	SparseTab *st1,*st2;
	while(hp.size()){
		now=hp.top();
		hp.pop();
		st1= now.second.first&1 ? &odd:&even;
		st2= now.second.first&1 ? &even:&odd;
		that=st2->qry(now.first.second,now.second.second);
		printf("%d %d ",now.first.first,that.first);
		if(now.second.first<now.first.second-1)
			hp.push(sub_qry(st1->qry(now.second.first,now.first.second-1),range(now.second.first,now.first.second-1)));
		if(now.first.second+1<that.second-1)
			hp.push(sub_qry(st2->qry(now.first.second+1,that.second-1),range(now.first.second+1,that.second-1)));
		if(that.second+1<now.second.second)
			hp.push(sub_qry(st1->qry(that.second+1,now.second.second),range(that.second+1,now.second.second)));
	}
}

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&p[i]);
	odd.build(n,p,1),even.build(n,p,0);
	solve(n);
	return 0;
}

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

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

int main(){
  int N,L;
  cin >> N >> L;
  vector<string> p(N);
  rep(i,N){
    cin >> p[i];
  }
  string ans;
  sort(p.begin(),p.end());

  rep(i,N){
    ans += p[i];
  }
  cout << ans << endl;
}

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

using ll = long long;
#define REP(i,n) for(int i = 0;i < n;i++)

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

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

    REP(i,5){
        int64_t foo;cin >> foo;
        if(foo == 0){
            cout << i+1 << '\n';
            return 0;
        }
    }
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(string S){
	ll n = S.length();
	bool flg = true;
	rep(i, n) {
		if (S[i] != S[(n-1)-i]) flg = false;
	}
	rep(i, (n-1)/2) {
		if (S[i] != S[(n-1)/2-1-i]) flg = false;
	}
	rep(i, (n-1)/2) {
		if (S[i+(n+3)/2-1] != S[(n-1)/2-1-i+(n+3)/2-1]) flg = false;
	}
	if (flg) cout << "Yes" << endl; else cout << "No" << endl;
}

int main(){	
	string S;
	cin >> S;
	solve(S);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n, a, b;
    cin >> n >> a >> b;

    ll res = min(n * a, b);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    long int cnt =0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]!=t[i])
        {
            cnt++;
        }

    }
            cout<<cnt<<endl;
            return 0;
}


Measured memory_bytes: 3816