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

int main(){
  int N,T,A;
  cin>>N>>T>>A;
  T*=1000,A*=1000;
  int k=100000000,l=0;
  for(int i=1;i<=N;i++){
    int H;
    cin>>H;
    if(k>abs(A-(T-H*6))){
      k=abs(A-(T-H*6));
      l=i;
    }
  }
  cout<<l<<endl;
}

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

string guki(int a){
  if(a % 2 == 0)return "gu";
  else return "ki";
}

int main(){
  unsigned long long int h,w;
  cin >> h >> w;
  unsigned long long int count = 0;
  
  if(guki(h) == "gu" && guki(w) == "gu"){count = (h / 2) * w;}
  else if(guki(h) == "gu" && guki(w) == "ki"){count = (h / 2) * w;}
  else if(guki(h) == "ki" && guki(w) == "gu"){count = h * (w / 2);}
  else if(guki(h) == "ki" && guki(w) == "ki"){count = ((h * w) / 2) + 1;}
  
  if(h == 1 || w == 1)count = 1;
  cout << count << endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split(' '))
S = [list(map(int,input().split(' '))) for i in range(N)]
C = [list(map(int,input().split(' '))) for i in range(M)]
for i in range(N):
  l = [abs(S[i][0]-C[j][0])+abs(S[i][1]-C[j][1]) for j in range(M)]
  print(l.index(min(l))+1)


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long LL;
const int Maxn = 1e5 + 5;
LL n, b[Maxn], a[Maxn];

int main(){
    int cnt = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a + 1, a + 1 + n);
    for (int i = n; i > 1; i--) {
        if (a[i] == a[i-1]){
            b[++cnt] = a[i];
            i--;
            if(cnt == 2){
                cout << b[1]*b[2] << endl;
                return 0;
            }
        }
    }
    cout << "0" << endl;
    return 0;
}


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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;

int main() {
    int a, b, c, k, m;
    cin >> a >> b >> c >> k;
    m = max(max(a, b), c);
    int tmp = m;
    rep(i, k) { m *= 2; }
    if (tmp == a)
        cout << b + c + m << endl;
    else if (tmp == b)
        cout << a + c + m << endl;
    else if (tmp == c)
        cout << a + b + m << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <stdio.h>
#define MAX 100000

void Print(int);
int depth(int,int);

struct Node{
  int oya, ri,le;
};

struct Node Tree[MAX];
int Depth[MAX];

int main(){
  int n,i,j,num,d,c,l,r;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    Tree[i].oya=Tree[i].le=Tree[i].ri=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&num,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0) Tree[num].le=c;
      else Tree[l].ri=c;
      l=c;
      Tree[c].oya=num;
    }
  }
  for(i=0;i<n;i++){
    if(Tree[i].oya==-1) r=i;
  }
  depth(r,0);
  for(i=0;i<n;i++)Print(i);
  return 0;
}





void Print(int a){
  int i,b;

  printf("node %d: ",a);
  printf("parent = %d, ",Tree[a].oya);
  printf("depth = %d, ",Depth[a]);

  if(Tree[a].oya==-1) printf("root, ");
  else if(Tree[a].le==-1) printf("leaf, ");
  else printf("internal node, ");

  printf("[");

  for(i=0,b=Tree[a].le;b != -1;i++,b=Tree[b].ri){
    if(i>0) printf(", ");
    printf("%d",b);
  }
  printf("]\n");
}




int depth(int a, int b){
  Depth[a]=b;
  if(Tree[a].ri !=-1) depth(Tree[a].ri, b);
  if(Tree[a].le !=-1) depth(Tree[a].le ,b+1);
  return 0;
}



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

#define ll long long

int main(){
    ll X,A,B,N, K,sum=0,l=0,r=0, tmp = 1000000000000000000LL;;
    cin >> X >> A >> B;
    if(B-A <= 0){
        cout << "delicious" << endl;
    }
    else if(B-A <= X){
        cout << "safe" << endl;
    }else{
        cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 384
#include<map> 
#include<ctime>
#include<algorithm>
#include<cstdio>
#include<set>
#include<memory.h>
#include<queue>
#include<cmath>
using namespace std;
#define ll long long
#define ld long double
#define For(i,x,y)  for(ll i=x;i<=y;++i)
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
inline ll read(){   ll x=0,f=1;char ch=getchar();   while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}  while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}  return x*f; } 
inline void write(ll x){    if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10);   putchar(x%10+'0');  } 
inline void writeln(ll x){ write(x);   puts("");   }
const ll mod=1e9+7,N=(1<<10)|111;
ll f[(1<<15)|111],g[20][(1<<15)|111],zyy[(1<<15)|111],n,m,mp[20][20],all,ans,ct[(1<<15)|111];
void add(ll &x,ll y){	x=(x+y)%mod;	}
ll qang(ll s,ll t){
	ll ans=1;
	for(;zyy[s&-s];s-=s&-s){
		ll to=zyy[s&-s];
		ans=ans*((1<<g[to][t])-1)%mod;
	}return ans;
}
ll sui(ll s,ll t){
	ll ans=1;
	for(;zyy[s&-s];s-=s&-s){
		ll to=zyy[s&-s];
		ans=(ans<<g[to][t])%mod;
	}return ans;
}
int main(){
	n=read();	m=read();
	For(i,1,m){	ll x=read(),y=read();	mp[x][y]=1;	}all=(1<<n)-1;
	For(s,0,all)	For(i,1,n)	For(j,1,n)if (!(s>>(i-1)&1)&&(s>>(j-1)&1))
	g[i][s]+=mp[i][j];
	For(s,0,all)	For(i,1,n)	if (s>>(i-1)&1)	zyy[s]=i;
	ans=1;
	For(i,1,m)	add(ans,ans);
	For(s,1,all)	ct[s]=ct[s-(s&-s)]+1;
	For(s,1,all)	if (!((s>>0&1)&&(s>>1&1)))f[s]=qang(all^s,s)*sui(s,all^s)%mod;
	For(s,1,all)	for(ll t=(s-1)&s;t;t=(t-1)&s)	if (!((s>>0&1)&&(s>>1&1)&&!(t>>0&1)&&!(t>>1&1)))	add(f[s],qang(all^s,s^t)*sui(s^t,all^s)%mod*f[t]);
	writeln(f[all]%mod);
}
/*
3 3
1 2
1 3
2 3
*/

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int H, W;
int N;
vector<int> a;

