akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̒萔 (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    string s;
    string t;
    cin >> s >> t;
    vector<int> s_c('z' + 1);
    vector<int> t_c('z' + 1);
    rep(i, s.size()) s_c[s[i]]++;
    rep(i, t.size()) t_c[t[i]]++;

    string sn = "";
    for (char i = 'a'; i <= 'z'; i++) {
        for (int j = 0; j < s_c[i]; j++) {
            sn += i;
        }
    }
    string tn = "";
    for (char i = 'z'; i >= 'a'; i--) {
        for (int j = 0; j < t_c[i]; j++) {
            tn += i;
        }
    }

    if (sn < tn)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

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

int main(){    
  int N;
  cin >> N;
  if(N == 1) cout << "Hello World" << endl;
  if(N == 2){
    int A,B;
    cin >> A >> B;
    cout << A + B << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{  int n,i,count=0;
   char s[100];
   scanf("%d%s",&n,s);
   for(i=0;s[i+2]!='\0';i++)
   {  if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')count++;

   }
   printf("%d",count);


    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define _ ios::sync_with_stdio(false);cin.tie(0);
#define __ cout<<fixed;cout<<setprecision(10);
#define int long long
#define fori(a,b) for(int i = a ; i < b ; i++)
#define forj(a,b) for(int j = a ; j < b ; j++)


void solve() {
	int n;
	cin >> n;
	int arr[n];
	fori(0, n) {
		cin >> arr[i];
	}
	int tot = 1000;
	int stocks = 0;
	int flag = arr[1] >= arr[0] ? 1 : 0;
	for (int i = 0; i < n - 1; i++) {
		if (flag == 1 && arr[i + 1] > arr[i]) {
			stocks += tot / arr[i];
			tot %= arr[i];
			//cout << i << "--\n";
			flag = 0;
		}
		else if (flag == 0 && arr[i + 1] < arr[i]) {
			tot += arr[i] * stocks;
			stocks = 0;
			flag = 1;
			//cout << i << "---\n";
		}
	}
	if (stocks > 0) {
		tot += arr[n - 1] * stocks;
	}
	cout << tot << "\n";
}

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

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

#ifndef ONLINE_JUDGE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif

	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define MOD 1000000007
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
//#define int long long  
signed main(){
    int N;
    int F[104][5][2];
    int P[104][11];
    int Ans=-(1<<30);
    cin >> N;
    REP(i,N){
        REP(j,10){
            cin >> F[i][j/2][j%2];
        }
    }
    
    REP(i,N){
        REP(j,11){
            cin >> P[i][j];
        }
    }
    for(int i=1;i<=1023;i++){
        int sum=0;
        REP(j,N){
            int kam=0;
            REP(k,10){
                if(F[j][k/2][k%2]==1 && (i>>k)&1){
                    kam++;
                }
            }
            sum+=P[j][kam];
        }
        Ans=max(Ans,sum);
    }
    cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    char g;
    cin>>s;
    int A,t,q,counter=0;
    cin>>A;
    deque<char>a;
   for(int i=0;i<s.size();i++){
   a.push_back(s.at(i));}
   for(int i=0;i<A;i++){
   cin>>t;
   if(t==1){
   counter++;
   counter=counter%2;}
   else{
   cin>>q>>g;
   if(q==1){
   if(counter%2==0){ 
   a.push_front(g);}
   else{
   a.push_back(g);}}
   else{
   if(counter%2==0){
   a.push_back(g);}
   else{
   a.push_front(g);}}}}
   if(counter%2==0){
   counter=a.size();
   for(int i=0;i<counter;i++){
   cout<<a.front();
   a.pop_front();}}
   else{counter=a.size();
   for(int i=counter;i>0;i--){
   cout<<a.back();
   a.pop_back();}}}


Measured memory_bytes: 896
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = IR(5)
    k = II()
    if max(a) - min(a) > k:
        print(":(")
    else:
        print("Yay!")
    return

#B
def B():
    a = IR(5)
    b = a[0]
    ans = 0
    for a_ in a:
        if a_ % 10 != 0:
            if b % 10> a_ % 10:
                b = a_
    flg = 0
    for a_ in a:
        if a_ != b or flg:
            ans += math.ceil(a_ / 10) * 10
        else:
            ans += b
            flg = 1
    print(ans)
            
    
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()

Measured memory_bytes: 5608
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

constexpr size_t    operator""_sz(unsigned long long value) { return value; };
constexpr intmax_t  operator""_im(unsigned long long value) { return value; };
constexpr uintmax_t operator""_um(unsigned long long value) { return value; };
// }}} End

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

    size_t N, H, W;
    cin >> N >> H >> W;

    int res = 0;
    for (size_t i = 0; i < N; ++i) {
        size_t a, b;
        cin >> a >> b;
        res += (a >= H && b >= W);
    }

    cout << res << "\n";

    return 0;
}


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

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

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    int syu;
    int zan;
    int chak;
    int gokei;
     
    public void solve(){
        Scanner sc = new Scanner(System.in);
        syu = sc.nextInt();
        while(syu!=0){
            gokei = 0;
            chak = 1;
            for(int i=1;i<=syu;i++){
                zan = sc.nextInt();
                if(zan>=2){
                    gokei = gokei+1;
                }
                if(zan>0){
                    chak = chak+1;
                }
            }
             
         
            if(gokei>0){
                System.out.println(chak);
            }else{
                System.out.println("NA");
            }
            syu = sc.nextInt();
        }
    }
    public static void main(String[]args){
        Main obj = new Main();
        obj.solve();
    }
}

Measured memory_bytes: 158644
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const ll INF = 1LL << 50;
const double EPS = 1E-10;

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

int v, d;
const int mod = 1001;
bool nums[1001];
bool used[1001];

void dfs(int p){
	used[p] = true;
	//cout <<p << endl;
	for(int i = p - d + 1; i < p + d; i++){
		if(i < 0 || i >= 1001) continue;
		if(!used[i] && nums[i]){
			dfs(i);
		}
	}
}

int main(){
	
	while(cin >> v >> d){
		memset(nums, false, sizeof(nums));
		memset(used, false, sizeof(used));
		int f0 = 1;
		int f1 = 2;
		rep(i, v){
			nums[f1] = true;
			int t = f1;
			f1 = (f0 + f1) % mod;
			f0 = t;
		}
		int cnt = 0;
		rep(i, 1001){
			if(nums[i] && !used[i]){
				cnt++;
				dfs(i);
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc =new Scanner(System.in);
		String a=sc.next();
		String b=sc.next();
		int flg=0;
		String ans;
		for(int i=0;i<3;i++){
			if(a.charAt(i)==b.charAt(2-i)) flg++;
		}
		if(flg==3) ans="YES";
		else ans="NO";

		System.out.println(ans);
	} 
}

Measured memory_bytes: 23764
n = gets.to_i
array = gets.split(" ").map(&:to_i)
result = array.inject(&:+)

(n - 1).times do |i|
  a = array.slice(0..i).inject(&:+)
  b = array.slice((i + 1)..(n - 1)).inject(&:+)
  result = (a - b).abs if result > (a - b).abs
end

puts result

Measured memory_bytes: 1788
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C, D = MAP()
if A+B > C+D:
	print("Left")
elif A+B == C+D:
	print("Balanced")
else:
	print("Right")

Measured memory_bytes: 5148
n=int(input())
if n < 10:
    print(n)
elif n<100:
    print(9)
elif n<1000:
    print(9+ n-100+1)
elif n<10000:
    print(9+900)
elif n<100000:
    print(9+900+ n-10000+1)
elif n<1000000:
    print(9+900+90000)

Measured memory_bytes: 3060
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          (x).begin(),(x).end()
#define     rz(x)           resize(x)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        (((a)*(b))/gcd((a),(b)))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

int p5(int x)
{
    int res=x*x*x*x*x;
    return res;
}

pii check(int x)
{
    if(x==0)
        return {0,1};

    x=abs(x);

    for(int i=1;p5(i)<=x;++i)
    {
        if(p5(i)==x)
            return {i,1};
    }

    return {0,0};
}

void solve()
{
    int x;
    cin>>x;

    int a,b;
    pii bi;
    for(int i=0;;++i)
    {
        a=p5(i);
        b=a-x;

        bi=check(b);
        if(bi.S)
        {
            cout<<i<<" ";
            if(b<0)
                cout<<"-";
            cout<<bi.F;

            return;
        }
    }
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 3652
from sys import stdin


def main() -> None:
    n = int(next_str())
    a = [int(input()) for _ in range(n)]
    a.sort()

    i = 0
    j = len(a) - 1
    flg = False
    left = right = 0
    ans = 0
    while i <= j:
        if not flg:
            if (a[-1] * 2 - a[0] - a[1]) > (a[-1] + a[-2] - a[0] * 2):
                left = right = a[-1]
                j -= 1
            else:
                left = right = a[0]
                i += 1
            flg = True
        else:
            best = (0, 0)
            for k, v in enumerate([left - a[i], left - a[j], right - a[i], right - a[j]]):
                if best[1] < abs(v):
                    best = (k, abs(v))
            ans += best[1]
            if best[0] == 0:
                left = a[i]
                i += 1
            elif best[0] == 1:
                left = a[j]
                j -= 1
            elif best[0] == 2:
                right = a[i]
                i += 1
            elif best[0] == 3:
                right = a[j]
                j -= 1

    print(ans)


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

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

int main() {
  vector<vector<int>> grid(3, vector<int>(3, 0));

  for (int i = 0; i < 3; i++) {
    int c1, c2, c3;
    scanf("%d%d%d", &c1, &c2, &c3);
    grid.at(i).at(0) = c1;
    grid.at(i).at(1) = c2;
    grid.at(i).at(2) = c3;
  }
  set<int> a2_diff;
  set<int> a3_diff;
  for (int x = 0; x < 3; x++) {
    a2_diff.insert(grid.at(x).at(1) - grid.at(x).at(0));
    a3_diff.insert(grid.at(x).at(2) - grid.at(x).at(0));
  }
  set<int> b2_diff;
  set<int> b3_diff;
  for (int y = 0; y < 3; y++) {
    b2_diff.insert(grid.at(1).at(y) - grid.at(0).at(y));
    b3_diff.insert(grid.at(2).at(y) - grid.at(0).at(y));
  }

  if (a2_diff.size() == 1 && a3_diff.size() == 1 && b2_diff.size() == 1 &&
      b3_diff.size() == 1)
    printf("Yes");
  else
    printf("No");
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <set>
#include <utility>

#define MAX_N (100)
#define MAX_M (1000)

typedef struct {
  int to;
  int cost;
} edge;

using namespace std;

void dijkstra(const vector<vector<edge>> &adj_lists, int s, int *distances) {
  // start from s
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      que;  // (distance, prev)
  que.push(pair<int, int>(0, s));
  while (!que.empty()) {
    const pair<int, int> p = que.top();
    const int d = p.first, v = p.second;
    que.pop();
    if (distances[v] < 0) {
      distances[v] = d;
      for (int i = 0; i < adj_lists[v].size(); i++) {
        const int u = adj_lists[v][i].to, w = adj_lists[v][i].cost;
        if (distances[u] < 0) {
          que.push(pair<int, int>(d + w, u));
        }
      }
    }
  }
}

int main(int argc, char *argv[]) {
  // read inputs
  int N, M, as[MAX_M], bs[MAX_M], cs[MAX_M];
  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; i++) {
    scanf("%d %d %d", &as[i], &bs[i], &cs[i]);
  }

  // create graph
  vector<vector<edge>> adj_lists;
  // add nodes
  for (int i = 0; i < N; i++) {
    adj_lists.push_back(vector<edge>());
  }
  // add edges
  for (int i = 0; i < M; i++) {
    int a = as[i] - 1, b = bs[i] - 1, c = cs[i];
    adj_lists[a].push_back({b, c});
    adj_lists[b].push_back({a, c});
  }

  // check which edges are used
  set<pair<int, int>> used_edges;
  for (int s = 0; s < N; s++) {
    // calculate distances from s
    int distances[MAX_N];
    memset(distances, -1, N * sizeof(int));
    dijkstra(adj_lists, s, distances);
    // check which edges are along the minimum path
    for (int v = 0; v < N; v++) {
      const int d_v = distances[v];
      for (int i = 0; i < adj_lists[v].size(); i++) {
        const int u = adj_lists[v][i].to, w = adj_lists[v][i].cost;
        if (distances[u] + w == d_v) {
          used_edges.insert(pair<int, int>(u, v));
          used_edges.insert(pair<int, int>(v, u));
        }
      }
    }
  }
  printf("%d\n", M - used_edges.size() / 2);

  return 0;
}


Measured memory_bytes: 256
s=(input())
t=(input())
n=len(t)
ans=float("inf")
for i in range(len(s)-len(t)+1):
    k=0
    l=s[i:i+n]
    for j in range(n):
        if l[j]!=t[j]:
            k+=1
    ans=min(ans,k)
print(ans)

Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    string S;
    cin >> S;
    string T = "";
    string R = "0";
    int cnt = 0;
    for(int i = 0; i < S.size(); i++) {
        T+=S[i];
        if(T == R) {
            continue;
        }
        else {
            R = T;
            T = "";
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3704
using System;
using System.Linq;
using System.Collections.Generic;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = new List<string>();
            var n = int.Parse(Console.ReadLine());
            for(int i = 0; i < n; i++)
            {
                list.Add(Console.ReadLine());
            }
            IEnumerable<string> result = list.Distinct();
            Console.WriteLine(result.Count());
        }
    }
}


Measured memory_bytes: 47936
#include <stack>
#include <iostream>

using namespace std;

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

	stack<int> a;

	for(int i = 0; i < n; i++)
	{
		int temp;

		cin >> temp;

		a.push(temp);
	}

	while(!a.empty())
	{
		cout << a.top();

		a.pop();

		if(!a.empty())
		{
			cout << ' ';
		}
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

typedef long long ll;
const int N=201000,MOD=1000000007;

ll inv(int x){return x==1?1:(-(MOD/x)*inv(MOD%x)%MOD);}

struct bit
{
	int w[N];
	inline void reset(){memset(w,0,sizeof(w));}
	inline int lowbit(int x){return x&(-x);}
	void inc(int p,int x){for(;p<N;p+=lowbit(p))w[p]=(w[p]+x)%MOD;}
	int ask(int p){int ret=0;for(;p;p-=lowbit(p))ret=(ret+w[p])%MOD;return ret;}
}T;

namespace calculator
{
	int cnt[N],D[N],bel[N];
	int *A,n;

	bool judge(int *A_,int n_)
	{
		A=A_,n=n_;
		memset(cnt,0,sizeof(cnt));
		for(int i=1;i<n;i++)cnt[i]=-1;
		for(int i=1;i<=n;i++)cnt[A[i]]++;
		for(int i=n;i;i--)cnt[i-1]+=cnt[i];

		for(int i=1;i<=n;i++)if(cnt[i]<1)return 0;
		return 1;
	}
	int solve(int *A_,int n_)
	{
		if(!judge(A_,n_))return 0;

		int ret=0,S=1;
		for(int i=1;i<=n;i++)S=(ll)S*cnt[i]%MOD;

		for(int i=1,j;i<=n;i=j+1)
		{
			for(j=i;j<n && cnt[j+1]!=1;j++);
			for(int k=i;k<=j;k++)bel[k]=i;

			D[i]=1;
			for(int k=i+1;k<=j;k++)
				D[k]=(ll)D[k-1]*(cnt[k]-1)%MOD*inv(cnt[k])%MOD;
		}

		T.reset();

		for(int i=1,x,y,z;i<=n;i++)
		{
			x=A[i]-1,y=bel[A[i]],z=(T.ask(x)-T.ask(y-1))%MOD;

			ret=(ret+(ll)z*D[A[i]]%MOD*S%MOD)%MOD;

			T.inc(A[i],inv(D[A[i]]));
		}

		ret=(ret+MOD)%MOD;

		return ret*inv(2)%MOD;
	}
}

int A[N],cnt[N];
int n,S,ans;

int fuck()
{
	T.reset();
	int ret=0;
	for(int i=1;i<=n;i++)
		ret=(ret+T.ask(n)-T.ask(A[i]))%MOD,T.inc(A[i],1);
	return ret;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",A+i);

	if(!calculator::judge(A,n)){printf("0\n");return 0;}

	for(int i=S=1;i<=n;i++)
		S=(ll)S*calculator::cnt[i]%MOD;

	ans=0;
	for(int i=1;i<=n;i++)
		ans=(ans+cnt[A[i]])%MOD,cnt[A[i]]++;
	ans=(ll)ans*S%MOD*inv(2)%MOD;

	ans=(ans+calculator::solve(A,n))%MOD;

	ans=(ans+(ll)S*fuck())%MOD;
	std::reverse(A+1,A+n+1);
	ans=(ans-calculator::solve(A,n))%MOD;

	ans=(ans+MOD)%MOD;

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

	return 0;
}


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

int main(){
  int n,d;
  cin>>n>>d;
  int x[n][d];
  for(int i=0;i<n;i++){
      for(int j=0;j<d;j++){
          cin>>x[i][j];
      }
  }
  int num=0;
  for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
          int su=0;
          for(int k=0;k<d;k++){
              su+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
          }
          int dus=sqrt(su);
          if(dus*dus==su) num++;
      }
  }
  cout<<num<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int k;
    cin >> k;
    long a[k];
    for (auto &ai:a) cin >> ai;
    long nmin=2, nmax=2;
    for (int i=k-1; i>=0; i--) {
        nmin = ((nmin-1) / a[i] + 1) * a[i];
        nmax = (nmax / a[i] + 1) * a[i] - 1;
        cerr << nmin << ' ' << nmax << '\n';
        if (nmax < nmin) {
            cout << -1 << '\n';
            return 0;
        }
    }
    cout << nmin << ' ' << nmax << '\n';
    return 0;
}

Measured memory_bytes: 1024
=begin
number = 105
count = 1
divisor = 0
ans = 0
loop do 
  break if number > 200
  while count <= number
    divisor += 1 if number%count == 0
    count += 1
  end
  if divisor == 8
    ans += 1
    puts number
  end
  count = 1
  number += 2
  divisor = 0
end
puts ans
=end

a = gets.to_i
if a >=195
  puts 5
elsif a >= 189
  puts 4
elsif a >= 165
  puts 3
elsif a >= 135
  puts 2
elsif a >= 105
  puts 1
else
  puts 0
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ll long long
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
int gcd(int a, int b){
    if(a%b == 0){
        return b;
    }else{
    return gcd(b, a%b);
    }
}

int main(){
    int x;
    cin>> x;
    if(x==1) cout<<0<<endl;
    else cout << 1<< endl;
    return 0;    
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;
int main()
{
	ll n;
	cin >> n;
	string str = "";

	while (n > 0) { 
        ll rem = n % 26; 
        if (rem == 0) { 
            str += 'z'; 
            n = (n / 26) - 1; 
        } 
        else
        { 
            str += (rem - 1) + 'a'; 
            n = n / 26; 
        } 
    } 


    reverse(str.begin(), str.end());
    cout << str;
	return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

int cmpDsc(const void* a, const void* b){
    int x = *(int*)a, y = *(int*)b;
    if(x < y){
        return 1;
    }
    if(x > y){
        return -1;
    }
    return 0;
}

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    int a[n+1];
    rep(i, 0, n+1){
        a[i] = 0;
    }
    rep(i, 0, n){
        int b;
        scanf("%d", &b);
        a[b]++;
    }
    qsort(a, n+1, sizeof(int), cmpDsc);
    int ans=0;
    rep(i, k, n+1){
        ans += a[i];
    }
    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <map>
#include <bitset>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <list>
#include <sstream>

#define ll long long
#define ld long double
#define ull unsigned long long
using namespace std;

const ll mod = 1000000007;
const ll inf = 9223372036854775803;
const int maxN = 300005;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    if (s == "ABC") {
        cout << "ARC";
    } else {
        cout << "ABC";
    }
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<pi,null_type,less<pi>,rb_tree_tag,tree_order_statistics_node_update> indexed_set_pair;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)1e3+5;
const int Q = 102;
const int logN = 19;

const double pie = acos(-1);

void solve() {
    int a;
    cin>>a;
    cout<<(a + a*a + a*a*a);
}
int main() {
    //freopen("./sort/b2.in","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


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


int main() 
{
	int A, B, C, D, X, N, M;
	char S[3];
	cin >> S;
	if (S[0] != S[1] && S[1] != S[2] && S[2] != S[0]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,-1,0};
const int vy[4] = {1,0,0,-1};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll

int n;
double p[10000];
double dp[3100][3100];


signed main(){
  cin>>n;
  rep(i,n){
    cin>>p[i+1];
  }

  dp[0][0]=1;
  FOR(i,1,n+1){
    dp[i][0]=dp[i-1][0]*(1-p[i]);
    FOR(j,1,i+1){
      dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
    }
  }

  double ans=0;
  FOR(i,n/2+1,n+1){
    ans+=dp[n][i];
  }

  printf("%.10lf\n",ans);
}


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

int field[52][52];

void dfs(int y, int x)
{
  static const int dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
  static const int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1};

  if (field[y][x] != 1)
    return;
  field[y][x] = 2;
  for (int i = 0; i < 8; ++i) {
    dfs(y+dy[i], x+dx[i]);
  }
}

int main()
{
  int w, h;
  while (scanf("%d%d", &w, &h), w|h) {
    memset(field, 0, sizeof(field));
    for (int i = 1; i <= h; ++i) {
      for (int j = 1; j <= w; ++j) {
        scanf("%d", &field[i][j]);
      }
    }
    int count = 0;
    for (int i = 1; i <= h; ++i) {
      for (int j = 1; j <= w; ++j) {
        if (field[i][j] == 1) {
          ++count;
          dfs(i, j);
        }
      }
    }
    printf("%d\n", count);
  }
}

Measured memory_bytes: 0
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
	int a[2];
	for(int i = 0; i < 2; i++){
		a[i] = 0;
		for(int j = 0; j < 4; j++){
			int t; scanf("%d", &t);
			a[i] += t;
		}
	}
	printf("%d\n", max(a[0],a[1]));
}

Measured memory_bytes: 1020
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(123456789012345678)
#define MAX_V 1000


int main(void){
	int N, K;	cin >> N >> K;
	vector<int> h(N);
	rep(i,N){
		cin >> h[i];
	}

	vector<int> dp(N, INF);
	dp[0] = 0;

	rep(i,N){
		reps(j, K){
			if(i+j < N){
				dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
			}
		}
	}
	cout << dp[N-1] << endl;
	return 0;
}


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

int main()
{
    int n,m,x,ans=0,ans1=0;
    map<int,int>cnt,cnt1;
    string s;
    cin>>n>>m;
    for(int i=0;i<m;i++){ 
        cin>>x>>s;
        if(cnt[x]==0){ 
        if(s=="AC"){ 
            ans++;
            cnt[x]=1;
            ans1+=cnt1[x];
        }    
        else cnt1[x]++;
        } 
    }
        
      
    cout<<ans<<" "<<ans1;
        
        
    return 0;
}


Measured memory_bytes: 9600
from collections import deque


X = input()
stk = deque()

for c in X:
    if len(stk) == 0:
        stk.append(c)
    else:
        if stk[-1] == "S":
            if c == "T":
                stk.pop()
            else:
                stk.append(c)
        else:
            stk.append(c)
print(len(stk))

Measured memory_bytes: 5092
#include <algorithm>
#include <iostream>
#include <vector>

void input(std::vector<int> *vector) {
  for (auto iv = vector->begin(); iv != vector->end(); ++iv) {
    std::cin >> *iv;
  }
  std::sort(vector->begin(), vector->end());
}

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

  std::vector<int> a(n);
  std::vector<int> b(n);
  std::vector<int> c(n);
  
  input(&a);
  input(&b);
  input(&c);
  
  long ans = 0;
  for (auto bi : b) {
    const auto a_upper = std::upper_bound(a.begin(), a.end(), bi - 	1);
    long a_count = a_upper - a.begin();
    if (0 == a_count) {
      continue;
    }
    const auto c_upper = std::upper_bound(c.begin(), c.end(), bi);
    long c_count = c.end() - c_upper;
    if (0 == c_count) {
      break;
    }
    ans += a_count * c_count;
  }
  
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template <typename _Tp>
struct BIT {
  vector<_Tp> bit;
  _Tp sz;
  BIT() {
    sz = 1;
  }
  BIT(_Tp m) {
    this->alloc(m);
  }

  void alloc(_Tp m) {
    bit.resize(m+1);
    this->sz = m+1;
  }

  // 1-indexed, [1, index] の総和
  _Tp get(_Tp index) {
    ll ret = 0;
    for (int i = index; i > 0; i -= i & (-i)) ret += bit[i];
    return ret;
  }

  // 1-indexed, (x, y]までの区間和を取る。
  ll sum(int x, int y) {
    return get(y) - get(x);
  }

  // 1-indexed a[index]をvalueだけ追加
  // ex) 0要素に1を加算したい -> bit.add(0+1, 1);
  void add(_Tp index, _Tp value) {
    if (index == 0) {
      cerr << "BIT add, idx must larger than 0" << endl;
      return;
    }
    for (_Tp i = index; i <= sz; i += i & (-i)) {
      bit[i] += value;
    }
  }
};

int main() {
  BIT<int> bits[27];
  int n, q;
  string s;
  cin >> n >> s >> q;
  for (int i = 0; i < 27; ++i) {
    bits[i].alloc(n+10);
  }
  for (int i = 0; i < n; ++i) {
    int ch = s[i] - 'a';
    bits[ch].add(i+1, 1);
  }
  for (int i = 0; i < q; ++i) {
    int com;
    cin >> com;
    if (com == 1) {
      char after;
      int t1;
      cin >> t1 >> after;
      int bef = s[t1-1] - 'a';
      int aft = after - 'a';
      s[t1-1] = after;
      bits[bef].add(t1, -1);
      bits[aft].add(t1, 1);
    } else if (com == 2) {
      int l, r;
      cin >> l >> r;
      l--;
      int cnt = 0;
      for (int j = 0; j < 26; ++j) {
        if (bits[j].sum(l, r) > 0) cnt += 1;
      }
      cout << cnt << endl;
    }
  }
}

Measured memory_bytes: 55812
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h>

typedef struct _node {
	int key;
	struct _node *next;
	struct _node *prev;
} NODE, *PNODE;

PNODE root;

void init(void) {
	root = (NODE *)malloc(sizeof(NODE));
	root->next = root;
	root->prev = root;
}

void insert(int key) {
	PNODE t = (NODE *)malloc(sizeof(NODE));
	t->key = key;
	t->next = root->next;
	t->prev = root;
	root->next->prev = t;
	root->next = t;
}

void deleteNode(PNODE node) {
	if (node == root) {
		return;
	}
	node->next->prev = node->prev;
	node->prev->next = node->next;
	free(node);
}

void _delete(int key) {
	PNODE cur = root->next;
	while (cur != root) {
		if (cur->key == key) {
			deleteNode(cur);
			return;
		}
		cur = cur->next;
	}
}

void deleteFirst(void) {
	deleteNode(root->next);
}

void deleteLast(void) {
	deleteNode(root->prev);
}

void printNodes(void) {
	PNODE cur = root->next;
	while (1) {
		printf("%d", cur->key);
		cur = cur->next;
		if (cur != root) {
			putchar(' ');
		}
		else {
			break;
		}
	}
	putchar('\n');
}

void release(void) {
	PNODE tmp, cur = root->next;
	while (cur != root) {
		tmp = cur;
		cur = cur->next;
		deleteNode(tmp);
	}
	free(root);
}

int main(void) {
	char cmd[100];
	int n, i, f;
	int key;

	init();

	scanf("%d", &n);

	f = 0;
	while (scanf("%s", cmd) > 0) {
		if (cmd[0] == 'i') {
			f = 1;
		}
		else if (cmd[0] == 'd') {
			switch (cmd[6]) {
			case '\0':
				f = 2;
				break;
			case 'F':
				deleteFirst();
				break;
			case 'L':
				deleteLast();
				break;
			}
		}
		else {
			key = atoi(cmd);
			if (f == 1) {
				insert(key);
			}
			else if (f == 2) {
				_delete(key);
			}
		}
	}

	printNodes();

	release();

	return 0;
}

Measured memory_bytes: 31848
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;
struct Data{

  long double x;
  long double y;
};
int main(){

  int N;
  cin>>N;
  vector<Data>data(N);
  double countmax=1;
  for(double i=0;i<=N-1;i++){
  
    cin>>data[i].x>>data[i].y;
    countmax*=i+1;
  }
  double x;
  double x2;
  double y;
  double y2;
  vector<double>P(N);
  for(int i=0;i<=N-1;i++)P[i]=i+1;
  double ave=0;
  do{
    for(int i=0;i<=N-2;i++){
    
      x=data[P[i]-1].x;
      x2=data[P[i+1]-1].x;
      y=data[P[i]-1].y;
      y2=data[P[i+1]-1].y;
      ave+=sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));
    }
  }while(next_permutation(P.begin(),P.end()));
  ave/=countmax;
  cout<< fixed << setprecision(15)<<ave;
  return 0;
}

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

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

    int ans = 0;
    double tmp_ans = 0.0;
    double i = 1.0;
    // while(tmp_ans <= double(k)){
    //     tmp_ans = pow(double(k),i);
    //     cout << tmp_ans << endl;
    //     i++;
    // }

    int j=0;
    double ab = 0.0;
    while(true){
        ab = pow(double(k),double(j));
        if(ab > double(n)){
            break;
        }
        
        j++;
    }

    ans = int(j);


    cout << ans << endl;
}

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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int a,b,m;
    cin>>a>>b>>m;
    int c1[a];
    int c2[b];
    for(int i=0;i<a;++i)
    {
        cin>>c1[i];
    }
    for(int j=0;j<b;++j)
    {
        cin>>c2[j];
    }
    int ans=(*min_element(c2,c2+b))+(*min_element(c1,c1+a));
    for(int i=0;i<m;++i)
    {
        int x,y,z;
        cin>>x>>y>>z;
        x--;y--;
        ans=min(ans,c1[x]+c2[y]-z);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1792
def euclid(A,B):

    big = max(A,B)
    small = min(A,B)

    r = big % small
    while r != 0:
        big = small
        small = r
        r = big % small
    
    return small


def LCM(A,B):
    return A*B//euclid(A,B)
    

N = int(input())

time = 1
for i in range(N):
    T = int(input())
    time = LCM(time,T)

print(time)

Measured memory_bytes: 3064
<?php

function check($a, $b, $c)
{
    $sum = 0;
    for ($i = 0; $i < count($a); $i++) {
        $sum += $a[$i] * $b[$i];
    }

    return $sum + $c > 0;
}

// 入力
fscanf(STDIN, "%d %d", $n, $m);

$v = [];
$shops = [];
for ($i = 0; $i < $n; $i++) {
    $str = fgets(STDIN);
    $s = array_map('intval', explode(' ', $str));
    $v[] = $s[0];
    $shops[] = [
        'value' => $s[0],
        'limit' => $s[1],
    ];
}

// A を安い順にソート
array_multisort($v, SORT_ASC, $shops);

// M 本になるまで金額を足していく
$yen = 0;
$count = 0;

$shopIndex = 0;
$shopCount = 0;

while ($count < $m) {
    if ($shopCount < $shops[$shopIndex]['limit']) {
        $yen += $shops[$shopIndex]['value'];
        $count++;
        $shopCount++;
    } else {
        $shopIndex++;
        $shopCount = 0;
    }
}

# 出力
echo $yen . "\n";


Measured memory_bytes: 58996
#include<iostream>
int main(){for(int a,b,c,d=0;std::cin>>a>>b,a||b;){c=0;for(;a<=b;a++)if(!(a%400)||!(a%4)&&(a%100))c++?0:d?puts(""):0,std::cout<<a<<'\n';if(!c)std::cout<<"\nNA\n";d++;}}

Measured memory_bytes: 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int maxn =2e5+50;
int n;
vector<int> b;
int a[maxn];
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(n%2==1)
    {
        for(int i=n-1;i>=0;i-=2)
        {
            if(i!=n-1)
                printf(" ");
            printf("%d",a[i]);
        }
        for(int i=1;i<n;i+=2)
        {
            printf(" %d",a[i]);
        }
    }
    else
    {
        for(int i=n-1;i>=0;i-=2)
        {
            if(i!=n-1)
                printf(" ");
            printf("%d",a[i]);
        }
        for(int i=0;i<n;i+=2)
        {
            printf(" %d",a[i]);
        }
    }
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 2944
N = int(input())
S = []
for i in range(N):
  S.append(input())

dict = {}
for i in range(N):
  if S[i] in dict:
    dict[S[i]] += 1
  else:
    dict[S[i]] = 1

m = 0
for k in dict:
  m = max(dict[k], m)

arr = []

for k in dict:
  if dict[k] == m:
    arr.append(k)

arr.sort()

for k in arr:
  print(k)


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  string s; cin >> s;

  int ans = INF;
  rep(i,s.size()-2){
    string t = "";
    t+=s[i];
    t+=s[i+1];
    t+=s[i+2];
    int tmp = stoi(t);
    ans = min(ans,abs(753-tmp));
  }

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


Measured memory_bytes: 3600
a,b=map(int,input().split())
c=1
for i in range(2,int(max(a**.5,b**.5))+2):
    if a%i==0==b%i:
        c+=1
    while a%i==0:
        a//=i
    while b%i==0:
        b//=i
if a==b!=1:
    c+=1
print(c)

Measured memory_bytes: 3060
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int n,ans,temp;
int f(int x){
    int cnt=0;
    while(x%2==0){
        cnt++;
        x/=2;
    }
    return cnt;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    if(n==1){
        cout<<1<<endl;
        return 0;
    }
    for(int i=1;i<=n;i++){
        if(f(i)>temp){
            temp=f(i);
            ans=i;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
s = list(input())
check = 'Yes'
for i in range(len(s)):
    if (i + 1) % 2 == 0:
        if s[i] == "R":
            check = 'No'
            break
    if (i + 1) % 2 != 0:
        if s[i] == "L":
            check = 'No'
            break

print(check)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

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: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
typedef unsigned long long int uli;
using namespace std;
int main() {
	int k;
	vector<int> s = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

	cin >> k;
	cout<<s.at(k - 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n,s) for (int i=a;s>0?i<n:i>n;i+=s)
#define rep(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int inf = 1e9+10, mod = 1e9+7; const long long llinf = 1e18;
// head

int main(){
  long long a;
  int b;
  string bb,c;
  cin >> a >> bb;
  rep(i,bb.size()){
    if (bb[i] != '.') c += bb[i];
  }
  b = stoi(c);
  cout << a*b/100 << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n,h;
    cin>>h>>n;
    vector<int> a(n),b(n),dp(h+1,1e9);
    rep(i,n)cin>>a[i]>>b[i];
    dp[0]=0;
    rep(i,n)rep(j,h+1)dp[min(j+a[i],h)]=min(dp[min(j+a[i],h)],dp[j]+b[i]);
    cout<<dp[h]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...)                                                             \
    { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
  public:
    void solve() {
        int n;
        cin >> n;
        vector<int> a(n), b(maxn + 2);
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
            b[a[i]]++;
        }
        i64 ans = 0;
        for (int i = 1; i < maxn; ++i) {
            ans += 1ll * b[i] * (b[i] - 1) / 2;
        }
        for (int i = 0; i < n; ++i) {
            i64 cur = ans;
            cur -= 1ll * b[a[i]] * (b[a[i]] - 1) / 2;
            cur += 1ll * (b[a[i]] - 1) * (b[a[i]] - 2) / 2;
            cout << cur << '\n';
        }
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

Measured memory_bytes: 4224