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

using Graph = vector<vector<int>>;

void bfs(const Graph& G, vector<int>& dist, queue<int>& todo) {
    while(!todo.empty()) {
        int v = todo.front();
        todo.pop();

        for(auto next_v : G[v]) {
            if(dist[next_v]!=-1) continue;

            dist[next_v] = dist[v] +1;
            todo.push(next_v);
        }
    }
}

int main() {
    int h,w;
    cin>>h>>w;
    vector<vector<char>> maze(h+2);
    int count = 0;

    //周りを壁で囲んでmaze作ってみた。あれ、悪くないのでは?
    for(int i=0; i<w+2; i++) maze[0].push_back('#');
    for(int i=1; i<=h; i++) {
        maze[i].push_back('#');
        for(int j=0; j<w; j++) {
            char s;
            cin>>s;
            if(s=='.') count++;
            maze[i].push_back(s);
        }
        maze[i].push_back('#');
    }
    for(int i=0; i<w+2; i++) maze[h+1].push_back('#');

    //グラフ入力作業
    Graph G(h*w+1);
    for(int i=1; i<=h; i++) {
        for(int j=1; j<=w; j++) {
            int posi = w*(i-1) + j;
            if(maze[i][j]=='.') {
                if(maze[i][j-1] == '.') G[posi].push_back(posi-1);
                if(maze[i-1][j] == '.') G[posi].push_back(posi-w);
                if(maze[i][j+1] == '.') G[posi].push_back(posi+1);
                if(maze[i+1][j] == '.') G[posi].push_back(posi+w);
            }
        }
    }


    vector<int> propo;
    for(int i=1; i<=h; i++) {
        for(int j=1; j<=w; j++) {
            if(maze[i][j]=='.') {
                vector<int> dist(h*w+1, -1);
                queue<int> todo;
                dist[w*(i-1)+j] = 0;
                todo.push(w*(i-1)+j);

                bfs(G, dist, todo);
                propo.push_back(*max_element(dist.begin(), dist.end()));
            }
        }
    }

    int ans = *max_element(propo.begin(), propo.end());
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;

	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		
		var k = p[0];
		p[0] = p[1];
		p[1] =k;
		k = p[0];
		p[0]=p[2];
		p[2] = k;
		Console.WriteLine("{0} {1} {2}", p[0], p[1], p[2]);
	}
	

	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
const int nmax=100005;
typedef long long ll;
struct edge{ll to;ll cost;};
vector<edge> tree[nmax],tree2[nmax];
ll d[nmax],d2[nmax];
ll n;

void dijkstra(ll s){
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
  fill(d,d+n,1e18);
  d[s]=0;
  pq.push(make_pair(0,s));
  while(!pq.empty()){
    pair<ll,ll> p=pq.top();
    pq.pop();
    ll v=p.second;
    if(d[v]<p.first){
      continue;
    }
    for(auto x:tree[v]){
      edge e=x;
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        pq.push(make_pair(d[e.to],e.to));
      }
    }
  }
}
void dijkstra2(ll s){
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
  fill(d2,d2+n,1e18);
  d2[s]=0;
  pq.push(make_pair(0,s));
  while(!pq.empty()){
    pair<ll,ll> p=pq.top();
    pq.pop();
    ll v=p.second;
    if(d2[v]<p.first){
      continue;
    }
    for(auto x:tree2[v]){
      edge e=x;
      if(d2[e.to]>d2[v]+e.cost){
        d2[e.to]=d2[v]+e.cost;
        pq.push(make_pair(d2[e.to],e.to));
      }
    }
  }
}
int main(){
  ll m,s,t;
  cin >> n >> m >> s >> t;
  s--,t--;
  for(int i=0;i<m;i++){
    ll u,v,a,b;
    cin >> u >> v >> a >> b;
    u--,v--;
    tree[u].push_back(edge{v,a});
    tree[v].push_back(edge{u,a});
    tree2[u].push_back(edge{v,b});
    tree2[v].push_back(edge{u,b});
  }
  vector<ll> ans(n);
  dijkstra(s);
  dijkstra2(t);
  ans[n-1]=d[n-1]+d2[n-1];
  for(int i=n-2;i>=0;i--){
    ans[i]=min(ans[i+1],d[i]+d2[i]);
  }
  for(int i=0;i<n;i++){
    cout << 1000000000000000-ans[i] << endl;
  }
}

Measured memory_bytes: 19140
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

const n = 3
var sc = bufio.NewScanner(os.Stdin)

func main()  {
	max := math.MinInt64
	maxIndex := 0
	v := make([]int,n)
	for i := 0; i < n; i++ {
		fmt.Scan(&v[i])
	}


	for i := 0; i < n; i++ {
		if max < v[i]{
			max = v[i]
			maxIndex = i
		}
	}

	result := 0
	for i := 0; i < n; i++ {
		if i == maxIndex {
			result += 10 * v[i]
			continue
		}
		result += v[i]
	}
	fmt.Println(result)

}



Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>

typedef struct list{
    int H;
    int W;
    struct list *next;
}List;