int main(){
  cin >> H >> W >> N;
  a.resize(N);
  REP(i, N){
    cin >> a[i];
  }
  int cnt = 0, idx = 0;
  vector<vector<int>> ans(H, vector<int>(W));
  REP(i, H){
    if(i % 2){
      REPR(j, W-1){
        ans[i][j] = idx + 1;
        cnt++;
        if(a[idx] <= cnt){
          idx++;
          cnt = 0;
        }
      }
    }
    else{
      REP(j, W){
        ans[i][j] = idx + 1;
        cnt++;
        if(a[idx] <= cnt){
          idx++;
          cnt = 0;
        }
      }
    }
  }
  REP(i, H){
    REP(j, W){
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }


  return 0;
}


Measured memory_bytes: 384
N = gets.to_i
A = []
N.times {
  A << gets.to_i
}

hash = Hash.new
A.each do |a|
  if hash.key?(a)
    hash[a] += 1
  else
    hash[a] = 1
  end
end

count = 0

hash.each do |k, v|
  if v % 2 == 1
    count += 1
  end
end

p count 

Measured memory_bytes: 9268
# -*- coding: utf-8 -*-

N = int(input())
abc = [list(map(int, input().split())) for i in range(N)]

happiness = [[0 for i in range(3)] for j in range(N)]

happiness[0] = abc[0]

for i in range(1, N):
    happiness[i][0] = abc[i][0] + max(happiness[i-1][1], happiness[i-1][2])
    happiness[i][1] = abc[i][1] + max(happiness[i-1][0], happiness[i-1][2])
    happiness[i][2] = abc[i][2] + max(happiness[i-1][0], happiness[i-1][1])

ans = max(happiness[-1])
print(ans)


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

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) a.begin(),a.end()

