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

int main(){
	int n , m ; 
	cin >> n >> m ; 
	if ( n >= m ){
		cout << 0 << endl;
		return 0 ; 
	}
	vector<int> v(m) ; 
	for(int i=0;i<m;i++){
		cin >> v[i] ; 
	}
	sort(v.begin(),v.end());
	vector<int> diff ; 
	for(int i=1;i<m;i++){
		diff.push_back( abs(v[i]-v[i-1]) ) ;  
	}
	sort(diff.rbegin(),diff.rend());
	int sum = 0 ; 
	for(int i=n-1;i<(int)diff.size();i++){
		sum += diff[i] ; 
	}
	cout << sum << endl;
	return 0 ; 
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define int long long 
using namespace std;
signed main(){
  int a,b;
  cin>>a>>b;
  if(a>=10){
    cout<<b<<"\n";
  }else{
    cout<<(100*(10-a))+b<<"\n";
  }
  return(0);
}


Measured memory_bytes: 256
//#pragma GCC optimize ('O3')
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 2e5 + 5;
const int M = 5e5 + 5;
const int OO = 1e9;
const int mod = 1e9 + 7;

int n,a[N],mx;
ll ans;

void init() {}

int main() {

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

    cin >> n;

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if(a[i]<mx) ans += mx-a[i];
        else mx = a[i];
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 4396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 40;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

typedef pair<int,ll> P;
int main(){
    int N;
    ll K;
    cin >> N >> K;
    priority_queue<P,vector<P>,greater<P> > que;
    int s; ll t;
    FOR(i,0,N){
        cin >> s >> t;
        que.push(P(s,t));
    }
    while(!que.empty()){
        s = que.top().first;
        t = que.top().second;
        que.pop();
        if (K-t<=0){
            cout << s << endl;
            break;
        }else{
            K -= t;
        }
    } 
    return 0;
}

Measured memory_bytes: 2420
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		print();
	}

	private static void print() throws IOException {
		int a;
		int b;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] num = str.split(" ", 0);
		a = Integer.parseInt(num[0]);
		b = Integer.parseInt(num[1]);

		compare(a, b);
	}

	private static void compare(int a, int b) {
		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else if (a == b) {
			System.out.println("a == b");
		}
	}

}

Measured memory_bytes: 24216
#include <bits/stdc++.h>
using namespace std;
int main(void){
    std::map<string,pair<long long int,long long int>> map;
    int n,q;
    while (cin>>n>>q) {
        if (n==0&&q==0) {
            break;
        }
        long long int era_year,western_year;
        string s;
        std::deque<string> era_name;
        std::map<string, int> seen;
        std::map<string, pair<long long int,long long int>> range;
        for (int i=0;i<n;i++) {
            cin>>s>>era_year>>western_year;
            if (seen[s]==0) {
                era_name.emplace_back(s);
                seen[s]++;
            }
            if (range[s].first==0&&range[s].second==0) {
                range[s]=make_pair(western_year-era_year+1,western_year);
            } else if (range[s].second<western_year) {
                range[s].second=western_year;
            }
        }
        long long int Q;
        for (int i=0;i<q;i++) {
            cin>>Q;
            int flag=0;
            for (int j=0;j<era_name.size();j++) {
                string era=era_name[j];
                if (range[era].first<=Q&&range[era].second>=Q) {
                    cout<<era<<" "<<Q-range[era].first+1<<endl;
                    flag=1;
                    break;
                }
            }
            if (flag==0) {
                cout<<"Unknown"<<endl;
            }
        }
    }
}


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


