akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<ctime>
#include<algorithm>
#include<iomanip>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
#include<set>
#include<map>
using namespace std;
#define MAXN 200010
#define MAXM 1010
#define eps 1e-8
#define ll long long
#define MOD 1000000007
#define INF 1000000000
#define lb(x) x&-x
int n,k;
ll a[MAXN];
ll tls[MAXN],tln,mx;
map<ll,int>h;
int c[MAXN];
ll ans;
void change(int x){
	for(;x<=mx;x+=lb(x)){
		c[x]++;
	}
}
int ask(int x){
	int re=0;
	for(;x;x-=lb(x)){
		re+=c[x];
	}
	return re;
}
int main(){
	int i;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		a[i]-=k;
		a[i]+=a[i-1];
		tls[++tln]=a[i];
	}
	
	tls[++tln]=0;
	sort(tls+1,tls+tln+1);
	for(i=1;i<=tln;i++){
		if(i==1||tls[i]!=tls[i-1]){
			h[tls[i]]=++mx;
		}
	}
	change(h[0]);
	for(i=1;i<=n;i++){
		int t=h[a[i]];
		ans+=ask(t);
		change(t);
	}
	printf("%lld\n",ans);
	return 0;
}

/*

*/


Measured memory_bytes: 16640
#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 x;
    cin>>x;
    for(int i=-1000; i<=1000; ++i){
        for(int j=-1000; j<=1000; ++j){
            if((ll)i*i*i*i*i-(ll)j*j*j*j*j==x){
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3612
#include<iostream>
#define MOD 1000000007

inline int to_mod(long long n) {
	return n >= 0 ? n % MOD : MOD + n % MOD;
}

inline int madd(int a, int b) {
	return (a + b) % MOD;
}

inline int msub(int a, int b) {
	int t = a - b;
	return t >= 0 ? t : MOD + t;
}

inline int mmul(int a, int b) {
	return (int)((long long)a * b % MOD);
}

inline int mpow(int a, int b) {
	int r = 1;
	for(; b != 0; b >>= 1) {
		if (b & 1) r = mmul(r, a);
		a = mmul(a, a);
	}
	return r;
}

inline int minv(int a) {
	return mpow(a, MOD - 2);
}

inline int mdiv(int a, int b) {
	return mmul(a, minv(b));
}


inline int mfact(int n) {
	int r = 1;
	for(; n > 0; n--) {
		r = mmul(r, n);
	}
	return r;
}

inline int mperm(int n, int m) {
	int r = 1;
	for(; m > 0; m--) {
		r = mmul(r, m);
		n--;
	}
	return r;
}

inline int mcomb(int n, int m) {
	int rn = 1, rm = 1;
	while(m > 0) {
		rn = mmul(rn, n);
		rm = mmul(rm, m);
		n--;
		m--;
	}
	return mdiv(rn, rm);
}
using namespace std;

int main() {
	long long n, a, b;
	cin >> n >> a >> b;
	long long r = mpow(2, n) - 1 - mcomb(n, a) - mcomb(n, b);
	cout << to_mod(r) << endl;
}






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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    int n,x,y;
    cin>>n>>x>>y;
    x--;
    y--;

    VVI d(n);
    REP(i,n){
        d[i].resize(n);
    }
    d[x][y] = 1;

    REP(i,n-1){
        d[i][i+1] = 1;
    }

    FOR(i,x,y){
        d[i][y] = min(y-i,i-x+1);
        d[x][i] = min(i-x,y-i+1);
    }
    FOR(i,x,y){
        FOR(j,i+1,y){
            d[i][j] = min(j-i,i-x+y-j+1);
        }
    }

    for(int i=n-1;i>=0;i--){
        for(int j=i+2;j<n;j++){
            if(d[i][j] != 0){
                continue;
            }
            d[i][j] = min(d[i][j-1],d[i+1][j]) + 1;
        }
    }

    VI result(n);

    FOR(i,0,n){
        FOR(j,i+1,n){
            result[d[i][j]]++;
        }
    }

    FOR(i,1,n){
        cout<<result[i]<<endl;

    }
    
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 16000
import java.io.*;
import java.util.*;
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */
public class Main
{
	static final long mod=1000000007;
	static final double eps=1e-8;
	static final boolean debug=false;
	static Reader in=new Reader();
	public static void main(String[] args) throws IOException
	{
		int a=ni(),b=ni(),c=ni();
		if(a+b>=c)
			pr("Yes");
		else
			pr("No");
		System.out.println(ans);
	}
	static StringBuilder ans=new StringBuilder();
	static long powm(long a, long b, long m)
	{
		long an=1;
		long c=a;
		while(b>0)
		{
			if(b%2==1)
				an=(an*c)%m;
			c=(c*c)%m;
			b>>=1;
		}
		return an;
	}
	static void pd(){if(debug)ans.append("hola");}
	static void pd(Object a){if(debug)ans.append(a+"\n");}
	static void pr(Object a){ans.append(a+"\n");}
	static void pr(){ans.append("\n");}
	static void p(Object a){ans.append(a);}
	static int ni(){return in.nextInt();}
	static long nl(){return in.nextLong();}
	static String ns(){return in.next();}
	static double nd(){return in.nextDouble();}
	static String pr(String a, long b)
	{
		String c="";
		while(b>0)
		{
			if(b%2==1)
				c=c.concat(a);
			a=a.concat(a);
			b>>=1;
		}
		return c;
	}
	static class Reader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public Reader() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
    }
}

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

int main(void) {
  string s;
  cin >> s;
  if(s=="SUN") cout << '7' << '\n';
  if(s=="MON") cout << '6' << '\n';
  if(s=="TUE") cout << '5' << '\n';
  if(s=="WED") cout << '4' << '\n';
  if(s=="THU") cout << '3' << '\n';
  if(s=="FRI") cout << '2' << '\n';
  if(s=="SAT") cout << '1' << '\n';
  return 0;
}

Measured memory_bytes: 3568
import java.util.*;
import java.io.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        String S = sc.next();

        int price = 700;
        for (int i = 0; i < S.length(); i++) {
            if (S.charAt(i) == 'o') {
                price += 100;
            }
        }
        out.printf("%d\n", price);
        out.flush();
    }
}

