akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long ;
int main(){
    ll x;
    ll ans=0;
    cin >> x;
    for(ll i=0;i<=pow(10,9);i++){
        if(ans>=x){
            cout << i-1 << endl;
            return 0;
        }
        ans+=i;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  int k[m],s[m][20],p[m];
  for(int i=0;i<m;i++){
       cin>>k[i];
    for(int j=0;j<k[i];j++){
       cin>>s[i][j];
    }
  }
  for(int i=0;i<m;i++) cin>>p[i];
  
  int ans=0;
  for(int bit=0;bit<(1<<n);bit++){
    int light=0;
    for(int i=0;i<m;i++){
      int cnt=0;
      for(int j=0;j<k[i];j++){
        if(bit&(1<<s[i][j]-1)) cnt++;
      }
      if(p[i]==0&&(cnt%2==0)) light++;
      if(p[i]==1&&(cnt%2!=0)) light++;
    }
    if(light==m) ans++;
  }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

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

















ll POW(ll n, ll m, ll p){
    ll res = 1, x = n;
    for(ll i = m; i > 0; i >>= 1){
        if(i & 1){
            res *= x;
            res %= p;
        }
        x *= x;
        x %= p;
    }
    return res;
}
 
int main(){
    ll n;
    cin >> n;
    vector<vector<pair<ll, ll>>> g(n);
    REP(i, n - 1){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back({b, 1LL << i});
        g[b].push_back({a, 1LL << i});
    }
    ll m;
    cin >> m;
    vector<ll> u(m), v(m);
    REP(i, m){
        cin >> u[i] >> v[i];
        u[i]--; v[i]--;
    }
    
    vector<ll> es(m);
    REP(i, m){
        [&, dfs = [&](auto &&dfs, ll now, ll par, ll target){
            if(now == target) return true;
            for(auto &next : g[now]){
                if(next.first == par) continue;
                es[i] ^= next.second;
                bool f = dfs(dfs, next.first, now, target);
                if(f) return true;
                es[i] ^= next.second;
            }
            return false;
        }](){ dfs(dfs, u[i], -1, v[i]); }();
    }
    /*
    REP(i, m){
        cerr << es[i] << endl;
    }
    */
    
    ll ans = 0;
    REP(bit, (1LL << m)){
        ll cnt = 0, e = 0;
        REP(i, m){
            if(bit & (1LL << i)){
                cnt++;
                e |= es[i];
            }
        }
        ll c = 0;
        while(e){
            if(e & 1) c++;
            e >>= 1;
        }
        ll val = 1LL << (n - 1 - c);
        if(cnt % 2 == 1) ans -= val;
        else ans += val;
        // cerr << bit << " " << val << " " << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

    Int k, n;
    cin >> k >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }

    Int ans = 0;
    for (Int i = 1; i < n; i++) {
        ans = max(ans, a[i] - a[i - 1]);
    }
    ans = max(ans, a.front() + (k - a.back()));
    ans = k - ans;

    cout << ans << endl;

    return 0;
}

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

using namespace std;

typedef long int lint;
typedef long long int llint;

#define INF 1073741824
#define LINF 4611686018000000000
#define MOD 1000000007

int main() {
    string s, t;
    cin >> s >> t;
    int ans = t.size();
    int n = s.size(), m = t.size();
    for (int i = 0; i <= n - m; i++) {
        int tmp = 0;
        for (int j = 0; j < m; j++) {
            if (s[i + j] != t[j]) tmp++;
        
        }
        ans = min(tmp, ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var nab = Input.ar;
        const int LI = 401;
        var abc = new int[nab[0]][];
        for (var i = 0; i < nab[0]; i++)
            abc[i] = Input.ar;
        var dp = new int[nab[0]+1, LI, LI];
        for (var i = 0; i <= nab[0]; i++)
            for (var j = 0; j < LI; j++)
                for (var h = 0; h < LI; h++)
                    dp[i, j, h] = int.MaxValue;
        dp[0, 0, 0] = 0;
        for(var i = 1; i <= nab[0]; i++)
        {
            for (var j = 0; j < LI; j++)
            {
                for (var h = 0; h < LI; h++)
                {
                    dp[i, j, h] = Min(dp[i, j, h], dp[i - 1, j, h]);
                    if (j - abc[i - 1][0] < 0 || h - abc[i - 1][1] < 0)
                        continue;
                    if (dp[i - 1, j - abc[i - 1][0], h - abc[i - 1][1]] != int.MaxValue)
                        dp[i, j, h] = Min(dp[i, j, h], dp[i - 1, j - abc[i - 1][0], h - abc[i - 1][1]] + abc[i - 1][2]); 
                }
            }
        }
        var min = int.MaxValue;
        for(var i=1;i<LI;i++)
            for(var j = 1; j < LI; j++)
                if (i * nab[2] == j * nab[1])
                    min = Min(min, dp[nab[0], i, j]);
        WriteLine(min == int.MaxValue ? -1 : min);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public  static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 36704
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL

ll ncr(ll n, ll r){
  if(n < r) return 0;
  if(r > n-r) r = n-r;

  ll a = 1, b = 1;
  for(int i = 0; i < r; i++){
    a *= (n - i);
  }
  for(int i = 0; i < r; i++){
    b *= (i + 1);
  }
  return a/b;
}

int main(){
  ll N;
  cin >> N;
  vector<string> s(N);
  for(int i = 0; i < N; i++){
    cin >> s.at(i);
    sort(ALL(s.at(i)));
  }
  map<string, ll> ma;
  for(int i = 0; i < N; i++){
    if(!ma.count(s.at(i))){
      ma[s.at(i)] = 1;
    }
    else ma.at(s.at(i))++;
  }
  ll ans = 0;
  for(auto ite = ma.begin(); ite != ma.end(); ite++){
    int n = ite -> second;
    ans += ncr(n, 2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 18176
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int n = sc.nextInt();

		if (n == 0){
			System.out.println(x);
			return;
		}

		HashSet<Integer>set = new HashSet<>();
		for (int i=0; i<n; i++){
			set.add(sc.nextInt());
		}

		for (int i=0; i<=200; i++){
			if (!set.contains(x-i)){
				System.out.println(x-i);
				return;
			}
			if (!set.contains(x+i)){
				System.out.println(x+i);
				return;
			}
		}
	}

}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main() {
    int H, W;
    cin>>H>>W;
    
    rep(h,H)rep(w,W){
        string s;
        cin>>s;
        if(s=="snuke"){
            cout << (char)('A'+w) << 1+h <<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int N = Integer.parseInt(str);
        str = br.readLine();
        String[] s = str.split(" ");
        int[] H = new int[N];
        for (int i=0;i<N;i++){
            H[i] = Integer.parseInt(s[i]);
        }
        int ans = 1;
        int mx = H[0];
        for (int i=1;i<N;i++){
            if (H[i]>=mx){
                ans++;
                mx = H[i];
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main() {
    string s;
    cin >> s;
    int count = 0;
    for (int i = 0; i < s.size(); i++) {
        count = (count + s[i] - '0') % 9;
    }
    if (count == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3748
let a = 1000000007

let fact n =
  let rec aux m acc =
    if m = 1 then acc
    else aux (pred m) ((acc * m) mod a)
  in
  aux n 1

let solve n m=
  match abs (n - m) with
  | 0 -> let l = fact n in ((l * l) mod a) * 2 mod a
  | 1 -> ((fact n) * (fact m)) mod a
  | _ -> 0

let () = Scanf.scanf "%d %d" solve |> Printf.printf "%d\n"

Measured memory_bytes: 4480
N, x = map(int, input().split())
arr = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
    if x >= arr[i]:
        x -= arr[i]
        ans += 1
    else:
        break
if ans == N and x != 0:
    ans -= 1
print(ans)

Measured memory_bytes: 38384
#include <cstdio>
#define min(x,y) (x<y?x:y)
const int maxn=2e5+7;
int n;
int a[maxn];
char s[maxn];
int main(){
  scanf("%d%s",&n,s+1);
  for(int i=1;i<=n;++i)
    a[i]=a[i-1]+(s[i]=='#');
  int sum=0,ans=n;
  for(int i=n;i;--i)
    ans=min(ans,a[i]+sum),sum+=(s[i]=='.');
  printf("%d\n",min(ans,sum));
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)

std::string l = "qwertasdfgzxcvb",r = "yuiophjklnm";

int han(string s){
  rep(i,l.size()){
    if(l.substr(i,1) == s) return 1;
  }
  return 0;
}

int main(){
  string s;
  while(cin >> s){
    if(s== "#") break;
    int pre = han(s.substr(0,1)),ans=0;
    rep(i,s.size()){
      if( pre != han(s.substr(i,1)) ){
	ans++;
	pre = han(s.substr(i,1));
      }
    }
    cout << ans << endl;
  }

}

Measured memory_bytes: 1192
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


int main(){
    string s; cin >> s;
    ll k; cin >> k;
    int cnt = 0;
    rep(i,100){
        if(s[i] == '1') cnt++;
        else break;
    }
    if(cnt >= k){
        cout << 1 << endl;
        return 0;
    }else{
        cout << s[cnt] << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int a, b;
    double e, f;
    scanf("%d %d",&a, &b);
   e = a;
   f = b;
    printf("%d %d %f\n", a/b,  a%b, e/f); 
    return 0;
}



Measured memory_bytes: 2740
<?php
//標準入力一行取得
$n = trim(fgets(STDIN));
$result = 0;
for($a = 1; $a < $n; $a++){
    for($b = 1; $b < $n; $b++){
        if($n <= $a * $b){
            break;
        }else{
            $result++;
        }
    }
}
echo $result;
?>


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

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    long long ans=0;
    for(int i=0;i<n;++i){
        cin >> v[i];
        v[i]--;
        ans+=v[i];
    }
    cout << ans << endl;
}

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

typedef pair<int, int> pi;

int n;
pi a[100005];
int main(){
    cin >> n;
    for(int i = 0; i < n; i++){ cin >> a[i].first; a[i].second = i+1; }
    sort(a, a+n);
    for(int i = 0; i < n; i++) cout << a[i].second << " ";
}


Measured memory_bytes: 1536
def solve(s):
    for i, j in zip(range(0, len(s) - 1), range(2, len(s)+1)):
        if s[i] == s[j - 1]:
            return "%d %d" % (i + 1, j)

    for i, j in zip(range(0, len(s) - 2), range(3, len(s)+1)):
        if s[i] == s[j - 1]:
            return "%d %d" % (i + 1, j)

    return "%d %d" % (-1, -1)

if __name__ == "__main__":
    print(solve(input()))


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

import heapq
N,M = map(int,input().split())
LRC = [tuple(map(int,input().split())) for i in range(M)]

es = [[] for i in range(N)]
for l,r,c in LRC:
    l,r = l-1,r-1
    es[l].append((r,c))
for i in range(N-1):
    es[i+1].append((i,0))

INF = 10 ** 18
dist = [INF]*N
dist[0] = 0
hq = [(0,0)]
heapq.heapify(hq)

while(hq):
    d,v = heapq.heappop(hq)
    if v==N-1:
        print(d)
        exit()
    for to,c in es[v]:
        if d+c >= dist[to]: continue
        dist[to] = d+c
        heapq.heappush(hq, (d+c, to))
print(-1)

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

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		List<Edge> edges = new ArrayList<Main.Edge>();
		for (int i = 0; i < m; i++) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int c = scanner.nextInt();
			edges.add(new Edge(a, b, c));
		}
		System.out.println(kruskal(n, edges));
	}

	private int kruskal(int n, List<Edge> edges) {
		int totalCost = 0;
		Collections.sort(edges);
		UnionFind unionFind = new UnionFind(n);
		for (Edge edge:edges) {
			if (!unionFind.isSame(edge.sorce, edge.target)) {
				totalCost += edge.cost;
				unionFind.merge(edge.sorce, edge.target);
			}
		}
		return totalCost;
	}

	class Edge implements Comparable<Edge> {
		int sorce, target, cost;

		@Override
		public String toString() {
			return "Edge [sorce=" + sorce + ", target=" + target + ", cost="
					+ cost + "]";
		}

		public Edge(int sorce, int target, int cost) {
			super();
			this.sorce = sorce;
			this.target = target;
			this.cost = cost;
		}

		@Override
		public int compareTo(Edge o) {
			return this.cost - o.cost;
		}

	}

	class UnionFind {
		int[] rank, node;

		UnionFind(int size) {
			rank = new int[size];
			node = new int[size];
			for (int i = 0; i < size; i++) {
				node[i] = i;
			}
		}

		@Override
		public String toString() {
			return "UnionFind [rank=" + Arrays.toString(rank) + ", node="
					+ Arrays.toString(node) + "]";
		}

		int find(int x) {
			if (x == node[x])
				return x;
			return node[x] = find(node[x]);
		}

		boolean isSame(int x, int y) {
			return find(x) == find(y);
		}

		void merge(int x, int y) {
			x = find(x);
			y = find(y);
			if (x == y)
				return;
			if (rank[x] > rank[y])
				node[y] = x;
			else {
				node[x] = y;
				if (rank[x] == rank[y])
					rank[y]++;
			}
		}

	}
}

Measured memory_bytes: 108404
#include<bits/stdc++.h>
using namespace std;
int main(){
int n ;
  cin>>n;
  int arr[n][2];
  for(int i =0; i<n;i++)
    for(int j =0; j<2; j++)
      cin >>arr[i][j];
int count=0;
  for(int i =0; i< (n-2); i++)
  if( (arr[i][0]==arr[i][1]) && (arr[i+1][0]==arr[i+1][1]) && (arr[i+2][0]==arr[i+2][1]) )
count++;
  if(count) cout <<"Yes"<<endl;
  else cout << "No"<<endl;
  return 0;  }


Measured memory_bytes: 3628
a=int(input())
b=int(input())
c=int(input())
x=int(input())
cnt=0
for i in range(a+1):
        for j in range(b+1):
                for k in range(c+1):
                        sm=i*500+j*100+k*50
                        if sm==x:
                                cnt+=1
print(cnt)

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

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

    for (int i = x - (k - 1); i < x + k; i++)
    {
        cout << i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main() {
	while (true) {
		int w, h;
		cin >> w >> h;
		if (w == 0) return 0;
		vector<pair<int, int>> ending;
		long long cost[60][30] = {};
		long long dp[2][60][30] = {};
		int visited[2][60][30] = {};
		REP(i, 2) {
			REP(q, 60) {
				REP(j, 30) {
					dp[i][q][j] = LONG_INF;
				}
			}
		}
		priority_queue<tuple<int, int, int, int>> next;
		REP(i, h) {
			REP(q, w) {
				string s;
				cin >> s;
				if (s == "S") {
					REP(j, 2) {
						dp[j][i][q] = 0;
						next.push(make_tuple(-0, j, i, q));
					}
				}
				else if (s == "T") {
					ending.push_back(make_pair(i, q));
				}
				else if (s == "X") {
					cost[i][q] = -1;
				}
				else {
					cost[i][q] = s[0] - '0';
				}
			}
		}
		int xe[9] = { 2,1,0,-1,-2,1,0,-1,0 };
		int ye[9] = { 1,1,1,1,1,2,2,2,3 };
		while (next.empty() == false) {
			tuple<int, int, int, int> now = next.top();
			next.pop();
			int now_here_x = get<2>(now);
			int now_here_y = get<3>(now);
			int asi = get<1>(now)+1;
			asi %= 2;
			if (visited[(asi+1)%2][now_here_x][now_here_y] == 0) {
				visited[(asi+1)%2][now_here_x][now_here_y] = 1;
				REP(q, 9) {
					int now_x = now_here_x + xe[q];
					int now_y = now_here_y;
					if (asi == 0) {
						now_y -= ye[q];
					}
					else {
						now_y += ye[q];
					}
					if (now_x >= 0 && now_x < h && now_y >= 0 && now_y < w) {
						if (cost[now_x][now_y] != -1) {
							int next_cost = dp[(asi + 1) % 2][now_here_x][now_here_y] + cost[now_x][now_y];
							if (dp[asi][now_x][now_y] > next_cost) {
								dp[asi][now_x][now_y] = next_cost;
								next.push(make_tuple(-next_cost, asi, now_x, now_y));
							}
						}
					}
				}
			}
		}
		long long ans = LONG_INF;
		REP(i, ending.size()) {
			ans = min(ans, dp[0][ending[i].first][ending[i].second]);
			ans = min(ans, dp[1][ending[i].first][ending[i].second]);
		}
		if (ans == LONG_INF) {
			cout << -1 << endl;
		}
		else {
			cout << ans << endl;
		}
	}
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
# define ll int
#define mmm 1000000007
#define pb push_back

									//nestedcode

 int main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   ll n,i;
   string s,ss;
   cin>>n;
   cin>>s>>ss;
   for(i=0;i<n;i++){
   	cout<<s[i]<<ss[i];
   }
  
 }   

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n,a,dp[200005][2];
ll m[200005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    dp[0][0]=1;
    rep(i,1,n+1)
    {
    	cin>>a;
    	dp[i][0]=(dp[i-1][0]+dp[i-1][1])%M;
    	if(m[a] and m[a]!=i-1)
    		dp[i][1]=(dp[m[a]-1][0]+dp[m[a]][1]+dp[m[a]-1][1])%M;
    	m[a]=i;
    	//cout<<dp[i][0]<<" "<<dp[i][1]<<"\n";
    }
    cout<<(dp[n][0]+dp[n][1])%M;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int n, c;
    cin >> n >> c;
    vector<vector<int>> d(c + 1, vector<int>(c + 1, 0));
    for (int i = 1; i <= c; i++) {
        for (int j = 1; j <= c; j++) {
            cin >> d[i][j];
        }
    }
    vector<vector<int>> v(n + 1, vector<int>(n + 1, 0));
    vector<vector<int>> vc(3, vector<int> (c + 1, 0));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> v[i][j];
            vc[(i + j) % 3][v[i][j]]++;
        }
    }

    int res = -1;
    for (int i = 1; i <= c; i++) {
        for (int j = 1; j <= c; j++) {
            if (i == j) continue;
            for (int k = 1; k <= c; k++) {
                if (i == k || j == k) continue;
                int r = 0;
                for (int a = 1; a <= c; a++) {
                    if (a != i) {
                        r += vc[0][a] * d[a][i];
                    }
                    if (a != j) {
                        r += vc[1][a] * d[a][j];
                    }
                    if (a != k) {
                        r += vc[2][a] * d[a][k];
                    }
                }
                if (res == -1 || r < res) {
                    res = r;
                }
            }
        }
    }
    cout << res << endl;
}


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

int main(){
    int n;
    string s1, s2;
    int a = 0, b = 0;

    cin >> n;
    
    for(int i = 0; i < n; i++){
        cin >> s1 >> s2;
        if(s1 > s2) a+=3;
        else if(s1 < s2) b+=3;
        else{
            a++; b++;
        }
    }

    cout << a << " " << b << endl;

}



Measured memory_bytes: 3212
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
#include <random>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define DBG(a) cerr<<(a)<<endl;
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7;
bool comp (pair<int,int> a, pair<int,int>b){
    return a.FI+a.SE<b.FI+b.SE or (a.FI+a.SE==b.FI+b.SE and a.FI<b.FI);
}
int cnt(multiset<pair<int,int>> &s, int a, int b){
    return s.count(make_pair(a,b));
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<int,int>> d;
    multiset<pair<int,int>> s;
    REP(i,n){
        int a,b;
        cin >> a>>b;
        s.insert(make_pair(a,b));
        d.push_back(make_pair(a,b));
    }
    if(d[0].FI!=0 or d[1].SE!=0 or d[1].FI!=d[0].SE or d[0].SE==0){
        cout << -1 << endl; return 0;
    }
    FOR(i,2,n){
        if(d[i].FI==0 or d[i].SE==0){
            cout << -1 << endl; return 0;
        }
    }
    FOR(i,1,d[0].SE){
        if(cnt(s,i,d[0].SE-i)==0){
            cout << -1 << endl; return 0;
        }
    }
    //0~1
    int ans=cnt(s,1,d[0].SE-1);

    FOR(i,1,d[0].SE){
        ans+=max(cnt(s,i,d[0].SE-i),cnt(s,i+1,d[0].SE-i-1));
    }
    sort(d.begin(),d.end());
    d.erase(unique(ALL(d)),d.end());
    sort(d.begin(),d.end(),comp);
    int v=0;
    for(auto it=lower_bound(ALL(d),make_pair(1,d[0].SE),comp); it<d.end();it++){
        int d0=it->FI,d1=it->SE,add=0,now=cnt(s,d0,d1);

        if(v){
            if(cnt(s,d0-1,d1-1)&&cnt(s,d0+1,d1-1)){
                add=max(v,now);
                v=min(v,now);
            }else if(cnt(s,d0-1,d1-1)){
                add=v+now;
                v=0;
            }else if(cnt(s,d0+1,d1-1)){
                add=max(v,now);
                v=now;
            }else if(cnt(s,d0,d1-1)){
                add=max(v,now)+now;
                v=0;
            }else {
                cout << -1 << endl; return 0;
            }
        }else if(cnt(s,d0-1,d1-1)){
            add=now;
        }else if(cnt(s,d0-1,d1)or cnt(s,d0-1,d1+1)){
            add=now;
            if(cnt(s,d0+1,d1-1)){
                v=add;
            }else if(cnt(s,d0,d1-1)){
                add*=2;
            }else{
                cout << -1 << endl; return 0;
            }
        }else{
            cout << -1 << endl; return 0;
        }
        ans+=add;
    }

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


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

#define ll long long
#define pi pair<int,int>
#define ppi pair<pi,pi>
#define mp make_pair
#define fr first
#define sc second

using namespace std;

ll Mod = 1e9 + 7;
ll Power(int x , int y){
    if(!y)return 1;
    ll Tmp = Power(x , y / 2);
    Tmp = Tmp * Tmp % Mod;
    if(y & 1)Tmp = Tmp * x % Mod;
    return Tmp;
}
const int nax = 2e5 + 100;
ll Dp[nax][2][2];
ll n , arr[nax];
ll solve(int i,int c1 , int c2){
    if(i >= n)return 0;
    ll &ret = Dp[i][c1][c2];
    if(ret + 1)return ret;
    ret = -1e18;
    ret = max(ret , arr[i] + solve(i + 2 , c1 , c2));
    ret = max(ret , arr[i] + solve(i + 2 + c1, 0 , c2));
    ret = max(ret , arr[i] + solve(i + 2 + c2, c1 , 0));
    ret = max(ret , arr[i] + solve(i + 2 + c1 + c2, 0 , 0));
    return ret;
}
int main(){

    ios::sync_with_stdio(0);
    cin.tie(0) , cout.tie(0);
    memset(Dp,-1,sizeof Dp);
    cin >> n ;
    for(int i = 0;i < n;i++)
        cin >> arr[i];
    ll Ans = solve(0,1,n%2);
    Ans = max(Ans,solve(1,0,n%2));
    if(n%2)
        Ans = max(Ans,solve(1,1,0));
    if(n%2)
        Ans = max(Ans,solve(2,0,0));
    cout << Ans << '\n';

    return 0;
}


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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

#define MAX_SIZE 1<<12
ll cost[MAX_SIZE];

int main() {
    int n, m;
    cin >> n >> m;
    vi a(m);
    vector<bitset<12> > cs(m);
    FOR(i, 1, (1<<n)) {
        cost[i] = INT_MAX;
    }
    REP(i, m) {
        int b;
        cin >> a[i] >> b;
        REP(j, b) {
            int c;
            cin >> c;
            cs[i].set(c - 1);
        }
    }
    for(int bit = 0; bit < (1 << n); ++bit) {
        if(cost[bit] < INT_MAX) {
            REP(i, m) {
                int nbit = (bit | cs[i].to_ulong());
                if(nbit < (1 << n)) cost[nbit] = min(cost[bit] + a[i], cost[nbit]);
            }
        }
    }
    cout << (cost[(1<<n) - 1] < INT_MAX ? cost[(1<<n) - 1] : -1) << "\n";

    return 0;
}


Measured memory_bytes: 256
import collections
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return collections.Counter(a)

N=int(input())
if N == 1:
  print(0)
  exit()
ps = prime_factorize(N)

cnt = 0
for p in ps:
  c = ps[p]
  i = 1
  while c >= i:
    cnt += 1
    c -= i
    i += 1
print(cnt)

Measured memory_bytes: 9464
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

/// input
int n;
vector<ll> v;

ll solve(int iv) {
    ll cnt, sum, prevSum, add;
    cnt = sum = add = 0;
    prevSum = iv;

    for (int i = 0; i < n; ++i) {
        sum += v[i];

        if (prevSum < 0 && sum <= 0) {
            add = -sum + 1;
            sum += add;
            cnt += llabs(add);

        } else if (prevSum > 0 && sum >= 0) {
            add = -sum - 1;
            sum += add;
            cnt += llabs(add);
        }

        prevSum = sum;
    }

    return cnt;
}

int main() {
    scanf("%d", &n);

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

    printf("%lld\n", min(solve(1), solve(-1)));

    return 0;
}

Measured memory_bytes: 1400
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char c) {return to_string((string) &c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

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

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> b(n);
    rep(i,n) cin >> b[i];
    ll ans = 0;
    rep(i,32){
        ll k = 1LL << i;
        vector<ll> t(n);
        rep(j,n)t[j] = b[j] % (k << 1);
        sort(all(t));
        ll cnt = 0;
        debug(t);
        rep(j,n){
            ll at = a[j] % (k << 1);
            ll id1 = lower_bound(all(t), k - at) - t.begin();
            ll id2 = upper_bound(all(t), k*2 - at - 1) - t.begin();
            cnt += (id2 - id1);
            debug(id1, id2);
            id1 = lower_bound(all(t), k * 3 - at) - t.begin();
            id2 = upper_bound(all(t), k * 4 - at - 1) - t.begin();
            cnt += (id2 - id1);
            debug(id1, id2);
        }
        debug(cnt);
        if(cnt & 1)ans += k;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=200000000000000;
double pi=3.141592653589793;

const int MOD = 1000000007;

long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	return gcd(a%b,b);
}

long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}
long myPow(long long x, long long n, long long m=MOD){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}


ll digit(ll num){
	ll ret=0;
	string s=to_string(num);
	return s.length();
}
	
class Edge{
public:
	ll num;
	ll a;
	ll b;
	ll color=0;
	Edge(ll _num,ll _a,ll _b){
		num=_num;
		a=_a;
		b=_b;
	}
};
	
	
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed<<endl;
	long double w,h,x,y;
	cin>>h>>w>>x>>y;
	cout<<setprecision(20)<<h*w/2<<endl;
	if(x*2==h&&y*2==w)cout<<1<<endl;
	else cout<<0<<endl;
}



Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

ans = 'APPROVED'
for i in range(N):
    if (A[i]%2 == 0) and (A[i]%3 != 0) and (A[i]%5 != 0):
        ans = 'DENIED'
        break

print(ans)


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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'


int a, b;

signed main()
{
    cin >> a >> b;

    if (a >=13) {
        cout << b << endl;
    } else if (a > 5) {
        cout << b/2 << endl;
    } else {
        cout << 0 << endl;
    }
}

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





int main()
{
    int b, a;

    cin >> a >> b;

    if((a % 2) == 0 || (b % 2) == 0)
    {
        cout << "Even" << endl;
    }
    else
    {
        cout << "Odd" << endl;
    }
    

    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    ll N, Q;
    cin >> N >> Q;
    fenwick_tree<ll> ft(N);
    rep(i, N) {
        ll a;
        cin >> a;
        ft.add(i, a);
    }

    rep(_, Q){
        ll q, a, b;
        cin >> q >> a >> b;
        if(q == 0){
            ft.add(a, b);
        }else{
            cout << ft.sum(a, b) << '\n';
        }
    }
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

class BIT:
    def __init__(self, n):
        # 0-indexed
        self.size = n
        self.tree = [0] * (n+1)
 
    def sum(self, i):
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s
    
    # 区間和の取得 [l, r)
    def get(self, l, r=None):
        # 引数が1つなら一点の値を取得
        if r is None: r = l+1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

    # 値の追加：添字, 値
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

# 1からnまでの等差数列の和
def get_sum(n): return (1+n)*n//2

N, K = MAP()
A = LIST()
M = max(A)

bit = BIT(M+1)
org = 0
for i in range(N-1, -1, -1):
    bit.add(A[i], 1)
    # 自分より右にある、自分より小さな数の個数
    org += bit.sum(A[i]-1)
bit = BIT(M+1)
org2 = 0
for i in range(N):
    bit.add(A[i], 1)
    # 自分より左にある、自分より小さな数の個数
    org2 += bit.sum(A[i]-1)

ans = (org*K+(org+org2)*get_sum(K-1)) % MOD
print(ans)


Measured memory_bytes: 3188
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int size = scan.nextInt(), queries = scan.nextInt();
        RangeSumQuery rmq = new RangeSumQuery(size);
        for(int i = 0; i < queries; i++){
            int c = scan.nextInt(); int x = scan.nextInt(); int y = scan.nextInt();
            if(c == 0) rmq.update(x - 1, y);
            else System.out.println(rmq.rangemin(x - 1, y - 1));
        }
    }
}

class RangeSumQuery{
    int height;
    int tree[];
    RangeSumQuery(int size){
        for(height = 0; 1 << height < size; height++);
        tree = new int[1 << (height + 1)];
        for(int i = 0; i < tree.length; i++) tree[i] = 0;
    }

    private int sibling(int i){
        if(i == 0) throw new IllegalArgumentException("");
        return ((i - 1) ^ 1) + 1;
    }

    void update(int i, int x){
        i += (1 << height) - 1;
        for(; i != 0; i = (i - 1) / 2) tree[i] += x;
        tree[0] += x;
        //dump();
    }

    int rangemin(int from, int to){
        if(!(0 <= from && from <= to && to < (1 << height)))
            throw new IllegalArgumentException("");
        int depth = height, size = (to - from) + 1, r = 0;
        from += (1 << height) - 1;
        while(0 < size){
            for(; from % 2 == 1 && 2 << (height - depth) <= size; depth--, from /= 2);
            for(; size < 1 << (height - depth); depth++, from = from * 2 + 1);
            r += tree[from];
            from++;
            size -= 1 << (height - depth);
        }
        return r;
    }

    void dump(){
        int subarr[];
        for(int i = 0; i <= height; i++){
            subarr = Arrays.copyOfRange(tree, (1 << i) - 1, (1 << i + 1) - 1);
            System.out.println(Arrays.toString(subarr));
        }
    }
}

Measured memory_bytes: 104676
#include <string>
#include <stack>
#include <stdlib.h>
#include <iostream>
#include <queue>
#include <utility>
using namespace std; 
int main()
{
    string cmd;
    priority_queue<int> Q;
    int a;
while (cin >> cmd && cmd != "end")
{
    if (cmd == "insert")
    {
        cin>>a;
        Q.push(a);
    }
    else if (cmd == "extract")
    {
        cout<<Q.top()<<endl;
        Q.pop();
    }
    
}
}


Measured memory_bytes: 7068
function myOut(text){console.log(text);}//standard output
function Main(input) {
	input = input.trim();
	//input = input.split(" ");
	input = input.split("\n");
	//input = input.split(" ").map((a)=>Number(a));
	//input = input.split("\n").map((a)=>Number(a));
  var len = parseInt(input[0]);
  var list = input[1].split("");
  var ind = list[parseInt(input[2]) - 1];
  for(var i = 0; i < len; i++){
    if(list[i] != ind){
       list[i] = "*";
       }
  }
  
  myOut(list.join(""));
}

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


Measured memory_bytes: 22208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().ToLower();

            Console.WriteLine(Enumerator().Sum(e => e.Count(f => f.Equals(s))));
        }

        private static IEnumerable<IEnumerable<string>> Enumerator()
        {
            while(true)
            {
                var s = Console.ReadLine();
                if (s.Equals("END_OF_TEXT")) yield break;
                yield return s.ToLower().Split(' ');
            }
        }

        /*private static bool IsInput(out int[] arr)
        {
            var s = Console.ReadLine();
            if (s == "0 0") { arr = null; return false; }

            arr = s.Split(' ').Select(int.Parse).ToArray();
            return true;
        }
        // */
    }
}


Measured memory_bytes: 16024
/*
    ##############################
    #  Author: Pratyush Gaurav   #
    #  College: NIT ROURKELA     #
    ##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define scan(n) scanf("%lld",&n)
#define scan2(a,b) scanf("%lld %lld",&a,&b)
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define print(n) printf("%lld\n",n)
#define scanS(s) scanf("%s",&s)
#define printS(s) printf("%s",s)

#define ff first
#define ss second
#define rep(i,a) for(i = 0 ; i < a ; i++)
#define repr(i,a) for(i = a ; i >= 0 ; i--)
#define REP(i,a,b) for(i = a ; i <= b ; i++)
#define REPR(i,a,b) for(i = a ; i >= b ; i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define pb push_back
#define popb pop_back
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

lli dx[]={0,0,-1,1,-1,-1,1,1};
lli dy[]={1,-1,0,0,1,-1,-1,1};

bool f(lli sum, lli n) {
    ld div = (ld)sum / n;
    return div >= 1.0;
}
void solve() {
    lli n, m;
    cin >> n >> m;
    lli i, ans = 1;
    for (i = 1; i * i <= m; ++i) {
        if (m % i) continue;
        if (f(m/i, n)) {
            ans = max(ans, i);
        }
        if (f(i, n)) {
            ans = max(ans, m / i);
        }
    }
    cout << ans << endl;
}

int main()
{
    opt;
    lli t = 1;
    //cin >> t;

    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 384