int main(){
  long long n;
  cin >> n;
  long long cal=0;
  long long a=n;
  while(a>0){
    cal+=a%10;
    a=a/10;
  }
  if(n%cal==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


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

#define MAX 200005
#define INFTY 1e13

int main() {
	int N;
	vector<int> A(MAX);
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];

	vector<long long> ans(MAX);
	for (int i = 0; i < N; i++) ans[i] = INFTY;
	
	long long sum = 0;
	for (int i = 1; i < N; i++) sum += A[i];
	ans[0] = (long long)A[0] - sum;
	for (int i = 1; i < N; i++) {
		if ((ans[i - 1] + 2LL * (long long)A[i]) > INFTY) ans[i] = INFTY;
		else ans[i] = ans[i - 1] + 2LL * (long long)A[i];
	}
	//for (int i = 0; i < N-1; i++) cout << ans[i] << " ";

	long long minl = INFTY;
	for (int i = 0; i < N-1; i++) {
		if (minl > llabs(ans[i])) minl = llabs(ans[i]);
	}

	cout << minl << endl;

	return 0;
}

Measured memory_bytes: 2560
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  "sort"
  "container/heap"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

type Item struct {
  Priority int
  Entry interface{}
}
type Heap []*Item
func (H Heap) Len() int { return len(H) }
func (H Heap) Less(i, j int) bool { return H[i].Priority < H[j].Priority }
func (H Heap) Swap(i, j int) { H[i], H[j] = H[j], H[i] }
func (H *Heap) Pop() interface{} {
  Old := *H
  n := len(Old)
  item := Old[n - 1]
  *H = Old[0:n - 1]
  return item
}
func (H *Heap) Push(x interface{}) {
  item := x.(*Item)
  *H = append(*H, item)
}
type PriorityQueue struct {
  Comparator func(e interface{}) int
  Items Heap
}
func (PQ *PriorityQueue) Push(e interface{}) {
  item := Item{PQ.Comparator(e), e}
  heap.Push(&PQ.Items, &item)
}
func (PQ *PriorityQueue) Pop() interface{} {
  return heap.Pop(&PQ.Items).(*Item).Entry
}
func InitPQ(F func(interface{}) int) PriorityQueue {
  var H Heap
  return PriorityQueue{F, H}
}

func main() {
  N := NextInt()
  S := NextIntVec()
  sort.Sort(sort.Reverse(sort.IntSlice(S)))
  ans := "Yes"
  B := 1 << uint(N)
  F := func(e interface{}) int { return -e.(int) }
  PQ := InitPQ(F)
  PQ.Push(B)
  for i := 0; i < B; i++ {
    cnt := 1
    for ; i < B - 1; i++ {
      if S[i + 1] < S[i] { break }
      cnt++
    }
    if len(PQ.Items) < cnt {
      ans = "No"
      break
    }
    CC := make([]int, cnt)
    for j := range CC {
      CC[j] = PQ.Pop().(int)
    }
    for _, cc := range CC {
      for 1 < cc {
        cc /= 2
        PQ.Push(cc)
      }
    }
  }
  Write(ans)
  Output()
}

Measured memory_bytes: 19840
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>


using namespace std;


int main() {

	string O, E;

	cin >> O >> E;

	for (int i = 0; i < O.size(); i++) {
		cout << O[i];
		if (E[i] != '\0') {
			cout << E[i];
		}
	}

	return 0;
}


Measured memory_bytes: 256
s=input()+'T'
x,y=list(map(int,input().split()))
x+=8000
y+=8000
n=len(s)
i=0

while i<n and s[i]=='F':
    i+=1

dx=[[0]*16001 for _ in range(2)]
dy=[[0]*16001 for _ in range(2)]

dx[0][i+8000]=1
dy[0][8000]=1

lstx=[]
lsty=[]
d='x'
cnt=0

while i<n:
    if s[i]=='F':
        cnt+=1
    else:
        if cnt>0:
            if d=='x':
                lstx.append(cnt)
            else:
                lsty.append(cnt)
        
        if d=='x':
            d='y'
        else:
            d='x'
        cnt=0
    
    i+=1

for i,cx in enumerate(lstx):
    for j in range(16001):
        if dx[i%2][j]==0:
            continue
        if j+cx<16001:
            dx[(i+1)%2][j+cx]=1
        if j-cx>-1:
            dx[(i+1)%2][j-cx]=1
    dx[i%2]=[0]*16001

for i,cy in enumerate(lsty):
    for j in range(16001):
        if dy[i%2][j]==0:
            continue
        if j+cy<16001:
            dy[(i+1)%2][j+cy]=1
        if j-cy>-1:
            dy[(i+1)%2][j-cy]=1
    dy[i%2]=[0]*16001

if dx[(len(lstx))%2][x]==1 and dy[(len(lsty))%2][y]==1:
    print('Yes')
else:
    print('No')

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

int main() {
  int A,B;
  cin >> A >> B;
  int count=0;
  int n1,n2,n4,n5;
  for(int i=A; i<=B; i++){
    n1 = i/10000;
    n2 = i/1000 - n1 *10;
    n5 = i % 10;
    n4 = (i%100)/10;
    if((n1 == n5)&&(n2==n4)){
      count++;
    }
  }
  cout << count << endl;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

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

inline int gcd(int a, int b) { return (a%b == 0) ? b : gcd(b, a%b); }
inline int fac(int n) { return (n==0) ? 1 : n * fac(n - 1); }

int main() {
    int N;
    cin >> N;
    int a[N];
    bool rate_num[9] = {};
    int n = 0;
    int c = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        for (int j = 0; j < 8; j++) {
            if (400 * j <= a[i] && a[i] < 400 * (j + 1)) {
                if (rate_num[j] == false) {
                    c++;
                    rate_num[j] = true;
                }
            }
        }
        if (400 * 8 <= a[i]) {
            n++;
        }
    }

    int max = n + c;
    int min = (c == 0) ? 1 : c;

    cout << min << " " << max << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

int n;

void go(string s, char mx) {
  if(s.length() == n) {
    print(s);
    return;
  }
  for(char x = 'a'; x <= mx; x++) {
    char n_mx = x == mx ? (char)(mx + 1) : mx;
    go(s + x, n_mx);
  }
}

int main() {
  read(n);
  go("", 'a');
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int dp[2][104];
int a[2][104];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            scanf("%d",&a[i][j]);
        }
    }
    dp[0][0]=a[0][0];
    dp[1][0]=a[0][0]+a[1][0];
    for(int i=0;i<2;i++){
        for(int j=1;j<n;j++){
            if(i==0) dp[i][j]=dp[i][j-1]+a[i][j];
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1])+a[i][j];
        }
    }
   /* for(int i=0;i<2;i++){
        for(int j=0;j<n;j++) printf("%d*",dp[i][j]);
        printf("\n");
    }*/
    printf("%d\n",dp[1][n-1]);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
namespace _0013
{
    class Program
    {
        static void Main(string[] args)
        {

            List<string> aru1 = new List<string> { };
           while (true)
            {
                string s = Console.ReadLine();
                if (s == null) { break; }
                if (s == "0") { Console.WriteLine(aru1[aru1.Count - 1]); aru1.Remove(aru1[aru1.Count - 1]); }
                else { aru1.Add(s); }
            }
            Console.ReadLine();

        }
    }
}

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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