int main() {
	int n;
	cin >> n;
	int ans = 1;
	while (ans * 2 <= n) {
		ans *= 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define INF ((1LL<<62)-(1LL<<31))

//*
//遅延セグ木ここから
//↓ここを変える
typedef struct sayouso{ll k;}sayouso;
typedef struct atai{ll m,M,x;}atai;
//↑ここを変える

typedef struct node{sayouso T;atai x;}node;
node *lsegN,*lseg;
ll lsegNUM;

//↓ここから変える
sayouso sid={0};
atai aid={INF,-INF,0};
atai xx(atai x,atai y){
	atai ret;
	ret.m=min(x.m,y.m);
	ret.M=max(x.M,y.M);
	ret.x=max(y.M-x.m,max(x.x,y.x));
	return ret;
}
atai Tx(sayouso T,atai x){
	atai ret;
	ret.m=x.m+T.k;
	ret.M=x.M+T.k;
	ret.x=x.x;
	return ret;
}
sayouso TT(sayouso S,sayouso T){
	sayouso ret;
	ret.k=S.k+T.k;
	return ret;
}
//↑ここまで変える

//要素数(2ベキ)でこれを呼ぶ
void lseguse(ll n){
	lsegN=(node*)calloc(2*n,sizeof(node));
	lsegNUM=n;
	lseg=lsegN+lsegNUM;
	rep(i,0,lsegNUM){
		lseg[i].x=aid;
		lseg[i].T=sid;
	}
	for(int i=lsegNUM-1;i>0;i--){
		lsegN[i].x=xx(lsegN[2*i].x,lsegN[2*i+1].x);
		lsegN[i].T=sid;
	}
}
//lseg[i].xに値を与えてから初期化
void lseginit(){
	for(int i=lsegNUM-1;i>0;i--)lsegN[i].x=xx(lsegN[2*i].x,lsegN[2*i+1].x);
}
void lsegupdatesub(ll l,ll r,sayouso T,ll i,ll cl,ll cr){
	if(l>=r)return;
	//disjointなとき
	if(cr<=l||r<=cl)return;
	//完全に含むとき
	if(l<=cl&&cr<=r){
		lsegN[i].T=TT(T,lsegN[i].T);
		return;
	}
	//どちらでもないとき
	//遅延伝播
	lsegN[2*i  ].T=TT(lsegN[i].T,lsegN[2*i  ].T);
	lsegN[2*i+1].T=TT(lsegN[i].T,lsegN[2*i+1].T);
	//再帰的に更新
	ll cm=(cl+cr)/2;
	lsegupdatesub(l,r,T,2*i  ,cl,cm);
	lsegupdatesub(l,r,T,2*i+1,cm,cr);
	//自身のnodeを更新
	lsegN[i].x=xx(Tx(lsegN[2*i].T,lsegN[2*i].x),Tx(lsegN[2*i+1].T,lsegN[2*i+1].x));
	lsegN[i].T=sid;
}
void lsegupdate(ll l,ll r,sayouso T){lsegupdatesub(l,r,T,1,0,lsegNUM);}
atai lsegcalcsub(ll l,ll r,ll i,ll cl,ll cr){
	if(l>=r)return aid;
	//完全に含むとき
	if(l<=cl&&cr<=r)return Tx(lsegN[i].T,lsegN[i].x);

	ll cm=(cl+cr)/2;
	//遅延伝播(変更はないので配るだけで良い)
	lsegN[2*i  ].T=TT(lsegN[i].T,lsegN[2*i  ].T);
	lsegN[2*i+1].T=TT(lsegN[i].T,lsegN[2*i+1].T);
	lsegN[i].x=Tx(lsegN[i].T,lsegN[i].x);
	lsegN[i].T=sid;

	//左側だけ
	if(r<=cm)return lsegcalcsub(l,r,2*i  ,cl,cm);
	//右側だけ
	if(cm<=l)return lsegcalcsub(l,r,2*i+1,cm,cr);
	//両方
	return xx(lsegcalcsub(l,r,2*i,cl,cm),lsegcalcsub(l,r,2*i+1,cm,cr));
}
atai lsegcalc(ll l,ll r){return lsegcalcsub(l,r,1,0,lsegNUM);}
//遅延セグ木ここまで
//*/

int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	lseguse(1<<17);
	{
		atai x={0,0,0};
		lseg[0].x=x;
	}
	ll s=0;
	rep(i,0,n){
		ll t;
		scanf("%lld",&t);
		s+=t;
		atai x={s,s,0};
		lseg[i+1].x=x;
	}
	lseginit();
	printf("%lld\n",lsegcalc(0,n+1).x);
	while(q--){
		ll i,t;
		scanf("%lld%lld",&i,&t);
		sayouso T={t-lsegcalc(i,i+1).m+lsegcalc(i-1,i).m};
		lsegupdate(i,n+1,T);
		printf("%lld\n",lsegcalc(0,n+1).x);
	}
}


Measured memory_bytes: 10044
#include <bits/stdc++.h>              
 using namespace std;                  
                                       
 int main(void){                       
   int N;                              
   cin >> N;                           
   int dum[N],ans[N];                  
   int sum = 0,sum1 = 0;               
   for(int i = 0; i < N;i++){          
     cin >> dum[i];                    
     sum += dum[i];                    
   }                                   
   sum1 = sum;                         
   for(int i = 1; i < N;i += 2){       
     sum1 -= 2*dum[i];                 
   }                                   
   ans[0] = sum1;                      
   for(int i = 1; i < N;i++){          
     ans[i] = 2*dum[i-1] -ans[i-1];    
   }                                   
   for(int i = 0; i < N;i++){          
     cout << ans[i] << " ";            
   }                                   
   cout <<endl;                        
   return 0;                           
 }                                     

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
template<class T> bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (auto &e : s) cin >> e;
    
    int a[h][w] = {};
    int b[h][w] = {};
    int c[h][w] = {};
    int d[h][w] = {};
    
    for (int i = 0; i < h; i++) {
        a[i][0] = (s[i][0] == '.');
        for (int j = 1; j < w; j++) {
            if (s[i][j] == '.') a[i][j] = a[i][j - 1] + 1;
            else a[i][j] = 0;
        }
        c[i][w - 1] = (s[i][w - 1] == '.');
        for (int j = w - 2; j >= 0; j--) {
            if (s[i][j] == '.') c[i][j] = c[i][j + 1] + 1;
            else c[i][j] = 0;
        }
    }
    for (int j = 0; j < w; j++) {
        b[0][j] = (s[0][j] == '.');
        for (int i = 1; i < h; i++) {
            if (s[i][j] == '.') b[i][j] = b[i - 1][j] + 1;
            else b[i][j] = 0;
        }
        d[h - 1][j] = (s[h - 1][j] == '.');
        for (int i = h - 2; i >= 0; i--) {
            if (s[i][j] == '.') d[i][j] = d[i + 1][j] + 1;
            else d[i][j] = 0;
        }
    }
    
    int ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') continue;
            int res = a[i][j] + b[i][j] + c[i][j] + d[i][j] - 3;
            ans = max(ans, res);
        }
    }
    
    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 66816
# -*- coding: utf-8 -*-
from collections import Counter

N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#-----

cnt_A = Counter(A_list)
A_list.sort()

max_num = A_list[-1]
cnt = 0


