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

long long gcd(long long a, long long b) {
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
void solve(long long A, long long B) { cout << lcm(A, B) << endl; }

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can
// remove this line by using your custom template)
int main() {
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto ABCD = RD!string;
	long[4] a;
	foreach (i, c; ABCD)
	{
		a[i] = [c].to!long;
	}

	foreach (i; 0..0b1000)
	{
		auto r = a[0];
		string ans = a[0].to!string;
		foreach (j; 0..3)
		{
			if ((i & (1 << j)))
			{
				r += a[j+1];
				ans ~= "+";
			}
			else
			{
				r -= a[j+1];
				ans ~= "-";
			}
			ans ~= a[j+1].to!string;
		}
		if (r == 7)
		{
			writeln(ans ~ "=7");
			break;
		}
	}

	stdout.flush();
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int n,k;
	int c = 0;

	scanf("%d", &n);
	scanf("%d", &k);
	int h[n];

	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &h[i]);
		if (h[i] < k) {
			c++;
		}
	}
	printf("%d", n - c);
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	
	static final int MAX_NUM_OF_PRIME_NUMBERS = 10000;
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			int numOfPrimeNumbers = Integer.parseInt(br.readLine());
			if( numOfPrimeNumbers == 0 )	break;
			System.out.println(getSumOfPrimeNumbers(numOfPrimeNumbers));
		}
	}
	public static long getSumOfPrimeNumbers(int numOfPrimeNumbers){
		long sum = 0;
		long[] primeNumber = getPrimeNumbers();
		for(int i = 0; i < numOfPrimeNumbers; i++){
			sum += primeNumber[i];
		}
		return sum;
	}
	private static long[] getPrimeNumbers(){
		long[] primeNumber = new long[MAX_NUM_OF_PRIME_NUMBERS];
		int numPrimeNumbers = 0;
		long n = 1;
		while(numPrimeNumbers < MAX_NUM_OF_PRIME_NUMBERS){
			if( isPrimeNumber(++n) ){
				primeNumber[numPrimeNumbers] = n;
				numPrimeNumbers++;
			}
		}
		return primeNumber;
	}
	private static boolean isPrimeNumber(long target){
		if( target == 2 )	return true;
		if( target % 2 == 0 )	return false;
		for(int i = 3; i * i < target + 1; i = i + 2){
			if( target % i == 0){
				return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 24436
#include <iostream>
#include <string>
#include <vector>
using namespace std;

char opposite(char a)
{
	if(a == 'W') return 'S';
	else return 'W';
}

char judgeByPreviousTwo(char a, char b, char c)
{
	if(b == 'S'){
		if(c == 'o') return a;
		if(c == 'x') return opposite(a);
	}else if(b == 'W'){
		if(c == 'o') return opposite(a);
		if(c == 'x') return a;
	}
}

char checkValidity(char a, char b, char c)
{
	if(b == 'S'){
		if(a == c) return 'o';
		else return 'x';
	}else{
		if(a != c) return 'o';
		else return 'x';
	}
}

int ind(int j, int size)
{
	if(j < 0) return size + j;
	if(j >= size) return j - size;
	return j;
}

int main()
{
	int n = 0; cin >> n;
	string s; cin >> s;

	vector<string> initial_patterns = {
		"SS", "SW", "WS", "WW",
	};

	bool found = false;
	string ans(n, '0'); 		
	for(int i = 0; i < initial_patterns.size(); i++){
		ans.replace(n - 2, 2, initial_patterns[i]);
		string check_validity(n, '0');
		for(int j = 0; j < n; j++){
			if(j < n - 2) ans[j] = judgeByPreviousTwo(ans[ind(j - 2, n)], ans[ind(j - 1, n)], s[ind(j - 1, n)]);
			check_validity[ind(j - 1, n)] = checkValidity(ans[ind(j - 2, n)], ans[ind(j - 1, n)], ans[ind(j, n)]);
			if(check_validity[ind(j - 1, n)] != s[ind(j - 1, n)]) break;
			if(j == n - 1) found = true;
		}
		// cout << ans << endl;
		// cout << check_validity << endl;
		if(found) break;
	}
	if(found) cout << ans << endl;
	else cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int n,a[50];
bool solve(int i,int m)
{
    if(m==0) return true;
    if(i>=n) return false;
    int res=solve(i+1,m)||solve(i+1,m-a[i]);
    return res;
}
int main()
{
    int q,m,i;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    cin>>q;
    for(i=0;i<q;i++)
    {
        cin>>m;
        if(solve(0,m))
        cout<<"yes"<<endl;
        else
        cout<<"no"<<endl; 
    }
    return 0;
}



Measured memory_bytes: 3116
#include<stdio.h>
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
int W,H;
char M[80][80];

string cmp(string a,string b)
{
	if(a=="0")a="";
	if(b=="0")b="";
	if(a.length()==b.length())
		return a>b?a:b;
	else
		return a.length()>b.length()?a:b;
}

int main()
{
	for(;scanf("%d%d\n",&W,&H),W+H;)
	{
		string res="";
		string dp[80][80];
		for(int i=0;i<H;i++)
			gets(M[i]);
		for(int i=0;i<H;i++)
			for(int j=0;j<W;j++)
			{
				if(M[i][j]<='9')
				{
					string a="",b="",c="";
					if('1'<=M[i][j]&&M[i][j]<='9')
					{
						char s[2]="";s[0]=M[i][j];
						c=string(s);
					}
					if(i>0)
						a=dp[i-1][j]+M[i][j];
					if(j>0)
						b=dp[i][j-1]+M[i][j];
					dp[i][j]=cmp(cmp(a,b),c);
				}
				else
				{
					dp[i][j]="";
				}
			}
		for(int i=0;i<H;i++)
			for(int j=0;j<W;j++)
				res=cmp(res,dp[i][j]);
		cout<<res<<endl;
	}
}

Measured memory_bytes: 1416
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <numeric>

using namespace std;

typedef unsigned long ulong;

static unordered_map<ulong, unordered_map<ulong, ulong>> g_gcd_cache;
static unsigned long euclidean_gcd(unsigned long a, unsigned long b) {

    auto origA = a, origB = b;
    auto it1 = g_gcd_cache.find(a);
    if (it1 != g_gcd_cache.end())
    {
        auto it2 = it1->second.find(b);
        if (it2 != it1->second.end())
        {
            return it2->second;
        }
    }

    if (a < b)
    {
        auto v = euclidean_gcd(b, a);
        return v;
    }
    unsigned r;
    while ((r = a%b)) {
        a = b;
        b = r;
    }
    g_gcd_cache[origA][origB] = b;
    g_gcd_cache[origB][origA] = b;
    return b;
}


int main()
{
    size_t N, Q;
    cin >> N >> Q;

    string str;
    cin >> str;

    int totalAppearCount = 0;

    vector<int> appearAC(str.size());
    for (size_t i = 0; i+1 < str.size(); ++i) {
        if (str[i] == 'A' && str[i + 1] == 'C') {
            appearAC[i] = 1;
            appearAC[i + 1] = 0;
            totalAppearCount++;
            i++;
        }
        else {
            appearAC[i] = 0;
        }
    }

    vector<int> appearACFromToRightest(str.size());
    for (size_t i = 0; i + 1 < str.size(); ++i) {
        appearACFromToRightest[i] = totalAppearCount;
        totalAppearCount -= appearAC[i];
    }

    // Get Questions
    for (size_t q = 0; q < Q; ++q) {
        size_t L, R;

        cin >> L >> R;

        L--; R--;
        int count = appearACFromToRightest[L] - appearACFromToRightest[R];

        cout << count << endl;
    }


    return 0;
}


Measured memory_bytes: 1792
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	xs := make([]int, n)
	for i := range xs {
		fmt.Scan(&xs[i])
	}

	for {
		sort.Ints(xs)
		min := xs[0]
		nexts := make([]int, 1)
		nexts[0] = min
		for i := 1; i < len(xs); i++ {
			if xs[i]%min != 0 {
				nexts = append(nexts, xs[i]%min)
			}
		}
		if len(nexts) == 1 {
			fmt.Println(min)
			break
		}
		xs = nexts
	}
}


Measured memory_bytes: 7296
import java.util.Scanner;
class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        String N = sc.next();
        String[] ar = N.split("");
        int sum=0;
        
        for(int i=0;i<N.length();i++){
            sum += Integer.parseInt(ar[i]);
        }
        String ans="No";
        if(sum%9==0) ans = "Yes";
        System.out.println(ans);
    }
}

Measured memory_bytes: 65224
package main

import "fmt"

func divisors(n int) []int {
	r := make([]int, 0)
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			r = append(r, i)
			if i*i != n {
				r = append(r, n/i)
			}
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 1; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func main() {
	var N int
	fmt.Scan(&N)
	// fmt.Println("Divisors of", N, divisors(N))
	divs := divisors(N)
	ans := int(1e12) + 1
	for i := 0; i < len(divs); i++ {
		ops := (N/divs[i] + divs[i] - 2)
		if ans > ops {
			ans = ops
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 768
//usr/bin/env go run $0 $@ ; exit

package main
 
import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)
 
func run() {
	n := nextInt()
	k := nextInt()
	s := nextInt()
	
	if( k/n >= s){
		Println(s)
	}else {
		Println(k/n)
	}
}

// --- template ---
// Thanks https://gist.github.com/halllllll/853ab587fd82ee3ffe6f7fb7fb499695
 
var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
 
// Caution: You will get unexpected result if a single token is larger than this size.
const BufferSize = 64 * 1024 * 1024
 
func Print(a ...interface{}) (n int, err error) {
	return fmt.Fprint(out, a...)
}
 
func Printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, format, a...)
}
 
func Println(a ...interface{}) (n int, err error) {
	return fmt.Fprintln(out, a...)	
}
 
func next() string {
	sc.Scan()
	return sc.Text()
}
 
func nextInt() int {
	a, err := strconv.Atoi(next())
	if err != nil {
		log.Fatal(err)
	}
	return a
}
 
func nextFloat() float64 {
	a, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		log.Fatal(err)
	}
	return a
}

 
func main() {
	sc.Buffer(make([]byte, 0, BufferSize), BufferSize)
	sc.Split(bufio.ScanWords)
	run()
	out.Flush()
}


Measured memory_bytes: 2816
while 1:
	n=input()
	if n==0:break
	dic={}
	for i in range(n):
		msg=raw_input().split()
		for word in msg:
			try:dic[word]+=1
			except:dic[word]=1
	alpha=raw_input()
	ans=[]
	for k,v in sorted(sorted(dic.items()),key=lambda x:x[1],reverse=True):
		if k[0]==alpha:ans.append(k)
	print " ".join(map(str,ans)) if len(ans)>0 else "NA"

Measured memory_bytes: 4244
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) { new Main(); }
	FS in = new FS();
	PrintWriter out = new PrintWriter(System.out);

	
	
	Main() {
		String s = in.next();
		String t = in.next();
		out.println((t + s));
		out.close();
	}

	
	
	int abs(int x) { if (x < 0) return -x; return x; }
	long abs(long x) { if (x < 0) return -x; return x; }
	int max(int x, int y) { if (x < y) return y; return x; }
	int min(int x, int y) { if (x > y) return y; return x; }
	long max(long x, long y) { if (x < y) return y; return x; }
	long min(long x, long y) { if (x > y) return y; return x; }

	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }

		void intArr(int sz, int[] x) { for (int i = 0; i < sz; i++) x[i] = nextInt(); }
		void longArr(int sz, long[] x) { for (int i = 0; i < sz; i++) x[i] = nextLong(); }
		void doubleArr(int sz, double[] x) { for (int i = 0; i < sz; i++) x[i] = nextDouble(); }
	}
}



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

