akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

const ll MOD = 1000000007;
const int SIZE = 100;
ll inv[SIZE],fac[SIZE],finv[SIZE];
void make(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<SIZE;i++){
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		fac[i]=fac[i-1]*(ll) i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
ll C (int a,int b) {
	if(a<b) return 0;
	return fac[a]*(finv[b]*finv[a-b]%MOD)%MOD;
}
int main(){
  int N, P;
  cin>>N>>P;
  int A[N];
  make();
  FOR(i,0,N) cin >> A[i];
  int odd = 0, even = 0;
  FOR(i,0,N){
    if(A[i]%2==0) even++;
    else odd++;
  }
  ll ans = 0;
  if(P==0){
    ans = pow(2, even);
    int x = 0, times = 0;
    while(x <= odd){
      times += C(odd, x);
      x += 2;
    }
    ans *= times;
  } else {
    ans = pow(2, even);
    int x = 1, times = 0;
    while(x <= odd){
      times += C(odd, x);
      x += 2;
    }
    ans *= times;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, raw_input().split())
s = [0]*M
c = [0]*M
for i in range(M):
  s[i], c[i] = map(int, raw_input().split())
  s[i] -= 1

for i in range(0 if N==1 else 10**(N-1), 10**N):
  i = str(i)
  ok = True
  for j in range(M):
    if i[s[j]]!=str(c[j]):
      ok = False
  if ok:
    print i
    exit(0)
print -1


Measured memory_bytes: 2692
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef struct P{  
  int x,y,c;
  P(){}
  P(int x,int y,int c):x(x),y(y),c(c){}
};
int dx[12]={-1,0,1,2,2,2,1,0,-1,-2,-2,-2};
int dy[12]={-2,-2,-2,-1,0,1,2,2,2,1,0,-1};
int sx[9]={-1,0,1,-1,0,1,-1,0,1};
int sy[9]={-1,-1,-1,0,0,0,1,1,1};
bool sp[15][15][15];
bool used[15][15][15];
int n;
int xs,ys;
int main(void){
  while(1){
    scanf("%d %d",&xs,&ys);
    if(!xs && !ys) break;
    memset(sp,false,sizeof(sp));
    scanf("%d",&n);
    for(int i=0;i<n;i++){
      int tx,ty;
      scanf("%d %d",&tx,&ty);
      for(int j=0;j<9;j++){
	int nx=tx+sx[j];
	int ny=ty+sy[j];
	if(0<nx && nx<10 && 0<=ny && ny<10) sp[i][nx][ny]=true;
      }
    }

    memset(used,true,sizeof(used));
    bool f=false;
    queue<P> que;
    que.push(P(xs,ys,0));
    while(!que.empty()){
      P p=que.front();
      que.pop();
      if(p.c>=n){
	f=true;
	break;
      }
      for(int i=0;i<12;i++){
	int nx=p.x+dx[i];
	int ny=p.y+dy[i];
	if(0<=nx && nx<10 && 0<=ny && ny<10){
	  if(sp[p.c][nx][ny] && used[p.c][nx][ny]){
	    used[p.c][nx][ny]=false;
	    que.push(P(nx,ny,p.c+1));
	  }
	} 
      }
    }
    if(f) puts("OK");
    else puts("NA");
  }
}

Measured memory_bytes: 0
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Set<String> set = new HashSet<>();
		char end = '0';
		for(int i = 0; i < n; i++) {
			String s = sc.next();
			if(i != 0) {
				if(end != s.charAt(0)
						|| set.contains(s)) {
					System.out.println("No");
					return;
				}
			}
			end = s.charAt(s.length()-1);
			set.add(s);
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const string YES = "YES";
const string NO = "NO";

void solve(long long N, std::vector<long long> A){
    map<ll, ll> mp;
    string ans = YES;
    for(auto a : A) mp[a]++;
    for(auto itr = mp.begin(); itr != mp.end(); itr++){
        if(itr->second > 1){
            ans = NO;
            break;
        }
    }
    cout << ans << endl;
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 17148
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

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

    vec<ll> A(N);
    rep(i, N) cin >> A[i];

    ll ans = 1000;
    ll kabu = 0;
    rep(i,N-1){
        ans+=kabu*A[i];
        kabu = 0;
        if(A[i]<A[i+1]){
            kabu=ans/A[i];
            ans-=kabu*A[i];
        }
    }

    cout << ans + kabu*A[N-1] << endl;
}


Measured memory_bytes: 3624
import sys

readline = sys.stdin.readline

def flatten_2dim(array):
    return [item for sublist in array for item in sublist]

def main():
    N, M = map(int, readline().split())
    number = [[] for _ in range(N)]
    for i in range(M):
        p, y = map(int, readline().split())
        p -= 1
        number[p].append([p+1, y, i])
    for pnumber in number:
        if len(pnumber)==0:
            continue
        pnumber.sort(key=lambda x: x[1])
        pbase = str(pnumber[0][0])
        numleft = '0'*(6-len(pbase)) + pbase
        cnt = 1
        for tmp in pnumber:
            numbase = str(cnt)
            numright = '0'*(6-len(numbase)) + numbase
            base = numleft+numright
            tmp.append(base)
            cnt += 1
    fnumber = flatten_2dim(number)
    fnumber.sort(key=lambda x: x[2])

    for tmp in fnumber:
        print(tmp[3])

if __name__ == "__main__":
    main()


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

int times10(int n) {
	int output = 1;
	for (int i = 0; i < n; i++) {
		output *= 10;
	}
	return output;
}

int main() {
	//enter
	int N, M;
	cin >> N >> M;

	vector<int> s(M);
	vector<int> c(M);
	for (int i = 0; i < M; i++) {
		cin >> s[i] >> c[i];
		s[i]--;
	}

	vector<int> output(N, -1);

	//program
	if (M == 0) {
		if (N == 1) {
			cout << 0 << endl;
			return 0;
		} else if (N == 2) {
			cout << 10 << endl;
			return 0;
		} else {
			cout << 100 << endl;
			return 0;
		}
	}

	for (int i = 0; i < M; i++) {
		if (N > 1 && s[i] == 0 && c[i] == 0) {
			cout << -1 << endl;
			return 0;
		}

		if (output[s[i]] == -1) {
			output[s[i]] = c[i];
		} else if (output[s[i]] == c[i]) {
			continue;
		} else {
			cout << -1 << endl;
			return 0;
		}
	}

	int num;
	if (output[0] == -1) {
		if (N == 0) {
			num = 0;
		} else {
			num = times10(N - 1);
		}
	} else {
		num = times10(N - 1) * output[0];
	}

	for (int i = 1; i < N; i++) {
		if (output[i] != -1) {
			num += times10(N - 1 - i) * output[i];
		}
	}

	cout << num << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		for (long i = 0; i <= n; i++) {
			long x = i*(i+1)/2;
			long y = (i+1)*(i+2)/2;
			if (x < n && n <= y) {
				System.out.println(i+1);
				return;
			}
		}
	}
}


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

int main() {
  int n;
  cin >> n;
  int x[n];
  bool p[2100] = {false};
  map<int, int> x_map;
  int i;
  for (i = 0; i < n; i++) {
    cin >> x[i];
    p[x[i]] = true;
    x_map[i + 1] = x[i];
  }
  int m;
  cin >> m;
  int a[m];
  for (i = 0; i < m; i++) {
    cin >> a[i];
  }
  for (i = 0; i < m; i++) {
    if (p[x_map[a[i]] + 1] == false && x_map[a[i]] != 2019) {
      p[x_map[a[i]] + 1] = true;
      p[x_map[a[i]]] = false;
      x_map[a[i]]++;
    }
  }
  for (i = 0; i < 2020; i++) {
    if (p[i]) {
      cout << i << endl;
    }
  }
  return 0;
}



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

double PI2 = acos(-1) * 2;
double normal(double a){
    while(a >= PI2) a -= PI2;
    while(a < 0) a += PI2;
    return a;
}

int main() {
    int N;
    int X[9], Y[9];
    cin >> N;
    for(int i=0; i<N; i++) cin >> X[i] >> Y[i];
    X[N] = Y[N] = 0;

    double ans = 1e18;
    vector<int> order(N+1);
    for(int i=0; i<=N; i++) order[i] = i;

    do{
        double res = 0;
        int x = 0, y = 0;
        double ang = 0;
        for(int i : order){
            double a = atan2(Y[i]-y, X[i]-x);
            res += min(normal(a-ang), normal(ang-a));
            x = X[i];
            y = Y[i];
            ang = a;
        }
        ans = min(ans, res);
    }while(next_permutation(order.begin(), order.end()-1));
    ans *= 360 / PI2;
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
 
using namespace std;
 
 
#define mod(cans) cans%10**9+7
#define debug(x) cout << "Debug" << x << "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define cin_pl(n,x) rep(i,n){cin>>x[i];}
#define cins(s,n) rep(i,n)cin>>s.at[i];
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define prians(Answer) cout<<Answer<<"\n"
#define TF(X) X==1?cout<<"Yes\n":cout<<"No\n"
#define elcon else{continue;}
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int> > matrix;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef greater<int> gi;
typedef vector<unsigned> vu;


ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
bool is_prime(const unsigned n){
    switch(n){
        case 0:
        case 1: return false;
        case 2: return true;
    }
 
 
    for(unsigned i=2;i<n;++i){
        if(n%i == 0) return false;
    }
 
    return true;
}

int main()
{
    string s;cin>>s;
    if(s[3]==s[2]&&s[5]==s[4]) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
n = gets.to_i
smap = gets.chomp.chars

ans = 0
ansmap = []

smap.each do |s|
  if s == 'I'
    ansmap << ans + 1
    ans += 1
  else
    ansmap << ans - 1
	ans -= 1
  end
end

p ansmap.max > 0 ? ansmap.max : 0

Measured memory_bytes: 14348
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<math.h>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long
#define endl '\n'
const double INF = 1e9+5;


pair<int, int>key[1001];//bitmask,value;
int d[1001][1 << 13];
int n, m;
int go(int here, int state)
{
 	if (state == (1<<n) - 1)
		return 0;
	if (here == m)   //실수했다.
		return INF;
	
	int& ret = d[here][state];
	if (ret != -1)
		return ret;
	ret = INF;

	ret = min(ret,go(here + 1, state | key[here].first) + key[here].second);
	ret = min(ret, go(here + 1, state));
	return ret;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	//memset(d, -1, sizeof(d));
	for (int i = 0; i < 1001; i++)
		for (int j = 0; j < (1 << 13); j++)
			d[i][j] = -1;

	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;

		int total = 0;
		for (int j = 0; j < b; j++)
		{
			int ci;
			cin >> ci;
			ci--;
			total |= (1<<ci);
		}
		key[i].first = total;
		key[i].second = a;
	}
	int val= go(0, 0);
	
	if (val == INF)
		cout << -1;
	else
		cout << val;
}

 

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

int main(){
	map<char,char> mp;
	vector<char> str;
	char pr, ne;
	int n;
	while(1){
		mp.clear();
		str.clear();
		cin >> n;
		if( n == 0 )	break;
		for( int i=0; i<n; i++ ){
			cin >> pr >> ne;
			mp[pr] = ne;
		}
		cin >> n;
		for( int i=0; i<n; i++ ){
			cin >> pr;
			if( mp[pr] ){
				str.push_back(mp[pr]);
			}else{
				str.push_back(pr);
			}
		}
		for( int i=0; i<str.size(); i++ ){
			cout << str[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
// #define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
// #define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
// const ll INF = 1LL << 60;
const ll INF = 100000000000;
#define pp pair<ll, pair<ll, ll>> 
// #define fi first
// #define se second
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
 
/*--------------------------------------------------------------------------------
 
--------------------------------------------------------------------------------*/
 
 int main() {
    ll n; cin >> n;
    Vl a(n+1);
    rep(i, 0, n+1) cin >> a[i];
 
    Vl Ma(n+1, 0), mi(n+1, 0); // 最大の葉の個数、最小の葉の個数
    Ma[n] = a[n];
    mi[n] = a[n];
    for(int i = n-1; i >= 0; i--){
        Ma[i] = Ma[i+1] + a[i];
        mi[i] = (mi[i+1]+1)/2 + a[i];
    }
    if(mi[0] > 1){
        co(-1);
        return 0;
    }
    if(n == 0 && a[0] != 1){
        co(-1);
        return 0;
    }
    // rep(i, 0, n+1) cout << mi[i] << " \n"[i==n];
    // rep(i, 0, n+1) cout << Ma[i] << " \n"[i==n];
    ll e = 1;
    ll ans = 0;
    rep(i, 0, n+1){
        chmin(e, Ma[i]); // eはMa[i]を超えない
        if(e < mi[i]){ // e >= mi[i] でなければグラフを作れない
            co(-1);
            return 0;
        }
        ans += e; // mi[i] <= e <= Ma[i];
        e -= a[i];
        e *= 2;
    }
    co(ans);

    return 0;
}

Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll mod=1e9+7;
ll inv(ll a){
    ll n=mod-2,ans=1;
    while(n>0){
        if(n&1) ans=ans*a%mod;
        n=n/2;
        a=a*a%mod;
    }
    return ans;
}
ll A[200001];
void init(){
    A[0]=1;
    rep(i,200000) A[i+1]=A[i]*(i+1)%mod;
}
ll nCk(ll n,ll k){
    ll ans=1;
    rep(i,k){
        ans=ans*(n-i)%mod;
    }
    rep(i,k){
        ans=ans*inv(i+1)%mod;
    }
    return ans;
}
ll pow_(ll n,ll k){
    ll ans=1;
    while(k>0){
        if(k&1) ans=ans*n%mod;
        k=k/2;
        n=n*n%mod;
    }
    return ans;
}
int n,a,b;
int main(){
    init();
    cin>>n>>a>>b;
    cout<<(pow_(2,n)-1-nCk(n,a)-nCk(n,b)+3*mod)%mod<<"\n";
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main () {
        int n, x, cnt = 0;
        cin >> n;
        for (int i = 1; i <= n; i++) {
                cin >> x;
                if (x % 2 == 1) cnt++;
        }
        if (cnt % 2 == 0) {
                cout << "YES" << endl;
        } else {
                cout << "NO" << endl;
        }
        return 0;
}


Measured memory_bytes: 256
//
// Created by moono on 2018/10/27.
//

#include <iostream>
#include <string>
#include <unordered_map>
#include <cmath>
using namespace std;


int main() {
    int N, M;
    unordered_map<string, int> map;
    string card;

    //

    //
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> card;
        if(map.find(card) == map.end())
            map[card] = 1;
        else
            map[card] = map[card] + 1;
    }

    //
    cin >> M;
    for (int i = 0; i < M; ++i) {
        cin >> card;
        if(map.find(card) != map.end())
            map[card] = map[card] - 1;
    }

    //
    int max_i = 0;
    for(auto item: map){
        int i = item.second;
        if(i > max_i) max_i = i;
    }


    cout << max_i << endl;

    return 0;
}

Measured memory_bytes: 384
package main

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

var sc *bufio.Scanner

const bufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, bufferSize)
	sc.Buffer(buf, 1e+7)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	x := nextInt() - 1
	y := nextInt() - 1
	ans := make([]int, n-1)
	debugf("n: %d, x: %d, y: %d\n", n, x, y)

	for i := 0; i < n-1; i++ {
		for j := i + 1; j < n; j++ {
			d := min(j-i, abs(x-i)+abs(y-j)+1, abs(x-j)+abs(y-i)+1)
			ans[d-1]++
		}
	}

	for i := range ans {
		_, _ = fmt.Fprintf(writer, "%d", ans[i])
		if i != len(ans)-1 {
			_, _ = fmt.Fprint(writer, "\n")
		}
	}
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    b = a;
    sort(b.begin(), b.end());
    for (int i = 0; i < n; i++) {
        if (a[i] == b[n - 1]) cout << b[n - 2] << endl;
        else cout << b[n - 1] << endl;
    }
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define f(i,l,h) for(ll i=l;i<h;i++)
#define fr(i,h,l) for(ll i=h;i>=l;i--)

using namespace std;

typedef pair<ll,ll> pll;
const ll INF=(ll)(1e9+7);
typedef vector<ll> vll;

int main()
{
    //cout << "Hello world!" << endl;
    ll n;
    cin>>n;
    ll a[n+1];
    f(i,0,n+1) cin>>a[i];
    if(n==0){
        if(a[0]==1) cout<<"1"<<endl;
        else cout<<"-1"<<endl;
        return 0;
    }
    ll leaf[n+1];
    leaf[n]=a[n];
    for(ll i=n-1;i>=0;i--){
        leaf[i]=a[i]+leaf[i+1];
    }
    ll ans=1;
    bool flag=true;
    ll lvl[n+1];
    lvl[0]=1;
    for(ll i=1;i<=n;i++){
        lvl[i]=min(2*(lvl[i-1] - a[i-1]),leaf[i]);
        if(lvl[i]<a[i]){
            flag=false;
            break;
        }
        ans+=lvl[i];
    }

    if(!flag){
        ans=-1;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 5964
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_map>

using namespace std;



int main() {
	ios::sync_with_stdio(false);

	int n, m;
	cin >> n >> m;

	unordered_map<int, int> ump;

	int cnt = 0;
	long long ans = 0;
	int sum = 0;

	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		
		sum = (sum + x) % m;

		ans += ump[sum] + (sum == 0);
		++ump[sum];
	}

	cout << ans;

	//system("pause");
	return 0;
}

Measured memory_bytes: 3724
t = list(map(int, list(input())))
t.append(7)
op = []

def dfs(x, i):
    if i == 4 or len(op) == 3:
        if x == 7:
            op.append('=')
            ans = ''
            for j in range(5):
                if j == 4:
                    ans += str(t[j])
                else:
                    ans += str(t[j]) + op[j]
            print(ans)
            exit()
        return

    i += 1
    op.append('+')
    dfs(x + t[i], i)
    op.pop()

    op.append('-')
    dfs(x - t[i], i)
    op.pop()
    i -= 1
    return

dfs(t[0], 0)


Measured memory_bytes: 3064
import math
n,m = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
cnt,tmp = 0,0
for i in range(n-1):
	for j in range(i+1,n):
		tmp = 0
		for M in range(m):
			tmp += (x[i][M] - x[j][M])**2
			#print(tmp)
		if math.sqrt(tmp).is_integer():
			cnt += 1
print(cnt)

Measured memory_bytes: 9148
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


A, B, N = lmi()
# (A*(x%B) - (A*x)%B )/B

# if N < B:
#     ans = -INF
#     for i in range(1, N + 1):
#         ans = max(ans, (A * (i % B) - (A * i) % B) // B)
#     print(ans)
#     exit()
#
i = min(B - 1,N)
print((A * (i % B) - (A * i) % B) // B)


Measured memory_bytes: 9464
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        var n = long.Parse(Console.ReadLine().Trim());
        getAns(n);
    }
    static void getAns(long n)
    {
        var ans = long.MaxValue;
        for (long i = 1; i * i <= n; i++)
            if (n % i == 0) ans = Min(i + n / i - 2, ans);
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11092
#include "bits/stdc++.h"
using namespace std;
using ll=long long;

const int MOD=1e9+7;

const int MAX_N=1e5;

ll dp[MAX_N][2];
string L;

ll rec(int k=0,bool tight=true){
   if(k==L.length()) return 1;
   
   if(dp[k][tight]!=-1) return dp[k][tight];
   else dp[k][tight]=0;

   if(tight){
      if(L[k]=='1'){
         dp[k][tight]+=2*rec(k+1,true);
         dp[k][tight]+=rec(k+1,false);
      }else{
         dp[k][tight]+=rec(k+1,true);
      }
   }else{
      dp[k][tight]+=3*rec(k+1,false);
   }

   return dp[k][tight]%=MOD;
}

int main(){
   cin>>L;
   for(int i=0;i<L.length();++i) for(int j=0;j<2;++j) dp[i][j]=-1;
   
   ll ans=rec();
   ans%=MOD;
   cout<<ans<<endl;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
#include <unordered_map>
#define mem(ara, a) memset(ara, a, sizeof(ara))
#define fo freopen("output.txt", "w", stdout)
#define fi freopen("bruh.txt", "r", stdin)
#define int long long
#define sp " "
#define pb push_back
#define ff first
#define sz(x) x.size();
#define len(x) x.length();
#define ss second
#define vi vector<int>
#define double long double
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define pii pair<int, int>


long long inf = 2e18;
long long minf = -inf;
int ans = 0;
using namespace std;

signed main() {
int a,b;
cin>>a;
b=a%2;
if (b==0){
    cout << a/2 << endl;
}
else if (b!=0){
    cout << b+(a/2) <<endl;
}
}


Measured memory_bytes: 256
// 入力マクロ
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::max;

fn main() {
    input! {
        n: usize, k: usize,
        h: [i64; n],
    }

    let mut dp: Vec<_> = vec![std::i64::MAX; n].into_iter().collect();
    dp[0] = 0;

    for i in 1..n {
        dp[i] = ((max(i as i64 - k as i64, 0) as usize)..i)
            .map(|x| dp[x] + (h[i] - h[x]).abs())
            .min()
            .unwrap() as i64;
    }

    println!("{}", dp[n - 1]);
}


Measured memory_bytes: 6396
N,M= map(int,input().split())
gate=[list(map(int,input().split())) for i in range(M)]
count2=0

min1=1
max1=N

for j in gate:
  if j[0]>min1:
    min1=j[0]
  if j[1]<max1:
    max1=j[1]
if max1>=min1:
  print(max1-min1+1)
else:
  print(0)

Measured memory_bytes: 59992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

ll n, m, num;
vector<ll> t, h;

int main(){
	while (cin >> n >> m&&n + m){
		t.clear(); h.clear();
		ll tsum = 0, hsum = 0;
		ll MIN = INF;
		bool f = 0;
		REP(i, n){
			cin >> num;
			t.push_back(num);
			tsum += num;
		}
		REP(i, m){
			cin >> num;
			h.push_back(num);
			hsum += num;
			if (find(ALL(t), num) != t.end()){
				MIN = min(MIN, num);
				f = 1;
			}
		}

		if (f&&hsum == tsum){
			cout << MIN << " " << MIN << endl;
			continue;
		}

		P ans;
		MIN = INF;
		f = 0;
		REP(i, n){
			REP(j, m){
				if (tsum - t[i] + h[j] == hsum - h[j] + t[i]){
					if (t[i] + h[j] < MIN){
						ans = P(t[i], h[j]);
						MIN = t[i] + h[j];
						f = 1;
					}
				}
			}
		}
		if (!f)cout << -1 << endl;
		else cout << ans.first << " " << ans.second << endl;
	}
}

Measured memory_bytes: 1224
/**
 * Created by hiramekun at 20:53 on 2020-04-26.
 */
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define each(i, mp) for(auto& i:mp)

int main() {
    string s;
    cin >> s;
    unordered_map<ll, ll> mp;
    mp[0] = 1;
    reverse(s.begin(), s.end());
    ll now = 0, ten = 1;
    each(e, s) {
        now = (now + (e - '0') * ten) % 2019;
        ten *= 10;
        ten %= 2019;
        mp[now]++;
    }
    ll ans = 0;
    each(e, mp) {
        ans += e.second * (e.second - 1) / 2;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3696
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI(A);
  char c;
  cin >> c;
  GI(B);
  if (c == '+') {
    print(A + B);
  } else {
    print(A - B);
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#define MAX 1e9
using namespace std;


int main()
{
int N;
cin>>N;
int A[N];
int B[N];
int min=MAX;
for(int i=0;i<N;i++){
  cin>>A[i];
  if(min>A[i])min=A[i];
};
int min1=0;
while(1){
  min1=min;
for(int i=0;i<N;i++){

  B[i]=A[i]%min;
  if(B[i]>0){if(min>B[i])min=B[i];}
  }
if(min1==min){
  cout<<min<<endl;
  break;
}
}
return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
namespace ITP1_2_B
{
    class MainClass
    {

        public static List<string[]> getinputdata (){

            List<string[]> list_temp = new List<string[]>();
            string strdata = Console.ReadLine ();

            while (strdata!=null) {

                string[] s_temp = strdata.Split (' ');

                list_temp.Add (s_temp);

                strdata = Console.ReadLine ();

            }

            return list_temp;
        }



        public static void Main (string[] args)
        {
            List<string[]> arr_result = new List<string[]>();
            arr_result = getinputdata ();
        
            int a = int.Parse(arr_result[0][0]);
            int b = int.Parse(arr_result[0][1]);
            int c = int.Parse(arr_result[0][2]);

            if (a < b && b < c)
            {
                Console.WriteLine("Yes");   
            }
            else
            {

                Console.WriteLine("No");
            }

        }
    }
}

Measured memory_bytes: 9044
n = int(input())
d = list(map(int,input().split()))

from collections import Counter
q=Counter(d)

ans = 1
if q[0]!=1 or d[0]!=0:
    print(0)
    exit()
d.sort()
for i in range(1,max(d)+1):
  ans *= q[i-1]**q[i]
  if ans == 0:
    break
print(ans%998244353)

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

int main()
{
	vector<int> a;
	for(int i = 0; i < 3; i++){
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	sort(a.begin(), a.end());
	cout << a[2] - a[0] << "\n";

	return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  string s, t;
  cin >> s >> t;
  ll ans = 0;
  REP(i, s.size()) {
    if (s[i] != t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 3844
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """

    def __init__(self, n_max, mod=10 ** 9 + 7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n + 1):
            fac.append(fac[i - 1] * i % self.mod)
            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n + 1)
        modinv[1] = 1
        for i in range(2, n + 1):
            modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
        return modinv


def main():
    N, K = map(int, input().split())
    comb = Combination(n_max=10 ** 5 * 4 + 10)

    if N <= K:
        ans = comb(2 * N - 1, N)
    else:
        if K == 1:
            ans = comb(N, 1) * comb(N - 1, 1)
        else:
            ans = 0
            # mはゼロとなる数
            for m in range(K + 1):
                ans += comb(N, m) * comb(N - 1, m)
                ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 50608
eval"N,*A,M=#{`tr ' 
' ,`}2**64-1"
C=[0,N].map{|z|y,*a=A[z,N]*3
a.map{y^y=_1}}
e,f=C.map{|z|z[b=0,N].map{b=b*9+_1&M}
b}
q=1-9**N&M
N.times{|i|e==f&&p(i,A[i]^A[N])
e=e*9+C[0][i]*q&M}

Measured memory_bytes: 64744
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

    cout << fixed << setprecision(6) << 3.1415926535 * 2 * n << "\n";
    return 0;
}

Measured memory_bytes: 3804
def main():

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

    min_v = float('inf')
    ans = 0
    for i in range(N):
        if p[i] <= min_v:
            ans += 1
        min_v  = min(min_v, p[i])
    return ans

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 75472
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String s = sc.next();
        int n = s.length();
        char[] num = {'0', '1'};
        int cnt1 = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) != num[i % 2]) {
                cnt1++;
            }
        }
        int cnt2 = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) != num[(i + 1) % 2]) {
                cnt2++;
            }
        }
        int ans = Math.min(cnt1, cnt2);
        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21712
# -*- coding: utf-8 -*-
year = input().split("/")
# print(year)
year[0] = 2018
year = map(str, year)
# joinを使うときはstrに変換しなければならない
# 便利なjoinですが、注意点があります。
# joinでリストを連結して文字列にできるのは、
# 元のリストを構成する要素が「すべて文字列の場合」です。
year = "/".join(year)
print(year)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    cout << n*n << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
s=input()
m=0
for i in range(1,n):
    d,c=0,0
    for j in range(i,n):
        if s[j-i]==s[j]:c+=1
        else:
            d=max(c,d)
            c=0
    m=min(max(c,d,m),i)
print(m)

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

int main() {
	vector<int>a(5);
	for (int i = 0; i < 5; i++)cin >> a.at(i);
	sort(a.begin(), a.end());
	int k;
	cin >> k;
	for (int i = 0; i < 4; i++) {
		for (int j = i; j < 5; j++) {
			if (a.at(j) - a.at(i) <= k)continue;
			else {
				cout << ":(" << endl;
				return 0;
			}
		}
	}
	cout << "Yay!" << endl;
}

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n;
    string s;
    cin >> n >> s;
    int r = count(s.begin(), s.end(), 'R');
    int b = count(s.begin(), s.end(), 'B');

    string ans = r > b ? "Yes" : "No";
    cout << ans << endl;

}


Measured memory_bytes: 256
#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>

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()



int main(void) {
	ll n; cin >> n;
	ll x=0;
	ll nn = n;
	while (nn > 0) {
		x += nn % 10;
		nn /= 10;
	}
	cout << (n % x == 0 ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
MOD=10**9+7
from collections import deque
#======================================================#
def main():
    n, k = MII()
    aa = MII()
    pos = [a for a in aa if a >= 0]
    neg = [a for a in aa if a <= 0]
    len_pos = len(pos)
    len_neg = len(neg)
    if n == k:
        res = 1
        for a in aa:
            res *= a
            res %= MOD
        print(res)
    elif len_pos == 0:
        if k%2==1:
            neg.sort(reverse=True)
        else:
            neg.sort()
        res = 1
        for i in range(k):
            res *= neg[i]
            res %= MOD
        print(res)
    else:
        pos.sort(reverse=True)
        neg.sort()
        ans = 1
        if k%2 == 1:
            ans *= pos.pop(0)
            k -= 1

        nums = [e1 * e2 for e1, e2 in zip(neg[::2], neg[1::2])]
        nums += [e1 * e2 for e1, e2 in zip(pos[::2], pos[1::2])]

        nums.sort(reverse=True)
        for e in nums[:k//2]:
            ans *= e
            ans %= MOD
        print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 32284
#include<bits/stdc++.h>
using namespace std;
#define chmax(a,b) if(a<b)a=b
const int N=1e5+5;
const int M=16;

int n,ans;
int a[N],cnt[M];
bool ok[1<<M];
int dp[1<<M];

int main()
{
	
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		a[u]^=w; a[v]^=w;
	}
	for(int i=1;i<=n;i++)
		cnt[a[i]]++;
	int mask=0;
	for(int i=1;i<=15;i++)
	{
		ans+=cnt[i]>>1;
		if(cnt[i]&1) mask|=1<<i;
	}
	for(int i=0;i<=mask;i+=2)
	{
		int X=0;
		for(int j=1;j<=15;j++)
			if((i>>j)&1) X^=j;
		if(!X) ok[i]=1;
	}
	for(int i=0;i<=mask;i+=2)
	for(int j=i;j;j=(j-1)&i)
		if(ok[j]) chmax(dp[i],dp[i-j]+1);
	printf("%d\n",ans+__builtin_popcount(mask)-dp[mask]);
	
	return 0;
}

Measured memory_bytes: 896
l,r=map(int,input().split())

a=l%2019
b=r%2019

result=2018

if l+(2019-a)>l and l+(2019-a)<r:
  print(0)
else:
  if a>b:
    n=a
    a=b
    b=n
  for i in range(a,b):
    for j in range(i+1,b+1):
      if (i*j)%2019<result:
        result=(i*j)%2019
  print(result)

Measured memory_bytes: 3064
import math
s = int(input())
x1=0
y1=0
x2=0
y2=0
x3=0
y3=0
i=math.ceil(s**(1/2))
x2=i
y3=i
y2=1
x3=(i)**2-s
print(x1,y1,x2,y2,x3,y3)


Measured memory_bytes: 3188
#include <iostream>
#include <map>

#define COMP(a, b) ((a) == (b) ? (-a) : (a))

using namespace std;

int main() {
	int pre, cur, ans;
	string str;
	map<char, int> v;
	v['I'] = 1;
	v['V'] = 5;
	v['X'] = 10;
	v['L'] = 50;
	v['C'] = 100;
	v['D'] = 500;
	v['M'] = 1000;

	while (cin >> str) {
		pre = cur = ans = 0;
		for (int i = 0; i < str.size(); i++) {
			cur = v[str[i]];
			switch (cur) {
				case 1:
					ans += pre;
					break;
				case 5:
				case 10:
					ans += COMP(pre, 1);
					break;
				case 50:
				case 100:
					ans += COMP(pre, 10);
					break;
				case 500:
				case 1000:
					ans += COMP(pre, 100);
					break;
			}
			pre = cur;
		}
		ans += pre;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1180
#include <stdio.h>

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

int main(){
  int k, ans=0;
  scanf("%d", &k);
  for(int i=1; i<=k; i++){
    for(int j=1; j<=k; j++){
      for(int l=1; l<=k; l++){
        ans+=gcd(gcd(i,j),l);
      }
    }
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 1704
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		long cnt = 0;
		long r = 0;
		long g = 0;
		long b = 0;

		for(int i = 0; i < s.length(); i++) {
			if('R'==s.charAt(i)) {
				r++;
			}else if('G'==s.charAt(i)) {
				g++;
			}else if('B'==s.charAt(i)) {
				b++;
			}
		}

		long num = r * g * b;
		
		for(int i = 0; i < s.length(); i++) {
			for(int j = 0; j < s.length(); j++) {
				if( i < j
						&& 2 * j - i < s.length()  
						&& j < 2 * j - i ) {
				
					if( s.charAt(i) != s.charAt(j) 
							&& s.charAt(i) != s.charAt(2 * j - i) 
							&& s.charAt(j) != s.charAt(2 * j - i) 
						) {
						cnt++;
					}
				}
			}
		}

		System.out.println(num - cnt);
		sc.close();
	}

}

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

using namespace std;

int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    
    int n, m, k;

    cin >> n >> m >> k;

    vector<vector<int>> f(n + 1), b(n + 1);
    int x, y;

    for(int i = 0; i < m; ++i) {
        cin >> x >> y;
        f.at(x).emplace_back(y);
        f.at(y).emplace_back(x);
    }

    vector<int> cnct(n + 1);
    vector<int> nom;
    queue<int> q;
    vector<bool> visited(n + 1);
    int qf, cn = 0;

    for(int i = 1; i <= n; ++i) {
        if(!visited.at(i)) {
            q.emplace(i);
            visited.at(i) = true;
            cnct.at(i) = cn;
            nom.emplace_back(1);
            while(!q.empty()) {
                qf = q.front();
                q.pop();
                for(int qft: f.at(qf)) {
                    if(!visited.at(qft)) {
                        q.emplace(qft);
                        visited.at(qft) = true;
                        cnct.at(qft) = cn;
                        ++nom.back();
                    }
                }
            }
            ++cn;
        }
    }

    vector<int> ans(n + 1);

    for(int i = 1; i <= n; ++i) {
        ans.at(i) = nom.at(cnct.at(i)) - 1 - f.at(i).size();
    }

    for(int i = 0; i < k; ++i) {
        cin >> x >> y;
        if(cnct.at(x) == cnct.at(y)) {
            --ans.at(x);
            --ans.at(y);
        }
    }

    for(int i = 1; i < n; ++i) {
        printf("%d ", ans.at(i));
    }
    printf("%d\n", ans.at(n));


    return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	string nm="zabcdefghijklmnopqrstuvwxy";
	ll n;
	cin>>n;
	string ans="";
	while(n)
	{
		ans=nm[n%26]+ans;
		n--;
		n/=26;
	}
	cout<<ans<<'\n';
}

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


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 4e5 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

bool cmp(pair<int, int> a, pair<int, int> b) {
  if(a.second != b.second)
    return a.second < b.second;
  if(a.second == b.second)
    return a.first < b.first;
}

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int n, a, b;
  ll cur = 0;
  cin >> n;
  vector<pair<int, int>> pr;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
    pr.push_back({a, b});
  }
  sort(pr.begin(), pr.end(), cmp);
//  for(auto it: pr)
//    cerr << it.first << ' ' << it.second << endl;
  bool can = 1;
  for(auto it: pr) {
    if(cur + it.first <= it.second) {
      cur += it.first;
    } else {
      can = 0;
      break;
    }
  }
  if(can)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}


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

int main() {
  long long N, sum = 0;
  cin >> N;

  for (int i = 1; i <= N; i++) {
    if (i % 3 == 0 || i % 5 == 0) {
      continue;
    } else {
      sum += i;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3636