for i in range(len(A_list)):
    if A_list[i] not in cnt_A:
        continue
    
    if cnt_A[ A_list[i] ] == 1:
        cnt += 1
    
    for j in range( 2, max_num // A_list[i] + 1 ):
        n = A_list[i] * j
        
        if n in cnt_A:
            del cnt_A[n]


print(cnt)


Measured memory_bytes: 36040
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int a1, b1, a2, b2;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> a1 >> b1 >> a2 >> b2;
	if (b2 < a1 || b1 < a2) cout << 0 << endl;
	else if (a1 <= a2 && b2 <= b1) cout << b2-a2 << endl;
	else if (a1 <= a2 && b1 < b2) cout << b1-a2 << endl;
	else if (a2 < a1 && b2 <= b1) cout << b2-a1 << endl;
	else if (a2 < a1 && b1 < b2) cout << b1-a1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <deque>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <sstream>
#include <type_traits>
#define SET(x,y) x |= (1 << y)
#define CLEAR(x,y) x &= ~(1<< y)
#define READ(x,y) ((0u == (x & (1<<y)))?0u:1u)
#define TOGGLE(x,y) (x ^= (1<<y))
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define si(n) scanf("%d",&n)
#define sf(n) scanf("%f",&n)
#define sl(n) scanf("%lld",&n)
#define slu(n) scanf("%llu",&n)
#define sd(n) scanf("%lf",&n)
#define ss(n) scanf("%s",n)
#define pnl printf("\n")
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pF first
#define pS second
#define CL(a,b) memset(a,b,sizeof(a))
#define sqr(x) ((x)*(x))
#define intLIMIT numeric_limits<int>
#define longLIMIT numeric_limits<long long>
#define GCD(a,b) __gcd((a),(b))
#define dbl(x) (double)(x)
#define vi vector <int>
#define vii vector < pair <int, int> >
#define vll vector <long long>
#define allof(x) (x).begin(), (x).end()
#define fastCin cin.sync_with_stdio(0);cin.tie(0)
#define scanUnsigned(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
#define printArr(a,l) cout<<#a<<": ";for(int i=0;i<(l);i++){cout<<a[i]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(int i=0;i<(r);i++){for(int j=0;j<(c);j++){cout<<a[i][j]<<" ";}cout<<endl;}
char _;
using namespace std;
void PRINT (int x, int y) { for (int i = y-1; i >= 0; i--) { cout << READ(x,i); } cout << endl; }

vector<string>vec_splitter(string s){s+=',';vector<string>res;while(!s.empty()){res.push_back(s.substr(0,s.find(',')));s=s.substr(s.find(',')+1);}
return res;}
void debug_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,__attribute__((unused))int LINE_NUM){cerr<<endl;}
template<typename Head,typename...Tail>void debug_out(vector<string>args,int idx,int LINE_NUM,Head H,Tail...T){if(idx>0)cerr<<", ";else cerr<<"Line("<<LINE_NUM<<") ";stringstream ss;ss<<H;cerr<<args[idx]<<" = "<<ss.str();debug_out(args,idx+1,LINE_NUM,T...);}
#ifdef LOCAL_DBG
#define dbg(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define dbg(...) 42
#endif

const int tot = 10000005;

int main () {
	fastCin;
	vi p;
	bool s[tot] = {0};
	ll cnt[tot];
	for (int x = 1; x <= tot-5; x++) {
		cnt[x] = 1;
	}
	for (int x = 2; x <= tot-5; x++) {
		if (!s[x]) {
			for (int i = 2*x; i < tot; i += x) {
				s[i] = true;
				ll cur = x, tmp = 1;
				while (i%(cur*x) == 0) {
					cur *= x;
					tmp++;
				}
				cnt[i] *= (tmp+1);
			}
			cnt[x] = 2;
			p.pb(x);
		}
	}
	int n;
	cin >> n;
	ll ans = 1;
	for (int x = 2; x <= n; x++) {
		ans += (ll)x * cnt[x];
	}
	cout << ans << "\n";
	return 0;
}

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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;

    vector<int> l(n);
    for (int i = 0; i < n; ++i) cin >> l[i];
    sort(l.begin(), l.end());

    int sum = 0;
    for (int i = 0; i + 1 < n; ++i) sum += l[i];
    if (l[n - 1] < sum) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


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

int main(){
	int s,a,b,c;
	cin >> s;
	a = s / 100;
	b = (s - 100 * a) / 10;
	c = s - 100 * a - 10 * b; 

	cout << a + b + c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>

#define ull unsigned long long
#define ul unsigned long
#define ll long long
#define size_t unsigned long long

using namespace std;

int func(int n){
  if(n % 2 == 0){
    return n/2;
  }else{
    return 3*n+1;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int arr[100000];
  int s;
  cin >> s;
  arr[s] = 1;
  int count = 2;
  while(true){
    s = func(s);
    if(arr[s] == 1){
      std::cout << count << '\n';
      return 0;
    }
    arr[s] = 1;
    count++;
  }
  return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,d,a = LI()
    xh = sorted([LI() for _ in range(n)])
    r = 0
    k = 0
    t = []
    ti = 0
    for x,h in xh:
        while len(t) > ti and t[ti][0] < x:
            k -= t[ti][1]
            ti += 1
        h -= k
        if h <= 0:
            continue
        u = (h+a-1) // a
        r += u
        k += u * a
        t.append((x+d*2, u*a))

    return r


print(main())





Measured memory_bytes: 81492
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
        	int n = sc.nextInt();
        	int [] S = new int[n];
        	for(int i=0;i<n;i++) {
        		S[i] = sc.nextInt();
        	}
        	
        	int q = sc.nextInt();
        	int [] T = new int[q];
        	for(int i=0;i<q;i++) {
        		T[i] = sc.nextInt();
        	}
        	int C = 0;
        	for(int i=0;i<q;i++) {
        		if(Arrays.binarySearch(S, T[i])>=0) {
        			C++;
        		}
        	}
        	System.out.println(C);
        }
    }
}
        		


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