int main(){
  
  int A,B,K;
  cin >>A>>B>>K;
  
  int maxAB = max(A,B);
  
  vector<int> ans(1,1);
  
  for(int i=2;i<=maxAB;i++){
    if(A%i==0&&B%i==0){
      ans.push_back(i);
    }
  }
  
  cout << ans[ans.size()-K] << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int k,s;
    cin>>k>>s;
    int ans=0;
    for(int i=0;i<=k;i++)
    {
        for(int j=0;j<=k;j++)
        {
            int ij=s-i-j;
            if(ij<=k&&ij>=0)
                ans++;
        }
    }
    cout<<ans<<endl;
}

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

int main(){
	int h,w;
	string s;
	cin >> h >> w;
	for(int i=0;i<w+2;i++){
		cout << "#";
	}
	cout << endl;
	for(int i=0;i<h;i++){
		cin >> s;
		cout << "#" << s << "#" << endl;
	}
	for(int i=0;i<w+2;i++){
		cout << "#";
	}
	cout << endl;
	return 0;
}

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

using namespace std;

int cnt;
int m;
vector<int> G;

void insertionSort(vector<int>& vec, int g)
{
  for(int i=g; i<vec.size(); i++) {
    int v = vec[i];
    int j = i-g;
    while(j >= 0 && vec[j] > v) {
      vec[j+g] = vec[j];
      j = j - g;
      cnt ++;
    }
    vec[j+g] = v;
  }
}

