akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    ll p = c*(n-1)+b-a, q = d*(n-1)+b-a;
    for (int i = 0; i <= n; ++i) {
        if(p <= (c+d)*i  && (c+d)*i <= q){
            cout << "YES\n";
            return 0;
        }
    }
    cout << "NO\n";
    return 0;
}


Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N = getN()
A = getList()
fore = copy.deepcopy(A)
back = copy.deepcopy(A)

for i in range(N - 1):
    fore[i + 1] += fore[i]
    back[N - i - 2] += back[N - i - 1]

left = 0
total = A[0]

fore_list = []
for right in range(1, N - 2):
    while abs((fore[right] / 2) - (total + A[left + 1])) < abs((fore[right] / 2) - total):
        left += 1
        total += A[left]
    fore_list.append([right, total, fore[right] - total])

right = N - 1
total = A[-1]

back_list = []
for left in range(N - 2, 1, -1):
    while abs((back[left] / 2) - (total + A[right - 1])) < abs((back[left] / 2) - total):
        right -= 1
        total += A[right]
    back_list.append([left, total, back[left] - total])
back_list.sort()

ans = float('inf')
for i in range(len(back_list)):
    ind1, a, b = fore_list[i]
    ind2, c, d = back_list[i]
    opt = max(a, b, c, d) - min(a, b, c, d)
    ans = min(ans, opt)
print(ans)

Measured memory_bytes: 154068
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
A_cnt = [0] * 100001
A_sum = 0

# 各数値の数を数えておく
for a in A:
    A_cnt[a]+=1
    # ついでに現時点の総和も出しておく
    A_sum+=a

for _ in range(Q):
    B, C = map(int, input().split())
    A_cnt[C] = A_cnt[C] + A_cnt[B]
    A_sum = A_sum + ((C-B) * A_cnt[B])
    A_cnt[B] = 0
    print(A_sum)


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

int main() {
	// your code goes here
	long long int n;
	cin>>n;
	
	long long int arr[n];
	long long int i,j,k;
	long long int total=0, total2=0;
	for(i=0;i<n;i++){
	    cin>>arr[i];
	    total = total + arr[i];
	}
	    
	long long int m;
	cin>>m;
	
	while(m--){
	    long long int p,x;
	    total2 = total;
	    cin>>p>>x;
	    total2 = total2 - arr[p-1];
	    total2 = total2 + x;
	    cout<<total2<<"\n";
	}
	
	return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

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

    int W, H, N;
    std::cin >> W >> H >> N;

    int x0 = 0, x1 = W, y0 = 0, y1 = H;

    for(int i=0;i<N;++i){
        int x, y, a;
        std::cin >> x >> y >> a;

        if(a == 1){
            x0 = max(x0, x);
        }else if(a == 2){
            x1 = min(x1, x);
        }else if(a == 3){
            y0 = max(y0, y);
        }else{
            y1 = min(y1, y);            
        }
    }

    std::cout << max(x1-x0, 0) * max(y1-y0, 0) << std::endl;
}


Measured memory_bytes: 256
import math

s = "{0}:"
s2 = " {0}"
def prime_factorize(n):
	m = math.sqrt(n)+1
	i = 2
	prime = []
	while n != 1 and i < m:
		if n % i == 0:
			prime.append(i)
			n //= i
		else:
			i += 1
	if n != 1:
		prime.append(n)
	return prime
n = int(input())
lst = prime_factorize(n)
print(s.format(n),end="")
for i in range(len(lst)):
	print(s2.format(lst[i]),end="")
print()



Measured memory_bytes: 5664
#include<stdio.h>
#define MAX 100000
typedef long long llong;

int n,k;
llong T[MAX];

int check(llong P)
{
	int i=0;
	for(int j=0;j<k;j++)
	{
		llong s=0;
		while(s+T[i]<=P)
		{
			s+=T[i];
			i++;
			if(i==n)
			{
				return n;
			}
		}
	}
	return i;
}