void print_cards(vector<string> &cards, int n)
{
	rep(i, n) {
		if (i) cout << " ";
		cout << cards[i];
	}
	cout << endl;
}

void bubble_sort(vector<string> &cards, int n)
{
	for (int i = 0; i < n; i++) {
		for (int j = n-1; j > i; j--) {
			if (cards[j-1][1] > cards[j][1])
				swap(cards[j-1], cards[j]);
		}
	}
}

void selection_sort(vector<string> &cards, int n)
{
	for (int i = 0; i < n-1; i++) {
		int minj = i;
		for (int j = i+1; j < n; j++) {
			if (cards[minj][1] > cards[j][1])
				minj = j;
		}
		swap(cards[i], cards[minj]);
	}
}

int main()
{
	int n;
	cin >> n;
	vector<string> a1(n), a2(n);
	for (int i = 0; i < n; i++)
		cin >> a1[i];
	a2 = a1;

	bubble_sort(a1, n);
	print_cards(a1, n);
	cout << "Stable" << endl;

	selection_sort(a2, n);
	print_cards(a2, n);

	bool stable = true;
	rep(i, n) {
		if (a1[i] != a2[i]) {
			stable = false;
			break;
		}
	}
	if (stable)
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;
}



Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  string s;
  cin >> s;

  int n = s.length();
  int ans = 0;

  for (int i = 0; i < n/2; ++i) {
    if (s[i] == s[n-i-1]) continue;
    ++ans;
  }

  cout << ans << '\n';

  return (0);
}

Measured memory_bytes: 3652
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws IOException {

		InputStreamReader sr = null;
		Scanner sc = null;

		try {
			sc = new Scanner(sr = new InputStreamReader(System.in));

			String[] str = sc.nextLine().split(" ");
			Integer[] values = toInteger(str);
			Arrays.sort(values, Collections.reverseOrder());

			StringBuilder sb = new StringBuilder();

			for (int i = 0; i < values.length; i++) {

				sb.append(values[i]);
				sb.append(" ");
			}
			sb.deleteCharAt(sb.length() - 1);
			System.out.println(sb);

		}catch(NoSuchElementException e){

		}

		finally {
			sr.close();
			sc.close();
		}

	}

	public static Integer[] toInteger(String[] str) {

		List<Integer> list = new ArrayList<Integer>();

		for (String s : str) {

			list.add(Integer.parseInt(s));

		}

		return list.toArray(new Integer[0]);

	}
}

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

int a[100050];
int o[100050];

