akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll h, w, k;
    cin >> h >> w >> k;

    string s;
    vvll a(h, vll(w));
    REP(i, h) {
        cin >> s;
        REP(j, w) {
            a[i][j] = int(s[j] - '0');
        }
    }
    ll res = 1e18;
    REP(bi, 1LL << h) {
        ll mem = 0;
        vll hc(h - 1);
        REP(i, h - 1) {
            if ((bi >> i) & 1) {
                mem++;
                hc[i] = 1;
            }
        }
        vll ccc(h);
        ll wpre = 0, ng = 0;
        REP(j, w) {
            ll hid = 0;
            REP(i, h) {
                ccc[hid] += a[i][j];
                if (hc[i]) hid++;
            }
            ll nxt = 0;
            REP(i, h) {
                if (ccc[i] > k) {
                    if (j == wpre) ng = 1;
                    else {
                        mem++;
                        wpre = j;
                        nxt = 1;
                    }
                    break;
                }
            }
            if (ng) break;
            if (nxt) {
                REP(i, h) ccc[i] = 0;
                j--;
            }
        }
        if (ng == 0) res = min(res, mem);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
ll n;
ll ans;
const ll MAX=500005;
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(ll i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(ll i,ll j){
    if(i<j) return 0;
    if(i<0||j<0) return 0;
    return fac[i]*(finv[j]*finv[i-j]%MOD)%MOD;
}
int main(void){
    cin>>n;
    ll N=n/3;
    COMinit();
    for(int i=1;i<=N;i++){
        ll s=n-3*i;
        //cout<<s<<endl;
        ans=(ans+COM(i-1+s,s))%MOD;
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 15348
#include <cstdio>
using namespace std;
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d%d", &x, &y);
int main() {
  scii(a,b) sci(c)
  if(a+b==c||b+c==a||c+a==b)printf("Yes\n");
  else printf("No\n");
}

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

int main()
{
	long N;
	long result;

	cin >> N;

	result = 0;

	int min = 0;
	for (long a = 0; a < N; a++) {
		long P;
		cin >> P;
		if (min == 0|| P < min) {
			min = P;
			result++;
		}
		
	}

	cout << result<<endl;
}



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

int main() {
	int A[100],n;

	cin >> n;
	for (int i = 0; i < n; i++) scanf("%d", &A[i]);

	for (int i=0; i < n; i++) {
		int v = A[i];
		int j = i - 1;
		while ((j >= 0) && (A[j] > v)) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		char out[400];
		int k,p=0;
		for (k = 0; k < n; k++) {
			int l = sprintf(&out[p], "%d ", A[k]);
			p = p + l;
		}
		out[p - 1] = '\n';
		cout << out;
	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	int n,k; scanf("%d%d",&n,&k);
	vector<int> a(n),b(n);
	rep(i,n) scanf("%d%d",&a[i],&b[i]);

	lint ans=0;
	rep(j,n) if((a[j]&k)==a[j]) ans+=b[j];

	rep(i,30) if(k>>i&1) {
		int x=(k|(1<<i)-1)&~(1<<i);
		lint sum=0;
		rep(j,n) if((a[j]&x)==a[j]) sum+=b[j];
		ans=max(ans,sum);
	}
	printf("%lld\n",ans);

	return 0;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, K;
int a[110000], b[110000];
int cnt[110000];
signed main() {
    cin >> N >> K;
    rep(i, N) {
        cin >> a[i] >> b[i];
        cnt[a[i]] += b[i];
    }
    int cur = 0;
    rep(i, 110000) {
        cur += cnt[i];
        if (K <= cur) { fin(i); }
    }
}


Measured memory_bytes: 2688
#init
max_num = 1000000
is_prime_num = [True for i in range (max_num+1)]

#0, 1 --- not prime number
is_prime_num[0] = False
is_prime_num[1] = False
end = int(max_num ** .5)

for i in range(2, end+1):
    if is_prime_num[i]:
        for j in range(i*i, max_num+1, i):
            is_prime_num[j] = False


while True:
    try:
        n = int(input())
        prime_cnt = 0
        for i in range(1, n+1):
            if is_prime_num[i]:
                prime_cnt = prime_cnt + 1
                   
   
        print(str(prime_cnt))
    except:
        break
    

Measured memory_bytes: 15112
import java.util.Scanner;

public class Main {
	static Scanner in = new Scanner(System.in);
	public static void main(String[] args){
		String o = in.nextLine();
		String e = in.nextLine();
		int a = o.length() < e.length() ? o.length() : e.length();
		for(int i = 0; i < a; i++){
			System.out.print("" + o.charAt(i) + e.charAt(i));
		}
		if(o.length() != e.length()){
			if(o.length() > e.length()){
				System.out.println(o.charAt(o.length() - 1));
			}else{
				System.out.println(e.charAt(o.length() - 1));
			}
		}
	}
}


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

int main(){
    int N; cin >> N;
    vector<int> C(N-1),S(N-1),F(N-1);
    for(int i = 0; i < N-1; i++) cin >> C[i] >> S[i] >> F[i];
    
    for(int i = 0; i < N; i++){
        int ans = 0;
        
        for(int j = i; j < N-1; j++){
            if(ans <= S[j]) ans = S[j];
            else if(ans % F[j] == 0);
            else ans = ans + (F[j] - ans%F[j]);
            ans += C[j];
        }
        
        cout << ans << endl;
        
        
    }
    
    
}




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

int main()
{
	int a;
	cin >> a;
	if (a/1000==a/1000*10-a/100||a/1000*10-a/100==a/100*10-a/10||a/100*10-a/10==a/10*10-a) {
		cout << "Bad" << endl;
	}
	else {
		cout << "Good" << endl;
	}
}

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

typedef  long long int ll;
typedef  vector<int> vi;
#define  IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define  pb push_back
#define  fn for(int i=0;i<n;i++)
#define  all(x) x.begin(), x.end()
#define  endl "\n"


void solve()
{
	// write your code here :
	int a,b;
	cin>>a>>b;
	int save,flag=0;
	for(int i=1;i<=1000;i++)
	{
		if((i*8)/100==a and (i*10)/100==b)
			{save =i;flag=1;break;}
	}
	if(flag)
		cout<<save;
	else cout<<-1<<endl;
}

int main()
{
	IOS
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
	// int t;
	// cin>>t;
	// while(t--)
	solve();
}


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

int main() {
	int i,H;
	vector<int> A;
	scanf("%d",&H);
	A.resize(H+1);
	for(i=1; i<=H; ++i) {
		scanf("%d",&A[i]);
	}
	for(i=1; i<=H; ++i) {
		printf("node %d: key = %d, ",i,A[i]);
		if(i!=1) {
			printf("parent key = %d, ",A[i/2]);
		}
		if(2*i<=H) {
			printf("left key = %d, ",A[2*i]);
		}
		if(2*i+1<=H) {
			printf("right key = %d, ",A[2*i+1]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2664
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto A = lreads(N);
    writeln(A.any!"(a&1)!=0" ? "first" : "second");
}


Measured memory_bytes: 4092
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

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

		BigDecimal a = new BigDecimal(sc.next());
		BigDecimal b = new BigDecimal(sc.next());

		System.out.println(a.multiply(b).setScale(0, RoundingMode.DOWN));
	}
}

Measured memory_bytes: 35940
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());

    let n: usize = io.read();
    let v = io.readn::<i64>(n);
    let c = io.readn::<i64>(n);

    let mut ans = -1e10 as i64;
    for bits in 0..1 << n {
        let mut tmp = 0i64;
        for i in 0..n {
            if bits >> i & 1 == 1 {
                tmp += v[i] - c[i];
            }
        }
        ans = max(ans, tmp);
    }
    io.writeln(ans);
}

static MOD: i64 = 1000000007;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, m, x[100008], y[100008];
ll mod = 1e9+7; 

int main() {
	cin >> n >> m;
	for(ll i = 1; i <= n; i++){cin >> x[i];}
	for(ll j = 1; j <= m; j++){cin >> y[j];}
	ll pseudoh = 0;
	ll pseudow = 0;
	for(ll i = 1; i <= n-1; i++){pseudoh += (i*(n-i)%mod)*(x[i+1]-x[i])%mod; pseudoh %= mod;}
	for(ll j = 1; j <= m-1; j++){pseudow += (j*(m-j)%mod)*(y[j+1]-y[j])%mod; pseudow %= mod;}
	
	cout << pseudoh*pseudow%mod;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define RI register int
const int mod=1e9+7,N=2005;
int n,m,K,ans,f[N<<1][N][2],s[N];
int qm(int x) {return x>=mod?x-mod:x;}
int main()
{
	scanf("%d%d%d",&n,&m,&K);
	f[0][0][0]=1;
	for(RI i=1;i<=max(n,m)*2;++i) {
		s[0]=qm(f[i-1][0][0]+f[i-1][0][1]);
		for(RI j=1;j<=n;++j)
			s[j]=qm(s[j-1]+qm(f[i-1][j][0]+f[i-1][j][1]));
		for(RI j=0;j<=n;++j) {
			f[i][j][0]=qm(s[j]-s[j-1]+mod);
			if(j) f[i][j][1]=qm(s[j-1]-(j-K>=0?s[j-K]:0)+mod);
		}
		for(RI j=0;j<=n;++j)
			if(j%(K-1)==n%(K-1)&&(N*(K-1)-j+1)%(K-1)==m%(K-1)&&i*(K-1)-j+1<=m)
				ans=qm(ans+f[i][j][1]);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 62976
let modulo = 998244353
let ( +@ ) a b = (a+b) mod modulo
let ( *@ ) a b = (a*b) mod modulo
let rec mod_pow a n =
  if n <= 0 then 1
  else if n mod 2 = 1 then a *@ mod_pow a (n-1)
  else let h = mod_pow a (n/2) in h *@ h
let ( /@ ) a b = a *@ mod_pow b (modulo - 2)

let rec for_fold a b v f = if a > b then v else for_fold (a+1) b (f v a) f

let () =
  Scanf.scanf "%d %d %d %d" @@ fun n a b k ->
  let comb = Array.make (n+1) 1 in
  for r = 1 to n do comb.(r) <- comb.(r-1) *@ (n+1-r) /@ r done;

  for_fold 0 n 0 (fun s r ->
    if k < r * a || (k - r * a) mod b > 0 then s
    else
      let m = (k - r * a) / b in
      if m > n then s else s +@ comb.(r) *@ comb.(m))
  |> Printf.printf "%d\n"

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int>vi;
#define pb push_back
#define sc(n) scanf("%d",&n)
#define lsc(n) scanf("%lld",&n)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(i=0LL;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define rev1(i,n) for(i=n;i>0;i--)
#define in insert
#define IT ::iterator
#define pr(n) printf("%d\n",n)
#define lpr(n) printf("%lld\n",n);

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


Measured memory_bytes: 3632
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#include<cmath>
#include<math.h>
using namespace std;
int main(){
    int a,b,c,n;
    cin>>a>>b>>c>>n;
    for(int i=0;i<n;i++){
    	if(a>=b)b=b*2;
    	else if(b>=c)c=c*2;
	}
    if(a<b&&b<c)cout<<"Yes";
    else cout<<"No";
    
    
    return 0;
}


Measured memory_bytes: 3592
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);  
int cnt=0;
int haha[1234]; 
int add(int val){
	int i=0;
	while(val>0){
		if(val%2){
			haha[i]++;
			if(haha[i]==2)
				cnt++;
		}
		i++;
		val/=2;
	}
	return 0;
}
int remove(int val){
	int i=0;
	while(val>0){
		if(val%2){
			haha[i]--;
			if(haha[i]==1){
				//cout<<"ad"<<endl;
				cnt--;
			}
		}
		i++;
		val/=2;
	}

	return 0;
}
int a[212345];
int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int i;
    rep(i,n){
    	cin>>a[i];
    }
    i=0;
    int j=0;
    ll ans=0;
    while(j<n){
    	add(a[j]);
    	while(cnt!=0){
    		//cout<<j<<" "<<i<<cnt<<endl;
    		ans+=j-i;
    		remove(a[i]);
    		i++;
    	}
    	j++;


    }
    if(j==n){
		f(j,i,n){
			ans+=n-j;
		}
	}
    cout<<ans<<endl;
    return 0;  
    
}



Measured memory_bytes: 1024
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  $a = array_map('intval', explode(" ", trim(fgets(STDIN))));

  if(in_array(0, $a)){
    echo 0;
    exit;
  }

  $ans = 1;
  for ($i=0; $i<$n; $i++) {
    $ans *= $a[$i];
    if($ans > 1000000000000000000){
      echo -1;
      exit;
    }
  }

  echo $ans;

Measured memory_bytes: 28704
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define MOD (long int)10e9 + 7
#define LD long double

int ans = 12 * 100000 + 20;

int main(){
    int n;
    cin >> n;
    int k;
    cin >> k;

    vector<bool> flag(n + 1,false);

    int d;

    for(int i = 0; i < k; ++i){
        cin >> d;
        for(int j = 0; j < d; ++j){
            int a;
            cin >> a;
            flag[a] = true;
        }
    }

    int ans = 0;

    for(int i = 1; i <= n; ++i) ans += !flag[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
//AnkitCode99 here....
#include<bits/stdc++.h>
#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define mp make_pair
#define pll pair<ll,ll>
#define pb push_back
//max xor btw range of two numbers..
#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
#define ceil(a,b) a/b+((a%b ==0 )?0:1)
using namespace std;

const ll sz=100005;
const ll szz=1000006;

int main()
{
	fast;
    

	ll n;
	cin>>n;
	set<int> s;
	rep(i,0,n)
	{
		ll ele;
		cin>>ele;
		s.insert(ele);
	}
	if((ll)s.size()==n)
		cout<<"YES\n";
	else
		cout<<"NO";
}
//Goodbye...

Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    int n, m, a, b;
    cin >> n >> m;
    vector<vector<int>> G(n, vector<int>(n, 0));
    for(int i =0; i<m; i++){
        cin >> a >> b;
        G[a-1][b-1] = 1;
        G[b-1][a-1] = 1;
    }
    vector<int> v(n);
    for(int i = 0 ; i<n; i++){
        v[i] = i;
    }
    int num = 0;
    do{
        for(int i=0; i<n-1; i++){
            if(G[v[i]][v[i+1]]==1){ 
                if(i == n-2) num++;
                continue;
            }else break;
        }
    }while(next_permutation(v.begin()+1, v.end()));

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

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

ll power(ll x,ll n){
    if(n==0) return 1;
    ll res=power(x*x%mod,n/2);
    if(n&1) res=res*x%mod;
    return res;
}

int main(){
  int n;
  ll k;
  cin>>n>>k;
  ll a[n+1];
  a[0]=1;
  rep(i,1,n+1) a[i]=a[i-1]*i%mod;
  ll b[n+1];
  b[0]=1;
  rep(i,1,n+1) b[i]=power(a[i],1e9+5);
  int p;
  if(n-1<=k) p=n-1;
  else p=k;
  ll ans=0;
  rep(i,0,p+1){
    ans+=(a[n]*b[i]%mod*b[n-i]%mod)*(a[n-1]*b[i]%mod*b[n-1-i]%mod)%mod;
    ans%=mod;
  }
  if(p==1) ans--;
  cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

using Graph=vector<vector<int>>;
Graph G;

int main(){
  ll n,m,v,p;
  cin >> n >> m >> v >> p;
  
  vector<ll>vec(n);
  rep(i,n)cin>>vec[i];
  sort(vec.begin(),vec.end(),greater<ll>());
  
  ll left=0;
  ll right=n;
  while(abs(right-left)>1){
    ll mid=(right+left)/2;
    if(mid<p)left=mid;
    else if(vec[mid]+m<vec[p-1])right=mid;
    else{
      ll vote = m*(p-1) + m*(n-mid);
      for(ll i=p-1;i<=mid-1;i++){
        vote+=max((ll)0,vec[mid]+m-vec[i]);
      }
      if(vote>=m*v)left=mid;
      else right=mid;
    }
  }
  cout<<left+1<<endl;                        
  
}
    


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

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

	int n; cin >> n;
	vector<int> a(n);
	REP(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	int mid = a[n - 1] / 2;
	auto itr = lower_bound(a.begin(), a.end(), mid);
	if (*itr == a[n - 1])
		cout << a[n - 1] << ' ' << a[n - 2] << '\n';
	else {
		int index = distance(a.begin(), itr);
		if (abs(mid - a[index]) <= abs(mid - a[index - 1]))
			cout << a[n - 1] << ' ' << a[index] << '\n';
		else
			cout << a[n - 1] << ' ' << a[index - 1] << '\n';
	}
    return 0;
}


Measured memory_bytes: 3736
#include<stdio.h>
#include<stdlib.h>
int main(void){
	char data[15];
	scanf("%s",data);
	char year[5] ={data[0],data[1],data[2],data[3]};
	char month[3] = {data[5],data[6]};
	char day[3] = {data[8],data[9]};
	int y = atoi(year);
	int m = atoi(month);
	int d = atoi(day);
	if(m < 4){
		printf("Heisei\n");
		return 0;
	}else if(m==4){
		if(d<=30){
			printf("Heisei\n");
			return 0;
		}
		printf("TBD\n");
	}else{
		printf("TBD\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main()
{
    char s[51],s1[51],t[51],ans[51];
    scanf("%s",s1);
    scanf("%s",t);
    int L1=strlen(s1),L2=strlen(t),i,j,flag=1,k,count=0;
    strcpy(ans,s1);
//    for(i=0; i<L1; i++)
//        if(ans[i]=='?')
//            ans[i]='z';
    for(i=0; i<L1; i++)
    {
        strcpy(s,s1);
        int count1=0;
        for(j=0; j<L2; j++)
            if((s1[i+j]=='?')||(s1[i+j]==t[j]))
                count1++;
        if(count1==L2)
        {
            for(k=0; k<L1; k++)
            {
                if((k<i)||(k>=i+L2))
                {
                    if(s[k]=='?')
                        s[k]='a';
                }
                else
                    s[k]=t[k-i];
            }
            strcpy(ans,s);
        }
        else
            count++;
    }
    if(count==L1)
        printf("UNRESTORABLE");
    else
        printf("%s",ans);
    return 0;
}


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

int f(vector<int> v,int n,vector<int> &dp,int k)
{
    dp[1]=0;
    for (int i=2;i<=n;i++)
        for (int j=i-1;j>=max(i-k,1);j--)
            dp[i]=min(dp[j]+abs(v[i]-v[j]),dp[i]);
    return dp[n];
}

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> v(n+1,0);
    const int g=1e9;
    vector<int> dp(n+1,g);
    for (int i=1;i<=n;i++)
        cin >> v[i];
    cout << f(v,n,dp,k);
}


Measured memory_bytes: 1408
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

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

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll a , p;

int main() {
    fast_io;

    cin >> a >> p;
    cout << (a * 3 + p) / 2 << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
using namespace std;

int main()
{
    string s;
    cin >> s;
    bool even = (s.size() % 2 == 0);
    bool same = (s[0] == s[s.size() - 1]);
    if ((even && !same) || (!even && same)) {
        printf("Second\n");
    } else {
        printf("First\n");
    }
}

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

int main(){
  unsigned long long N;
  cin >> N;
  unsigned long long tN = N/10;
  if(N%2 == 1) cout << 0 << endl;
  else{
    long long ans = tN;
    long long tr = 5;
    while(tN / tr > 0){
      ans += tN / tr;
      tr *= 5;
    }
    cout << ans << endl;
  }
}


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

using namespace std;

int main() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    size_t n;
    cin >> n;
    vector<pair<int64_t, int64_t>> jobs;
    for (size_t i = 0; i < n; ++i) {
        int64_t time, deadline;
        cin >> time >> deadline;
        jobs.emplace_back(deadline, time);
    }
    sort(jobs.begin(), jobs.end());
    int64_t total_time = 0;
    for (size_t i = 0; i < n; ++i) {
        total_time += jobs[i].second;
        if (total_time > jobs[i].first) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007;

ll dp[200005];
vector<ll> pos[200005];
int main(void){
    ll n;
    cin >> n;


    ll c[n];
    rep(i, 0, n){
        cin >> c[i];
        c[i]--;
        pos[c[i]].push_back(i);
    }

    dp[0] = 1;
    rep(i, 1, n){
        dp[i] = dp[i - 1];
        ll prev = lower_bound(pos[c[i]].begin(), pos[c[i]].end(), i) - pos[c[i]].begin() - 1;

        if(prev < 0) continue;
        if(i - pos[c[i]][prev] > 1){
            dp[i] += dp[pos[c[i]][prev]];
            dp[i] %= MOD;
        }
    }

    cout << dp[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 14336
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define mod (int)1e9+7
#define inf (int)1e16
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
int n;
int w[114];
int ans = inf;
int sum = 0;
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> w[i];
	}
	rep(i, n - 1) {
		int s1 = 0, s2 = 0;
		rep(j, i + 1) {
			s1 += w[j];
		}
		for (int j = i + 1; j < n; j++) {
			s2 += w[j];
		}
		ans = min(ans, abs(s1 - s2));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D, A--, B--, C--, D--;
  string S;
  cin >> S;
  for (int i = A; i <= max(C, D); i++) {
    if (S[i] == '#' && S[i + 1] == '#') {
      cout << "No" << endl;
      return 0;
    }
  }
  if (D < C) {
    bool t = false;
    for (int i = B - 1; i <= D - 1; i++) {
      if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.') t = true;
    }
    if (t) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
    return 0;
  } else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
typedef pair<string,string> Paist;
bool PairSc(const Paist &a , Paist &b){
  if(a.first == b.first){
    return a.second < b.second;
  }else{
    return a.first < b.first;
  }
}
int main(){
    int n,c;cin>>n>>c;
    vector<string> a;
    vector<string> b[n];
    for(int i = 0; n > i; i++){
        int z;cin>>z;
        for(int j = 0; z > j; j++){
            string t;cin>>t;
            a.push_back(t);
            b[i].push_back(t);
        }
        sort(b[i].begin(),b[i].end());
    }
    sort(a.begin(),a.end());
    vector<string> k;
    vector<pair<string,string> > ans;
    for(int i = 0; a.size() > i; i++){//
        k.clear();
        if(i != 0){
            if(a[i-1] == a[i])continue;
        }
        for(int j = 0; n > j; j++){
            bool finda = false;
            for(int x = 0; b[j].size() > x; x++){
                if(a[i] == b[j][x]){
                    finda = true;
                    break;
                }
            }
            if(finda){
                for(int x = 0; b[j].size() > x; x++){
                    if(a[i] != b[j][x]){
                      k.push_back(b[j][x]);
                    }
                }
            }
        }
        sort(k.begin(),k.end());
        int nw = 1;
        for(int j = 1; k.size() > j; j++){
            if(k[j-1] != k[j]){
                if(nw >= c){
                    ans.push_back({min(a[i],k[j-1]),max(a[i],k[j-1])});
                }
                nw = 1;
            }else{
                nw++;
            }
        }
        if(nw >= c){
            ans.push_back({min(a[i],k[k.size()-1]),max(a[i],k[k.size()-1])});
        }
        
    }
    sort(ans.begin(),ans.end(),PairSc);
    vector<pair<string,string> > ansp;
    for(int i = 0; ans.size() > i; i++){
        if(i!=0){
            //cout << ans[i-1].first << ":" << ans[i-1].second << " " << ans[i].first << ":" << ans[i].second << endl;
            if(ans[i-1] == ans[i])continue;
            //cout << ans[i-1].first << ":" << ans[i-1].second << " " << ans[i].first << ":" << ans[i].second << endl;
        }
        ansp.push_back(ans[i]);
    }
    cout << ansp.size() << endl;
    sort(ansp.begin(),ansp.end(),PairSc);
    for(int i = 0; ansp.size() > i; i++){
        cout << ansp[i].first << " " << ansp[i].second << endl;
    }
}


Measured memory_bytes: 3320
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int n, d;

vector < vector <int> > v;

void read() {
  cin >> n >> d;
  for(int i = 0; i < n; ++i) {
    vector <int> x;
    for(int j = 0; j < d; ++j) {
      int y;
      cin >> y;
      x.pb(y);
    }
    v.pb(x);
  }
}

void solve() {
  int sol = 0;
  for(int i = 0; i < n; ++i) {
    for(int j = i + 1; j < n; ++j) {
      float l = 0;
      for(int k = 0; k < d; ++k) {
        l += (v[i][k] - v[j][k]) * (v[i][k] - v[j][k]);
      }
      int sqr = sqrt(l);
      if (sqr * sqr == l)
        ++sol;
    }
  }
  cout << sol;
}

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

	return 0;
}


Measured memory_bytes: 256
num_list = [input() for i in range(5)]

num_first =[]

for str1 in num_list:
  number=10-int(str1[-1])
  if number==10:
    number=0
  num_first.append(number)

index=num_first.index(max(num_first))
sum=0
for i in range(5):
    sum=sum+int(num_list[i])+num_first[i]
    if i == index:
      sum=sum-num_first[i]
    
    
print(sum)

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int N;
int x[111], y[111], h[111];

int check(int cy, int cx) {
   set<int> cand;
   int Max = 1e10;
   rep (i, N) {
      int dist = abs(cy - y[i]) + abs(cx - x[i]);
      if (h[i] <= 0) {
         chmin(Max, dist);
      } else {
         cand.insert(h[i] + dist);
      }
   }

   if (cand.size() == 0) {
      return -1;
   }

   if (cand.size() == 1 && *cand.begin() <= Max) {
      return *cand.begin();
   }

   return -1;
}

signed main() {
   cin >> N;
   rep (i, N) {
      cin >> x[i] >> y[i] >> h[i];
   }

   int ax = 0, ay = 0, ah = 0;
   [&]() {
      for (int cy = 0; cy <= 100; cy++) {
         for (int cx = 0; cx <= 100; cx++) {
            int t = check(cy, cx);
            if (t == -1) continue;

            ay = cy, ax = cx, ah = t;
            return;
         }
      }
   }();

   printf("%lld %lld %lld\n", ax, ay, ah);

   return 0;
}

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

int main(){
    int D, T, S;
    std::cin >> D >> T >> S;
    
    if(D <= T * S){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
    
    
    return 0;
    
}


Measured memory_bytes: 3636
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(b-a==c-b)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll kai[200001];
ll mokai[200001];
ll p;

ll mod_pow (ll x, ll y) {
    ll ret = 1;
    while (y) {
        if (y&1) ret = ret*x%p;
        x = x*x%p;
        y /= 2;
    }
    return ret;
}

void init (int _n) {
    kai[0] = 1;
    for (int i = 1; i <= _n; i++) kai[i] = kai[i-1]*i%p;
    for (int i = 0; i <= _n; i++) mokai[i] = mod_pow(kai[i],p-2);
}

ll conb (ll x, ll y) {
    ll z = x-y;
    ll ret = kai[x]*mokai[y]%p;
    ret = ret*mokai[z]%p;
    return ret;
}

ll c[3000];
ll prep[3000][3000];

int main() {
    cin >> p;
    init(3000);
    rep(i,p+1) {
        prep[i][0] = 1;
        for (int j = 1; j <= p; j++) prep[i][j] = prep[i][j-1] * i % p;
    }
    rep(i,p) {
        ll a; cin >> a;
        if (a == 0) continue;
        (c[0] += 1) %= p;
        rep(j,p) {
            c[j] += -1 * conb(p-1, p-1-j) * prep[p-i][p-1-j];
        }
    }
    rep(i,p) {
        cout << (c[i]+p*p*p)%p;
        if (i != p-1) cout << " ";
    }
    cout << endl;
}

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

using namespace std ;

const int MAX = 1e4 + 5 ;
int cost[] = {2,5,5,4,5,6,3,7,6} ;

int can[MAX], dig[MAX] , arr[12];
int m ;
void solve(int n)
{
	if(n == 0)
		return ;
	for(int i = m-1 ; i >= 0 ; --i)
	{
		if(n-cost[arr[i]-1] < 0)
			continue ;
		if(can[n-cost[arr[i]-1]] && dig[n] == dig[n-cost[arr[i]-1]]+1)
		{
			cout<<arr[i] ;
			solve(n-cost[arr[i]-1]) ;
			return ;
		}
	}
	return ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n ;
	cin>>n>>m ;
	for(int i = 0 ; i < m ; ++i)
		cin>>arr[i] ;
	sort(arr , arr + m) ;
	can[0] = 1 ;
	for(int i = 0 ; i <= n ; ++i)
	{
		for(int j = 0 ; j < m ; ++j)
		{
			if(i-cost[arr[j]-1] < 0)
				continue ;
			can[i] |= can[i-cost[arr[j]-1]] ;
			if(can[i-cost[arr[j]-1]])
				dig[i] = max(dig[i] , dig[i-cost[arr[j]-1]]+1) ;
		}
	}
	solve(n) ;
	return 0 ;
}

Measured memory_bytes: 384
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
INF=10**9+7
a_list=list(map(int,input().split()))
count=0
ans=0
for i in range(n):
    for j in range(i+1,n):
        if a_list[i]>a_list[j]:
            count+=1
ans=(count*k)%INF
m=max(a_list)
D=[0]*m
for i in a_list:
    D[i-1]+=1
count=0
Sum=D[m-1]
for i in range(m-2,-1,-1):
    count=(count+Sum*D[i])%INF
    Sum=(Sum+D[i])%INF
count=(count*k*(k-1)//2)%INF
ans=(ans+count)%INF
print(ans)
    




Measured memory_bytes: 41580
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


INF = 10**18


def main():

    N, K = in_nn()
    H = in_nl()

    dp = [INF] * N
    dp[0] = 0

    for i in range(N):
        for k in range(1, K + 1):
            if i + k < N:
                dp[i + k] = min(dp[i + k], dp[i] + abs(H[i] - H[i + k]))

    print(dp[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 82364
import math
X=int(input())
t=int(math.sqrt(X))
L=[]
for i in range(1,t+1):
	if X%i==0:
		L.append([i,X//i])
for i in range(10010):
	for x,y in L:
		j=i-x
		tmp=pow(i,4)+pow(i,3)*j+pow(i,2)*pow(j,2)+i*pow(j,3)+pow(j,4)
		if tmp==y:
			print(i,j)
			exit()
		j=i-y
		tmp=pow(i,4)+pow(i,3)*j+pow(i,2)*pow(j,2)+i*pow(j,3)+pow(j,4)
		if tmp==x:
			print(i,j)
			exit()

Measured memory_bytes: 9244
n, k = map(int, input().split())
s = list(input())

if s[k-1] == 'A':
    s[k-1] = 'a'
elif s[k-1] == 'B':
    s[k-1] = 'b'
else:
    s[k-1] = 'c'

print(''.join(s))

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

int main(){
  int N; cin >> N;
  string s; cin >> s;
  int r = 0;
  int state = 0;
  REP(i,N){
    char c = s[i];
    switch(c){
      case 'A':
        state = 1;
        break;
      case 'B':
        if(state==1){
          state = 2;
        }else{
          state = 0;
        }
        break;
      case 'C':
        if(state==2){
          r++;
          state = 0;
        }else{
          state = 0;
        }
        break;
      default:
        state = 0;
        break;
    }
  }
  cout << r << "\n";
}
  

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <stdbool.h>
#define MAX 100001

int n, head = 0, tail = 0;

typedef struct pp{
	char name[11];
	int time;
}P;

P Q[MAX + 1];

bool isEmpty(){
	return head == tail;	
}

bool isFull(){
	return head == (tail +1) % MAX;
}

void enqueue(P x){
	if (isFull())
		printf("overflow");
	Q[tail] = x;
	if ((tail+1)==MAX)
		tail = 0;
	else
		tail++;
}

P dequeue(/*int q[]*/){
	P x;
	if (isEmpty())
		printf("underflow");
	x = Q[head];
	if ((head+1) == MAX)
		head = 0;
	else
		head++;
	return x;
}

int main(void) {
	int q, i, total=0;
	P rr;
	
	scanf("%d %d", &n, &q);
	
	for (i = 1; i<=n; i++){
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].time);
		enqueue(Q[i]);
	}
	do{
		if(Q[head].time<=q){
			total += Q[head].time;
			rr = dequeue();
			rr.time = total;
			printf("%s %d\n", rr.name, rr.time);
		}
		else{
			total += q;
			Q[head].time -= q;
			rr = Q[head];
			dequeue();
			enqueue(rr);

		}
	} while (!isEmpty());

	

	return 0;
}



Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long int a,b,c;
  cin>>a>>b>>c;
  if(a*b*c%2==0){
    cout<<0;
  }else{
    cout<<min(min(a*b,b*c),c*a);
  }
}

Measured memory_bytes: 256
h, n = map(int, input().split())
a, b = [0] * n, [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

dp = [(-(-i // a[0]) * b[0]) for i in range(h + 1)]
for i in range(1, n):
    for j in range(1, h + 1):
        dp[j] = min(dp[j], dp[max(j-a[i],0)] + b[i])

print(dp[-1])

Measured memory_bytes: 42204
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N, K;

void solve(){
	int a = (N+ 1) / 2;
	if(a >= K)
		cout << "YES" <<endl;
	else
		cout << "NO" <<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> K;
		solve();
	return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
alist = gets.chomp.split.collect{ |item| item.to_i}
xlist = Array.new(n)

a1 = 0
n.times do |ni|
  i = ni+1
  if ((i%2) == 0)
    a1 -= alist[ni]
  else
    a1 += alist[ni]
  end
end
xlist[0] = a1
1.upto(n-1) do |i|
  xlist[i] = (2 * alist[i-1]) - xlist[i-1]
end
puts xlist.join(" ")


Measured memory_bytes: 15236
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v){stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n<<=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}
void YN(bool z){cout<<(z?"YES\n":"NO\n");}
void Yn(bool z){cout<<(z?"Yes\n":"No\n");}
void yn(bool z){cout<<(z?"yes\n":"no\n");}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 0;
struct Prime{
  vector<ll> pl;
  void init(int a){ // a以下の素数列挙
    pl.resize(0);
    vector<bool> z(a+1, true);
    FOR(i, 2, a+1){
      if(z[i])pl.push_back(i);
      for(int b=i*2; b <= a; b+=i) z[b]=false;
    }
  }
  void divisor(ll a, vector<ll>&v){ // v に約数が入る
    v.resize(0);
    v.push_back(1);
    for(ll b: pl){
      if(b*b > a) break;
      if(a%b) continue;
      int l=0, vs=v.size();
      while(a%b==0){
        a /= b;
        FORR(i, v.size()-1, l) v.push_back(v[i] * b);
        l += vs;
      }
    }
    if(a>1) FORR(i, v.size()-1, 0) v.push_back(v[i] * a);
    sort(v.begin(), v.end());
  }
} pr;
ll n, m;
vl v;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  pr.init(100000);
  pr.divisor(m, v);
  for(ll a: v)if(a >= n){
    cout << m/a << endl;
    return 0;
  }
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int n,m,a[N],b[N],c[N];
long long vb[N];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",a+i);sort(a+1,a+n+1);
	for (int i=1;i<=n;++i) scanf("%d",b+i);sort(b+1,b+n+1);
	for (int i=1;i<=n;++i) scanf("%d",c+i);sort(c+1,c+n+1);
	for (int i=1,pos=0;i<=n;++i){
		while (pos<n&&a[pos+1]<b[i]) ++pos;
		vb[i]=vb[i-1]+pos;
	}
	long long ans=0;
	for (int i=1,pos=0;i<=n;++i){
		while (pos<n&&b[pos+1]<c[i]) ++pos;
		ans+=vb[pos];
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 2176
def linear_search(array, value)
  length = array.length
  i = 0
  array.push(value)
  loop do
    if array[i] == value
      if i == length
        return false
        break
      else
        return true
        break
      end
    else
      i += 1
    end
  end
  array.delete(-1)
end

def linear_search(array, value)
  length = array.length
  for i in 0..(length-1)
    if array[i] == value
      return true
    end
  end
end

n = gets.chomp.to_i
s = gets.chomp.split.map(&:to_i)
q = gets.chomp.to_i
t = gets.chomp.split.map(&:to_i)



sum_count = 0
  for i in 0..(q-1)
    if linear_search(s, t[i]) == true
      sum_count += 1
    end
  end

puts sum_count

Measured memory_bytes: 8976