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

// types
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
}

ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

  ll n,k;
  cin >> n >> k;

  vll a(n);
  REP(i, n)
    cin >> a[i];

  sort(a.begin(), a.end());
  vll cum(n+1);
  REP(i, n)
    cum[i+1] = (a[i]+cum[i])%MOD;


  COMinit();
  vll t(n+1-k);
  REP(i, n+1-k){
    t[i] =((cum[n]-cum[k-1+i])-(cum[n-k-(i-1)-1+1]-cum[0]))%MOD;
    if(t[i]<0)
      t[i] += MOD;
    t[i] = t[i]*COM(k-2+i,k-2)%MOD;
  }

  ll ans = 0;
  REP(i,n+1-k)
    ans = (ans+t[i])%MOD;

  cout << ans << endl;

}


Measured memory_bytes: 14208
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;
int A[103];

int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> N;
  rep(i, N) cin >> A[i];

  string ans = "DENIED";
  rep(i, N) {
    if (A[i]%2==0) {
      if (A[i]%3!=0 && A[i]%5!=0) {
        cout << ans << "\n";
        return 0;
      }
    }
  }
  cout << "APPROVED" << "\n";
  return 0;
}

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

#define ll   long long int
#define rep(i,n)    for(int i=0;i<(int)n;i++)
#define show(s)     cout<<s<<endl


ll gcd(ll a, ll b)
{
    if(a < b)  swap(a,b);
    ll r = a % b;

    if(r == 0){
        return b;
    }else{
        return gcd(b,r);
    }
}

int main() {

    int N;
    cin >> N;

    vector<ll> A(N);
    rep(i,N)    cin >> A[i];

    vector<ll> L(N);
    vector<ll> R(N);

    L[0] = A[0];
    for(int i=1; i<N; i++){
        L[i] = gcd(L[i-1],A[i]);
    }
    R[N-1] = A[N-1];
    for(int i=N-2; i>=0; i--){
        R[i] = gcd(R[i+1],A[i]);
    }

    ll mx = 0;
    for(int i=0; i<N-2; i++){
        mx = max(mx,gcd(L[i],R[i+2]));
    }

    mx = max(mx,L[N-2]);
    mx = max(mx,R[1]);

    show(mx);

    return 0;
}