void shellSort(vector<int>& vec)
{
  cnt = 0;

  G.push_back(1);
  for(int i=1; 3*G[i-1]+1 < vec.size() && G.size()<=100; i++) {
    G.push_back(3*G[i-1]+1);
  }
  m = G.size();
  reverse(G.begin(), G.end());
  
  for(int i=0; i<m; i++) insertionSort(vec, G[i]);
}

int main()
{
  int N; cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++) cin >> vec[i];
  
  cnt = 0;
  shellSort(vec);
  
  cout << m << endl;
  for(int i=0; i<m; i++) {
    if(i) cout << " ";
    cout << G[i];
  }
  cout << endl;
  cout << cnt << endl;
  
  for(int i=0; i<N; i++) {
    cout << vec[i] << endl;
  }

  return 0;
}

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

int main(){
	int n;
	long long sum=0;
	cin>>n;
	int a[n+2];
	a[0]=0;
	a[n+1]=0;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=0;i<=n;i++) sum+=abs(a[i]-a[i+1]);
	for(int i=1;i<=n;i++) cout<<sum-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1])<<endl;
	return 0;
}


Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int A = in.nextInt();
			int B = in.nextInt();
			int C = in.nextInt();
			int D = in.nextInt();
			out.println(A * B > C * D ? A * B : C * D);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

	}
}


