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

using namespace std;

const int MX = 200200;

int N, X, Y;
vector<int> adjr[MX];
vector<int> adjb[MX];
int distr[MX];
int distb[MX];
int anc[18][MX];

void dfs(int v, int p) {
   for (int z = 1; z < 18; ++z) anc[z][v] = anc[z-1][anc[z-1][v]];
   for (int u : adjb[v]) if (u != p) {
      distb[u] = distb[v]+1;
      anc[0][u] = v;
      dfs(u, v);
   }
}

int lca(int v, int u) {
   if (distb[v] > distb[u]) swap(v, u);
   for (int z = 17; z >= 0; --z) if (distb[anc[z][u]] >= distb[v]) u = anc[z][u];
   if (v == u) return v;
   for (int z = 17; z >= 0; --z) if (anc[z][v] != anc[z][u]) {
      v = anc[z][v];
      u = anc[z][u];
   }
   return anc[0][v];
}

int get_dist(int v, int u) {
   return distb[v] + distb[u] - 2 * distb[lca(v, u)];
}

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   cin >> N >> X >> Y;
   for (int i = 0; i < N-1;++i) {
      int v, u; cin >> v >> u;
      adjr[v].emplace_back(u);
      adjr[u].emplace_back(v);
   }
   for (int i = 0; i < N-1; ++i) {
      int v, u; cin >> v >> u;
      adjb[v].emplace_back(u);
      adjb[u].emplace_back(v);
   }
   anc[0][Y] = Y;
   dfs(Y, 0);
   queue<int> bfs;
   for (int i = 1; i <= N; ++i) distr[i] = -1;
   distr[X] = 0;
   bfs.emplace(X);
   int ans = 0;
   while (!bfs.empty()) {
      int v = bfs.front(); bfs.pop();
      ans = max(ans, 2 * distb[v]);
      for (int u : adjr[v]) if (distr[u] == -1) {
         if (get_dist(v, u) >= 3) {
            cout << "-1\n";
            return 0;
         }
         if (distr[v] + 1 > distb[u]) continue;
         if (distr[v] + 1 == distb[u]) {
            ans = max(ans, 2 * distb[u]);
         } else {
            distr[u] = distr[v]+1;
            bfs.emplace(u);
         }
      }
   }
   cout << ans << '\n';
   return 0;
}


Measured memory_bytes: 52204
#define S(i) scanf("%d",&i);
int i,n,D,t,d[500001],Q,m[500001],N=1,a[500001];main(){S(n)S(D)t=D;for(i=0;i<n;++i){S(d[i])if(t*2>d[i])t=abs(t-d[i]);m[i]=t;}for(i=n;i>0;--i){if(m[i-1]>=N)a[i]=1;if(2*N>d[i])N+=d[i];}if(D>=N)a[0]=1;S(Q)for(i=0;i<Q;++i){S(D)if(a[D-1])puts("YES");else puts("NO");}}

Measured memory_bytes: 7680
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

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

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