List *head = NULL;


void insert(int a, int b){
    List *node = (List *) malloc(sizeof(List));
    node->H = a;
    node->W = b;
    node->next = NULL;

    if (head == NULL){
        head = node;
    }

    else
    {
        List *p = head;

        while (p->next != NULL)
        {
            p = p->next;
        }
        p->next = node;
    }
}

void print(){
    List *p = head;

    while (p != NULL)
    {
        // printf("%d %d\n",p->H , p->W);

        for (int i = 0; i < p->H; i++)
        {
            for (int j = 0; j < p->W; j++)
            {
                printf("#");
            }
            printf("\n");

        }
        printf("\n");

        p = p->next;
    }

}



int main(){
    while(1){
        int H, W;
        scanf("%d" "%d" , &H, &W);
        if (H == 0 && W == 0){
            break;
        }
        insert(H, W);
    }

    print();



    return 0;
}



Measured memory_bytes: 2048
package main

import (
  "bufio"
  "fmt"
  "os"
  "sort"
  "strconv"
  "strings"
)

func main() {
  input := Input{bufio.NewReaderSize(os.Stdin,100)}
  n := input.NextInt()
  es := make(Edges,n-1)
  for i:=0;i<n-1;i++ {
    a,b,c := input.NextInts()
    es[i] = Edge{a-1,b-1,int64(c)}
  }
  sort.Sort(sort.Reverse(es))
  uf := NewUnionFind(n)
  t := make(Graph,2*n-1)
  par := NewUnionFind(2*n-1)
  for i:=0;i<n-1;i++ {
    fm,to,c := es[i].fm,es[i].to,es[i].c
    fmp,top := par.Find(fm),par.Find(to)
    fms,tos := uf.Size(fm),uf.Size(to)
    t.Add(n+i,fmp,int64(tos)*c)
    t.Add(n+i,top,int64(fms)*c)
    uf.Unite(fm,to)
    par.Unite(n+i,fm)
    par.Unite(n+i,to)
  }
  ans := make([]int64,n)
  var dfs func(int,int64)
  dfs = func(v int,c int64) {
    if v < n { ans[v] = c;return }
    for _,e := range t[v] { dfs(e.to,e.c+c) }
  }
  dfs(2*n-2,0)
  for i:=0;i<n;i++ { fmt.Println(ans[i]) }
}

type Edge struct { fm,to int;c int64 }
type Edges []Edge
type Graph [][]Edge
func(e Edges) Len() int { return len(e) }
func(e Edges) Swap(i,j int) { e[i],e[j] = e[j],e[i] }
func(e Edges) Less(i,j int) bool { return e[i].c < e[j].c }
func(g Graph) AddEdge(fm int,e Edge) { g[fm] = append(g[fm],e) }
func(g Graph) Add(fm,to int,c int64) { g.AddEdge(fm,Edge{fm,to,c}) }

type UnionFind struct { par,size []int }
func NewUnionFind(n int) UnionFind {
  par := make([]int,n)
  size := make([]int,n)
  for i:=0;i<n;i++ { par[i],size[i] = i,1 }
  return UnionFind{par,size}
}
func(u UnionFind) Find(i int) int {
  if u.par[i] == i { return i }
  u.par[i] = u.Find(u.par[i])
  return u.par[i]
}
func(u UnionFind) Same(i,j int) bool { return u.Find(i) == u.Find(j) }
func(u UnionFind) Unite(i,j int) {
  i,j = u.Find(i),u.Find(j)
  if i == j { return }
  u.par[j] = i
  u.size[i] += u.size[j]
}
func(u UnionFind) Size(i int) int { return u.size[u.Find(i)] }

type Input struct { reader *bufio.Reader }
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInt() int {
  n,_ := strconv.Atoi(i.NextLine())
  return n
}
func(i *Input) NextInts() (int,int,int) {
  s := strings.Fields(i.NextLine())
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  z,_ := strconv.Atoi(s[2])
  return x,y,z
}

Measured memory_bytes: 53632
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define MX 20000000000000005
using namespace std;
int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	cout<<a[0]+a[1]<<endl;
	return 0;
	#ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())
h = input().split()
count = n
for i in range(n):
    h[i] = int(h[i])
    if i > 0:
        for j in range(i):
            if h[j] > h[i]:
                count -= 1
                break
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  cin >> a >> b >>c;
  set<int> n;
  n.insert(a);
  n.insert(b);
  n.insert(c);
  if(n.size()==2) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
n = int(input())
w = list(map(int, input().split()))
s = sum(w)
t = 0
ans = s
for e in w:
	t += e
	if t * 2 > s:
		ans = min(ans, t * 2 - s)
	else:
		ans = min(ans, s - t * 2)
print(ans)

Measured memory_bytes: 3060
//#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 = 5e3 + 5;
const int M = 5e5 + 5;
const int OO = 1e9;
const int mod = 1e9 + 7;

int n,k,p[N],c[N];
ll ans = LLONG_MIN;

void init() {}