int main() {
	int n = nxt();
	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; ++i) {
		a[i].first = nxt();
		a[i].second = nxt();
	}
	int ans = 0;

	{
		sort(all(a));
		vector<pair<int, int>> inters(n + 1);
		inters[n] = {0, (int)1e9};
		for (int i = n - 1; i >= 0; --i) {
			inters[i] = inters[i + 1];
			inters[i].first = max(inters[i].first, a[i].first);
			inters[i].second = min(inters[i].second, a[i].second);
		}

		pair<int, int> seg = {0, (int)1e9};
		for (int i = 0; i < n - 1; ++i) {
			seg.first = max(seg.first, a[i].first);
			seg.second = min(seg.second, a[i].second);
			int tmp = 0;
			if (seg.first <= seg.second) {
				tmp += seg.second - seg.first + 1;
			}
			if (inters[i + 1].first <= inters[i + 1].second) {
				tmp += inters[i + 1].second - inters[i + 1].first + 1;
			}
			ans = max(ans, tmp);
		}
	}

	{
		sort(all(a));
		vector<pair<int, int>> inters(n + 1);
		inters[n] = {0, (int)1e9};
		for (int i = n - 1; i >= 0; --i) {
			inters[i] = inters[i + 1];
			inters[i].first = max(inters[i].first, a[i].first);
			inters[i].second = min(inters[i].second, a[i].second);
		}

		pair<int, int> seg = {0, (int)1e9};
		for (int i = 0; i < n; ++i) {
			auto q = seg;
			q.first = max(q.first, inters[i + 1].first);
			q.second = min(q.second, inters[i + 1].second);
			seg.first = max(seg.first, a[i].first);
			seg.second = min(seg.second, a[i].second);
			int tmp = 0;
			if (q.first <= q.second) {
				tmp += q.second - q.first + 1;
			}
			if (a[i].first <= a[i].second) {
				tmp += a[i].second - a[i].first + 1;
			}
			ans = max(ans, tmp);
		}
	}

	cout << ans << "\n";

	return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

