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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

    ll N, M;
    cin >> N >> M;
    vll H(N), A(M), B(M);
    rep(i, N) cin >> H[i];
    rep(i, M) cin >> A[i] >> B[i];

    vll checked(N, 0);
    vector<unordered_set<ll>> e(N);
    rep(i, M){
        e[A[i]-1].insert(B[i]-1);
        e[B[i]-1].insert(A[i]-1);
    }
    vector<pair<ll, ll>> t(N);
    rep(i, N){
        t[i].first = i;
        t[i].second = H[i];
    }
    sort(all(t), [](auto l, auto r){ return l.second>r.second; });
    ll count = 0;
    rep(i, N){
        ll n = t[i].first;
        bool ok = true;
        for(ll s : e[n]){
            checked[s] = 1;
            e[s].erase(n);
            ok &= H[n]>H[s];
        }
        if(ok && !checked[n]) ++count;
        checked[n] = 1;
    }
    cout << count << endl;
}


Measured memory_bytes: 22976
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

using P = pair<double, int>;
void outl(vector<P> &v) {
	sort(v.begin(), v.end());
	for (P p: {v[0], v[1]}) {
		out(p.second, ' ');
		printf("%.2lf\n", p.first);
	}
}

int main() {
	vector<P> a, b(8);
	for (int i = 0; i < 3; i++) {
		double d;
		for (P &x: b) {
			x.second = in();
			scanf("%lf", &d);
			x.first = d;
		}
		outl(b);
		a.push_back(b[2]);
		a.push_back(b[3]);
	}
	outl(a);
}


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

vector<int> X(100);

