akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1};
int dy[]={0,1,0,-1,1,1,};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/


signed main(){
  string t;
  cin>>t;

  int n=t.size();
  rep(i,n){
    if(t[i]=='?'){

      t[i]='D';
    }
  }

  cout<<t<<endl;
  return 0;
}


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

int main(){

    int a, b, c;
    cin >> a >> b >> c;

    int maior_lado = max(a, b);
    maior_lado = max(maior_lado, c);

    if(maior_lado == a){
        cout << b * c/2 << endl;
    } else if(maior_lado == b){
        cout << a * c/2 << endl;
    } else {
        cout << a * b/2 << endl;
    }

    return 0;
}

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

student_arr = [(A[i], i) for i in range(N)]
student_arr.sort()

res = ''
for i in range(N):
    res += str(student_arr[i][1] + 1)
    if i < N - 1:
        res += ' '

print(res)

Measured memory_bytes: 24208
k,a,b = map(int,input().split())
k -= a-1
div,mod = divmod(k,2)
ans = 1 + (a-1)
if a+2 <= b:
    dum = b-a
    ans += dum*div
    if mod == 1:
        ans += 1
else:
    ans += k
print(ans)

Measured memory_bytes: 2940
S = gets.chomp.chars

color = '0'
count1 = 0
S.each do |c|
  count1 += 1 if c != color
  color = color == '0' ? '1' : '0'
end

color = '1'
count2 = 0
S.each do |c|
  count2 += 1 if c != color
  color = color == '0' ? '1' : '0'
end

ans = [count1, count2].min
puts ans


Measured memory_bytes: 9468
#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