ll gcd(ll a, ll b)
{
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main()
{
    ll a, b;
    cin >> a >> b;
    ll ans = (a * b) / gcd(a, b);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(lint i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(8)
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }

signed main() {
	int n = in();
	vector<int>a(n);
	REP(i, n) {
		a[i] = in();
	}
	int m = in();
	vector<int>b(m);
	REP(i, m) {
		b[i] = in();
	}
	vector<int>result;
	set_symmetric_difference(a.begin(), a.end(), b.begin(), b.end(), inserter(result, result.end()));
	REPC(i, result) {
		cout << i << endl;
	}
}


Measured memory_bytes: 6452
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N = 1000;

int lcs(string, string);

int main()
{
  string s1, s2;
  int n;
  cin >> n;

  for( int i = 0; i < n; i++)
    {
      cin >> s1 >> s2;
      cout << lcs(s1, s2) << endl;
    }
  return 0;
}

int lcs(string X, string Y)
{
  int c[N + 1][N + 1];
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for( int i = 0; i <= m; i++) c[i][0] = 0;
  for( int j = 1; j <= n; j++) c[0][j] = 0;

  for( int i = 1; i <= m; i++)
    {
      for( int j = 1; j <= n; j++)
        {
          if( X[i] == Y[j] ) c[i][j] = c[i - 1][j - 1] + 1;
          else c[i][j] = max(c[i - 1][j], c[i][j - 1]);
          maxl = max(maxl, c[i][j]);
        }
    }

  return maxl;
}



Measured memory_bytes: 7096
#include<stdio.h>

int main(void)
{
	int n;
	int p[20];
	int count = 0;
	
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
    {
        scanf("%d", &p[i]);
    }
    for(int j = 0; j < n - 2; j++)
    {
    	if(p[j] > p[j + 1] && p[j + 1] > p[j + 2]) count++;
        if(p[j] < p[j + 1] && p[j + 1] < p[j + 2]) count++;
    }
	
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
int main(){
    ll n,m;
    cin>>n>>m;
    ll u,v,s,t;
    vector< vector<ll> > g(n, vector<ll>());
    rep(i,m){
        cin>>u>>v;
        u--;v--;
        g[u].push_back(v);
    }
    vector< vector<ll> >  position(n,vector<ll>(3,-1));
    cin>>s>>t;
    s--;t--;
    queue<P> que;
    que.push({s,0});
    while(!que.empty()){
        P p = que.front();que.pop();
        ll pos = p.fi;
        ll state = (p.se+1)%3;
        for(auto nv:g[pos]){
            if(position[nv][state]==-1){
                position[nv][state] = p.se + 1;
                que.push({nv,p.se + 1});
            }
        }
    }
    if(position[t][0]!=-1) cout<<position[t][0]/3<<endl;
    else cout<<-1<<endl;

    return 0;
}

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

#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
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};
const int INF = 1e9;
const int MOD = 1e9+7;

signed main(){
    int x,y,a,b,c; cin >> x >>y>>a>>b>>c;
    vector<int>p(a),q(b),r(c);
    rep(i,a) cin >> p[i];
    rep(i,b) cin >> q[i];
    rep(i,c) cin >> r[i];

    vector<int> rg;
    sort(all(p)); sort(all(q)); sort(all(r));
    reverse(all(p)); reverse(all(q)); reverse(all(r));
    rep(i,x) rg.PB(p[i]);
    rep(i,y) rg.PB(q[i]);
    rep(i,c) rg.PB(r[i]);
    sort(all(rg));
    reverse(all(rg));
    int res=0;
    rep(i,x+y){
        res+=rg[i];
    }
    cout<<res<<endl;
}

Measured memory_bytes: 8560
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<numeric>
#include<set>
#include<math.h>
using namespace std;

int N, K;
// オリジナル値格納ベクトル, 左右両方からの累積和ベクトルと負の値を格納するベクトル
vector<int> fromL, fromR;
vector<pair<int, int> >hoodoo;

// 与えられた組み合わせに対して利得を計算する
int gain(int l, int r, int b){
    // 不可能なパターン : 与えられた列以上の個数取得する、可能以上の個数返却する
    if(l + r > N) return 0;
    vector<int> cumul;
    int cnt = 0;
    cumul.push_back(0);
    for(int i = 0; i < hoodoo.size(); i++){
        if(hoodoo[i].second < l || hoodoo[i].second >= N - r){
            cumul.push_back(cumul[cnt] + hoodoo[i].first);
            cnt++;
        }
    }
    if(b > cnt) return 0;
    // 以上、不可能パターンの潰し終了

    int ret = 0; // 返り値

    // 左から一回でも取っていたら左側からの利得を加算
    if(l > 0) ret += fromL[l-1];
    // 同様に、右から一回でも取っていたら右側からの利得を加算
    if(r > 0) ret += fromR[r-1];
    // 負の宝石を返すことによるリターンの加算
    ret -= cumul[b];    

    return ret;   
}

int main(){
    cin >> N >> K;
    int v, tmp = 0;

    // fromL および fromR は累積和として構成する
    for(int i = 0; i < N; i++){
        cin >> v;
        tmp += v;
        if(v < 0) hoodoo.push_back(make_pair(v, i));
        fromL.push_back(tmp);
    }

    tmp = 0;

    for(int i = N - 1; i >= 0; i--){
        if(i == 0) v = fromL[i];
        else v = fromL[i] - fromL[i-1];
        tmp += v;
        fromR.push_back(tmp);
    }

    stable_sort(hoodoo.begin(), hoodoo.end());
    // fromL, fromR, hoodoo の完成
    
    vector<int> gains;
    gains.push_back(0); // バッファ用

    for(int a1 = 0; a1 <= K; a1++){
        for(int a2 = a1; a2 <= K; a2++){
            for(int a3 = a2; a3 <= K; a3++){
                tmp = gain(a1, a2 - a1, a3 - a2);
                if(tmp > 0) gains.push_back(tmp);
            }
        }
    }

    stable_sort(gains.begin(), gains.end(), greater<int>());

    cout << gains[0] << "\n";

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;



int main()
{
	ll n; cin >> n;
	vector<ll> a(n);
	rep(i,n)cin>>a[i];

	rep(i,n)if(i<a[i])
	{
		cout<<0<<endl;
		return 0;
	}

	ll ans=1;
	vector<ll> pea(n);

	rep(i,n)
	{
		
		if(a[i])
		{
			ans*=pea[a[i]-1]-pea[a[i]];
			pea[a[i]]++;
		}
		else 
		{
			ans*=(1LL)*3-pea[a[i]];
			pea[a[i]]++;
		}
		ans%=1000000007;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1792
import numpy as np

N=int(input())
all_lst=[]
for i in range(3):
    buf = input()
    for e in buf.split():
        all_lst.append((int(e), 3 - i))
        
all_lst = sorted(all_lst, key = lambda x: (x[0], x[1]))
ac, bc, cc = 0, 0, 0
for tpl in all_lst:
    if tpl[1]==3:
        ac += 1
    elif tpl[1]==2:
        bc += ac
    elif tpl[1] == 1:
        cc += bc
print(cc)

Measured memory_bytes: 72444
from collections import deque
H,W=map(int,input().split(' '))
S=[list(input()) for i in range(H)]
S[0][0]=1
next  = deque([[0,0]])
ans = H*W
while next:
    x,y =next.popleft()
    s = S[x][y]
    for i,j in [[1,0],[0,1],[-1,0],[0,-1]]:
        if 0<=x+i<H and 0<=y+j<W and S[x+i][y+j]=='.':
            S[x+i][y+j]=s+1
            next.append([x+i,y+j])
for i in S:
    ans -=i.count('#')
if type(S[H-1][W-1])==str:
    print(-1)
else:
    print(ans-S[H-1][W-1])

Measured memory_bytes: 3316
gets.to_i.times{
  gets
  a=gets.split.map &:to_i
  s=gets.chop.chars
  b=[]
  p a.zip(s).reverse.all?{|a,f|
    b.map{a=[a,a^_1].min}
    a<1||f[?0]&&b<<a
  }?0:1
}

Measured memory_bytes: 14632
a, b, k = map(int, input().split())

if b-a <= k:
  for i in range(a, b+1):
    print(i)
else:
  ans = []
  for i in range(a, a+k):
    if i not in ans:
      ans.append(i)
      print(i)
  for j in range(b-k+1, b+1):
    if j not in ans:
      print(j)


Measured memory_bytes: 9180
import sys
#sys.exit()
#sorted( ,reverse=True)
#N = int(input())
X, Y = map(int, input().split())
#A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]

#cnt = 0
#cnt += 1

for i in range(0,X+1):
    if i * 2 + (X-i) * 4 == Y:
        print("Yes")
        sys.exit()



#print(N)
#print(S,T)
#print(A)
#print('Yes')
print('No')
#print(cnt)

Measured memory_bytes: 9168
s = str(input())
t = str(input())

if s.islower() and s.isalpha() and t.islower() and t.isalpha() and 1<=len(s)<=10:
    a = t[:-1]
    #print(a)
    if s==a:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 9116
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		int ss = Integer.parseInt(sa[2]);
		List<List<Hen>> list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			int u = Integer.parseInt(sa[0]) - 1;
			int v = Integer.parseInt(sa[1]) - 1;
			int a = Integer.parseInt(sa[2]);
			int b = Integer.parseInt(sa[3]);

			list.get(u).add(new Hen(v, a, b));
			list.get(v).add(new Hen(u, a, b));
		}
		int[] c = new int[n];
		int[] d = new int[n];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			c[i] = Integer.parseInt(sa[0]);
			d[i] = Integer.parseInt(sa[1]);
		}
		br.close();

		int total = 2500;
		long[][] ans = new long[n][total + 1];
		for (int i = 0; i < n; i++) {
			Arrays.fill(ans[i], Long.MAX_VALUE);
		}
		int e = Math.min(ss, total);
		for (int i = 0; i <= e; i++) {
			ans[0][i] = 0;
		}

		PriorityQueue<Node> que = new PriorityQueue<Node>();
		Node first = new Node(0, 0, e);
		que.add(first);
		while (!que.isEmpty()) {
			Node cur = que.poll();
			for (Hen hen : list.get(cur.v)) {
				if (cur.s >= hen.a) {
					long alt = ans[cur.v][cur.s] + hen.b;
					int rem = cur.s - hen.a;
					if (alt < ans[hen.v][rem]) {
						ans[hen.v][rem] = alt;
						que.add(new Node(hen.v, alt, rem));
					}
				}
			}
			int gin = cur.s;
			long alt = ans[cur.v][cur.s];
			if (gin < total) {
				gin = Math.min(gin + c[cur.v], total);
				alt += d[cur.v];
				if (alt < ans[cur.v][gin]) {
					ans[cur.v][gin] = alt;
					que.add(new Node(cur.v, alt, gin));
				}
			}
		}

		for (int i = 1; i < n; i++) {
			long min = Long.MAX_VALUE;
			for (int j = 0; j < 2500; j++) {
				min = Math.min(min, ans[i][j]);
			}
			System.out.println(min);
		}
	}

	static class Hen {
		int v, a, b;

		public Hen(int v, int a, int b) {
			this.v = v;
			this.a = a;
			this.b = b;
		}
	}

	static class Node implements Comparable<Node> {
		int v;
		long d;
		int s;

		public Node(int v, long d, int s) {
			this.v = v;
			this.d = d;
			this.s = s;
		}

		public int compareTo(Node o) {
			if (d != o.d) {
				return Long.compare(d, o.d);
			}
			return Long.compare(o.s, s);
		}
	}
}


Measured memory_bytes: 52508
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n,m;
	vector<int> times;
	
	cin >> n;
	for(int i=0;i<n;i++){
		int x, y;
		cin >> x >> y;
		times.push_back(x*60+y);
	}
	cin >> m;
	n += m;
	for(int i=0;i<m;i++){
		int x, y;
		cin >> x >> y;
		times.push_back(x*60+y);
	}
	
	sort(times.begin(), times.end());
	
	for(int i=0;i<times.size();i++){
		if(i!=0 && times[i] == times[i-1]) continue;
		if(i!=0) cout << " ";
		printf("%d:%02d", times[i]/60, times[i]%60);
	}
	cout << endl;
}

