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

template<class Abel> struct UnionFind {
    vector<int> p;
    vector<int> r;
    vector<Abel> dw;

    UnionFind(int n=1, Abel SUM_UNITY=0) {
        init(n, SUM_UNITY);
    }

    void init(int n=1, Abel SUM_UNITY=0) {
        p.resize(n);
        r.resize(n);
        dw.resize(n);
        for(int i=0; i<n; i++)
          p[i]=i, r[i]=0, dw[i]=SUM_UNITY;
    }

    int root(int x) {
        if(p[x] == x)
            return x;
        else {
            int r=root(p[x]);
            dw[x] += dw[p[x]];
            return p[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return dw[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if(x == y)
          return false;
        if(r[x] < r[y])
          swap(x,y), w=-w;
        if(r[x] == r[y])
          ++r[x];
        p[y] = x;
        dw[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};


int main() {
  int N,M,i,L,R,D;
  cin >> N >> M;
  UnionFind<int> uf(N);

  for(i=0; i<M; i++) {
    cin >> L >> R >> D;
    if(uf.issame(L-1,R-1) && uf.diff(L-1, R-1)!=D) {
      cout << "No" << endl;
      return 0;
    }
    uf.merge(L-1, R-1, D);
  }

  cout << "Yes" << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
struct line{
	int l,r;
	bool operator <(const line &b) const{
		return (r==b.r)?l<b.l:r<b.r;
	}
}a[100005];
int main(){
	int n,x,l;
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>x>>l,a[i].l=x-l,a[i].r=x+l;
	sort(a+1,a+n+1);
	int ans=1,tmp=a[1].r;
	for(int i=2;i<=n;++i)
		if(tmp<=a[i].l) ++ans,tmp=a[i].r;
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 4392
<?php

    // AtCoder Beginner Contest 164
    // B - Battle

    list($hp1, $atk1, $hp2, $atk2) = in_ints();
    while ($hp1 != 0 && $hp2 != 0) {
        $hp2 -= $atk1;
        if ($hp2 <= 0) {
            break;
        }
        $hp1 -= $atk2;
    }
    if ($hp1 <= 0) {
        no();
    } else {
        yes();
    }

    // -----------------------------------------------------
    function in() { return trim(fgets(STDIN)); }
    function in_int() { return (int)in(); }
    function in_vals() { return explode(' ', in()); }
    function in_ints() { return array_map('intval', in_vals()); }
    function out($s) { echo $s . PHP_EOL; }
    function yes() { out('Yes'); }
    function no() { out('No'); }


Measured memory_bytes: 16192
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

def dfs(x):
    for i in tree[x]:
        if al[i]<0:
            al[i]=0
            dfs(i)
    
        
    
n,m=MI()
lis=[LI() for i in range(m)]
#print(lis)
cou=0
for i in range(m):
    tree=[[] for i in range(n)]
    for j in range(m):
        if i!=j:
            tree[lis[j][0]-1].append(lis[j][1]-1)
            tree[lis[j][1]-1].append(lis[j][0]-1)
    count=0
    for k in range(n):
        al=[-1]*n
        al[k]=0
        dfs(k)
        #print(al)
        if sum(al)==0:
            count+=1
    if count!=n:
        cou+=1
print(cou)        

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

struct Data {
    int64_t x;
    int64_t y;
    int64_t z;
};

int main() {
    int N, M;
    std::cin >> N >> M;
std::vector<Data> vals;
    int64_t x, y, z;
    for (int i = 0; i < N; ++i) {
        std::cin >> x >> y >> z;
        vals.push_back({x, y, z});
    }

    int64_t max = INT32_MIN;
    for (int i = 0; i < (1 << 3); ++i) {
        int flags[3];
        flags[0] = (i >> 0) & 1;
        flags[1] = (i >> 1) & 1;
        flags[2] = (i >> 2) & 1;

        std::vector<Data> buf = vals;

        std::sort(buf.begin(), buf.end(), [&](const auto& l, const auto& r) {
            int64_t lsum = 0, rsum = 0;
            if (flags[0]) {
                lsum += l.x;
                rsum += r.x;
            } else {
                lsum -= l.x;
                rsum -= r.x;
            }

            if (flags[1]) {
                lsum += l.y;
                rsum += r.y;
            } else {
                lsum -= l.y;
                rsum -= r.y;
            }

            if (flags[2]) {
                lsum += l.z;
                rsum += r.z;
            } else {
                lsum -= l.z;
                rsum -= r.z;
            }

            return lsum < rsum;
        });

        int64_t x_sum = 0, y_sum = 0, z_sum = 0;
        for (int j = 0; j < M; ++j) {
            x_sum += buf[j].x;
            y_sum += buf[j].y;
            z_sum += buf[j].z;
        } 

        max = std::max(max, (std::abs(x_sum) + std::abs(y_sum) + std::abs(z_sum)));  
    }

    std::cout << max << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int main(){
  int n,a,b;
  scanf("%d %d %d",&n,&a,&b);
  if((b-a)%2==0){
    printf("Alice\n");
  }
  else{
    printf("Borys\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
using namespace std;
#define low(i) ((i)&(-(i)))
 
const int maxm=1e5+5;
 
int n,m,cnt;
vector<int>range[maxm];
vector<int>::iterator it;
 
int read() {
    int x=0,f=1;char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
    for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
    return x*f;
}
 
struct TreeArray {
    int c[maxm];
 
    void change(int pos,int v) {
        for(int i=pos;i<=m;i+=low(i))
            c[i]+=v;
    }
 
    int query(int pos) {
        int res=0;
        for(int i=pos;i;i-=low(i))
            res+=c[i];
        return res;
    }
}T;
 
int main() {
    cnt=n=read(),m=read();
    for(int i=1;i<=n;i++) {
        int l=read(),r=read();
        range[r-l+1].push_back(l);
    }
    for(int i=1;i<=m;i++) {
        int ans=cnt;
        for(int pos=i;pos<=m;pos+=i)
            ans+=T.query(pos);
        for(it=range[i].begin();it!=range[i].end();it++)
            T.change(*it,1),T.change((*it)+i,-1),cnt--;
        printf("%d\n",ans);
    }
    return 0;
}


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

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

	vector<int> h;
	int max = 0;
	int total = 0;
	for (int i = 0; i < n; ++i)
	{
		int num;
		cin >> num;
		h.push_back(num);
		if (max <= num)
		{
			max = num;
			++total;
		}
	}

	cout << total;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int h, w;
int b, c;
int a[26];

int main()
{
    scanf("%d%d\n", &h, &w);
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            char ch;
            scanf("%c", &ch);
            a[ch - 'a']++;
        }
        scanf("\n");
    }
    for(char i = 'a'; i <= 'z'; i++)
    {
        a[i - 'a'] %= 4;
        if(a[i - 'a'] >= 2) b++, a[i - 'a'] -= 2;
        if(a[i - 'a'] >= 1) c++, a[i - 'a']--;
    }
    if(h % 2 == 0 && w % 2 == 0)
    {
        if(b == 0 && c == 0) printf("Yes");
        else printf("No");
    }
    else if(h % 2 == 1 && w % 2 == 0)
    {
        if(b <= w / 2 && c == 0) printf("Yes");
        else printf("No");
    }
    else if(h % 2 == 0 && w % 2 == 1)
    {
        if(b <= h / 2 && c == 0) printf("Yes");
        else printf("No");
    }
    else
    {
        if(b <= h / 2 + w / 2 && c <= 1) printf("Yes");
        else printf("No");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int MAX = 53;

long long pow2[MAX] = {1};

long long size(long long n) {
	return pow2[n+2] - 3;
}

long long f(long long n, long long x) {
	if (n == 0) return 1;
	if (x == 1) return 0;
	x--;
	if (x <= size(n-1)) return f(n-1, x);
	x -= size(n-1);
	if (x == 1) return pow2[n];
	x--;
	if (x <= size(n-1)) return pow2[n] + f(n-1, x);
	return 2 * (pow2[n]-1) + 1;
}

int main() {
	for (int i = 1; i < MAX; i++) pow2[i] = 2 * pow2[i-1];
	long long n, x;
	cin >> n >> x;
	long long ans = f(n, x);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3596
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var H = cin.ReadLongArray(N);
            if (N == 1)
            {
                WriteLine("Yes");
                return;
            }
            for (int i = N - 1; i > 0; i--)
            {
                if (H[i - 1] > H[i])
                {
                    if (H[i - 1] - H[i] >= 2)
                    {
                        WriteLine("No");
                        return;
                    }
                    else
                    {
                        H[i - 1]--;
                    }
                }
                if (H[i - 1] < 0)
                {
                    WriteLine("No");
                    return;
                }
            }
            WriteLine("Yes");
        }
        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

Measured memory_bytes: 31196
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"


int main(int argc, char const *argv[]) {

  // std::string A;
  // std::cin >> A;
  // std::cout << A[0] << '\n';
  //
  // int NN;
  // std::cin >> NN;
  // std::cout << NN*NN << '\n';

  int K;
  std::cin >> K;

  if (K % 2 == 0) {
    std::cout << K * K / 4 << '\n';
  }else{
    std::cout << (K-1)*(K+1)/4 << '\n';
  }


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(void){
    long long int a,b,c,d,ans=INT64_MIN;
    cin>>a>>b>>c>>d;
    if(b*d>ans){
        ans=b*d;
    }
    if(b*c>ans){
        ans=b*c;
    }
    if(a*d>ans){
        ans=a*d;
    }
    if(a*c>ans){
        ans=a*c;
    }
    cout<<ans<<endl;
    return 0;
}

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

const int MOD = 1000000007;

int vis[10010][110];
long long dp[10010][110];
string s;
int d;

long long dfs(int len, int mod, int pd){
//	cout << "  " << len << " " << mod << " " << pd << endl;
	if (len == -1) return mod == 0;
	if (!pd && vis[len][mod]) return dp[len][mod];
	long long cnt = 0;
	int maxj = pd ? s[len] - '0' : 9;
//	cout << "    " << (int)s[len] - '0' << endl;
	for (int i = 0; i <= maxj; i++){
//		cout << "    " << i << endl;
		cnt = (cnt + dfs(len - 1, (mod + i) % d, pd && i == maxj)) % MOD;
	}
	if (!pd) dp[len][mod] = cnt, vis[len][mod] = 1;
	return cnt;
}

char buf[10010];

int main(){
	scanf("%s", buf);
	s = buf;
	scanf("%d", &d);
	reverse(s.begin(), s.end());
//	cout << "s:" << s << endl;
//	cout << "  " << s[1] << endl;
//	cout << "  s.length():" << s.length() << endl;
	printf("%d\n", (dfs(s.length() - 1, 0, 1) - 1 + MOD) % MOD);
	return 0;
}

Measured memory_bytes: 13952
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;


void solve() {
	int n, x;
	cin >> n >> x;
	int arr[n];
	for(int i = 0; i < n; ++i) cin >> arr[i]; 
	sort(arr, arr + n);
	ll ans = 0;
	int i = n - 1; 
	while(x--) ans += arr[i--];
	cout << ans << endl;
}

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	solve();
	return 0;
	}


Measured memory_bytes: 3616
#include <iostream>
#include <stdio.h>
#include <numeric>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    for(int i=n-1;i>0;--i){
        cout<<a[i]<<" ";
    }
    cout<<a[0]<<endl;
    return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

int main(){
  int N, C;
  cin >> N >> C;
  int D[C+1][C+1];
  map<int, int> mod0, mod1, mod2;
  for(int i = 1; i <= C; i++){
    for(int j = 1; j <= C; j++){
      cin >> D[i][j];
    }
  }
  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= N; j++){
      int c;
      cin >> c;
      if((i+j) % 3 == 0) mod0[c]++;
      else if((i+j) % 3 == 1) mod1[c]++;
      else if((i+j) % 3 == 2) mod2[c]++;
    }
  }
  int ans = INF;
  for(int i = 1; i <= C; i++){
    for(int j = 1; j <= C; j++){
      for(int k = 1; k <= C; k++){
        if(i != j && j != k && k != i){
          int dif = 0;
          for(auto x : mod0) dif += D[x.first][i]*x.second;
          for(auto x : mod1) dif += D[x.first][j]*x.second;
          for(auto x : mod2) dif += D[x.first][k]*x.second;
          ans = min(ans, dif);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    import itertools
    import numpy as np
    H,W,K=list(map(int,sys.stdin.readline().split()))
    C=np.zeros((H,W))
    for i in range(H):
        C[i]=[1 if x=='#' else 0 for x in sys.stdin.readline().strip()]

    nums = [0,1]
    count=0
    for pat in itertools.product(nums, repeat=H+W):
        patH=list(i for i,x in enumerate(pat[:H]) if x==1)
        patW=list(i for i,x in enumerate(pat[H:]) if x==1)
        CH=C[patH]
        if CH.shape[0]:
            CHW=CH[:,patW]
            p=np.count_nonzero(CHW)
            if p==K:
                count+=1


    print(count)

    


main()

Measured memory_bytes: 27188
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = (int)(1e6) + 5;
char str[N];
int k;
int dp[333][333][333];
int f(int l,int r,int t)
{
    if (dp[l][r][t] != -1)
        return dp[l][r][t];
    if (l > r)
        return 0;
    if (l == r)
        return 1;
    int &ans = dp[l][r][t];
    ans = max(f(l + 1,r,t),f(l,r - 1,t));
    if (str[l] == str[r])
        smax(ans,f(l + 1,r - 1,t) + 2);
    else
    if (t + 1 <= k)
        smax(ans,2 + f(l + 1,r - 1,t + 1));
    return ans;
}
int main(void)
{
    cin>>(str + 1);
    cin>>k;
    memset(dp,-1,sizeof(dp));
    int n = strlen(str + 1);
    cout << f(1,n,0) << '\n';
    return 0;
}


Measured memory_bytes: 144640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  ld x, y; cin >> x >> y;
  outl(ll(log2(y / x)) + 1);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

int main() 
{
    int h, w;
    cin >> h >> w;
    vector<vector<char>> v1(h);
    vector<vector<char>> v2(w);
    for (int i=0; i<h; i++)
    {
        for (int j=0; j<w; j++)
        {
            char x;
            cin >> x;
            v1[i].push_back(x);
            v2[j].push_back(x);
        }
    }
    set<int> s;
    for (int i=0; i<v1.size(); i++)
        if (count(v1[i].begin(), v1[i].end(), '.') == v1[i].size())
        {
            v1.erase(v1.begin() + i);
            i--;
        }
            // cout << "a";
    for (int i=0; i<v2.size(); i++)
        if (count(v2[i].begin(), v2[i].end(), '.') == v2[i].size())
            s.insert(i);
    // for (auto x:s)
    //     cout << x << endl;
    // return 0;
    for (int i=0; i<v1.size(); i++) 
    {
        // cout << "a";
        // cout << v1[i].size() << endl;
        for (int j=0; j<v1[i].size(); j++)
            if (find(s.begin(), s.end(), j) != s.end())
            {
                // cout << j << endl;
                // v1[i].erase(v1[i].begin() + j);
                v1[i][j] = '?';
            }
    }
    // return 0;
    // cout << "result" << endl;
    for (int i=0; i<v1.size(); i++) 
    {
        for (int j=0; j<v1[i].size(); j++)
            if (v1[i][j] != '?')
                cout << v1[i][j];
        cout << endl;
    }
    // cout << "abs";
    return 0;
}

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

string S;

int main()
{
  
  
  cin>>N;
  
  
  while(N)
  {
    N--;
    S += 'a' + N%26;
    N /= 26;
  }
  
  reverse(S.begin(),S.end());
  cout<<S;
  
  return 0;

}

Measured memory_bytes: 3612
#include<stdio.h>

int esearch(int, int );
int sumdata;
int sumquestion;
int data[20];
int question[200];
int main(){

  int i,answer;

  scanf("%d",&sumdata);

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

    scanf("%d",&data[i]);

  }

  scanf("%d",&sumquestion);

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

    scanf("%d",&question[i]);

  }

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

    answer = esearch(0,question[i]);

    if(answer >= 1){

      printf("yes\n");

    }
    
    else{

      printf("no\n");

    }
  }
return 0;


}

int esearch(int x, int y){

  int answer;


  if(y == 0) {

    return 1;
  }

  else if(x >= sumdata){

    return 0;

  }


  answer = esearch( x + 1, y) || esearch(x + 1, y - data[x]);

  return answer;

}

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

#define ARC(i, a, b) for(int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)

template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a > b ? a - b : b - a; }
template<class T> T &anth(T &a, const T &b){ return a = ant(a, b); }
template<class T> T &onth(T &a, const T &b){ return a = ont(a, b); }

using ull = unsigned long long;

int main(){
	ull n, m, ans = 0;
	std::cin >> n >> m;
	std::vector<std::pair<ull, ull> > drink(n);
	RC(i, n) std::cin >> drink[i].first >> drink[i].second;
	std::sort(drink.begin(), drink.end());
	RC(i, n){
		if(m > drink[i].second){
			ans += drink[i].first * drink[i].second;
			m -= drink[i].second;
		}else{
			ans += drink[i].first * m;
			std::cout << ans << std::endl;
			return 0;
		}
	}
}


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

using namespace std;

using ll = long long;

int main()
{
    ll t, n, k, sum = 0, i;
    cin >> n;
    vector < ll > v(n-1);

    for(i=0; i<n-1; i++){
        cin >> v[i];
    }

    for(i=0; i<n-2; i++){
        sum += min(v[i], v[i+1]);
    }

    cout << sum + v[n-2] + v[0] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
int main()
{
    string str, tmp, command, p;
    int q, a, b;
    cin >> str >> q;
    for (int i=0; i<q; ++i){
        cin >> command;
        // parse
        // print
        if (command[0] == 'p'){
            cin >> a >> b;
            for (int j=0; j<b-a+1; ++j){
                cout << str[a+j];
            }
            cout << endl;
        }
        // replace
        else if (command[0] == 'r' && command[1] == 'e' && command[2] == 'p'){
            cin >> a >> b >> p;
            for (int j=0; j<b-a+1; ++j){
                str[a+j] = p[j];
            }
        }
        // reverse
        else if (command[0] == 'r' && command[1] == 'e' && command[2] == 'v'){
            cin >> a >> b;
            tmp = str;
            for (int j=0; j<b-a+1; ++j){
                str[a+j] = tmp[b-j];
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3168
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        long N = nextLong();

        long n = N-1;
        long a = 1;
        long l = N-1;

        println(n*(a+l)/2L);
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


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


int main(){
  string n;
  cin >> n;
  for (int i = 0; i < 3; i++){
    if (n.at(i) == '1'){
      n.at(i) = '9';
    }else if (n.at(i) == '9'){
      n.at(i) = '1';
    }
  }
  cout << n << endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
MOD = 10**9 + 7

M = int(K ** .5)
f_l = [0] * (M+1)  # f(k)
f_h = [0] * (M+1)  # f(K//d)

def f(k):
  return f_l[k] if k <= M else f_h[K//k]

def compute_f(k):
  x = pow(k, N, MOD)
  sq = int(k ** .5)
  for d in range(2, k+1):
    n = k // d
    if n <= sq:
      break
    x -= f(n)
  for n in range(1, sq+1):
    cnt = k//n - k//(n+1)
    x -= f_l[n] * cnt
  return x

for k in range(1, M+1):
  f_l[k] = compute_f(k)

for d in range(M, 0, -1):
  f_h[d] = compute_f(K//d)

answer = 0

for k in range(1, M+1):
  low_d = K // (k+1) + 1
  high_d = K // k
  items = high_d - low_d + 1
  coef = (low_d + high_d) * items // 2
  answer += coef * f_l[k]
  
for d in range(1, M+1):
  if K // d <= M:
    break
  answer += d * f_h[d]

answer %= MOD
print(answer)

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

int main(){
      string s1,s2;cin >> s1 >> s2;
      int n1 = s1.length();
      int n2 = s2.length();
      if(n1 < n2 && s1.substr(0, n1) == s2.substr(0, n1))return cout << "Yes", 0;
      for(int i = 0;i < n1;i++){
            for(int j = 0;j < n2;j++){
                  if(s2[j] > s1[i])return cout << "Yes", 0;
            }
      }
      cout << "No";
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 5;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const ll N = 1e6+5;
vector<ll> v;
ll n,x,result;

void solve(ll a, ll b) {
  if(a%b == 0) {
    result += (a/b) * (2*b) - b;
    return;
  } else {
    result += (a/b) * (2*b);
    // cout << a << " : " << b << " : " <<  result << endl;
    if(b > a%b) solve(b, a%b);
    else solve(a%b, b);
  }
}

int main () {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> x;
  x = 2*x > n ? n -x : x;
  solve(n-x,x);
  cout << n + result << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <random>
#include <set>
#include <sstream>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-9;
const double PI = acos(-1);
const int MOD = 998244353;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 3005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
int arr[MAXN];
ll dp[MAXN][MAXN];
ll sum[MAXN];
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &arr[i]);
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        dp[i][arr[i]] += i;
        for (int k = 0; k <= m; k++) {
            if (k < arr[i])
                dp[i][k] = (dp[i][k] + dp[i - 1][k]) % MOD;
            else
                dp[i][k] =
                    (dp[i][k] + dp[i - 1][k] + dp[i - 1][k - arr[i]]) % MOD;
        }
    }
    for (int i = 1; i <= n; i++) {
        ans += dp[i][m];
        if (ans >= MOD) ans -= MOD;
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int MAX_N = 101;
int MAX_V = 100100;
int dp[101][100100];

void solve(istream& cin, ostream& cout) {
  int n, W;
  cin >> n >> W;
  vector<int> w(n), v(n);
  REP(i, n) cin >> w[i] >> v[i];
  REP(i, MAX_N) REP(j, MAX_V) dp[i][j] = MOD;
  dp[0][0] = 0;
  REP(i, n) REP(j, MAX_V) {
    if (j >= v[i]) dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
    else
      dp[i + 1][j] = dp[i][j];
  }
  int ans = 0;
  REP(j, MAX_V) if (dp[n][j] <= W) ans = max(ans, j);
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


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

int main() {
    set<int> ss;
    int q;
    cin >> q;
    while (q--) {
        int t, x;
        cin >> t >> x;
        if (t == 1) {
            cout << ss.count(x) << endl;
        } else if (t == 0) {
            ss.insert(x);
            cout << ss.size() << endl;
        } else {
            ss.erase(x);
        }
    } 
}


Measured memory_bytes: 12460
a,b=map(int,input().split(" "))
#print(a,b)
min=0
max=0
count=0

for i in range(b,a+2):
    min = int((i-1)*i/2)
    max = int((2*a-i+1)*i/2)
    count+=max-min+1
print(count%1000000007)

Measured memory_bytes: 64592
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

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

int n;
int l[100005];

bool can(int numC) {
  // is it possible that there are numC colors distinct?
  int numColorAssign = numC;
  for(int i = 0; i < n;) {
    if(l[i] != numC) {
      // cannot see any other color
      if(numColorAssign-- == 0) return false;
      i++;
      continue;
    }
    // must be present with at least one other color
    break;
  }
  int nonunique = 0;
  for(int i = 0; i < n; i++) if(l[i] == numC) nonunique++;
  // do we have colors left to assign?
  if(numColorAssign == 0 && nonunique) return false;
  // does there exist a partition of nonunique of size numColorAssign
  // where each elem has size >= 2?
  if(nonunique < 2 * numColorAssign) return false;
  nonunique -= 2 * numColorAssign;
  // vacuously true?
  return true;
}

void solve() {
  cin >> n;
  for(int i = 0; i < n; i++) cin >> l[i];
  sort(l, l+n);
  if(l[n-1] - l[0] <= 1 && (can(l[n-1]) || can(l[0]+1))) cout << "Yes\n";
  else cout << "No\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


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

using namespace std;

const int NMAX = 1e5;

int N;
int v[3];
int dp[NMAX + 5][3];

int main()
{
    cin >> N;
    for(int i = 1; i <= N; i++)
    {
        for(int j = 0; j < 3; j++)  cin >> v[j];
        for(int j = 0; j < 3; j++)
        {
            dp[i][j] = -(1 << 30);
            for(int k = 0; k < 3; k++)
                if(j != k)
                    dp[i][j] = max(dp[i][j], dp[i - 1][k] + v[j]);
        }
    }

    cout << max({dp[N][0], dp[N][1], dp[N][2]});

    exit(0);
}

Measured memory_bytes: 1408
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int ans = 0;
		int N = sc.nextInt();
		int X = sc.nextInt();
		List<Integer> donuts = new ArrayList<Integer>();

		for(int i=0;i<N;i++) {
			donuts.add(sc.nextInt());
		}
		Collections.sort(donuts, null);
		for(int j=0;j<N;j++) {
		if(X-donuts.get(j)>=0) {
			X=X-donuts.get(j);
			ans +=1;
		}

		}

		while(X-donuts.get(0)>=0) {
			X=X-donuts.get(0);
			ans +=1;
		}
		System.out.println(ans);
}
}

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

int main(){
    ll n, d;
    cin >> n >> d;
    vector<ll> x(n);
    vector<ll> y(n);
    ll ans = 0;
    double z;
    rep(i,n){
        cin >> x[i] >> y[i];
    }
    rep(i,n){
        z = sqrt(x[i]*x[i]+y[i]*y[i]);
        if(z <= d){
            ans ++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6488
#include<bits/stdc++.h>
using namespace std;
int n,m;
inline int read(){
	char c=getchar();int s=0;
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9'){
		s=s*10+c-'0';c=getchar();
	}return s;
}
const int N=2500;
const int mod=1e9+7;
int f[N][N];
int fac[N*N];
int ksm(int x,int y){
	int b=1;
	while(y){
		if(y&1)b=(1ll*b*x)%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}return b;
}
int C(int x,int y){
	return 1ll*fac[x]*ksm(1ll*fac[y]*fac[x-y]%mod,mod-2)%mod;
}
int main(){
	n=read();m=read();
	if(m==1){
		cout<<1;
		return 0;
	}
	f[0][0]=1;fac[0]=1;
	for(int i=1;i<=2000*2000;i++)fac[i]=1ll*fac[i-1]*i%mod;
	for(int i=1;i<=n;i++){
		for(int k=0;k<=i;k++){
			f[i][k]=(f[i-1][k]+(k>0?1ll*f[i][k-1]*(n-k+1)%mod*C(n*m-i-(k-1)*(m-1)-1,m-2)%mod:0))%mod;
		}
	}
	cout<<f[n][n];
	return 0;
}

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

int main()
{
	ll n,k,a[200005]={},sum=0,MOD=1000000007;
	cin>>n>>k;
	for(int i=1;i<=n+1;i++)a[i]+=i+a[i-1];
	for(int i=k;i<=n;i++)
	{
		//cout<<a[n]<<" "<<a[n-i]<<" "<<a[i-1]<<endl;
		sum+=(a[n]-a[n-i]-a[i-1])%MOD+1;
		sum%=MOD;
	}
	cout<<(sum+1)%MOD<<endl;
	return 0;
}

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

int main()
{
    int n;
    cin>>n;
    int arr[n+5];
    for(int i=0;i<n;i++)cin>>arr[i];
    long long k=0;
    for(int i=0;i<n;i++)k+=(arr[i]-1);
    cout<<k<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF (int)1e9
#define INFL (ll)1e11
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N, M;
	cin >> N >> M;
	vector<ll> x(N), y(N), z(N);
	REP(i, N) {
		cin >> x[i] >> y[i] >> z[i];
	}
	ll res = 0;
	for (int bit = 0;bit < (1 << 3);bit++) {
		vector<ll> sum(N, 0);
		for (int i = 0;i < N;i++) {
			if (bit&(1 << 0)) sum[i] += x[i];
			else sum[i] -= x[i];
			if (bit&(1 << 1)) sum[i] += y[i];
			else sum[i] -= y[i];
			if (bit&(1 << 2)) sum[i] += z[i];
			else sum[i] -= z[i];
		}
		sort(sum.begin(), sum.end(), greater<ll>());
		ll tmp = 0;
		for (int i = 0;i < M;i++) {
			tmp += sum[i];
		}
		res = max(res, tmp);
	}
	cout << res << "\n";

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int abcde[]=new int[5];
		for(int i=0;i<abcde.length;i++) {
			abcde[i]=scan.nextInt();
		}
		int k=scan.nextInt();
		scan.close();
		if(k<(abcde[abcde.length-1]-abcde[0]))System.out.println(":(");
		else System.out.println("Yay!");
	}
}

Measured memory_bytes: 22996
#!/usr/bin/env python3
from math import factorial as f
n, k = map(int, input().split())
mod = 10**9+7
for i in range(k):
    try:
        print(f(n - k + 1) * f(k - 1) // f(i + 1) // f(n - k - i) // f(i) // f(k - i - 1) % mod)
    except ValueError:
        print(0)

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

int main()
{
	long N, W;
	cin >> N;
	cin >> W;
	long w[110],v[110];
	for (int i = 0; i < N; i++)
	{
		cin >> w[i];
		cin >> v[i];
	}
	long dp[110][100010];
	for (int i = 0; i <= W; i++)
	{
		dp[0][i] = 0;
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j <= W; j++)
		{
			if (w[i] <= j)
			{
				dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
			}
			else
			{
				dp[i + 1][j] = dp[i][j];
			}
		}
	}
	cout << dp[N][W] << endl;
}

Measured memory_bytes: 81024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
	long long int n,k,i,j;
	cin>>n>>k;
	long long int a[n+10];
	long long int ans[k+10];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ans[0]=0;
	for(i=1;i<=k;i++)
	{
		ans[i]=0;
		for(j=0;j<n;j++)
		{
			if(a[j]>i)
			break;
			if(ans[i-a[j]]==0)
			{
				ans[i]=1;
				break;
			}
		}
	}
	if(ans[k])
	cout<<"First"<<endl;
	else
	cout<<"Second"<<endl;
}

Measured memory_bytes: 1024
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;
list<long long int> Prime(int M) {
	list<long long int>P;
	P.push_back(2);
	P.push_back(3);
	for (int i = 5; i <= M; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	return P;
}

long long int N, M, K, Q, W, H;
long long int ans;



int main() {
	ios::sync_with_stdio(false);
	string s[3];
	for (int i = 0; i < 3; i++) {
		cin >> s[i];
		reverse(s[i].begin(), s[i].end());
	}
	int box = 0;
	while (1) {
		if (s[box].empty()) {
			cout << char('A' + box) << endl;
			return 0;
		}
		int bag = *s[box].rbegin() - 'a';
		s[box].pop_back();
		box = bag;
	}
	return 0;
}

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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define INF LLONG_MAX

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  ll n,m;
  
  cin >> n >> m;

  if(n>=3&&m>=3){
    cout << (n-2)*(m-2) << endl;
  }
  else if(n==1||m==1){
    if(n>=3){
      cout << n-2 << endl;
    }
    else if(m>=3){
      cout << m-2 << endl;
    }
    else if(n==1&m==1){
      cout << "1" << endl;
    }
    else{
      cout << "0" << endl;
    }
  }
  else{
    cout << "0" << endl;
  }
  
  // xxx
  // xxx
  
  return 0;
}



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

int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L.at(i);
  }

  sort(L.begin(),L.end());
  int add = 0;
  for(int i = 0; i < N-1; i++) {
    add += L.at(i);
  }

  if(L.at(N-1) < add) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    
    double x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double r = sqrt(pow(x1-x2,2) + pow(y1-y2,2));
    cout << fixed << setprecision(4) << r << endl;
}



Measured memory_bytes: 3280
#include<bits/stdc++.h>
using namespace std;
#define ld long double
int main(){
	int n;
	cin>>n;
	ld a[n+1]={};
	for(int i=1;i<=n;i++)
	cin>>a[i];
	ld dp[n+1][n+1]={};
	dp[1][1]=a[1];
	dp[1][0]=1-a[1];
	for(int i=2;i<=n;i++){
		for(int j=0;j<=i;j++){
			if(j==0){
				dp[i][j]=dp[i-1][j]*(1-a[i]);
			}
			else{
				dp[i][j]=a[i]*dp[i-1][j-1]+(1-a[i])*dp[i-1][j];
			}
		}
	}
	ld z=0;
	for(int i=n/2+1;i<=n;i++){
		z+=dp[n][i];
	}
	printf("%0.10Lf",z);
	return 0;
}

Measured memory_bytes: 140928
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s[1005];
struct node{
    int x,y;
    int step;
    node(int x,int y,int step):x(x),y(y),step(step){}
};
queue<node>q;
int vis[1005][1005];
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;++i){
        cin>>s[i];
    }
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            if(s[i][j]=='#'){
                q.push(node(i,j,0));
                vis[i][j]=1;
            }
        }
    }
    int ans=0;
    while(!q.empty()){
        node now=q.front();
        q.pop();
        for(int i=0;i<4;++i){
            int xx=now.x+dir[i][0];
            int yy=now.y+dir[i][1];
            if(xx>=0&&xx<n&&yy>=0&&yy<m&&!vis[xx][yy]){
                q.push(node(xx,yy,now.step+1));
                ans=max(ans,now.step+1);
                vis[xx][yy]=1;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 17296
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N, K; cin >> N >> K;
	chmin(K, N);
	vector<int>H(N); rep(i, 0, N) { cin >> H[i]; }
	sort(all(H));

	int ans = accumulate(all(H), 0ll);
	rep(i, 0, K) {
		ans -= H[N - 1 - i];
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
package main

import (
        "fmt"
)

func solution(n int, a []int) int {
        out := 0
        for {
                flag := true
                for i := range a {
                        if a[i]%2 != 0 {
                                flag = false
                                break
                        }
                        a[i] >>= 1
                }
                if !flag {
                        break
                }
                out++
        }
        return out
}

func main() {
        var n int
        fmt.Scan(&n)
        a := make([]int, 0, n)
        for i := 0; i < n; i++ {
                t := 0
                fmt.Scan(&t)
                a = append(a, t)
        }
        fmt.Println(solution(n, a))
}

Measured memory_bytes: 512
#  --*-coding:utf-8-*--

def f(N, XY):
    S = set(XY)
    sc = N

    for i in range(N):
        x0, y0 = XY[i]

        for j in range(i+1, N):
            x1, y1 = XY[j]

            sc = min(sc, N - g(S, x1-x0, y1-y0))

    return sc


def g(S, p, q):
    cnt = 0

    for x,y in S:
        if (x+p, y+q) in S:
            cnt += 1

    return cnt
            
    


def main():
    N = int(input())
    XY = [tuple(map(int, input().split())) for i in range(N)]

    print(f(N, XY))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
string = input()
cnt = int(input())

for i in range(cnt):
    linearr = (input().split())
    cmd = linearr[0]
    a = int(linearr[1])
    b = int(linearr[2])

    if cmd == "print":
        print(string[a:b+1])
    elif cmd == "replace":
        string = string[:a] + linearr[3] + string[b + 1:]
    elif cmd == "reverse":
        string = string[:a] + string[a:b + 1][::-1] + string[b + 1:]

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define fin(x) cout << x << endl;

using namespace std;
using ll = long long;

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

Measured memory_bytes: 384