int solve()
{
	llong left=0;
	llong right=100000*10000;
	llong mid;
	
	while(right-left>1)
	{
		mid=(left+right)/2;
		int v=check(mid);
		if(v>=n)
		{
			right=mid;
		}
		else
		{
			left=mid;
		}
	}
	return right;
}
int main()
{
	scanf("%d %d",&n,&k);
	
	for(int i=0;i<n;i++)
	{
		scanf("%d",&T[i]);
	}
	llong ans=solve();
	
	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 2640
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int main() {
  int n;
  scanf("%d", &n);
  vi a(n);
  rep (i, n) {
    scanf("%d", &a[i]);
  }
  sort(all(a));
  reverse(all(a));
  vi point(2, 0);
  rep (i, n) {
    point[i % 2] += a[i];
  }
  printf("%d\n", point[0] - point[1]);


  return 0;
}


Measured memory_bytes: 888
import java.util.Arrays;

public class Main {
  private static void solve() {
    char[] s = ns();
    int[] count = new int[3];
    for (char c : s) {
      count[c - 'a'] ++;
    }
    
    Arrays.sort(count);
    if (count[2] - count[0] <= 1) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}




Measured memory_bytes: 24532
n=input()
ln=len(n)
if ln==6:
    print(90909)
elif ln==5:
    print(909+int(n)-9999)
elif ln==4:
    print(909)
elif ln==3:
    print(9+int(n)-99)
elif ln==2:
    print(9)
else:
    print(int(n))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt();
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int l = sc.nextInt(), r = sc.nextInt();
			ans += r - l + 1;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 25700
import collections
n=int(input())

A=[]
for i in range(n):
    s=sorted(input())
    t=''.join(s)
    A.append(t)

r=collections.Counter(A)
r=r.most_common()

cnt=0
for j in range(len(r)):
    if r[j][1]==1:
        cnt+=0
    else:
        cnt+=((r[j][1]-1)*r[j][1])//2
print(cnt)

Measured memory_bytes: 24492
def find(D):
    if D[0]!=0:
        return 0
    
    count=[0 for _ in range(len(D))]
    MAX=max(D)
    
    ans=1
    for x in D:
        count[x]+=1
    
    if count[0]!=1:
        return 0
    
    for i in range(1,MAX+1):
        ans=ans*pow(count[i-1],count[i],998244353)
        ans%=998244353
    return ans
N=int(input())
D=list(map(int,input().strip().split()))
print(find(D))

Measured memory_bytes: 14396
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int A, B, C;
    int count = 0;
    cin >> A >> B >> C;

    int check, num1, num2, num3;
    //num3
    int max = A;
    check = 0;
    if(B > max){
        max = B;
        check = 1;
    }  
    if(C > max){
        max = C;
        check = 2;
    }

    if(check == 0){
        num3 = A;
        A = -1;
    }else if(check == 1){
        num3 = B;
        B = -1;        
    }else{
        num3 = C;
        C = -1;     
    }

    //num2
    max = A;
    check = 0;
    if(B > max){
        max = B;
        check = 1;
    }    
    if(C > max){
        max = C;
        check = 2;
    }

    if(check == 0){
        num2 = A;
        A = -1;
    }else if(check == 1){
        num2 = B;
        B = -1;        
    }else{
        num2 = C;
        C = -1;     
    }
    
    //num1
    if(A >= 0){
        num1 = A;
    }else if(B >= 0){
        num1 = B;
    }else{
        num1 = C;
    }

    //cout << num1 << ' ' << num2 << ' ' << num3 <<endl;

    while(num2 - num1 >1){
        num1 = num1 + 2;
        count++;
    }

    while(num3 != num2){
        num1++;
        num2++;
      	count++;
    }

    if(num1 == num2)
        cout << count <<endl;
    else
        cout << count + 2 <<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    int a=9,b,ans=0;
    vector<int> v(5);
    bool flag=false;
    for(int i=0;i < 5;i++){
        cin >> v.at(i);
    
    if(a >= v.at(i)%10 && v.at(i)%10>0){
        a=v.at(i)%10;
        b=i;
        flag =true;
    }
    }

    for(int j=0;j < 5;j++){
        if(j!=b){
            ans+=(v.at(j)+9)/10*10;
        }
    }
    if(flag){ans += v.at(b);}
    cout << ans << endl;
    
}

Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let mut d: Vec<i32> = (0..n).map(|_| input()).collect();
    d.sort();
    let (l, r) = (d[n / 2 - 1], d[n / 2]);
    println!("{}", r - l);
}


Measured memory_bytes: 4352
S = input()
T = input()
L = len(T)
res = 10000
for i in range(len(S)-L+1):
    tmp = 0
    for a, b in zip(list(S[i:i+L]), list(T)):
        tmp += 1 if a != b else 0
    res = min(tmp, res)
print(res)


Measured memory_bytes: 9116
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <map>

using namespace std;

char s[10];

