akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i,n) for (int i=0;i<n;++i)
typedef pair<int,int> P;

int main() {
    int n, q;
    ll sum=0;
    cin >> n;
    map<int,int> a;
    rep(i,n){
        int tmp;
        cin >> tmp;
        sum+=tmp;
        if(a.count(tmp)==0){
            a[tmp]=1;
        }else{
            ++a[tmp];
        }
    }
    cin >> q;
    int b[q], c[q];
    rep(i,q){
        cin >> b[i];
        cin >> c[i];
    }
    ll sum_a[q];
    rep(i,q){
        ll tmp=0;
        if(a.count(b[i])){
            tmp=(c[i]-b[i])*a[b[i]];
            if(a.count(c[i])){
                a[c[i]]+=a[b[i]];
            }else{
                a[c[i]]=a[b[i]];
            }
            a.erase(b[i]);
        }
        if(i==0){
            sum_a[i]=sum+tmp;
        }else{
            sum_a[i]=sum_a[i-1]+tmp;
        }
    }
    rep(i,q){
        cout << sum_a[i] << "\n";
    }

}

Measured memory_bytes: 8048
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {

	long long int n;
	cin >> n;
	
	vector<long long int> a(n);

	for (long long int i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(a.begin(), a.end());

	if (n % 2 == 0) {
		vector<long long int> b;
		vector<long long int> c;

		for (long long int i = 0; i < n; i++) {
			if (i < n / 2) {
				b.push_back(a[i]);
			}
			else {
				c.push_back(a[i]);
			}
		}

		reverse(c.begin(), c.end());

		long long int ans = 0;
		for (long long int i = 0; i < b.size(); i++) {
			if (i + 1 == b.size()) {
				ans += abs(c[i] - b[0]);
			}
			else {
				ans += abs(b[i] - c[i]);
				ans += abs(b[i + 1] - c[i]);
			}
		}

		long long int ans2 = 0;
		for (long long int i = 0; i < b.size(); i++) {
			if (i + 1 == b.size()) {
				ans2 += abs(c[0] - b[i]);
			}
			else {
				ans2 += abs(b[i] - c[i]);
				ans2 += abs(b[i] - c[i + 1]);
			}
		}

		cout << max(ans, ans2) << endl;
	}
	else {
		vector<long long int> b;
		vector<long long int> c;

		long long int d;

		for (long long int i = 0; i < n; i++) {
			if (i < n / 2) {
				b.push_back(a[i]);
			}
			else if (i == n / 2) {
				d = a[i];
			}
			else {
				c.push_back(a[i]);
			}
		}

		reverse(c.begin(), c.end());


		long long int ans = 0;
		for (long long int i = 0; i < b.size(); i++) {
			if (i + 1 == b.size()) {
				ans += abs(b[i] - c[i]);
				ans += max(abs(c[i] - d), abs(b[0] - d));
			}
			else {
				ans += abs(b[i] - c[i]);
				ans += abs(b[i + 1] - c[i]);
			}
		}

		long long int ans2 = 0;
		for (long long int i = 0; i < b.size(); i++) {
			if (i + 1 == b.size()) {
				ans2 += abs(b[i] - c[i]);
				ans2 += max(abs(c[0] - d), abs(b[i] - d));
			}
			else {
				ans2 += abs(b[i] - c[i]);
				ans2 += abs(b[i] - c[i+1]);
			}
		}

		cout << max(ans, ans2) << endl;
	}

	return 0;
}

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

int main() {
  ll n,k;
  cin >> n>>k;
  vector<ll> v(n,0);
  rep(i,k){
    ll d1;
    cin>>d1;
    rep(j,d1){
      ll temp;
      cin>>temp;
      temp--;
      v[temp]++;
    }

  }

  ll ans=0;
  rep(i,n){
    if (v[i]==0)ans++;

  }
  cout<<ans;

}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
vector<pair<int, int>> to[100010];
bool visited[100010];
ll dist[100010];

int main() {
    int n;
    cin >> n;
    vector<ll>a(n);
    vector<ll>b(n);
    vector<ll>c(n);
    rep(i,0,n){
        cin >> a[i];
    }
    rep(i,0,n){
        cin >> b[i];
    }
    rep(i,0,n){
        cin >> c[i];
    }
    sort(a.begin(), a.end());
    sort(c.begin(), c.end());
    ll ans = 0;
    rep(i, 0, n){
        auto aindex = lower_bound(a.begin(), a.end(), b[i]);
        ll ac = aindex - a.begin();
        auto cindex = upper_bound(c.begin(), c.end(), b[i]);
        ll cc =  c.end() - cindex;
        ans += ac * cc;
    }
    cout << ans << endl;
   return 0;
}


Measured memory_bytes: 8012
#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;

#define MAX_M 420

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

int dp[42][MAX_M][MAX_M];

int main() {
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;

    // init
    for (int i=0; i<42; i++) {
        for (int j=0; j<MAX_M; j++) {
            for (int k=0; k<MAX_M; k++) {
                dp[i][j][k] = INT_MAX;
            }
        }
    }
    dp[0][0][0] = 0;

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

        for (int j=0; j<MAX_M; j++) {
            for (int k=0; k<MAX_M; k++) {
                if (dp[i][j][k] != INT_MAX) {
                    // 薬品iを使わない
                    dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
                    // 薬品iを使う
                    dp[i+1][j+a][k+b] = min(dp[i+1][j+a][k+b], dp[i][j][k] + c);
                }
            }
        }
    }

    int ans = INT_MAX;
    for (int i=1; i<MAX_M; i++) {
        for (int j=1; j<MAX_M; j++) {
            if (dp[N][i][j] != INT_MAX) {
                int g = gcd(i, j);
                if (i/g == Ma && j/g == Mb) {
                    ans = min(ans, dp[N][i][j]);
                }
            }
        }
    }

    cout << (ans == INT_MAX ? -1 : ans) << endl;

    return 0;
}

