akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
sys.setrecursionlimit(10**6)
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)

from collections import Counter

n = int(input())
v = list(map(int, input().split()))

c = Counter(v)
if len(c) == 1:
    print(n//2)
    exit()
# fc = c.most_common(2)
# count1 = fc[0][1]
# count2 = fc[1][1]
# ok = 0
# debug(fc)

# if count1 <= n//2:
#     ok += count1
# else:
#     ok += n//2
# ok += count2


# print(n-ok)

odd = [v[2*i+1] for i in range(n//2)]
even = [v[2*i] for i in range(n//2)]
# odd_count = Counter(odd).most_common(1)[0][1]
# even_count = Counter(even).most_common(1)[0][1]

oc = Counter(odd).most_common()
ec = Counter(even).most_common()

if oc[0][0] != ec[0][0]:
    odd_count = oc[0][1]
    even_count = ec[0][1]
    both_count = odd_count + even_count
else:
    # if oc[0][1] > ec[0][1]:
    #     odd_count = oc[0][1]
    #     even_count = ec[1][1]
    # else:
    #     odd_count = oc[1][1]
    #     even_count = ec[0][1]
    both1 = oc[0][1] + ec[1][1]
    both2 = oc[1][1] + ec[0][1]
    both_count = max(both1, both2)

print(n-both_count)


Measured memory_bytes: 73576
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  ll n,k;
  cin>> n >> k;
  ll a[n],ans[n];
  for(ll i=0;i<n;i++) cin>>a[i];
  
  for(int i=1;i<=n && i<=k;i++)
  {
    ans[n-i] = abs(a[n-i] - a[n-1]);
  }

  for(ll i=n-k-1;i>=0;i--)
  {
    int j = 1;
    ans[i] = INT_MAX;
    while(j<=k)
    {
      ans[i] = min(ans[i], ans[i+j] +abs(a[i+j] - a[i]));
      j++;
    }
  }

  /*for(int i=0;i<n;i++) cout<<ans[i]<<" ";
    cout<<endl;*/
  cout<<ans [0]<<endl;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<ll>a(3*N);
  for(int i=0;i<3*N;i++)cin>>a[i];
  sort(rng(a));
  ll ans=0;
  for(int i=0;i<2*N;i++)if(i%2==1)ans+=a[3*N-i-1];
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 2560
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author hakamada
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC104_2 solver = new ABC104_2();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC104_2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String SS = in.next();
            int cexisit = 0;
            for (int i = 0; i < SS.length(); i++) {
                if (i == 0) {
                    if (SS.charAt(i) != 'A') {
                        out.println("WA");
                        return;
                    }
                } else if (i >= 2 && i < (SS.length() - 1)) {
                    if (SS.charAt(i) == 'C') {
                        if (cexisit != 0) {
                            out.println("WA");
                            return;
                        } else {
                            cexisit = i;
                        }
                    } else if (Character.isUpperCase(SS.charAt(i)) == true) {
                        out.println("WA");
                        return;
                    }
                } else if (Character.isUpperCase(SS.charAt(i)) == true) {
                    out.println("WA");
                    return;
                }
            }
            if (cexisit == 0) {
                out.println("WA");
            } else {
                out.println("AC");
            }
        }

    }
}



Measured memory_bytes: 23124
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,m,p,x;
	while(true){
		cin>>n>>m>>p;
		if(n==0&&m==0&&p==0)
			break;
		int w=0,a=0;
		for(int i=0;i<n;i++){
			cin>>x;
			w+=x;
			if(i==m-1)
				a+=x;
		}
		if(a==0)
			cout<<"0"<<endl;
		else
			cout<<w*(100-p)/a<<endl;
	}
	return 0;
}

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

int main(){
	int n, k, r, s, p;
	char prev;
	long long ans = 0;
	string t;
	cin >> n >> k >> r >> s >> p >> t;

	for(int i=0; i<k; i++){
		prev = ' ';
		for(int j=i; j<n; j+=k){
			if(t[j] == prev){
				prev = ' ';
			}else{
				if(t[j]=='r'){
					ans += p;
					prev = 'r';
				}else if(t[j]=='s'){
					ans += r;
					prev = 's';
				}else{
					ans += s;
					prev = 'p';
				}
			}

		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define pb push_back
#define lp(j, n)  for(int j=0; j<(int)(n); ++j)
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
#define F first
#define S second
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int,int> > vpii;
typedef map<int, int> mii;
const ll N=1e5+5;
ll arr[N],A[N]  ;
bool visited[N]={};
int main()
{
  int n,sum=0;
  cin>>n;
  for(int i=0 ; i<n && cin>>arr[i] ; i++);
  sort(arr , arr+n , greater<int>());
  arr[0]/=2;
  rep(i,n)
  sum+=arr[i];
  cout<<sum;
 go;
}


Measured memory_bytes: 256
import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange
BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0
 
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = 'x' in file.mode or 'w' in file.mode
        self.write = super(FastIO, self).write if self.writable else None
 
    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s
 
    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()
 
    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b'\n') + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
 
# Cout implemented in Python
import sys
class ostream:
    def __lshift__(self,a):
        sys.stdout.write(str(a))
        return self
cout = ostream()
endl = '\n'




def solve():
    n, m = map(int, input().split())

    adj_list = {x: [] for x in range(1, n + 1)}

    uf = [x for x in range(n + 1)]
    sz = [1]  * (n + 1)

    def find(i):
        while uf[i] != i:
            uf[i] = uf[uf[i]]
            i = uf[i]
        return i

    def check(i, j):
        return find(i) == find(j)

    def union(i, j):
        a = find(i)
        b = find(j)
        if sz[a] < sz[b]:
            uf[a] = uf[b]
            sz[b] += sz[a]
        else:
            uf[b] = uf[a]
            sz[a] += sz[b]

    for _ in range(m):
        a, b = map(int, input().split())
        if not check(a, b):
            union(a, b)

    sets = 0

    for i in range(1, n + 1):
        if uf[i] == i:
            sets += 1

    cout<<sets - 1<<endl




def main():
    solve()


if __name__ == "__main__":
    main()

Measured memory_bytes: 101992
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.stream.LongStream;
import java.util.Scanner;
import java.util.OptionalInt;

/**
 * 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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int[] A = new int[N];
            int nega = 0;
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
                nega += A[i] < 0 ? 1 : 0;
                A[i] = Math.abs(A[i]);
            }
            int min = 0;
            if (nega % 2 == 1) {
                min = Arrays.stream(A).min().getAsInt();
            }
            long sum = Arrays.stream(A).asLongStream().sum();
            out.println(sum - (min * 2));
        }

    }
}



Measured memory_bytes: 51760
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
using namespace std;

int main(){
  int A, B , ans=0 ;
  cin >> A >> B ;
  if(A < 10){
    ans = B + 100 * (10 - A) ;
  }  
  else{
    ans = B ;
  }  
  cout << ans << endl ;
  return 0 ;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int isPrime(int);
int main(){
	int n,i,j=0;
	scanf("%d",&n);
	int A[n];
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	for(i=0;i<n;i++){
		if(isPrime(A[i])==1){
			j++;
		}
	}
	printf("%d\n",j);
}
int isPrime(int x){
	int i;
  if (x == 2)
    return 1;
  if (x < 2 || x%2==0){
    return 0;
   }
  i = 3;
  while( i <= sqrt(x)){ //の平方根
    if (x % i==0) //で割り切れる
      return 0;
    i = i + 2;
	}
 return 1;
 }


Measured memory_bytes: 2060
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}

signed main() {
	int n, q;
	cin >> n >> q;
	int a[100005];
	rep(i, n) {
		cin >> a[i];
	}
	sort(a, a + n);
	rep(i, q) {
		int l, r;
		cin >> l >> r;
		cout << (upper_bound(a, a + n, r) - 1) - (lower_bound(a, a + n, l))+1 << endl;
	}

	return 0;
}



Measured memory_bytes: 3948
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)

int main() {
    int n,m;
    long long ans=0;
    int tmp1,tmp2;
    scanf("%d %d", &n,&m);
    vector<pair<int,int> > pa;
    REP(i,n) {
        scanf("%d %d",&tmp1,&tmp2);
        pa.push_back(make_pair(tmp1,tmp2));
    }
    sort(pa.begin(), pa.end());
    REP(i,n) {
        while(pa[i].second!=0){
            ans+=pa[i].first;
            pa[i].second--;
            m--;
            if(m==0) {
                cout << ans << "\n";
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int m,g;
  int card[7];
  int num[7];
  while(cin>>m){
    if(m==0) break;
    REP(i,m){
      cin>>card[i]>>num[i];
    }
    cin>>g;
    int dp[1001]={};
    dp[0] = 1;
    for(int i=0; i<m; i++){
      for(int j=1000-card[i];j>=0;j--){
        for(int k=1; k<=num[i]&&j+k*card[i]<=1000;k++){
          dp[j+k*card[i]] += dp[j];
        }
      }
    }
    while(g--){
      int n;
      cin>>n;
      cout<<dp[n]<<endl;
    }
  }
  return 0;
}

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

int main(){
    int N, M;
    cin >> N >> M;
    int s, c;
    string moji;
    vector<pair<int,int>> data(M);
    rep(i, 0, M){
        cin >> s >> c;
        data[i].first = s-1;
        data[i].second = c;
    }
    rep(i, 0, 1000){
        moji = to_string(i);
        bool b = true;
        if (moji.size() != N){
            continue;
        }
        rep(j, 0, M){
            if ((moji[data[j].first] - '0') != data[j].second){
                b = false;
            }
        }
        if (b){
            cout << moji << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("in.txt");ofstream coutt("out.txt");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Use __builtin_popcountll for ll;
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 


signed main(){
    FASTER;
    int r;cin>>r;
    cout<<3*r*r;
}



Measured memory_bytes: 3588
#include<cstdio>
using namespace std;

int check( double x0, double y0, double x1, double y1, double x2, double y2 ){
	return (x1-x0)*(y2-y0)-(y1-y0)*(x2-x0) > 0 ? 1 : -1; 
}

int main(){
	double x[3], y[3], xp, yp;
	while( scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&xp,&yp) != EOF ){
		int ch = check( x[0], y[0], x[1], y[1], xp, yp );
		ch += check( x[1], y[1], x[2], y[2], xp, yp );
		ch += check( x[2], y[2], x[0], y[0], xp, yp );
		if( ch==3 || ch==-3 ){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;


	public class Main {
		
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
	        
			int n = sc.nextInt();
			int a;
			int ans = 0;
			
			Map<Integer,Integer> m = new TreeMap<Integer,Integer>();
			
			for(int i=0;i<n;i++) {
				a = sc.nextInt();
				m.merge(a, 1, Integer::sum);
			}
			
			for(Map.Entry<Integer, Integer> e : m.entrySet()){
				int key = e.getKey();
				int value = e.getValue();
				
				if(key==value) {
					continue;
				}else if(key>value) {
					ans += value;
				}else {
					ans += (value-key);
				}
			}
			
			System.out.println(ans);
		}
	}


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

void insertsort(vector<int> &array,int n){
    for(int i=1; i<n; i++){
        int val = array.at(i);
        int j = i-1;
        while(j >= 0 && array.at(j) > val){
            array.at(j+1) = array.at(j);
            j--;
        }
        array.at(j+1) = val;
        for(int k=0; k<n; k++){
        if(k == n-1){
            cout << array.at(k) << "\n";
        }else{
            cout << array.at(k) << " ";
        }
    }
}
}

int main(){
    int n;
    cin >> n;
    vector<int> array(n);
    for(int i=0; i<n; i++) cin >> array.at(i);
    for(int k=0; k<n; k++){
        if(k == n-1){
            cout << array.at(k) << "\n";
        }else{
            cout << array.at(k) << " ";
        }
    }
    insertsort(array,n);
}


Measured memory_bytes: 3084
#include<iostream>

using namespace std;

int F[50];


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


Measured memory_bytes: 3088
#include <iostream>
#include <cmath>
using namespace std;
#define MAX 1000000

int main(){
	bool p[MAX+1];
	int n, ans;

	for(int i=0 ; i<=MAX ; i++){
		p[i] = (i<=1)? false : true ;
	}

	for(int i=2 ; i<=sqrt((double)MAX)+1 ; i++){
		if(p[i]){
			for(int j=i*2 ; j<=MAX ; j+=i){
				p[j] = false;
			}
		}
	}

	while( cin >> n ){		
		ans = 0;
		for(int i=0 ; i<=n ; i++){
			if(p[i]){
				ans++;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, k;
	cin >> a >> b >> k;
	set<int> st;
	REP(i, k)if(i+a<=b)st.insert(i + a);
	REP(i, k)if(b-i>=a)st.insert(b - i);
	for (auto i : st)cout << i << endl;

}


Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
count = 0
for i in range(N):
  A = list(map(int, input().split()))
  tmp = C
  for j in range(M):
    tmp += A[j]*B[j]
  if tmp > 0:
    count += 1
print(count)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
ll a[100009];
ll c[100009];
int main()
{
	FAST
	#ifdef ayk_16
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
	#endif
	ll n,m;
	ll x;
	string y;
	cin>>n>>m;
	for(ll i=0;i<m;i++)
	{
		cin>>x>>y;
		if(y=="WA"&&a[x]==0)
			c[x]++;
		if(y=="AC")
			a[x]=1;
	}
	ll ans1=0,ans2=0;
	for(ll i=0;i<=n;i++)
	{
		ans1+=a[i];
		if(a[i]==1)
		    ans2+=c[i];
	}
	cout<<ans1<<' '<<ans2;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int ans = 0;
    for (int i = 0; i < 3; i++){
      int a = sc.nextInt();
      ans += a;
    }
    System.out.println(ans <= 21 ? "win" : "bust");
  }
}


Measured memory_bytes: 35608
import java.util.Scanner;
import java.util.Arrays;

public class Main {
  static String s;

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

    s = sc.next();
    int n = s.length();

    long ans = 0;
    for(int ss = 0; ss < (1 << (n - 1)); ss++){
      int[] tmp = new int[n - 1];
      int sp = 0;
      for(int i = 0; i < n - 1; i++){
        if((ss & (1 << i)) != 0){
          tmp[sp++] = 2 * i + 1;
        }
      }
      char[] str = new char[n + n - 1];
      Arrays.fill(str, ' ');
      for(int i = 0; i < sp; i++){
        str[tmp[i]] = '+';
      }
      int c = 0;
      for(int i = 0; i < n; i++){
        str[2 * i] = s.charAt(i);
      }
      long sum = 0;
      for(int i = 0; i < n + n - 1; i++){
        if(str[i] == ' '){
          continue;
        }
        if(str[i] != '+'){
          sum = (sum + str[i] - '0') * 10;
        }
        else{
          ans += sum / 10;
          sum = 0;
        }
      }
      ans += sum / 10;
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 10068
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;

vector<int> fac(300001); //n!(mod M)
vector<int> ifac(300001); //k!^{M-2} (mod M)

long long fpow(long long a,long long n){
  long long ret=1;
  if(n==1) return a;
  if(n%2==0) {
      ret = fpow(a*a%mod, n/2) %mod ;
  }else {
      ret = (a%mod)*fpow(a*a%mod, n/2) %mod;
  }
  return ret %mod;
}
int comb(int a, int b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    int tmp = ifac[a-b]* ifac[b] % mod;
    return tmp * fac[a] % mod;
}

vector<int> ra(MX,0);
vector<int> par(MX,0);

signed main(){
    int n, m, k ;
    cin >> n >> m >> k;

    int ans = 0;
    for (size_t i = 0; i < m; i++)
    {
        ans += i*(m-i)*n*n;
    }
    for (size_t i = 0; i < n; i++)
    {
        ans += i*(n-i)*m*m;
    }

    fac[0] = 1;
    ifac[0] = 1;
    for(int i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % mod; // n!(mod M)
        ifac[i+1] = ifac[i]*fpow(i+1,mod-2) % mod; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }

    int cnb = comb(m*n-2, k-2);
    cout << (ans%mod*cnb)%mod << endl;
}

Measured memory_bytes: 20608
#include<iostream>

using namespace std;

int main(){

	int T[101][101], r, c;

	cin >> r >> c;

	for( int i = 0; i < r; i++)

		for( int j = 0; j < c; j++) cin >> T[i][j];

	for( int i = 0; i <= r; i++) T[i][c] = 0;

	for( int j = 0; j <= c; j++) T[r][j] = 0;

	for( int i = 0; i < r; i++){

		for( int j = 0; j< c; j++){

			T[i][c] += T[i][j];

			T[r][j] += T[i][j];

			T[r][c] += T[i][j];

		}

	}


	for( int i = 0; i <= r; i++){

		for( int j = 0; j <= c; j++){

			if ( j ) cout << " ";

			cout << T[i][j];

		}

		cout << endl;

	}

	return 0;

}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <iostream>
#include <cstdlib>
using namespace std;

int main(){
	long long int n,i;
	cin>>n;
	long long int h[n];
	for(i=0;i<n;i++){
		cin>>h[i];
	}
	
	long long int dp[n];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+ abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1792
from heapq import heappush, heappop
inf = float('inf')
mod = 10**9 + 7

class dijkstra:
    def __init__(self, to, start):
        self.N = len(to)
        self.to = [s[:] for s in to]
        self.start = start
        self.dist = [inf] * self.N
        self.dist[start] = 0
        self.cnt = [0] * self.N
        self.cnt[start] = 1
        self.pq = [(self.dist[start], start)]

    def update(self) -> None:
        while self.pq:
            _, v = heappop(self.pq)
            for nv, w in self.to[v]:
                if self.dist[nv] > self.dist[v] + w:
                    self.dist[nv] = self.dist[v] + w
                    heappush(self.pq, (self.dist[nv], nv))
                if self.dist[nv] == self.dist[v] + w:
                    self.cnt[nv] += self.cnt[v]
                    self.cnt[nv] %= mod

n, m, s, t = map(int,input().split())
s -= 1; t -= 1
jpy = [[] for _ in range(n)]
snuke = [[] for _ in range(n)]
for _ in range(m):
    u, v, a, b = map(int,input().split())
    u -= 1; v -= 1
    jpy[u].append((v, a))
    jpy[v].append((u, a))
    snuke[u].append((v, b))
    snuke[v].append((u, b))

JPY = dijkstra(jpy, s)
JPY.update()
SNUKE = dijkstra(snuke, t)
SNUKE.update()

cost_list = []
cost = inf

for i in range(n)[::-1]:
    cost = min(cost, JPY.dist[i] + SNUKE.dist[i])
    cost_list.append(cost)

cost_list.reverse()
for cost in cost_list:
    ans = pow(10, 15) - cost
    print(ans)

Measured memory_bytes: 131232
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a[4];
  for(int i=0;i<3;i++)
  {
    cin>>a[i];
  }
  sort(a,a+3);
  cout<<a[1]-a[0]+a[2]-a[1]<<endl;
}


Measured memory_bytes: 3576
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

bool** logTable;

void func(int n,int m,int h, int k){

	int work[n+1],loc_value[n+1],value[n+1],sum = 0,left,height;

	for(int i = 1; i <= n; i++)work[i] = i;

	for(int i = 1; i <= n; i++)scanf("%d",&loc_value[i]);

	for(int i = 0; i < m; i++){
		scanf("%d %d",&left,&height);
		logTable[height][left] = true;
	}

	for(int depth = 1; depth <= h; depth++){
		for(int col = 1; col <= n; col++){
			if(logTable[depth][col] == true){
				swap(work[col],work[col+1]);
			}
		}
	}

	for(int i = 1; i <= n; i++){
		value[work[i]] = loc_value[i];
		if(work[i] <= k){
			sum += loc_value[i];
		}
	}

	int div_max = -1000000,tmp_div;

	for(int i = 1; i <= n; i++)work[i] = i;

	for(int depth = 1; depth <= h; depth++){
		for(int col = 1; col <= n; col++){
			if(logTable[depth][col] == true){
				if(work[col] <= k && work[col+1] > k){
					tmp_div = value[work[col]] - value[work[col+1]];
					if(tmp_div > div_max){
						div_max = tmp_div;
					}
				}else if(work[col] > k && work[col+1] <= k){
					tmp_div = value[work[col+1]] - value[work[col]];
					if(tmp_div > div_max){
						div_max = tmp_div;
					}
				}
				swap(work[col],work[col+1]);
			}
		}
	}

	if(div_max > 0){
		sum -= div_max;
	}

	printf("%d\n",sum);
}

int main(){

	int n,m,h,k;

	logTable = new bool*[1001];
	for(int i = 0; i < 1001; i++){
		logTable[i] = new bool[1001];
	}

	while(true){
		scanf("%d %d %d %d",&n,&m,&h,&k);
		if(n == 0 && m == 0 && h == 0 && k == 0)break;

		for(int i = 0; i < 1001; i++){
			for(int k = 1; k <= 1000; k++)logTable[i][k] = false;
		}

		func(n,m,h,k);
	}
    return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){	

int ans = 0;
string N;
cin >> N;
for(int i = 0; i < 4; i++){
	if(N[i] == '2'){
		ans++;
	}
}
cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <string.h>
#include <bitset>
#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define allr(x) x.begin(),x.end(),greater<int>()
#define P pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1ll << 60
#define PI 3.14159265359

using namespace std;

int main(){
	int n;
	cin >> n;
	int a,b;
	cin >> b;
	ll ans = 0;
	rep1(i,n){
		cin >> a;
		if(a <= b) ans++;
		b = a;
	}
	cout << ans+1 << endl << n << endl;
	return 0;
}


Measured memory_bytes: 3120
n = int(input())
t_x_y_list = [list(map(int, input().split())) for _ in range(n)]
pt = 0
px = 0
py = 0
for t, x, y in t_x_y_list:
    if t - pt < abs(px - x) + abs(py - y):
        print("No")
        exit()
    if (t - pt) % 2 != (abs(px - x) + abs(py - y)) % 2:
        print("No")
        exit()
    pt = t
    px = x
    py = y
print("Yes")

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

using namespace std;
using ll = long long;
ll mo=1e9+7;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m,q;
    cin>>n>>m>>q;
    vector<vector<int>> exp(n+5,vector<int>(n+5));
    for(int i=0;i<m;++i){
        int x,y;
        cin>>x>>y;
        exp[x][y]++;
    }
    for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)exp[i][j] += exp[i][j-1];
    for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)exp[i][j] += exp[i-1][j];
    for(int i=0;i<q;++i){
        int ql,qr;
        cin>>ql>>qr;
        cout << exp[qr][qr] +  exp[ql-1][ql-1] - exp[qr][ql-1] - exp[ql-1][qr]<<endl;
    }
    return 0;
}



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

using namespace std;

using ll = long long;

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)

typedef pair<int, int> P;

const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

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;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	double a[n];
	rep(i, n) cin >> a[i];
	
	double sum = 0;
	rep(i, n) sum += a[i];
	double ave = sum / n;
	
	int id = 0;
	double d = INF;
	rep(i, n) {
		double dis = abs(a[i] - ave);
		if (dis < d) {
			d = dis;
			id = i;
		}
	}
	
	cout << id << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

void prime_factorize(int n, std::map<int,int>& prime_factors) {
	for(int i=2;i*i<=n;i++) {
		while(n%i==0) {
			prime_factors[i]++;
			n/=i;
		}
	}
	if(n!=1) prime_factors[n]++;
}


int check(int n, int k) {
	while(n%k==0) n/=k;
	if(n%k==1) return 1;
	else return 0;
}

signed main() {
	int n;
	std::cin >> n;
	int count=check(n,n);
	for(int x=2;x*x<=n;x++) {
		if(n%x==0) {
			count+=check(n,x);
			if(x*x!=n) count+=check(n,n/x);
		}
	}
	std::map<int,int> map;
	prime_factorize(n-1,map);
	int cnt=1;
	for(auto x:map) cnt*=x.second+1;
	cnt--;
	if(map.empty()) cnt=0;
	debug(cnt,count);
	print(count+cnt);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;cin >> n;
	ll ans=0;
	for(ll i=1;i*i<n;++i){
		if(n%i==0 && n/i-1!=i){
			ans+=n/i-1;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  ll a[3*n];
  rep(i,0,3*n) cin>>a[i];
  priority_queue<ll,vector<ll>,greater<ll>> b;
  ll cur=0;
  rep(i,0,n){
    cur+=a[i];
    b.push(a[i]);
  }
  ll c[n+1];
  c[0]=cur;
  rep(i,0,n){
    if(b.top()<a[n+i]){
      cur=cur-b.top()+a[n+i];
      b.pop();
      b.push(a[n+i]);
    }
    c[i+1]=cur;
  }
  
  priority_queue<ll> d;
  cur=0;
  rep(i,0,n){
    cur+=a[2*n+i];
    d.push(a[2*n+i]);
  }
  ll e[n+1];
  e[0]=cur;
  rep(i,0,n){
    if(d.top()>a[2*n-1-i]){
      cur=cur-d.top()+a[2*n-1-i];
      d.pop();
      d.push(a[2*n-1-i]);
    }
    e[i+1]=cur;
  }
  ll ans=-1e15;
  rep(i,0,n+1) ans=max(ans,c[i]-e[n-i]);
  cout<<ans<<endl;
}

  

Measured memory_bytes: 5876
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;

int main(void) {
    char a;
    cin >> a;

    if ('A' <= a && a <= 'Z') cout << "A" << endl;
    else cout << "a" << endl;

    return 0;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

int main() {
    cin >> n;
    vs s;

    NREP() {
        IPT(string, s)
        sort(ALL(s.at(i)));
    }

    sort(ALL(s));

    ll ans = 0;
    ll sum = 1;

    for (ll i = 0; i < s.size() - 1; ++i) {
        if (s.at(i) == s.at(i + 1)) {
            sum++;
        } else {
            ans += (sum * (sum - 1)) / 2;
            sum = 1;
        }
    }

    ans += (sum * (sum - 1)) / 2;
    MSG(ans)
}


Measured memory_bytes: 5748
/*
 *  Language:   C++
 *  Author:     Debajyoti Dasgupta
 */

#include <bits/stdc++.h>

using namespace std;
#define int long long
vector<vector<int>> a;
vector<int> cost, v;
int n, m, x;

void dfs(int i, int c, int &res) {
    if (i == n) {
        for (int j = 0; j < m; ++j) {
            if (v[j] < x)return;
        }
        res = min(res, c);
        return;
    }
    dfs(i + 1, c, res);
    for (int j = 0; j < m; ++j) { v[j] += a[i][j]; }
    dfs(i + 1, c + cost[i], res);
    for (int j = 0; j < m; ++j) { v[j] -= a[i][j]; }
}

signed main() {
    cin >> n >> m >> x;
    cost.resize(n);
    a.assign(n, vector<int>(m));
    for (int i = 0; i < n; ++i) {
        cin >> cost[i];
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }
    v.resize(m);
    int ans = INT_MAX;
    dfs(0, 0, ans);
    if (ans == INT_MAX)cout << -1 << endl;
    else cout << ans << endl;
}

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

int main(void){
    string s;
    cin>>s;
    int n=s.size();
    int a=n/2;
    int ans=0;
    rep(i, a){
        if(s[i]!=s[n-i-1]){
            ans++;
        }
    }
    cout<<ans<<endl;
}

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

int main(){
  
  int w, h, t, p;
  int x[50], y[50];
  int s[50][50];

  cin>>w>>h>>t>>p;
  for(int i=0;i<p;i++){
    int t;
    cin>>x[i]>>y[i]>>t;
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>s[i][j];
    }
  }

  int sum=0;
  for(int i=0;i<p;i++){
    if(s[y[i]][x[i]]==1) sum++;
  }

  cout<<sum<<endl;
  
  return 0;
}

Measured memory_bytes: 3112
#include<iostream>

using namespace std;

int main(){

	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if(W<x+r){
		cout<<"No"<<endl;
	}else{
		if(H<y+r){
			cout<<"No"<<endl;
		}else{
			if(x<r){
				cout<<"No"<<endl;
			}else{
				if(y<r){
					cout<<"No"<<endl;
				}else{
					cout<<"Yes"<<endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int n, p;
    cin >> n >> p;
    map<int, int> mp;
    for (int i = 2; i * i <= p; i++) {
        while (p % i == 0) {
            p /= i;
            mp[i]++;
        }
    }
    mp[p]++;
    int ans = 1;
    for (auto p : mp) {
        ans *= pow(p.first, p.second / n);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 4104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
const int N=1e5+5;
ll cnt[N];
ll n,k,ans;

ll pow(ll num){
    ll res=1,m=n;
while(m>0){
    if(m&1)
    res=res*num%mod;
    num=num*num%mod;
    m>>=1;
}
//cout<<res<<'.'<<endl;
return res;
}

int main(){
ios::sync_with_stdio(0);
cin>>n>>k;
for(ll i=k;i>=1;i--){
    cnt[i]=pow(k/i);
    for(ll j=2;j*i<=k;j++){
        cnt[i]-=cnt[j*i];
    }
    ans+=(mod+(cnt[i]*i)%mod)%mod;
    ans=(ans+mod)%mod;
    //cout<<ans<<endl;
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 4320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
namespace IO
{
	template <typename T> inline void read(T &x)
	{
		int f = 1; x = 0; char c = getchar();
		for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
		for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
		x *= f;
	}

	template <typename T> inline void chkmax(T &x, T y) { x = x > y ? x : y; }
	template <typename T> inline void chkmin(T &x, T y) { x = x < y ? x : y; }

	template <typename T> inline void write(T x)
	{
		if (x < 0) putchar('-'), x = -x;
		if (x > 9) write(x / 10);
		putchar(x % 10 + '0');
	}
	template <typename T> inline void writesp(T x) { write(x); putchar(' '); }
	template <typename T> inline void writeln(T x) { write(x); putchar('\n'); }
}
using namespace IO;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
inline void mul(ll &x, ll y) { x = (x * y % mod + mod) % mod; }
vector <ll> vec[2];
int n, k;
int main(){
	read(n); read(k);
	ll x;
	bool f = 0;
	for (int i = 1; i <= n; i++) {
		read(x);
		if (x > 0) vec[0].push_back(x);
		if (x < 0) vec[1].push_back(x);
		if (x == 0) f = 1;
	}
	for (int i = 0; i < 2; i++) sort(vec[i].begin(), vec[i].end());
	
	if (vec[0].size() + vec[1].size() < k) {
		puts("0");
		return 0;
	}

	if ((vec[0].empty() && k % 2 == 1)) {
		if (f) {
			puts("0");
			return 0;
		}
		reverse(vec[1].begin(), vec[1].end());
	
		ll ans = 1;
		for (int i = 0; i < k; i++) mul(ans, vec[1][i]);
		writeln(ans);
		return 0;
	}
	if (vec[0].size() + vec[1].size() == k) {
		if (vec[1].size() % 2 == 1 && f) {
			puts("0");
			return 0;
		}
		ll ans = 1;
		for (int i = 0; i < vec[0].size(); i++) mul(ans, vec[0][i]);
		for (int i = 0; i < vec[1].size(); i++) mul(ans, vec[1][i]);
		writeln(ans);
		return 0;
	}
	
	if (vec[1].size() & 1) vec[1].pop_back();
	for (int i = 0; i < vec[1].size(); i++) vec[1][i] = -vec[1][i];
	
	ll ans = 1;
	if (k & 1) {
		mul(ans, vec[0].back()); vec[0].pop_back();
		k--;
	}
	reverse(vec[0].begin(), vec[0].end());
	if (vec[0].size() & 1) vec[0].pop_back();
	int posa = 0, posb = 0;
	
	while (k)
	{
		k -= 2;
		if (posa >= vec[0].size()) {
			mul(ans, vec[1][posb]);
			mul(ans, vec[1][posb + 1]);
			posb += 2;
		}
		else if (posb >= vec[1].size()) {
			mul(ans, vec[0][posa]);
			mul(ans, vec[0][posa + 1]);
			posa += 2;
		}
		else {
			ll B = vec[1][posb] * vec[1][posb + 1];
			ll A = vec[0][posa] * vec[0][posa + 1];
			if (A > B) {
				mul(ans, vec[0][posa]);
				mul(ans, vec[0][posa + 1]);
				posa += 2;
			}
			else {
				mul(ans, vec[1][posb]);
				mul(ans, vec[1][posb + 1]);
				posb += 2;
			}
		} 
	}
	writeln(ans);
  return 0;
}

Measured memory_bytes: 5360
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>

using namespace std;
typedef long long int ll;typedef pair<int, int> P;
const long long mod = 1e9 + 7;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }

int main(void) {
	int n; cin >> n;
	bool f = 0;
	for (int i = 1; i <= 9; i++) {
		int x = n;
		if (x % i == 0) {
			x /= i;
			if (x < 10) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;



	return 0;
}



Measured memory_bytes: 256
import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

a,b,c=mp()
if b-a==c-b:
    print("YES")
else:
    print("NO")
    

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define mod 1000000007
#pragma GCC optimize("O3")
using namespace std;
long long ans[2002], n, k, combi[4002][4002];
void pascal()
{
    combi[0][0] = combi[1][0] = combi[1][1] = 1;
    for(int i = 2; i <= 4000; ++i)
    {
        combi[i][0] = 1;
        for(int j = 1; j <= i; ++j)
        {
            combi[i][j] = combi[i-1][j] + combi[i-1][j-1];
            if(combi[i][j] >= mod)
                combi[i][j] -= mod;
        }
    }
}
long long pw(long long a, long long b)
{
    long long ans = 1;
    while(b)
    {
        if(b&1)
            ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    pascal();
    ans[1] = n - k + 1;
    for(long long j = 2; j <= k; ++j)
    {
        int lft = n - k - (j - 1);
        long long nr = (combi[k-1][j-1] * combi[j+lft][lft]) % mod;
        ans[j] = nr;
    }
    for(int i = 1; i <= k; ++i)
        cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 123648
N = gets.to_i
A = gets.split().map(&:to_i)


sum = A.inject(&:+)

min = 100000000000

left = 0

(0..N-1).each do |i|
  left += A[i]
  if left >= sum / 2
    right = sum - left
    min = [min, left-right].min
    left -= A[i]
    right = sum - left
    min = [min, right-left].min
    break
  end
  next
end

puts min





Measured memory_bytes: 16132
import heapq

S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        exit()

ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1

print(ans)

Measured memory_bytes: 3620
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;

int main() {
    ll N, K, ans = 0, s = 0;
    cin >> N >> K;
    vector<int> p(N);
    rep(i, N) cin >> p[i];
    rep(i, K) s += p[i];
    ans = s;
    rep(i, N - K) {
        s = s - p[i] + p[K + i];
        ans = max(ans, s);
    }
    cout << setprecision(10) << (ans + K) / 2.0 << "\n";
}

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

using namespace std;
#define ll long long

void init();
void solve();

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

#define MOD 1000000007

signed main()
{
	init();
	solve();
}

int N;

void init()
{
	cin >> N;
}

void solve()
{
	int a, b;
	a = N / 2;
	b = (N+1) / 2;
	cout << a*b << endl;
}


Measured memory_bytes: 764
def paint(rect, x, y, a):
    if a == 1:
        indx = x
        for j in range(len(rect)):
            for i in range(indx):
                rect[j][i] = 1
    elif a == 2:
        indx = x
        for j in range(len(rect)):
            for i in range(indx, len(rect[0])):
                rect[j][i] = 1
    elif a == 3:
        indx = y
        for j in range(indx):
            for i in range(len(rect[0])):
                rect[j][i] = 1
    elif a == 4:
        indx = y
        for j in range(indx, len(rect)):
            for i in range(len(rect[0])):
                rect[j][i] = 1

def disp(rect):
    for i in range(len(rect)):
        print(rect[i])

def sum(rect):
    sum = 0
    for i in range(len(rect)):
        for j in range(len(rect[0])):
            sum += rect[i][j]
    return sum

if __name__ == '__main__':
    [W, H, N] = [int(i) for i in raw_input().split(' ')]
    rectangle = [[0 for i in range(W)] for j in range(H)]
    for i in range(N):
        [x, y, a] = [int(n) for n in raw_input().split(' ')]
        paint(rectangle, x, y, a)
    print(H*W - sum(rectangle))




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




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


    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    if(n==1){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 0;
    ll r = 1;
    for(int i=0;i<n;){
        ll ret = 0;
        r = i+1;
        while(r<n && a[r-1]>=a[r]){
            r++;
        }
        ans = max(ans,r-i-1);
       // cerr << r << " " << i << ans<<endl;
        i = r;
    }
    cout << ans << endl;

}

Measured memory_bytes: 1024