Measured memory_bytes: 21332
int printf(const char * restrict, ...) __attribute__((__format__ (__printf__, 1, 2)));
int scanf(const char * restrict format, ...);

int main(void){
    int a,b;
    scanf("%d%d",&a,&b);
    if (a*b%2==0){
        printf("No\n");
    } else {
        printf("Yes\n");
    }
    return 0 ;
}

Measured memory_bytes: 128
import fractions


def lcm(x, y):
    aaa = (x * y) // fractions.gcd(x, y)
    return aaa


A, B, C, D = map(int, input().split())

AtoB = (B - (A - 1))

divisible_C = (B // C) - ((A - 1) // C)
divisible_D = (B // D) - ((A - 1) // D)

minLcm = lcm(C, D)

divisible_CD = (B // minLcm) - ((A - 1) // minLcm)

divisible_CtoD = (divisible_C + divisible_D) - divisible_CD

answer = AtoB - divisible_CtoD

print(answer)

Measured memory_bytes: 5048
from collections import defaultdict

n = int(input())
alst = list(map(int, input().split()))
dd = defaultdict(int)

for i, num in enumerate(alst, start = 1):
    s = str(min(i, num)) + "-" + str(max(i, num))
    dd[s] += 1

ans = 0
for i, j in dd.items():
    if j == 2:
        ans += 1
print(ans)

Measured memory_bytes: 27408
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数


template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*///map < string, ll> s;

/*if (N % 2 != 0)a = N / 2;
else a = N / 2 - 1;
for (int i = 1;i <= a;i++) {
	for (int j = 0;j < N - (i * 2);j++) {
		if (S[j] != S[j + i] && S[j + i * 2] != S[j] && S[j + i] != S[j + i * 2]) sum--;
		if (sum == 0)break;
	}
}*/

int main() {
	string s, t;cin >> s >> t;
	ll mins = 999999;
	ll mint = 999999;
	vector<ll>ls(s.size()), lt(t.size());
	for (int i = 0;i < s.size();i++) {
		ll a = s[i] - 'A';
		ls[i] = a;
	}
	sort(all(ls));
	for (int i = 0;i < t.size();i++) {
		ll a = t[i] - 'A';
		lt[i] = a;
	}
	sort(all(lt),greater<ll>());
	ll l;
	if (s.size() >= t.size()) l = t.size();
	else l= s.size();
	bool ok = true;
	for (int i = 0;i < l;i++) {
		if (ls[i] < lt[i]) break;
		if (ls[i] > lt[i]) {
			ok = false;break;
		}
		if (i == l - 1) {
			if (s.size() < t.size())break;
			else ok = false;
		}
	}
	if (ok)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	LL N, A, B; cin >> N >> A >> B;
	LL q = N / (A+B);
	LL r = N % (A+B);
	LL ans = A*q;
	if(r != 0){
		ans += min(r, A);
	}
	printf("%lld\n", ans);
	return 0;
}

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

int n, l[20], r[20];
long long a[20], ans = 1LL << 60;

void go(int sz, int last)
{
  if (sz == 2)
  {
    ans = min(ans, a[r[0]] + a[r[r[0]]]);
    return;
  }

  int cnt = 0, id = r[0];
  for (int i = 2; i < sz; i++)
  {
    id = r[id];
    if (i >= last)
    {
      a[l[id]] += a[id];
      a[r[id]] += a[id];
      int oldLR = l[r[id]], oldRL = r[l[id]];
      l[r[id]] = l[id];
      r[l[id]] = r[id];
      go(sz - 1, max(2, i - 1));
      a[l[id]] -= a[id];
      a[r[id]] -= a[id];
      l[r[id]] = oldLR;
      r[l[id]] = oldRL;
    }
  }
}

int main()
{
  cin >> n;
  for (int i = 1; i <= n; i++)
  {
    cin >> a[i];
    l[i] = i - 1;
    r[i] = i + 1;
  }
  r[0] = 1;
  l[n + 1] = n;
  go(n, 2);
  cout << ans << endl;
}


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

int dp[100001];
int fun(int *a, int i,  int n)
{
    if(i==n-1)
    {
        return 0;
    }
    if(i==n-2)
    {
        return abs(a[i]-a[i+1]);
    }
    if(dp[i]!=-1)
    {
        return dp[i];
    }
    dp[i]=min(abs(a[i]-a[i+1])+fun(a, i+1, n), abs(a[i]-a[i+2])+fun(a, i+2, n));
    return dp[i];
}
int main()
{
    int n;
    cin>>n;
    memset(dp, -1, sizeof(dp));
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    cout<<fun(a, 0, n)<<endl;
return 0;

}



Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define ll long long
#define l long
#define all(x) x.begin(),x.end()
#define pb push_back
#define len(x) x.len
int main()
{ int n;int k;
cin>>n>>k;
ll a[n];
FOR(i,n)cin>>a[i];
sort(a,a+n);
ll sum=0;
FOR(i,k){sum+=a[i];}
cout<<sum;



return 0;
    
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
	ll n;
	cin >> n;
	vector<string>s(n);
    rep(i,n)cin>>s[i];
	sort(s.begin(), s.end());
	ll cnt = 1;
	rep(i, n - 1) {
		if (s[i] != s[i + 1]) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 9576
#include <stdio.h>

    
    int l[7];
    void dice(int num){
    l[0] = l[1];
    l[1] = l[num];
    l[num] = l[6];
    l[6] = l[7-num];
    l[7-num] = l[0];
}
 
int main(void){
    int n,u,f;
    for(int i=0; i<6; i++) scanf("%d", &l[i+1]);
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d%d", &u, &f);
        if(f==l[3] || f==l[4]) dice(4);
        while(f!=l[2]) dice(2);
        while(u!=l[1]) dice(4);
        printf("%d\n", l[3]);
    }
    return 0;
}




Measured memory_bytes: 2040
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];


int main () {
    int N, K;
    cin >> N >> K;

    vector<int>H(N);
    rep(i,N)cin >> H[i];

    sort(H.begin(),H.end(),greater<int>());

    rep(i,min(N,K))H[i]=0;
    long long ans=0;
    rep(i,N)ans += H[i];

    cout << ans << endl;

}

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

int main()
{
    double a,b,c,d,e,f;
    
    while(cin>>a>>b>>c>>d>>e>>f){
    
        double x=(e*c-b*f)/(e*a-b*d);
        double y=(d*c-a*f)/(d*b-a*e);
    
        printf("%.3f %.3f\n",x+0.0,y+0.0);
    }
    
    return 0;
    
}

Measured memory_bytes: 1236
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const inputList = input.split('/'); // 空白文字に注意
// const inputNumberList = inputList.map(Number);

// const input = require('fs').readFileSync('/dev/stdin', 'utf8');
// const inputList = input.split('\n');
// const inputNumberList = inputList.map(Number);

const month_str = inputList[1];
let month;

if (month_str[0] === '0') {
  month = Number(month_str[1]);
} else {
  month = Number(month_str);
}

if (month > 4) {
  console.log('TBD');
} else {
  console.log('Heisei');
}

Measured memory_bytes: 7372
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[][] a = new int[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                a[i][j] = scanner.nextInt();
            }
        }
        Collection<Collection<Integer>> lines = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            ArrayList<Integer> row = new ArrayList<>();
            row.add(a[i][0]); row.add(a[i][1]); row.add(a[i][2]);
            lines.add(row);
            ArrayList<Integer> col = new ArrayList<>();
            col.add(a[0][i]); col.add(a[1][i]); col.add(a[2][i]);
            lines.add(col);
        }
        ArrayList<Integer> diag1 = new ArrayList<>();
        diag1.add(a[0][0]); diag1.add(a[1][1]); diag1.add(a[2][2]);
        lines.add(diag1);
        ArrayList<Integer> diag2 = new ArrayList<>();
        diag2.add(a[2][0]); diag2.add(a[1][1]); diag2.add(a[0][2]);
        lines.add(diag2);

        boolean[][] b = new boolean[3][3];
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            int c = scanner.nextInt();
            for (Collection<Integer> line : lines) {
                line.remove(c);
                if(line.isEmpty()){
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}

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

#define ll long long int
#define ff(i,a,b) for(ll i = a; i < b; i++)
#define bf(i,b,a) for(ll i = b-1; i >= 0; i--)
#define itf(i,a) for(auto i = a.begin(); i != a.end(); i++)
#define MII map<int,int> 
#define MCI map<char,int>
#define MSI map<string,int>
#define VI vector<int> 
#define VC vector<char> 
#define VS vector<string> 
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define tc ll t; cin>>t; while(t--)
#define DISPV(v) itf(i,v) cout << *i << ' ';
#define DISPM(m) itf(i,m) cout << i->F << ' ' << i->S << endl;

const int MOD = int(1e9) + 7;

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    ll sum = 0;
    if(k <=a)
        sum = k;
    else
    {
        sum += a;
        k -= a;
        if(k <= b)
            sum += 0;
        else
        {
            // sum += b;
            k -= b;
            sum -= min(k,c);
        }        
    }
    cout << sum << '\n';
}   

Measured memory_bytes: 3660
N, M = map(int, input().split())
PY = [[int(i) for i in input().split()] for _ in range(M)]

iPY = []
for i, (P, Y) in enumerate(PY) :
    iPY.append((i, P, Y))
iPY.sort(key=lambda x: x[2])

ret = [0] * M
counter = [0] * N
for i, P, _ in iPY :
    counter[P-1] += 1
    ret[i] = '{:06d}'.format(P) + '{:06d}'.format(counter[P-1])

for i in range(M) :
    print(ret[i])

Measured memory_bytes: 92888
//clang 3.8.0

#include <iostream>
using namespace std;
#define		endl		"\n"
#define		ll			long long int
#define		mod			1000000007
#define		f(i,a,b)	for(ll i = (ll)(a); i < (ll)(b); i++)
#define		rf(i,a,b)   for(ll i = (ll)(a); i > (ll)(b); i--)
#define		ull			unsigned long long
#define		ld			long double


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

    if (a == b)
        return a;

    if (a > b)
        return gcd(a - b, b);
    return gcd(a, b - a);
}
int main()
{
    ll n;
    cin >> n;
    ll sum = 0;
    ll rec[201][201];
    for (ll i = 0; i < 201; i++)
    {
        for (ll j = 0; j < 201; j++)
        {
            rec[i][j] = -1;
        }
    }
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = 1; j <= n; j++)
        {
            for (ll k = 1; k <= n; k++)
            {
                ll hcf;
                if (rec[i][j] != -1)
                    hcf = rec[i][j];
                else
                {
                    hcf = gcd(i, j);
                    rec[i][j] = hcf;
                }
                if (rec[hcf][k] != -1)
                    hcf = rec[hcf][k];
                else
                {
                    hcf = gcd(hcf, k);
                    rec[hcf][k] = hcf;
                }
                sum += hcf;
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3512
#include <utility>
#include <stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define YES(b) std::cout<< (b ? "YES" : "NO")
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, sum = 0;
	cin >> n;
	REP(i, n) {
		sum += i + 1;
	}
	cout << sum;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 1000000000;
const double PI = acos(-1);
const int mod = 1000000007;


int main()
{
    int n;
    cin >> n;
    
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        double price = (double)(i) * 1.08;
        if ((int)(price) == n) ans = i;
    }
    if (ans == 0) cout << ":(" << endl;
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main(void) {
  int N;
  vector<int> a;
  long ans;

    cin >> N;
    long count = 1;
    int tmp;
    for (int i = 0; i < N; ++i) {
        cin >> tmp;
        if (tmp == count) {
            count++;
        }
    }

    if (count == 1) {
        ans = -1;
    }
    else {
        ans = N - count + 1;
    }
    
  cout << ans << endl;
  
  return 0;
}   

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(usize, usize); m],
    }
    let mut forest = UnionFind::new(n);
    for (a, b) in ab {
        forest.union(a.min(b) - 1, a.max(b) - 1);
    }
    println!(
        "{}",
        (0..n)
            .filter(|&i| forest.is_root(i))
            .map(|i| forest.size[i])
            .max()
            .unwrap_or(0)
    );
}