Measured memory_bytes: 1252
//   ┏━━┓┏━━┓┏┓┏┓┏┳━┳┓┏━━┓┏━┳┓┏━━┓     ┏┳┓┏┳┓┏━┳━┓┏━━┓┏━┓
//   ┃┏┓┃┃━━┫┃┗┛┃┃┃┃┃┃┃┏┓┃┃┃┃┃┗┃┃┛     ┃┏┛┃┃┃┃┃┃┃┃┃┏┓┃┃╋┃
//   ┃┣┫┃┣━━┃┃┏┓┃┃┃┃┃┃┃┣┫┃┃┃┃┃┏┃┃┓     ┃┗┓┃┃┃┃┃┃┃┃┃┣┫┃┃┓┫
//   ┗┛┗┛┗━━┛┗┛┗┛┗━┻━┛┗┛┗┛┗┻━┛┗━━┛     ┗┻┛┗━┛┗┻━┻┛┗┛┗┛┗┻┛
#include<bits/stdc++.h>
using namespace std;
#define FOR(a, c) for (int a = 0; a<c ; a++)
#define FORL(a, b, c) for (int a = b; a<c ; a++)
typedef long long int ll;

int main()
{
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int k;
  cin>>k;
  while(k--){
    cout<< "ACL";
  }
  return 0;
}
// By Ashwani Kumar, Indian Institute Of Technology(IIT), Guwahati.
//   ╔══╗╔══╗╔══╗     ╔══╗╔╦╗╔╦═╦╗╔══╗╔╗╔╗╔══╗╔══╗╔══╗
//   ╚║║╝╚║║╝╚╗╔╝     ║╔═╣║║║║║║║║║╔╗║║╚╝║║╔╗║╚╗╔╝╚║║╝
//   ╔║║╗╔║║╗─║║─     ║╚╗║║║║║║║║║║╠╣║║╔╗║║╠╣║─║║─╔║║╗
//   ╚══╝╚══╝─╚╝─     ╚══╝╚═╝╚═╩═╝╚╝╚╝╚╝╚╝╚╝╚╝─╚╝─╚══╝


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String O = sc.next();
		String E = sc.next();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < O.length(); i++) {
			sb.append(O.charAt(i));
			if (i < E.length()) {
				sb.append(E.charAt(i));
			}
		}
		System.out.println(sb.toString());
		sc.close();
	}
}

Measured memory_bytes: 21972
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  int r;
  cin >> r;
  cout << pow(r, 2) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;