Measured memory_bytes: 2560
while True:
	a, op, b = input().split()
	if(op=='+'):
		print(int(a) + int(b))
	elif(op=='-'):
		print(int(a) - int(b))
	elif(op=='*'):
		print(int(a) * int(b))
	elif(op=='/'):
		print(int(a) // int(b))
	elif(op=='?'):
		break


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  cin>>a>>b;
  vector<vector<int>> dp(a.length()+1,vector<int>(b.length()+1,0));
  for(int i=1;i<=a.length();i++)
  {
  	for(int j=1;j<=b.length();j++){
    	if(a[i-1]==b[j-1]){
        	dp[i][j]=dp[i-1][j-1]+1;
        }
      	else{
        	dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
  }
  int i=a.length();int j=b.length();
  string ans;
  while(i>0&&j>0){
  	if(a[i-1]==b[j-1]){
    	ans+=a[i-1];
      	i--;j--;
    }
    else if(dp[i-1][j]>dp[i][j-1]){
    	i--;
    }
    else j--;
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;
  return 0;
}

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

int main(){
    int ans=0;
    int a,b,c,d;
    cin >>a>>b>>c>>d;

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << min(a,b)+min(c,d) << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    [n, s, k] = [str(readline().rstrip()) for _ in range(3)]
    s = list(s)
    strS = ""
    target = s[int(k) - 1]
    for i in range(int(n)):
        if s[i] == target:
            strS += s[i]
        else:
            strS += "*"
    print(strS)


if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> as(n);

    for (size_t i = 0; i < n; ++i)
        cin >> as[i];

    int kk = min(k, 50);

    for (int t = 0; t < kk; ++t)
    {
        vector<int> bs(n, 0);

        for (int i = 0; i < n; ++i)
        {
            int l = max(0, i - as[i]);
            int r = min(n - 1, i + as[i]);
            bs[l]++;
            if (r + 1 < n)
                bs[r + 1]--;
        }
        for (int i = 0; i < n; ++i)
            bs[i] += bs[i - 1];
        for (int i = 0; i < n; ++i)
            as[i] = bs[i];
    }

    for (auto v : as)
        cout << v << " ";
    cout << endl;

    return 0;
}

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

int w[100010], v[100010];
long long dp[128][100010];

long long calc(int pos, int left) {
    if(pos == 0) return 0;
    long long &y = dp[pos][left];
    if(y!=-1) return y;
    y = calc(pos-1, left);
    if(left >= w[pos]) y = max(y, v[pos] + calc(pos-1, left - w[pos]));
    return y;
}

int main() {
    memset(dp, -1, sizeof(dp));
	int n, W;
	cin >> n >> W;
	for(int i=1; i<=n; ++i) {
	    cin >> w[i] >> v[i];
	}
	cout << calc(n, W);
	return 0;
}


Measured memory_bytes: 103616
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

void dfs(int v, int prev, vector<lint>& sum, const vector< vector<int> >& g){
    for(auto to : g[v]){
        if(to != prev){
            sum[to] += sum[v];
            dfs(to, v, sum, g);
        }
    }
    return;
}

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

    int n, q;
    cin >> n >> q;

    vector< vector<int> > g(n);
    rep(i, n - 1){
        int a, b;
        cin >> a >> b;
        g[--a].emplace_back(--b);
        g[b].emplace_back(a);
    }

    vector<lint> sum(n);
    rep(i, q){
        int p;
        lint x;
        cin >> p >> x;
        sum[--p] += x;
    }

    dfs(0, -1, sum, g);

    rep(i, n){
        if(i) cout << ' ';
        cout << sum[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 30592
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define hell 1000000007
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mp make_pair
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
map< string, ll> mpp;
int main()
{
	IOS
	ll n,i;
	cin>>n;
	string s[n+5];
	for(i=1;i<=n;i++)
	{
		cin>>s[i];
		sort(s[i].begin(),s[i].end());
		mpp[s[i]]++;
	}
	ll ans=0;
	auto it=mpp.begin();
	while(it!=mpp.end())
	{
		ll x=it->second;
		ll val=x*(x-1);
		val=val/2;
		ans=ans+val;
		it++;
	}
	cout<<ans;
	return 0;

}             

Measured memory_bytes: 16640
#include <iostream>
#include <cmath>
#define rep(i,N) for(int i = 0; i<(int)(N); i++)
#define REP(i,k,N) for(int i = k; i<(int)(N); i++)
using namespace std;
const int MAX_N = 10000010;
bool d[MAX_N];
int main(){
        int n;
        while(cin >> n) {
                rep(i,MAX_N) d[i]=true;
                for(int i = 2; i< sqrt(n+1); i++) {
                        if(d[i]) {
                                for(int j = 2; i*j<n+1; j++) {
                                        d[i*j]=false;
                                }
                        }
                }
                int ans = 0;
                REP(i,2,n+1){
                        if(d[i]) ans++;
                }
                cout << ans << endl;
        }

        return 0;
}



Measured memory_bytes: 12816
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn main() {
    let v = read_vec::<usize>();
    println!("{}", if v[0] <= 8 && v[1] <= 8 {"Yay!"} else {":("});
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
#define ull unsigned long long
#define u unsigned
#define mod (u)(1e9+7)
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ull a10=1,a9=1,a8=1;
  u n;
  cin>>n;
  while(n--)
  {
      a10=(a10*(10))%mod;
      a9=(a9*9)%mod;
      a8=(a8*8)%mod;
  }
  cout<<(a10+a8-a9*2+2*mod)%mod<<'\n';
 	return 0;
}


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

int main(){
	int N;string S;
	cin >> S ; N = S.size();
  	int ans = INF;
	for(int i = 0;i < N-1;i++){
  	  if(S[i]!=S[i+1]) ans = min(ans,max(i+1,N-i-1));
  	}
  	if(ans==INF) ans = N;
  	cout << ans << endl;
	return 0;
}

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

int res,n,d,a[200010],dpl[200010],dpr[200010];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>d;
	for(int i=1;i<=n;i++){cin>>a[i];res+=a[i];}
	res+=(n-1)*d;
	dpl[1]=a[1];
	for(int i=2;i<=n;i++) dpl[i]=min(a[i],dpl[i-1]+d);
	dpr[n]=a[n];
	for(int i=n-1;i>=1;i--) dpr[i]=min(a[i],dpr[i+1]+d);
	for(int i=2;i<=n-1;i++) res+=min(dpl[i],dpr[i]);
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>

int main(){
	int i = 0;
	
	scanf("%d",&i);
	
	if(i % 2 == 0){
		printf("%d",((i / 2) - 1));
	}else{
		printf("%d",(((i + 1) / 2) - 1));
	}
	return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<pair<int, int>> vals;
    vector<int> same_vals;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        vals.push_back({a[i], b[i]});
    }

    sort(vals.begin(), vals.end(), [](pair<int, int>& a, pair<int, int>& b) {
        return (a.first + a.second) > (b.first + b.second);
    });

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2) ans -= vals[i].second;
        else ans += vals[i].first;
    }

    cout << ans;

}

Measured memory_bytes: 2168
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
#include<map>

using namespace std;

#define INF 100000000
#define mp make_pair
#define pii pair<int,int>

int h,w,s;
int board[55][55];
int box[55][55];


void boxset(){
	for(int i=1;i<=h;i++)box[i][1] = board[i-1][0] + box[i-1][1];
	for(int i=1;i<=w;i++)box[1][i] = board[0][i-1] + box[1][i-1];
	
	for(int i=1;i<=h;i++)for(int j=1;j<=w;j++){
		box[i][j] = box[i-1][j] + box[i][j-1] - box[i-1][j-1] + board[i-1][j-1];
	}
}

int boxget(int y1,int x1,int y2,int x2){
	return box[y2][x2] - box[y1][x2] - box[y2][x1] + box[y1][x1];
}


//pair<int,int> : 分割数,区画内の和の最小値

pii marge(pii a, pii b){
	return mp(a.first + b.first,  min(a.second, b.second));
}

pii memo[33][33][33][33];
pii saiki(int y1,int x1,int y2,int x2){
	if(memo[y1][x1][y2][x2].first!=0) return memo[y1][x1][y2][x2];
	
	pii cand = mp(1, boxget(y1,x1,y2,x2));
	
	pii a1,b1,a2,b2;
	
	//左右分割
	for(int i=y1+1; i<y2; i++){
		pii a = saiki(y1, x1, i, x2);
		pii b = saiki(i, x1, y2, x2);
		
		cand = max(marge(a,b), cand);
	}
	
	//上下分割
	for(int i=x1+1; i<x2; i++){
		pii a = saiki(y1, x1, y2, i);
		pii b = saiki(y1, i, y2, x2);
		cand = max(marge(a,b), cand);
	}
	
	if(boxget(0,0,h,w) - cand.second > s)cand = mp(-INF,0);
	return memo[y1][x1][y2][x2] = cand;
}

int main(){
	
	while(1){
		//入力
		cin>>h>>w>>s;
		if(h==0)break;
		
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>board[i][j];
		
		for(int i=0;i<=h;i++)for(int j=0;j<=w;j++){
			for(int k=0;k<=h;k++)for(int p=0;p<=w;p++){
				memo[i][j][k][p] = mp(0,0);
			}
		}
		
		//二次元累積和計算
		boxset();
		
		pii ans = saiki(0,0,h,w);
		printf("%d %d\n",ans.first, ans.second + s - boxget(0,0,h,w));
	}
}

Measured memory_bytes: 10440
#include <stdio.h>
int d;
int c[26];
int l[26];
int s[365][26];
int t[365];
int ans;
int main() {
	scanf("%d", &d);
	for (int i = 0; i < 26; i++) {
		scanf("%d", c + i);
		l[i] = -1;
	}
	for (int i = 0; i < d; i++) {
		for (int j = 0; j < 26; j++) {
			scanf("%d", s[i] + j);
		}
	}
	for (int i = 0; i < d; i++) {
		scanf("%d", t + i);
		t[i]--;
	}
	for (int i = 0; i < d; i++) {
		ans += s[i][t[i]];
		l[t[i]] = i;
		for (int j = 0; j < 26; j++) {
			ans -= c[j] * (i - l[j]);
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1772
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int N; cin>>N;
  vector<ll> a(N);
  REP(i,N) cin>>a[i];
  sort(a.begin(), a.end());
  ll ans = 0;
  if(N % 2 == 0) {
    for(int i = 1; i < N/2; i++) {
      ans += (ll)(i*2)*abs(a[i] - a[i-1]);
      ans += (ll)(i*2)*abs(a[N-1-i] - a[N-i]);
    }
    ans += (ll)(N-1)*abs(a[N/2]-a[N/2-1]);
  } else {
    for(int i = 1; i <= N/2; i++) {
      ans += (ll)(i*2)*abs(a[i] - a[i-1]);
      ans += (ll)(i*2)*abs(a[N-1-i] - a[N-i]);
    }
    ll work = min(abs(a[N/2]-a[N/2-1]),	a[N/2+1]-a[N/2]);
    ans -= work;

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


Measured memory_bytes: 1024
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)
 
int main() {
	// 入力
	int A, B;
	cin >> A >> B;
	
	// 解法
	int ans = (A-1)*(B-1);
	printf("%lld\n", ans); // lld としないとオーバーフローする
}
 


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

int s[100000];
int t[50000];

bool binarysearch(int t,int n)
{
  int left=0;
  int right=n;
  int mid=0;

  while(left < right){
    
    mid = (left + right)/2;
    
    if(t == s[mid])
      {
	return true;
      }
    else if(t < s[mid])
      {
	right = mid;
      }
    else
      {
	left = mid + 1;
      }
  }
  return false;   
}

int main(){
  int n,q;
  int cnt=0;

  cin >> n;
  for(int i=0;i < n;i++){
    cin >> s[i];
  }
  
  cin >> q;
  for(int i=0;i < q;i++){
    cin >> t[i];
    if( binarysearch(t[i],n) ) cnt++;
  }
  
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 3592
fun main(args: Array<String>) {
    val (w, h, x, y) = readLongList()

    val ans = w * h * 0.5
    if (2 * x == w && 2 * y == h) {
        println("$ans 1")
    } else {
        println("$ans 0")
    }
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 36664
#include <cstdio>

int main()
{
    int S;
    std::scanf("%d", &S);
    int h, m, s;
    h = S / 3600;
    S = S % 3600;
    m = S / 60;
    s = S % 60;
    std::printf("%d:%d:%d\n", h, m, s);
    return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

const ll M = 1000000000000000000;
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n)
    {
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    int ans = 0;
    rep(i, k)
    {
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  ll n,m;
  cin >> n >> m;
  
  cout << (n*(n-1) + m*(m-1)) / 2 << endl;
}

Measured memory_bytes: 3600
/*------------------------- Bism Allah Alruhmin Alrahim -------------------------------*/
#include <bits/stdc++.h>
using namespace std;

#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                    \
    sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
    {
sim > struct rge
{
    c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
    ~debug()
    {
        cerr << endl;
    }
    eni(!=) cerr << boolalpha << i;
    ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
    sim dor(const c &)
    {
        ris;
    }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);

#define forn(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i > -1; i--)
#define forl(i, l, r) for (int i = l; i <= r; i++)
#define vc vector
#define f first
#define s second
#define pb(i) push_back(i)
#define mx(ar, n) (*max_element(ar, ar + n))
#define mn(ar, n) (*min_element(ar, ar + n))

using namespace std;

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

ll LCM(ll x, ll y)
{
    return (x * y) / __gcd(x, y);
}

bool even(ll n){
  return n%2 == 0;
}

bool odd(ll n){
  return n%2 == 1;
}

int main()
{
    fastio
    clock_t tStart = clock();
    /* --------- My Solution -------- */

    
    double n ;
    cin >> n ; 
    if(even(n)){
        cout << fixed << setprecision(6) << 0.5 << endl;
    }
    else{
        ll  x  = n/2 + 1;
        cout << fixed << setprecision(6) << (x/n) << endl;
    }
    // printf("\nTime taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}




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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;

typedef long long LL;
typedef long double ldouble;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n;
    cin >> n;
    P a[9];
    vector<int> v;
    for(int i = 1; i <= n; ++i) {
        cin >>a[i].F >> a[i].S;
        v.pb(i);

    }

    double ss = 0;
    int c = 0;
    do {
        double s = 0;
        for(int i = 0; i < v.size() - 1; ++i) {
            double x, y;
            x = abs(a[v[i]].F - a[v[i + 1]].F);
            y = abs(a[v[i]].S - a[v[i + 1]].S);
            s += sqrt(x * x + y * y);

        }
        ss += s;
        ++c;
    } while(next_permutation(all(v)));

    printf("%.10lf\n", ss / c);


    return 0;
}


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

int main(void){
	int* num = new int[ 1 ];
	int* t = new int[ 1 ];

	int  count = 0;
	while( true ){
		cin >> num[ count ];
		if( num[ count ] == 0 ) break;
		count++;
		delete[] t;
		t = new int[ count ];
		for( int loop = 0 ; loop < count ; loop++ )	t[ loop ] = num[ loop ];
		delete[] num;
		num = new int[ count + 1 ];
		for( int loop = 0 ; loop < count ; loop++ )	num[ loop ] = t[ loop ];
	}
	for( int loop = 0 ; loop < count ; loop++ ) cout << "Case " << loop + 1 << ": " << num[ loop ] << endl;

	delete[] num;
	delete[] t;
	num = t = 0;

	return 0;
}

Measured memory_bytes: 1312
#include <bits/stdc++.h>
#include <string>
//#include <queue>
using namespace std;
#define ll long long
#define ld long double


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    if (k==1) cout << 0 << endl; else
    cout << n-k << endl;
    return(0);
}


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

class Program
{
    static void Main(string[] args)
    {
        string[] a = Console.ReadLine().Split(' ');
        int[] ans = new int[int.Parse(a[2])];
        int[] person = new int[int.Parse(a[0])];
        string[] ret = new string[int.Parse(a[0])];
        for (int i = 0; i < ans.Length; i++)
        {
            ans[i] = 0;
        }
        for (int i = 0; i < int.Parse(a[2]); i++)
        {
            ans[i] = int.Parse(Console.ReadLine());
        }

        for (int i = 0; i < ans.Length; i++)
        {
            person[ans[i] - 1] += 1;
        }

        for (int i = 0; i < int.Parse(a[0]); i++)
        {
            if ((int.Parse(a[1]) + person[i] - int.Parse(a[2])) > 0)
            {
                ret[i] = "Yes";
            }
            else
            {
                ret[i] = "No";
            }

        }
        foreach (var item in ret)
        {
            Console.WriteLine(item);
        }
        Console.ReadKey();
    }
}


Measured memory_bytes: 20828
n = int(input())
e = [0] * (n+1)

for i in range(2, n+1):
    for j in range(2, i+1):
        while i % j == 0:
            e[j] += 1
            i //= j
            
def count(m):
    return len(list(filter(lambda x: x >= m-1, e)))

a = count(75)
b = count(25) * (count(3) - 1)
c = count(15) * (count(5) - 1)
d = count(5) * (count(5) - 1) * (count(3) - 2) // 2

print(a + b + c + d)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
	int H, A;
  	cin>>H>>A;
  	int sum =0;	
  for(int i=1; i<=A; i++){
      int a; cin>>a;
  	sum+=a;  
  }
  if(sum>=H) cout<<"Yes\n";
  else cout<<"No\n";
  
}

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

using namespace std;

int main(void)
{
	string s, ss, key;
	int i, j;


	cin >> s;
	cin >> key;

	ss = s + s;

	if(ss.find(key) == -1)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
using namespace std;
int main(){
  int n,m,l;
  cin >> n >> m >> l;
  int a[n][m];
  int b[m][l];
  long long sum;
  long long c[n][l];
  for(int i = 0;i < n;i++){
    for(int j = 0;j < m;j++){
      cin >> a[i][j];
    }
  }
  for(int i = 0;i < m;i++){
    for(int j = 0;j < l;j++){
      cin >> b[i][j];
    }
  }
  sum = 0;
  for(int i = 0;i < n;i++){
    for(int j = 0;j < l;j++){
      for(int k = 0;k < m;k++){
         sum += a[i][k] * b[k][j];
      }
      c[i][j] = sum;
      sum = 0;
    }
  }

  for(int i = 0;i < n;i++){
    for(int j = 0;j < l;j++){
      cout << c[i][j];
      if(j != l-1){
        cout << " ";
      }
    }
    cout << "\n";
}
  return 0;
}


Measured memory_bytes: 3168
// -*- coding:utf-8-unix -*-

use proconio::{input, fastout};


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

    let mut ans = 0;
    let mut wer = "No";

    for (x,y) in d{
        if x == y{
            ans += 1;
        }else{
            ans = 0;
        }

        if ans == 3{
            wer = "Yes";
        }
    }


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

Measured memory_bytes: 2180
//
// !!!WARNING!!!
// AUTO SUBMITTION TEST ALERT
// !!!WARNING!!!
//

#include <stdio.h>

int isPrime(const int N) {
    // 2 is prime
    if(N == 2) return 1;
    // 0, 1 and even number is not prime
    if(N < 2 || N % 2 == 0) return 0;
    // prime factor of N should less than or equal sqrt(N)
    for(int i = 3; i * i <= N; i += 2) {
        if(N % i == 0) return 0;
    }
    return 1;
}

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



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

int main() {
  int N;
  cin >> N;
  for (int i=0; i<N; i++){
  	string color;
    cin >> color;
  	if (color =="Y"){
      cout << "Four" << endl;
      break;
    }
    else if (i+1==N){
      cout << "Three" << endl;
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */
int a[5];
int main(){
    int k;
    rep(i, 5) cin >> a[i];
    cin >> k;
    sort(a, a+5);
    if(a[4] - a[0] > k){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }

}



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

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

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

    #define int long long

    using namespace std;

    signed main()
    {
        string x;
        int y=0,z=0,w,i,j;
        cin>>x;
        rep1(i,x.length()){
        if(x[i]==x[i-1]){
                z++;
            if(x[i-1]==48)x[i]=49;
            else x[i]=48;
        }
        }



        cout<<z<<endl;
        return 0;
    }



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

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    if(abs(a-b)<=1)cout<<"Yay!"<<endl;
    else cout<<":("<<endl;

    return 0;
}

Measured memory_bytes: 256
import heapq
N,M = map(int,input().split())
l = [tuple(map(int,input().split())) for _ in range(N)]
l = sorted(l,reverse=True)
heap = []
ans = 0
for i in range(1,M+1):
        while l and l[-1][0] == i:
            heapq.heappush(heap, -(l.pop()[1]))
        if heap :
            ans -= (heapq.heappop(heap))
print(ans)





Measured memory_bytes: 17804
s = gets.chomp.split("")
s.length.times do |i|
  if (i+1) % 2 == 0
    if s[i] == "R"
      puts "No"
      exit
    end
  else
    if s[i] == "L"
      puts "No"
      exit
    end
  end
end
puts "Yes"

Measured memory_bytes: 1788
X, K, D = map(int, input().split())

aX = abs(X)
if aX // D >= K:
    ans = aX - K * D
else:
    if (K - (aX // D )) % 2 == 0:
        ans = aX % D
    else:
        ans = (aX % D) - D
    
print(abs(ans))

Measured memory_bytes: 9076
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String[] S = new String[N];
		for( int i=0; i<N; i++ ){
			S[i] = sc.next();
			String[] str = new String[10];
			for( int j=0; j<10; j++ ){
				str[j] = String.valueOf(S[i].charAt(j));
			}
			Arrays.sort(str);
			S[i] = "A";
			for( int j=0; j<10; j++ ){
				S[i] += str[j];
			}
		}
		Arrays.sort(S);
		long ans = 0;
		long count = 1;
		for( int i=1; i<N; i++ ){        
			if( S[i].equals(S[i-1]) ){
				count++;
            }              
			if( !(S[i].equals(S[i-1])) || i==N-1 ){           
				ans += count*(count-1)/2;           
				count = 1;
			}
		}   
		System.out.println(ans);
	}
}


Measured memory_bytes: 96336
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 3223372036854775807
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
//#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
#define lg length()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invp(a,p)pom(a,p-2,p)
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<Pll,ll> a,pair<Pll,ll> b){
        return a.fi.se>b.fi.se;
}
ll cmp2(pair<ll,ll> a,pair<ll,ll> b){
    if(a.fi!=b.fi)
        return  a.se<b.se;
    else
        return a.se>b.se;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(int argc, char * argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("big.txt", "r", stdin);
    //freopen("out3.txt", "w", stdout);
    //------------------------------
    ll a,b,c,d;cin>>a>>b>>c>>d;
    ll ans=-INF;
    if(a<=0&&b>=0)ans=0;
    if(c<=0&&d>=0)ans=0;
    chmax(ans,mmax(b*d,a*c));
    chmax(ans,mmax(b*c,a*d));
    cout<<ans<<endl;
    //------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //------------------------------- 
    return 0;
}
//----------------------------------------------------------------------








































Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long int ll;
#define ipair pair<int,int>
#define mod 1000000007

int main()
{
    int n;
    cin>>n;
    int u,v,res=0;
    for(int i=0;i<n;i++)
    {
        cin>>u>>v;
        res+=v-u+1;
    }
    cout<<res<<endl;
}



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

public class AtCoderF
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();

        long answer = 0;

        var divisors1 = GetDivisors(n);
        foreach (var div in divisors1)
        {
            if (div == 1)
            {
                continue;
            }
            long tmpN = n;
            while (true)
            {
                if (tmpN % div == 0)
                {
                    tmpN /= div;
                }
                else
                {
                    break;
                }
            }
            if (tmpN % div == 1)
            {
                answer++;
            }
        }

        var divisors2 = GetDivisors(n - 1);
        answer += divisors2.Count - 1;


        Console.WriteLine(answer);
    }

    private static List<long> GetDivisors(long n)
    {
        List<long> divisors = new List<long>();
        for (long i = 1; i * i <= n; i++)
        {
            if (n % i == 0)
            {
                divisors.Add(i);
                if (n / i != i)
                {
                    divisors.Add(n / i);
                }
            }
        }
        return divisors;
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
char s[200];
int main()
{
	cin >> s + 1;
	int len = strlen(s + 1);
	bool c,f;
	c = f = 0;
	for(register int i = 1; i <= len; ++i)
	{
		if(s[i] == 'C')
			c = 1;
		if(s[i] == 'F' && c)
			f = 1;
	}
	puts(c && f ? "Yes" : "No");
	return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
    long double _1, _2, _3, _4; cin >> _1 >> _2 >> _3 >> _4;
    complex<long double> a(_1, _2), b(_3, _4);
    cout << fixed <<setprecision(12) << abs(a-b) << endl; 
}


Measured memory_bytes: 3348
#include<stdio.h>

 


int main(void){
    int n;
    scanf("%d",&n);
    int a[n],b=0,c=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);   
    }
    for(int d=0;d<n;d++){
        for(int j=0;j<n-1;j++){
            if(a[j]<a[j+1]){
                int e;
                e=a[j];
                a[j]=a[j+1];
                a[j+1]=e;
            }

        }
    }

    for(int i=0;i<n;i++){
        if(i%2==0){
            b=b+a[i];
        }else{
            c=c+a[i];
        }
    }

        
    printf("%d",b-c);



    
    return 0;
}

Measured memory_bytes: 128
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  vi a(n), p(n, -INF), q(n, -INF);
  rep(i, n) cin >> a[i];
  int s = 0;
  rep(i, n) {
    int x = i, c = 0;
    for (; p[x] < 0; c++) {
      p[x] = c;
      q[x] = i;
      x    = (x + a[x]) % n;
    }
    if (q[x] == i) s += c - p[x];
  }
  cout << s << endl;
}

Measured memory_bytes: 5128
#include <bits/stdc++.h>
using namespace std;
#define LONGLONGMAX 9223372036854775807
#define LONGLONGMIN -9223372036854775807
#define INTMAX 32767
#define INTMIN -32767
#define ROUNDUP(divisor,dividend) (divisor + (dividend - 1)) / dividend
std::vector<int> v(5);
int k; bool c=true;
int main(){
  for (size_t i = 0; i < 5; i++) {
    cin >> v[i];
  }
  cin >> k;
  if(v[4]-v[0] > k)c = false;
  cout << (c ? "Yay!":":(") << endl;
}


Measured memory_bytes: 256
s = input()
is_ok = True
for i in range(len(s)):
    if i % 2 == 0 and s[i] == "L":
        is_ok = False
        break
    if i % 2 == 1 and s[i] == "R":
        is_ok = False
        break
print("Yes" if is_ok else "No")


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <unordered_set>
#include <algorithm>

using namespace std;


int minDistance(unordered_set<int> &s, int n, int x) {
    if (n == 0) return x;
    if (s.find(x) == s.end()) return x;
    int i = 1;
    while (1) {
        if (s.find(x - i) == s.end())
            return x - i;
        if (s.find(x + i) == s.end())
            return x + i;
        i++;
    }
    return x;
}

int main() {
    int x, n, ele;
    cin >> x >> n;
    unordered_set<int> s;
    for (int i = 0; i < n; i++) {
        cin >> ele;
        s.insert(ele);
    }
    cout << minDistance(s, n, x) << endl;
    return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;
import java.util.Arrays;

class Main {
    public static void main(String[] args){
    	 Scanner sc = new Scanner(System.in);
         int n = sc.nextInt();
         int max = sc.nextInt();
         int x = 1001;
         int y = 0;
         int count = 0;
         int[] d = new int[n];
         for(int i=0;i<n;i++){
            d[i]=sc.nextInt();
            x=Math.min(x,d[i]);
            y+=d[i];
         }
         System.out.println(n+(max-y)/x);
    }    
}

Measured memory_bytes: 23124
/*input
2
5 1 1
100 1 1
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii; 


#define FileIn(file) freopen(file, "r", stdin)
#define FileOut(file) freopen(file, "w", stdout)
#define syso(n) cout<<n<<endl;
#define sysom(message, n) cout<<message<<n<<\n;
#define all(c) c.begin(), c.end() 
#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define present(container, element) (container.find(element) != container.end())  //map, set
#define cpresent(container, element) (find(all(container),element) != container.end()) //vector
#define what_is(x) cout << #x << " is " << x << endl; 


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

ll lcm(ll fir, ll sec){
	return (fir*sec)/(gcd(fir, sec));
}


const int MOD = 1e9 + 7;
const string small_alphabets = "abcdefghijklmnopqrstuvwxyz";
const int month_days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
// --
// -- 
// -- 
// std::cout << std::fixed;
// std::cout << std::setprecision(5) << f << '\n';


// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
int main(){
	int n;
	cin>>n;
	int t,x,y;
	int prevt=0,prevx=0,prevy=0;
	bool ans = true;
	int index;
	// cin>>prevt>>prevx>>prevy;
	for (int i = 0; i < n; ++i){
		cin>>t>>x>>y;
		int dis = abs(x-prevx) + abs(y-prevy);
		// what_is(dis);
		if(dis>t-prevt){
			ans = false;
			index = x;
		}
		if((t-prevt-dis)%2!=0){
			index = x;
			ans = false;
		}
		prevx = x;
		prevy = y;
		prevt = t;
	}
	if(ans){
		syso("Yes");
	}else{
		syso("No");
	}
	// what_is(index);
	return 0;
}


Measured memory_bytes: 256
/*
  AOJ 2523
  Title:Time Complexity
  @kankichi573
  14/04/10 WA 2/26
*/
#include <stdio.h>
#include <string.h>
#include <float.h>
#include <setjmp.h>
jmp_buf jb;

int n,T;
char expr[50];

double expt(int x,int n)
{
  double ret;

  if(n==0)
    ret=1.0;
  else
    ret=x*expt(x,n-1);
  if(ret>1000000000)
    longjmp(jb,1);
  return(ret);
}

double eval_single(char expr[],int n)
{
  int ret;
  if(expr[1]=='^')
    {
      ret=expt(n,expr[2]-'0');
    }
  else
    ret=n;

  return(ret);
}
double evaluate(char exp[],int n)
{
  double ret;
  char *p;

  ret=0;
  p=strtok(exp,"+\0");
    do
    {
      ret+=eval_single(p,n);
      if(ret>1000000000)
	longjmp(jb,1);
    }while(p=strtok(NULL,"+\0"));
  return(ret);
}

main()
{
  double ret;

  scanf("%d %d",&n,&T);
  scanf("%s",expr);

  if(setjmp( jb ) == 0 ) 
    ret=T*evaluate(expr,n);  
  else
    {
      printf("TLE\n");
      return(0);
    }
  if(ret>1000000000)
    printf("TLE\n");
  else
    printf("%.0lf\n",ret);
    
  return(0);
}

Measured memory_bytes: 632
// starter code
# include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  long int A[n+1],B[n+1];
  B[n] = 0;
  // monsters array
	for(int i = 0; i < n+1; i++){
     	cin >> A[i];
	}
  // heros array
	for(int i = 0; i < n; i++){
     	cin >> B[i];
	}  
	long int ul_pow = 0, res=0;
	for(int i = 0; i < n+1; i++){
		if(ul_pow > A[i]){
        	res += A[i];
            ul_pow = B[i];
        }
        else{
        	res += min(ul_pow+B[i], A[i]);
            ul_pow = max(ul_pow-ul_pow,B[i]+ul_pow-A[i]);
        }
    }
    cout << res<<'\n';

	return 0;
}

Measured memory_bytes: 1792
N = int(input())
inputs = [int(input()) for i in range(N)]

points = [int(s) for s in inputs]
points_sorted = sorted(points)

get_point = sum(points_sorted)
non_10 = [x for x in points_sorted if (x % 10 != 0)]

if get_point % 10 != 0:
    print(get_point)
elif non_10 == []:
    print(0)
else:
    print(get_point - min(non_10))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>

typedef long long ll;
using namespace std;
ll ans=0;
int main()
{
    ll N;
    ll i=1;
    scanf("%lld",&N);
    while(i*i<N)
    {
        if(N%i==0)
        {
            ll x=N/i-1;
            if(N%x!=0)
                ans+=x;
        }
        i++;
    }
    //ans=2499687339916;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var md = ReadInts();
            var md2 = ReadInts();
            if (md[0] == md2[0])
            {
                WriteLine(0); 
            }
            else
            {
                WriteLine(1);
            }
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140