lint euler_phi(lint n){
    lint ret = n;
    if(n == 0){
        return 0;
    }
    for (lint i=2; i*i <= n; ++i){
        if(n % i == 0){
            ret -= ret / i;
            while(n % i == 0){
                n /= i;
            }
        }
    }
    if(n > 1){
        ret -= ret / n;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    vector<lint> n(t);
    vector<lint> euler_phi_num(1000000+1, 1);
    vector<lint> sum(1000000+1, 1);
    REP(i, t){
        cin >> n[i];
    }
    FOR(i, 1, 1000000+1){
        euler_phi_num[i] = euler_phi(i);
    }
    REP(i, 1000000){
        sum[i+1] = sum[i] + euler_phi_num[i+1];
    }
    REP(i, t){
        cout << sum[n[i]] << endl;
    }
    return 0;
}


Measured memory_bytes: 18528
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
// #define int long long
//#define ll long long
#define ull  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 340000;
int mod = 1e9 + 7;
int a[N], f[N], invf[N], d[N], used[N];
set < int > t;
int b = -1;
set < pair < int, int > > s;
int binpow(int x, int y){
    if (y == 0) return 1;
    if (y % 2) return x * binpow(x, y - 1) % mod;
    int z = binpow(x, y / 2);
    return z * z % mod;
}
int c(int n, int k){
    return f[n] * invf[k] % mod * invf[n - k] % mod;
}
void work(int v){
    cout << v << " ";
    b = v;
    used[v] = 1;
    s.erase({-d[v],v});
    int u = a[v];
    if (!used[u]){
        s.erase({-d[u], u});
        d[u]--;
        s.insert({-d[u], u});
    }
    t.erase(v);
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    if (n == 2){
        cout << -1;
        return 0;
    }

    for (int i = 1; i <= n; i++){
        cin >> a[i];
        d[a[i]]++;
        t.insert(i);
    }
    for (int i = 1; i <= n; i++) s.insert({-d[i], i});
    for (int i = 1; i <= n; i++){
        int q = 1;
        int ss = 0;
        if (n == i + 2){
            for (auto i: t) ss += !used[a[i]];
        }
        if (n == i + 2 && ss == 2){
            for (auto i: t){
                int v = a[i];
                if (!used[v] && a[v] == i){
                    if (v < i && v != b) work(v); else
                    if (i < v && i != b) work(i); else
                    if (v == b) work(i); else
                    if (i == b) work(v);
                    q = 0;
                }
                if (q == 0) break;
            }
        }
        if (q == 0) continue;
        auto x = *s.begin();
        if (-x.F == n - i){
            cout << x.S << " ";
            b = a[x.S];
            used[x.S] = 1;
            s.erase(x);
            int v = a[x.S];
            if (!used[v]){
                s.erase({-d[v], v});
                d[v]--;
                s.insert({-d[v], v});
            }
            t.erase(x.S);
        } else{
            auto it = t.begin();
            if (*it == b) it++;
            int x = *it;
            cout << x << " ";
            used[x] = 1;
            b = a[x];
            s.erase({-d[x], x});
            int v = a[x];
            if (!used[v]){
                s.erase({-d[v], v});
                d[v]--;
                s.insert({-d[v], v});
            }
            t.erase(x);
        }
    }
}


Measured memory_bytes: 13056
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

#define f first 
#define s second 
#define mp make_pair
#define pb push_back

typedef long long ll;

const int mod=1e9+7;
const int INF=INT_MAX;

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

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


int main(){
    int a,b;
    cin >> a >> b;
    cout << (a>=13?b:(6<=a&&a<=12?b/2:0)) << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())

sList =[0] * N

for i in range(N):
    sList[i] = ''.join(sorted(list(input())))

sList = sorted(sList)

ans = 0
tmp = 1

for i in range(N-1):
    if sList[i] == sList[i+1]:
        tmp += 1
    else:
        ans += (tmp * (tmp - 1)) // 2
        tmp = 1
if sList[N-2] == sList[N-1]:
    ans += (tmp * (tmp - 1)) // 2
            
print(ans)

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

#define NIL -2
#define INF 1000000001

using namespace std;
static const int BLK = 2;
static const int GRY = 1;
static const int WHT = 0;

void dijkstra(  const   vector<vector<int> > &weight_matrix, 
                        vector<int> &color,
                        vector<int> &minpath,
                        vector<int> &parent)
{
    int n = (int)weight_matrix.size();
    int u,v;
    int mincost;
    while(true){
        mincost = INF;
        for(int i = 0;i < n;i++){
            if(color[i] != BLK && minpath[i] < mincost){
                mincost = minpath[i];
                u = i;
            }
        }
        if(mincost == INF) break;
        color[u] = BLK;

        for(int v = 0; v < n;v++){
            if(color[v] != BLK && weight_matrix[u][v] < INF){
                if( minpath[v] > minpath[u] + weight_matrix[u][v]){
                    minpath[v] = minpath[u] + weight_matrix[u][v];
                    parent[v] = u;
                    color[v] = GRY;
                }
            }
            
        }
    }
    

}

int main(){
    int mat_size;
    int node, deg;
    int to,weight;
    int temp;
    int cost = 0;

    scanf("%d",&mat_size);
    vector<vector<int> > weight_matrix(mat_size,vector<int>(mat_size,INF));
    vector<int> color(mat_size,WHT);
    vector<int> minpath(mat_size,INF);
    vector<int> parent(mat_size,-1);

    for(int i = 0;i < mat_size;i++){
        scanf("%d %d",&node,&deg);
        for(int j = 0;j < deg;j++){
            scanf("%d %d", &to, &weight);
            weight_matrix[node][to] = weight;
        }
    }
    minpath[0] = 0;
    dijkstra(weight_matrix,color,minpath,parent);
    for(int i = 0; i < mat_size;i++){
        printf("%d %d\n",i,minpath[i]);
    }

    return 0;   
}



Measured memory_bytes: 3252
#include<bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
using namespace std;
//using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX 500003
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >
//#define endl "\n"
 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const int mod=998244353;
int power(int a,int b)
{
    int ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a);
        }
        a=(a*a);
        b>>=1;
    }
    return ans;
}