int main(){
    int N,R=0,B=0;
    string s;
    cin>>N;
    cin>>s;
    for(int i=0;i<N;i++){
        if(s.at(i)=='R')R++;
        else B++;
    }
    if(R>B)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

}

Measured memory_bytes: 256
stick = [i for i in range(1, int(input()) + 1)]

net = int(input())

for _ in range(net):
    a, b = list(map(int, input().split(",")))
    stick[a - 1], stick[b - 1] = stick[b - 1], stick[a - 1]
for v in stick:
    print(v)

Measured memory_bytes: 7688
#include <bits/stdc++.h>
using namespace std;
#define int long long
int Knapsack(int w, int n, int weight[], int value[]){
    int i, j;
    int Knap[n+1][w+1];
    for(i=0;i<=n; ++i){
        for(j=0; j<=w; ++j){
            if(i==0 || j==0){
                Knap[i][j] = 0;
            }
            else if(weight[i-1]<=j){
                Knap[i][j] = max(Knap[i-1][j], value[i-1] + Knap[i-1][j-weight[i-1]]);
            }
            else{
                Knap[i][j]  = Knap[i-1][j];
            }
            //cout<<Knap[i][j]<<' ';
        }
        //cout<<'\n';
    }
    return Knap[n][w];
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, w, i, j;
    cin>>n>>w;
    int weight[n], value[n];
    for(i=0; i<n; ++i){
        cin>>weight[i]>>value[i];
    }
    int ans = Knapsack(w, n, weight, value);
    cout<<ans;
}

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