int main()
{
	map<pair<int,string>,int> m;
	int n;
	scanf("%d",&n);
	for(int i = 0; i < n; i++)
	{
		int w;
		scanf("%s %d",s,&w);
		int l = strlen(s);
		if(m.end() != m.find(make_pair(l,s)))
		{
			m[make_pair(l,s)] += w;
		}
		else
		{
			m[make_pair(l,s)] = w;
		}
	}
	map<pair<int,string>,int>::iterator it = m.begin();
	while(it != m.end())
	{
		printf("%s %d\n",(*it).first.second.c_str(),(*it).second);
		it++;
	}
	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector <double> p(n + 1);
  REP1(i, n) {
	cin >> p[i];
  }
  vector <vector <double> > dp(n + 1, vector <double>(n + 1, 0.0));
  dp[0][0] = 1.0;
  REP1(i, n) {
	REP(j, n + 1) {
	  dp[i][j] = dp[i - 1][j] * (1 - p[i]);
	  if (j > 0) {
		  dp[i][j] += dp[i - 1][j - 1] * p[i];
		}
	}
  }
  double ans = 0.0;
  for (int i = n / 2 + 1; i <= n; i++) {
	  ans += dp[n][i];
	}
  printf("%.16f\n", ans);
  return 0;
}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
   long long int t,n,x,c=0;
   n=100;
   cin>>x;
   while(n<x)
   {
     n=n+(n/100);
     c++;
   }
   cout<<c<<endl;
   return 0;
}


Measured memory_bytes: 3644
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		
		// 計算
		long result = 0;
		for(int i = 1; i < n; i++){
		    result += (n-1)/i;
		}
		
		// 出力
		System.out.println(result);
		
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}

}


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

using namespace std;

