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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
typedef long long ll;

int main() {
    int n, min_abs = -1, neg_cnt = 0;
    cin >> n;
    vector<int> a(n);
    ll ans = 0;
    rep(i, n){
        cin >> a[i];
        ans += abs(a[i]);
        if(min_abs == -1 || min_abs > abs(a[i])) min_abs = abs(a[i]);
        if(a[i] < 0) neg_cnt++;
    }
    if(neg_cnt % 2 == 0){
        cout << ans << el;
    }else {
        cout << ans - (min_abs*2) << el;
    }
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
from sys import stdin

in_strings = lambda: stdin.readline()[:-1] # s = in_strings()
in_int = lambda: int(stdin.readline()) # N = in_int()
in_intlist = lambda: list(map(int, stdin.readline().split())) # List = in_intlist()

N, M, K = in_intlist()

for n in range(N+1):
    if n == N/2:
        continue
    if (K - M*n) / (N - 2*n) == (K - M*n) // (N - 2*n):
        if 0 <= (K - M*n) / (N - 2*n) <= M:
            print('Yes')
            exit()

print('No')


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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int INF = 1000000007;
const ll MOD = 1000000007;

void solve_test()
{
    int x;
    cin >> x;
    cout << (x^1);
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int tests;
    tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve_test();
    }
    return 0;
}


Measured memory_bytes: 3648
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")



#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include <ext/rope>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define Find order_of_key
// #define at find_by_order
#define x first
#define y second
#define ll long long
#define lll __int128
#define ull unsigned long long
#define ulll unsigned __int128
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#define gu getchar_unlocked()
#define pu putchar_unlocked()
#define all(x) x.begin(),x.end()
#define endl '\n'
const ll mod=1000000007;
ll Pow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}return res;
}

int main()
{
	ll n;
	cin>>n;
	ll a=Pow(10,n);
	ll b=Pow(9,n);
	ll c=Pow(8,n);
	ll an=a-b-b+c;
	an%=mod;
	if(an<0)an+=mod;
	cout<<an<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,c=0;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    c+=a[i];
  }
  if(c%10!=0)
    cout<<c;
  else{
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++){
      if((c-a[i])%10!=0){
        cout<<c-a[i];
        return 0;
      }
    }
    cout<<0;
  }
}

Measured memory_bytes: 256
# abc112_c

def main():
    N=int(input())
    xyh=[]
    
    for i in range(N):
        a=[int(i) for i in input().split()]
        xyh.append(a)
    
    xyh.sort(key=lambda x:x[2],reverse=True)
    
    flag2=True
    for i in range(0,101):
        for j in range(0,101):
            flag=True
            H=xyh[0][2]+abs(xyh[0][0]-i)+abs(xyh[0][1]-j)
            for k in range(1,N):
                if xyh[k][2]!=max(0,H-abs(xyh[k][0]-i)-abs(xyh[k][1]-j)):
                    flag=False
                    break
            
            if flag:
                print("{} {} {}".format(i,j,H))
                flag2=False
                break
        if not flag2:
            break