Measured memory_bytes: 29312
use std::cmp::{max, min};
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (n, k): (usize, usize) = parse!(it, 2);
    let p: Vec<(i64, i64)> = (0..n).map(|_| parse!(it, 2)).collect();
    let mut cands = vec![];
    for i in 0..n {
        for j in i..n {
            if k == 2 {
                cands.push(vec![p[i], p[j]]);
                continue;
            }
            for k in j..n {
                if k == 3 {
                    cands.push(vec![p[i], p[j], p[k]]);
                    continue;
                }
                for l in k..n {
                    cands.push(vec![p[i], p[j], p[k], p[l]])
                }
            }
        }
    }

    let mut ret = std::i64::MAX;
    for ps in cands {
        let l = ps.iter().min_by_key(|x| x.0).unwrap().0;
        let r = ps.iter().max_by_key(|x| x.0).unwrap().0;
        let u = ps.iter().max_by_key(|x| x.1).unwrap().1;
        let d = ps.iter().min_by_key(|x| x.1).unwrap().1;
        let s = (r - l) * (u - d);
        if p.iter()
            .filter(|&&(x, y)| l <= x && x <= r && d <= y && y <= u)
            .count()
            >= k
        {
            ret = min(s, ret)
        }
    }
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 33020
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[5010];
const int INF = 1e12+10;
int32_t main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int n;
    cin>>n;
    vector<pair<int,int> > v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i].first>>v[i].second;
    }
    sort(v.begin(), v.end(), [](const pair<int,int> &l, const pair<int,int> &r){
        return l.first+l.second<r.first+r.second;
    });
    for(int i=1;i<=5000;i++)
        dp[i] = INF;
    for(int i=0;i<n;i++)
    {
        for(int j=5000;j>=0;j--)
        {
            if(dp[j]<=v[i].first)
                dp[j+1] = min(dp[j+1],dp[j]+v[i].second);
        }
    }
    for(int i=5000;i>=0;i--)
    {
        if(dp[i]!=INF)
        {
            cout<<i;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); 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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  rep(i, h) {
    rep(j, w) {
      cin >> a[i][j];
    }
  }

  rep(i, h + 2) {
    cout << '#';
    rep(j, w) {
      if (1 <= i && i <= h) cout << a[i - 1][j];
      else cout << '#';
    }
    cout << '#' << endl;
  }


  
  return 0;
}

