akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

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

        try{
            int N = scan.nextInt();
            int M = scan.nextInt()+1;
            int[][] A_ = new int[N][M];
            int[] Kind_ = new int[M];

            //初期化
            for(int i = 0; i < N; i++){
                for(int j = 0; j < M; j++){
                    A_[i][j] = 0;
                }
            }
            for(int i = 0; i < M; i++){
                Kind_[i] = 0;
            }

            //連想配列
            for(int i = 0; i < N; i++){
                int K = scan.nextInt();
                for(int j = 0; j < K; j++){
                    A_[i][j] = scan.nextInt();
                    Kind_[A_[i][j]]++;
                }
            }

            int count = 0;
            for(int i = 1; i < M; i++){
                if(Kind_[i] == N){
                    count++;
                }
            }
            System.out.println(count);
        }finally{
            scan.close();
        }
    }
}


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

int main(){

  int i, n, x, flag = 0;

  cin >> n;
 
  for(i = 3; i <= n; i++){
    x = i;
    if(x % 3 == 0){
      cout <<" "<< i;
      flag = 1;
    }
    while(x != 0 && flag == 0){
      if (x % 10 == 3){
	cout <<" "<< i;
	break;
      }
      x = x / 10;
    }
    flag = 0;
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3092
#include <stdio.h>

int main(void) {
	int i, n, k, s[2000001];
	scanf("%d", &n);
	for (i = 1; i < n; i++)
	{
		scanf("%d", &k);
		s[k]++;
	}
	for (i = 1; i < n + 1; i++)
	{
		printf("%d\n", s[i]);
	}
	return 0;
}

Measured memory_bytes: 2512
package main

import (
	"fmt"
	"strings"
)

func main() {
	var h, w int

	for {
		fmt.Scan(&h, &w)
		if h == 0 && w == 0 {
			break
		}
		for i := 0; i < h; i++ {
			if i == 0 || i == h-1 {
				fmt.Println(strings.Repeat("#", w))
			} else {
				fmt.Println("#" + strings.Repeat(".", w-2) + "#")
			}
		}
		fmt.Println()
	}
}



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

const int INF = 1e9;

int main() {
  int n;
  cin >> n;
  vector<int> dp(n+1, INF);
  dp[0] = 0;
  rep(i, n) {
    dp[i+1] = min(dp[i+1], dp[i] + 1);
    for (int j = 6; i+j <= n; j *= 6) {
      dp[i+j] = min(dp[i+j], dp[i] + 1);
    }
    for (int j = 9; i+j <= n; j *= 9) {
      dp[i+j] = min(dp[i+j], dp[i] + 1);
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 3664
N,K = map(int,input().split())
A = [int(i) for i in input().split()]

from collections import Counter
A_C = Counter(A)
LEN = len(A_C)
ans = 0
for i,(k,v) in enumerate(sorted(A_C.items(),key=lambda x:x[1])):
    
    if i < LEN-K:
        ans +=v
print(ans)

Measured memory_bytes: 39324
S = raw_input()
T = raw_input()
N = len(S)
M = len(T)
ans = '{'

for i in xrange(N-M+1):
    if all(S[i+j] == T[j] or S[i+j] == '?' for j in xrange(M)):
        tmp = list(S)
        for j in xrange(M):
            tmp[i+j] = T[j]
        tmp = ''.join(tmp)
        tmp = tmp.replace('?', 'a')
        ans = min(ans, tmp)

print ans if ans != '{' else 'UNRESTORABLE'


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define f(i,l,n) for(ll i=l;i<n;i++)
#define ff first
#define ss second
#define pb push_back
#define E "\n"
#define mp make_pair
#define N (ll)pow(2,32)-1
 
const int M=1e9+7;


 int solve()
 {

  int n,k;
  cin >> n >> k;

  cout<<min(n%k,k-n%k)<<E;


  return 0;
 }
int32_t main()
{
  
  int t=1;
  //cin >> t;
  while(t--)
  {
    solve();  
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000


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

    std::string S;
    cin >> S;
    int ans = 0;
    rep(i, 4) {
        if(S[i] == '+') ++ans;
        else --ans;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
	let line = get_input();
    let mut split = line.split_whitespace();
    let a:u64 = split.next().unwrap().parse().unwrap();
    let b:u64 = split.next().unwrap().parse().unwrap();
    let c:u64 = split.next().unwrap().parse().unwrap();
    
    let mut ans = b / a;
    println!("{}", if ans > c { c } else { ans });
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define int long long

#define mp make_pair
#define pb push_back
#define mod (int)1e9+7
using namespace std;

signed main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt1[n];
    int cnt2[n];
    int cnt3[n];
    memset(cnt1,0,sizeof cnt1);
    memset(cnt2,0,sizeof cnt2);
    memset(cnt3,0,sizeof cnt3);
    cnt1[0] = (s[0] == 'R' ? 1 : 0);
    cnt2[0] = (s[0] == 'G' ? 1 : 0);
    cnt3[0] = (s[0] == 'B' ? 1 : 0);
    for(int i = 1;i<n;i++){
        cnt1[i] = cnt1[i-1];
        cnt2[i] = cnt2[i-1];
        cnt3[i] = cnt3[i-1];
        cnt1[i] += (s[i] == 'R' ? 1 : 0);
        cnt2[i] += (s[i] == 'G' ? 1 : 0);
        cnt3[i] += (s[i] == 'B' ? 1 : 0);
    }
    int res = 0;
    for(int i =0;i<n;i++){
        for(int z = i+1;z<n;z++){
            int x = z+z-i;
            if(s[i] == s[z]) continue;
            set<char> ccc;
            ccc.insert('R');
            ccc.insert('G');
            ccc.insert('B');
            ccc.erase(s[i]);
            ccc.erase(s[z]);
            auto it = *ccc.begin();
            int cc = 4;
            if(it == 'R') cc = 0;
            if(it == 'G') cc = 1;
            if(it == 'B') cc = 2;
            if(cc == 0){
                res += cnt1[n-1]-cnt1[z];
                if(x >= n) continue;
                if(s[x] != s[i] && s[i] != s[z] && s[z] != s[x]) res--;
            }
            if(cc == 1){
                res += cnt2[n-1]-cnt2[z];
                if(x >= n) continue;
                if(s[x] != s[i] && s[i] != s[z] && s[z] != s[x]) res--;
            }
            if(cc == 2){
                res += cnt3[n-1]-cnt3[z];
                if(x >= n) continue;
                if(s[x] != s[i] && s[i] != s[z] && s[z] != s[x]) res--;
            }
        }
    }
    cout << res;
}


Measured memory_bytes: 3648
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int maxn=100000+10;
int fa[maxn],co[maxn];
bool bz[maxn],pd[maxn];
int i,j,k,l,r,t,n,m,cnt;
ll ans;
int getfa(int x){
    if (!fa[x]) return x;
    int t=getfa(fa[x]);
    co[x]^=co[fa[x]];
    return fa[x]=t;
}
int main(){
    scanf("%d%d",&n,&m);
    fo(i,1,m){
        scanf("%d%d",&j,&k);
        bz[j]=1;bz[k]=1;
        l=getfa(j);r=getfa(k);
        if (l<r){
            swap(l,r);
            swap(j,k);
        }
        if (l==r&&co[j]==co[k]) pd[l]=1;
        if (l==r) continue;
        pd[r]|=pd[l];
        fa[l]=r;
        co[l]=co[j]^co[k]^1;
    }
    fo(i,1,n)
        if (!bz[i]) cnt++;
    ans=(ll)cnt*(n-cnt)*2+(ll)cnt*cnt;
    cnt=0;
    fo(i,1,n)
        if (bz[i]&&!fa[i]) cnt++;
    ans+=(ll)cnt*cnt;
    cnt=0;
    fo(i,1,n)
        if (bz[i]&&!fa[i]&&!pd[i]) cnt++;
    fo(i,1,n)
        if (bz[i]&&!fa[i]&&!pd[i]) ans+=(ll)cnt;
    printf("%lld\n",ans);
}

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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
// x!
ll factorial_r(ll x) {
  assert(x>=0);
  ll ret = 1;
  while (x>1) {
    ret *= x;
    x--;
  }
  return ret;
}

// xCy
ll combi_r(ll x, ll y) {
  assert(x>=0);
  assert(y>=0);
  assert(x>=y);
  ll ret = 1;
  for (int i=0; i<y; i++) {
    ret *= (x-i);
  }
  return ret/factorial_r(y);
}

int main(int argc, char** argv) {
  int N;
  cin >> N;

  vector<vector<char> > S(N, vector<char>(11));
  map<string, int> counts;

  for (int i=0; i<N; i++) {
    for (int j=0; j<10; j++) {
      cin >> S[i][j];
    }
    S[i][10] = '\0';
    sort(begin(S[i]), begin(S[i])+10);
    string s(&S[i][0]);
    counts[s] += 1;
  }

  ll ret = 0;
  for (auto kv : counts) {
    ll v = kv.second;
    if (v<2) continue;
    ret += combi_r(v, 2);
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 16640
#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
#include <cmath>
using namespace std;

int fact(int n){
  int a=1;
  for(int i=1;i<=n;++i)a*=i;
  return a;
}

int main(){
  int n;
  int p[n], q[n];
  cin >> n;
  for(int i=0;i<n;++i) cin>>p[i];
  for(int i=0;i<n;++i) cin>>q[i];
  int cp, cq;
  cp = cq =0;
  vector<int> vec={1,2,3,4,5,6,7,8};
  for(int i=0;i<n;++i){
    vector<int>::iterator itr=find(vec.begin(),vec.end(),p[i]);
    int index = distance(vec.begin(), itr);
    vec.erase(itr);
    cp+=fact(n-i-1)*index;
  }
  vec={1,2,3,4,5,6,7,8};
  for(int i=0;i<n;++i){
    vector<int>::iterator itr=find(vec.begin(),vec.end(),q[i]);
    int index = std::distance(vec.begin(), itr);
    vec.erase(itr);
    cq+=fact(n-i-1)*index;
  }
  printf("%d\n",abs(cp-cq));
  return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const int MAX_N = 100;
int n;
vi b;

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n;
  forn(i,n) {
    int v;
    cin >> v;
    b.push_back(v);
  }

  vi ans;
  for (int i = n; i >= 1; i--) {
    vi temp;
    bool found = false;
    for (int j = i; j >= 1; j--) {
      if (!found && b[j-1] == j) {
        ans.push_back(j);
        found = true;
      } else {
        temp.push_back(b[j-1]);
      }
    }
    if (!found) {
      cout << -1 << "\n";
      return 0;
    }
    reverse(temp.begin(),temp.end());
    b = temp;
  }

  reverse(ans.begin(),ans.end());
  for (int v : ans)
    cout << v << "\n";

  return 0;
}


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

int main(){
  int K,S;
  cin >> K >> S;
  
  int ans = 0;
  for(int X = 0; X <= K; X++){
    for(int Y = 0; Y <= K; Y++){
      int Z = S - X - Y;
      if(0 <= Z && Z <= K){
        ans++;
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
while True:
    n = int(input())
    if n == 0:
        break
    f = list(input().split())
    
    is_on = False
    left_up = False
    right_up = False
    ans = 0
    for i in range(n):
        if f[i] == "lu":
            left_up = True
        elif f[i] == "ld":
            left_up = False
        elif f[i] == "ru":
            right_up = True
        else:
            right_up = False
        
        if left_up and right_up and not is_on:
            is_on = True
            ans += 1
        elif not left_up and not right_up and is_on:
            is_on = False
            ans += 1
    print(ans)


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b;
  cin >> a >> b;
  int c=b*10;
  bool judge=false;
  for(c;c<(b+1)*10;c++){
    if(c*8/100==a){
      judge=true;
      break;
    }
  }
  if(judge){
   cout << c << endl;
  }
  else{
    cout << "-1" << endl;
  }
}


Measured memory_bytes: 256
x,k,d=map(int, input().split())
x=abs(x)

if x-k*d>0:
    print(x-k*d)
else:
    cur=x-x//d*d
    k=k-x//d
    if k%2==0:
        print(cur)
    else:
        print(abs(cur-d))


Measured memory_bytes: 8956
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int main() {
	int n; cin >> n;
	
	ll l[2] = {2, 1};
	if (n <= 1) cout << l[n] << endl;
	else {
		REP(i, n - 1) l[i&1] = l[0] + l[1];
		cout << l[n & 1] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop") 
#define all(a) a.begin(),a.end()
#define bs binary_search
#define ll long long int
#define ps push_back
#define fs first
#define sc second
#define mkp make_pair
#define mod 1000000007
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	char ar[101];
	cin>>ar;
	n=strlen(ar);

	l=1000000000;
	for(i=1;i<n-1;i++){
		k=((ar[i-1]-'0')*100)+((ar[i]-'0')*10)+(ar[i+1]-'0');
		if((abs(753-k))<l){
			l=abs(753-k);
		}
	}
	cout<<l;
	return 0;
}
//ctrl H replace

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN
#define INF         100000000000000000
#define PI          3.1415926535897932384626433832795l



#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)






// struct mycomp {
//     bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{
//         if (a.second-a.first != b.second-b.first)
//         return (a.second-a.first > b.second-b.first);
//         return a.first < b.first;
//     }
// };



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


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}	
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}


///////////////////////////BFS//////////////////////////////////
void bfs(vector<int>& distance, vector<int> a[], vector<bool>& visited, int u, vector<int>& parent)
{
	visited[u]=true;
	parent[u]=-1;
	distance[u]=0;
	queue<int> q;

	q.push(u); 
    while (!q.empty()) { 
  
        int f = q.front(); 
        q.pop(); 
  		for(int i =0; i < a[f].size(); i++)
  		{
  			if(visited[a[f][i]]==false)
  			{
  				distance[a[f][i]]=distance[f]+1;
  				parent[a[f][i]]=f;
  				visited[a[f][i]]=true;
  				q.push(a[f][i]);
  			}
  		}
    } 

}

void solve()
{

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

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	int l, r, d, c = 0;
	cin>>l>>r>>d;
	for(int i = l; i <= r; i++) 
	{
		if(i%d==0) c++;
	}
	cout<<c<<endl;
	// int ans = (r-l)/d;
	// cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3616
#include<cstdio>
main(){int a,b,d=0,c;while(scanf("%d%d",&a,&b),a){if(d++)puts("");c=0;for(;a<=b;a++)if(a%4<1)if(a%100)c++,printf("%d\n",a);else if(a%400<1)c++,printf("%d\n",a);if(!c)puts("NA");}}

Measured memory_bytes: 0
card = list(map(int, input().split()))
k = int(input())

for i in range(k):
    if card[0] >= card[1]:
        card[1] *= 2
    elif card[1] >= card[2]:
        card[2] *= 2
    else:
        card[2] *= 2

print("Yes") if card[0] < card[1] < card[2] else print("No")


Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
long long int o[110004];
int e[110004];
int main()
{
  long long int N,M,i,j,k,a1,a2,a11,a22,now1,now2;
  cin >> N;
  for(i = 0;i <= 110000;i++)
  {
    o[i] = 0;
    e[i] = 0;
  }
  for(i = 1;i <= N;i++)
  {
    cin >> k;
    //assert(k <= 100000 && k >= 1);
    if((i) % 2 == 0)
      o[k]++;
    else
      e[k]++;
  }
  a1 = 0;
  a2 = 0;
  a11 = 0;
  a22 = 0;
  for(i = 0;i <= 110000;i++)
  {
    if(o[i] >= a1)
    {
      now1 = i;
      a11 = a1;
      a1 = o[i];
    }
    else if(o[i] >= a11)
    {
      a11 = o[i];
    }
    if(e[i] >= a2)
    {
      now2 = i;
      a22 = a2;
      a2 = e[i];
    }
    else if(e[i] >= a22)
    {
      a22 = e[i];
    }
  }
  if(now1 != now2)
    cout << N - a1 - a2 << endl;
  else
  {
    cout << min(N-a1-a22,N-a2-a11) <<endl;
  }
}


Measured memory_bytes: 1536
n = int(input())
s = input()
b = [0] * (n + 1)
w = [0] * (n + 1)

for i in range(n):
    if s[i] == '#':
        b[i + 1] = b[i] + 1
    else:
        b[i + 1] = b[i]

for i in range(n - 1, -1, -1):
    if s[i] == '.':
        w[i] = w[i + 1] + 1
    else:
        w[i] = w[i + 1]

ans = [vb + vw for vb, vw in zip(b, w)]
print(min(ans))


Measured memory_bytes: 20960
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m;
	cin>>n>>m;
	vvi dp(10,vi(10,inf));
	rep(i,10)dp[i][i]=0;
	rep(i,10)rep(j,10)cin>>dp[i][j];
	rep(k,10)rep(i,10)rep(j,10)
		dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
	int out=0;
	rep(i,n*m){
		int a;cin>>a;
		if(a+1)out+=dp[a][1];
	}
	cout<<out<<endl;
}




Measured memory_bytes: 256
n = int(input())
ai = [int(i) for i in input().split()]
bi = [int(i) for i in input().split()]

sita = 0
ue = 0

for i in range(n):
    if ai[i] >= bi[i]:
        sita += ai[i] - bi[i]
    else:
        ue += (bi[i] - ai[i]+1) // 2

#print(sum(bi),sum(ai),ue,sita)
        
if sum(bi) - sum(ai) - max(ue,sita) >= 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 41456
#include <iostream>
#include <cstdio>
using namespace std;
char c;
int main(){
	scanf("%c",&c);
	if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u')
	    printf("vowel\n");
	else
	    printf("consonant\n");
	return 0;
}

Measured memory_bytes: 256
/*input
4
*/

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

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 1e18
#define M 1000000007
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'
#define UQ(x) (x).resize(distance((x).begin(),unique(all((x)))))

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}

ll a[10000001];

void solve(){
	ll i,j,k;
	ll n;
	cin>>n;
	ll ans=0;
	rep(i,1,n+1){
		for(j=i;j<n+1;j+=i)a[j]++;
		ans+=i*a[i];
	}
	cout<<ans<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}




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

int hoge=1;

int calc(int a,int b){
  return min(abs(a-b),hoge-abs(a-b));
}

signed main(){
  string a;
  cin >> a;
  
  int n = 0;
  for (int i = 0; i < a.size(); ++i) {
    n = 10 * n + (a[i] - '0');
  }
  // cin>>n;
  int kt=a.size();
  lp(i,kt)hoge*=10;
  vector<int> v({0,1,2,3,4,5,6,7,8,9});
  int ans;
  int maxdst=-1;
  string ansd = "";
  do{
    int x=0;
    string res = "";
    lp(i,kt){
      res = res+char(v[i] + '0');
      x*=10;
      x+=v[i];
    }

    if (maxdst < calc(n, x)) {
      ansd = res;
      ans = x;
      maxdst = calc(n, x);
    }
  }
  while(next_permutation(v.begin(),v.end()));
  //string ansd=string(kt-to_string(ans).size(),'0')+to_string(ans);
  cout<<ansd<<endl;
  return 0; 
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S;
const ll MOD = (1e+9) + 7;
const ll INF = 1000;//1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    string T;
    cin>>S>>T;
    string ans = "EQUAL";
    if(S.size() > T.size()){
        ans = "GREATER";
    }else if(S.size() < T.size()){
        ans = "LESS";
    }else{
        if(S != T){
            ans = (S > T) ? "GREATER" : "LESS";
        }
    }
    cout<<ans<<endl;
}

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

int main() {
    int n,l;
    cin >> n >> l;
    vector<string>s(n);
    rep(i,n) {
        cin >> s[i];
    }
    sort(s.begin(),s.end());
    string ans;
    rep(i,n) {
        ans +=s[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main(){
  string w[3] = {"Sunny", "Cloudy", "Rainy"}, s;
    cin >> s;
    for(int i=0; i<3; i++)
      if(w[i]==s)
        if(i==2) cout << w[0];
        else cout << w[i+1];
    cout << endl;
}


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

ll dp[3001][3001];
ll n, a[3001];

void solve(ll n, ll m)
{
    // cout << n <<m<<"\n";
    if (dp[n][m]!=-1)
    {
        return;
    }
    else
    {
        dp[n][m]=0;
    }
    if (n==m)
    {
        return;
    }
    if (m==n+1)
    {
        dp[n][m]=a[n];
        return;
    }
    solve(n, m-1);
    solve(n+1, m);
    dp[n][m]=max(a[n]-dp[n+1][m], a[m-1]-dp[n][m-1]);


}

int main()
{

    cin >> n;
    for (int i = 0; i < 3001; ++i)
    {
        for (int j = 0; j < 3001; ++j)
        {
            dp[i][j]=-1;
        }
    }
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }

    solve(0, n);
    cout << dp[0][n];
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;

//clang++ -std=c++11 -stdlib=libc++ 
int main() {
  int N;cin>>N;
  string s; cin>>s;
  int ans = 0;
  for (int i=0; i<N-2; i++) {
    if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(b-a==c-b)
	{
		printf("YES");
	}
	else
	{
		printf("NO");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,a[210],sum,t;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	while (1)
		{
			t = 0;
			for (int i = 1; i <= n; i++)
				{
					if (a[i] % 2 == 0)
						{
							a[i] /= 2;
						}
						else
							{
								t = 1;
								break;
							}
				}
			if (t == 1) break;
			sum++;	
		}	
	cout << sum <<endl;				
	return 0;	
 } 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int A, B, C, D;
bool turn = true;
int main() {
  cin >> A >> B >> C >> D;
  while (A > 0 && C > 0) {
    if (turn) {
      C -= B;
      turn = false;
    } else {
      A -= D;
      turn = true;
    }
  }
  if (A > C) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
// -*- coding:utf-8-unix -*-

use proconio::{fastout, input};
use std::collections::VecDeque;

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        ch: usize,
        cw: usize,
        dh: usize,
        dw: usize,
        s_lines: [String; h],
    }
    let mut is_road: Vec<Vec<bool>> = Vec::new();
    for i in 1..=h {
        let si: Vec<_> = s_lines[i - 1]
            .as_bytes()
            .iter()
            .cloned()
            .map(|b| b == b'.')
            .collect();
        is_road.push(si);
    }
    let mut message_queue: VecDeque<(usize, usize, u64)> = VecDeque::new();
    message_queue.push_back((ch, cw, 0));
    let mut minimum_warping: Vec<Vec<u64>> = vec![vec![10000000; w]; h];
    while let Some((ph, pw, k)) = message_queue.pop_front() {
        for i in -2..=2 {
            let phi = ph as isize + i;
            if phi <= 0 || phi > h as isize {
                continue;
            }
            let phi = phi as usize;
            for j in -2..=2 {
                let pwj = pw as isize + j;
                if pwj <= 0 || pwj > w as isize {
                    continue;
                }
                let pwj = pwj as usize;
                if !is_road[phi - 1][pwj - 1] {
                    continue;
                }
                let mhtn = i.abs() + j.abs();
                if mhtn == 0 {
                    continue;
                }
                if mhtn == 1 {
                    if minimum_warping[phi - 1][pwj - 1] > k {
                        minimum_warping[phi - 1][pwj - 1] = k;
                        message_queue.push_front((phi, pwj, k));
                    }
                } else {
                    if minimum_warping[phi - 1][pwj - 1] > k + 1 {
                        minimum_warping[phi - 1][pwj - 1] = k + 1;
                        message_queue.push_back((phi, pwj, k + 1));
                    }
                }
            }
        }
    }
    if minimum_warping[dh - 1][dw - 1] > 1000000 {
        println!("-1");
    } else {
        println!("{}", minimum_warping[dh - 1][dw - 1]);
    }
}


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

int main(){
  int N;
  cin >> N;
  vector<long long> A(N), sumA(N+1, 0);
  long long mod_ = 1000000007;
  for (int i=0; i<N; i++){
    cin >> A.at(i);
    sumA.at(i+1) = sumA.at(i)+A.at(i);
    if (sumA.at(i+1) >= mod_) sumA.at(i+1) %= mod_;
  }
  
  long long ans = 0;
  long long sum_comp = 0;
  for (int i=0; i<N-1; i++){
    sum_comp = sumA.at(N) > sumA.at(i+1) ? sumA.at(N)-sumA.at(i+1) : sumA.at(N)+mod_-sumA.at(i+1);
    ans += A.at(i)*sum_comp;
    if (ans >= mod_) ans %= mod_;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 6408
#include<stdio.h>
int a,b,c,d,e;
int main(void){
    scanf("%d%d",&a,&b);
c = a+b;
d = a-b;
e = a*b;
if(c>=d&&c>=e){
    printf("%d",c);
}else if(d>=c&&d>=e){
    printf("%d",d);
}else{
    printf("%d",e);
}
return 0;
}

Measured memory_bytes: 128
S=input()
L=len(S)

total=0
for i in range(2**(L-1)):
    formula=S
    for b in range(L-1):
        if i&2**b!=0:
            formula=formula[:L-b-1]+'+'+formula[L-b-1:]
    ans=eval(formula)
    total+=ans
print(total)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    string s;
    cin >> s;
    int n=s.length();
    s.push_back('B');
    vector<int> L,R;
    vector<int> ans(n,0);
    vector<int> c;
    int r = 1; int l = 0;

    rep(i,n) {
        if (s[i]=='R' && s[i+1]=='L') c.push_back(i);
    }

    rep(i,n) {
        if (s[i]!=s[i+1]) {
            if (s[i]!='R') {
                r++;
                if (l) L.push_back(l);
                l=0;
            }
            else {
                l++;
                if (r) R.push_back(r);
                r=0;
            }
        }
        else {
            if (s[i]=='R') r++;
            else l++;
        }
    }

    /*
    rep(i,R.size()) {
        cout << R[i] << " ";
    }
    cout << endl;
    rep(i,L.size()) cout << L[i] << " ";
    cout << endl;
    */

    rep(i,R.size()) {
        if ((R[i]+L[i])%2==0) {
            ans[c[i]]=ans[c[i]+1]=(R[i]+L[i])/2;
        }
        else {
            ll sum=R[i]+L[i];
            if (R[i]>L[i]) {
                if (max(R[i],L[i])%2==1) ans[c[i]]=sum/2+1, ans[c[i]+1]=sum/2;
                else ans[c[i]]=sum/2, ans[c[i]+1]=sum/2+1;
            }
            else {
                if (max(R[i],L[i])%2==1) ans[c[i]]=sum/2, ans[c[i]+1]=sum/2+1;
                else ans[c[i]]=sum/2+1, ans[c[i]+1]=sum/2;
            }
        }
    }

    rep(i,ans.size()) {
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1724
#include<stdio.h>

int main(void){

	int num;
	int box;
	int sum = 0;
	int max;
	int i;

	while(scanf("%d",&num) != EOF){

		for(i = 0; i < num; i++){


			scanf("%d",&box);

			if(i == 0){
				max = box;
			}

			else{

			if(max <= box){

				sum += max;
				max = box;
			}
			else{
				sum += box;
				}			
			}
		}
		if(max < sum) printf("Yes\n");
		else          printf("No\n");


	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;
// C以降はintじゃなくてllを使え
// これかな？は確証なくても5分で考えられなさそうなら出せ
// 極端なテストケースも試せ
int main(){
    ll K;
    cin >> K;
    if(K%2==0 || K%5==0) cout << -1;
    else{
        ll ans=1;
        ll a=7;
        while(1){
          	ll c=a%K;
          	if(c==0) break;
            a=c*10+7;
            ans++;
        }
        cout << ans;
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> board(50);
    for (int i=0; i<H; i++) cin >> board[i];
    const int dx[8] = {1,0,-1,0,1,-1,-1,1};
    const int dy[8] = {0,1,0,-1,1,1,-1,-1};

    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            if (board[i][j]=='#') continue;

            int num=0;
            for (int k=0; k<8; k++) {
                const int ni=i+dy[k];
                const int nj=j+dx[k];

                if (nj<0 || H<=ni) continue;
                if (ni<0 || W<=nj) continue;
                if (board[ni][nj]=='#') num++;
            }
            board[i][j] = char(num+'0');
        }
    }
    for (int i=0; i<H; i++) cout << board[i] << endl;
} 



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = (1ll<<31)-1;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n),b(n),c(n),d(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    ll ans = 0;
    rep(i,29){
        ll t = (1<<i);
        rep(i,n) c[i] = a[i]%(t*2);
        rep(i,n) d[i] = b[i]%(t*2);
        SORT(d);
        ll cnt = 0;
        rep(j,n){
            cnt += (lower_bound(all(d),2*t-c[j])-lower_bound(all(d),t-c[j]))+(lower_bound(all(d),4*t-c[j])-lower_bound(all(d),3*t-c[j]));
        }
        if (cnt%2) ans += t;
    }
    PRINT(ans);
}


Measured memory_bytes: 6528
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        var coin = new List<int>() { 500, 100, 50, 10, 5, 1 };
        while (true)
        {
            var r = 1000 - int.Parse(Console.ReadLine().Trim());
            if (r == 1000) break;
            var coincount = 0;
            foreach (var x in coin)
            {
                coincount += r / x;
                r -= r / x * x;
            }
            Console.WriteLine(coincount);
        }
    }
}

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

void answer1() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> l(N);
  for (auto& l_i: l) {
    cin >> l_i;
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      for (int k = j + 1; k < N; k++) {
        if (l[i] < l[j] + l[k] && l[j] < l[k] + l[i] && l[k] < l[i] + l[j]) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

void answer2() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> l(N);
  for (auto& l_i: l) {
    cin >> l_i;
  }
  sort(l.begin(), l.end());
  int count = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      //
      int target = l[i] + l[j];
      // target以上値を探す
      auto itr = lower_bound(l.begin() + j + 1, l.end(), target);


      count += itr - (l.begin() + j + 1);
    }
  }
  cout << count << endl;
}

int main() {
  //answer1(); // 実行時間制限超過
  answer2();
}


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

string solve() {
  string S, T;
  cin >> S >> T;
  map<char, char> mp, mp2;
  rep(i, S.size()) {
    char s = S[i];
    char t = T[i];
    if (!mp[t])
      mp[t] = s;
    else {
      if (mp[t] != s)
        return "No";
    }
    if (!mp2[s])
      mp2[s] = t;
    else {
      if (mp2[s] != t)
        return "No";
    }
  }
  return "Yes";
}

int main() {
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
const ll mod = 1000000007;

int main(){
  /*
  ifstream in("hand_01.txt");
  cin.rdbuf(in.rdbuf());
  */

  int N, K; cin >> N >> K;
  vector<ll> A(N); rep(i,N) cin >> A[i];
  ll ans = 1;
  if(N==K){
    rep(i,N) {ans *= ((A[i]+mod)%mod); ans %= mod;}
    cout << ans << endl;
    return 0;
  }
  int noz=0; int z=0;
  int ppp = 0; int mmm = 0;
  rep(i,N) {
    if(A[i]!=0) noz++;
    if(A[i]==0) z++;
    if(A[i]>0) ppp++;
    if(A[i]<0) mmm++;
  }
  if(noz < K){
    cout << 0 << endl;
    return 0;
  }
  if(z && noz==K && mmm%2==1){
    cout << 0 << endl;
    return 0;
  }
  if(z && ppp==0 && K%2==1){
    cout << 0 << endl;
    return 0;
  }


  vector<ll> B;
  rep(i,N) if(A[i]!=0) B.pb(A[i]);
  N = sz(B);
  vector<ll> pls,mns;
  rep(i,N) {
    if(B[i]>0) pls.pb(B[i]);
    else mns.pb(B[i]);
  }

  if(ppp==0&&K%2==1){
    sort(rall(mns));
    rep(i,K){
      ans *= (mns[i]+mod)%mod;
      ans %= mod;
    }
    cout << ans << endl;
    return 0;
  }


  sort(rall(pls));
  sort(all(mns));
  pls.pb(0);
  pls.pb(0);
  mns.pb(0);
  mns.pb(0);
  mns.pb(0);
  int idp=0,idm=0;
  rep(i,K){
    if(pls[idp]!=0 && pls[idp]*pls[idp+1]>=mns[idm]*mns[idm+1] || i==K-1){
      ans *= pls[idp];
      ans %= mod;
      idp++;
    }
    else{
      ans *= (mns[idm]*mns[idm+1]%mod);
      ans %= mod;
      idm += 2;
      i++;
    }
  }



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


Measured memory_bytes: 9380
A,B = (int(i) for i  in input().split())
from math import sqrt
from fractions import gcd
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
divisors = make_divisors(gcd(A,B))
def is_prime(n):
    if n == 1: return True
    for k in range(2, int(sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True
ans = 0
for d in divisors:
    ans += is_prime(d)
print(ans)

Measured memory_bytes: 5328
#include <iostream>

using namespace std;

int main(){

  


  int n,a;
  bool x = false;

  cin >> n;
  cin >> a;

  // cout << x <<endl;
  // cout << a <<endl;
  // cout << b <<endl;
  int p = n % 500;
  if (p <= a)
    x=true;
  
  if (x){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int x;
	
	scanf("%d", &x);
	
	if ( x >= 1 && x <= 3000 )
	{
		if ( x < 1200)
		{
			printf("ABC");
		}else{
			printf("ARC");
		}
	}
	return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 3223372036854775807
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
//#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
#define lg length()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invp(a,p)pom(a,p-2,p)
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<Pll,ll> a,pair<Pll,ll> b){
        return a.fi.se>b.fi.se;
}
ll cmp2(pair<ll,ll> a,pair<ll,ll> b){
    if(a.se!=b.se)
        return a.se<b.se;
    else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(int argc, char * argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("big.txt", "r", stdin);
    //freopen("out3.txt", "w", stdout);
    //------------------------------
    ll n;cin>>n;
    V<ll>a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    ll ans=0;
    ll maxh=a[0];
    for(ll i=1;i<n;i++){
        if(a[i]<maxh){
            ans+=maxh-a[i];
        }
        chmax(maxh,a[i]);
    }
    cout<<ans<<endl;
    //------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //------------------------------- 
    return 0;
}
//----------------------------------------------------------------------












































Measured memory_bytes: 4776
N = int(input())

a = [list(map(str, input().split())) for _ in range(N)]
lst = []

for i, (x, y) in enumerate(a):
    lst.append([i + 1, x, int(y)])

lst.sort(key=lambda x:(x[1], -x[2]))
for i, x, y in lst:
    print(i)

Measured memory_bytes: 3060
// IN THE NAME OF RIGHT
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,sum,cnt;
ll a[100+10];
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	sum=(sum+(4*m)-1)/(4*m);
	for(int i=0;i<n;i++){
		if(a[i]>=sum){
			cnt++;
		}
	}
	if(cnt>=m){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K,Q;
int A[2020];
int mi=1<<30;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K>>Q;
	FOR(i,N) cin>>A[i];
	
	FOR(i,N) {
		vector<int> P;
		vector<int> V;
		FOR(j,N) {
			if(A[j]<A[i]) {
				if(V.size()>=K) {
					sort(ALL(V));
					FOR(x,V.size()-K+1) P.push_back(V[x]);
				}
				V.clear();
			}
			else {
				V.push_back(A[j]);
			}
		}
		if(V.size()>=K) {
			sort(ALL(V));
			FOR(x,V.size()-K+1) P.push_back(V[x]);
		}
		if(P.size()<Q) continue;
		sort(ALL(P));
		mi=min(mi,P[Q-1]-P[0]);
	}
	cout<<mi<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int main() {
  map<string, int> dict;
  int n;
  cin >> n;
  for(string x; n--; dict[x]++) cin >> x;
  cout << dict.size() << endl;
}


Measured memory_bytes: 19128
n, m = map(int, input().split())
list_a = []
list_b = []
for a in range(n):
    str = input()
    list_a.append(str)
    
for b in range(m):
    str = input()
    list_b.append(str)

list_Count = []
answer = "No"
for j in range(n - m + 1):
    #1行目を探す
    for i in range(n - m + 1):
        if m == 1 and list_a[j][i:m+i] == list_b[0]: answer = "Yes"
        elif list_a[j][i:m+i] == list_b[0]: 
            list_Count.append([i, j])

for id in range(len(list_Count)):
    for x in range(m - 1):
        if list_a[list_Count[id][1] + x + 1][list_Count[id][0] : m+ list_Count[id][0]] != list_b[x + 1]: break
        elif x + 1 ==  m - 1: answer = "Yes"

print(answer)




Measured memory_bytes: 3064