int main()
{
    int n;
    cin >> n;
    long m;
    cin >> m;

    map<long,long> r;
    long  t = 0;
    long a;
    for(int i = 0;i<n;i++){
       cin >> a;
       t = (t+a) % m;
       r[t]++;
    }
    long long k = 0;
    if(r[0]!=0){
    k += ((1+r[0])*r[0])/2;}
    
    
    for(auto itr = r.begin(); itr != r.end(); ++itr) {
        if(itr->second!=0 && itr->first!=0){
            k+= (itr->second*((itr->second)-1))/2;
            
             
        }
    }
    
    
    cout << k ;
    return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define mp map<int,int>
#define pp make_pair
#define endl "\n"
#define vi vector<int>
#define vbl vector<bool>
#define ll long long 
#define clock high_resolution_clock::now()

// auto duration = duration_cast<microseconds>(stop - start);  cout<<duration.count();

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

using namespace std;
using namespace std::chrono;

int main(){
     int N; ll int x;
     cin>>N>>x;
     vector<ll> v(N+1, 0);
     for(int i=1; i<=N; i++)cin>>v[i];
     ll int ans = 0;
     ll int t = 0;
     for(int i=1; i<=N; i++){
          if(v[i]+v[i-1]>x){
               t = v[i] + v[i-1]-x;
               ans+=t;
               v[i]-=t;
          }
     }
     cout<<ans<<endl;
               
               
               
     
     
	return 0;
}
	
	

Measured memory_bytes: 4056
#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;

  //順列を格納する
  vector<int> p(n);
  rep(i,n) cin >> p[i];

  int ans = 0;
  int curmin = 1e9;//範囲の最大値

  //各要素の最小値が自分自身の時カウントアップ
  rep(i,n) {
    curmin = min(curmin,p[i]);
    if (curmin == p[i]) ans++;
  }

  cout << ans << endl;
}

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

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 998244353

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ll n, m, x;
    cin >> n >> m;
    vvi sw(m);
    REP(i, 0, m) {
        cin >> x;
        sw[i].resize(x);
        REP(j, 0, x) {
            cin >> sw[i][j];
            sw[i][j]--;
        }
    }
    vi p(m);
    REP(i, 0, m)
        cin >> p[i];
    ll ans = 0, poss;
    REP(i, 0, (1 << n)) {
        bitset<10> cs(i);
        poss = 1;
        REP(j, 0, m) {
            ll t = 0;
            REP(k, 0, sw[j].size())
                t += cs[sw[j][k]];
            if (t%2 != p[j]) {
                poss = 0;
                break;
            }
        }
        if (poss)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
#define MAX 1401

int c[MAX][MAX], C[MAX][MAX], H, W;

void dp() {
    int Max = 0;

    for (int i=0; i<=H; i++) C[i][0] = 0;
    for (int i=0; i<=W; i++) C[0][i] = 0;

    for (int i=1; i<=H; i++) {
        for (int j=1; j<=W; j++) {
            if (c[i][j]==1) C[i][j] = 0;
            else {
                C[i][j] = min(C[i-1][j-1], min(C[i-1][j], C[i][j-1])) + 1;
                Max = max(Max, C[i][j]);
            }
        }
    }

    printf("%d\n", Max*Max);
}

int main() {
    scanf("%d %d", &H, &W);

    for (int i=1; i<=H; i++) {
        for (int j=1; j<=W; j++) {
            scanf("%d", &c[i][j]);
        }
    }

    dp();

    return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n,x=0,ans=0;;
    string s;
    cin>>n>>s;
    
    for(int i = 0; i < n; i++)
    {
        if(s[i]=='I')
        {
            x++;
            ans=max(ans,x);
        }
        else
        {
            x--;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 384
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int x = sc.nextInt();
		for(int i = x-k+1; i < x+k; i++){
			System.out.print(i + " ");
		}
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

int N,M,H[MAXN];
bool good[MAXN];
main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>M;
	FOR(i,1,N) cin>>H[i];
	memset(good,1,sizeof good);
	FOR(i,1,M){
		int a,b;cin>>a>>b;
		if (H[a]<=H[b]) good[a]=0;
		if (H[b]<=H[a]) good[b]=0;
	}
	int ans=0;
	FOR(i,1,N) ans+=good[i];
	cout<<ans;
}


Measured memory_bytes: 4144
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1<<30;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[8]={1,0,-1,0,1,1,-1,-1} , dy[8]={0,1,0,-1,1,-1,1,-1} ;

int main(){
    string s,t;
    cin>>s>>t;
    rep(i,200){
        if(s==t){
            cout<<"Yes"<<endl;
            return 0;
        }
        t=t.substr(1)+t[0];
    }
    cout<<"No"<<endl;
    return 0;
}


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

vector<int> par,rk;

void init(const int n){
	par.resize(n);
	rk.resize(n);
	for(int i=0;i<n;++i) par[i]=i;
	fill(rk.begin(),rk.end(),0);
}

int find(int x){
	if(par[x]==x){
		return x;
	}else{
		return par[x]=find(par[x]);
	}
}

void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y){
		return;
	}else if(rk[x]<rk[y]){
		par[x]=y;
	}else{
		par[y]=x;
		if(rk[x]==rk[y]){
			++rk[x];
		}
	}
}

bool same(int x,int y){
	return find(x)==find(y);
}

struct edge{
	int from,to;
	ll cost;
};

bool cmp(edge e,edge f){
	return e.cost<f.cost;
}

#define MAX_Q 100000

vector<edge> es;

#define MAX_N 4000

vector<int> g[MAX_N];
ll d[MAX_N][MAX_N];

void dfs(int v0,int v){
	for(int j=0;j<g[v].size();++j){
		int e=g[v][j],w=es[e].from;
		if(v==w) w=es[e].to;
		if(d[v0][w]>=0) continue;
		d[v0][w]=max(d[v0][v],es[e].cost);
		dfs(v0,w);
	}
}

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	while(m-->0){
		int a,b,c;
		cin>>a>>b>>c;
		es.pb((edge){--a,--b,c});
	}
	sort(es.begin(),es.end(),cmp);
	init(n);
	ll sc=0;
	for(int j=0,e=0;e<n-1;++j){
		int v=es[j].from,w=es[j].to;
		if(same(v,w)) continue;
		unite(v,w);
		sc+=es[j].cost;
		g[v].pb(j);
		g[w].pb(j);
		++e;
	}
	for(int v=0;v<n;++v){
		fill(d[v],d[v]+n,-1);
		d[v][v]=0;
		dfs(v,v);
	}
	int q;
	scanf("%d",&q);
	while(q-->0){
		int s,t;
		scanf("%d%d",&s,&t);
		printf("%lld\n",sc-d[--s][--t]);
	}
}

Measured memory_bytes: 134504
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
#define sqr(x) (x) * (x)

#include <iomanip>
int main() {
    cout << fixed << setprecision(12);
    int n; cin >> n;
    vector<int> r(n);
    for (int &ri: r) cin >> ri;
    vector<double> x(n);
    for (int i = 0; i < n; i++) x[i] = r[i];
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < i; j++) {
            double d = x[j] + sqrt(sqr(r[i] + r[j]) - sqr(r[i] - r[j]));
            chmax(x[i], d);
        }
    }
    double ans = 0;
    for (int i = 0; i < n; i++) chmax(ans, x[i] + r[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3276
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    string s;
    cin >> s;
    ll ans=0;
    ll a=0;
    rep(i,s.size()){
        if(s[i]=='A')a++;
        else if(i+1<s.size()&&s[i]=='B'&&s[i+1]=='C'){
            i++;ans+=a;
        }
        else {
            a=0;
        }
    }
    cout << ans <<endl;
}

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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  bool poss = false;
  for (int i = a; i <= b; ++i) {
    if (i % k == 0) {
      poss = true;
      break;
    }
  }

  if (poss) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll n, t; cin >> n >> t;
    vector<ll> a(n); rep(i,n) cin >> a[i];
    ll ans = 0;
    rep(i,n-1) ans += min(t,a[i+1] - a[i]);
    ans += t;

    cout << ans << endl;
}