Measured memory_bytes: 256
function Main(arg) {
 
    var N = arg.split("\n")[0]-0;
    var a = arg.split("\n")[1].split(" ").map(v => v-0);

    var num = 1;
    var block = 0;
    for (var i = 0; i < N; i++){

        if (num !== a[i]) {
            block++;
        }
        else {
            num++;
        }
    }
    if (block === N && num == 1) block = -1;
        
    console.log(block);

    return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22244
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
const ll MOD=1000003;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const vector<pll> dir={{0,1},{1,0},{-1,0},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=b-1;i>=a;i--)
#define range(i) (i).begin(),(i).end()
#define rrange(i) (i).rbegin(),(i).rend()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm (ll a,ll b) {return a*b/gcd(a,b);}
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
inline constexpr int modf(ll n){
    ll ans=1;
    rep(i,0,n) {ans=ans*(n-i)%MOD;}
    return ans;
}
inline long double median(vector<ll> v){
    ll size=v.size();
    sort(v.begin(),v.end());
    if (size % 2 == 1) return v[(size - 1) / 2];
    else return v[(size / 2) - 1] ;
}
template<class T> inline bool chmax(T& a,T b) {if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b) {if(a>b){a=b;return 1;} return 0;}
template<class T,class L>ostream& operator << (ostream& os, pair<T,L>& p){os << p.first << " " << p.second;return os;}

int main(){
    ll n;
    cin>>n;
    vector<ll> d(n);
    rep(i,0,n) cin>>d[i];
    sort(range(d));
    cout<<d[n/2]-d[n/2-1];
}


Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
	int N;
	scanf("%d", &N);
	int i;
	long long int sum=1;
	for (i = 1; i <= N; i++) {
		sum = (sum * i) % 1000000007;
	}
	printf("%lld\n", sum);
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

int main(void){
	while(1){
		int n,i,o,sum,sum1=0;
		scanf("%d",&n);
		int a[50][50]={0};
		if(n == 0)
			break;
		for(i=0;i<n;i++){
			for(o=0;o<n;o++){
				scanf("%d",&a[i][o]);
			}
		}
		for(i=0;i<n;i++){
			sum=0;
			for(o=0;o<n;o++){
				printf("%5d",a[i][o]);
				sum+=a[i][o];
			}
			printf("%5d\n",sum);
		}
		for(i=0;i<n;i++){
			sum=0;
			for(o=0;o<n;o++){
				sum+=a[o][i];
			}
			sum1+=sum;
			printf("%5d",sum);
		}
		printf("%5d\n",sum1);
	}
return 0;
}

Measured memory_bytes: 624
import math
from decimal import Decimal
from sys import stdin


def get_result(data):
    A, B = data
    return int(A * B)


if __name__ == '__main__':
    data = stdin.readline().rstrip().split(' ')
    data = [int(data[0]), Decimal(data[1])]
    result = get_result(data)
    print(result)


Measured memory_bytes: 10016
package main
import "fmt"
func main() {
  var n int
  var t,u int64
  fmt.Scan(&n)
  fmt.Scan(&u)
  for i:=1;i<n;i++ {
    fmt.Scan(&t)
    u = lcm(u,t)
  }
  fmt.Println(u)
}
func lcm(x int64,y int64) int64 {
  var gcd int64 = gcd(x,y)
  return (x/gcd)*y
}
func gcd(x int64,y int64) int64 {
  if x < y { return gcd(y,x) }
  if x%y == 0 { return y }
  return gcd(y,x%y)
}

Measured memory_bytes: 512
/*
	0061:Rank Checker
*/
#include	<cstdio>
#include	<iostream>
#include	<vector>
#include	<utility>
#include	<algorithm>

using namespace std;

typedef vector< pair<int, int> > VPII;

int main(void) {
	VPII numPointSet;		/*Storage of team-num and points*/
	VPII numRankSet;		/*Storage of team-num and rank*/
	
	/*Input data*/
	while(1) {
		int a, b;
		
		scanf("%d,%d", &a, &b);
		if(a == 0 && b == 0) { break; }
		
		numPointSet.push_back( pair<int, int>(b, a) );
	}
	
	/*Sort and make rank*/
	sort( numPointSet.begin(), numPointSet.end() );
	VPII::reverse_iterator it = numPointSet.rbegin();
	int pointST = it->first;
	int rank = 1;
	
	while(it != numPointSet.rend()) {
		if(pointST != it->first) {
			++rank;
			pointST = it->first;
		}
		numRankSet.push_back( pair<int, int>( it->second, rank ) );
		++it;
	}
	sort( numRankSet.begin(), numRankSet.end() );
	
	while(1) {
		int a;
		
		cin >> a;
		if( cin.eof() ) { break; }
		
		cout << numRankSet[a-1].second << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1248
#include <stdio.h>
#include <math.h>
 
//#define getchar_unlocked()  getchar()
int in()
{
    int n = 0, c = getchar_unlocked();
    do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
    return n;
}
 
int main()
{
    int N, i, a, r, ans;
 
    N = in();
    ans = 0;
    while (N--) {
        a = in();
        if (a == 2) ans++;
        else if (a&1) {
            r = (int)sqrt(a);
            for (i = 3; ; i+=2) {
                if (i > r) { ans++; break; }
                if (a%i == 0) break;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 2700
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct card {
    char string;
    int number;
};

int main() {
    struct card input[100], bubble[100], selection[100], Tmp;
    int i = 0, j, k, n, m, l, key, minj, count;

    // カードの枚数
    scanf("%d", &n);
    key = n;

    while ( key-- ) {
        scanf(" %c%d", &input[i].string, &input[i].number);
        bubble[i].string = input[i].string;
        selection[i].string = input[i].string;
        bubble[i].number = input[i].number;
        selection[i].number = input[i].number;
        i++;
    }

    // bubble sort
    int flag = 1;

    while (flag) {
        flag = 0;
        for (j = n-1; j > 0; j--) {
            if (bubble[j].number < bubble[j-1].number){
                Tmp = bubble[j];
                bubble[j] = bubble[j-1];
                bubble[j-1] = Tmp;
                flag = 1;
                count++;
            }
        }
        i++;
    }

    // 選択ソート
    count = 0;
    flag = 0;
    for (i = 0; i < n; i++) {
        minj = i;
        for (j = i; j < n; j++) {
            // 配列要素の中で最小値を見つけ、indexをminjに保持
            if (selection[j].number < selection[minj].number) {
                minj = j;
            }
        }

        if (minj != i) {
            // 要素を交換する
            Tmp = selection[i];
            selection[i] = selection[minj];
            selection[minj] = Tmp;

            // 交換回数をカウントアップ
            count++;
        }
    }

    // 結果を表示

    // bubble
    printf("%c%d", bubble[0].string, bubble[0].number);
    for (i = 1; i < n; i++) {
        printf(" %c%d", bubble[i].string, bubble[i].number);
    }
    printf("\nStable\n");

    // selection
    printf("%c%d", selection[0].string, selection[0].number);
    for (i = 1; i < n; i++) {
        printf(" %c%d", selection[i].string, selection[i].number);
    }
    for (i = 0; i < n; i++) {
        if (bubble[i].string != selection[i].string){
            printf("\nNot stable\n");
            break;
        }
    }
    if (i == n) printf("\nStable\n");

    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

int main() {
    #ifdef LOCAL
    assert(freopen("a.in", "r", stdin));
    #else
    #endif
    string s;
    cin >> s;
    set<char> S;
    for (auto c: s)
        S.insert(c);
    if (S.count('N') != S.count('S') || S.count('W') != S.count('E'))
        cout << "No\n";
    else
        cout << "Yes\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  string S;
  unordered_map<string, int> count;
  long result = 0;
  
  int i = 0;
  while(i < N) {
    cin >> S;
    sort(S.begin(), S.end());
    if (count[S] > 0 ) {
      result += count[S];
    }
    count[S]++;
    i++;
  }

  cout << result << endl;
}


Measured memory_bytes: 10660
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    A = [list(map(int, input().split())) + [i] for i in range(m)]
    B = [''] * m
    A.sort()
    count = 0
    i, x = 1, 1
    for a in A:
        if a[0] == i:
            B[a[2]] = '{:06}{:06}'.format(a[0], x)
        else:
            i, x = a[0], 1
            B[a[2]] = '{:06}{:06}'.format(a[0], x)
        x += 1
    print('\n'.join(B))


if __name__ == '__main__':
    main()

Measured memory_bytes: 34216
import math

N, K = map(int, input().split())

# print(N)
# print(K)

A = 0
B = []

a = 0

for n in range(1, N+1):
    if K/n > 1:
        i = math.ceil(math.log2(K/n))
        a += 2 ** (N+1-i)
        B.append(a)
    else:
        a += 2 ** (N+1) * (N + 1-n)
        break

# for n in range(1, N+1):
#     if K/n <= 1:
#         i = 0
#     else:
#         i = math.ceil(math.log2(K/n))
#     a += 2 ** (N+1-i)

    #A += 1/(2**i)
# print(A)
# print(A*(1/N))

print(a/(2**(1+N))/N)


Measured memory_bytes: 16500
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 4010;
LL MOD = 1000000007;
LL table[MAXN][MAXN];
//LL comb[MAXN][MAXN];

vector<LL> kaijo;

void init(int N) {
	kaijo.push_back(1);
	for(LL i=1; i<10000; i++) {
		kaijo.push_back(kaijo.back() * i % MOD );
	}
	/*
	for(int i=0; i<N; i++) {
		for(int j=0; j<N; j++) {
			comb[i][j] = 0;
		}
		
	}
	for(int i=0; i<N; i++) {
		comb[i][0] = 1;
		comb[i][i] = 1;
	}
	for(int i=2; i<N; i++)
		for(int j=1; j<i-1; j++) {
			comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
			comb[i][j] %= MOD;
		}
	*/
	
}
//高速べき乗
LL Power(LL N, LL t){	
	N%=MOD;
	LL ret = 1;
	while(t){
		if(t&1) ret*=N, ret%=MOD;
		N*=N;
		N%=MOD;
		t/=2;
	}
	return ret;	
}

//MODの中での割り算(MODは素数であること
//(a/b)mod(MOD=p) を求める
LL mod_frac(LL a,LL b){
	return (a* Power(b,MOD-2))%MOD;
}


LL calc(LL n, LL k) {
	return kaijo[n] * mod_frac(1, kaijo[k]) % MOD * mod_frac(1, kaijo[n-k]) % MOD;
	
}



int main() {
	init(10000);
	for(int i=0; i<MAXN; i++) {
		for(int j=0; j<MAXN; j++)
			table[i][j] = 0;
	}
	int N;
	cin >> N;
	LL ans = 0;
	LL P = 2003;
	for(int i=0; i<N; i++) {
		int a,b;
		cin >> a  >> b;
		ans -= calc(2*a + 2*b, 2*a);
		table[P+a][P+b]++;
	}
	for(int i=MAXN-1; i>=1; i--)
		for(int j=MAXN-1; j>=1; j--) {
		table[i][j] %= MOD;
		table[i][j-1] += table[i][j];
		table[i-1][j] += table[i][j];
	}
	
	for(int i=-P; i<P; i++) {
		ans += table[P+i][P-i] * table[P-i][P+i] % MOD;
	}
	ans %= MOD;
	ans += MOD;
	ans %= MOD;
	ans = mod_frac(ans, 2);
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 126080
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(llint a, llint b) {
	return a > b;
}

int main() {
	int h, w;
	cin >> h >> w;
	vector<string>s(h);
	rep(i, h) {
		cin >> s[i];
	}

	UnionFind Uni(h * w);
	rep(i, h) {
		rep(j, w) {
			if (i != 0) {
				if (s[i][j] != s[i - 1][j]) {
					Uni.connect(i * w + j, i * w + j - w);
				}
			}
			if (i != h - 1) {
				if (s[i][j] != s[i + 1][j]) {
					Uni.connect(i * w + j, i * w + j + w);
				}
			}
			if (j != 0) {
				if (s[i][j] != s[i][j - 1]) {
					Uni.connect(i * w + j, i * w + j - 1);
				}
			}
			if (j != w - 1) {
				if (s[i][j] != s[i][j + 1]) {
					Uni.connect(i * w + j, i * w + j + 1);
				}
			}
		}
	}
	vpint a(h * w, { 0,0 });
	rep(i, h) {
		rep(j, w) {
			if (s[i][j] == '#') {
				a[Uni.root(i * w + j)].first++;
			}
			else {
				a[Uni.root(i * w + j)].second++;
			}
		}
	}
	llint ans = 0;
	rep(i, h * w) {
		ans += (llint)a[i].first * a[i].second;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

ll ppow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
ll fact[300000];
ll Ppow[300000];
void fact_init(int n){
	fact[0]=1;for(int i=1;i<=n;i++)fact[i]=(fact[i-1]*i)%MOD;
	for(int i=0;i<=n;i++){
		Ppow[i]=ppow(fact[i],MOD-2);
	}
}
ll nCr(ll n,ll r){
	return fact[n+r]*Ppow[n]%MOD*Ppow[r]%MOD;
}

ll dp[4000][2];
P p[4000];

int main(){
	fact_init(250000);
	int h,w;scanf("%d%d",&h,&w);
	int n;scanf("%d",&n);
	rep(i,n){
		scanf("%d%d",&p[i].first,&p[i].second);
		p[i].first--;
		p[i].second--;
	}
	sort(p,p+n);
	rep(i,n)dp[i][1]=nCr(p[i].first,p[i].second);
	rep(i,n)rep(j,2){
		for(int k=i+1;k<n;k++){
			if(p[k].second>=p[i].second)
			(dp[k][!j]+=dp[i][j]*nCr(p[k].first-p[i].first,p[k].second-p[i].second))%=MOD;
		}
	}
	ll ans=0;
	rep(i,n){
		(ans+=dp[i][1]*nCr(h-1-p[i].first,w-1-p[i].second)%MOD)%=MOD;
		ans+=MOD;
		(ans-=dp[i][0]*nCr(h-1-p[i].first,w-1-p[i].second)%MOD)%=MOD;
	}
	cout<<(nCr(h-1,w-1)+MOD-ans)%MOD<<endl;
}

Measured memory_bytes: 4608
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    n, m = map(int, readline().rstrip().split())
    A = [-1] + [int(readline().rstrip()) for _ in range(m)] + [n + 1]
    num = 10 ** 5 + 10
    # num = 10
    aList = [0] * (num)
    aList[0] = 1
    aList[1] = 1
    aList[2] = 2
    for i in range(3, num):
        aList[i] = aList[i - 1] + aList[i - 2]
    sumA = 1
    for j in range(m + 1):
        if A[j + 1] - 1 == A[j]:
            print(0)
            return
        sumA = (sumA * aList[(A[j + 1] - 1) - (A[j] + 1)]) % (10 ** 9 + 7)
    print(sumA)


if __name__ == '__main__':
    main()


Measured memory_bytes: 469964
#include<iostream>
#include<climits>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;

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

int g[10][10];
int n;
int ans;
int m[10];
int flag[10];
int p[10];

void solve(int pos, int nn){
  int now = p[nn - 1];
  if(nn == n){
    ans = min(ans, now);
  }else if(now < ans){
    REP(i,n) if(!flag[i]){
      int dst = 0;
      flag[i] = 1;
      m[nn] = i;
      REP(j, nn) dst = max(dst, p[j] + g[i][m[j]]);
      p[nn] = dst;
      solve(i, nn + 1);
      flag[i] = 0;
    }
  }
}

int main(){
  while(scanf("%d", &n), n){
    REP(i,n) REP(j,n)
      scanf("%d", &g[i][j]);
    REP(i,n) REP(j,n)
      g[i][j] = max(g[i][j], g[j][i]);

    ans = INT_MAX;

    REP(i,n){
      m[0] = i;
      flag[i] = 1;
      solve(i, 1);
      flag[i] = 0;
    }
    printf("%d\n", ans);
  }
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	int R;
	cin >> R;
	cout << 2 * (float)R * acos(-1) << "\n";

}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 3772
#include <stdio.h>
#include <stdlib.h>
int count=0;

int judge(long long int data,int n,int a,int b,int c)
{
    if(data>n)
        return 0;
    if(a==1&&b==1&&c==1)
    {
        count++;
    }
    judge(data*10+3,n,1,b,c);
    judge(data*10+5,n,a,1,c);
    judge(data*10+7,n,a,b,1);

    return 0;
}
int main()
{
    int t;
    scanf("%d",&t);
    judge(0,t,0,0,0);
    printf("%d\n",count);
    return 0;


}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines  

import numpy as np

def shake_cnt(x):
  # 両手x - 左手の価値 = 右手の価値
  # x - a[i]未満の個数(行わない握手)を数える
  # X以上の和がM個未満かどうか
  X = np.searchsorted(A, x-A)
  return (N - X).sum()
  

N, M = map(int, input().split())
A = np.array(input().split(),np.int64)
A.sort()

left = 0 # 握手の回数がM以上
right = 10 ** 6 # 握手の回数がM未満
while left + 1 < right:
    x = (left + right) // 2
    if shake_cnt(x) < M:
        right = x
    else:
        left = x

# 終了時にngにX-1,okにXが入っている。

X = np.searchsorted(A,right-A) # 行わない人数
Acum = np.zeros(N+1,np.int64) # 人数 -> 累積和
Acum[1:] = np.cumsum(A)

# right(最大値) 以上の握手を全て行ったとして、回数と総和を計算
# N**2通りの握手から価値の高い上位の握手  

shake = N * N - X.sum() # 総数-行わない人数
happy = (Acum[-1] - Acum[X]).sum() + (A * (N - X)).sum()
happy += (M - shake) *left
print(happy)

Measured memory_bytes: 17880
N, M = map(int, input().split())

bridge1 = []
bridge1_right = set()
bridge2 = []
bridge2_left = set()
for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        bridge1.append((a, b))
        bridge1_right.add(b)
    if b == N:
        bridge2.append((a, b))
        bridge2_left.add(a)

if len(bridge1) == 0 or len(bridge2) == 0:
    print('IMPOSSIBLE')
    exit()

if len(bridge1_right & bridge2_left) > 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 35080
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

int main(){
	long long A, B, C; std::cin >> A >> B >> C;
	if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0)
		std::cout << 0 << std::endl;
	else
		std::cout << std::min({A * B, B * C, C * A}) << std::endl;
	
	return 0;
}

Measured memory_bytes: 3636
def calc(days):
    if sum(days) == 0:
        return
    profit = 0
    for i in range(N):
        both = 0
        for f, d in zip(F[i], days):
            if f == d == 1:
                both += 1
        profit += P[i][both]
    global ans
    ans = max(ans, profit)


def dfs(days):
    if len(days) == 10:
        calc(days)
        return
    dfs(days + [0])
    dfs(days + [1])


ans = 10 ** 9 * (-1)
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

dfs([])
print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int c[9];
int main() {
  int n;
  cin >> n;
  rep(i,n){
    int a;
    cin >> a;
    a /= 400;
    c[min(a,8)]++;
  }
  int ans = 0;
  rep(i,8) if(c[i]>0) ++ans;
  cout << max(ans,1) << " " << ans+c[8] << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
int main(){
	double t;
	cin>>t;
	t/=3;
	printf("%.10f",t*t*t);
	RE 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll MAXN = 200005;

int h, w, a, b;
ll fact[MAXN], inv[MAXN];

ll mpow (ll bs, ll ep) {
    ll ret = 1;
    while (ep) {
        if (ep & 1) {
            ret = (ret * bs) % MOD;
        }
        bs = (bs * bs) % MOD;
        ep >>= 1;
    }
    return ret;
}

ll cob (int x, int y) {
    return fact[x+y] * inv[x] % MOD * inv[y] % MOD;
}
/********** Good Luck :) **********/
int main()
{
    IOS();

    fact[0] = 1;
    inv[0] = 1;
    REP1 (i, MAXN - 1) {
        fact[i] = fact[i-1] * i % MOD;
        inv[i] = mpow(fact[i], MOD - 2);
        assert(fact[i] * inv[i] % MOD == 1);
    }

    cin >> h >> w >> a >> b;

    ll ans = 0;
    REP (i, h-a) {
        ans = (ans + cob(i, b-1) * cob(h-i-1, w-b-1)) % MOD;
    }

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


Measured memory_bytes: 3328
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-21 16:17:12
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template <class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '(' << p.first << ", " << p.second << ')'; }
template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { int flag = 0; for (auto e : vec) os << (flag++ ? ", " : "{") << e; return os << '}'; }
template <class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { int flag = 0; for (auto e : st) os << (flag++ ? ", " : "{") << e; return os << '}'; }
template <class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { int flag = 0; for (auto e : mp) os << (flag++ ? ", " : "{") << e; return os << '}'; }
template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { for (T& e : vec) is >> e; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

inline unsigned int fast_gcd(unsigned int x, unsigned int y) {
  int shift;
  if (x == 0) return y;
  if (y == 0) return x;
  shift = __builtin_ctz(x | y);
  x >>= __builtin_ctz(x);
  do {
    y >>= __builtin_ctz(y);
    if (x > y) {
      unsigned int t = y;
      y = x;
      x = t;
    }
    y -= x;
  } while (y);
  return x << shift;
}

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

  unsigned int k; cin >> k;
 
  unsigned long long ans = 0;
 
  for (unsigned int a = 1; a <= k; ++a) {
    for (unsigned int b = 1; b <= k; ++b) {
      for (unsigned int c = 1; c <= k; ++c) {
        ans += fast_gcd(a, fast_gcd(b, c));
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3600
// AtCoder Beginner Contest 126 - Problem F: XOR Matching (https://atcoder.jp/contests/abc126/tasks/abc126_f)
#include <bits/stdc++.h>

using namespace std;

set<int> bits(int x)
{
    set<int> bs;

    while (x)
    {
        bs.insert(x & -x);
        x &= (x - 1);
    }

    return bs;
}

vector<int> solve(int N, int K)
{
    if (K >= (1 << N))
        return { };

    vector<int> ans(1 << (N + 1));

    for (int i = 0; i < 1 << N; ++i)
    {
        ans[2*i] = i;
        ans[2*i + 1] = i;
    }

    if (K == 0)
        return ans;

    auto bs = bits(K);

    list<int> xs;
    xs.push_back(K);

    if (bs.size() == 1)
    {
        if (K == 1 and 3 >= (1 << N))
            return { };

        bs.clear();

        if (K == 1)
        {
            bs.insert(2);
            bs.insert(3);
        } else
        {
            if (K + 1 >= (1 << N))
                return { };

            bs.insert(K + 1);
            bs.insert(1);
        }
    }

    for (int i = 0; i < (1 << N); ++i)
        if (bs.count(i) == 0 and i != K)
        {
            xs.push_front(i);
            xs.push_back(i);
        }

    for (auto b : bs)
    {
        xs.push_front(b);
        xs.push_back(b);
    }

    xs.push_back(K); 

    return vector<int>(xs.begin(), xs.end());
}

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

    auto ans = solve(N, K);

    if (ans.empty())
        cout << "-1\n";
    else
        for (size_t i = 0; i < ans.size(); ++i)
            cout << ans[i] << (i + 1 == ans.size() ? '\n' : ' ');

    return 0;
}


Measured memory_bytes: 11004
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

using namespace std;

int main() {
  string s;
  cin >> s;
  if(s[0] == s[1] && s[1] == s[2]) cout << "Yes" << endl;
  else if(s[1] == s[2] && s[2] == s[3]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vi A, B;
string S, T;

void input() {
  int x, y, z;
  ;
  cin >> N;
}
void solve() {
  int a = 1;
  int i;
  for (i = 0; i < N; ++i) {
    a <<= 1;
    if (a > N) {
      break;
    }
  }
  cout << a / 2 << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

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

	vector<bool> a(n, false);

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

	int count = 0;
	for(int i=0;i<n;i++){
		if(a[i] == false) count++;
	}
	cout << count << "\n";
}

Measured memory_bytes: 3644
#C
import math
k = int(input())
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        ij = math.gcd(i, j)
        for l in range(1, k + 1):
            ans += math.gcd(l, ij)
print(ans)


Measured memory_bytes: 9032
#include<iostream>
#include<algorithm>
#include<cmath>//不知哪个是max
using namespace std ;
int n, t, ans, maxn, lastans;//ans是高桥的收益， lastans是最终答案
int a[100010];
int main(){
    cin >> n >> t;
    for(int i=1; i<=n; i++) cin >> a[i];
    for(int i=n; i; i--){maxn=max(a[i], maxn); ans=max(maxn-a[i], ans);}//这里求出高桥君的最大收益。
    maxn=0;//清零
    for(int i=n; i; i--){maxn=max(a[i], maxn); if(maxn-a[i]==ans) lastans++;}//这里求那个捣乱的青木君的最小代价。
    cout << lastans << endl;//输出
    return 0 ;//（@ o @）卖个萌
}

Measured memory_bytes: 640
/*
 * @Author: Kaizyn
 * @Date: 2020-03-22 20:57:41
 * @LastEditTime: 2020-03-22 21:21:18
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const int N = 3e3+7;
const int MOD = 998244353;
const double eps = 1e-7;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> pii;

template <int _MOD> struct Mint
{
    int v = 0;
    Mint() {}
    Mint(int _v) : v((_v%_MOD+_MOD)%_MOD) {}
    Mint(long long _v) : v(static_cast<int>((_v%_MOD+_MOD)%_MOD)) {}
    Mint operator = (const int &_v) { return *this = Mint(_v); }
    Mint operator = (const long long &_v) { return *this = Mint(_v); }
    bool operator ! () const { return !this->v; }
    bool operator < (const Mint &b) const { return v < b.v; }
    bool operator > (const Mint &b) const { return v > b.v; }
    bool operator == (const Mint &b) const { return v == b.v; }
    bool operator != (const Mint &b) const { return v != b.v; }
    bool operator <= (const Mint &b) const { return v < b.v || v == b.v; }
    bool operator >= (const Mint &b) const { return v > b.v || v == b.v; }
    Mint operator + (const Mint &b) const { return Mint(v+b.v); }
    Mint operator - (const Mint &b) const { return Mint(v-b.v); }
    Mint operator * (const Mint &b) const { return Mint(1ll*v*b.v); }
    Mint operator / (const Mint &b) const { return Mint(b.inv()*v); }
    Mint& operator += (const Mint &b) { return *this = *this+b; }
    Mint& operator -= (const Mint &b) { return *this = *this-b; }
    Mint& operator *= (const Mint &b) { return *this = *this*b; }
    Mint& operator /= (const Mint &b) { return *this = *this/b; }
    Mint operator - () const { return Mint(-v); }
    Mint& operator ++ () { return *this += 1; }
    Mint& operator -- () { return *this -= 1; }
    Mint operator ++ (int) { Mint tmp = *this; *this += 1; return tmp; }
    Mint operator -- (int) { Mint tmp = *this; *this -= 1; return tmp; }
    Mint pow(int p) const {
        Mint res(1), x(*this);
        while (p) {
            if (p&1) res = res*x;
            x *= x;
            p >>= 1;
        }
        return res;
    }
    Mint inv() const { return pow(_MOD-2); }
    friend istream& operator >> (istream &is, Mint &mt) { return is >> mt.v; }
    friend ostream& operator << (ostream &os, const Mint &mt) { return os << mt.v; }
};
using mint = Mint<MOD>;

int n, s;
int a[N];
mint cnt[N];

inline void solve()
{
    cin >> n >> s;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    mint res = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] > s) continue;
        if (a[i] == s) {
            res += i*(n-i+1);
            continue;
        }
        res += cnt[s-a[i]]*(n-i+1);
        for (int j = s-a[i]-1; j; --j) {
            cnt[j+a[i]] += cnt[j];
        }
        cnt[a[i]] += i;
    }
    cout << res << endl;
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int testcase = 1;
    // cin >> testcase;
    for (int i = 1; i <= testcase; ++i) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int n,i,j,h,w[10],l[10],t,u[10];
    char q[11],g;
    while(1){
        for(i=0;i<10;i++){
            w[i]=0; l[i]=0;
        }   
        scanf("%d",&n);
        if(n==0) break;
            for(i=0;i<n;i++){
				u[i]=i;
                scanf(" %c",&q[i]);
                for(j=0;j<n-1;j++){
                    scanf("%d",&h);
                    if(h==0) w[i]++;
                    if(h==1) l[i]++;
                }
            }
            for(i=0;i<n-1;i++){
                for(j=i+1;j<n;j++){
                    if(w[i]<w[j]||(w[i]==w[j]&&l[i]>l[j])||(w[i]==w[j]&&l[i]==l[j]&&u[i]>u[j])){
                        t=w[i]; w[i]=w[j]; w[j]=t;
                         
                        t=l[i]; l[i]=l[j]; l[j]=t;
                         
                        t=u[i]; u[i]=u[j]; u[j]=t;
                     
                        g=q[i]; q[i]=q[j]; q[j]=g;
                    }               
                }   
            }       
            for(i=0;i<n;i++) printf("%c\n",q[i]);
    }
    return 0;
}

Measured memory_bytes: 2596
#include <cstdio>

const int MAXN = 1e2+2, MAXK = 1e5+5;
const int MOD = 1e9+7;

int n, k;
int dp[MAXN][MAXK], pre[MAXN][MAXK];
bool solved[MAXN][MAXK];
int a[MAXN];


int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
  }

  for (int j = 0; j <= k; ++j) {
    dp[0][j] = j <= a[0] ? 1 : 0;
  }
  pre[0][0] = dp[0][0];
  for (int j = 1; j <= k; ++j) {
    pre[0][j] = (pre[0][j-1] + dp[0][j]) % MOD;
  }

  for (int i = 1; i < n; ++i) {
    for (int j = 0; j <= k; ++j) {
      dp[i][j] = pre[i-1][j] - ((j-a[i]-1) < 0 ? 0 : pre[i-1][j-a[i]-1]);
      dp[i][j] %= MOD;
      if (dp[i][j] < 0) dp[i][j] += MOD;
    }
    pre[i][0] = dp[i][0];
    for (int j = 1; j <= k; ++j) {
      pre[i][j] = (dp[i][j] + pre[i][j-1]) % MOD;
    }
  }

  printf("%d\n", dp[n-1][k]);
  return 0;
}


Measured memory_bytes: 80896
#define _USE_MATH_DEFINES
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>


using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const long long int INF=1001001001001001001;
int a[3];

int main(){
	scanf("%d %d %d",&a[0],&a[1],&a[2]);
	sort(a,a+3);
	if(a[0]==5&&a[1]==5&&a[2]==7)printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
N, M = list(map(int, input().split(' ')))
A = list(map(int, input().split(' ')))
A_ = [-1 * num for num in A]

import heapq
import math

heapq.heapify(A_)

for k in range(M):
    maxA_ = heapq.heappop(A_)
    heapq.heappush(A_, math.ceil(maxA_ / 2))
    #print(maxA_, math.ceil(maxA_ / 2))
    #print(A_)
print(sum(A_) * (-1))

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int > pp;
typedef long long ll;
 
int const N=1e5+2,oo=1e9;
ll const OO=2e18;
double const eps=1e-8,PI=acos(-1);
int mod=oo+7;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll k,a,b;
    cin>>k>>a>>b;
    if(a>=b)cout<<k+1<<endl;
    else{
        if(k<=a)cout<<k+1<<endl;
        else{
            ll res=k+1;
            k-=a-1;
            res=max(res,(k/2)*b-(k/2-1)*a+(k&1));
            cout<<res<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 256
s=input()
n=len(s)

for i in range(n-1):
  t=s[i:i+2]
  if t[0]==t[-1]:
    print(i+1,i+2)
    exit(0)

for i in range(n-2):
  t=s[i:i+3]
  if t[0]==t[-1] and t[0]!=t[1]:
    print(i+1,i+3)
    exit(0)
print(-1,-1)


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



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll n;
    cin>>n;
    ll a[n];
    ll ans = 0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        ans += a[i] - i-1;

    }
    cout << ans << endl;
}



Measured memory_bytes: 3996
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
ll dp[100010];
ll h[100010];

int main() {
    int N, K;
    cin >> N >> K;
    for(int i = 1;i <= N; i++){
        cin >> h[i];
    }
    
    dp[0] = INF;
    dp[1] = 0;
    for(int i = 2; i <= N; i++){
        for(int j = 1; j <= K; j++){
            if(j == 1){
                dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
            }else{
                if(i-j >= 0){
                    dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
                }
            }
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	string s;
	cin >> s;
	
	if(s[0] == s[1] || s[0] == s[2] || s[1] == s[2])
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n; cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0 ) sum+=i;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3608
// ABC 156-D
// 2020.2.23 bal4u

#include <stdio.h>

typedef long long ll;

#define M 1000000007

int pow_mod(int b, int p) {
   int r = 1;
   while (p) {
      if (p & 1) r = (ll)r * b % M;
      b = (ll)b * b % M;
	  p >>= 1;
   }
   return r;
}

#define MOD 1000000007
#define MAX 200005
int fact[MAX] = {1,1};
int inv[MAX] = {1,1};
int factinv[MAX] = {1,1};

int comb(int n, int a, int b) {
	int i, t, ans = 1;
	for (i = 0; i < a; ++i) ans = (ll)ans * (n-i) % M;
	t = 1;
	for (; i < b; ++i) t = (ll)t * (n-i) % M;
	return (ll)ans * (factinv[a] + (ll)t*factinv[b]%M) % M;
}

int main()
{
	int i, n, a, b;
	ll ans;

	scanf("%d%d%d", &n, &a, &b);
	for (i = 2; i <= b; i++) {
		fact[i] = (ll)fact[i-1]*i % M;
		inv[i] = -(M/i)*(ll)inv[M%i] % M;
		factinv[i] = (ll)factinv[i-1]*inv[i] % M;
	}
	ans = ((ll)pow_mod(2, n) - 1 - comb(n, a, b)) % M;
	if (ans < 0) ans += M;
	printf("%d\n", (int)ans);
	return 0;
}


Measured memory_bytes: 2560