int32_t main()
{
    fast;
    
    int t;
    t=1;
    while(t--)
    {   
        int n,val;
        vi v;
        int sum=0;
        cin>>n;
        map<int,int> mpp;

        rep(i,n)
        {
            cin>>val;
            mpp[val]++;
            sum+=val;
        }

        int q;
        cin>>q;

        while(q--)
        {
            int x,y;
            cin>>x>>y;

            sum-=(x*mpp[x]);
            sum+=(y*mpp[x]);
            mpp[y]+=mpp[x];
            mpp[x]=0;

            cout<<sum<<endl;
        }
    }
}


Measured memory_bytes: 9460
n, m = map(int, input().split(" "))
ans = 0

ar = [0] * n + [1] * m
for s in range(len(ar)):
    for a in range(s + 1, n + m):
        if (ar[s] + ar[a]) % 2 == 0:
            ans += 1

print(ans)

Measured memory_bytes: 3060
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500 * i + 100 * j + 50 * k == X:
                count += 1
print(count)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  int N;cin>>N;
  vector<int> vec (N,0);
  for (int i = 0; i < N; i++)
  {
     cin>>vec[i];
  }
  int res = INF;
  for (int c = -100; c < 101; c++)
  {
    int cost = 0;
    for (int i = 0; i < N; i++)
    {
      cost += (vec[i] - c) * (vec[i] - c);
    }
    chmin(res,cost);
    
  }
  
  cout<<res<<endl;
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int a = sc.nextInt();

        String str = "";
        for (int i = 0; i < s.length(); i += a) {
            str += s.charAt(i);
        }

        System.out.println(str);
    }
}

Measured memory_bytes: 23892
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    int n;
    cin >> n;
    int cnt = 0;
    int db = 0;

    reps(a,1,n+1){
        reps(b,1,n+1){
            int c = n-a*b;
            if(c > 0){
                cnt++;
            }else{
                break;
            }
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3620
use List::Util qw(max min sum);

my ($d) = split(/\s+/, <>);
my (@c) = (-1, split(/\s+/, <>));

my @s = ();
for my $i (1..$d) {
    $s[$i] = [-1, split(/\s+/, <>)];
}

sub score {
    my (@contest) = @_;
    my $ret = 0;
    my @last = (-1); for (1..26) { push @last, 0; }
    my $j = 1;

    for my $i (@contest) {
	$ret += $s[$j][$i];
	$last[$i] = $j;
	for (1..26) {
	    $ret -= $c[$_] * ($j-$last[$_]);
	}
	$j++;
    }
    return $ret;
}

sub max_index {
    my (@list) = @_;
    my $maxi = 0;
    for (my $i=0; $i<scalar(@list); $i++) {
	$maxi = $i if $list[$maxi] < $list[$i];
    }
    return $maxi;
}

sub over_index {
    my ($val, @list) = @_;
    my @ret = ();
    for (my $i=0; $i<scalar(@list); $i++) {
	push @ret, $i if $list[$i] > $val;
    }
    return @ret;
}

my @last = (-1); for (1..26) { push @last, 0; }
my @cont = ();
for my $j (1..$d) {
    my $max = max(@{$s[$j]});
    my @can = over_index($max*0.9, @{$s[$j]});
    #print "$j: ", join(",", @can), "\n";
    
    my $index = -1;
    my $maxre = 0;
    for my $i (@can) {
	my $re = $s[$j][$i] + $c[$i] * ($j-$last[$i]);
	if ($maxre < $re) { $maxre=$re; $index = $i; }
    }
    #push @cont, max_index(@{$s[$j]});
    push @cont, $index;
    $last[$index] = $j;
}

print join("\n", @cont), "\n";
#print score(@cont), "\n";


Measured memory_bytes: 6604
///*Bismillahir Rahmanir Rahim***///
/***Stay_Home_Stay_Safe***/
///**Author Thasin Sheikh**///
/*while(a)
    {
        if(a%2==0)
            dvi.push_back(0);
        else
            dvi.push_back(1);
        a/=2;
    }
    reverse(dvi.begin(),dvi.end());*/
#include<bits/stdc++.h>
using namespace std;
#define MAX 35000
#define makefast__  ios_base::sync_with_stdio(false);
using ll=long long int  ;
using dl =double;
const int N = 2e5 + 10;
ll aarray[200000+10];
ll magic[101][101];
vector<ll>primes;
bool fk[1000001];

int main()
{
    makefast__
    string str;
    ll a,c,d,e,f,x,y,t,A=0,B=0,L,j,i,l,r,m,n,C=0,ans=0,sum=0,sum1=0;
    vector<ll>v,v1;
    queue<ll>qu;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>aarray[i];
        A+=aarray[i];
    }
    A-=n;
    cout<<A<<endl;

}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  cin >> n;
  cin.ignore();
  while(n--) {
    int h,m;
    scanf("%d:%d\n",&h,&m);
    double angh = h * 30 + m / 2.0;
    double angm = m * 6;
    if (angh<angm) swap(angm,angh);
    double ang = min(angh-angm, angm-angh+360);
    if (ang < 30)
      cout << "alert";
    else if (ang >= 90)
      cout << "safe";
    else
      cout << "warning";
    cout << endl;
  }
}

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