Measured memory_bytes: 1792
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


n = inp()
a = inpl()
a_ = set(a)
if len(a) == len(a_):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 122056
/*
¸ø¶¨µÄÊÇÒ»¸öÕûÊýn¡£ÇóÐ¡ÓÚ»òµÈÓÚnµÄÕýÕûÊýµÄ¸öÊý£¬ÆäÎ»ÊýÎªÆæÊý£¨10½øÖÆ£¬²»´øÇ°µ¼Áã£©¡£
*/

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n,ans;
inline bool check(int x) {
	int sum = 0;
	while(x) {
		x /= 10; ++sum; 
	}
	return sum%2;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) {
		if(check(i)) ++ans;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;

const int MAX_N = 100000;
const int MAX_Q = 100000;
const long long UB = 1000000000;

long long A[MAX_N];
int N;

long long eSum[MAX_N], oSum[MAX_N];
long long sum[MAX_N];

bool lt(int x, int a, int b){
	long long d1 = abs(x - A[a]);
	long long d2 = abs(x - A[b]);
	if(d1 < d2) return true;
	return false;
}

long long calc(int r, int d){
	if(r < 0) return 0;
	if(d == 0) return eSum[r];
	else if(d == 1) return oSum[r];
	else return sum[r];
}

long long calc(int l, int r, int d){
	if(l > r) return 0;
	return calc(r, d) - calc(l - 1, d);
}

long long query(int x){
	int lb = 1, ub = N + 1;
	while(ub - lb > 1){
		int mid = (lb + ub) / 2;
		int a = mid / 2;
		int b = mid / 2;
		if(a + b < mid) a++;
		int l = N - mid;
		int r = N - a - 1;
		// take [l, r]
		if(lt(x, r + 1, l)) ub = mid;
		else lb = mid;
	}
	// lb cards: no conflict
	int a = (lb + 1) / 2;
	int d = N % 2;
	long long ans = calc(0, N - lb - 1, d) + calc(N - lb, N - a - 1, -1);
	return sum[N - 1] - ans;
}

int main(){
	int Q;
	scanf("%d%d", &N, &Q);
	for(int i = 0; i < N; ++i) scanf("%lld", A + i);
	sum[0] = A[0];
	for(int i = 1; i < N; ++i) sum[i] = sum[i - 1] + A[i];
	eSum[0] = A[0];
	for(int i = 1; i < N; ++i) eSum[i] = eSum[i - 1] + (i % 2 == 0 ? A[i] : 0);
	oSum[0] = 0;
	for(int i = 1; i < N; ++i) oSum[i] = oSum[i - 1] + (i % 2 == 1 ? A[i] : 0);
	for(int i = 0; i < Q; ++i){
		long long x;
		scanf("%lld", &x);
		long long ans = query(x);
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 4736
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, n, k, ans = -1e15, sum = 0, now1 = 0, now2 = 0;
  scanf("%lld%lld", &n, &k);
  ll a[n];
  for(i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
    if(i < k) {
      if(a[i] < 0) now1 += a[i];
      else now2 -= a[i];
    } else {
      if(now1 > ans) ans = now1;
      if(now2 > ans) ans = now2;
      if(a[i] < 0) now1 += a[i];
      else now2 -= a[i];
      if(a[i - k] < 0) now1 -= a[i - k];
      else now2 += a[i - k];
    }
    if(a[i] > 0) sum += a[i];
  }
  if(now1 > ans) ans = now1;
  if(now2 > ans) ans = now2;
  if(ans + sum > 0) printf("%lld", ans + sum);
  else printf("0");
  return 0;
}

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

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

  for(int i=1; i<=n; i++){
    int x = i;
    if(x%3 == 0){
      cout << " " << i;
      continue;
    }
    while(x != 0){
      if(x%10 == 3){
        cout << " " << i;
        break;
      }
      x /= 10;
    }
  }
  cout << endl;

}

Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    string s;
    cin >> s;
    int times = 0;
    char last = s[0];
    int length = s.length();
    for (int i=1; i < length; i++){
        if (s[i] == last){
            times += 1;
            if (s[i] == '0'){
                s[i] = '1';
                last = '1';
            }
            else if (s[i] == '1'){
                s[i] = '0';
                last = '0';
            }
        }
        else{
            last = s[i];
        }
    }
    cout << times << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N; cin>>N;
	double p[N];
    rep(i,0,N) cin>>p[i];
	double dp[N+1][N+1] = {}; dp[0][0] = 1;
	rep(i,1,N+1){
		dp[i][0] = (1 - p[i-1]) * dp[i-1][0];
		rep(j,1,N+1){
			dp[i][j] = p[i-1] * dp[i-1][j-1] + (1 - p[i-1]) * dp[i-1][j];
		}
	}
	double ans = 0;
	rep(i,(N+1)/2,N+1) ans += dp[N][i];
    cout.precision(15);
	cout<<fixed<<ans<<endl;
}

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