struct UnionFind {
    parents: Vec<usize>,
    size: Vec<usize>,
}
impl UnionFind {
    fn new(n: usize) -> Self {
        UnionFind {
            parents: (0..n).collect(),
            size: vec![1; n],
        }
    }

    fn union(&mut self, primary: usize, standby: usize) -> usize {
        let primary_root = self.find(primary);
        let standby_root = self.find(standby);
        if primary_root != standby_root {
            self.parents[standby_root] = primary_root;
            self.size[primary_root] += self.size[standby_root];
        }
        primary_root
    }

    fn find(&mut self, x: usize) -> usize {
        if self.is_root(x) {
            x
        } else {
            let root = self.find(self.parents[x]);
            self.parents[x] = root;
            root
        }
    }

    fn is_root(&self, x: usize) -> bool {
        self.parents[x] == x
    }
}


Measured memory_bytes: 10816
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int64 C(int64 n) {
  return n * (n + 1) / 2 % MOD;
}

int64 power_mod(int64 a, int n) {
  int64 ret = 1;
  for (; n; n >>= 1) {
    if (n & 1) ret = ret * a % MOD;
    a = a * a % MOD;
  }
  return ret;
}

const int K = 2e5 + 10;
int64 inv[K];

int main() {
  for (int i = 1; i < K; ++i) inv[i] = power_mod(i, MOD - 2);
  int64 n, m, k;
  scanf("%lld%lld%lld", &n, &m, &k);
  int64 ret = 1;
  for (int i = 0; i < k - 2; ++i) {
    ret = ret * (n * m - 2 - i) % MOD * inv[k - 2 - i] % MOD;
  }
  int64 X = 0, Y = 0;
  for (int i = 0; i < n; ++i) {
    int64 cur = C(i);
    // trace(i, C(i), C(n - i));
    X = (X + cur) % MOD;
  }
  for (int i = 0; i < m; ++i) {
    int64 cur = C(i);
    Y = (Y + cur) % MOD;
  }
  // trace(ret, X, Y);
  X = X * m % MOD * m % MOD;
  Y = Y * n % MOD * n % MOD;
  ret = ret * (X + Y) % MOD;
  printf("%lld\n", ret);
  return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vi a(n),b(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    vi S(2*n-1), T(n);
    rep(i,2*n-1) S[i] = a[i%n]^a[(i+1)%n];
    rep(i,n) T[i] = b[i]^b[(i+1)%n];
    // MP Table
    vi A(n+1); A[0]=-1;
    int j=-1;
    rep(i,n){
        while(j>-1 && T[i]!=T[j]) j = A[j];
        A[i+1] = ++j;
    }
    // Matching
    j=0;
    rep(i,2*n-1){
        while(j>-1 && S[i]!=T[j]) j = A[j];
        if (++j == n){
            int k = i-j+1;
            cout<<k<<" "<<(b[0]^a[k])<<"\n";
            j = A[j];
        }
    }
    return 0;
}


Measured memory_bytes: 8192
#include <stdio.h>


int main(void)
{
	int i = 0;
	int j = 0;

	for(i = 1; i <= 9; i++)
	{
		for(j = 1; j <= 9; j++)
		{
			printf("%dx%d=%d\n", i, j, i *j);
		}
	}

	return 0;

}

Measured memory_bytes: 520
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
ll n,k;

bool solve(long long  m,vector<ll> &w,vector<ll> &d){
	unsigned long long  c=0;
	for(int i=0;i<n;i++){
		if(m>w[i]){
			c += (m-w[i])/d[i]+(ll)1;
		}
		if(m==w[i]){
			c++;
		}
	}
	if(c>=k)return true;
	else return false;
}

ll binary_search(long long  x,vector<ll>&w,vector<ll>&d){
	ll ok,ng,mid;
	ok = x;
	ng = 0;
	while(abs(ok-ng)>1){
		ll mid = (ok+ng)/(ll)2;
		if(solve(mid,w,d)){
			ok = mid;
		}else{
			ng = mid;
		}
	}
	return ok;
}


int main(){
	cin >> n >> k;
	vector<ll> w(n),d(n);
	for(int i=0;i<n;i++){
		cin >> w[i] >> d[i];
	}
	long long p = 9223372000000000000;
	cout << binary_search(p,w,d) << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 110000
#define MOD 1000000007
typedef long long ll;
typedef pair<string,int> P;

bool is_prime[110000];
ll prime[1100000];

//n以下の素数の数を返す
//計算量は大体O(n)
ll sieve(ll n){
  ll count=0;
  for(int i=0;i<=n;i++) is_prime[i]=true;
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      prime[count++]=i;
      for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
    }
  }
  return count;
}
int main(){
  sieve(55555);
  int ans[100],count=0,N;
  cin>>N;
  for(int i=6;i<=55555;i+=5){
      if(is_prime[i]){
          ans[count++]=i;
      }
      if(count==N) break;
  }
  for(int i=0;i<N;i++){
      cout<<ans[i];
      if(i==N-1) cout<<" ";
      else cout<<endl;
  }

  cout<<endl;
}


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