Measured memory_bytes: 22864
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int N, M, Q, p[509][509];

int main() {
	cin >> N >> M >> Q;
	for (int i = 1; i <= M; i++) {
		int L, R; cin >> L >> R; p[L][R]++;
	}
	for (int i = 1; i <= N; i++) { 
		for (int j = 1; j <= N; j++) p[i][j] += p[i][j - 1]; 
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) p[i][j] += p[i - 1][j];
	}

	for (int i = 1; i <= Q; i++) {
		int L, R; cin >> L >> R;
		cout << p[R][R] + p[L - 1][L - 1] - p[L - 1][R] - p[R][L - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1920
a,b,c=(int(x) for x in input().split())
nana_count=0
go_count=0
def check(x):
  if x==5:
      global go_count
      go_count+=1
  elif x==7:
      global nana_count
      nana_count+=1
check(a)
check(b)
check(c)
if nana_count==1 and go_count==2:
  print("YES")
else:
  print("NO")


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

int n,pd[100002];
vector<int> A;
inline void mmin(int &a,int b){
    a = min(a,b);
}
int main(){
    cin >> n;
    A = vector<int> (n);
    for(auto &a:A) cin >> a;
    memset(pd,63,sizeof pd);
    pd[n-1]=0;
    for(int i=n-2;i>=0;i--){
        if((i+2)<=(n-1))
            mmin(pd[i],pd[i+2]+abs(A[i]-A[i+2]));
        mmin(pd[i],pd[i+1]+abs(A[i]-A[i+1]));
    }
    cout << pd[0] << '\n';
}


Measured memory_bytes: 1024
import math
def is_prime(n):
    for i in range(2, int(math.sqrt(n)) + 1):
        if n%i ==0:
            return False
    return True
 
target = int(input())
 
not_found_flg = True
if target == 2:
    print("2")
else:
    if target %2 == 0:
        target = target+1
    result = 0

    while not_found_flg:
        if (is_prime(target)):
            result = target
            break
        target = target+2
 
    print(result)

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

#define fastio 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ld long double
#define forn(low,high,i) for(i = low; i < high; i++)
#define forrev(high,low,i) for(i = high; i >= low; i--)
#define all(v) v.begin(),v.end()
#define decimal_digits cout << fixed << setprecision(15);

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e9;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

inline int add(long long a, long long b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(long long a, long long b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(long long a, long long b){a %= mod; b %= mod; return (int)((long long) a * b % mod);}
inline int modexpo(long long a, long long b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(long long a, long long b){return mul(a, modexpo(b, mod - 2));}
inline int inv(long long a){return modexpo(a, mod - 2);}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

void pre(){ // Reset each global variable (esp. for graphs)
  
}

string s; int n;

const int N = 1e6 + 5;
long long cc[N][2];

long long dp(int idx, int carry){
  if(idx == n)
    return carry;
  long long &ans = cc[idx][carry];
  if(~ans)
    return ans;
  ans = INF;
  ans = min(ans, 10 - (s[idx] - '0') - carry + dp(idx + 1, 1));
  if(s[idx] - '0' + carry != 10)
    ans = min(ans, (s[idx] - '0') + carry + dp(idx + 1, 0));
  return ans;
}

void solve(){
  cin >> s;
  n = s.size();
  reverse(all(s));
  memset(cc, -1, sizeof cc);
  cout << dp(0, 0) << '\n';
}

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

  pre();

  int t = 1;
  // cin >> t;
  while(t--){
    solve();
  }

  ktj();
}


Measured memory_bytes: 79516
#include <iostream>
#include <vector>

using namespace std;

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

  int n, m;
  cin >> n >> m;
  vector<vector<int>> bs(m);
  vector<int> p(m);
  int k;
  for (int i = 0; i < m; i++) {
    cin >> k;
    bs[i].resize(k);
    for (int j = 0; j < k; j++) {
      cin >> bs[i][j];
      bs[i][j]--;
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }

  int ans = 0;
  for (int i = 0; i < (1 << n); ++i) {
    bool ok = true;
    for (int j = 0; j < m; j++) {
      int cnt = 0;
      for (auto s : bs[j]) {
        if ((i >> s) & 1) ++cnt;
      }
      if (cnt % 2 != p[j]) {
        ok = false;
        break;
      }
    }
    if (ok) ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}

vector<vector<double>> memo(50,vector<double>(50,-1));

double dfs(int depth,vi &vec,int left,int right) {
  if(memo[left][right] > 0) {
    return memo[left][right];
  }
  if(left >= right) {
    memo[left][right] = (double)(vec[left])/(double)(pow(2,depth));
    return (double)(vec[left])/(double)(pow(2,depth));
  }
  int N = right - left+1;
  double ans = 0;
  srep(i,1,(N/2)+1) {
    ans = max(ans,dfs(depth+1,vec,left,left+i-1)+dfs(depth+1,vec,left+i,right));
  }
  memo[left][right] = ans;
  return ans;
}
  
int main() {
  int N;
  cin >> N;
  vi V(N);
  rep(i,N) {
    cin >> V[i];
  }
  sort(rng(V));
  reverse(rng(V));
  if(N == 1) {
    cout << V[0] << endl;
    return 0;
  }
  double ans = 0;
  srep(i,1,(N/2)+1) {
    ans = max(ans,dfs(1,V,0,i-1)+dfs(1,V,i,N-1));
  }
  cout << setprecision(30) << ans << endl;
  return 0;
}

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

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

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<ll> A(N); rep(i, N) cin >> A[i];
  vector<ll> B(N); rep(i, N) cin >> B[i];
  priority_queue<pair<ll, int>> q;
  rep(i, N) {
    if (A[i] < B[i]) q.emplace(B[i], i);
    if (A[i] > B[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  ll ans = 0;
  while (!q.empty()) {
    int i = q.top().second; q.pop();
    ll x = B[(i - 1 + N) % N];
    ll z = B[(i + 1) % N];
    // B[i] - k*(x+z) >= u && B[i] - k*(x+z) >= A[i]
    // (B[i] - u) / (x + z)
    ll k1 = (B[i] - A[i]) / (x + z);
    ll k2 = (B[i] - max(x, z) - 1) / (x + z) + 1;
    ll k = min(k1, k2);
    if (k <= 0) k = 1;
    B[i] -= k * (x + z);
    ans += k;
    if (B[i] < A[i]) {
      cout << -1 << endl;
      return 0;
    }
    if (B[i] > A[i]) {
      q.emplace(B[i], i);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 9584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << "Hello World" << endl;
  }
  else {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> ans(n + 1), S(n + 1);
    for(int i = 0; i < n - 1; i++) {
        if(s[i] == 'A' and s[i+1] == 'C') {
            ans[i+1] = 1;
        }
    }
    partial_sum(ans.begin(), ans.end(), S.begin());
    for(int i = 0; i < q; i++) {
        int L, R;
        cin >> L >> R;
        cout << S[R] - S[L - 1] - ans[R] << endl;
    }
    return 0;
}


Measured memory_bytes: 1872
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
signed main(){
	int a,b,x;
	cin>>x>>a>>b;
	if(b<=a) cout<<"delicious"<<endl;
	else if(b<=x+a) cout<<"safe"<<endl;
	else cout<<"dangerous"<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std; //std::の省略のため
using ll = long long;

int main()
{

  int n, d;
  cin >> n >> d;

  pair<ll, ll> pos[n];

  for (int i = 0; i < n; i++)
    cin >> pos[i].first >> pos[i].second;

  ll x, y;
  int count = 0;

  for (int i = 0; i < n; i++)
  {
    x = pos[i].first;
    y = pos[i].second;
    if (sqrt(x * x + y * y) <= d)
      count++;
  }

  cout << count << endl;
}


Measured memory_bytes: 6644
def solve():
    N = int(input())
    P = list(map(int, input().split()))
    bp = [False]*N
    for i in range(N):
        if P[i] == i+1:
            bp[i] = True
    counter = 0
    for b in bp:
        if not b:
            counter += 1
    if counter > 2:
        print('NO')
    else:
        print('YES')


solve()


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

const int N = 1e5 + 5;
int arr[N][3], memo[2][3];

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

	int n;
	cin >> n;

	rep(i, 0, n)
		rep(j, 0, 3)
			cin >> arr[i][j];

	for(int i = n - 1; i >= 0; i--)
	{
		for(int j = 2; j >= 0; j--)
		{
			int a = -1, b = -1;
			rep(k, 0, 3)
			{
				if (k == j)
					continue;
				if (a == -1)
					a = k;
				else
					b = k;
			}

			int curr = i&1, nxt = (curr&1) ^ 1;
			memo[curr][j] = arr[i][j] + memo[nxt][a];
			memo[curr][j] = max(memo[curr][j], arr[i][j] + memo[nxt][b]);
		}
	}

	cout << max(memo[0][0], max(memo[0][1], memo[0][2])) << endl;

	return 0;
}


Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main(){
int A[3][3],N,b[10],i,j,k,x=0;
for(j=1;j<=3;j++){cin >> A[1][j];}
for(j=1;j<=3;j++){cin >> A[2][j];}
for(j=1;j<=3;j++){cin >> A[3][j];}
cin >> N;
for(k=1;k<=N;k++){cin >> b[k];}
for(k=1;k<=N;k++){for(i=1;i<=3;i++){for(j=1;j<=3;j++){if(b[k]==A[i][j]){A[i][j]=0;}}}}

for(i=1;i<=3;i++){if((A[i][1]==A[i][2])&&(A[i][2]==A[i][3]))x++;}
for(j=1;j<=3;j++){if((A[1][j]==A[2][j])&&(A[2][j]==A[3][j]))x++;}
if((A[1][1]==A[2][2])&&(A[2][2]==A[3][3]))x++;
if((A[3][1]==A[2][2])&&(A[2][2]==A[1][3]))x++;
if(x>0){cout << "Yes" << endl;}else{cout << "No" <<endl;}
return 0;
}

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

int main(){
  int i,j,k,cnt=0;
  int n;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  int b[n];
  for(i=0;i<n;i++)b[i]=1;
  for(i=1;i<n;i++){
    if(a[i-1]==a[i]){
      b[cnt]++;
    }else cnt++;
  }
  int sum=0;
  for(i=0;i<=cnt;i++)sum+=b[i]%2;
  cout<<sum<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    ll N,M;
    cin>>N>>M;
    v A(N);
    rep(i,0,N)cin>>A[i];
    v sum(N,0);
    map<ll,ll> m;

    sum[0] = A[0]%M;
    m[sum[0]]++;
    rep(i,1,N){
        sum[i] = (sum[i-1] + A[i]) % M;
        m[sum[i]]++;
    }
    ll ans = 0;
    for(pair<ll,ll> elem : m){
        if(elem.first == 0)ans+=elem.second * (elem.second+1)/2 ;
        else ans += elem.second*(elem.second-1)/2;
    }
    cout<<ans;


    return 0;
}

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

int a[500100];
int a2[500100];
int main()
{
	int n;
	cin >> n;
	for( int i = 0; i < n; i++ ) {
		cin >> a[i];
		a2[i] = a[i] - (i+1);
	}
	sort( a2, a2+n+1 );
	int b = a2[n/2];
	int b2 = a2[(n/2)+1];
	long long sum = 0;
	long long sum2 = 0;
	//cout << "b=" << b << endl;
	for( int i = 0; i < n; i++ ) {
		sum += abs( a[i] - b-(i+1) );
		sum2 += abs( a[i] - b2-(i+1) );
	}
	cout << min(sum,sum2) << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<int> p;
	int i;
	for(i=0; i<n; i++){
		int x;
		cin >> x;
		p.push_back(x);
	}
	int count = 1, k = p[0];
	for(i=1; i<n; i++){
		if(p[i]<=k) count++;
		k = min(k, p[i]);
	}
	cout << count << "\n";
	return 0;
}


Measured memory_bytes: 4348
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

ll inf=1ll<<60,mod=1000000007;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int x,t;
	cin>>x>>t;
	cout<<max(0,x-t);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  ll n, m;
  cin >> n >> m;
  map<ll, ll> mp;
  rep (i, n) {
    ll a, b;
    cin >> a >> b;
    auto itr = mp.find(a);
    if (itr != mp.end()) mp[a] += b;
    else mp[a] = b;
  }

  ll ans = 0;
  ll count = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    // cout << itr->first << " => " << itr->second << endl;
    if (count + itr->second >= m) {
      ans += (m - count) * itr->first;
      break;
    } else {
      ans += itr->first * itr->second;
      count += itr->second;
    }
  }

  P(ans);
  return 0;

}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)

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

int main() {
	int k;
	cin >> k;
	ll sum = 0;
	FOR(a, 1, k) {
		FOR(b, 1, k) {
			FOR(c, 1, k) {
				int tmp = GCD(a, b);
				sum += GCD(tmp, c);
			}
		}
	}
	pv(sum)
	return(0);
}

Measured memory_bytes: 3584
s = list(input())
t = list(input())
m = len(t)
for i in range(len(s)-len(t)+1):
    c = 0
    target = s[i:i+len(t)]
    # print(target)
    for j in range(len(t)):
        # print(target[j],t[j])
        if not target[j] == t[j]:
            c += 1
    # print(m,c)
    if c < m :
        m = c
print(m)

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

typedef long long ll;

const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m)
{
    long long ans = 1;
    while (n)
    {
        if (n & 1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}
long long combi(long long n, long long a)
{
    long long ans = 1, ans1 = 1;
    for (long long i = n - a + 1; i <= n; i++)
    {
        ans *= i % MOD;
        ans %= MOD;
    }

    for (long long i = 2; i <= a; i++)
        ans1 = (ans1 * i) % MOD;
    ans1 = modpow(ans1, MOD - 2, MOD);
    return ((ans % MOD) * ans1) % MOD;
}

void dfs(string s, char mx, ll N)
{
    if(s.length()==N){
        cout << s.c_str() << endl;
    }
    else{
        for (char c = 'a'; c <= mx; c++){
            dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx), N);
        }
    }
}

int main()
{

    ll N;
    cin >> N;
    dfs("", 'a', N);
    return 0;
}


Measured memory_bytes: 1536
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

d = Counter(A)

tmp_2 = []
tmp_4 = []
for k, v in d.items():
    if v >= 4:
        tmp_4.append(k)
    if v >= 2:
        tmp_2.append(k)

ans = 0
tmp_2.sort()
tmp_4.sort()
if len(tmp_4):
    ans = tmp_4[-1]**2
if len(tmp_2) >= 2:
    ans = max(ans, tmp_2[-1]*tmp_2[-2])
print(ans)


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

using namespace std;

int main(){
    long long n;
    long long k;
    cin>>n>>k;
    vector<pair<long long,long long>> hoge(n);
    map<long long,long long> count;
    
    for(int i=0;i<n;i++){
        cin>>hoge.at(i).first>>hoge.at(i).second;
        
        if(!count.count(hoge.at(i).first)){
            count[hoge.at(i).first]=hoge.at(i).second;
        }else{
            count[hoge.at(i).first]+=hoge.at(i).second;
        }
    }
    
    sort(hoge.begin(),hoge.end());
    
    long long nowcnt=-1;
    
    for(auto a:hoge){
        if(nowcnt==a.first){
            continue;
        }else{
            nowcnt=a.first;
            k-=count[a.first];
            if(k<=0){
                cout<<a.first<<endl;
                break;
            }
        }
    }
    
    return 0;
}

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

int main() {
  int A;
  double B;
  cin >> A >> B;
    
  vector<int> num(A);
  for(int i = 0;i < A;i++){
    cin >> num.at(i);
  }
  
  double sum = 0;
  
  for(int i = 0;i < A;i++){
    sum += num.at(i);
  }
  
  double ssum = sum / (4 * B);
  int ccount = 0;
   sort(num.begin(), num.end());
    reverse(num.begin(), num.end()); 
  
  for(int i = 0;i < B;i++){
    if(ssum <= num.at(i)){
      ccount++;
    }
  }
  
  if(ccount == B){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
  
      
}
    



Measured memory_bytes: 256
n,m = map(int,input().split())
l = sorted(list(map(int,input().split())))[::-1]
l1 = []
l2 = sorted(list( list(map(int,input().split())) for _ in range(m)),key=lambda x:x[1])[::-1]
#print(l2)
for j,k in l2:
    for t in range(j):
        if len(l1)<n: 
          l1.append(k)
        else:
          break
l3 = sorted(l+l1)[::-1]
print(sum(l3[0:n]))
  

Measured memory_bytes: 36080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#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 ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<ll> l(n);
    REP(i,n){
        cin >> l[i];
    }
    int ans=0;
    REP(i,n){
        FOR(j,i+1,n){
            FOR(k,j+1,n){
                vector<ll> d(3);
                d[0]=l[i],d[1]=l[j],d[2]=l[k];
                sort(ALL(d));
                if(d[0]==d[1]||d[1]==d[2]) continue;
                if(d[0]+d[1]>d[2]) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;

int main(){
	map<long long int,long long int>ANS;
	map<long long int,long long int>ANS2;
	long long int N,M;
	
	cin>>N>>M;
	long long int A[M];
	long long int B[M];
	long long int H[N];
	for(long long int i = 0; i < N; i++){
		cin>>H[i];
		
	}
	for(long long int i = 0; i < M; i++){
		cin>>A[i]>>B[i];
		A[i]--;
		B[i]--;
		ANS2[A[i]]++;
		ANS2[B[i]]++;
		if(H[A[i]] > H[B[i]]){
			ANS[A[i]]++;
			ANS[B[i]]=-1000000;
		}
		else if(H[B[i]] > H[A[i]]){
			ANS[B[i]]++;
			ANS[A[i]]=-1000000;
		}else{
			ANS[A[i]]=-1000000;
			ANS[B[i]]=-1000000;
		}
	}
	long long int ans = 0;
	for(long long int i = 0; i < N; i++){
		
		if(ANS[i] > 0){
			ans++;
			
		}
			
		if(ANS2[i] == 0){
			ans++;
		
		}
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 18476
import math

(n, k) = tuple(map(int, input().split()))
arr = list(map(int, input().split()))
one = arr.index(1)
if k == n:
    print(1)
else:
    res1 = math.ceil(one / (k - 1))
    one1 = (k - 1) * res1
    res1 += math.ceil((len(arr) - one1 - 1) / (k - 1))

    arr.reverse()
    res2 = math.ceil(one / (k - 1))
    one2 = (k - 1) * res2
    res2 += math.ceil((len(arr) - one2 - 1) / (k - 1))
    print(min(res1, res2))

Measured memory_bytes: 13812
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int a, b, c; cin>>a>>b>>c;
    int ans=0;
    for(int i=1; i<=b; i++){
        if(i%a==0) ans++;

        if(ans==c) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)



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

	int N;
	cin >> N;
	vector<ll>a(N),b(N);
	for (int i = 0; i < N; i++)cin >> a[i] >> b[i];


	sort(all(a));
	sort(all(b));
	reverse(all(b));
	ll ma, mi;
	if (N % 2 == 0) {
		ma = b[N / 2] + b[(N / 2) - 1];
		mi = a[N / 2] + a[(N / 2) - 1];
	}
	else {
		ma = b[N / 2];
		mi = a[N / 2];
	}
	puts(ma - mi + 1);
	
	return 0;
}

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

using namespace std;
typedef long long ll;
#define MOD 1000000007

int main()
{
  ll n, k;
  cin >> n >> k;
  set<ll> x = {};

  ll a;
  string str;
  for (auto i = 0; i < k; i++)
  {
    ll d;
    cin >> d;
    for (auto j = 0; j < d; j++)
    {
      ll a;
      cin >> a;
      x.insert(a);
    }
  }

  ll cnt = 0;
  for (auto i = 1; i <= n; i++)
  {
    if (x.count(i) == 0)
    {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

const string YES = "Yes";


int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);

    vector<vector<long long>> G(N);

    for (int i = 0; i < M; i++) {
        long long a, b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<long long> dist(N, -1);
    queue<long long> que;

    dist[0] = 0;
    que.push(0);

    while (!que.empty()) {
        long long  v = que.front();
        que.pop();

        for (long long nv : G[v]) {
            if (dist[nv] != -1) continue;
            dist[nv] = v;
            que.push(nv);
        }
    }
    int y = 1;
    for (int i = 0; i < N; i++) {
        if (dist[i] == -1) {
            y = 0;
            break;
        }
    }
    if (y == 1) {
        cout << "Yes" << endl;
        for (int v = 1; v < N; ++v) cout << dist[v] + 1 << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  string S;
  cin >> S;
  if('A' <= S[0] && S[0] <= 'Z') {
    cout << "A" << endl;
  }
  else {
    cout << "a" << endl;
  }

  return 0;
}


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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cout << #a << " = " << a << endl

const ll inf = 1e15;
const ll mod = 1e9+7;

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

ll N, C;

ll solve(vector<ll> x, vector<ll> v) {
    vector<ll> S(N, 0);
    S[0] = v[0];
    FOR(i, 1, N) S[i] = S[i-1] + v[i];
    REP(i, N) S[i] -= x[i];

    vector<ll> T(N, 0); 
    T[N-1] = v[N-1];
    RREP(i, N-2) T[i] = T[i+1] + v[i];
    RREP(i, N-1) T[i] -= (C - x[i]);
    RREP(i, N-2) T[i] = max(T[i], T[i+1]);

    ll res = 0;
    REP(i, N) {
        ll val = 0;

        val += S[i];
        res = max(res, val);

        val -= x[i];
        if (i != N-1) val += T[i+1];

        res = max(res, val);
    }
    return res;
}

int main() {
    cin >> N >> C;
    vector<ll> x(N), v(N); REP(i, N) cin >> x[i] >> v[i];

    ll ans = 0;
    ans = max(ans, solve(x, v));

    reverse(ALL(x));
    REP(i, N) x[i] = C - x[i];
    reverse(ALL(v));

    ans = max(ans, solve(x, v));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin >> n;
    int w[n];
    rep(i, n) { cin >> w[i]; }
    int sum = 0;
    rep(i, n) { sum += w[i]; }

    int ans = pow(10, 9);
    repd(i, 1, n) {
        int sum_temp = 0;
        repd(j, 0, i) { sum_temp += w[j]; }
        int dif = sum - sum_temp;
        int ans_temp = abs(dif - sum_temp);
        ans = min(ans, ans_temp);
    }

    cout << ans << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 256
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	set := make(map[int]int, n)
	for i := 0; i < n; i++ {
		set[nextInt(sc)]++
	}
	m := nextInt(sc)
	for i := 0; i < m; i++ {
		set[nextInt(sc)]++
	}
	ans := make([]int, 0, max(n, m))
	for k, v := range set {
		if v > 1 {
			ans = append(ans, k)
		}
	}
	sort.Ints(ans)
	wtr := bufio.NewWriter(os.Stdout)
	for _, v := range ans {
		fmt.Fprintln(wtr, v)
	}
	wtr.Flush()
}



Measured memory_bytes: 21976