int main(void){
    int r,g,b,n;
    int ans = 0;
    cin >> r >> g >> b >> n;
    for(int i = 0;r*i <= n;i++){
        for(int j = 0;g*j <= n;j++){
            int sum = r*i+g*j;
            if((n-sum)% b == 0 && n >= sum)ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
vector<int> node[18];
vector<int> dis[18];
int vis[20];
int cnt=0;

int pre[18][18];
void dfs(int x)
{
    cnt++;
    vis[x]=1;
    //tmp.push_back(x);
    for(int i=0; i<node[x].size(); i++)
    {
        int y=node[x][i];
        if(vis[y]==0)
        {
            //cnt++;
            //vis[y]=1;
            //vis[y]=1;
            dfs(y);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        int t;
        cin>>t;
        while(t--)
        {
            int x,y;
            cin>>x>>y;
            if(y==1)
                node[i].push_back(x);
            else
                dis[i].push_back(x);
            pre[i][x]=y;
        }
    }
    ll nw=(1LL<<(n))-1;
    int ans=0;
    for(ll i=1; i<=nw; i++)
    {
        vector<int> tmp;
        for(int j=0; j<n; j++)
        {
            ll req=(i&(1LL<<j));
            if(req!=0)
            {
                tmp.push_back(j+1);
            }
        }
        memset(vis,0,sizeof vis);
        int sz=tmp.size();
        cnt=0;
        for(int j=0; j<sz; j++)
        {
            if(vis[tmp[j]]==0) dfs(tmp[j]);
        }
        bool chk=0;

        for(int j=1; j<=n; j++)
        {
            if(vis[j]==1)
            {
                for(int k=0; k<dis[j].size(); k++)
                {
                    int nw=dis[j][k];
                    if(vis[nw]==1)
                    {
                        chk=1;
                        break;
                    }
                }
            }
            if(chk==1)
            {
                break;
            }
        }
        if(chk==0)
            ans=max(ans,cnt);

    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
const double EPS=1e-8;
double xs[31],ys[31],zs[31];
int main(){
  int n;
  while(cin>>n&&n){
    double cx=0,cy=0,cz=0;
    for(int i=0;i<n;i++){
      cin>>xs[i]>>ys[i]>>zs[i];
      cx+=xs[i],cy+=ys[i],cz+=zs[i];
    }
    cx/=n,cy/=n,cz/=n;
    const int ITE_MAX=50;
    double co=0.5;
    for(int o=0;o<50;o++){
      for(int iter=0;iter<ITE_MAX;iter++){
	int idx=-1;
	double max_dist=-1;
	double d;
	for(int j=0;j<n;j++){
	  d=sqrt(pow(xs[j]-cx,2)+pow(ys[j]-cy,2)+pow(zs[j]-cz,2));
	  if(max_dist<d)max_dist=d,idx=j;
	}
	double dx=xs[idx]-cx,dy=ys[idx]-cy,dz=zs[idx]-cz;
	cx+=dx*co;
	cy+=dy*co;
	cz+=dz*co;
      }
      co/=2;
    }
    double d=0;
    double max_dist=-1;
    for(int j=0;j<n;j++){
      d=sqrt(pow(xs[j]-cx,2)+pow(ys[j]-cy,2)+pow(zs[j]-cz,2));
      max_dist=max(max_dist,d);
    }
    printf("%.5f\n",max_dist);
  }
  
  return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

const int MOD = 1000000007;
const int INF = 1 << 30;

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

    int c = 0;
    while (n) {
        n /= k;
        c++;
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
N,Q=map(int,input().split())
C=[[] for _ in range(N+1)]
V=set([])
R=[0]*(N+1)
def main():
  for i in range(N-1):
    a,b=map(int,input().split())
    C[a].append(b)
    C[b].append(a)
  for i in range(Q):
    a,b=map(int,input().split())
    R[a]+=b

  from collections import deque
  q = deque([])
  q.append(1)
  while len(q) > 0:
    p = q.popleft()
    for i in C[p]:
      if not i in V:
        R[i]+=R[p]
        q.append(i)
    V.add(p)
  print(*R[1:])
main()

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

int main(){
  ll n, c, k;
  cin >> n >> c >> k;
  
  vector<ll> v(n);
  for ( ll i = 0; i < n; i++ ) cin >> v[i];
  
  sort(v.begin(), v.end());
  
  ll bus_count = 0;
  ll visitor_count = 0;
  ll time = v[0];
  
  for ( auto x: v ){
    if ( visitor_count == c || x - time > k ){
      bus_count++;
      visitor_count = 1;
      time = x;
      continue;
    }
    visitor_count++;
  }
    
  if (visitor_count) bus_count++;
  
  cout << bus_count << endl;
  
}

Measured memory_bytes: 1024
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N, K = sc.nextInt()
    val max = (N - 1) * (N - 2) / 2
    if (max < K) {
      println(-1)
      sys.exit
    } else {
      val diff = max - K
      val combinations = (2 to N).combinations(2).take(diff)
      println(diff + N - 1)
      for (i <- 2 to N) {
        println(s"1 $i")
      }
      for (pair <- combinations) {
        println(s"${pair(0)} ${pair(1)}")
      }
    }
  }
}

Measured memory_bytes: 41608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    set<int> s;
    rep(i,4){
        int n;
        cin >> n;
        s.insert(n);
    }
    if(s.count(1) && s.count(9) && s.count(7) && s.count(4)) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    
    
    

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int l = scan.nextInt();
		int[][] A = new int[n][m];
		int[][] B = new int[m][l];
		long c = 0;
		
		for(int i = 0;i < n;i++)
		{
			for(int j = 0;j < m;j++)
			{
				A[i][j] = scan.nextInt();
			}
		}
		
		for(int i = 0;i < m;i++)
		{
			for(int j = 0;j < l;j++)
			{
				B[i][j] = scan.nextInt();
			}
		}
		
		for(int i = 0;i < n;i++)
		{
			for(int j = 0;j < l;j++)
			{
				c = 0;
				for(int k = 0;k < m;k++)
				{
					c += (A[i][k] * B[k][j]);
				}
				if(j != 0){System.out.print(" ");}
				System.out.print(c);
			}
			System.out.println("");
		}
	}
}

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

#define INF_LL (int64_t)1e18
#define INF (int32_t)1e9

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int H, W;
int dy[4] = {-1, 1, 0, 0};
int dx[4] = {0, 0, -1, 1};

int main() {
  cin >> H >> W;
  int white = 0;

  vector<string> s(H);
  for (auto&& e : s) {
    cin >> e;
    for (auto &&c : e) {
      if (c == '.') white++;
    }
  }

  auto dis = make_v<int>(H, W);
  fill_v<int>(dis, INF);
  dis[0][0] = 0;

  using T = tuple<int, int, int>;
  queue<T> que;
  que.emplace(0, 0, 0);

  auto valid = [&](int y, int x) {
    return 0 <= y && y < H && 0 <= x && x < W && s[y][x] != '#';
  };

  while (que.size()) {
    int d, y, x;
    tie(d, y, x) = que.front(); que.pop();

    for (int k = 0; k < 4; k++) {
      int ny = y + dy[k], nx = x + dx[k];
      if (!valid(ny, nx)) continue;
      if (dis[ny][nx] <= d + 1) continue;

      dis[ny][nx] = d + 1;
      que.emplace(d+1, ny, nx);
    }
  }

  if (dis[H-1][W-1] == INF) {
    cout << -1 << endl;
  } else {
    cout << white - dis[H-1][W-1] - 1 << endl;
  }
}


Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    let mut ans: usize = 0;
    for i in 1..=n {
        ans += i * g(n / i);
    }
    return ans.to_string();
}

fn g(n: usize) -> usize {
    return n * (n + 1) / 2;
}


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

int main(){
  int A, B, C, D, W;
  cin >> A >> B >> C >> D;

  W = A + B - C - D;
  if (W > 0) cout << "Left" << endl;
  else if (W == 0) cout << "Balanced" << endl;
  else cout << "Right" << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

unordered_map<ll, int> get_factors(ll N) {
    ll n2 = N;
    unordered_map<ll, int> ans;
    for(ll i = 2; i*i <= N; i++) {
        while (n2 % i == 0) {
            n2 /= i;
            ans[i] += 1;
        }
    }
    if (n2 > 1)
        ans[n2] += 1;
    return ans;
}

int main() {
    ll n, p;
    cin >> n >> p;
    ll ans = 1;
    for(auto pp: get_factors(p)) {
        for(int i = 0; i < pp.second/n; i++)
            ans *= pp.first;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
package main
import (
  "container/list"
  "fmt"
  "os"
)
func main() {
  var h,w,sx,sy,gx,gy,infty,b int
  var s string
  var maze [][]int
  queue := list.New()
  fmt.Scan(&h,&w)
  sx,sy = 1,1
  gx,gy = h,w
  maze = make([][]int,h+2)
  infty = h*w+1
  maze[0] = make([]int,w+2)
  maze[h+1] = make([]int,w+2)
  for j:=0;j<w+2;j++ {
    maze[0][j] = -1
    maze[h+1][j] = -1
  }
  b = 0
  for i:=1;i<h+1;i++ {
    fmt.Scan(&s)
    maze[i] = make([]int,w+2)
    maze[i][0] = -1
    maze[i][w+1] = -1
    for j:=1;j<w+1;j++ {
      if s[j-1:j] == "#" {
        maze[i][j] = -1
        b++
      } else {
        maze[i][j] = infty
      }
    }
  }
  maze[sx][sy] = 1
  queue.PushBack([]int{sx,sy})
  for ;; {
    if queue.Len() == 0 {
      fmt.Println(-1)
      os.Exit(0)
    }
    r,_ := queue.Remove(queue.Front()).([]int)
    if r[0] == gx && r[1] == gy { break }
    if maze[r[0]+1][r[1]] == infty {
      maze[r[0]+1][r[1]] = maze[r[0]][r[1]]+1
      queue.PushBack([]int{r[0]+1,r[1]})
    }
    if maze[r[0]-1][r[1]] == infty {
      maze[r[0]-1][r[1]] = maze[r[0]][r[1]]+1
      queue.PushBack([]int{r[0]-1,r[1]})
    }
    if maze[r[0]][r[1]+1] == infty {
      maze[r[0]][r[1]+1] = maze[r[0]][r[1]]+1
      queue.PushBack([]int{r[0],r[1]+1})
    }
    if maze[r[0]][r[1]-1] == infty {
      maze[r[0]][r[1]-1] = maze[r[0]][r[1]]+1
      queue.PushBack([]int{r[0],r[1]-1})
    }
  }
  fmt.Println(h*w-maze[gx][gy]-b)
}

Measured memory_bytes: 768
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;


ll f(ll x);


int main() {
    ll A, B;
    cin >> A >> B;
    
    ll ans = f(A - 1) ^ f(B);
    cout << ans << '\n';

}

ll f(ll x) {
    ll res;
    if (x % 2 == 0) {
        if ((x / 2)  % 2 == 1) {
            res = 1;
        }
        else {
            res = 0;
        }
        res ^= x;
    }
    else {
        if (((x+1) / 2)  % 2 == 1) {
            res = 1;
        }
        else {
            res = 0;
        }
    }

    return res;
}
    


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

B = list(map(int, input().split()))

ans = 0
for _ in range(N):
    A = list(map(int, input().split()))
    x = C
    for i in range(M):
        x += B[i] * A[i]
    if x > 0:
        ans += 1

print(ans)

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

using LL = long long;
using LD = long double;
 
LL mod = 1e9+7;


int main()
{
	LL n, m, x;
	cin >> n >> m >> x;

	vector<LL> c(n);
	vector<vector<LL>> cbit(n, vector<LL> (m));

	for (LL i = 0; i < n; ++i) {
		cin >> c[i];
		for (LL j = 0; j < m; ++j) {
			cin >> cbit[i][j];
		}
	}
	bool found = false;
	LL mincost = LLONG_MAX;

	for (LL i = 0; i < (1<<n); ++i) {
		// setbits indicate chosen book
		vector<LL> skill(m, 0);
		LL cost = 0;

		for (LL j = 0; j < n; ++j) {
			if (i & (1<<j)) {
				cost += c[j];
				for (LL k = 0; k < m; ++k) {
					skill[k] += cbit[j][k];
				}
			}
		}

		bool isthis = true;
		for (LL j = 0; j < m; ++j) {
			if (skill[j] < x) {
				isthis = false;
				break;
			}
		}
		
		if (isthis) {
			found = true;
			mincost = min(mincost, cost);
		}
	}

	if (found) {
		cout << mincost << "\n";
	}
	else {
		cout << "-1\n";
	}

}

Measured memory_bytes: 3608
input = gets.chomp
N,M = input.split(" ").map{|e| e.to_i}

array = []
M.times do
  array << 0
end

N.times do
  input = gets.chomp
  sukinamono = input.split(" ").map{|e| e.to_i}
  sukinamono.shift
  sukinamono.each do|item|
    array[item-1] += 1
  end
end
sum =0
array.sort.reverse.each do |item|
  sum += 1 if item == N
  break if item < N
end

puts sum

Measured memory_bytes: 1788
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll b, ll m) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll h = modpow(a, b / 2, m);
        return h * h % m;
    } else {
        return a * modpow(a, b - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int k = S.size(), cnt = 0;
    REP(i, k) {
        if (S[i] == 'o') {
            cnt++;
        }
    }
    if (k - cnt <= 7) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void myout(Object text){//standard output
		System.out.println(text);
	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		//Long tmp = sc.nextLong();
      PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
      int N = sc.nextInt();
      int M = sc.nextInt();
      Long output = new Long(0);
      for(int i = 0; i < N; i++){
        pq.add(sc.nextInt());
      }
      
      int[][] bc = new int[M][2];
      for(int i = 0; i < M; i++){
        bc[i][0] = sc.nextInt();
        bc[i][1] = sc.nextInt();
      }
      Arrays.sort(bc,Comparator.comparingInt(o -> o[1]));
      
      for(int i = M - 1; i >= 0; i--){
          for(int j = 0; j < bc[i][0]; j++){
            if(pq.peek() < bc[i][1]){
              pq.poll();
              pq.add(bc[i][1]);
            }else{
              break;
            }
          }
      }
      
      Iterator it = pq.iterator();
      //myout(it);
      while(it.hasNext()){
        int tmp = (Integer)it.next();
        //myout(tmp);
        output = output + tmp;
      }
      myout(output);
	}
}



Measured memory_bytes: 101492
#include "bits/stdc++.h"
using namespace std;

bool isList[105];

int main() {
  int X,N;
  cin >> X >> N;
  
  if (N == 0) {
    cout << X << endl;
    return 0;
  }
  
  int p;
  for(int i=0; i<N; i++) {
    cin >> p;
    isList[p] = true;
  }
  
  int max_val = 999999;
  int ans = 0;
  for(int i=0; i<=101; i++) {
    if (!isList[i]) {
      if (max_val > abs(X - i)) {
        max_val = abs(X - i);
        ans = i;
      }
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3636