string N;
int main(){
    cin >> N;
    cin.ignore();

    int sum = 0;
    for(int i = 0; i < N.size(); i++){
        sum += (N[i] - '0');
        sum %= 9;
    }

    if(sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 3748
/***************************************************************
	File name: A.cpp
	Author: ljfcnyali
	Create time: 2019年07月20日 星期六 19时47分02秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i ) 
#define mem(a) memset ( (a), 0, sizeof ( a ) ) 
#define str(a) strlen ( a ) 

int main()
{
    int x; scanf("%d", &x);
    printf("%d\n", 3 * x * x);
    return 0;
}

Measured memory_bytes: 256
import sys

read = lambda: sys.stdin.readline().rstrip()

class Solution(object):
    def flipping_signs(self,N, A):

        oddeven = 1
        cnt = 0
        B = [0]*N
        for i in range(N):
            B[i] = abs(A[i])
            if A[i] == 0:
                oddeven = 0
            elif A[i] < 0:
                cnt += 1
        if cnt%2 == 0: oddeven = 0

        return sum(B)-2*min(B) if oddeven != 0 else sum(B) 

def main():

    N0 = int(read())
    A0 = tuple(map(int, read().split()))



    res = Solution().flipping_signs(N0, A0)

    print(res)
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 14608
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>

typedef long long ll;


using namespace std;

int main() {
    ll a, b;
    cin >> a >> b;

    int price = -1;
    for (int i = 0; i < 10000; i++) {
        if ((int)(i * 0.08) == a && (int)(i * 0.1) == b) {
            price = i;
            break;
        }
    }

    cout << price;

    return 0;
}

Measured memory_bytes: 256
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int main(void){
  uint32_t n;
  scanf("%"PRIu32, &n);
  uint32_t *d;
  do{ d=calloc(n, sizeof(uint32_t)); }while(!d);
  for(uint32_t i=1; i<n; i++){
    uint32_t a;
    scanf("%"PRIu32, &a);
    d[a-1]++;
  }
  for(uint32_t i=0; i<n; i++){
    printf("%"PRIu32"\n", d[i]);
  }
  free(d); d=NULL;
}



Measured memory_bytes: 2208
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

long long int ans(long long int a, long long int b){
	if(a>b){
		long long int c;
		c=a;
		a=b;
		b=c;
	}
	if(b%a==0){
		return (2*b/a-1)*a;
	}else{
		long long int q=b/a, r=b%a;
		return 2*q*a+ans(r, a);
	}
}

int main()
{
	long long int n, x;
	scanf("%lld %lld", &n, &x);
	printf("%lld\n", n+ans(x, n-x));
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final long n = scanner.nextInt();
        final long m = scanner.nextInt();

        if (n == 1) {
            if (m == 1) {
                System.out.println(1);
                return;
            }

            System.out.println(m - 2);
            return;
        }

        if (m == 1) {
            System.out.println(n - 2);
            return;
        }

        System.out.println(n * m - (n * 2 + m * 2 - 4));
    }
}


Measured memory_bytes: 23252
import java.text.MessageFormat;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int number = sc.nextInt();
		double p1x = 0;
		double p1y = 0;
		double p2x = 100;
		double p2y = 0;
		System.out.println(MessageFormat.format("{0,number,0.00000000}",p1x)+" "+MessageFormat.format("{0,number,0.00000000}",p1y));
		koch(number, p1x, p1y, p2x, p2y);
		System.out.println(MessageFormat.format("{0,number,0.00000000}",p2x)+" "+MessageFormat.format("{0,number,0.00000000}",p2y));
		sc.close();

		
	}
	
	public static void koch(int n, double p1x, double p1y, double p2x, double p2y){
		if(n == 0) return;
		double Sx = (2 * p1x + 1 * p2x) / 3;
		double Sy = (2 * p1y + 1 * p2y) / 3;
		double Tx = (1 * p1x + 2 * p2x) / 3;
		double Ty = (1 * p1y + 2 * p2y) / 3;
		double Ux = (Tx - Sx) *(double) Math.cos(Math.toRadians(60)) - (Ty - Sy) * (double)Math.sin(Math.toRadians(60)) + Sx;
		double Uy = (Tx - Sx) * (double)Math.sin(Math.toRadians(60)) +(Ty - Sy) * (double)Math.cos(Math.toRadians(60)) + Sy;
		
		koch(n-1 , p1x, p1y, Sx ,Sy);
		System.out.println(MessageFormat.format("{0,number,0.00000000}",Sx)+" "+MessageFormat.format("{0,number,0.00000000}",Sy));
		koch(n - 1, Sx, Sy, Ux, Uy);
		System.out.println(MessageFormat.format("{0,number,0.00000000}",Ux)+" "+MessageFormat.format("{0,number,0.00000000}",Uy));
		koch(n - 1, Ux, Uy, Tx, Ty);
		System.out.println(MessageFormat.format("{0,number,0.00000000}",Tx)+" "+MessageFormat.format("{0,number,0.00000000}",Ty));
		koch(n - 1, Tx, Ty, p2x, p2y);
	}

}



Measured memory_bytes: 62020
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

i = 0
minGap = 100000
while i < N:
    AT = T - H[i] * 0.006
    gap = abs(A - AT)
    if minGap > gap:
        minGap = gap
        ans = i + 1
    i += 1

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 

using namespace std;
using namespace __gnu_pbds; 
#define     mod            (int)1e9+7
#define     MOD             998244353
#define     ll              long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     t()             int test;cin>>test;while(test--)
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif






 
int main()
 
{  
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    IOS;
    
   int h, w, k;
   cin >> h >> w >> k;

   string s[h];
   for(int i=0; i<h; i++)
    cin>>s[i];

  int ans = 0;

  for(int i=0; i<(1<<h)-1; i++)
  {
    for(int j=0; j<(1<<w)-1; j++)
    {
       int black =0;

       for(int x= 0; x<h; x++)
       {
         for(int y=0; y<w; y++)
         {
            if(((i>>x) & 1)==0 && ((j>>y)&1)==0)
            {
               if(s[x][y] == '#')black++;
            }
         }
       }
       if(black == k)ans++;
    }
  }

  cout<<ans<<endl;
   
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define debug(x) //cout << #x << "\t" << x << endl
using namespace std;
using ll = long long;
const int maxn = 1e5+7;
const int mod = 1e9+7;
int n;
int a[maxn]={0};
ll fac[maxn];
ll inv[maxn];
void init(){
	fac[0]=fac[1]=1;
	inv[0]=inv[1]=1;
	for(int i=2; i<maxn; ++i){
		fac[i] = fac[i-1]*i%mod;
		inv[i] = (mod-mod/i)*inv[mod%i]%mod;
	}
	for(int i=1; i<maxn; ++i){
		inv[i] =inv[i]*inv[i-1]%mod;
	}
}
ll C(ll n, ll m){
	if(m>n)return 0;
	return (fac[n]*inv[m]%mod)*inv[n-m]%mod;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	int p1=0, p2=0;
	for(int i=1, x; i<=n+1; ++i){
		cin >> x;
		if(!a[x])a[x]=i;
		else {
			p1 = i;
			p2 = a[x];
		}
	}
	debug(p1);
	debug(p2);
	init();
	for(int i=1; i<=n+1; ++i){
		ll ret=0;
		ret += C(n+1, i);
		ret %= mod;
		ret -= C(n-p1+p2, i-1);
		while(ret<0)ret+=mod;
		cout << ret<<"\n";
	}
	
}

Measured memory_bytes: 3200
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

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

const int N=100000+10;

int n,x[N]; ll a,b;

int main() {
	n=read(),a=read(),b=read();
	for (int i=1;i<=n;++i) x[i]=read();
	ll ans=0;
	for (int i=2;i<=n;++i) ans+=min(a*(x[i]-x[i-1]),b);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4080
#include <iostream>
#include <algorithm>

using namespace std;
int arr[200000];

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr[i];
        
    int maxdf=-2000000000;
    int mindf=arr[0];
    
    for(int i=1;i<n;i++){
        maxdf=max(maxdf,arr[i]-mindf);
        mindf=min(mindf,arr[i]);
    }
    
    cout<<maxdf<<endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> B(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> B.at(i);
  }
  
  vector<int> A(N);
  
  A.at(0) = B.at(0);
  
  for (int i = 1; i < N - 1; i++) {
    A.at(i) = min(B.at(i),B.at(i-1));
  }
  
  A.at(N - 1) = B.at(N - 2);
  
  long long sum = 0;
  for (int i = 0; i < N ; i++) {
    sum += A.at(i);
  }
  
  cout << sum << endl;
}
    

Measured memory_bytes: 256
S = int(input())

if S <= 10 ** 9:
    a = S
    b = c = 0
    d = 1
else:
    q = S % (10 ** 9)
    if q == 0:
        a = S // (10 ** 9)
        b = c = 0
        d = 10 ** 9
    else:
        b = 1
        c = 10 ** 9 - q
        d = 10 ** 9
        a = (S+c) // 10 ** 9


print("{} {} {} {} {} {}".format(0, 0, a, b, c, d))


Measured memory_bytes: 38420
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef pair< int,int > point;
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    vector< point > data(n+1,point(0,0));
    int in,kind=0;
    for(int i=0;i<n;++i){
        scanf("%d",&in);
        kind+=data[in].F==0;
        data[in].F++;
        data[in].S=in;
    }
    sort(data.begin(),data.end(),greater< point >());
    int cnt=0;
    for(int i=kind;i>k;--i){
        cnt+=data[i-1].F;
        
    }
    printf("%d\n",cnt);
    return 0;
}



Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define OUT(x)                cout << #x << " = " << x << endl
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int x; scanf("%d", &x); return x; }
long long lin() { long long x; scanf("%lld", &x); return x; }

#define int long long

signed main() { 
        int x;
        cin >> x;
        int y = x % 11;
        int ans = x / 11;
        ans *= 2;
        if (0 < y && y <= 6) ans ++;
        else if (y > 6) ans += 2;
        cout << ans << endl;
        return 0;
}               



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main (){

  int test;
  cin>>test;
  int d1[test],d2[test];

  for (int i =0; i< test;i++){
    cin>>d1[i];
    cin>>d2[i];
  }


  // for (int i =0; i< test;i++){
  // cout<<d1[i]<<"/t";
  //   cout<<d2[i]<<"/n";
  // }
  int flag = 0;
  for (int i = 0; i < test; i++){
    if(d1[i] == d2[i])
      if(d1[i+1] == d2[i+1])
        if(d1[i+2] == d2[i+2])
          flag  = 1;
  }

  if (flag == 1)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}


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

int main(){
  int n, m, ans = 0; cin >> n >> m;
  vector<vector<int>> v(n);
  rep(i, m){
    int x, y, z; cin >> x >> y >> z;
    x--; y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  queue<int> q;
  vector<bool> visited(n, false);
  rep(i, n){
    if(visited[i] == true) continue;
    ans++;
    q.push(i);
    visited[i] = true;
    while(q.size() > 0){
      int now = q.front(); q.pop();
      rep(j, v[now].size()){
        int next = v[now][j];
        if(visited[next] == true) continue;
        visited[next] = true;
        q.push(next);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
    string N;
    cin >> N;
    ll sum = 0;
    for(auto c : N){
        sum += (int)(c - '0');
    }
    if(sum % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    int count = 0;
    int v[n] = {};
    for(int i = 0;i < s.size() - 1;i++)
    {
        if(s[i] == 'A' && s[i + 1] == 'C')
        {
            count++;
        }
        v[i + 1] = count;
    }
    int v2[q];
    for(int i = 0;i < q;i++)
    {
        int x,y;
        cin >> x >> y;
        v2[i] = v[y - 1] - v[x - 1];
    }
    for(int i = 0;i < q;i++)
    {
        cout << v2[i] << "\n";
    }

    return 0;
}

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

using namespace std;
typedef long long ll;
#define mp make_pair

const int N = 1e5 + 10;
ll pos[N];
ll new_pos[N];
ll w[N];

int main() {
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);	
	ll n, l, t;
	cin >> n >> l >> t;
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> pos[i] >> w[i]; 
		if (w[i] == 2)
			w[i] = -1;
		new_pos[i] = (pos[i] + t * w[i]) % l;
		if (new_pos[i] < 0)
			new_pos[i] += l;
		sum = (sum + t * w[i]) % (n * l);
		if (sum < 0)
			sum += n * l;
	}
	sort(new_pos, new_pos + n);
	ll last = 0;
	ll new_sum = 0;
	for (int i = 0; i < n; i++) {
		ll tmp = (new_pos[i] - pos[i]) + (last / l) * l + 2 * l;
		if (i == 0) {
			tmp = tmp % l;
		}
		while (i > 0 && (pos[i - 1] + last <= pos[i] + tmp - l))
			tmp -= l;
		new_sum += tmp;
		last = tmp;
	}
	ll shift = ((new_sum - sum) / l) % n;
	if (shift < 0)
		shift += n;
	for (int i = 0; i < n; i++) {
		cout << new_pos[(i - shift + n) % n] << "\n";
	}
	return 0;
}


Measured memory_bytes: 3584
import java.util.Scanner;

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

        String S, T;
        S = sc.nextLine();
        T = sc.nextLine();

        int cnt = 0;

        char[] cS = S.toCharArray();
        char[] cT = T.toCharArray();

        for(int i = 0; i<3;i++){
            if(cS[i] == cT[i]){
                    cnt ++;
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 21844
lo = int(input())
ngl = ["AGC", "ACG", "GAC", "AAGC", "AGGC", "ATGC", "ACGC", "AGAC", "AGGC", "AGTC", "AGCC"]
memo = {}


def ac(s, dep):
    if s == "":
        rv = 0
        for sv in "AGCT":
            rv += ac(s + sv, dep+1)
        return rv % (10 ** 9 + 7)
    else:
        if len(s) == lo:
            if chs(s):
                return 1
            else:
                return 0
        else:
            if len(s) >= 4:
                if chs(s):
                    if (s[-3:] + ":" + str(dep)) in memo:
                        return memo.get(s[-3:] + ":" + str(dep))
                    else:
                        rv = 0
                        for sv in "AGCT":
                            rv += ac(s + sv, dep+1)
                        memo[s[-3:] + ":" + str(dep)] = rv
                        return rv % (10 ** 9 + 7)
                else:
                    return 0
            else:
                rv = 0
                for sv in "AGCT":
                    rv += ac(s + sv, dep+1)
                return rv % (10 ** 9 + 7)


def chs(s):
    for ng in ngl:
        if ng in s:
            return False
    return True


print(ac("", 0))


Measured memory_bytes: 4212
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int[] v1 = new int[n];
        int[] v2 = new int[n];

        for(int i=0; i<n; i++) {
            v1[i] = sc.nextInt();
        }

        for(int i=0; i<n; i++) {
            v2[i] = sc.nextInt();
        }

        sc.close();

        double p1 = 0.0;
        double p2 = 0.0;
        double p3 = 0.0;
        double inf = 0.0;

        for(int i=0; i<n; i++) {
            p1 += Math.abs(v1[i]-v2[i]);
            p2 += Math.pow(Math.abs(v1[i]-v2[i]),2);
            p3 += Math.pow(Math.abs(v1[i]-v2[i]),3);
            inf = Math.max(inf, Math.abs(v1[i]-v2[i]));
        }

        System.out.println(String.format("%.6f",p1));
        System.out.println(String.format("%.6f",Math.sqrt(p2)));
        System.out.println(String.format("%.6f",Math.cbrt(p3)));
        System.out.println(String.format("%.6f",inf));

    }
}



Measured memory_bytes: 26656
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define M 205
LL a,b,c,d,e;
LL Solve(LL x) {
	return x/c+x/d-x/e;
}
int main() {
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d),a--,e=c*d/__gcd(c,d);
	printf("%lld",b-a-Solve(b)+Solve(a));
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
 
S = list(readline().rstrip())
K = int(readline())
N = len(S)
for i,s in enumerate(S):
    t = ord(s)-97
    if t == 0:
        continue
    if 26 - t <= K:
        S[i] = 'a'
        K -= 26-t
S[-1] = chr((ord(S[i]) + K%26)%97+97)
print(''.join(S))
 
 

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

using namespace std;
 
int main() {
  string s;
  int ans = 0;
  cin >> s;
  if (s[0] == '1') ans++;
  if (s[1] == '1') ans++;
  if (s[2] == '1') ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b,c,d;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b){
		d = b;
		b = a;
		a = d;
	}
	if(b>c){
		d = c;
		c = b;
		b = d;
	}
	if(a>b){
		d = b;
		b = a;
		a = d;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

int main(){
    char a;
    cin >> a;
    /*if(a - 'A' >= 0){
        cout << 'A' << endl;
    }
    else{
        cout << 'a' << endl;
    }*/
    if(isupper(a)){
        cout << 'A' << endl;
    }
    else{
        cout << 'a' << endl;
    }

}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <iomanip>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


int main(){
    int n,m,x,a ;
    cin >> n >> m >> x ;
    int r = 0 ;
    int l = 0 ;
    for (size_t i = 0; i < m; i++)
    {
        cin >> a ;
        if (a < x)
        {
            l ++ ;
        }else
        {
            r ++ ;
        }
        
        
    }
    cout << min(l,r) << endl ;
    
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {

	static Scanner inp= new Scanner(System.in);
	static PrintWriter out= new PrintWriter(System.out);
	public static void main(String args[]) {		    	
	   	Main g=new Main();
	   	g.main();
	   	out.close();
	}

	
	
	//Main
	void main() {
		
		int n=inp.nextInt();
		int x=inp.nextInt();
		int t=inp.nextInt();
		System.out.println((((n+x-1))/x)*t);
		
	}
    
    
		
}


Measured memory_bytes: 35908
#include<cstdio>
#include<utility>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define INF 1<<20
typedef pair<int,int>p;
int N,M,K,a,b,l,d[3005],rd[3005];
vector<p>G[3005];//to,cost

void dij(int s)
{
	priority_queue<p,vector<p>,greater<p> >Q;
	fill(d,d+N,INF);
	d[s]=0;Q.push(p(0,s));
	for(;!Q.empty();)
	{
		p tmp=Q.top();Q.pop();
		int v=tmp.second;
		if(d[v]<tmp.first)continue;
		for(int i=0;i<G[v].size();i++)
		{
			p e=G[v][i];
			if(d[e.first]>d[v]+e.second)
			{
				d[e.first]=d[v]+e.second;
				Q.push(p(d[e.first],e.first));
			}
		}
	}
}

int main()
{
	scanf("%d%d%d",&N,&M,&K);
	for(int i=0;i<M;i++)
	{
		scanf("%d%d%d",&a,&b,&l);
		a--;b--;
		G[a].push_back(p(b,l));
		G[b].push_back(p(a,l));
	}
	fill(rd,rd+N,INF);
	for(int i=0;i<K;i++)
	{
		scanf("%d",&a);
		a--;
		dij(a);
		for(int j=0;j<N;j++)rd[j]=min(rd[j],d[j]);
	}
	int res=0;
	for(int i=0;i<N;i++)
		for(int j=0;j<G[i].size();j++)
		{
			int tmp=(double)(abs(rd[i]-rd[G[i][j].first])+G[i][j].second)/2+0.5;
			int tmp1=rd[G[i][j].first];
			int tmp2=G[i][j].second-tmp;
			res=max(res,rd[i]+(rd[i]<=tmp1?max(tmp,tmp2):min(tmp,tmp2)));
		}
	printf("%d\n",res);
	return 0;
}

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

int N;
vector<int> first_sum;
vector<int> second_sum;


int main() {
  cin >> N;
  
  int num;
  for(int i = 0; i < N; i++) {
    cin >> num;
    first_sum.push_back(num);
    if (i > 0) {
      first_sum[i] += first_sum[i-1];
    }
  }

  for(int i = 0; i < N; i++) {
    cin >> num;
    second_sum.push_back(num);
  }
  
  for(int i = N-1; i >= 0; i--) {
    if (i < N-1) {
      second_sum[i] += second_sum[i+1];
    }
  }

  int max_sum = -1;
  int this_sum;
  for(int i = 0; i < N; i++) {
    this_sum = first_sum[i] + second_sum[i];
    if (this_sum > max_sum) {
      max_sum = this_sum;
    }
  }

  cout << max_sum << endl;

  return 0;
} 


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




int main() {
 string s;
  cin>>s;
  int a , z ,N;
  N=s.size();
  
  for (int i=0;i<200000;i++){
    if (s.at(i)=='A'){
      a = i;
      break;
    }
  }
  for (int i=N-1;i<200000;i--){
    if (s.at(i)=='Z'){
      z = i;
      break;
    }
  }
  
  cout << z - a + 1 << endl;
  
 
}

Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};

const ll INF = 1e18;
vector<int> pow2(16, 1);

int main () {
    for (int i = 0; i <= 14; i++) {
        pow2[i+1] = pow2[i] * 2;
    }

    int n; cin >> n;
    vector<ll> x(n), y(n), p(n);
    rep(i, n) cin >> x[i] >> y[i] >> p[i];

    vector<vector<ll>> dist_x(n, vector<ll> (n)), dist_y(n, vector<ll> (n));
    rep(i, n) rep(j, n) {
        dist_x[i][j] = dist_x[j][i] = abs(x[i] - x[j]);
        dist_y[i][j] = dist_y[j][i] = abs(y[i] - y[j]);
    }

    vector<vector<ll>> ver(1<<n, vector<ll> (n)), hor(1<<n, vector<ll> (n));
    rep(i, 1<<n) {
        vector<int> c;//路線通す都市
        rep(j, n) {
            if ((i >> j) & 1) c.push_back(j);
        }
        rep(j, n) {
            {
                ll cost = min(abs(x[j]) * p[j], abs(y[j]) * p[j]);
                for (int q : c) {
                    cost = min(cost, abs((x[j] - x[q]) * p[j]));
                }
                ver[i][j] = cost;
            }
            {
                ll cost = min(abs(x[j]) * p[j], abs(y[j]) * p[j]);
                for (int q : c) {
                    cost = min(cost, abs((y[j] - y[q]) * p[j]));
                }
                hor[i][j] = cost;
            }
            
        }
    }

    vector<ll> ans(n+1, INF);
    vector<ll> zero(n);
    rep(i, n) zero[i] = min(abs(x[i]), abs(y[i]));
    for (int i = 0; i < (1 << n); i++) {
        int k = _popcnt32(i);
        vector<int> city;
        rep(j, n) {
            if ((i >> j) & 1) city.push_back(j);
        }
        for (int j = 0; j < (1 << k); j++) {
            int _ver = 0, _hor = 0;
            rep(l, k) {
                if ((j >> l) & 1) _ver += pow2[city[l]];
                else _hor += pow2[city[l]];
            }
            ll cost = 0;
            rep(l, n) {
                cost += min(ver[_ver][l], hor[_hor][l]);

            }
            ans[k] = min(ans[k], cost);
            /*
            vector<ll> cnt = zero;
            rep(l, n) {
                rep(m, k) {
                    if ((j >> m) & 1) cnt[l] = min(cnt[l], dist_x[l][city[m]]);
                    else cnt[l] = min(cnt[l], dist_y[l][city[m]]);
                }
                cnt[l] *= p[l];
            }
            ll s = 0;
            rep(l, n) s += cnt[l];
            ans[k] = min(ans[k], s);
            */
        }
    }
    for (int k = 0; k <= n; k++) cout << ans[k] << endl;
    return 0;
}

Measured memory_bytes: 13016
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n, k = na()
a = na()

neg = []
pos = []
for i in range(n):
    if a[i] < 0:
        neg.append(a[i])
    elif a[i] > 0:
        pos.append(a[i])
neg.sort()
pos.sort(reverse=True)

mx = -1
arg = -1
lall = 0

nn, np = 0, k
while np > len(pos):
    np -= 2
    nn += 2

if np >= 0 and nn <= len(neg):
    arg = nn
    while np-2 >= 0 and nn+1 < len(neg):
        if pos[np-1] * pos[np-2] < neg[nn] * neg[nn+1]:
            nn += 2
            np -= 2
            arg = nn
        else:
            break

ans = 1
mod = 1000000007
if arg == -1:
    a.sort(reverse=True)
    for i in range(k):
        ans = ans * a[i] % mod
    print(ans)
else:
    for i in range(arg):
        ans = ans * neg[i] % mod
    for i in range(k-arg):
        ans = ans * pos[i] % mod
    print(ans)


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}