if __name__ == "__main__": main()

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

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> D(10);
  int d;
  for (int i = 0; i < K; i++)
  {
    cin >> d;
    D[d] = 1;
  }

  for (int i = N; N <= 10000; i++)
  {
    int c = i;
    while (c && !D[c % 10])
      c /= 10;

    if (c == 0)
    {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define FOR(i,n) for(int i = 0; i < n; i++)
#define FORa(i,a,b) for(int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a,n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define UP(s) transform(s.begin(),s.end(),s.begin(),::toupper)

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

int main() {
	ll x, k;
	cin >> x >> k;

	cout << (x%k < abs(x%k-k) ? x%k : abs(x%k-k)) << endl;
  
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset> 
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll qpow(ll a,ll b)
{
	if(b==0) return 1;
	ll c=qpow(a,b/2);
	if(b%2==0) return c*c%mod;
	else return c*c%mod*a%mod;
} 
ll fac[2000006]={0};
char s[2000006];
ll cnm(ll n,ll m)
{
	return fac[n]*qpow(fac[n-m],mod-2)%mod*qpow(fac[m],mod-2)%mod;
}
int main(void)
{
	fac[0]=1;
	for(ll i=1;i<=2000000;i++)
	{
		fac[i]=fac[i-1]*i%mod;
	}
	ll ans=0;
	ll n,k;
	scanf("%lld %s",&k,s);
	n=strlen(s);
	for(ll i=0;i<=k;i++)
	{
		ans+=cnm(n+i-1,n-1)*qpow(25,i)%mod*qpow(26,k-i)%mod;
	}
	printf("%lld\n",ans%mod);
}

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

using namespace std;

int N;

void addEdge(int n, int m){
    cout << n << " " << m << "\n";
}

int main(){
    cin >> N;
    if((1<<__builtin_ctz(N)) == N){
        cout << "No" << "\n";
        return 0;
    }
    cout << "Yes" << "\n";

    for(int i = 2; i<N; i+=2){
        addEdge(i, 1);
        addEdge(i+1, 1);
        addEdge(i, i+1+N);
        addEdge(i+1, i+N);
    }
    addEdge(N+2, N+1);
    if(N&1^1){
        int b = 31 - __builtin_clz(N);
        addEdge(N, (1<<b));
        addEdge(N+N, (1<<b)^N^1);
    }
}


Measured memory_bytes: 2304
from sys import stdin, stdout

input = lambda: stdin.readline().rstrip()
write = stdout.write

def main():
    H, W = map(int, input().split())
    A = stdin.read().splitlines()

    def func(a):
        ret = []
        for s in a:
            if s.count('#'):
                ret.append(s)
        return ret

    ans = func(list(zip(*A)))
    ans = func(list(zip(*ans)))
    for s in ans:
        print(*s, sep='')

main()


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

typedef long long int ll;
ll mod = 1000000000 + 7;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    
    int c[n][3] = {0};
    vector<int> seq(n, 0);

    for(int i = 0; i < n; i++){
        if(s[i] == 'R') seq[i] = 0;
        if(s[i] == 'G') seq[i] = 1;
        if(s[i] == 'B') seq[i] = 2;
    }

    for(int i = n - 1; i >= 0; i--){
        for(int j = 0; j < 3; j++) c[i][j] = i == n - 1 ? 0 : c[i + 1][j];
        if(s[i] == 'R') c[i][0] = i == n - 1 ? 1 : c[i + 1][0] + 1;
        if(s[i] == 'G') c[i][1] = i == n - 1 ? 1 : c[i + 1][1] + 1;
        if(s[i] == 'B') c[i][2] = i == n - 1 ? 1 : c[i + 1][2] + 1;
    }

    // for(int j = 0; j < 3; j++) {
    //     for(int i = 0; i < n; i++)
    //         cout << c[i][j] << " ";
    //     cout << endl;
    // }

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

    ll ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            if(seq[i] == seq[j]) continue;

            unordered_set<int> check = {0, 1, 2};
            check.erase(seq[i]); check.erase(seq[j]);
            int other = *check.begin();
            // cout << i << " " << j << " " << " : " << j + j - i << " " << other << endl;

            if(j + 1 < n) ans += c[j + 1][other];
            if(j + (j - i) < n && seq[j + (j - i)] == other) ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3700
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

// must include vector and cmath
int main(int argc, char const *argv[]) {
  long long N;
  cin >> N;

  long long A, B;
  A = 1;
  B = N;
  long long root = sqrt(N);
  for (int i = 2; i <= root; i++) {
    if (N % i == 0) {
      A = i;
      B = N / i;

      if (A >= B) {
        break;
      }
    }
  }

  long long ans = 1;
  long long bigger = A > B ? A : B;
  while (true) {
    bigger /= 10;
    if (bigger == 0) {
      break;
    }
    ans++;
  }

  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;

int f(int n)
{
    if ((n % 2) == 0)
    {
        return n / 2;
    }
    else
    {
        return 3 * n + 1;
    }
}

int main()
{
    fastio;
    int s;
    cin >> s;

    set<int> nums;

    auto a = s;
    int m = 1;
    while (nums.find(a) == nums.end())
    {
        nums.insert(a);
        a = f(a);
        m++;
    }

    cout << m << endl;
    return 0;
}


Measured memory_bytes: 256
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 1 << 30
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int main(){
    std::ios_base::sync_with_stdio(false);

    int a[4]; cin >> a[0] >> a[1] >> a[2] >> a[3];
    int one=0;
    int seven=0;
    int nine=0;
    int four=0;

    REP(i,4){
        if(a[i]==1) one++;
        if(a[i]==7) seven++;
        if(a[i]==9) nine++;
        if(a[i]==4) four++;
    }

    if(seven==1 && nine==1 && four==1 && one==1){
        cout << "YES" << endl;
    } else{
        cout << "NO" << endl;
    }

    return 0;
}


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

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

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll N, M;
  cin >> N >> M;
  vector<P> work;
  rep(i, N){
    ll A, B;
    cin >> A >> B;
    work.emplace_back(B, A);
  }
  sort(work.begin(), work.end(), greater<P>());

  set<ll> hima;
  rep(i, M) hima.insert(-i);
  ll ans = 0;
  rep(i, N){
    auto it = hima.lower_bound(-(M - work[i].second));
    if(it != hima.end()){
      ans += work[i].first;
      hima.erase(it);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int a,b,c,x;

  cin >> a;
  cin >> b;
  cin >> c;
  cin >> x;

  int ans = 0;
  int i, j, k;

  for(i = 0; i <= a; i++){
    if(i * 500 > x) {
      continue;
    }
    for(j = 0; j <= b; j++){
      if(j * 100 + i * 500 > x){
        continue;
      }

      for(k = 0; k <= c; k++){
        // cout << i << "," << j << "," << k << endl;
        if(i * 500 + j * 100 + k * 50 == x){
          ans++;
          break;
        }
      }
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
/// 11:01 PM 11/05/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>

using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define VARIABLE_ERROR(x) cout << #x << " = " << x << endl;
#define CONTAINER_ERROR(v) cout << "{";for (auto &x:v) { cout << x << ','; }cout << "}" << endl;
#define PI 3.14159265358979323846
#define M 1000000007
#define INF 1e15
typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n;
    cin >> n;
    vector<ll> v(n);
    for(auto &x:v) {
        cin >> x;
    }
    vector<ll> dp(n);
    dp[0] = 0;
    for(ll i=1;i<n;i++) {
        dp[i] = abs(v[i] - v[i-1]) + dp[i-1];
        if(i>=2) {
            dp[i] = min(dp[i], dp[i-2] + abs(v[i] - v[i-2]));
        }
    }
    cout << dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int S[2100];
int T[2100];

int DP[2100][2100];

// 負の数にも対応した % 演算

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

signed main() {
  int N, M; cin >> N >> M;
  
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> T[i];
  }

  memset(DP, 0, sizeof(DP));
  DP[0][0] = 1;

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      if (i - 1 >= 0 && j - 1 >= 0 && S[i - 1] == T[j - 1]) {
        DP[i][j] += DP[i-1][j-1];
        DP[i][j] = mod(DP[i][j], MOD);
      }
      
      if (i - 1 >= 0) {
        DP[i][j] += DP[i-1][j];
        DP[i][j] = mod(DP[i][j], MOD);
      }
      if (j - 1 >= 0) {
        DP[i][j] += DP[i][j-1];
        DP[i][j] = mod(DP[i][j], MOD);
      }
      if (i - 1 >= 0 && j - 1 >= 0) {
        DP[i][j] -= DP[i-1][j-1];
        DP[i][j] = mod(DP[i][j], MOD);
      }
      DP[i][j] = mod(DP[i][j], MOD);
    }
  }

  // DP[N][M] %= MOD;
  cout << DP[N][M] << endl;
}


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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int a, b;
	cin >> a >> b;
	if ((a == 1 || b == 1) && (b == 2 || a == 2))
	{
		cout << 3 << endl;
	}
	else if ((a == 1 || b == 1) && (b == 3 || a == 3))
	{
		cout << 2 << endl;
	}
	else if ((a == 2 || b == 2) && (a == 3 || b == 3))
	{
		cout << 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3624
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    a,b = readInts()
    print(a - b*2 if a - b*2 >= 0 else 0)
if __name__ == '__main__':
  main()


Measured memory_bytes: 5784
#include<stdio.h>
int main()
{
  int a,b,i;
  scanf("%d %d",&a,&b);
  if(a>=b)
  {
    for(i=1;i<=a;i++)
    {
      printf("%d",b);
    }
  }
  else if(b>a)
    {
    for(i=1;i<=b;i++)
    {
      printf("%d",a);
    }
  }
    return 0;
}


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

int main()
{
    long long int x,y,a,b,c,i,j,ans=0;
    cin>>x>>y>>a>>b>>c;
    long long int p[a],q[b],r[c+x+y];

    for( i=0;i<a;i++)
        cin>>p[i];

    for(i=0;i<b;i++ )
        cin>>q[i];

    for(i=0;i<c;i++)
        cin>>r[i];

    sort(p,p+a);
    sort(q,q+b);

    for(i=0;i<x;i++)
        r[c+i]=p[a-1-i];

    for(i=0;i<y;i++)
        r[c+x+i]=q[b-1-i];

    sort(r,r+(c+x+y));

    i=x+y; j= c+x+y-1;

    while(i)
    {
        ans+=r[j--];
        i--;
    }
    cout<<ans<<endl;


}



Measured memory_bytes: 3968
#include<stdio.h>

#include<string.h>

int main(void){

int num,i,count,sum;

char number[1001];

char*str;

while(1){

scanf("%s",number);

i=0;

sum=0;

str=&number;

count=(int)strlen(str);

if(number[0]=='0'){

if(count==1){

break;

}

}

while(i<count){

num=number[i]-'0';

sum=sum+num;

i++;

}

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

}

return 0;

}

Measured memory_bytes: 536
N = int(raw_input())

A_c = [int(raw_input()) for i in range(N)]

t_pairs = 0

group_count = 0
for i in range(N):
    if A_c[i] > 0:
        group_count += A_c[i]
    else:
        t_pairs += group_count // 2
        group_count = 0

print (t_pairs + group_count//2)


Measured memory_bytes: 20380
#include<stdio.h>

int main()
{
 int A,B,C,D;

 scanf("%d%d%d%d",&A,&B,&C,&D);

 if((A*B==C*D)||(A*B>C*D))printf("%d\n",A*B);
 else if(A*B<C*D)printf("%d\n",C*D);

 return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <list>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define N_MAX 1000

using namespace std;

int cnt = 0;

/* aとbの値を入れ替える */
void swap(int *a, int *b)
{
	int tmp;

	tmp = *a;
	*a = *b;
	*b = tmp;
}

/* バブルソート */
void bubble_sort(int a[], int n)
{
	int i, j;

	for (i = 0; i < n - 1; i++) {
		for (j = 0; j < n - 1 - i; j++) {
			if (a[j] > a[j + 1]) {
				swap(&a[j], &a[j + 1]);
				cnt++;
			}
		}
	}
}

int main()
{
	int n;
	int a[105];

	while (1) {
		cin >> n;
		if (n == 0) break;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		cnt = 0;
		bubble_sort(a, n);
		cout << cnt << endl;
	}

	

	return (0);
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n;
    cin>>n;
    double SqrtNum=sqrt(n);
    long long int ans=1000;
    for (long long int i=1;i<=SqrtNum;i++) {
        if (n%i==0) {
            string tmp1=to_string(i);
            string tmp2=to_string(n/i);
            long long int max_size=max(tmp1.size(),tmp2.size());
            ans=min(ans,max_size);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int N, M, K, Q, W, H, R, C;
string S;

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

    cin >> N >> K;
    vector<P> p(N);
    REP(i, N) {
        ll x, y;
        cin >> x >> y;
        p[i] = make_pair(x, y);
    }
    sort(ALL(p));
    ll ans = 4e18;
    REP(i, N) {
        FOR(j, i + 1, N) {
            FOR(k, i, j + 1) {
                ll x1 = p[i].first;
                ll x2 = p[j].first;
                ll y1 = p[k].second;
                ll num = 0;
                vector<ll> y2;
                FOR(l, i, j + 1) {
                    if (y1 <= p[l].second) {
                        num++;
                        y2.push_back(p[l].second);
                    }
                }
                if ((int)y2.size() >= K) {
                    sort(ALL(y2));
                    chmin(ans, abs(x2 - x1) * abs(y2[K - 1] - y1));
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
a,b,t = STDIN.read.chomp.split(" ")

tot_time = t.to_f + 0.5
time_span = a.to_f
buisquets_per_span = b.to_i

tot_buisquets = 0
tot_time.div(time_span).floor.times do |i|
  tot_buisquets += buisquets_per_span
end
puts tot_buisquets.to_i


Measured memory_bytes: 1788
// Problem : A - Station and Bus
// Contest : AtCoder Beginner Contest 158
// URL : https://atcoder.jp/contests/abc158/tasks/abc158_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define DEBUG(...) cerr << #__VA_ARGS__ << ": ", debug(__VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator << (ostream &os, const vector<T> &v) {os << "["; for (int i=0; i<(int)v.size(); i++) {if (i) os << ", "; os << v[i];} return os << "]";}
void debug() {cerr << "\n";} template<typename T, typename... Args> void debug(T x, Args... args) {cerr << x << "; "; debug(args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    string s;
    cin >> s;
    
    if (s[0] == s[1] && s[0] == s[2])
        cout << "No\n";
    else
        cout << "Yes\n";

    return 0;
}


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

int main(){
    int c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++) cin>>c[i][j];
    }
    int x[3],y[3];
    x[0]=0;
    for(int i=0;i<3;i++) y[i]=c[0][i];
    for(int i=0;i<3;i++) x[i]=c[i][0]-y[0];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(x[i]+y[j]!=c[i][j]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,c=1;
  cin>>n;
  string s;
  cin>>s;
  for(i=0;i<n-1;i++)
  {
    if(s.at(i)!=s.at(i+1))
    c++;
  }
  cout<<c;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-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; }

ll gcd(ll a, ll b) {
  if (b==0) return a;
  else return gcd(b,a%b);
}
ll lcm(ll a, ll b) {
  ll g=gcd(a,b);
  return a/g*b;
}

int main(){
  ll A,B,g,cnt=0;
  cin>>A>>B;
  set<ll> s;
  g=gcd(A,B);
  for(ll i=2;i*i<=g;i++){
    if(g%i==0){
      cnt++;
      while(g%i==0) g/=i;
    }
  }
  if(g!=1) cnt++;
  cout<<cnt+1<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

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

Measured memory_bytes: 3908
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
    a = input()
    if a == "AC":
        ac += 1
    if a == "WA":
        wa += 1
    if a == "TLE":
        tle += 1
    if a == "RE":
        re += 1
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))


Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const int INF=2*1e9;
ll dp[200005],a[200005],sum[200005];
int main()
{
    ll n;
    cin>>n;
    rep1(i,n) cin>>a[i];
    sum[1]=a[1];
    for(int i=2;i<=n;i++) sum[i]=sum[i-2]+a[i];
    for(int i=2;i<=n;i++)
    {
        if(i%2==1) dp[i]=max(dp[i-1],dp[i-2]+a[i]);
        else dp[i]=max(sum[i-1],dp[i-2]+a[i]);
    }
    cout<<dp[n];
}



Measured memory_bytes: 8240
// import std = require('tstl')

{
  type Print = void | string | number | string[] | number[]
  let outs: Print[] = []

  const main = (): Print => {
    const r = _io()
    const [N] = r.nn()
    const [S] = r.ss()

    if (S.length > N) {
      return S.substr(0, N) + '...'
    }

    return S
  }

  const _io = (i = 0) => {
    const str: string = require('fs').readFileSync('/dev/stdin', 'utf8')
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')

    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map((v) => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  outs.push(main())

  console.log(
    outs
      .map((line) => (typeof line === 'object' ? line.join(' ') : String(line)))
      .join('\n')
  )
}


Measured memory_bytes: 29584
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
int r,s,p;
int score(char te){
    int ans=0;
    if(te=='r')ans=p;
    if(te=='s')ans=r;
    if(te=='p')ans=s;
    return ans;
}

int main(){
    int n,k;cin>>n>>k;
    cin>>r>>s>>p;
    string t;cin>>t;
    vector<vector<char>> te(k,vector<char>(0));
    rep(i,n){
        int buf=i%k;
        te[buf].push_back(t[i]);
    }
    ll ans=0;
    rep(i,k){
        int num=te[i].size();
        char before='.';
        rep(j,num){
            if(before!=te[i][j]){
                ans+=score(te[i][j]);
            }
            else{
                te[i][j]='.';
            }
            before=te[i][j];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5120
n = int(input())
time = [0 for _ in range(n)]

for i in range(n-1):
  c, s, f = map(int, input().split())
  for j in range(0, i+1):
    if time[j] < s:
      time[j] = s + c
    elif time[j] % f == 0:
      time[j] += c
    else:
      time[j] = time[j] + f - time[j] % f + c

for t in time:
  print(t)


Measured memory_bytes: 3060
//https://atcoder.jp/contests/agc031/tasks/agc031_a
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(int argc, char const *argv[]) {
  int H,W,h,w;
  cin >> H >> W >> h >> w;
  cout << H*W-h*W-w*H+h*w << endl;
  return 0;
}


Measured memory_bytes: 256
import Data.Fixed

toBin' :: Int -> Int -> String
toBin' (-1) _ = []
toBin' n v =
  if (v`mod`2) == 1
  then (toBin' (n-1) (v `div` 2)) ++ "1"
  else (toBin' (n-1) (v `div` 2)) ++ "0"

toBin a =
  let s = toBin' 11 a
  in
    (take 8 s) ++ "." ++ (drop 8 s)

ans :: Float -> String
ans i = 
  let m = i * 16
  in
    if (m `mod'` 1.0) == 0.0 && m < 2**12 
    then toBin (round m)
    else "NA"

main = do
  c <- getContents
  let i = map read $ lines c :: [Float]
      i'= takeWhile (>=0) i
      o = map ans i'
  mapM_ putStrLn o

Measured memory_bytes: 4644
import sys
def calc():                                             
    _ = int(sys.stdin.readline())                       
    xs = [int(x) for x in sys.stdin.readline().split(" ")]
    for x in xs:                                          
        if x == 0:                                        
            return 0                                      
    r = 1                                                 
    m = 10 ** 18                                          
    for x in xs:                                          
        r *= x                                            
        if r > m:                                         
            return -1                                     
    return r                                              
                                                          
print(calc())                                             

Measured memory_bytes: 22700
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,l,n) for(int i=l; i<n; ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using mii = map<int,int>;
using pii = pair<int,int>;
using vpii = vector<pair<int,int>>;
using ti3 = tuple<int,int,int>;

int main(){
  ll x; cin>>x;
  FOR(i,x,110000){
    bool isPrime=true;
    FOR(j,2,sqrt(x)){
      if(i%j==0){
        isPrime=false;
      }
    }
    if(isPrime){
      cout<<i<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
 
int main(void){
    int n=0;            // input; items num <= 1000;
    int S[1000]={0};    // input; data set, 0<=s[i]<=100
    int i=0;            // loop index
    int sum=0;
    double ave=0.0;
    double a_sum=0.0;
    double ans=0.0;
 
    scanf("%d", &n);
    while(n != 0){
        sum = 0;
        a_sum = ave = ans = 0.0;
 
        for(i=0;i<n;i++){
            scanf("%d", &S[i]);
            sum += S[i];
        }
        ave = (double)sum / (double)n;
        for(i=0;i<n;i++) a_sum += pow((double)S[i] - ave, 2);
 
        ans = sqrt(a_sum / (double)n);
        printf("%lf\n", ans);
        scanf("%d", &n);
    }
    return 0;
}
 

Measured memory_bytes: 636
#include<bits/stdc++.h>
#define pb push_back
#define p2(x) (x)*(x)
using namespace std;
typedef long double ld;
typedef long long ll;

signed main(){
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int n;
    cin >> n;
    vector < int > a(n);
    for(auto &i : a)cin >> i;
    int curr = 1;
    for(int j = 0 ; j < n;  ++j)
        if(a[j]==curr)++curr;
    if(curr == 1)return cout << -1 , 0;
    cout << n - (curr - 1);
    return 0;
}


Measured memory_bytes: 1024
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;

#define PB push_back
#define MP make_pair
#define F first
#define S second

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
  	ll n,k,s=0;
  	cin >> n >> k;
  	for(ll i=k;i<=n+1;i++){
      	ll tmp= (n*(n+1)/2 - (n-i)*(n-i+1)/2 - (i-1)*i/2+1)%1000000007;
      	s = (s+ tmp)%1000000007;
    }
  	cout << s << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, ans=0;
  std::cin >> N;
  std::vector<ll> po(3*N);
  range(i, 3*N) std::cin >> po[i];
  sort(po.begin(), po.end());
  for(int i=N;i<3*N;i+=2) ans += po[i];
  std::cout << ans << '\n';
  return 0;
}


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;
void run_case()
{
    int N;
    double D;
    cin >> N >> D;
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        double p, q;
        cin >> p >> q;
        double t = sqrt(p * p + q * q);
        if (t <= D)
        {
            //DBG(t);
            ans++;
        }
    }
    cout << ans << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int n;
vector<string> brd;

bool can(int a, int b) {
	rep(i,0,n) rep(j,0,n) {
		if(brd[(i+a)%n][(j+b)%n] != brd[(j+a)%n][(i+b)%n]) {
			return false;
		}
	}
	return true;
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	cin >> n;
	brd.resize(n);
	rep(i,0,n) {
		cin >> brd[i];
	}
	int ret = 0;
	rep(i,0,n) {
		if(can(i,0)) {
			ret += n;
		}
	}
	cout << ret << endl;
	return 0;
}


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

using namespace std;

int main() {
  #ifdef _OFFLINE_
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n, k;
  cin >> n >> k;
  vector<int> arr(n);
  for(int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  sort(arr.begin(), arr.end());
  int sum = 0;
  for(int i = n - 1; i >= n - k; --i) {
    sum += arr[i];
  }
  cout << sum;
}

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

#define ipow(a,b)+0.5 (int)pow(a,b)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fi first
#define se second

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

using namespace std;
typedef long long ll;
typedef long double ld;

class Task
{
public:
    void solve(istream& in,ostream& out)
    {
        ll n,m;
        in>>n>>m;

        if(n>=m/2)
        {
            out<<m/2<<endl;
        }
        else
        {
            ll res=0;
            res+=n;
            m-=2*n;

            res+=m/4;

            out<<res<<endl;
        }
    }
};


int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	Task solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in,out);
	out.flush();

    return 0;
}





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

int main() {
  int a;
  string s;
  cin >> a >> s;
  if ( a < 3200 ){
    cout << "red" << endl;
  }else{
    cout << s << endl;
  }

  return 0; 
}

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

using namespace std;
#define BUF (100)
#define ll long long 

int n;
char s[BUF];
char c[258];

int main(void){
	cin >> s;

	int n= strlen(s);

	for(int i=0;i<n;i++){
		c[s[i]]=1;
	}

	for(char i='a';i<='z';i++){
		if(c[i]==0){
			s[n]=i;
			s[n+1]='\0';
			cout << s;
			cout << endl;
			return 0;
		}
	}


	for(int i=n-1;i>=0;i--){
		if(s[i]=='z'){
			c['z']=0;
			continue;
		}
		for(char j=s[i]+1;j<='z';j++){
			if(c[j]==0){
				s[i] = j;
				s[i + 1] = '\0';
				cout << s << endl;
				return 0;
			}
		}
		c[s[i]]=0;
	}

	cout << -1 << endl;
	return 0;
}


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

int main(){
  int N;
  string S;
  cin>>N>>S;
  int x=0;
  int max=0;
  for(int i=0; i<N; i++){
    if(S.at(i)=='I') x++;
    if(S.at(i)=='D') x--;
    if(x>=max) max=x;
    }
  cout<<max<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  long long T = 0;
  for (int i = 0; i < N; i++){
    cin >> A[i];
    T += A[i];
  }
  vector<long long> S(N - 1);
  S[0] = A[0];
  for (int i = 0; i < N - 1; i++){
    S[i + 1] = S[i] + A[i + 1];
  }
  long long m = 1e16;
  for (int i = 0; i < N - 1; i++){
    m = min(m, abs((T - S[i]) - S[i]));
  }
  cout << m;
}

Measured memory_bytes: 2560
m,d = map(int,input().split())
count = 0
if d>21:
	for i in range(d-21):
		b = int((i+22)/10)
		a = (i+22)-(b*10)
		if a>1 and b>1:
			if m >= (a*b):
				count += 1
	print(count)
else:
	print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
int main()
{
    int n;
    std::cin >> n;
    std::unordered_map<int,int> v[2];
    for (int i = 0; i < n; i+=2) {
        int o,e;
        std::cin >> o >> e;
        v[0][o]++;
        v[1][e]++;
    }
 
    int key[2][2] = {};
    int val[2][2] = {};

    for (auto x : v[0]) {
        if (x.second > val[0][0]) {
            key[0][1] = key[0][0];
            val[0][1] = val[0][0];
            key[0][0] = x.first;
            val[0][0] = x.second;
        } else if (x.second > val[0][1]) {
            key[0][1] = x.first;
            val[0][1] = x.second;
        }
    }
    for (auto x : v[1]) {
        if (x.second > val[1][0]) {
            key[1][1] = key[1][0];
            val[1][1] = val[1][0];
            key[1][0] = x.first;
            val[1][0] = x.second;
        } else if (x.second > val[1][1]) {
            key[1][1] = x.first;
            val[1][1] = x.second;
        }
    }

    if (key[0][0] != key[1][0]) {
        std::cout << n - val[0][0] - val[1][0] << std::endl;
        return 0;
    }
 
    std::cout << n - std::max(val[0][0]+val[1][1], val[1][0]+val[0][1]) << std::endl;
 
    return 0;
}


Measured memory_bytes: 4376
n=int(input())
l=[0]*5
for i in range(n):
    s=input()
    if s[0]=='M':
        l[0]+=1
    elif s[0]=='A':
        l[1]+=1
    elif s[0]=='R':
        l[2]+=1
    elif s[0]=='C':
        l[3]+=1
    elif s[0]=='H':
        l[4]+=1
k0=l[0]*(l[1]*(l[2]+l[3]+l[4])+l[2]*(l[3]+l[4])+l[3]*l[4])
k1=l[1]*(l[2]*(l[3]+l[4])+l[3]*l[4])
k2=l[2]*l[3]*l[4]
print(k0+k1+k2)


Measured memory_bytes: 44264
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

class SegmentTree():
   
    def __init__(self,N,f,unit):
        self.f = f
        self.unit = unit
        self.N = N
        self.tree = [self.unit] * (2*self.N)
        #self._build(array)
    
    def _build(self,array):
        for i,x in enumerate(array,self.N):
            self.tree[i] = x
        for i in range(self.N - 1,0,-1):
            self.tree[i] = self.f(self.tree[i << 1],self.tree[i << 1|1])
    
    def update(self,k,x):
        k += self.N
        self.tree[k] = x
        while k > 1:
            k >>= 1
            self.tree[k] = self.f(self.tree[k << 1],self.tree[k << 1|1])
    
    def query(self,l,r):
        l += self.N
        r += self.N
        vl = self.unit
        vr = self.unit
        while l < r:
            if l&1: 
                vl = self.f(vl,self.tree[l])
                l += 1
            if r&1:
                r -= 1
                vr = self.f(self.tree[r],vr)
            l >>= 1
            r >>= 1
        return self.f(vl,vr)
    
    def debug(self):
        print(self.tree)

def main():
    N = int(input())
    A = list(map(int,input().split()))

    st = SegmentTree(N,max,-1)
    L = [-1] * N
    for i,a in enumerate(A):
        L[i] = st.query(0,a - 1)
        st.update(a - 1,i)
    
    st = SegmentTree(N,min,N)
    R = [N] * N
    for i in range(N - 1,-1,-1):
        R[i] = st.query(0,A[i] - 1)
        st.update(A[i] - 1,i)
    
    ans = sum((R[i] - i)*(i - L[i])*A[i] for i in range(N))
    print(ans) 
if __name__ == '__main__':
    main()

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

	string str;cin >> str;
	vector<char> v;

	REP(i, str.size()){
		if(str[i] == 'A')v.PB('A');
		else if(str[i] == 'B' && str[i+1] == 'C'){
			v.PB('X');
			i++;
		}
		else {
			v.PB('Y');
		}
	}

	ll ans = 0;
	ll cou = 0;
	REV(i, v.size()){
		if(v[i] == 'A')ans += cou;
		else if(v[i] == 'X')cou++;
		else cou = 0;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 788
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
//#include<cmath>
#define MAX 50000
using namespace std;
int c[21][MAX+10];

int main()
{
    int n,m,sum=0;
    int coin[MAX];
    cin>>n>>m;
    int i,w;
    for(i=0;i<m;i++)
    {
        cin>>coin[i];
    }
    sort(coin,coin+m);
//    vector<vector<int> > c(m+1,vector<int>(n+1));
    for(int i=1;i<=n;i++) c[1][i]=1000000;
    c[1][0]=0;
    for(int i=0;i<m;i++){
        for(int j=coin[i];j<=n;j++) c[1][j]=min(c[1][j],c[1][j-coin[i]]+1);
    }
    cout<<c[1][n]<<endl;
//    for(i=0;i<=m;i++)
//    {
//        c[m][1]=1;
//        c[m][0]=0;
//    }
//    for(w=1;w<=n;w++)
//    {
//        c[1][w]=w/coin[0];
//       //c[0][w]=0;
//    }
//
//    for(i = 2; i <= m; i++)
//    {
//        for(w = 2; w <= n; w++)
//        {
//            if(w < coin[i-1])
//            {
//                c[i][w] = c[i - 1][w];
//            }
//            else
//            {
//                int x = c[i-1][w];
//                int y = c[i][w - coin[i-1]] + 1;
//                c[i][w] = x > y ? y : x;
//            }
//        }
//    }
//	cout<<c[m][n]<<endl;
    return 0;
}






Measured memory_bytes: 3380
#mport sympy
i=int(input().replace(" ",""))
if i % 256 in set(map(lambda x: x * x % 256,  range(0,256))):
  if i % 9 in set(map(lambda x: x * x % 9,  range(0,9))):
    if i % 5 in set(map(lambda x: x * x % 5,  range(0,5))):
      if i % 7 in set(map(lambda x: x * x % 7,  range(0,7))):
        if i % 13 in set(map(lambda x: x * x % 13,  range(0,13))):
          if i % 17 in set(map(lambda x: x * x % 17,  range(0,17))):
            if int(i**0.5)**2 == i:
              print("Yes")
              exit()
            else:
              print("No")
              exit()
          else:
            print("No")
            exit()
        else:
          print("No")
          exit()
      else:
        print("No")
        exit()
    else:
      print("No")
      exit()
  else:
    print("No")
    exit()
else:
  print("No")

Measured memory_bytes: 3188
// https://atcoder.jp/contests/abc131/tasks/abc131_b

#include <bits/stdc++.h>
using namespace std;

int n, l, f[205], pie, pie2 = 10000;

int main()
{
	cin >> n >> l;
	for (int i = 0; i < n; ++i){
		f[i] = l + i;
		pie += f[i];
	}
	for (int i = 0; i < n; ++i){
		if (abs(pie2 - pie) > abs((pie - f[i]) - pie)) pie2 = pie - f[i];
	}
	cout << pie2;
	return 0;
}



Measured memory_bytes: 256
//
//  main.cpp
//  ProCon
//
//  Created by hashimotoryoma on 2017/08/20.
//  Copyright © 2017年 hashimotoryoma. All rights reserved.
//

#include <iostream>
#include <algorithm>
using namespace std;

int N;
int p[112345];
int ans;
int main() {
    // insert code here...
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> p[i];
        p[i]--;
    }
    for(int i=0;i<N;i++){
        if(i == p[i]){
            ans++;
            if(i+1<N)
                swap(p[i],p[i+1]);
            else
                swap(p[i],p[i-1]);
        }
    }
    cout << ans  << endl;
    return 0;
}


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

int main(){
  ll N, M; cin >> N >> M;
  vector<pair<ll, ll> > ab(N);
  for(ll i = 0; i < N; i++){
    ll a, b; cin >> a >> b;
    ab[i] = make_pair(a, b);
  }
  sort(ab.begin(), ab.end());
  
  ll ans = 0, ext = 0;
  priority_queue<ll> pq;
  
  for(ll i = 1; i <= M; i++){
    
    while((ab[ext].first <= i) && (ext < N)){
      pq.push(ab[ext].second);
      ext++;
    }
    if(pq.empty()) continue;
    ans += pq.top();
    pq.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 2936
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

void solve(){
  int n;
  cin>>n;
  if(n==3){
    cout<<2<<" "<<3<<" "<<25;
    return;
  }
  if(n==4){
    cout<<2<<" "<<5<<" "<<20<<" "<<63;
    return;
  }  
  if(n==5){
    cout<<2<<" "<<5<<" "<<20<<" "<<30<<" "<<63;
    return;
  }
  set<int>st;
  st.emplace(2);st.emplace(3);
  int num=4;
  while(st.size()<n){
      if((num%2==0)||(num%3==0))st.emplace(num),++num;
      else ++num;
  }
  ll sum=0;
  for(auto x:st){
    sum+=x;
  }
  if(sum%6==2){
    st.erase(8);
    while(num%6!=0)++num;
    st.emplace(num);
  }
  else if(sum%6==3){
    st.erase(9);
    while(num%6!=0)++num;
    st.emplace(num);
  }
  else if(sum%6==5){
    st.erase(8);
    while(num%6!=3)++num;
    st.emplace(num);
  }
  for(auto x:st){
    cout<<x<<" ";
  }
  cout<<endl;
}

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


Measured memory_bytes: 1280
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

for i in range(0,A+1):
  a = 500*i
  
  for j in range(0,B+1):
    b = 100*j
    
    for k in range(0,C+1):
      c = 50*k
      
      if a + b + c == X:
        ans += 1
        
print(ans)
  
  

Measured memory_bytes: 9132