int main() {

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

    cin >> n >> k;

    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
    }

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

    for (int i = 1; i <= n; ++i) {

        ll sum = c[i];
        int cnt = 1;

        for (int j = p[i]; j != i; j = p[j]) {
            sum += c[j];
            ++cnt;
        }

        if(k >= cnt) {
            ans = max(ans, k/cnt * sum);
        }
        ll cum = 0;

        for (int j = p[i], steps = 0; j != i; j = p[j]) {
            cum += c[j];
            ++steps;
            if(k>=steps) {
                if(sum < 0) {
                    ans = max(ans, cum);
                } else {
                    ans = max(ans, cum + (k-steps)/cnt * sum);
                }

            }
        }

    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 3648
/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
	static char buf[1000000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int frd(){
	int x=0,f=1; char ch=gc();
	for (;ch<'0'||ch>'9';ch=gc())	if (ch=='-')	f=-1;
	for (;ch>='0'&&ch<='9';ch=gc())	x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}
inline int read(){
	int x=0,f=1; char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')	f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}
inline void print(int x){
	if (x<0)	putchar('-'),x=-x;
	if (x>9)	print(x/10);
	putchar(x%10+'0');
}
const int N=5e2;
int cnt[N+10],A[N*N+10],C[N+10],B[N+10];
int pos[N+10][N+10];
bool cmp(int x,int y){return B[x]<B[y];}
bool check(int n){
	for (int i=1;i<=n*n;i++)	pos[A[i]][++pos[A[i]][0]]=i;
	for (int i=1;i<=n;i++)	if (pos[i][i]!=B[i])	return 0;
	return 1;
}
int main(){
	int n=read();
	for (int i=1;i<=n;i++)	C[i]=A[B[i]=read()]=i;
	sort(C+1,C+1+n,cmp);
	for (int i=1;i<=n;i++)	cnt[i]=i-1;
	for (int i=1;i<=n*n;i++){
		if (A[i])	continue;
		for (int j=1;j<=n;j++){
			if (cnt[C[j]]){
				cnt[A[i]=C[j]]--;
				break;
			}
		}
	}
	for (int i=1;i<=n;i++)	cnt[i]=n-i;
	for (int i=n*n;i>=1;i--){
		if (A[i])	continue;
		for (int j=n;j>=1;j--){
			if (cnt[C[j]]){
				cnt[A[i]=C[j]]--;
				break;
			}
		}
	}
	if (!check(n)){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	for (int i=1;i<=n*n;i++)	printf("%d",A[i]),putchar(i==n*n?'\n':' ');
	return 0;
}

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

int n, a[200010];

const int sz = 262144;
struct Seg{
	int dat[2 * sz];
	void ini(){
		for(int i = sz; i < sz + n; i++) dat[i] = i - sz + 1;
		for(int i = sz - 1; i >= 1; i--){
			if(a[dat[2 * i]] < a[dat[2 * i + 1]]) dat[i] = dat[2 * i];
			else dat[i] = dat[2 * i + 1];
		}
	}
	int get(int s, int e){
		int ret = 0;
		for(s += sz - 1, e += sz - 1; s <= e; s /= 2, e /= 2){
			if(s % 2 == 1){
				if(a[ret] > a[dat[s]]) ret = dat[s];
				s++;
			}
			if(e % 2 == 0){
				if(a[ret] > a[dat[e]]) ret = dat[e];
				e--;
			}
		}
		return ret;
	}
} S;

ll f(int s, int e){
	if(s > e) return 0;
	int mi = S.get(s, e);
	return 1LL * (mi - s + 1) * (e + 1 - mi) * a[mi] + f(s, mi - 1) + f(mi + 1, e);
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", a + i);
	a[0] = n + 1;
	S.ini();
	printf("%lld\n", f(1, n));
}

Measured memory_bytes: 18432
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
bool solve(int &a, int &b, int &c){
	if(a & 1)
		return 0;
	if(b & 1)
		return 0;
	if(c & 1)
		return 0;
	int x = a / 2 + b / 2;
	int y = a / 2 + c / 2;
	int z = b / 2 + c / 2;
	a = x;
	b = y;
	c = z;
	return 1;
}
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int cnt = 0;
	while(1){
		if(!solve(a, b ,c))
			break;
		cnt++;
		if(cnt > 500000){
			cnt = -1;
			break;
		}
	}
	cout << cnt <<endl;
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long int

void findAns()
{
    int n, m, k;
    cin >> n >> m >> k;

    ll a[n], b[m];

    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];

    int i = 0;
    int j = 0;
    ll sum = 0;
    ll count;
    while (i < n and sum + a[i] <= k)
    {
        sum += a[i];
        i++;
    }
    count = i;

    while (j<m and i >= 0)
    {
        sum += b[j];
        j++;
        while (sum > k and i > 0)
        {
            i--;
            sum -= a[i];

        }
        if (sum <= k and i + j > count) count = i + j;
    }
    cout << count;

}
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
//     freopen("o1.txt", "w", stdout);
//     //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s" << "\n";
// #endif

    fastio;
    ll  t = 1;
    // cin >> t;

    while (t--)
        findAns();
}


Measured memory_bytes: 6728
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define x first
#define y second
#define oo 1000000000
#define PII pair <int, int>
 
using namespace std;

int n;
 
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s;
    cin >> s;
    string S = s;
    reverse(S.begin(), S.end());
    if (S == s) cout << "Yes";
    else cout << "No";
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define true 1
#define false 0

int n, q, A[2000], m[2000];
int main()
{
  int i, j;
  
  scanf("%d", &n);  // A????????°
  for(i = 0; i < n; i++)
    scanf("%d", &A[i]);
  scanf("%d", &q);  // m????????°
  for(i = 0; i < q; i++)
    scanf("%d", &m[i]);

  for(i = 0; i < q; i++)
    {
      if(solve(0, m[i])) printf("yes\n");
      else printf("no\n");
    }
return 0;
}
  
int solve(int i, int m)
{
  int res;
  if(m == 0) return true;
  if(i >= n) return false;
  res = solve(i+1, m) || solve(i+1, m-A[i]);
  return res;
}

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

int n;
int primes[] = {11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381};

int main() {
  cin >> n;
  cout << primes[0];
  for (int i = 1; i < n; i++) {
    cout << " " << primes[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int p[1000],a[1000],b,c,n,m;
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++)cin>>a[i];
	for(int i=0;i<m;i++){
		c=0;
		for(int j=1;j<=n;j++){
			cin>>b;
			if(a[i]==b)p[j]++;
			if(a[i]!=b)c++;
		}
		p[a[i]]+=c;
	}
	for(int i=1;i<=n;i++)cout<<p[i]<<endl;
	return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
int n, a[200001], l[200001], r[200001], deq[200001];
 
signed main()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    deq[0] = 0;
    int top = 0;
    for(int i = 1; i <= n; i++){
        while(top > 0 && a[deq[top]] >= a[i]) top--;
        l[i] = deq[top] + 1;
        top++;
        deq[top] = i;
    }    
    deq[0] = n + 1;
    top = 0;
    for(int i = n; i >= 1; i--){
        while(top > 0 && a[deq[top]] >= a[i]) top--;
        r[i] = deq[top] - 1;
        top++;
        deq[top] = i;
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans += (i - l[i] + 1) * (r[i] - i + 1) * a[i];
    }
    cout << ans;
}

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

using namespace std;

//mem(a, b) memset(a, (b), sizeof(a))

typedef long long ll;

#define f(i,a,b) for (ll i=a ; i<b ; i++)

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define faster ios::sync_with_stdio(0);cin.tie(0);
typedef pair<int, int> p;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<p> vii;
typedef vector<vi> vvi;
typedef map<int,int> mp;
typedef set<int> se;
typedef multiset<int> MSETI;


// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

// traversal function to avoid long template definition. Now with C++11 auto alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)

// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define present(c,x) ((c).find(x) != (c).end())

//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())

// Avoiding wrap around of size()-1 where size is a unsigned int.
#define sz(a) int((a).size())


struct duo{
    ll x,y;
};

bool mycomp(duo a,duo b) { return a.x < b.x ;}

bool comp(int a,int b){
	return a<b;
}


int main()
{
	faster


	ll t,n,b=0,d,i,j,k,c,sum;
   cin>>n>>k;
   vi v(n);
   f(i,0,n)cin>>v[i];
   sort(v.begin(),v.end());
   f(i,0,k)
   {
       b+=v[i];
   }
   cout<<b;
    
	
	
}


Measured memory_bytes: 3664
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
// #define int ll
#define pll pair<ll, ll> 
#define pdd pair<ld, ld> 
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define mod 1000000007
using namespace std;

void dfs(unordered_set<int> adj[], int sv, vector<bool> &vis, int &z){
	vis[sv] = true;
	z++;
	for(auto i = adj[sv].begin(); i != adj[sv].end(); i++){
		if(!vis[*i]){
			dfs(adj, *i, vis, z);
		}
	}
}
ll power(ll x, ll y){  
	if(x == 1 || y == 0)
		return 1;
    ll res = 1;   
    x = x % mod; 
    if (x == 0) 
		return 0;  
    while (y > 0){  
        if (y & 1)  
            res = (res * x) % mod;  
        y = y >> 1; 
        x = (x * x) % mod;  
    }  
    return res;  
} 

signed main(){
	FASTIO
	int n, m;
	cin >> n >> m;
	unordered_set<int> adj[n+1];

	rep(i, 0, m){
		int u, v;
		cin >> u >> v;
		adj[u].insert(v);
		adj[v].insert(u);
	}
	vector<bool> vis(n + 1, false);
	int ans = 0;
	rep(i, 1, n + 1){
		if(!vis[i]){
			int z = 0;
			dfs(adj, i, vis, z);
			ans = max(ans, z);
		}
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 42540
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,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; }







void solve(){
    ll x;
    cin>>x;
    ll ans=0;
    ans+=x/500;
    x-=ans*500;
    ans*=1000;
    ans+=x/5*5;
    cout<<ans<<endl;
}




signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);


    solve(); 


    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {

	long long int a, b, c;
	long long int x, y;
	cin >> a >> b >> c >> x >> y;

	long long int ans = a*x + b*y;

	for (long long int i = 2; i < 900000; i+=2) {
		long long int ans2 = c*i;
		if (x - (i / 2) > 0) {
			ans2 += a*(x - (i / 2));
		}
		if (y - (i / 2) > 0) {
			ans2 += b*(y - (i / 2));
		}
		ans = min(ans, ans2);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, k, r, s, p;
	string t;
	cin >> n >> k >> r >> s >> p >> t;

	vector<int> t2;
	for(int i=0;i<n;i++) {
		if (t[i] == 'r') t2.push_back(2);
		if (t[i] == 's') t2.push_back(0);
		if (t[i] == 'p') t2.push_back(1);
	}
	int sc[3] = { r, s, p };

	int score = 0;
	for(int i=0;i<n;i++) {
		score += sc[t2[i]];
	}

	for(int i=0;i<n-k;i++) {
		if (t2[i] == t2[i + k]) {
			if (sc[t2[i]] < sc[t2[i + k]]) {
				score -= sc[t2[i]];
			}else {
				score -= sc[t2[i + k]];
				t2[i + k] = -1;
			}
		}
	}
	cout << score;
	return 0;
}

Measured memory_bytes: 1020
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1 << 30)

int H, A[MAX+1];

void maxHeapify(int i) {
    int l, r, largest;
    l = 2 * i;
    r = 2 * i + 1;
    
    if (l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    if (r <= H && A[r] > A[largest] ) largest = r;
    
    if ( largest != i) {
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

int extract() {
    int maxv;
    if (H < 1) return -INFTY;
    maxv = A[1];
    A[1] = A[H--];
    maxHeapify(1);
    return maxv;
}

void increaseKey(int i, int key) {
    if (key < A[i]) return;
    A[i] = key;
    while( i > 1 && A[i / 2] < A[i]) {
        swap(A[i], A[i / 2]);
        i = i /2;
    }
}

void insert(int key) {
    H++;
    A[H] = -INFTY;
    increaseKey(H, key);
}

int main() {
    int key;
    char com[10];
    
    while(1) {
        scanf("%s", com);
        if ( com[0] == 'e' && com[1] == 'n') break;
        if (com[0] == 'i') {
            scanf("%d", &key);
            insert(key);
        } else {
            printf("%d\n", extract());
        }
    }
    
    return 0;
}


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

int main() {
  string W;
  cin >> W;
  int count = 0;
  if (W.at(0) == 'R') {
    count += 1;
  }
  if (W.at(1) == 'R') {
    count += 2;
  }
  if (W.at(2) == 'R') {
    count += 4;
  }
  if (count == 0) {
    cout << 0 << endl;
  } else if (count == 1 || count == 2 || count == 4 || count == 5) {
    cout << 1 << endl;
  } else if (count == 3 || count == 6) {
    cout << 2 << endl;
  } else if (count == 7) {
    cout << 3 << endl;
  }
}

Measured memory_bytes: 3556
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n:usize,s:String};

    let r = s.match_indices("R").count();
    let g = s.match_indices("G").count();
    let b = s.match_indices("B").count();

    let s = s.as_str().as_bytes();

    let mut count = 0;
    for i in 0..n {
        for j in i + 1..n {
            let k = 2 * j - i;
            if k >= n {
                continue;
            }
            if s[i] != s[j] && s[j] != s[k] && s[k] != s[i] {
                count += 1;
            }
        }
    }

    println!("{}", r * g * b - count);
}


Measured memory_bytes: 2128
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * b / g;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using Graph = vector<VE>;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n; cin >> n;
	double cnt = 0;
	rep(i, n)
	{
		if ((i + 1) % 2 == 1) {
			cnt++;
		}
	}
	cout << fixed << setprecision(15) << cnt / (double)(n) << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
import itertools
import collections
from collections import deque

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

h = itertools.combinations_with_replacement
p = itertools.permutations

def main():
    # input
    N, K = map(int, input().split())
    rest = N%K
    reverse = abs(rest - K)
    ans = min(N, rest, reverse)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 21516
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
	char n[4];
	scanf("%s", &n);

	int i = strlen(n);
	int j = atoi(&n[i - 1]);
	if (j == 3) 
	{
		printf("bon");
	}
	else if (j == 2 || j == 4 || j == 5 || j == 7 || j == 9) {
		printf("hon");
	}
	else {
		printf("pon");
	}
	return 0;
}

Measured memory_bytes: 1732
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        int ques = int.Parse(ReadLine());
        string[] time = ReadLine().Split(' ');
        int drink = int.Parse(ReadLine());
        for(int i=0;i<drink;i++){
            string[] temp = ReadLine().Split(' ');
            int num = int.Parse(temp[0]);
            int jikan = int.Parse(temp[1]);
            int output = 0;
            for(int j=0;j<ques;j++){
                if(num-1 == j){
                    output += jikan;
                }else{
                    output += int.Parse(time[j]);
                }
            }
            WriteLine(output);
        }
    }
}


Measured memory_bytes: 13140
n = gets.to_i
as = gets.split.map(&:to_i)
multiple_of_4 = 0
multiple_of_2 = 0
as.each do |a|
  if a % 4 == 0
    multiple_of_4 += 1
  elsif a % 2 ==0
    multiple_of_2 += 1
  end
end

can_save = multiple_of_4
can_save += 1 if multiple_of_2 == 0

# puts "[debug] 4の倍数: #{multiple_of_4}個、2の倍数: #{multiple_of_2}個、その他: #{n-multiple_of_4-multiple_of_2}個"
# puts "[debug] 4の倍数によってカバー可能な個数: #{can_save}個"
puts multiple_of_2 + multiple_of_4 + can_save >= n ? "Yes" : "No"


Measured memory_bytes: 8452
// finish date: 2018/02/26

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


struct E {
    int to, distance;

    E(int t, int d) {
        to = t;
        distance = d;
    }
};

vi x;
vector<vector<E>> EL, ER;
vb useL, useR;

bool dfs(vector<vector<E>> &edges, int node, vb &use) {
    if (use[node]) return true;
    use[node] = true;
    if (x[node] == INT_MAX) x[node] = 0;
    bool flag = true;
    for (E e:edges[node]) {
        int newD = x[node] + e.distance;
        if (x[e.to] != INT_MAX && x[e.to] != newD) return false;
        x[e.to] = newD;
        flag &= dfs(EL, e.to, useL);
        flag &= dfs(ER, e.to, useR);
    }
    return flag;
}


int main() {
    int N, M;
    cin >> N >> M;
    if (M == 0) {
        cout << "Yes" << endl;
        return 0;
    }
    vi L(M), R(M), D(M);
    EL = vector<vector<E>>(N);
    ER = vector<vector<E>>(N);
    x = vi(N, INT_MAX);
    useL = vb(N, false);
    useR = vb(N, false);
    rep(i, M) {
        cin >> L[i] >> R[i] >> D[i];
        L[i]--;
        R[i]--;
        EL[R[i]].emplace_back(E(L[i], -D[i]));
        ER[L[i]].emplace_back(E(R[i], D[i]));
    }
    rep(i, N) {
        bool con1 = dfs(EL, i, useL);
        bool con2 = dfs(ER, i, useR);
        if (!(con1 && con2)) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;


}





Measured memory_bytes: 23040
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <deque>

using namespace std;

int main()
{
    string S;
    cin >>S;
    int N = S.size();

    vector<int> L(N);
    int lb=0,rb=0;
    for (int i=1; i<N;++i) {
        if (S[i] == 'L') {
            if (S[i-1]=='R') {
                lb=i-1;
            }
            L[i]=i-lb;
        }
        int j=N-i-1;
        if (S[j]=='R') {
            if (S[j+1]=='L') {
                rb = j+1;
            }
            L[j] = rb-j;
        }
    }

    //for (auto x:L) cerr << x << " ";
    //cerr << endl;

    vector<int> P(N);
    for (int i=0;i<N;++i) {
        if (S[i]=='R') {
            int j=i+L[i] - (L[i]&1);
            P[j]++;
        } else {
            int j=i-L[i] + (L[i]&1);
            P[j]++;
        }
    }

    for (auto x:P) cout << x << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 1408
N = int(input())
A = list(map(int,input().split()))
B = [0 for _ in range(N+1)]
for i in range(N):
    B[i+1] = B[i]+A[i]
C = {}
for i in range(N+1):
    b = B[i]
    if b not in C:
        C[b] = 0
    C[b] += 1
cnt = 0
for b in C:
    cnt += (C[b]*(C[b]-1))//2
print(cnt)

Measured memory_bytes: 112900
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double p = acos(-1);

double solve(double a,double b,double x)
{
    double h,l,Cos,y;
    h = 2*x/(a*b);
    if(h>a)
    {
        y = (2*x-b*a*a)/(a*a);
        b-=y;
        h = a;
    }
    l = sqrt(h*h+b*b);
    Cos = h/l;
    Cos = acos(Cos);
    Cos = Cos*180/p;
    return Cos;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie();
    cout.tie();

    double a,b,x,h,l,Cos;
    cin>>a>>b>>x;

    printf("%.8f\n",solve(a,b,x));
    return 0;
}


Measured memory_bytes: 256
n,k = map(int, input().split())
alist=list(map(int, input().split()))
def is_ok(arg):
    cnt=0
    for i in alist:
      cnt+=(i-1)//arg
    return cnt<=k
def nibun(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok
print(nibun(0 , 10**9 + 1))

Measured memory_bytes: 31096
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

int gcd(int a, int b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

int lcm(int a, int b) { //最小公倍数
  return a * b / gcd(a, b);
}


int main()
{
  ll n,k,a[200010],cnt[200010]={};
  cin>>n>>k;
  rep(i,n){
    cin>>a[i];
    cnt[a[i]]++;
  }

  ll max=0;
  sort(cnt,cnt+200010);

  rep(i,200010){
    if(cnt[i]>0)max++;
  }
  ll ans=0;
  if(max<=k){
    cout<<0<<endl;
    return 0;
  }

  ll tmp=0,tmp2=0;
  while(1){
    if(cnt[tmp]!=0){
      ans+=cnt[tmp];
      tmp2++;
      if(tmp2==max-k){
        break;
      }
    }
    tmp++;
  }
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 6732
A,B,M=map(int,input().split())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
 
answer=min(alist)+min(blist)
for _ in range(M):
  x,y,c=map(int,input().split())
  disc=alist[x-1]+blist[y-1]-c
  answer=min(answer,disc)
  
print(answer)

Measured memory_bytes: 24780
#![allow(unused_imports)]
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;
use std::str::FromStr;
use std::cmp::Reverse;

#[allow(dead_code)]
type Error = Box<dyn std::error::Error>;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

struct Scanner {
    buff: Vec<String>,
    pos: usize,
}

#[allow(dead_code)]
impl Scanner {
    pub fn new() -> Self {
        Scanner {
            buff: Vec::new(),
            pos: 0,
        }
    }

    pub fn next<T: FromStr>(&mut self) -> T {
        while self.buff.len() <= self.pos {
            self.pos = 0;
            self.buff = read_line().split_whitespace().map(|s| s.to_owned()).collect();
        }

        let result = self.buff[self.pos].parse::<T>();
        self.pos += 1;
        result.ok().unwrap()
    }

    pub fn next_line(&mut self) -> String {
        let result  = read_line().trim().to_owned();
        self.buff.clear();
        self.pos = 0;

        result
    }

    pub fn next_vec<T: FromStr>(&mut self) -> Vec<T> {
        self.buff.clear();
        self.pos = 0;
        read_line().trim().split_whitespace().map(|s| s.parse().ok().unwrap()).collect()
    }
    
    pub fn next_line_chars(&mut self) -> Vec<char> {
        let result  = read_line().trim().chars().collect();
        self.buff.clear();
        self.pos = 0;

        result
    }
}

const MOD: u64 = 1_000_000_007;

fn func(a: &Vec<usize>, b: &Vec<usize>, n: usize, m: usize) -> u64 {
    let mut p = vec![false; n*m];
    let mut q = vec![false; n*m];

    for i in 0..n {
        let tar = a[i]-1;
        if p[tar] {
            eprintln!("double row at {}: {}", tar, i);
            return 0;
        }
        p[tar] = true;
    }
    for i in 0..m {
        let tar = b[i]-1;
        if q[tar] {
            eprintln!("double line at {}: {}", tar, i);
            return 0;
        }
        q[tar] = true;
    }
    let mut row = 0;
    let mut line = 0;
    let mut ans = 1;
    let mut tar = n*m-1;
    let mut used = 0;

    while row < n || line < m {
        if p[tar] && q[tar] {
            row += 1;
            line += 1;
            used += 1;
        } else if p[tar] {
            ans *= line as u64;
            ans %= MOD;
            row += 1;
            used += 1;
        } else if q[tar] {
            ans *= row as u64;
            ans %= MOD;
            line += 1;
            used += 1;
        } else {
            if row * line > used {
                ans *= (row * line - used) as u64;
                ans %= MOD;
                used += 1;
            } else {
                eprintln!("empty for {}", tar);
                return 0;
            }
        }
        tar-= 1;
    }

    for i in 0..n*m-used {
        ans *= (i+1) as u64;
        ans %= MOD;
    }

    ans
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.next();
    let m: usize = sc.next();

    let a: Vec<usize> = sc.next_vec();
    let b: Vec<usize> = sc.next_vec();

    println!("{}", func(&a, &b, n, m));
}


Measured memory_bytes: 2204
n = int(input())
s = list(map(int,input().split()))
s.sort()
ans=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1, n):
            if s[i] != s[j] != s[k]:
                if s[i]+s[j]>s[k]:
                    ans+=1
print(ans)

Measured memory_bytes: 9168
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<int,int> mp[2];
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    mp[i & 1][x]++;
  }
  vector<pair<int,int>> v[2];
  for (int u = 0; u < 2; u++) {
    for (auto &p : mp[u]) {
      v[u].emplace_back(p.second, p.first);
    }
    if (v[u].size() == 1) {
      v[u].emplace_back(0, -1);
    }
    sort(v[u].rbegin(), v[u].rend());
  }
  int ans = 0;
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      if (v[0][i].second != v[1][j].second) {
        ans = max(ans, v[0][i].first + v[1][j].first);
      }
    }
  }
  cout << n - ans << '\n';
  return 0;
}

Measured memory_bytes: 8900
#include<iostream>
#include<cstdlib>
#include<stack>
using namespace std;

int main(){
    stack<int> S;
    int a, b, x;
    string s;
    
    while( cin >> s){
        if(s[0] == '+'){
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(a + b);
        }else if( s[0] == '-'){
            b = S.top(); S.pop();
            a = S.top(); S.pop();
            S.push(a - b);
        }else if( s[0] == '*'){
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(a * b);
        }else{
            S.push(atoi(s.c_str()));
        }
    }
    
    cout << S.top() << endl;
    
    return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int a,b;
  cin >> a >> b;
  if ((a + b)%2==0) cout << (a+b)/2 << endl;
  else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 3636
import fractions

A, B, C, D = [int(i) for i in input().strip().split()]

# (B - A + 1) - n(C) - n(D) + n(C∩D)

def count_divisible_numbers(x):
  a = (A-1) // x
  b = B // x
  return b - a

n_C = count_divisible_numbers(C)
n_D = count_divisible_numbers(D)
CD_lcm = C*D // fractions.gcd(C, D)
n_CD = count_divisible_numbers(CD_lcm)

res = (B - A + 1) - n_C - n_D + n_CD
print(res)


Measured memory_bytes: 5852
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long int64;
int MOD = 1e9 + 7;

map<int, int> kish;

int main() {
  int N, tmp;
  int64 ans = 1;
  cin >> N;
  kish[-1] = 3;
  rep(i, N) {
    cin >> tmp;
    ans *= kish[tmp - 1] - kish[tmp];
    ans %= MOD;
    ++kish[tmp];
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define Point pair<double, double>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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; }

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);

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

  int n, k; cin >> n >> k;
  vector<P> vec(n);
  vector<bool> used(n+1);

  rep(i, n) {
    ll t, d; cin >> t >> d;
    vec[i] = P(d, t);
  }

  sort(vec.rbegin(), vec.rend());

  ll ans = 0;
  ll sum = 0;
  ll kind = 0;
  priority_queue<ll, vector<ll>, greater<>> que;
  rep(i, k) {
    sum += vec[i].first;
    if (used[vec[i].second]) {
      que.push(vec[i].first);
    } else {
      used[vec[i].second] = true;
      kind++;
    }
  }
  ans = sum + kind*kind;

  for(int i=k; i<n; i++) {
    if (used[vec[i].second]) {
    } else {
      if (que.size() == 0) {
        break;
      }
      used[vec[i].second] = true;
      kind++;
      sum += vec[i].first;
      ll mi = que.top(); que.pop();
      sum -= mi;
      chmax(ans, sum+kind*kind);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 2428
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::*;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

use std::time::Instant;
fn main() {
    let _ = read::<usize>();
    let aa = readv::<usize>();
    let bb = readv::<usize>();
    let x = aa.iter().fold(0, |acc, &a| acc ^ a);
    let (mut aa, bb): (Vec<_>, Vec<_>) = aa.iter().zip(bb.iter()).filter(|&(&a, &b)| a != b).unzip();
    let n = aa.len();
    aa.push(x);
    let mut nums = HashMap::with_capacity(n + 1);
    for &a in &aa {
        *nums.entry(a).or_insert(0) += 1;
    }
    // let mut nums: HashMap<_, i32> = aa.iter()
    //     .fold(HashMap::with_capacity(n + 1), |mut acc, &a| { *acc.entry(a).or_insert(0) += 1; acc });
    for &b in &bb {
        *nums.entry(b).or_insert(0) -= 1;
        if nums[&b] < 0 {
            println!("{}", -1);
            return;
        }
    }

    let mut dests = bb.iter().enumerate()
        .fold(HashMap::new(), |mut acc, (a, b)| { (acc.entry(b).or_insert(Vec::new())).push(a); acc });
    let mut q: VecDeque<_> = std::iter::once(n).collect();
    let mut rems: HashSet<_> = (0..n + 1).collect();
    let mut ans = n;
    #[cfg(local)] println!("{}: {:?}", "(aa, bb)", (&aa, &bb));
    while !rems.is_empty() {
        while let Some(s_idx) = q.pop_front() {
            if !rems.remove(&s_idx) { continue; }
            let s_num = aa[s_idx];
            // if let Some(destv) = dests.remove(&s_num) {
            //     for dest in destv {
            //         q.push_back(dest);
            //     }
            // }
            if let Some(destv) = dests.get_mut(&s_num) {
                for &dest in destv.iter() {
                    q.push_back(dest);
                }
                destv.clear();
            }
        }
        if let Some(&rem) = rems.iter().next() {
            q.push_back(rem);
            q.push_back(rem);
            ans += 1;
        }
    }
    println!("{}", ans);
    std::process::exit(0);
}


Measured memory_bytes: 27576
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<int,int> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
	int n,l;
	cin>>n>>l;
	int sum=0;
	for(int i=0;i<n;i++){
		sum+=(l+i);
	}
	int k;
	if(l*(n+l-1)<=0)k=0;
	else if(l>0)k=l;
	else k=n+l-1;
	cout<<sum-k<<endl;
	return 0;
}

Measured memory_bytes: 256