int main()
{
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<vector<int> > query(Q, vector<int>(4));
  for (int i = 0; i < Q; i++) cin >> query.at(i).at(0) >> query.at(i).at(1) >> query.at(i).at(2) >> query.at(i).at(3);
  vector<int> A(N, 1);
  A.at(0) = 1;
  int now = N-1;
  int ans = 0;
  while(A.at(0) != M+1)
  {
    if (now == N-1)
    {
      for (int i = A.at(now-1); i <= M; i++)
      {
        A.at(now) = i;
        int tmp = 0;
        for (int j = 0; j < Q; j++)
        {
          if (A.at(query.at(j).at(1)-1) - A.at(query.at(j).at(0)-1) == query.at(j).at(2)) tmp += query.at(j).at(3);
        }
        ans = max(ans, tmp);
      }
    }
    while(A.at(now) == M && now != 0) now--;
    A.at(now)++;
    while(now != N-1)
    {
      now++;
      A.at(now) = A.at(now-1);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int l,r,d;
  cin >> l >> r >> d;
  int cnt = 0;
  REP(i,l,r+1){
    if(i % d == 0) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3584
# import itertools
import math
# import sys
# import numpy as np

K = int(input())
# S = input()
# n, *a = map(int, open(0))
# K, N = map(int, input().split())
# A = list(map(int, input().split()))
# Q = list(map(int, input().split()))
# S = input()

# d = sorted(d.items(), key=lambda x:x[0]) # keyでsort

tot = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        gcd_ab = math.gcd(a, b)
        for c in range(1, K + 1):
            tot += math.gcd(gcd_ab, c)

print(tot)

Measured memory_bytes: 8988
#include<bits/stdc++.h>
#define N 105
using namespace std;

int h, w;
string s[N];
int cnt[300];
int used[N][N];

int main(){

  cin>>h>>w;

  for(int i=0;i<h;i++){
    
    cin>>s[i];
    
    for(int j=0;j<w;j++)
      cnt[s[i][j]]++;
    
  }

  bool ans=true;
  
  for(int i=0;i<h;i++){

    if(h%2&&i>h/2) continue;
    if(!(h%2)&&i>=h/2) continue;
    
    for(int j=0;j<w;j++){
      
      if(w%2&&j>w/2) continue;
      if(!(w%2)&&j>=w/2) continue;
      
      if(used[i][j]) continue;
    
      int C=0;

      if(h%2&&i==h/2) C++;
      if(w%2&&j==w/2) C++;

      if(!C){

	int flag=0;
	
	for(int k=0;k<300;k++){
	  if(cnt[k]>=4){
	    cnt[k]-=4;
	    flag=1;
	    break;
	  }
	}

	if(!flag) ans=false;
	
	used[i][j]=true;
      }
      
    }
    
  }
  
  for(int i=0;i<h;i++){

    if(h%2&&i>h/2) continue;
    if(!(h%2)&&i>=h/2) continue;
    
    for(int j=0;j<w;j++){
      
      if(w%2&&j>w/2) continue;
      if(!(w%2)&&j>=w/2) continue;
      
      if(used[i][j]) continue;
      
      int C=0;

      if(h%2&&i==h/2) C++;
      if(w%2&&j==w/2) C++;

      if(C==1){

	int flag=0;
	
	for(int k=0;k<300;k++){
	  if(cnt[k]>=2){
	    cnt[k]-=2;
	    flag=1;
	    break;
	  }
	}

	if(!flag) ans=false;
	
	used[i][j]=true;
      }
      
    }
    
  }
  
  for(int i=0;i<h;i++){

    if(h%2&&i>h/2) continue;
    if(!(h%2)&&i>=h/2) continue;
    
    for(int j=0;j<w;j++){
      
      if(w%2&&j>w/2) continue;
      if(!(w%2)&&j>=w/2) continue;

      if(used[i][j]) continue;
      
      int C=0;

      if(h%2&&i==h/2) C++;
      if(w%2&&j==w/2) C++;

      if(C==2){

	int flag=0;
	
	for(int k=0;k<300;k++){
	  if(cnt[k]>=1){
	    cnt[k]-=1;
	    flag=1;
	    break;
	  }
	}

	if(!flag) ans=false;
	
	used[i][j]=true;
      }
      
    }
    
  }

  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    
    long long b=0;
    for(int i=0;i<N;++i){
        int a;
        cin>>a;
        b|=a;
    }
    
    int cnt=0;
    while(!(b&1)){
        b>>=1;
        ++cnt;
    }
    
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
int a[3];

int main(){
	cin>>n;
	ll res=1;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		int t=0;
		for(int j=0;j<3;j++) if(a[j]==x){
			if(!t) a[j]++;
			t++;
		}
		(res*=t)%=mod;
	}
	cout<<res<<endl;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

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

void Main(){
    ll N; cin >> N;
    VL A(N); REP(i,N) cin >> A[i];
    ll sum = 0; REP(i,N) sum += A[i];

    if(sum % (N*(N+1)/2) != 0){
        cout << "NO" << en;
        return;
    }

    ll k = sum / (N*(N+1)/2);
    VL m(N);
    REP(i,N){
        ll d = A[(i+1)%N] - A[i];
        if(k-d<0 || (k-d)%N!=0){
            cout << "NO" << en;
            return;
        }

        m[(i+1)%N] = (k-d) / N;
    }

    sum = 0; REP(i,N) sum += m[i];
    cout << (sum==k ? "YES" : "NO") << en;
    return;
}

int main(void){
    cin.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t){
        Main();
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h> 
using namespace std;
const int INF = 1e9+5;
const int MOD = 1e9+7;
double pi = 2 * acos(0.0); 
double calcAngle(double h, double m) 
{ 
	if (h == 12) h = 0; 
	if (m == 60) m = 0; 
	double hour_angle = 0.5 * (h * 60 + m); 
	double minute_angle = 6 * m; 

	double angle = abs(hour_angle - minute_angle); 
	angle = min(360 - angle, angle); 
    //setprecision(20) ;
	return angle; 
} 
int main() 
{ 
	 int a,b,h,m;
	 cin>>a>>b>>h>>m;
	 double ang=calcAngle((double)h,(double)m);
	 double rad=(ang*pi)/180;
	 cout << fixed << setprecision(15) << sqrt((a * a) + (b * b) - 2 * a * b * cos(rad));
	//return 0; 
} 


Measured memory_bytes: 4156
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
#define X real()
#define Y imag()
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;

double dot(xy_t a, xy_t b){
    return (conj(a) * b).X;
}

double cross(xy_t a, xy_t b){
    return (conj(a) * b).Y;
}

pair<xy_t, xy_t> cc_inter(xy_t a, double r, xy_t b, double s){
    double d = abs(a - b);
    double t = (r*r - s*s + d*d) / (2*d);
    double x = sqrt(r*r - t*t);
    xy_t v = t/d * (b-a) + a;
    xy_t u = x/d * (b-a) * xy_t(0, 1);
    return make_pair(v+u, v-u);
}

double f(xy_t a, xy_t b, xy_t c){
    return (b.Y-a.Y)*(c.X-a.X) - (b.X-a.X)*(c.Y-a.Y);
}

bool is_crossing(xy_t a, xy_t b, xy_t c, xy_t d){
    bool b1 = f(a, b, c) * f(a, b, d) <= 0;
    bool b2 = f(c, d, a) * f(c, d, b) <= 0;
    return b1 & b2;
}

int n;
double d[210][210];
xy_t p[210];

int main(){
    while(scanf("%d", &n) && n){
        double x[110], y[110], r[110];
        rep(i, n) scanf("%lf%lf%lf", &x[i], &y[i], &r[i]);
        p[0] = xy_t(x[0], y[0]);
        p[2*n-1] = xy_t(x[n-1], y[n-1]);
        rep(i, n-1){
            auto tmp = cc_inter(xy_t(x[i], y[i]), r[i], xy_t(x[i+1], y[i+1]), r[i+1]);
            p[i*2+1] = tmp.fi;
            p[i*2+2] = tmp.se;
        }
        rep(i, 2*n){
            rep(j, 2*n) d[i][j] = 1e18;
            d[i][i] = 0;
        }
        rep(i, 2*n-1)For(j, i+1, 2*n){
            bool flag = true;
            for(int k=(i+1)/2*2+1; k<(j-1)/2*2; k+=2){
                if(!is_crossing(p[i], p[j], p[k], p[k+1])){
                    flag = false;
                    break;
                }
            }
            if(flag) d[i][j] = d[j][i] = abs(p[i] - p[j]);
        }
        rep(k, 2*n)rep(i, 2*n)rep(j, 2*n)if(d[i][k] < 1e18 && d[k][j] < 1e18){
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
        printf("%.10lf\n", d[0][2*n-1]);
    }
}


Measured memory_bytes: 3528
s = input()
q = int(input())

from collections import deque

ss = deque(s)
flg = True

for i in range(q):
  t = input().split()
  if t[0] == '1':
    flg = not flg
  else:
    if t[1] == '2':
        ss.append(t[2]) if flg else ss.appendleft(t[2])
    else:
        ss.append(t[2]) if not flg else ss.appendleft(t[2])

ss = list(ss)

print("".join(ss)) if flg else print("".join(ss[::-1]))



Measured memory_bytes: 10100
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  int N;
  lint ans=0;
  cin >> N;
  lint a[N];
  rep(i,N) cin >> a[i];
  rep(i,N) a[i]--;
  lint place[N];
  rep(i,N) place[a[i]]=i;
  set<lint> save{-1,N};
  rep(i,N){
    lint now=place[i];
    lint l,r;
    auto tmp=save.lower_bound(now);
    r=*tmp;
    tmp--;
    l=*tmp;
    ans+=(i+1)*(r-now)*(now-l);
    save.insert(now);
  }
  cout << ans << endl;
}

Measured memory_bytes: 12800
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

int main(){
    long long N;

    cin >> N;

    cout << (N * (N - 1)) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int check(string s, string t) {
    int n = s.size();
    assert(t.size() == n);
    int ans = 0;
    rep(i, n) {
        if (s[i] != t[i]) ans++;
    }
    return ans;
}

int main() {
    string s, t;

    cin >> s >> t;

    int ans = INT_MAX;
    for (int i = 0; i <= s.size() - t.size(); i++) {
        int now = check(s.substr(i, t.size()), t);
        cmin(ans, now);
    }
    cout << ans << endl;


}


Measured memory_bytes: 3640
N = int(input())
A = tuple(map(int, input().split()))
assert len(A) == N

# 出席番号iの生徒が到着した時点でAi人が到着済み(i含む)
print(' '.join(list(map(str, sorted(range(1,N+1), key=lambda v:A[v-1])))))

Measured memory_bytes: 92160
#include<cstdio>
int max(int x,int y) {return x>y?x:y;}
int abs(int x) {return x>0?x:-x;}
int main()
{
	int n,x,y,a,b;
	scanf("%d%d%d",&n,&x,&y);
	if(n==1)
	{
		scanf("%d",&a);
		return printf("%d\n",abs(a-y)),0;
	}
	for(int i=1;i<=n;i++) a=b,scanf("%d",&b);
	printf("%d\n",max(abs(b-y),abs(a-b)));
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 100
using namespace std;
char Map[MAXN+5][MAXN+5];
int n,m,ex,ey;
int sumr[MAXN+5][MAXN+5],sumc[MAXN+5][MAXN+5];
int dp[MAXN+5][MAXN+5][MAXN+5];
void Init()
{
	memset(dp,-1,sizeof(dp));
}
int main()
{
//	freopen("robot.in","r",stdin);
//	freopen("robot.out","w",stdout);
	Init();
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",Map[i]+1);
		for(int j=1;j<=m;j++)
		{
			sumr[i][j]=sumr[i][j-1];
			sumc[i][j]=sumc[i-1][j];
			if(Map[i][j]=='E')
				ex=i,ey=j;
			else if(Map[i][j]=='o')
			{
				sumr[i][j]++;
				sumc[i][j]++;
			}
		}
	}
	int L,R,U,D,ans=0;
	L=ey-1;
	R=m-ey;
	U=ex-1;
	D=n-ex;
	dp[0][0][0]=0;
	for(int l=0;l<=L;l++)
		for(int r=0;r<=R;r++)
			for(int u=0;u<=U;u++)
				for(int d=0;d<=D;d++)
				{
					if(dp[r][u][d]==-1)
						continue;
					ans=max(dp[r][u][d],ans);
					int up=max(ex-u,d+1);
					int down=min(ex+d,n-u);
					int left=max(ey-l,r+1);
					int right=min(ey+r,m-l);
					if(up>down||left>right)
						continue;
					int add;
					if(u<U-d)
					{
						add=sumr[ex-u-1][right]-sumr[ex-u-1][left-1];
						dp[r][u+1][d]=max(dp[r][u+1][d],dp[r][u][d]+add);
					}
					if(d<D-u)
					{
						add=sumr[ex+d+1][right]-sumr[ex+d+1][left-1];
						dp[r][u][d+1]=max(dp[r][u][d+1],dp[r][u][d]+add);
					}
					if(r<R-l)
					{
						add=sumc[down][ey+r+1]-sumc[up-1][ey+r+1];
						dp[r+1][u][d]=max(dp[r+1][u][d],dp[r][u][d]+add);
					}
					if(l<L-r)
					{
						add=sumc[down][ey-l-1]-sumc[up-1][ey-l-1];
						dp[r][u][d]=max(dp[r][u][d],dp[r][u][d]+add);
					}
				}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4736
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let n: i64 = buf.trim().parse().unwrap();

    let mut count: i64 = 0;

    for i in 1..n + 1 {
        if i % 3 != 0 && i % 5 != 0 {
            count += i;
        }
    }

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


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

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++) // repマクロ
#define all(v) v.begin(), v.end() // sort等の関数呼び出しを簡潔にする

using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

int main() {
    string S;
    cin >> S;

    if((S == "AAA") || (S == "BBB")){
        cout << "No" << endl;
    } else{
        cout << "Yes" << endl;
    }
return 0;
}

Measured memory_bytes: 256
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;
const auto red = '0';
const auto blue = '1';

int main()
{
    string s;
    cin >> s;
    const int n = int(s.length());
    int cnt = 0;

    string skipped;
    skipped.reserve(n);
    skipped.push_back('*');

    for (int i = 0; i < n; ++i) {
        auto t = s[i] == '0' ? '1' : '0';
        if (skipped.back() == t) {
            skipped.pop_back();
            cnt += 2;
            continue;
        }
        skipped.push_back(s[i]);
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3848
/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/

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

int main(){

  int n;
 cin>>n;
 bool isOK = false;

 for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
        if(i*j == n){
          cout<<"Yes"<<endl;
            return 0;
           }
    }
 }


 cout<<"No"<<endl;

return 0;
}

Measured memory_bytes: 256
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int A = Integer.parseInt(st.nextToken());
         int B = Integer.parseInt(st.nextToken());
         int C = Integer.parseInt(st.nextToken());
         int D = Integer.parseInt(st.nextToken());
         double a1 = (C+1.0*D/60)*(Math.PI/6.0);
         double a2 = 2*Math.PI*(1.0*D/60);
         double dif = Math.abs(a1-a2);
         dif = Math.min(dif, 2*Math.PI-dif);
         double res = A*A+B*B-2*A*B*Math.cos(dif);
         System.out.println(Math.sqrt(res));
      }
   }

Measured memory_bytes: 33312
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n, k;
	cin >> n >> k;
	vi a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	if(a.back() < k) {
		cout << "IMPOSSIBLE" << endl;
		return 0;
	}
	if(n == 1) {
		cout << (a[0] == k ? "POSSIBLE":"IMPOSSIBLE") << endl;
		return 0;
	}
	int g = __gcd(a[0], a[1]);
	REP(i, 2, n) g = __gcd(g, a[i]);
	cout << (k%g == 0 ? "POSSIBLE": "IMPOSSIBLE") << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main()
{
  int n, k, ans = 0;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p.at(i);
  sort(p.begin(), p.end());
  rep(i, k) ans += p[i];
  cout << ans;
}


Measured memory_bytes: 3556
#include <iostream>
#include <deque>
#include <vector>

using namespace std;

vector <int> v[100010];
int used[100010];
deque <int> ans;

void df1(int x)
{
    used[x]=1;
    ans.push_back(x);
    for(auto it:v[x])
        if(!used[it])
        {
            df1(it);
            return;
        }
}

void df2(int x)
{
    used[x]=1;
    if(x!=1)
    ans.push_front(x);
    for(auto it:v[x])
        if(!used[it])
        {
            df2(it);
            return;
        }
}

int main()
{
    int i,n,m,a,b;
    cin>>n>>m;
    for(i=1; i<=m; ++i)
    {
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    df1(1);
    df2(1);
    cout<<ans.size()<<'\n';
    for(auto it:ans)
        cout<<it<<' ';
}


Measured memory_bytes: 7040
//use std::io::{stdout, Write, BufWriter}

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::min;

fn main() {
    input!{
        n: i64,
        k: i64,
    }
    let n = n % k;
    println!("{}", min(n, k - n));
}


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

using namespace std;

int N;
string S;

int main(void)
{
	cin >> N;
	cin >> S;
	
	int x = 0, ans = 0;
	for(int i = 0; i < S.size(); i++){
		if(S[i] == 'I') x++;
		else x--;
		ans = max(ans, x);
	}
	
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}

#define deb(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define END '\n'
#define inf 9e18
#define ff first
#define ss second
#define pb push_back

void solve(){
    int a, b;
    cin >> a >> b;
    if (a == 1) a += 100;
    if (b == 1) b += 100;
    cout << (a >= b ? (a == b ? "Draw" : "Alice") : "Bob");
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3580
/*
 * Created by KeigoOgawa
 */


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <cmath>

#define INF (int)1e8
#define EPS 1e-10
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define debug(x) cout << #x << ": " << x << endl
#define all(a) (a).begin(), (a).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;

string s;

void solve() {
  bool x = s.size() % 2 == 0 ? 1 : 0;
  bool y = s[0] == s[s.size() - 1] ? 1 : 0;
  if ((x ^ y) == 0) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s;
  solve();
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int main ( )
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
if (a>=0 && a<=100 && b>=0 && b<=100 && c>=0 && c<=100)
    {
    if(a<b && c>b)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    }

return 0;
}






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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  string a, b;
  cin >> a >> b;

  int c = stoi(a + b);

  bool flag = false;
  for (int i = 1; i * i <= c; i++) {
    if (c == i * i) flag = true;
  }
  printf("%s\n", flag ? "Yes" : "No");
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

def check(x):
    cnt = 0
    for a in A:
        cnt += (a + x - 1) // x - 1
    return cnt <= K

left = 0
right = 10 ** 9
while right - left > 1:
    mid = (left + right) // 2
    if check(mid):
        right = mid
    else:
        left = mid
print(right)

Measured memory_bytes: 30724
#include <iostream>

using namespace std;

int n,x,a,br = 1;

int main()
{
	cin >> n >> x;
	a = 2*n-1;
	if(x == 1 || x == a)
	{
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	if(x > 2)
	{
		for(int i = 0;i < a;i++)
		{
			if(br == x-2)
				br=x+2;
			if(i == n-1)
			{
				cout << x << endl;
				continue;
			}
			if(i == n-2)
			{
				cout << x-1 << endl;
				continue;
			}
			if(i == n)
			{
				cout << x+1 << endl;
				continue;
			}
			if(i == n+1)
			{
				cout << x-2 << endl;
				continue;
			}
			cout << br << endl;
			br++;
		}
	} else {
		for(int i = 0;i < a;i++)
		{
			if(br == x-1)
				br=x+3;
			if(i == n-1)
			{
				cout << x << endl;
				continue;
			}
			if(i == n-2)
			{
				cout << x+1 << endl;
				continue;
			}
			if(i == n)
			{
				cout << x-1 << endl;
				continue;
			}
			if(i == n+1)
			{
				cout << x+2 << endl;
				continue;
			}
			cout << br << endl;
			br++;
		}	
	}
	return 0;	
}

Measured memory_bytes: 1536
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#define int long long 
using namespace std;

int32_t main()
{
    int a,b;
    cin>>a>>b;
    if(a==1||b==1) cout<<1<<endl;
    else {
        if((a*b)%2!=0) cout<<(a*b)/2+1<<endl;
        else cout<<(a*b)/2<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
t = gets.chomp.split.map &:to_i

h = Hash.new(0)
t.each do |d|
  h[d] += 1
end
t = t.uniq.sort{|a,b|b<=>a}
f = true
if(h[t[0]] != 1)
  f = false
end
t.delete_at(0)

tree  = Array.new(n, 0)
max   = Array.new(n, 0)
n.times{|i|max[i] = 2**i}

t.each do |d|
  able  = 1
  stock = h[d]
  n.times do |i|
    plable = tree[i]
    if(tree[i]<max[i])
      note    = [[max[i]-tree[i], able-tree[i], stock].min, 0].max
      tree[i] += note
      stock   -= note
    end
    able  += plable
  end
  f = false if(stock != 0)
end

puts (f)? "Yes" : "No"


Measured memory_bytes: 58388
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
ll a[1000];
int main()
{
    ll n,i,j,ci=0;
    scanf("%lld",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        if((i%2==1)&&(a[i]%2==1))
            ci++;
    }
    printf("%lld\n",ci);
    return 0;
}


Measured memory_bytes: 3752