int main() {
    int N;
    scanf("%d", &N);
    int ans = 0;
    for (int i = 0; i < N; i++) {
        scanf("%d", &a[i]);
        if (o[a[i]] == 0) {
            ans++;
        }
        o[a[i]] += 1;
    }
    if (ans % 2 == 0) ans--;
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip> //fixed << setprecision(10)

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;

int main(){
    int h, a;
    cin >> h >> a;

    if (h%a == 0){
        cout << h/a << endl;
    }
    else{
        cout << (h/a)+1 << 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 repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;


ll gcd(ll a, ll b) {
  return b != 0 ? gcd(b, a % b) : a;
}

int main(void)
{
    ll A, B;
    cin >> A >> B;
    ll C = gcd(A, B);
    ll n = C;
    //cout << C << endl;
    int count = 1;
    for(ll i = 2; i * i <= C; i++)
    {
        if(n % i == 0)
        {
            count++;
            while(n % i == 0)
            {
                n /= i;
            }
        //cout << i << " " << C << endl;
        }
    }
    if(n != 1){
        count++;
    }
    cout << count  << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  ll n, a, sum;
  cin >> n;
  vector<ll> num(100001);
  rep(i, n){
    cin >> a;
    num[a]++;
    sum += a;
  }
  
  ll q;
  cin >> q;
  rep(i, q){
    ll b, c;
    cin >> b >> c;
    sum += (c - b)*num[b];
    cout << sum << endl;
    num[c] += num[b];
    num[b] = 0;
  }  
  
  return 0;
}

Measured memory_bytes: 4048
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	ll n, k;
	cin >> n >> k;

	//if (n >= k)
	{
		ll x = n % k;
		if (x == 0)
		{
			println(0);
		}
		else
		{
			println(min(n, abs(k - x)));
		}
	}
}


Measured memory_bytes: 256
/**
*    author:  yuya1234
*    created: 09.07.2020 09:28:00
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define ALL(v) (s).begin(), (s).end()
#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

  int r,g,b,n;
  cin>>r>>g>>b>>n;

  ll cnt=0;
  REP(i,n/r+1)REP(j,n/g+1)
  {
    if((n-i*r-j*g)%b==0 && n-i*r-j*g>=0)
    {
      cnt++;
    }
  }

  cout<<cnt<<endl;

  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M,X,count,counter2=0;
    cin>>N>>M>>X;
    int c[N]={0};
    int a[N][M]={{0}};
    int d[N]={0};
    int answer[M]={0};
    set<int> S;
    for(int i=0; i<N; i++){
    cin>>c[i];
    for(int j=0; j<M; j++){
    cin>>a[i][j];}}
    for(int i=0;i<pow(2,N);i++){
    count=i;
    for(int k=0; k<M; k++){
    answer[k]=0;}
    for(int j=0;j<N;j++){
    d[j]=count%2;
    count/=2;
    }
    for(int k=0;k<N;k++){
    if(d[k]==1){
    for(int h=0;h<M;h++){
    answer[h]+=a[k][h];
    }
    }}
    int counter1=0;
    for(int k=0;k<M;k++){
    if(answer[k]>=X){
    counter1++;
    }}
    if(counter1==M){
    counter2=0;
    for(int k=0;k<N;k++){
    if(d[k]==1){
    counter2+=c[k];
    }}
    S.insert(counter2);}}
    if(S.empty()==1)
    cout<<-1<<endl;
    else{
    int Q=*begin(S);
    cout<<Q<<endl;
    }}


Measured memory_bytes: 4300
#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> B(N-1);
    rep(i, N-1){
        cin >> B[i];
    }
    int ans = 0;
    rep(i, N){
        if(i == 0){
            ans += B[i];
        } else if(i == N-1) {
            ans += B[i-1];
        } else {
            ans += min(B[i], B[i-1]);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(){

  int n,i,j,count = 0,minj,v;

  scanf("%d",&n);

  int A[n];

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  for(i=0;i<=n-1;i++){
    minj = i;
    for(j=i;j<=n-1;j++){
      if(A[j] < A[minj]){
	minj = j;
      }
    }
    if(i!=minj){
      v = A[i];
      A[i] =  A[minj];
      A[minj] = v;
      count++;
    }
  }

  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i<n-1){
      printf(" ");
    }

    else{
      printf("\n");
    }
    
  }

  printf("%d\n",count);
  return 0;
}



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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N;
    vector<ll> x[15],y[15];
    cin >> N;
    for (int i = 0; i < N; i++) {
        ll A; cin >> A;
        for (int j = 0; j < A; j++) {
            ll X,Y; cin >> X >> Y;
            X--; 
            x[i].pb(X);
            y[i].pb(Y);
        }
    }
    ll cnt = 0;
    for (int i = 0; i < (1 << N); i++) {
        int flg[15];
        fillnum(flg,-1);
        bool ans = true;
        for (int j = 0; j < N; j++) {
            ll b = (1 << j) & i;
            if(b != 0){
                flg[j] = 1;
            } else {
                flg[j] = 0;
            }
        }
        for (int j = 0; j < N; j++) {
            if(flg[j] == 1){
                for (int k = 0; k < x[j].size(); k++) {
                    if(flg[x[j][k]] != y[j][k]){
                        ans = false;
                        break;
                    }
                }
            }
            if(ans == false){
                break;
            }
        }
        if(ans == true){
            ll c = 0;
            for (int j = 0; j < N; j++) {
                if(flg[j] == 1){
                    c++;
                }
            }
            cnt = max(cnt,c);
        }
    }
    cout << cnt << endl;
}

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

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

    int x[] = {1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};

    if(x[a - 1] == x[b - 1]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

bool templete_matching(vector<string> A, vector<string> B, int n, int m){
    for(int ay = 0; ay < n - m + 1; ay++){
        for(int ax = 0; ax < n - m + 1; ax++){
            
            bool flag = true;
            
            for(int by = 0; by < m; by++){
                for(int bx = 0; bx < m; bx++){
                    
//                    cout << A.at(ay+by).at(ax+bx) << " " << B.at(by).at(bx) << endl;
                    if(A.at(ay+by).at(ax+bx) != B.at(by).at(bx)){
                        flag = false;
                        break;
                    }
                }
                if(flag == false){
                    break;
                }
            }
            if(flag == true){
                return true;
            }
            
        }
    }
    
    return false;
}
int main(){
    int n, m; cin >> n >> m;
    
    vector<string> A(n);
    for(int i = 0; i < n; i++){
        cin >> A.at(i);
    }
    
    vector<string> B(m);
    for(int i = 0; i < m; i++){
        cin >> B.at(i);
    }
    
    if(templete_matching(A, B, n, m)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}




Measured memory_bytes: 256
require 'matrix'

def makeStepPattern( w, prevStep )
  if w == 1
    if prevStep == 0
      [[0],[1]]
    else
      [[0]]
    end
  elsif w == 0
  	[[0]]
  else
    offPat = makeStepPattern( w - 1, 0 )
    offPat.each {|pat| pat<< 0 }
    if prevStep == 1
      offPat
    else
	    onPat = makeStepPattern( w - 1, 1 )
	    onPat.each {|pat| pat<< 1 }
      offPat + onPat
		end
	end
end

(h,w,k) = STDIN.gets.split(/ +/).map(&:to_i)

stepPattern =  makeStepPattern( w - 1, 0 )

startGoalMatrix = []

w.times { startGoalMatrix<< Array.new( w, 0 ) }


( 0..w-1 ).each do |i|
	stepPattern.each do |pattern|
	  if i == 0
	    
	    if pattern[i] == 0
	      startGoalMatrix[ i ][ i ] += 1
	    else
	      startGoalMatrix[ i ][ i + 1] += 1
	  	end
	  	
	  elsif i == w - 1
	    
	    if pattern[i-1] == 0
	      startGoalMatrix[ i ][ i ] += 1
	    else
	      startGoalMatrix[ i ][ i - 1] += 1
	  	end
	  
	  else
	  
	    if pattern[i-1] == 0 && pattern[i] == 0
	      startGoalMatrix[ i ][ i ] += 1
	    elsif pattern[i-1] == 1
	      startGoalMatrix[ i ][ i - 1] += 1
	    elsif pattern[i] == 1
	      startGoalMatrix[ i ][ i + 1] += 1
	  	end
	  
	  end
  end 
end


sgm = Matrix.rows( startGoalMatrix, false )

v = Array.new( w, 0 )
v[0] = 1

goalVector = Vector.elements( v, false )


h.times do 
  goalVector = sgm * goalVector
end

puts goalVector[ k - 1 ] % 1000000007


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

int main()
{
  int n, k, x, y;
  cin >> n >> k >> x >> y;

  int ans = 0;
  for( int i = 0; i < n; i++ ) {
    if( i < k ) {
      ans += x;
    }
    else {
      ans += y;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  bool D = false;
  for(int i = 1;i <= A * B;i++) {
    if(A * i % B == C) {
      D = true;
      break;
    }
  }
  if(D == true) {
    cout << "YES" << endl;
  }
  else { 
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
import math
a,b,C = map(int, input().split())
S = a * b * math.sin(math.radians(C)) / 2
L = a + b + math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(C)))
h = 2 * S / a
print(S)
print(L)
print(h)



Measured memory_bytes: 5700
n, m = map(int, input().split())
a = []
b = []
c = []
for _ in range(m):
    x, y, z = map(int, input().split())
    a.append(x - 1)
    b.append(y - 1)
    c.append(z * -1)

d = [float('inf')] * n
d[0] = 0

for x in range(n * 2):
    for i in range(m):
        if d[a[i]] + c[i] < d[b[i]]:
            d[b[i]] = d[a[i]] + c[i]
            if n - 1 <= x and b[i] == n - 1:
                print('inf')
                exit(0)

print(d[n - 1] * -1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////


int main(){fastio
    ll n;cin>>n;
    ll ans=0;
    for(ll i=1;i*i<=n;i++){
        //しょうと余りがi
        ll p=(n-i)/i;//n=p*i+i
        if((n-i)%i==0){
            if(i<p)ans+=p;
        }
    }
    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;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  int x = (int)(n / 1.08);

  for (int i = -1; i <= 1; ++i) {
    if ((int)((x + i) * 1.08) == n) {
      cout << x + i;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 256
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Fri Dec 28 15:48:15 2018
//
package main

import (
	"fmt"
	"sort"
)

func main() {
	arr := make([]int, 3)
	fmt.Scan(&arr[0], &arr[1], &arr[2])
	sort.Ints(arr)
	ans := arr[2] - arr[1]
	diff := arr[2] - (arr[0] + ans)
	if diff%2 == 0 {
		fmt.Println(ans + diff/2)
	} else {
		fmt.Println(ans + (diff+1)/2 + 1)
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define     ll          long long
#define     MOD         10e9+7
#define     pb          push_back
#define     vll         vector<long long>
#define     vi          vector<int>
#define     vl          vector<long>
#define     pii         pair<int, int>
#define     pll         pair<ll,ll>
#define     mp          make_pair
#define     all(a)      (a).begin(),(a).end()
#define     rep(i,a,b)  for(int i=a;i<b;i++)
#define     MAX         100002 
#define     ios	      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;


int main() {
    
    ios
    ll x,n;
    cin >> x >> n;
    vll a(n);
    ll dp[102]={0};
    for(ll i=0;i<n;i++){
        cin >> a[i];
        dp[a[i]]++;
    }
    if(n==0)cout << x << "\n";
    else if(!dp[x])cout << x << "\n";
    else{
        ll num=x;
        ll i=1;
        while((num+i>=0&&num+i<=101)||(num-i>=0&&num-i<=101)){
            if(!dp[num-i]){
                cout << num-i <<"\n";
                break;
            }else if(!dp[num+i]){
                cout << num+i << "\n";
                break;
            }else i++;

        }
    }   
    
    return 0;
}



Measured memory_bytes: 3684
#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() {
ios::sync_with_stdio(false);
cin.tie(0);

int x,y,z;
cin>>x>>y>>z;

cout<<z<<" "<<x<<" "<<y<<endl;
return 0;
}

Measured memory_bytes: 256
/**
 *     author: nayakashutosh9
 *     college: National Institute of Technology, Rourkela
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define mod 1000000007
#define inf 1e18
const int N = 200005;

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




int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	// int t, z = 1; cin >> t;
	// cin.ignore();
	// while (t--) {

	// }
	int n, k; cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 0;
	for (int i = 0; i < k; i++) ans += a[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3556
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, R = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    if N<10:
        print(R+100*(10-N))
    else:
        print(R)





if __name__ == "__main__":
    main()

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


#define IOS ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
 
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vp vector<pii>
#define vs vector<string>
#define all(v) v.begin(),v.end()

#define lb  lower_bound
#define ub  upper_bound
#define bs  binary_search
#define ff  first
#define ss  second
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
 
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
     
#define pi 3.14159265358979323846//20 decimals
#define MOD 1000000007

 
int32_t main(){

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
     IOS
     string s,t,ans="Yes";
     cin>>s>>t;
     for(int i=0;i<s.size();i++)
     {
        if(s[i]!=t[i])
            ans="No";
     }
     cout<<ans<<endl;

return 0;
}

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

int main(){
    string S; cin >> S;
    ll cnt0=0;
    ll cnt1=0;
    rep(i,S.size()){
        if(S[i]=='0') cnt0++;
        else cnt1++;
    }
    ll ans=2*min(cnt0,cnt1);
    cout << ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int n, k;
    cin >> n >> k;
    int x[n];
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    int ans = 1000000000;
    for (int i = 0; i + k <= n; i++) {
        int s = abs(0 - x[i]) + abs(x[i] - x[i + k - 1]);
        int t = abs(0 - x[i + k - 1]) + abs(x[i] - x[i + k - 1]);
        ans = min(ans, min(s, t));
    }

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

Measured memory_bytes: 640
import sys
N,A,B,C,D=map(int,input().split())
h=B-A
for K in range(N):
    s=C*K-D*(N-1-K)
    t=D*K-C*(N-1-K)
    if s<=h<=t:
        print('YES')
        sys.exit()
print('NO')

Measured memory_bytes: 39280
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <string.h>
using namespace std;
int main()
{
	int a[100005];
	int ans1[100005];
	int ans2[100005];
	int i, n;
	int count1 = 0,count2 = 0;
	scanf("%d", &n);
	for(i = 1 ; i <= n ; i++)
	{
		scanf("%d", &a[i]);
	}
	if(n > 2)
	{
		sort(a + 1 , a + 1 + n);
		for(i = 1 ; i <= n - 1 ; i++)
		{
			if(a[n] / 2 - a[i] <= 0)
			{
				count1++;
				ans1[count1] = a[i] - a[n] / 2;
			}
			else
			{
				count2++;
				ans2[count2] = a[n] / 2 - a[i];
			}
		}
		sort(ans1 + 1, ans1 + count1 + 1);
		sort(ans2 + 1, ans2 + count2 + 1);
		if(ans1[1] > ans2[1])
		{
			printf("%d %d\n", a[n], a[n] / 2 - ans2[1]);
		}
		else
		{
			printf("%d %d\n", a[n], a[n] / 2 + ans1[1]);
		}
	}
	else
	{
		printf("%d %d",max(a[1],a[2]),min(a[1],a[2]));
	}

}

Measured memory_bytes: 896
n, m = map(int, input().split())
p = ""
c = ""

for i in range(n):
  p = p + input()

for i in range(m):
  if not i % 2 == 0:
    c = c + input()[::-1]
  else:
    c = c + input()

if c in p:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    auto n = readLong();
    auto a = readLongs().sort();
    auto b = readLongs().sort();
    auto c = readLongs().sort();

    auto m = new long[](n+1);
    foreach(i; iota(n)) {
        m[i+1] = a.trisect(b[i])[0].length;
    }

    foreach(i; iota(n)) {
        m[i+1] += m[i];
    }

    long ans;
    foreach(i; iota(n)) {
        auto t = b.trisect(c[i]);
        ans += m[t[0].length];
    }
    writeln(ans);
}



Measured memory_bytes: 15048
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int time = scanner.nextInt();
    int h = time/3600;
    int m = (time%3600)/60;
    int s = (time%3600)%60;
    System.out.println(h + ":" + m +":"+s);

}
}

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

#define endl '\n'

int n,m,k, ans = 1e6;
string s[11];

void solve(int ii, vector<int> grupos){
    if (ii < n-1){
        grupos.back()++;
        solve(ii+1, grupos);
        grupos.back()--;
        grupos.push_back(ii+1);
        solve(ii+1, grupos);
    } else{
        int cur_ans = grupos.size() - 1;
        vector<int> tam(grupos.size(), 0);
        bool need_cut = false, ok = true;

        for (int j=0; j<m; j++){
            vector<int> col(grupos.size());
            for (int i=0, g=0; i<n; i++){
                if (grupos[g] < i)g++;
                if (s[i][j] == '1'){
                    tam[g]++;
                    col[g]++;
                }
                if (tam[g] > k) need_cut = true;
                if (col[g] > k){
                    ok = false;
                    break;
                }
            }
            if (!ok) break;
            if (need_cut){
                cur_ans++;
                tam = col;
                need_cut = false;
            }
        }
        if (ok) ans = min(ans, cur_ans);
    }
}

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

    cin >> n >> m >> k;
    for (int i=0; i<n; i++) cin >> s[i];
    solve(0, {0});
    cout << ans << endl;
}

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

int main(){
    string s;
    cin >> s;
    
    int ans = 0;
    int cnt = 0;
    rep(i, s.length()){
        if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T')cnt++;
        else cnt=0;
        ans = cnt>ans? cnt: ans;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3568