int main(){
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            ans += X[i]*X[j];
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
n,m,p = map(int,input().split())
d = [(int(input())+n-p)%n for _ in range(m)]
d.append(0)
d.sort()
ans = n
m = len(d)
for i in range(m):
    ans = min(ans, d[i]*2+(n-d[(i+1)%m])%n, d[i]+(n-d[(i+1)%m])%n*2)
print(ans*100)



Measured memory_bytes: 5948
package main
import "fmt"

func gcd(a, b int) int {
    if a > b {
        a, b = b, a
    }
    if a == 0 {
        return b
    }
    b = b % a
    return gcd(a, b)
}

func main() {
    var n int
    fmt.Scan(&n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    pre := make([]int, n+1)
    post := make([]int, n+1)
    pre[0] = 0
    post[n] = 0
    for i := 0; i < n; i++ {
        pre[i+1]  = gcd(pre[i],  a[i])
        post[i+1] = gcd(post[i], a[n-i-1])
    }
    ret := 0
    for i := 0; i < n; i++ {
        tmp := gcd(pre[i], post[n-i-1])
        if ret < tmp {
            ret = tmp
        }
    }
    fmt.Println(ret)
}


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

typedef pair<int,int> PII;
const int MV=2505;
const int ME=5005;
const int INF=0x3f3f3f3f;

struct Edge
{
	int u,v,c;
	Edge(int u=0,int v=0,int c=0)
		:u(u),v(v),c(c){}
};
vector<Edge> edges;
vector<int> rg[MV];
int vis[MV];
int d[MV];

void dfs(int u)
{
	if(vis[u]) return;
	vis[u]=1;
	for(int v:rg[u])
		dfs(v);
}

int main()
{
	int n,m,p;
	scanf("%d%d%d",&n,&m,&p);
	int u,v,c;
	for(int i=0;i<m;i++)
	{
		scanf("%d%d%d",&u,&v,&c);
		edges.emplace_back(u,v,p-c);
		rg[v].push_back(u);
	}
	memset(d,INF,sizeof(d));
	d[1]=0;
	dfs(n);
	if(!vis[1])
	{
		//cout<<"here1"<<endl;
		printf("-1\n");
		return 0;
	}
	for(int i=0;i<=n;i++)
	{
		for(Edge e:edges)
		{
			int u=e.u,v=e.v,c=e.c;
			if(!vis[u]||!vis[v]) continue;
			if(d[u]==INF) continue;
			if(d[u]+c<d[v])
			{
				if(i==n)
				{
					//cout<<"here2"<<endl;
					printf("-1\n");
					return 0;
				}
				d[v]=d[u]+c;
				//cout<<v<<" "<<u<<" "<<d[v]<<endl;
			}
		}
	}
	printf("%d\n",max(0,-d[n]));
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>

#define endl '\n'

using namespace std;

const int MAXN=1e5+3;
int dp[MAXN],height[MAXN];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;++i){
        cin>>height[i];
        dp[i]=1e9;
    }
    dp[0]=0;
    for(int i=1;i<n;++i){
        for(int i2=1;i2<=k and i2<=i;++i2){
            dp[i]=min(dp[i],dp[i-i2]+abs(height[i]-height[i-i2]));
        }
    }
    cout<<dp[n-1]<<endl;
return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
#define int long long
#define MOD (long long)(1e9+7)
#define MAX_V (long long)(1e5*2+200)

long long MAX_VAL, MAX_VAL2;
long long fac[MAX_V], mmi[MAX_V], temp[MAX_V];

inline void factorial(){
	fac[0] = fac[1] = 1;
	for(long long i = 2; i < MAX_VAL; fac[i]%=MOD,i++)
		fac[i] = fac[i-1]*(i%MOD);
}

inline long long power_mod(long long x, long long n){
	long long ans = 1;
	for(;n;n>>=1,x*=x,ans%=MOD,x%=MOD)
		if(n&1)ans*=x;
	return ans;
}

inline void modular_multiplicatibe_inverse(){
	mmi[MAX_VAL2-1] = power_mod(fac[MAX_VAL2-1],MOD-2);
	for(long long i = MAX_VAL2-2; i >= 0; mmi[i]%=MOD,i--)
		mmi[i] = mmi[i+1]*(i+1);
}

inline long long combination(long long n, long long r){
	return fac[n]*(mmi[r]*mmi[n-r]%MOD)%MOD;
}

inline long long foo(long long n, long long r){
}
signed main(){
	int H, W, A, B, ans = 0;
	cin>>H>>W>>A>>B;
	MAX_VAL = max(W+H-A-2,A+W-1)+5;
	MAX_VAL2 = max(max(W-B+1,W-1),max(H-A-1, A-1))+3;
	
	factorial();
	modular_multiplicatibe_inverse();

	for(int i = B+1; i <= W; ans%=MOD,i++)
		ans += combination(H-A+i-2,H-A-1)*combination(W+A-i-1,A-1);
	cout<<ans<<endl;

}

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

int main() {
    
	int n, sm;
	cin >> n >> sm;
	int low = INT_MAX;
	for (int i=0; i<n; i++) {
		int x;
		cin >> x;
		sm -= x;
		low = min(low, x);
	}
	cout << n + sm / low << endl;
	
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = 0;

		do {
			n = sc.nextInt();
				if (n == 0) {
					break;
				} else {
					System.out.println( maximumSum(n) );
				}
		}while(true);

	}

	private static int maximumSum(int n) {
		int[] nums = new int[n];
		int max = Integer.MIN_VALUE;
		int sum = 0;

			for (int i = 0; i < n; i++ ) {
				nums[i] = sc.nextInt();
			}

			for (int i = 0; i < n; i++ ) {
				sum = 0;
					for (int j = i ; j < n; j++ ) {
						 sum += nums[j];
					 	 max = Math.max(max, sum);
					}

			}

		return max;
	}

}


Measured memory_bytes: 33552
import java.util.*;
import java.io.*;
public class Main
{
	public static void main(String args[]) throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		char f[]=(br.readLine()).toCharArray();
		char s[]=(br.readLine()).toCharArray();
		int n=f.length,m=s.length;
		int dp[][]=new int[f.length+1][s.length+1];
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			{
				if(f[i-1]==s[j-1])
					dp[i][j]=dp[i-1][j-1]+1;
				else
					dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
			}
		}
		
		String ans="";
		int ip=n,jp=m;
		int ctr=0;
		while(ip>0&&jp>0)
		{
			if(f[ip-1]==s[jp-1])
			{
				ans+=f[ip-1];
				ip--;
				jp--;
				ctr++;
			}
			else if(dp[ip-1][jp]>dp[ip][jp-1])
				ip--;
			else
				jp--;
			
			if(ctr==dp[n][m])
				break;
		}
		char ans1[]=ans.toCharArray();
		StringBuilder sb=new StringBuilder();
		for(int i=ans.length()-1;i>=0;i--)
			sb.append(ans1[i]);
		System.out.println(sb);
	}
}

Measured memory_bytes: 97364
while 1:
	n = int(raw_input())
	if n == 0:
		break
	w,h = map(int,raw_input().split(" "))
	tree_loc = [map(int,raw_input().split(" ")) for i in range(n)]
	s,t = map(int,raw_input().split(" "))
	get_field = [[0 for i in range(0,w-s+2)] for j in range(0,h-t+2)] 
	for x,y in tree_loc:
		get_field[max(y-t+1,1)][max(x-s+1,1)] += 1
		if y + 1 <= h - t + 1:
			get_field[y+1][max(x-s+1,1)] -= 1
		if x + 1 <= w - s + 1:
			get_field[max(y-t+1,1)][x+1] -= 1
		if y + 1 <= h - t + 1 and x + 1 <= w - s + 1:
			get_field[y+1][x+1] += 1

	for i in range(1,w-s+1):
		for j in range(1,h-t+2):
			get_field[j][i+1] += get_field[j][i]	
	for j in range(1,h-t+1):
		for i in range(1,w-s+2):
			get_field[j+1][i] += get_field[j][i]

	tree_max = max([max(get_field[j]) for j in range(1,h-t+2)])
	print tree_max

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   string a,b;cin >>a;
   ll n=a.size();
    for (int i = 0; i < n; ++i) {
        if(a[i]=='A')b+='T';
        else if(a[i]=='T')b+='A';
        else if(a[i]=='C')b+='G';
        else b+='C';
    }
    cout <<b<<endl;
   return 0;
}