int main() {
  int N, n;
  int fn = 0;
  cin >> N;
  n = N;
  while(n > 0){
    fn += (n % 10);
    n /= 10;
  }
  if(N % fn == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	REP(i, t) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[t]=power(fact[t], MOD-2);
	FORR(i, 0, t) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
  int i,ans=0,N,K; cin >> N >> K;
  vector <int>p(N,0); rep(i,N){cin >> p[i];}
  sort(p.begin(),p.end());
  rep(i,K){ans+=p[i];}
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3628
/*
 * atcoder/abc148_2nd/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int N;
vector<int> A;
void solve() {
  cin >> N;
  A.resize(N);
  loop(n,0,N) cin >> A[n];

  int tgt = 1;
  int count = 0;
  loop(n,0,N) {
    if (A[n] == tgt) tgt++;
    else count++;
  }

  if (count == N) cout << -1 << endl;
  else cout << count << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,(e))
#define irp(i,s,e) for(int i=(s);i>(e);--i)
#define irpz(i,s) irp(i,(s),-1)
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T> T in(){T x;cin>>x;return x;}
template<class T> vector<T> inarr(int s,int e, T init=0){
	vector<T> v;T x;
	for(int i=0;i<s;++i)v.push_back(init);
	for(int i=s;i<e;++i){x=in<T>();v.push_back(x);}
	return v;
}
int R,G;
string S;

int solve(){
	return 2*G-R;
}

int main(){
	cin>>R;
	cin>>G;
	cout<< solve() <<endl;
	// printf("%f\n",solve());
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define REP(i,n)  for(int i=0;i<(n);i++)

int main() {
    int n,ans=0;
    cin>>n;
    LL h,w; cin>>h >>w;
    vector<vector<long long>> ab(n,vector<long long>(2));
    for(int i=0;i<n;i++){
        cin>>ab[i][0] >>ab[i][1];
        if(ab[i][0]>=h&&ab[i][1]>=w)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
	int n;
	ll a[200005];
	cin >> n;
	rep(i, n) cin >> a[i];
	map<ll, int> m;
	ll ans = 0;
	rep(i, n) {
		auto it = m.find(i - a[i]);
		if (it != m.end()) {
			ans += it->second;
		}
		auto itn = m.find(a[i] + i);
		if (itn == m.end()) {
			m[a[i] + i] = 1;
		} else {
			itn->second += 1;
		}
		if (i == 3) {
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 17552
n = int(input())
XA ,BA ,BX = 0 ,0 ,0
AB = 0
for i in range(n):
    s = str(input())
    AB += s.count("AB")
    if s[0] == "B":
        if s[-1] == "A":
            BA += 1
        else:
            BX += 1
    else:
        if s[-1] == "A":
            XA += 1

if BA > 1:
    AB += (BA-1)
    BA = 1
if XA:
    if BA:
        AB += 1
        XA -= 1
if BX:
    if BA:
        AB += 1
        BX -= 1
AB += min(XA,BX)
print(AB)

Measured memory_bytes: 44008
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
using namespace std;
typedef long long ll;
ll dx[] = { 0,0,1,1,1,-1,-1,-1 };
ll dy[] = { 1,-1,0,1,-1,0,1,-1};
ll prime(ll x) {
	ll i; 
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (i = 3; i*i <= x; i += 2) {
		if (x%i == 0) return 0;
	}
	return 1;
}
ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}

ll MOD = 1000000007;
int main() {
	string board[100];
	ll X,Y;
	cin >> X >> Y;
	for (ll i = 0; i < X; i++) {
		cin >> board[i];
	}
	for (ll i = 0; i < X; i++) {
		for (ll j = 0; j < Y; j++) {
			if (board[i][j] =='.') {
				ll cnt = 0;
				for (ll k = 0; k < 8; k++) {
					ll x = i + dx[k];
					ll y = j + dy[k];
					if (x >= 0 && x < X&&y >= 0 && y < Y&&board[x][y] == '#')
						cnt++;
				}
				board[i][j] = '0' + cnt;
			}
		}
	}
	for (ll i = 0; i < X; i++)
		cout << board[i] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    vp data;
    int2(n, k);
    rep(i, n) {
        int2(a, b);
        data.pb(i_i(a, b));
    }
    sort(all(data));
    int sum = 0;
    rep(i, n) {
        sum += data[i].second;
        if (sum >= k) {
            cout << data[i].first << endl;
            return 0;
        }
    }


    return 0;
}



Measured memory_bytes: 2420
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int a=in.nextInt(),b=in.nextInt(),c=in.nextInt();
		int o,p,q;
		
		if(a<=b && a<=c) {
			o=a;p=b;q=c;
		}
		else if(c<=b && c<=a) {
			o=c; p=a; q=b;
		}
		else {
			o=b; p=a; q=c;
		}
		
		if(p<q)System.out.printf("%d %d %d\n", o,p,q);
		else System.out.printf("%d %d %d\n", o,q,p);
	}

}



Measured memory_bytes: 26184
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

long long f(long long A, long long B, long long x) {
    return (A * x / B) - A * (x / B);
}

int main() {

    long long A, B, N;
    cin >> A >> B >> N;
    cout << f(A, B, min(B - 1, N)) << endl;
    return 0;
}

Measured memory_bytes: 3612
package main

import (
	"fmt"
)

func main() {
	var w, h, x, y float64
	var halfArea float64
	fmt.Scan(&w, &h, &x, &y)

	halfArea = w * h / 2

	midX := w / 2
	midY := h / 2

	if midX == x && midY == y {
		fmt.Println(halfArea, 1)
	} else {
		fmt.Println(halfArea, 0)
	}
}


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

int main()
{
    int x, ans;
    for (int i = 0; i < 5; i++) {
        cin >> x;
        if (x == 0) {
            ans = i + 1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{
    gearup;
    ll n; cin >> n;
    vs s(n);
    rep(i,n)cin>>s[i];
    ll res = 0;
    rep(a,n){
        bool is_true = true;
        auto ss = s;
        rep(i,n)rep(j,n)ss[i][ (j + a) % n] = s[i][j];
        rep(i,n){
            rep(j,n){
                if(ss[i][j] != ss[j][i])is_true = false;
            }
        }
        if(is_true)res += n;
    }
    out(res);
}


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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll) 1e9 + 7;
constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, rev;
    long double cap;
	Edge(ll _to, long double _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, long double cap, bool revFlag, long double revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
    ll n;
    cin>>n;
    Array a(n),b(n);
    REP(i,n) cin>>a[i]>>b[i];

    sort(all(a));
    sort(all(b),greater<ll>());

    if(n%2){
        ll l1=a[n/2];
        ll r1=b[n/2];
        cout<<r1-l1+1<<en;
    }else{
        ll l1=a[n/2-1];
        ll l2=a[n/2];
        ll r1=b[n/2];
        ll r2=b[n/2-1];
        cout<<r1+r2-l1-l2 + 1<<en;
    }

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 6356
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=200003;
int x[1001];
void primefactor(int n){

  bool flag=true;
  for( int i=2LL ;i*i<=n;i++){
    while(n%i==0){
      x[i]++;
      n/=i;
      flag=false;
    }
  }
  if(n!=1)x[n]++;
}


int main(){
  int n;
  cin>>n;
  int a[101];
  int res=100000000;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=-100;i<=100;i++){
    int tmp=0;
    for(int j=0;j<n;j++){
      tmp+=((i-a[j])*(i-a[j]));
    }
    res=min(tmp,res);
  }
  cout<<res<<endl;
  return 0;
}


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

typedef long long ll;
typedef pair<int,int>P;
#define INF (int)(1e9)
#define EPS (1e-7)
#define MOD ((ll)1e9+7)
#define REP(i,n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,k,n) for(int i = (k); i < (int)(n); i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define pb push_back
#define vec vector<int>


/*--------------------------------------------*/
/*ll factorial(ll);
void list_Prime(ll);
ll divisor(ll);
ll lcm(ll, ll);//AとBの最小公倍数
ll gcd(ll,ll);*/
/*--------------------------------------------*/


int main(){
    int n;ll k;cin>>n>>k;
    ll a[100000+10];ll b[100000+10];
    REP(i,n)cin>>a[i]>>b[i];
    //vector<ll> c(n);//dummy
    //REP(i,n)c[i]=a[i];
    vector<ll> d(100000+10,0);
    REP(i,n)d[a[i]]+=b[i];
    //sort(ALL(c));
    //REP(i,n)cout<<c[i]<<","<<d[c[i]]<<endl;
    ll cnt=0;
    for(ll now=1;now<=100000;now++){
        //printf("now=%lld\n",now);
        if(cnt<k){
            cnt+=d[now];
            if(cnt>=k){cout<<now--<<endl;break;}    
        }
    }
}



/*--------------------------------------------*/
/*
ll factorial(ll n){
    if(n==1)return 1;
    return n*factorial(n-1);
}
ll lcm(ll A, ll B) {//最小公倍数
    ll a = A;
    ll b = B;
    if (a == 0 || b == 0) { return 0; }
    if (a < 0) { a = -a; }
    if (b < 0) { b = -b; }
    while (b > 0) {
        ll c = a % b;
        a = b;
        b = c;
    }
    return A/a*B;
}

ll gcd(ll a,ll b){
    while (b != 0) {
        int t = b;
        b = a % b;
        a = t;
    }
    return a;
}


void list_Prime(ll n){//n以下の素数を全て見つける
    ll Limit=(int)sqrt((double)n);
    for(ll i=2;i<=n;i++)prime[i]=1;//最初はみんな素数かも
    //素数の整数倍を消していく(ルートnまで)
    for(ll i=2;i<=Limit;i++){
        if(prime[i]){
            for(ll j=2*i;j<=n;j++){
                if(j%i==0){
                    prime[j]=0;                
                }
            }
        }
    }
}

ll divisor(ll n){
    for(ll i=2;i<=n;i++){
        ll d=1;
        ll tmp=i;
        while(tmp>0){
            d++;
            while(tmp%d==0){
                prime[i]++;
                tmp/=i;
            }
        }
    }
    ll sum=1;
    for(ll i=2;;i<=n;i++){
        sum*=(prime[i]+1)/MOD;
    }    
    cout<<"sum="<<sum<<endl;

    return sum%MOD;
}
*/


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

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

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;
const int mod = 1000000007;


int main() {
    while (true) {
        int a, b;
        char op;
        cin >> a >> op >> b;
        if (op == '?') return 0;

        if (op == '+') cout << a + b << endl;
        if (op == '-') cout << a - b << endl;
        if (op == '*') cout << a * b << endl;
        if (op == '/') cout << a / b << endl;


    }
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define ll long long
#define N 100005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
main()
{
    ll now=100;
    ll x;
    cin>>x;
    for(int i=1;;i++)
    {
        now=now+(now*0.01);
        if(now>=x)
        {
            cout<<i;
            return 0;
        }
    }
}



Measured memory_bytes: 3636
#include<iostream>

using namespace std;

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

	if (a != b && b != c && a != c)cout << "No" << endl;
	else if (a == b && b == c)cout << "No" << endl;
	else cout << "Yes" << endl;




	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
//This code is written by Itst
using namespace std;

inline int read(){
	int a = 0;
	char c = getchar();
	while(!isdigit(c))
		c = getchar();
	while(isdigit(c)){
		a = a * 10 + c - 48;
		c = getchar();
	}
	return a;
}

const int MAXN = 2e5 + 7;
struct pack{
	int minN , maxN;
	bool operator <(const pack a)const{return minN < a.minN;}
}now[MAXN];
int N;

int main(){
	N = read();
	for(int i = 1 ; i <= N ; ++i){
		now[i].minN = read(); now[i].maxN = read();
		if(now[i].minN > now[i].maxN) swap(now[i].minN , now[i].maxN);
	}
	sort(now + 1 , now + N + 1);
	int maxInd = 1;
	for(int i = 2 ; i <= N ; ++i)
		if(now[maxInd].maxN < now[i].maxN)
			maxInd = i;
	int minN = now[1].maxN , maxN = now[maxInd].minN;
	for(int i = 2 ; i <= N ; ++i)
		if(i != maxInd){
			minN = min(minN , now[i].maxN);
			maxN = max(maxN , now[i].minN);
		}
	long long ans = 1ll * (maxN - now[1].minN) * (now[maxInd].maxN - minN);
	if(maxInd != 1){
		multiset < int > s;
		s.insert(now[1].maxN);
		for(int i = 2 ; i <= N ; ++i)
			s.insert(now[i].minN);
		ans = min(ans , 1ll * (now[maxInd].maxN - now[1].minN) * (*--s.end() - *s.begin()));
		for(int i = 2 ; i <= N ; ++i)
			if(i != maxInd){
				s.erase(s.find(now[i].minN));
				s.insert(now[i].maxN);
				ans = min(ans , 1ll * (now[maxInd].maxN - now[1].minN) * (*--s.end() - *s.begin()));
			}
	}
	cout << ans;
	return 0;
}


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

using namespace std;

typedef long long ll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

int main() {
    int a,b,res = 0;
    cin>>a >> b;
    
    REP(i,2)
    {
        if (a > b)
        {
            res += a;
            a--;
        }
        else
        {
            res += b;
            b--;
        }
    }
    cout << res << endl;
    return 0;
}

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


int main() {
    int n;cin >> n;
    vector<char> v(n);
    rep(i,n){
        cin >> v.at(i);
    }
    char x=v.at(0);
    int ans=1;
    rep2(i,n){
        if(x!=v.at(i)){
            ans++;
            x=v.at(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
import math

a, b, h, m = map(int, input().split())

h = 30 * h + 0.5 * m
m = 6 * m

kakudo = abs(h-m)

kakudo = math.radians(kakudo)

re = math.sqrt((a ** 2) + (b ** 2) - (2 * a * b * math.cos(kakudo)))
print(re)


Measured memory_bytes: 9388
K, N = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

dists = []

N.times do |i|
  dist = if i == N - 1
           A[0] + K - A[-1]
         else
           (A[i] - A[(i + 1) % N]).abs
         end

  dists << dist
end

total = dists.inject(:+)
max = dists.max

puts total - max


Measured memory_bytes: 17028
# D - Flipping Signs

n = int(input())
a = list(int(x) for x in input().split())

cntMinus = 0
ans = 0
minAbs = 10**10
for i in range(n):
    if a[i]<0:
        cntMinus += 1
    absi = abs(a[i])
    minAbs = min(minAbs, absi)
    ans += absi

if cntMinus%2==0:
    print(ans)
else:
    print(ans-minAbs*2)

Measured memory_bytes: 14412
def main():
    import sys
    input=sys.stdin.readline
    sys.setrecursionlimit(1000000000)
    n,m=map(int,input().split())
    G=[[] for _ in range(n)]
    for _ in range(m):
        x,y,z=map(int,input().split())
        x-=1
        y-=1
        G[x].append(y)
        G[y].append(x)
    
    visited=[True]*n
    def dfs(i):
        visited[i]=False
        for e in G[i]:
            if visited[e]:
                dfs(e)
    
    cnt=0
    for i in range(n):
        if visited[i]:
            cnt+=1
            dfs(i)
    
    print(cnt)  

if __name__=='__main__':
    main()
    

Measured memory_bytes: 129020
#f = open("input.txt")
#N, K = [int(x) for x in f.readline().split(' ')]
#lines = f.readlines()
#f.close()
from sys import stdin
N, K = [int(x) for x in stdin.readline().split(' ')]
lines = stdin.readlines()

schedule = [0]*N
for line in lines:
    strs = line.split(' ')
    schedule[int(strs[0])-1] = int(strs[1])

number = [1]*9
for i in range(9):
    (l1,l2) = divmod(i,3)
    if   schedule[0]!=l2+1 and schedule[0]!=0:
        number[i] = 0
    elif schedule[1]!=l1+1 and schedule[1]!=0:
        number[i] = 0

for s in schedule[2:]:
    tmp = [0]*9
    for i in range(9):
        (l1,l2) = divmod(i,3)
       	tmp[i] = [number[l2*3+j] for j in range(3) \
                 if (s==0 or s==l1+1) and  not (l2==j and l1==j)]
    number = [sum(tmp_i) for tmp_i in tmp]
print(sum(number) % 10000)

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

#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define f first
#define s second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

signed main(){
	
	int a, b, c;

	cin >> a >> b >> c;

	int temp1, temp2;

	temp1 = a;

	a = b;

	b = temp1;

	temp2 = a;

	a = c;

	c = temp2;

	cout << a << " " << b << " " << c <<endl;


	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define MAX 100000

int partition(int,int);
 
int arr[MAX];

int main(){

  int i,n,x;

  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&arr[i]);
  }
  
  x = partition(0,n-1);
  
  for(i=0;i<x;i++){
    printf("%d ",arr[i]);
  }

  printf("[%d] ",arr[x]);
  
  
  for(i=x+1;i<n-1;i++){
    printf("%d ",arr[i]);
  }
  printf("%d\n",arr[n-1]);

  return 0;
}


int partition(int a,int b){

  int x,i,j,tmp;

  x = arr[b];
  i = a - 1;

  for(j=a;j<b;j++){
    if(arr[j]<=x){
      i++;
      tmp=arr[i];
      arr[i]=arr[j];
      arr[j]=tmp;
    }
  } 
  tmp=arr[i+1];
  arr[i+1]=arr[b];
  arr[b]=tmp; 
  return i+1;
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define ternary(condition, x, y) ((condition) ? x : y) 
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

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

    llong n, m;
    cin >> n >> m;
    if (m % n == 0) {
        cout << m / n << endl;
        return 0;
    }

    llong ans = 0;
    for (llong i = m; i > 0; --i) {
        if (n * i <= m) {
            if (m % i == 0) {
                ans = i;
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void) {
  string a, b, c;
  cin >> a >> b >> c;
  if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

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

int main ()
{
    double r;
    int n;
    while (cin >> r >> n, r || n) {
        vector<double> height(21 * 2 + 1, 0);
        for (int i = 0; i < n; i++) {
            int x1, x2;
            double h;
            cin >> x1 >> x2 >> h;
            for (int j = x1; j < x2; j++) {
                height[j + 21] = max(height[j + 21], h);
            }
        }

        double res = 20. + r;
        for (int i = 0; i < 21 * 2 + 1; i++) {
            if (abs(i - 21) >= r) continue;
            double low = min(height[i-1], height[i]);
            double C = low * low + abs(i - 21) * abs(i - 21) - r * r;
            double ret = low - sqrt(pow(low,2) - C) + r;
            res = min(res, ret);
        }

        printf("%.4f\n", res);
    }

    return 0;
}

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

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		boolean[] card=new boolean[52];
		Arrays.fill(card,false);
		String[] c= {"S","H","C","D"};
		for(int i=0; i<N; i++) {
			String s=sc.next();
			int suji=sc.nextInt();
			if(s.equals(c[0])) {
				card[suji-1]=true;
			}
			else if(s.equals(c[1])) {
				card[13+suji-1]=true;
			}
			else if(s.equals(c[2])) {
				card[26+suji-1]=true;
			}
			else if(s.equals(c[3])) {
				card[39+suji-1]=true;
			}
		}
		for(int i=0; i<52; i++) {
			if(!card[i]) {
				System.out.println(c[i/13]+" "+(i%13+1));
			}
		}
	}
}


Measured memory_bytes: 26336
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma warning(disable:4786)
#pragma warning(disable:4996)

#define                           ll                          long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
int a[M],b[M];
bitset<35>bt,kbt,z;
vector<int>vec;
 main()

{
    int n,k;
    scanf("%d%d",&n,&k);
    f(i,1,n)
    {
       scanf("%d%d",&a[i],&b[i]);
       vec.pb(i);
    }
    kbt=k;
    ll ses=0;
    for(int j=32;j>=0;j--)
    {

        if(kbt[j]==0)
        {
            vector<int>nw;
            for(auto x:vec)
            {
                z=a[x];
                if(z[j]==0)nw.pb(x);
            }
            vec=nw;
        }
        else
        {

            vector<int>zr,o;
            for(auto x:vec)
            {
                z=a[x];
                if(z[j]==0)zr.pb(x);
                o.pb(x);
            }
           vec=o;
           ll cost=0;
           for(auto x:zr)
           {
               cost+=b[x];
           }
           ses=max(ses,cost);
        }

    }
    ll cost=0;
    for(auto x:vec)
    {
        cost+=b[x];
    }
    ses=max(ses,cost);
    printf("%lld\n",ses);
    return 0;

}





































Measured memory_bytes: 5996
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template<class T>
vector<T> divisor(T n){
    vector<T> ret;
    for(T i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return(ret);
}

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    int g = v[0];
    for (int i = 0; i < n; ++i) {
        g = __gcd(g, v[i]);
    }
    for (int i = 0; i < n; ++i) {
        v[i] /= g;
    }
    map<int, int> x;
    for (int i = 0; i < n; ++i) {
        x[v[i]]++;
    }
    map<int, int> m;
    for (auto &&j : x) {
        auto w = divisor(j.first);
        for (auto &&k : w) {
            m[k] += j.second;
        }
    }
    int ans = 0;
    for (auto &&k : m) {
        if(k.second >= n-1){
            ans = max(ans, k.first);
        }
    }
    cout << ans*g << "\n";
    return 0;
}

Measured memory_bytes: 640