int main() {
  int n;
  cin >> n;
  map<string, int> kind;
  for ( int i = 0; i < n; i++ ) {
    string s;
    cin >> s;
    kind[s]++;
  }
  int ans = 0;
  for ( auto m : kind ) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 19224
#include<iostream>
#include<string>
#include<set>
#include<utility>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>

using namespace std;

//グラフの表現
int main(){
	int n;
	int M[101][101] = {};
	cin >> n;

	for(int i=0; i<n; i++){
		int u, k;
		cin >> u >> k;
		for(int j=0; j<k; j++){
			int v;
			cin >> v;
			M[u-1][v-1] = 1;
		}
	}

	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			cout << M[i][j];
			if(j != n-1){
				cout << " ";
			}
			else{
				cout << endl;
			}
		}
	}

	return 0;
}



Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  bool c=false,f=false;
  for(int i=0;i<s.size();i++){
    if(s[i]=='C') c=true;
    if(c&&s[i]=='F') f=true;
  }
  if(c&&f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

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

  if(n==0){
    cout << 0 << endl;
    return 0;
  }

  vector<bool> out;
  out.clear();
  ll tmp = 1;
  while(n!=0){
    if(n%(abs(tmp)*2)!=0){
      out.push_back(1);
      n -= tmp;
    }
    else{
      out.push_back(0);
    }
    tmp *= -2;
  }

  for(int i=out.size()-1;i>=0;i--){
    cout << out[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=[]
l=[0]*n
ans=0
for i in range(n):
	a.append(int(input()))
	l[i]=[list(map(int,input().split())) for i in range(a[-1])]
for i in range(2**n):
	i=format(i,'b').zfill(n)
	c=[]
	for j in range(n):
		if i[j]=='1':
			c.append(j)
	for j in c:
		for k in l[j]:
			#print(k)
			if k[1]==1 and (k[0]-1 not in c):
				break
			elif k[1]==0 and (k[0]-1 in c):
				break
		else:
			continue
		break
	else:
		ans=max(ans,len(c))
print(ans)

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

string a;
long long int check[26] = {};

int main(){
	cin >> a;
	sort(a.begin(), a.end());
	for(int i = 0; i < a.size(); i++){
		check[ a[i]-'a' ]++;
	}
	// cout << a <<endl;
	long long int ans=0;
	for(int i = 0; i < 26; i++){
		long long int temp=0;
		for(int j = i+1; j < 26; j++){
			temp += check[j];
		}
		ans += temp*check[i];
	}
	cout << ans+1;
	return 0;
}

Measured memory_bytes: 640
H, W=map(int, input().split())
m=[[-1 for i in range(W+2)]]
mm=[[-1]+[0 for j in range(W)]+[-1] for i in range(H)]
m=m+mm+m
m[1][1]=1

counter0=0
for i in range(1, H+1):
  c=input()
  for j in range(1, W+1):
    if c[j-1]=='#':
      m[i][j]=-1
    else:
      counter0+=1
      
def f(math, kazu, h, w):
  cha=0
  for i in range(1, h+1):
    for j in range(1, w+1):
      if math[i][j]==kazu:
        if math[i-1][j]==0:
          math[i-1][j]=kazu+1
          cha=1
        if math[i+1][j]==0:
          math[i+1][j]=kazu+1
          cha=1
        if math[i][j-1]==0:
          math[i][j-1]=kazu+1
          cha=1
        if math[i][j+1]==0:
          math[i][j+1]=kazu+1
          cha=1
  return math, cha

cha=1
i=1
while cha==1:
  m, cha=f(m, i, H, W)
  i+=1
  
if m[H][W]==0:
  out=-1
else:
  out=counter0-m[H][W]
  
print(out)

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

using namespace std;
using ll = long long;

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

  string s;
  cin >> s;

  int len = s.size();
  int i = 0;
  reverse(s.begin(), s.end());
  // dream   maerd
  // dreamer remaerd
  // erase   esare
  // eraser  resare
  while (i < len) {
    if (s.substr(i, 5) == "maerd")
      i += 5;
    else if (s.substr(i, 7) == "remaerd")
      i += 7;
    else if (s.substr(i, 5) == "esare")
      i += 5;
    else if (s.substr(i, 6) == "resare")
      i += 6;
    else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;

  return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
    int main(){
    int N,M;cin>>N>>M;
    vector<int> v(N);
    int sum=0;
    for(int i=0;i<N;i++){
        cin>>v[i];
        sum+=v[i];
    }

    double j=1.0*sum/(4*M);
    int ans=0;
    for(int i=0;i<N;i++){
        if(v[i]>=j)ans++;

    }
    if(ans>=M)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    }










Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String lineLine = line + line;
        String word = sc.nextLine();
        if(lineLine.contains(word)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
    }
}


Measured memory_bytes: 26236
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

	char c[3][3];
	rep(i,3){
		rep(j,3){
			cin >> c[i][j];
		}
	}
	cout << c[0][0] << c[1][1] << c[2][2] << endl;
}

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

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 main(){

  ll k;
  string s;
  cin >> k >> s;
  if(s.size() <= k){
    cout << s << endl;
  }else{
    cout << s.substr(0,k) << "..." << endl;
  }

  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
using ll = long long; constexpr int inf = INT_MAX / 2; constexpr ll infl = 1LL << 60;
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; }

void _main() {
  int N;
  ll K;
  cin >> N >> K;
  vector<pair<int,int>> ab(N);
  rep(i, 0, N) cin >> ab[i].first >> ab[i].second;
  sort(all(ab));

  fore(x, ab) {
    K -= x.second;
    if (K < 1) {
      cout << x.first << endl;
      return;
    }
  }
}

Measured memory_bytes: 1024
#include <iostream>
    #include <string>
    #include <set>  
    #include <stack>
    #include <algorithm>
    #include <vector>
    #include <cmath>
    #include <queue>
    #include <deque>
    #include <cstring>
    #include <cstdio>
    #include <map>
    #include <numeric>
    #include <cassert>
    #include <iomanip>
    #include <sstream>
    #include <ctime>
    #include <bitset> 
using namespace std;
#define for1(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,maxn) for1(i,0,maxn)
#define ford(i,b,a) for(int i=(int)(b)-1;i>=a;--i)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii > piii;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define dprintf(...) printf(__VA_ARGS__)
const int maxn=110;
ll h[maxn];
ll ncnt;
int n;
vector<pii> dive;
ll qp(ll base,ll ind)
{
	ll ans=1;
	if(ind<0)cout<<"Wrong"<<endl;
	while(ind>0)
	{
		if(ind&1)ans=ans*base%mod;
		ind>>=1;
		base=base*base%mod;
	}
	return ans%mod;
}
ll f[maxn],g[maxn];
ll cal(int bg,int ed)
{
	f[bg]=qp(2,h[bg]-1);
	g[bg]=1;
	for1(i,bg,ed)
	{
	//	cout<<i<<" "<<f[i]<<" "<<g[i]<<endl;
	//	system("pause");
		if(h[i+1]>=h[i])
		{
			ll buf=qp(2,h[i+1]-h[i]);
			f[i+1]=(f[i]+g[i])%mod*buf%mod;
			g[i+1]=g[i]*2%mod;
		}
		else
		{
			ll rst=qp(2,h[i]-h[i+1])-1;
		//	cout<<rst<<endl;
			ll res=0;
			ll buf=1;
			f[i+1]=(f[i]+g[i])%mod;
			int cur=i;ll mx=h[i];ll pre=h[i];
			while(rst>0&&cur>bg)
			{
				cur--;
				if(h[cur]==pre)continue;
				if(h[cur]>pre)
				{
					buf=buf*qp(2,h[cur]-pre)%mod;
					pre=h[cur];
				//	cout<<cur<<" "<<buf<<endl;
				//	system("pause");
					continue;
				} 
				if(h[cur]<=h[i+1])
				{
					res+=rst*2%mod*g[cur]%mod*buf%mod;
					res%=mod;
			//		cout<<res<<endl;
					buf=0;rst=0;
					break;
				}
				pre=h[cur];
				if(h[cur]>=mx)continue;
			//	cout<<h[i]<<" "<<mx<<" "<<h[cur]<<endl;
				ll ok=qp(2,h[i]-h[cur])-qp(2,h[i]-mx);
				if(ok<0)ok=(ok+mod)%mod;
				res+=g[cur]*2*ok%mod*buf%mod;
				rst=((rst+mod)-ok)%mod;
			//	cout<<ok<<" "<<rst<<" "<<res<<endl;
			//	system("pause");
				mx=h[cur];
			}
		//	if(buf<0)cout<<"Error"<<endl;
			res=(res+rst*buf%mod)%mod;
			f[i+1]+=res;
			f[i+1]%=mod;
			g[i+1]=(res+g[i])*2%mod;
		//	cout<<res<<" "<<buf<<" "<<f[i+1]<<" "<<g[i+1]<<endl;
		}
	}
	return f[ed]%mod;
}
int main()
{
	scanf("%d",&n);
	rep(i,n)scanf("%lld",h+i);
	int stp=0,edp=-1;
	rep(i,n)
	{
		ll pre=(i?h[i-1]:1);
		ll nxt=(i==n-1?1:h[i+1]);
		ll cur;
		cur=min(h[i],pre);
		cur=max(cur,min(h[i],nxt));
		ncnt+=h[i]-cur;
		h[i]=cur;
	//	cout<<i<<" "<<cur<<" "<<pre<<" "<<nxt<<" "<<h[i]<<endl;
		if(h[i]==1)
		{
	//		cout<<i<<endl;
			if(stp<edp)
				dive.pb(mp(stp,edp));
			stp=i+1,edp=i;
			ncnt++;
		}
		else edp++;
	}
	if(stp<edp)dive.pb(mp(stp,edp));
	ll ans=1;
	ans%=mod;
	rep(i,dive.size())
	{
		ans*=2*cal(dive[i].st,dive[i].nd);
		ans%=mod;
	}
//	cout<<ans<<endl;
//	cout<<ans<<endl;
	if(!dive.size())ans=1;
	if(ncnt)ans*=qp(2,ncnt);
	ans%=mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>

int main(){
  long long int N, K, R, S, P;
  std::string T;
  
  scanf("%lld%lld%lld%lld%lld", &N, &K, &R, &S, &P);
  std::cin >> T;

  std::vector<long long int> score(N);

  for(long long int i = 0; i < N; i++){
    // arbitrary hand
    if(i-K<0){
      if(T[i] == 'r') score[i] = P;
      else if(T[i] == 's')score[i] = R;
      else /*if(T[i] == 'p')*/score[i] = S;
    }
    else{

      if(T[i] == 'r'){
        if(T[i-K] == 'r' && score[i-K] > 0){
          score[i] = 0;
        }
        else{
          score[i] = P;
        }
      }

      if(T[i] == 's'){
        if(T[i-K] == 's' && score[i-K] > 0){
          score[i] = 0;
        }
        else{
          score[i] = R;
        }
      }

      if(T[i] == 'p'){
        if(T[i-K] == 'p' && score[i-K] > 0){
          score[i] = 0;
        }
        else{
          score[i] = S;
        }
      }
    }
  }

  long long int ans = 0;
  for(long long int i = 0; i < N; i++){
    ans += score[i];
  }

  std::cerr << "Answer: " << std::endl;
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  n++;
  vector<pair<int, int>> v0, v;
  for(int i=0;i<n;++i) {
    v.clear();
    string s; cin >> s;
    int tmp = -1;
    for(int j=0;j<(int)(s.size());++j) {
      if('0' <= s[j] && s[j] <= '9') {
        if(tmp == -1) tmp = 0;
        tmp *= 10;
        tmp += s[j] - '0';
      } else {
        if(tmp != -1) {
          if(i == 0) v0.push_back({0, tmp});
          else v.push_back({0, tmp});
          tmp = -1;
        }
        if(i == 0) v0.push_back({1, s[j]});
        else v.push_back({1, s[j]});
      }
    }
    if(tmp != -1) {
      if(i == 0) v0.push_back({0, tmp});
      else v.push_back({0, tmp});
    }
    if(i > 0) {
      if(v >= v0) {
        cout << "+" << endl;
      } else {
        cout << "-" << endl;
      }
    }
  }
}



Measured memory_bytes: 3232
# vim: fileencoding=utf-8


def main():
    n, k = map(int, input().split())
    li = [0] * n
    a = list(map(int, input().split()))
    for i in a:
        li[i - 1] += 1

    li.sort(reverse=True)
    print(sum(li[k:]))


if __name__ == "__main__":
    main()


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

#define TR 100001

using namespace std;

bool dp[TR], visited[TR];
int a[TR];
int n, k;


bool f(int q) {
	if(q < 0)
		return 0;
	if(visited[q])
		return dp[q];
	bool val = 0;
	for(int i = 0 ; i < n ; i++)
		val |= f(q - a[i]);
	dp[q] = !val;
	visited[q] = 1;
	return dp[q];
}

int main() {
	cin >> n >> k;
	for(int i = 0 ; i < n ; i++) 
		cin >> a[i];
	memset(dp, 0, TR * sizeof(bool));
	if(!f(k))
		cout << "First"  << endl;
	else
		cout << "Second" << endl;
	return 0;
}

Measured memory_bytes: 8468
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,n) for (int i = (int)(n); i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

#define yes printf("Yes\n")
#define Yes printf("YES\n")
#define no printf("No\n")
#define No printf("NO\n")

struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
using D = pair<double, double>;
//const long long mod = 998244353;
const long long mod = 1e9 + 7, inf = 3e18;
const string sp = " ";
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 modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n == r) return 1;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

int nck[1010][1010];
void comb(int n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}

map<int, int> factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

int n, m;
int a[1001], b[1001], c[1001];
int d[101][101];
signed main() {
	cin >> n >> m;
	rep(i, n) {
		rep(j, n) {
			if (i != j) d[i][j] = inf;
		}
	}
	rep(i, m) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
		d[a[i]][b[i]] = d[b[i]][a[i]] = c[i];
	}
	rep(k, n) {
		rep(i, n) {
			rep(j, n) {
				chmin(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	int ans = m;
	rep(i, m) {
		rep(j, n) {
			if (d[j][a[i]] + c[i] == d[j][b[i]]) {
				--ans;
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
//<(") 
#define ll int 
using namespace std;
 
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
 
const ll mod = 1e9 + 7;
const ll siz = 1e5 + 10;
const ll base = 32;
const ll MAXX = 1e9;

ll n, m;
string a, b;

ll pre[siz][2];

bool check(ll x1, ll y1, ll x2, ll y2) {
	ll val1 = (pre[y1][0] - pre[x1 - 1][0] + mod) % 3;
	ll val2 = (pre[y2][1] - pre[x2 - 1][1] + mod) % 3;
	return (val1 == val2);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("INP.txt", "r", stdin);
	//freopen("OUT.txt", "w", stdout);
	cin >> a >> b;
	n = a.size(); m = b.size();
	a = ' ' + a; b = ' ' + b;
	for (ll i = 1; i <= n; i++) {
		pre[i][0] = pre[i - 1][0] + ((a[i] == 'A') ? 1 : -1);
		//cerr << pre[i][0] << ' ';
	}
	//cerr << '\n';
	for (ll i = 1; i <= m; i++) {
		pre[i][1] = pre[i - 1][1] + ((b[i] == 'A') ? 1 : -1);
		//cerr << pre[i][1] << ' ';
	}
	//cerr << '\n';
	ll q;
	cin >> q;
	while (q--) {
		ll x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		if (check(x1, y1, x2, y2)) {
			cout << "YES\n";
		}
		else {
			cout << "NO\n";
		}
	}
	return 0;
}  	 	   		  		 		 	  			  		

Measured memory_bytes: 4580
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>
#include <stack>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

signed main() {
	int n,m;
	std::cin >> n >> m;
	std::vector<std::vector<int> > g(n);
	rep(i,m) {
		int a,b;
		std::cin >> a >> b ;
		a--;b--;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	// use bfs and hold par
	{
		std::vector<int> went(n,-1);
		std::queue<int> que;
		que.emplace(0); went[0]=1;
		std::vector<int> par(n);
		while(!que.empty()) {
			int x = que.front(); que.pop();
			debug(x);
			for(auto to:g[x]) {
				if(went[to]!=-1) continue;
				went[to]=1;
				par[to]=x;
				que.emplace(to);
			}
		}
		debug(g);
		rep(i,n) {
			if(went[i]==-1) {
				debug(i);
				print("No");
				return 0;
			}
		}
		print("Yes");
		rep(i,n) {
			if(i==0) continue;
			print(par[i]+1);
		}
	}
	return 0;
}


Measured memory_bytes: 13672