template <typename T>
vector<T> accum(vector<T>& v){
    vector<T> res(v.size()+1);
    res[0] = 0;
    partial_sum(ALL(v), res.begin()+1);
#ifdef DEBUG
    cerr << v << " -> accum -> " << res << endl;
#endif
    return res;
}



ll move(int n, vi& a, int target) {
    int ac = 0;
    ll mv = 0;
    rep(i, n){
        ac += a[i];
        // targetとsignが同じなら何もしない
        // そうでなければtargetに持っていく
        if (target * ac <= 0) {
            mv += llabs(target - ac);
            ac = target;
        }
        target = -target;
    }
    return mv;
}

ll solve(int n, vi& a) {
    // vi ac = accum(a);
    return min(move(n,a,1), move(n,a,-1));
}

int main() {
    vi a;
    int N = loadvec(a);
    cout << solve(N,a) << endl;
    return 0;
}


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

// using mint = modint1000000007;
// using mint = modint998244353;

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

void solve() {
    bool x;
    cin >> x;
    print(not x);
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
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; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  int n,i;
  cin >> n >> i;
  cout << n-i+1 << "\n";
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;} return false;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;

int main(){
	ll t1, t2, a1, a2;
	cin >> t1 >> t2 >> a1 >> a2;
	cout << ((a1 + t2 - 1) / t2 <= (a2 + t1 - 1) / a2 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3672