Measured memory_bytes: 256
MOD = 2019
class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % MOD
        return self
    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other)) % MOD
        if self.value < 0: self.value += MOD
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

S=input()
m=[0]*MOD
m[0]=1
now=Mint()
ans=0
for i in range(1,len(S)+1):
    now += Mint(int(S[-i])) * pow(10,i-1,MOD)
    ans += m[now.value]
    m[now.value] += 1
print(ans)

Measured memory_bytes: 68432
#include<iostream>
#include<vector>
#include<utility>
#include<bitset>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

int main(){
	int n, x;
	cin >> n >> x;
	vector<int> a(n);
	for(int i=0; i<n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 0;
	for(int i=0; x>0 && i<n; i++){
		x -= a[i];
		ans++;
	}
	if(x)
		ans--;
	cout << ans << '\n';
	return 0;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main(){

	cout<<setprecision(15);

	double r;
	cin>>r;

	cout<<2*r*PI<<endl;

    return 0;
}


Measured memory_bytes: 3788
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int z(int a){
  if(a<1)a*=-1;
  return a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int n;
int f(int b,int c){
  return c*((n-1)/b+1);
}
int main(void){
  int n;
  ll a[105],x[105];
  while(1){
    scanf("%d",&n);
    if(!n)break;
    FOR(n+1)scanf("%lld",&x[i]);
    FOR(n+1){
      int l=0;
      FORJ(n+1){
        a[l]=x[j];
        if(i!=j)l++;
      }
      a[n]=x[i];
      int flg=1;
      FORJ(n-2)if(a[j]-a[j+1]!=a[j+1]-a[j+2])flg=0;
      if(flg){
        PRL(a[n]);
        break;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 2104
#include<stdio.h>
int main(){
        int H,W,j,i;
        
        scanf("%d %d",&H,&W);
        
        while(1){
        	//HとWの値が0の時抜ける
        	if(H == 0 && W == 0){
        	   break;
        	}
        	//iがH以下の間
        	for(i = 1;i <= H;i++){
        		if(i == 1 || i == H){
        			for(j = 1;j <= W;j++){
        				//全て#を出力する
        				printf("#");
        			}
        				printf("\n");
        		}
        		
        	else{
        	//jがw以下の間
        	for(j = 1;j <= W;j++){
        		if(j == 1 || j == W){
        			//#を出力する
        			printf("#");
        		}
        		else{
        			//.を出力する
        			printf(".");
        		}
        	}
        			printf("\n");
        	}
        	}
        		printf("\n");
        		scanf("%d %d",&H,&W);
        }
        return 0;
}


Measured memory_bytes: 2052
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue>
#define ll long long
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
using namespace std;
inline int gi(){
	int sum=0,f=1;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
inline ll gl(){
	ll sum=0,f=1;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
char s[5];
int main(){
	int i,j,n,m,k;
	cin>>s;
	if(strlen(s)==2)puts(s);
	else{
		for(int i=2;i>=0;i--)printf("%c",s[i]);
		puts("");
	}
	return 0;
}


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

int main () {
  string s;
  cin >> s;
  if(s=="RRR") cout << 3 << endl;
  else if(s=="RRS" || s=="SRR") cout << 2 << endl;
  else if(s=="SSS") cout << 0 << endl;
  else cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 3624
import sys

def is_stable(bs_data, ss_data):
    # in_data : ??????????????????????????????????????????
    # ss_data : ???????????????????????????????????????
    len_data = len(bs_data)

    for i in range(len_data):
        if bs_data[i] != ss_data[i]:
            return False

    return True

def bubble_sort(data, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if data[j][1] < data[j-1][1]:
                data[j], data[j-1] = data[j-1], data[j]

def selection_sort(data, n):
    for i in range(n):
        minj = i                # ??¨?????????????????????????°??????¨??????
        for j in range(i, n):
            if data[j][1] < data[minj][1]:
                minj = j

        data[i], data[minj] = data[minj], data[i]

def main():
    n = int(sys.stdin.readline().strip())
    card1 = sys.stdin.readline().strip().split(' ')

    card2 = card1[::]
    bubble_sort(card2, n)
    print(' '.join(card2))
    
    print('Stable')

    card3 = card1[::]
    selection_sort(card3, n)
    print(' '.join(card3))
    
    if is_stable(card2, card3):
        print('Stable')
    else:
        print('Not stable')

if __name__ == '__main__':
    main()
    

Measured memory_bytes: 7820
S = raw_input()
A = [chr(ord("a")+i) for i in range(26)]
if len(S)<26:
  for a in A:
    if a not in S:
      print S+a
      exit(0)
else:
  for p in range(26)[::-1]:
    for a in A[A.index(S[p])+1:]:
      if a not in S[:p]:
        print S[:p]+a
        exit(0)
  print -1


Measured memory_bytes: 2568
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<bool> vbool;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<llint> vllint;
typedef vector<vllint> vvllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
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;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

int main() {
	vector<char>ans;
	while (1) {
		int m, f, r;
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1)break;
		if (m == -1 || f == -1) {
			ans.push_back('F');
		}
		else if (m + f >= 80)ans.push_back('A');
		else if (m + f >= 65)ans.push_back('B');
		else if (m + f >= 50)ans.push_back('C');
		else if (m + f >= 30 && r >= 50)ans.push_back('C');
		else if (m + f >= 30)ans.push_back('D');
		else {
			ans.push_back('F');
		}
	}
	rep(i, ans.size())cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
 
using namespace std;

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

signed main(){
    io();
    ull a, b, c, d; cin >> a >> b >> c >> d;
    --a;
    ull cs = b/c - a/c;
    ull ds = b/d - a/d;
    ull lcm = c*d/__gcd(c,d);
    ull cds = b/lcm - a/lcm;
    cout << b - a - cs - ds + cds  << '\n';
    return 0;  
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    ll r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}
int main() {
ll a,b,c,d;  cin>>a>>b>>c>>d;

 ll e=lcm(c,d);
 //cout<<"e "<<e<<endl;
 
 ll res=b - a + 1 - ( ( b / c - ( a - 1 ) / c ) + ( b / d - ( a - 1 ) / d ) -( b / e - (a-1)/e ) );
 cout<<res<<endl;

}

Measured memory_bytes: 256
a = [int(c) * pow(10, i, 2019) % 2019 for i, c in enumerate(reversed(input()))]
s = [0]
for x in a:
  s += [(s[-1] + x) % 2019]
cnt, ans = [0] * 2019, 0
for x in s:
  ans += cnt[x]
  cnt[x] += 1
print(ans)


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

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

using namespace std;

const int INF=INT_MAX;

int main(){
	int n; scanf("%d",&n);
	pair<int,int> a[5000];
	rep(i,n) scanf("%d%d",&a[i].first,&a[i].second);

	sort(a,a+n,[](const pair<int,int>& x,const pair<int,int>& y){
		return x.first+x.second<y.first+y.second;
	});

	// dp[i][j] = (i 人目まで見て j 人が座布団を積んだときの高さの最小値)
	static int dp[5001][5001];
	rep(i,n+1) rep(j,n+1) dp[i][j]=INF;
	dp[0][0]=0;
	rep(i,n){
		int hi,pi; tie(hi,pi)=a[i];
		rep(j,i+1) if(dp[i][j]<INF) {
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
			if(dp[i][j]<=hi) dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+pi);
		}
	}

	int ans=0;
	rep(j,n+1) if(dp[n][j]<INF) ans=j;
	printf("%d\n",ans);

	return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


i64 N, Q;
string s;

int main() {
    cin >> N >> Q;
    cin >> s;

    vector<i64> C(N + 1, 0);
    for (i64 i = 0; i < N; i++) {
        C[i + 1] = C[i] + (i + 1 < N && s[i] == 'A' && s[i + 1] == 'C');
    }

    i64 l, r;
    REP(i, Q) {
        cin >> l >> r;
        l--; r--;
        cout << C[r] - C[l] << endl;
    }

    return 0;
}

Measured memory_bytes: 1872
def main():
    n=int(input())
    x=list(map(int, input().split()))
    d=[]
    rui=0
    kei=sum(x)
    for i in range(n-1):
        rui += x[i]
        d.append( abs(rui - (kei - rui)) )
    print(min(d))
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <stdio.h>

int isRight(int a, int b, int c)
{
    if (a * a == b * b + c * c) return 1;
    if (b * b == c * c + a * a) return 1;
    if (c * c == a * a + b * b) return 1;
    
    return 0;
}

int main(void)
{
    int n, i;
    int a, b, c;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d %d %d", &a, &b, &c);
        printf("%s\n", isRight(a, b, c) ? "YES" : "NO");
    }

    return 0;
}

Measured memory_bytes: 0
from sys import stdin
from math import factorial

def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

n = int(stdin.readline().rstrip())
li = [list(stdin.readline().rstrip()) for _ in range(n)]

set_list = {}

for i in li:
    i.sort()
    s = "".join(i)
    if s in set_list:
        set_list[s] += 1
    else:
        set_list[s] = 1

point = 0

for i in set_list.values():
    if i >= 2:
        point += combinations_count(i,2)

print(point)

Measured memory_bytes: 39040
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N,M,X,Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x.sort()
y.sort()
f1=False
f2=False

#
ans ="War"
for Z in range(-100,101):
    f1=False
    f2=False
    if X < Z <Y:
        f1 =True
    if x[-1] < Z <=y[0]:
        f2 =True
    if f1 ==f2 ==True:
        ans ="No War"
        break
print(ans)

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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if (A > B){
    if (C > D) cout << B + D << endl;
    else cout << B + C << endl;
  }
  else {
    if (C > D) cout << A + D << endl;
    else cout << A + C << endl;
  }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  rep(i, N){
    int x;
    cin >> x;
    if(K - x > x){
      ans += x*2;
    } else {
      ans += (K-x)*2;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  int a, b; readV(a, b);
  string s; readV(s);

  foreach (i, c; s) {
    if (i == a) {
      if (c != '-') {
        writeln("No");
        return;
      }
    } else {
      if (c < '0' || c > '9') {
        writeln("No");
        return;
      }
    }
  }

  writeln("Yes");
}


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

using namespace std;

int main (int argc, char const* argv[])
{
    int n,c=0;
    vector<int> v;
    
    cin >> n;
    for (int i = 0; i < n; i += 1)
    {
        int _n;
        cin >> _n;
        v.push_back(_n);
    }
    
    for (int i = 0; i < v.size(); i += 1)
    {
        for (int j = v.size()-1; j > i; j -= 1)
        {
            if (v[j] < v[j-1])
            {
                int b = v[j];
                v[j] = v[j-1];
                v[j-1] = b;
                ++c;
            }
        }
    }
    
    for (vector<int>::iterator it = v.begin(); it != v.end(); ++it)
    {
        cout << *it;
        if(it != v.end()-1)
        	cout << " ";
    }
    cout << endl << c << endl;
    
    return 0;
}

Measured memory_bytes: 1216
#include<vector>

class BinaryTree{
private:
    static const int NIL = -1;
    struct Node{
        int parent, sibling, left, right, degree, depth, height;
        Node(){parent = sibling = left = right = depth = height = NIL; degree = 0;}
    };
    std::vector<Node> T;
    int root;
    int N = T.size();    
public:
    BinaryTree(int N):T(N){root = NIL;}
    void addNode(int p, int l, int r){
        T[p].left = l;
        T[p].right = r;
        T[l].parent = T[r].parent = p;
    }
    void makeTree(){
        setRoot();
        setDepth(root, 0);
        setHeight(root);
        setSibling();
    }
    int getDegree(int v){
        return T[v].degree;
    }
    int getDepth(int v){
        return T[v].depth;
    }
    int getHeight(int v){
        return T[v].height;
    }
    int getParent(int v){
        return T[v].parent;
    }
    std::vector<int> getChildren(int v){
        std::vector<int> c;
        for(int i=T[v].left;i!=NIL;i=T[i].right) c.push_back(i);
        return c;
    }
    int getSibling(int v){
        return T[v].sibling;
    }
    int getType(int v){
        if(T[v].parent == NIL) return NIL;
        if(T[v].left == NIL && T[v].right == NIL) return 1;
        else return 0;
    }
private:
    void setRoot(){
        for(int i=0;i<N;++i)
            if(T[i].parent == NIL) root = i;
    }
    void setDepth(int v, int d){
        if(v == NIL) return;
        T[v].depth = d;
        setDepth(T[v].right, d+1);
        setDepth(T[v].left, d+1);
    }
    int setHeight(int v){
        int h1 = 0, h2 = 0;
        if(T[v].left != NIL) h1 = setHeight(T[v].left) + 1;
        if(T[v].right != NIL) h2 = setHeight(T[v].right) + 1;
        return T[v].height = std::max(h1, h2);
    }
    void setSibling(){
        for(int i=0;i<N;++i){
            if(T[i].parent == NIL) continue;
            if(T[T[i].parent].left != i && T[T[i].parent].left != NIL) T[i].sibling = T[T[i].parent].left;
            else if(T[T[i].parent].right != i && T[T[i].parent].right !=NIL) T[i].sibling = T[T[i].parent].right;
            ++T[T[i].parent].degree;
        }
    }
};
#include<iostream>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    BinaryTree T(n);
    for(int i=0;i<n;++i){
        int id, left, right;
        cin>>id>>left>>right;
        T.addNode(id, left, right);
    }
    T.makeTree();
    for(int i=0;i<n;++i){
        cout<<"node "<<i<<": parent = "<<T.getParent(i)<<", sibling = "<<T.getSibling(i)<<", degree = "<<T.getDegree(i)<<", depth = "<<T.getDepth(i)<<", height = "<<T.getHeight(i)<<", "<<(T.getType(i)?~T.getType(i)?"leaf":"root":"internal node")<<endl;
    }
}

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

int main() {
  string s;
  cin >> s;
  int n = stoi(s);
  bool a = false; //前２桁が西暦としてありえるか
  bool b = false; //後２桁が西暦としてありえるか
  bool c = false; //前２桁が月としてありえるか
  bool d = false; //後２桁が月としてありえるか
  for(int i = 0; i <= 99; i++) {
    if(n/100 == i) a = true;
    if(n%100 == i) b = true;
  }
  for(int i = 1; i <= 12; i++) {
    if(n/100 == i) c = true;
    if(n%100 == i) d = true;
  }
  if((a && d) && !(b && c)) cout << "YYMM" << endl;
  else if(!(a && d) && (b && c)) cout << "MMYY" << endl;
  else if(a && d && b && c) cout << "AMBIGUOUS" << endl;
  else cout << "NA" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int[] p = new int[A];
		int[] q = new int[B];
		int[] r = new int[C];
		for(int i=0; i<A; i++)
			p[i] = sc.nextInt();
		for(int i=0; i<B; i++)
			q[i] = sc.nextInt();
		for(int i=0; i<C; i++)
			r[i] = sc.nextInt();
		
		Arrays.sort(p);
		Arrays.sort(q);
		Arrays.sort(r);
		
		ArrayList<Integer> cand = new ArrayList<>();
		for(int i=0; i<X; i++)
			cand.add(p[A-1-i]);
		for(int i=0; i<Y; i++)
			cand.add(q[B-1-i]);
		for(int i=0; i<C; i++)
			cand.add(r[i]);
		Collections.sort(cand);
		
		long ans = 0;
		for(int i=0; i<X+Y; i++)
			ans += cand.get(X+Y+C-1-i);
		
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 96940
#include<iostream>
#include<string>
#include<algorithm>


using namespace std;

int main()
{
	long long a, b, x;
	long long count = 0;
	cin >> a >> b >> x;

	if (a == 0) {
		count = (b / x + 1);
	}else{
		count = (b/x+1) - ((a-1)/x+1);
	}
    cout << count << endl; 
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j,v;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  trace(A, n);
  for(i = 2;i <= n;i++) {
    v = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }
    trace(A,n);
  }
  
  return 0;
}

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

long check(long number){
  if(number>10000000000)number%=1000000007;
  return number;
}

int main(){
  int n;
  std::cin >> n;
  long ans=1;
  for (int i = 1; i <= n; i++) {
    ans*=i;
    ans=check(ans);
  }

  std::cout << ans << '\n';

return 0;
}


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

int calc(int a){
	if(a==1){return 0;}
	if(a==2){return 1;}

	int x=sqrt((double)a);
	for(int i=2;i<(x+1);i++){
		if((a%i)==0){
			return 0;
		}
	}
	return 1;
}

int main(){
    int n,a;
	int count=0;

	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a);
		count+=calc(a);
	}
	printf("%d\n",count);
	
	return 0;
}


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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))



def main():
    mod=10**9+7
    N=I()
    S=input()
    Q=I()
    
    #####segfunc######

    #評価関数
    def segfunc(x,y):
        return x|y


    #初期化
    def init(init_val):
        #init_valは操作する数列
        for i in range(N):
            seg[i+num-1]=set([ord(init_val[i])])    
        #built
        for i in range(num-2,-1,-1) :
            seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
            

    #k番目の値をxに更新
    def update(k,x):
        k += num-1
        seg[k] = x
        while k:
            k = (k-1)//2
            seg[k] = segfunc(seg[k*2+1],seg[k*2+2])

            
    #[p,q)の区間に対するクエリへの応答
    def query(p,q):
        if q<=p:
            return ide_ele
        p += num-1
        q += num-2
        res=ide_ele
        while q-p>1:
            if p&1 == 0:
                res = segfunc(res,seg[p])
            if q&1 == 1:
                res = segfunc(res,seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = segfunc(res,seg[p])
        else:
            res = segfunc(segfunc(res,seg[p]),seg[q])
        return len(res)


    #####単位元######
    ide_ele = set([])

     #num:n以上の最小の2のべき乗
    num =2**(N-1).bit_length()
    seg=[ide_ele]*2*num
    init(S)



    
    for i in range(Q):
        q,a,b=input().split()
        if q=="1":
            update(int(a)-1,set([ord(b)]))
        else:
            print(query(int(a)-1,int(b)))
            
    
    

main()


Measured memory_bytes: 473640
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 998244353

class CmbMod:
    def __init__(self, n, p):
        """
        二項係数nCr(n個の区別できるものからr個のものを選ぶ組み合わせの数)をpで割った余りを求める
        """
        self.n = n
        self.p = p
        self.fact = [1, 1]
        self.factinv = [1, 1]
        self.inv = [0, 1]

    def cmb_mod(self, n, r):
        """
        二項係数nCr(mod p)をO(r)にて計算。nが大きいがrは小さい時に使用。
        """
        numer, denom = 1, 1
        for i in range(r):
            numer = (numer * (n - i)) % self.p
            denom = (denom * (i + 1)) % self.p
        return (numer * pow(denom, self.p - 2, self.p)) % self.p

    def prep(self):
        """
        二項係数nCr(mod p)をO(1)で求める為の前処理をO(N)にて実行。
        """
        for i in range(2, self.n + 1):
            self.fact.append((self.fact[-1] * i) % self.p)
            self.inv.append((-self.inv[self.p % i] * (self.p // i)) % self.p)
            self.factinv.append((self.factinv[-1] * self.inv[-1]) % self.p)

    def cmb_mod_with_prep(self, n, r):
        """
        二項係数nCr(mod p)をO(1)で求める。事前にprepを実行する事。
        """
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return self.fact[n] * self.factinv[r] * self.factinv[n - r] % self.p


def resolve():
    n, m, k = map(int, input().split())
    cmb = CmbMod(n, mod)
    cmb.prep()

    res = 0
    for i in range(k + 1):
        res += (m * pow(m - 1, n - (i + 1), mod) * cmb.cmb_mod_with_prep(n - 1, i)) % mod
        res %= mod
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 33068
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
int main(int argc, const char * argv[]) {



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

    int n;
    cin>>n;
    int l[n];
    rep(i,n)cin>>l[i];
    sort(l,l+n);
    int cnt=0;
    rep(i,n){
        for(int j=i;j<n;j++){
            for(int k=j;k<n;k++){
                if((l[i]!=l[j]&&l[j]!=l[k]&&l[j]!=l[k])&&l[k]<l[i]+l[j]){
                    cnt++;
                }
            }
        }
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0;i < n;i++){
		cin >> a[i];
		a[i] -= i + 1;
	}

	sort(a.begin(),a.end());

	int mid = a[n/2];

	ll ans = 0;
	for(int i = 0;i < n;i++){
		ans += abs(a[i] - mid);
	}

	cout << ans << endl;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int m = ri(), n = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri() - 1;
	
	if (m <= 4) {
		int dp[n][m];
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) dp[i][j] = 1000000000;
		for (int i = 0; i < m; i++) dp[0][i] = i == a[0] ? 0 : 1;
		for (int i = 0; i + 1 < n; i++) {
			for (int j = 0; j < m; j++) {
				for (int k = 0; k < m; k++) {
					if (j == k) continue;
					int cost = k == a[i + 1] ? 0 : 1;
					dp[i + 1][k] = std::min(dp[i + 1][k], dp[i][j] + cost);
				}
			}
		}
		std::cout << *std::min_element(dp[n - 1], dp[n - 1] + m) << std::endl;
	} else {
		int res = 0;
		for (int i = 0; i + 1 < n; i++) {
			if (a[i] == a[i + 1]) a[i + 1] = 1000000001, res++;
		}
		std::cout << res << std::endl;
	}
	return 0;
}




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

typedef long long ll;

struct LazySegment
{
	vector<ll> node;
	vector<ll> lazy;
	vector<bool> lazyFlag;
	ll n;


	ll init = (1LL << 31) - 1;

	LazySegment(const vector<ll>& vec)
	{
		int sz = vec.size();

		n = 1;
		while(n < sz) n <<= 1;

		node.resize(2 * n - 1);
		lazy.resize(2 * n - 1,init);
		lazyFlag.resize(2 * n - 1,false);

		for(int i = 0;i < sz;i++)
		{
			node[n - 1 + i] = vec[i];
		}

		for(int i = n - 2;i >= 0;i--)
		{
			node[i] = min(node[2 * i + 1] , node[2 * i + 2]); 
		}
	}

	void eval(int k,int l,int r)
	{
		if(lazyFlag[k])
		{
			node[k] = lazy[k];

			if(r - l > 1)
			{
				lazy[2 * k + 1] = lazy[k];
				lazy[2 * k + 2] = lazy[k];
				lazyFlag[2 * k + 1] = true;
				lazyFlag[2 * k + 2] = true;
			}

			lazy[k] = 0;
			lazyFlag[k] = false;
		}
	}

	void add_inter(int a,int b,ll x,int k = 0,int l = 0,int r = -1)
	{
		if(r < 0) r = n;

		eval(k,l,r);

		if(b <= l || r <= a) return ;

		if(a <= l && r <= b)
		{
			lazy[k] = x;
			lazyFlag[k] = true;
			eval(k,l,r);
		}

		else
		{
			add_inter(a,b,x,2 * k + 1,l,(l + r) / 2);
			add_inter(a,b,x,2 * k + 2,(l + r) / 2,r);
			node[k] = min(node[2 * k + 1] , node[2* k + 2]);
		}
	}

	ll get_inter(int a,int b,int k = 0,int l = 0,int r = -1)
	{
		if(r < 0) r = n;

		eval(k,l,r);
		if(b <= l || r <= a) return init;

		if(a <= l && r <= b) return node[k];

		ll lv = get_inter(a,b,k * 2 + 1,l , (l + r) / 2);
		ll rv = get_inter(a,b,k * 2 + 2,(l + r) / 2 , r);

		return min(lv , rv);
	}
};

signed main()
{
	int n;
	int q;
	cin >> n >> q;
	LazySegment seg(vector<ll>(n,(1LL << 31) - 1));

	for(int i = 0;i < q;i++)
	{
		int t;
		cin >> t;
		if(t == 0)
		{
			int a,b;
			ll x;
			cin >> a >> b >> x;
			seg.add_inter(a,b + 1,x);
		}
		else
		{
			int a,b;
			cin >> a >> b;

			cout << seg.get_inter(a,b + 1) << endl;
		}
	}

	return 0;
}



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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,n) FOR(i,0,n)
#define REPD(i,n) FOR(i,n-1,0)
#define PB push_back
#define mod 1000000007


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    double l;
    cin>>l;
    double ans=l/3.0;
    double vol=ans*ans*ans*1.0;
    printf("%lf",vol);
    return 0;   
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define fo(i,n) for(long long i=0;i<n;i++)
#define ll long long int
#define inf 999999999999999999
#define pb push_back
#define MOD 1000000007
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
//freopen("explicit.in", "r", stdin);
//freopen("explicit.out", "w", stdout);
 
void SieveOfEratosthenes() 
{ 
    bool prime[10000001];
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=10000000; p++) 
    { 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (ll i=p*p; i<=10000000; i += p) {
                prime[i] = false; 
            }
        } 
    }  
} 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
	if(b%a==0)
	   return a;
	return gcd(b%a,a);
}
ll nCrModpDP(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C));   
    C[0] = 1;
    for (ll i = 1; i <= n; i++) 
    {
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
ll nCrModp(ll n, ll r, ll p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
   ll ni = n%p, ri = r%p; 
  
   return (nCrModp(n/p, r/p, p) * 
           nCrModpDP(ni, ri, p)) % p; 
} 
int32_t main() 
{
    fio
	ll j,i,n,t,l,r,c,h,k,m,maxi,d,x;
	cin>>n;
	ll a[n+1];
	c=0;
	for(j=1;j<=n;j++)
	{
		cin>>a[j];
		if(j%2==1 && a[j]%2==1)
			c++;
	}
	cout<<c<<endl;
}



	

		

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
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; }

int main(){
  int n,k;
  cin >> n >> k;
  vi a(n);
  rep(i,n) cin >> a[i];
  sort(all(a));
  int sum = 0;
  rep(i,k) sum += a[i];
  cout << sum << endl;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main {
	private static int[] ans;
  	private static int n;
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	n = sc.nextInt();
    	int m = sc.nextInt();

    	ans = new int[n];
    	for (int i = 0; i < n; i++) {
    		ans[i]=-1;
    	}
    	for (int i = 0; i < m; i++) {
	    	int s = sc.nextInt();
	    	int c = sc.nextInt();

    		if (!aaa(s,c)) {
    			System.out.println(-1);
    			return;
    		} 
    	}
    	if (check()) {

    	} else {
			System.out.println(-1);
			return;
    	}
    }
    private static boolean check() {
    	if (ans[0]==0 && n!=1) {
    		return false;
    	}
    	for (int i=0;i< ans.length; i++) {
    		if (ans[i]==-1){
    			if(i==0 && n!=1){
    		System.out.print(1);
}else{
    		System.out.print(0);
}
    		}else{
    		System.out.print(ans[i]);
    	}
    	}
		return true;
    }
    private static boolean aaa(int s, int c) {
    	if (s > n) {
    		return false;
    	}
    	if (ans[s-1]!=-1 && ans[s-1]!=c ) {
    		return false;
    	}
    	ans[s-1]=c;
    	return true;
    }
}





Measured memory_bytes: 22868
import java.util.*;
import java.util.Arrays;
import java.util.Collections;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
    int k = sc.nextInt();
    LinkedList<Integer> h = new LinkedList<Integer>();
    for(int i = 0; i < n; i++){
      h.add(sc.nextInt());
    }
    Collections.sort(h,  Collections.reverseOrder());
    //char[] a = sc.nextLine().toCharArray();
    for(int i = 0; i < k; i++){
      h.poll();
    }
    double sum = 0;
    for(int i = 0; i < n-k; i++){
      sum += h.poll();
    }
    System.out.println(String.format("%.0f", sum));
  }
}

Measured memory_bytes: 98856
#include<bits/stdc++.h>
 
 
using namespace std;
 
char c='\0';

int main(){
	for(int i=1;c!='\n';i++){
		scanf("%c",&c);
		if(c=='L'){
			if(i%2!=0){
				printf("No");
				return 0;
			}
		}
		if(c=='R'){
			if(i%2!=1){
				printf("No");
				return 0;
			}
		}
	}
	printf("Yes");
}

Measured memory_bytes: 256
INF=10**18
N,K,C=map(int,input().split())
S=input()
left=[0]*N
right=[0]*N
l=-INF
for i in range(N):
    if S[i]=='o':
        if l==-INF:
            left[i]=1
            l=i+C
        elif l<i:
            left[i]=max(left[i],left[i-C-1]+1)
            l=i+C
        else:
            left[i]=left[i-1]
    else:
        left[i]=left[i-1]
r=INF
for i in reversed(range(N)):
    if S[i]=='o':
        if r==INF:
            right[i]=1
            r=i
        elif i<r-C:
            right[i]=max(right[i],right[i+C+1]+1)
            r=i
        else:
            right[i]=right[(i+1)%N]
    else:
        right[i]=right[(i+1)%N]

for i in range(N):
    lsum=left[i-1] if i-1>=0 else 0
    rsum=right[i+1] if i+1<N else 0
    if lsum+rsum<K:
        print(i+1)

Measured memory_bytes: 25132