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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using Pair = pair<int, int>;
const ll mod = 1e9 + 7;


template<class T>
T gcd(T a, T b)
{
  if(a && b) {
    return gcd(min(a, b), max(a, b) % min(a, b));
  } else {
    return a;
  }
}

template<class T>
T lcm(T a, T b)
{
  return a / gcd(a, b) * b;
}

ll power(ll base, ll exponent, ll module)
{
  if(exponent % 2) {
    return power(base, exponent - 1, module) * base % module;
  } else if(exponent) {
    ll root_ans = power(base, exponent / 2, module);
    return root_ans * root_ans % module;
  } else {
    return 1;
  }
}

struct combination
{
  vector<ll> fact, inv;
  combination(int sz) : fact(sz + 1), inv(sz + 1)
  {
    fact[0] = 1;
    for(int i = 1; i <= sz; i++) {
      fact[i] = fact[i - 1] * i % mod;
    }
    inv[sz] = power(fact[sz], mod - 2, mod);
    for(int i = sz - 1; i >= 0; i--) {
      inv[i] = inv[i + 1] * (i + 1) % mod;
    }
  }
  ll P(int n, int r)
  {
    if(r < 0 || n < r) return 0;
    return (fact[n] * inv[n - r] % mod);
  }
  ll C(int p, int q)
  {
    if(q < 0 || p < q) return 0;
    return (fact[p] * inv[q] % mod * inv[p - q] % mod);
  }
};

template<typename T>
void print_vec(vector<T>& v)
{
  for(const auto& e: v) {
    cout << e << " ";
  }
  cout << endl;
}
template<typename T>
void print_2dvec(vector<vector<T>>& m)
{
  for(const auto& v: m) {
    for(const auto& e: v) {
      cout << e << " ";
    }
    cout << endl;
  }
}

class Sieve
{
  int n;
  vector<int> table;
  // vector<int> primes;
  vector<int> factors(int x)
  {
    vector<int> fs;
    while(x != 1) {
      fs.push_back(table[x]);
      x /= table[x];
    }
    return fs;
  };

public:
  Sieve(int n) : n(n), table(n + 1, 0)
  {
    table.at(0) = table.at(1) = -1;
    for (int i = 2; i <= n; i++) {
      if (table.at(i)) continue;
      table.at(i) = i;
      for (ll j = (ll) i + i; j <= n; j += i) {
        table.at(j) = i;
      }
    }
  };

  vector<Pair> factor(int x)
  {
    vector<int> fs = factors(x);
    if (!fs.size()) return {};
    vector<Pair> dict_fs(1, Pair(fs.at(0), 0));
    for (const auto& f: fs) {
      if (dict_fs.back().first == f) dict_fs.back().second++;
      else dict_fs.emplace_back(f, 1);
    }
    return dict_fs;
  };
};


int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<ll> as;
  int a, max_a = 0;
  for (int i = 0; i < n; i++) {
    cin >> a;
    as.push_back(a);
    max_a = max(max_a, a);
  }

  Sieve sieve = Sieve(max_a);
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    for (const auto& e: sieve.factor(as.at(i))) {
      m[e.first] = max(m[e.first], e.second);
    }
  }

  ll lcm = 1;
  for (const auto& p: m) {
    REP(i, p.second) {
      lcm = (lcm * p.first) % mod;
    }
  }

  ll ans = 0;
  for (const auto& a: as) {
    ans = (ans + (lcm * power(a, mod - 2, mod)) % mod) % mod;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[100010];
    long long ans = 0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        ans+=a[i];
    }
    ans -= n;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
using namespace std;
int cnt=0;
string s;
signed main(){
	cin>>s;
	rep(i,s.size()-2){
		int a=(s[i]-48)*100+(s[i+1]-48)*10+s[i+2]-48;
		if(abs(a-753)<abs(cnt-753)){
			cnt=a;
		}
	}
	cout<<abs(cnt-753);
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    val a = scn.nextInt()
    val b = scn.nextInt()

    var A = ""
    var B = ""

    for(i in 1..b){
        A+=a.toString()
    }
    for(i in 1..a){
        B+=b.toString()
    }

    if(A <= B){
        println(A)
    }else{
        println(B)
    }
}

Measured memory_bytes: 31272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

int main(){
    ll n; cin >> n;
    vector<ll> d(61000,0);
    FOR(x,1,100)FOR(y,1,100)FOR(z,1,100){
        ll u = x*x+y*y+z*z+x*y+y*z+z*x;
        d[u]++;
    }
    FOR(i,1,n){
        cout << d[i] << endl;
    }
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int x;
  cin >> x;
  if(x == 0) cout << 1;
  else cout << 0;
}

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, k, n) for (int i = (int)(k); i < (int)(n); ++i)
#define rrep(i, k, n) for (int i = (int)(n) - 1; i >= (int)(k); --i)

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vv_ii;
typedef pair<int,ii> i_ii;
typedef vector<i_ii> vi_ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;

template <class T>
inline ostream& operator<<(ostream & o, vector<T> const& v) {
    for (int i = 0; i < (int)(v.size()) - 1; ++i)
        o << v[i] << ' ';
    if (!v.empty())
        o << v.back();
    return o;
}

template <class T, class Q>
inline ostream& operator<<(ostream & o, pair<T,Q> const& p) {
    o << "(" << p.fi << "," << p.se << ")";
    return o;
}


int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    ll a, b, k;
    cin >> a >> b >> k;
    ll o = max(k - a, 0LL);
    a = max(a - k, 0LL);
    b -= o;
    b = max(0LL, b);
    //cerr << "o -> " << o << endl;
    cout << a << ' ' << b << '\n';
    
    return 0;
}

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

answer = []
for x in range(N):
    answer.append(-1)

failCheck = False
for x in range(M):
    s, c = map(int, input().split())
    if answer[s - 1] == -1 or answer[s - 1] == c:
        answer[s - 1] = c
    else:
        failCheck = True
    if s == 1 and c == 0 and N > 1:
        failCheck = True

if failCheck:
    print(-1)
else:
    for x in range(len(answer)):
        if answer[x] == -1:
            if N == 1:
                answer[0] = 0
            elif x == 0:
                answer[x] = 1
            else:
                answer[x] = 0
    str_answer = map(str, answer)
    print("".join(str_answer))


Measured memory_bytes: 3064
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

struct UnionFind {
    typedef vector<int> vi;
    int n;
    vi par, rank, cnt;

    UnionFind(int n)
        : n(n), par(n), rank(n, 0), cnt(n, 1) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

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

    void unite(int a, int b) {
        a = find(a);
        b = find(b);

        if (a == b) return;
        if (rank[a] < rank[b]) {
            par[a] = b;
            cnt[b] += cnt[a];
        } else {
            par[b] = a;
            cnt[a] += cnt[b];
            if (rank[a] == rank[b]) rank[a]++;
        }
    }

    int count(int a) { return cnt[find(a)]; }

    bool same(int a, int b) { return find(a) == find(b); }
};

const int MAX_N = 100000;
int n, m, k;
vi f[MAX_N];
vi b[MAX_N];

int main() {
    fastio();

    cin >> n >> m >> k;

    UnionFind uf(n);

    forn(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        f[a].push_back(b);
        f[b].push_back(a);
        uf.unite(a, b);
    }

    forn(i, k) {
        int c, d;
        cin >> c >> d;
        c--, d--;
        b[c].push_back(d);
        b[d].push_back(c);
    }

    forn(i, n) {
        int ans = uf.count(i) - 1;
        for (int j : f[i]) {
            if (uf.same(i, j)) ans--;
        }
        for (int j : b[i]) {
            if (uf.same(i, j)) ans--;
        }

        cout << ans << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 13048
n,k=map(int,input().split())
d=list(map(int,input().split()))
for i in range(n,1000000):
  s=str(i)
  ok=True
  t_str=""
  for ss in s:
    if int(ss) in d:
      ok=False
      break
    t_str+=ss
  if ok:
    print(int(t_str))
    exit(0)


Measured memory_bytes: 40796
n,d = map(int,input().split())
p = []
for i in range(n):
    x,y = map(int,input().split())
    p.append([x,y])
ans = 0 
for i in range(n):
    if p[i][0]**2 + p[i][1]**2 <= d**2:
        ans += 1
print(ans)

Measured memory_bytes: 103620
#include <bits/stdc++.h>
#define RI register int
using namespace std;
typedef long long LL;
char s[100005];
int stk[100005];
int main(){
	scanf("%s", s);
	int len = strlen(s), top = 0;
	for(RI i = 0 ; i < len ; ++i){
		if(!top) stk[++top] = s[i];
		else if(s[i] == stk[top]) stk[++top] = s[i];
		else --top;
	}
	printf("%d\n", len - top);
	return 0;
}

Measured memory_bytes: 768
#include<stdio.h>
/*
  struct node{
  struct node* parent;
  struct node* left;
  struct node* right;
  int key;
  };
*/

void print (int,int);

#define N 10000

int H[N];

//#define NIL NULL

//struct node* heap[N];

int main(){ 
  int num;
  int i;

  scanf("%d",&num);

  for(i=1;i<=num;i++) {
    scanf("%d",&H[i]);
    //heap[i]->parent = NIL;
  }

  /*
    for(i=1;i*2+1<=num;i++){
    heap[i]->key = H[i];
    heap[H[i]]->left = H[i*2];
    heap[H[i]]->right = H[i*2+1];
    }
  */

  for(i=1;i<=num;i++) {
    print(i,num);
    printf("\n");
  }
  


  return 0;
}
    
    
void print(int i,int num){

  printf("node %d: ",i);
  printf("key = %d, ",H[i]);
  if(i/2 >= 1){
    printf("parent key = %d, ",H[i/2]);
  }
  if(i*2 <= num){
    printf("left key = %d, ",H[2*i]);
  }
  if((i*2+1) <= num){
    printf("right key = %d, ",H[2*i+1]);
  }
}


  

  

  



Measured memory_bytes: 2688
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    w, h, x, y = mi()
    g_x = w/2
    g_y = h/2
    ans = "{} {}".format(w*h/2, 1) if x==g_x and y==g_y else "{} {}".format(w*h/2, 0)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
package main

import "fmt"

func main()  {
	var N, A, B int

	fmt.Scan(&N, &A, &B)
	ans := 0

	for i := 1; i <= N ; i++{
		tmp := 0
		num := i
		for num >= 1 {
			tmp += num % 10
			num /= 10
		}
		if A <= tmp && tmp <= B {
			ans += i
		}
	}
	fmt.Println(ans)
}

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

const int INF = 1e9;
vector<int> arr;
vector<int> dp;
int N, K;

int solve(int x) {
    if (x >= N - 1) return 0;
    if (dp[x] != -1) return dp[x];
    
    int res = INF;
    for (int i = 1; i <= K; i++) {
        if (x + i >= N) break;
        res = min(res, abs(arr[x]-arr[x+i]) + solve(x + i));
    }

    return dp[x] = res;
}

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

    cin >> N >> K;
    arr = vector<int>(N);
    dp = vector<int>(N, -1);
    for (auto& x : arr) cin >> x;

    cout << solve(0) << "\n";
}



Measured memory_bytes: 7296
from collections import deque

x = input()
q = deque(x[0])

for i in range(1, len(x)):
    if q:
        p = q.pop()
        if p == 'S' and x[i] == 'T':
            pass
        else:
            q.append(p)
            q.append(x[i])
    else:
        q.append(x[i])
print(len(q))


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

using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m, n) {
    vector<int> s(m), k(m);
    vector<vector<int>> c(m, vector<int>());
    for (int i = 0; i < m; i++) {
      cin >> s[i] >> k[i];
      for (int j = 0; j < k[i]; j++) {
        int a;
        cin >> a;
        a--;
        c[i].emplace_back(a);
      }
    }
    vector<int> smin(n, 0), smax(n, 0);
    for (int i = 0; i < m; i++) {
      if (k[i] == 1) smin[c[i][0]] += s[i];
      for (int j = 0; j < k[i]; j++) {
        int idx = c[i][j];
        smax[idx] += s[i];
      }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == j) continue;
        ans = max(ans, smax[i] - smin[j] + 1);
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 2019;


int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);


    string s;
    cin >> s;

    int n = s.size();
    vector<int>count(2019,0);
    ll val = 0, ans = 0;;
    count[val]++;
    int power_of_ten = 1;
    for(int i=n-1;i>=0;--i){
        int curr = s[i]-'0';
        val = (val + power_of_ten * curr) %mod;
        power_of_ten = 10 * power_of_ten % mod;
        ans = ans + count[val];
        count[val]++;


    }
    cout << ans << "\n";

    

    return 0;
}

Measured memory_bytes: 3716
#include<stdio.h>
int main()
{
  int a[1001] ;
  int i, j, k ;
  int n ;
  scanf("%d",&n) ;

  // オリジナル配列入力
  for( i = 0 ; i < n ; i++ ){
    scanf("%d",&a[i]) ;
  }

  int tmp ;
  for( i = 1 ; i < n ; i++ ){
    for( k = 0 ; k < n-1 ; k++ ){
      printf("%d ", a[k]) ;
    }
    printf("%d\n", a[k]) ;
    tmp = a[i] ;
    j = i - 1 ;
    while( 0 <= j && a[j] > tmp ){
      a[j+1] = a[j] ;
      j-- ;
    }
    a[j+1] = tmp ; // ここでi回目のソート完了
  }

  for( k = 0 ; k < n-1 ; k++ ){
    printf("%d ", a[k]) ;
  }
  printf("%d\n", a[k]) ;

  return 0 ;
}


Measured memory_bytes: 2068
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;


ll dp[100005][200][5];

ll go(ll index,ll n,const string &s,ll k,ll sum,bool tight)
{
    
 if(index==n)
 {
  if(sum%k==0)
      return 1;
     return 0;
 }
   
    if(dp[index][sum][tight]!=-1)return dp[index][sum][tight];
    
    
    ll ans=0;
    if(tight)
    {
        ll limit=s[index]-'0';
        for(ll i=0;i<limit;i++)
         ans=(ans%mod+go(index+1,n,s,k,(sum+i)%k,false)%mod)%mod;
        
        ans=(ans%mod+go(index+1,n,s,k,(sum+limit)%k,true)%mod)%mod;
    }
    else
    {
       for(ll i=0;i<=9;i++)
          ans=(ans%mod+go(index+1,n,s,k,(sum+i)%k,false)%mod)%mod;  
    }
    dp[index][sum][tight]=ans%mod;
    return dp[index][sum][tight];
}

void solve()
{
  string s;
    cin>>s;
    ll k,n;
    cin>>k;
    n=s.length();
    memset(dp,-1,sizeof(dp));
    ll ans=go(0LL,n,s,k,0LL,true)%mod;
    ans=(ans-1+mod)%mod;
    cout<<ans<<endl;    
}


int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t=1;
   // cin>>t;
    while(t--)
        solve();
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

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

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<double> p(N), ps(N + 1, 0);
    REP(i, N) {
        cin >> p[i];
        p[i] = (p[i] + 1) / 2.0;
        ps[i + 1] = ps[i] + p[i];
    }
    double ans = 0.0;
    REP(i, N - K + 1) {
        ans = max(ans, ps[i + K] - ps[i]);
    }
    printf("%.10f\n", ans);
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>

using namespace std;

int R,C,K;
vector<vector<long long>> V;

int main()
{
	cin >> R;
	cin >> C;
	cin >> K;

	V = vector<vector<long long>>(R + 1, vector<long long>(C + 1, 0));
	
	for (int i = 0; i < K; i++) {
		int r, c;
		cin >> r;
		cin >> c;
		cin >> V[r][c];
	}

	

	auto dpm =vector<vector<vector<long long>>>(R + 1, vector<vector<long long>>(C + 1, vector<long long>(4,0)));


	for (int r = 1; r <= R; r++) {
		for (int c = 1; c <= C; c++) {
			for (int i = 3; i >= 0; i--) {
				if (i > 0) {
					dpm[r][c][i] = max(dpm[r][c][i], dpm[r][c][i - 1] + V[r][c]);
				}


				if (r < R) {
					dpm[r + 1][c][0] = max(dpm[r + 1][c][0], dpm[r][c][i]);
				}
				if (c < C) {
					dpm[r][c + 1][i] = max(dpm[r][c + 1][i], dpm[r][c][i]);
				}
			}
		}
	}

	long long ans = dpm[R][C][0];
	for (int i = 1; i <= 3; i++) {
		ans = max(ans,dpm[R][C][i]);
	}

	cout << ans << endl;

	return 0;
}



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

const int INF = 1001001001;

int a[12][12];

int main()
{
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    vector<int> b(n, -1);
    for (int i = 0; i < n; ++i)
    {
        int t;
        cin >> t;
        t -= 1;
        a[i] = t;
    }
    int s = 0;
    int x = 0, y = 0;
    rep(i, n)
    {
        if (b[s] == -1)
        {
            b[s] = i;
        }
        else
        {
            x = i - b[s];
            y = b[s];
            break;
        }
        s = a[s];
    }
    int ans;
    int pos = 0;
    if (k < y)
    {
        pos = k;
    }
    else
    {
        pos = ((k - y) % x) + y;
    }
    s = 0;
    for (int i = 0; i < pos; ++i)
    {
        s = a[s];
    }
    ans = s;
    ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		long[] a = new long[n];
		
		int mincnt = 0;
		
		for(int i = 0; i < n; i++) {
			a[i]=sc.nextInt();
			if(a[i] < 0) {
				mincnt++;
			}
		}
		
		long sum = Arrays.stream(a).map(x->Math.abs(x)).sum();
		
		if(mincnt % 2 == 0) {
			out.println(sum);
		}else{
			long min = Arrays.stream(a).map(x->Math.abs(x)).min().getAsLong();

			out.println(sum-2*min);
		}
	}

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

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 42960
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 8080
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD=1e9+7;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;


int main(){
	int A,B;
	cin>>A>>B;
	if(A<=8&&B<=8)cout<<"Yay!"<<endl;
	else cout<<":("<<endl;
}




















Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int P, Q, R; cin >> P >> Q >> R;

    cout << min(P+Q, min(Q+R, R+P)) << endl;
}

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

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

	cin >> n;

	long long int res = n*(n-1);
	res/=2;

	cout << res << '\n';
	return 0;
}

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

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

  int ans = double(b-a)/(a-1) + 1.999999;

  cout << ans << endl;

}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

int main() {
    Int n;
    cin >> n;
    vector<Int> d, c;
    Int res = 0;
    Int m = 0;
    for (Int i = 0; i < n; i++) {
        Int x, y;
        cin >> x >> y;
        if (x == 0) {
            res += y;
            continue;
        }
        m++;
        d.push_back(x);
        c.push_back(y);
    }
    vector<pair<Int, Int>> re(10);
    for (Int i = 1; i <= 9; i++) {
        Int x = i;
        Int i_cnt = 1;
        Int cnt = 1;
        while (x != i || cnt == 1) {
            x += i;
            if (x >= 10) {
                cnt++;
            }
            x = x / 10 + x % 10;
            cnt++;
            i_cnt++;
        }
        //cout << i << " " << i_cnt << " " << cnt << endl;
        re[i] = {i_cnt, cnt - 1};
    }
    vector<Int> p;
    for (Int i = 0; i < m; i++) {
        while (c[i] >= re[d[i]].fi) {
            res += re[d[i]].se * (c[i] / re[d[i]].fi);
            c[i] = (c[i] % re[d[i]].fi) + (c[i] / re[d[i]].fi);
        }
        Int x = d[i];
        for (Int j = 0; j < c[i] - 1; j++) {
            x += d[i];
            if (x >= 10) {
                res++;
            }
            x = x / 10 + x % 10;
            res++;
        }
        p.push_back(x);
    }
    Int cur = p[0];
    for (Int i = 1; i < m; i++) {
        cur += p[i];
        if (cur >= 10) {
            res++;
        }
        cur = cur / 10 + cur % 10;
        res++;
    }
    dump(res);
    return 0;
}

Measured memory_bytes: 6116
import collections
n, m = map(int, input().split())
linked = collections.defaultdict(list)
i2group = dict()

gid = n + 1
def get_root(i):
  if i not in linked:
    return i
  j = get_root(linked[i])
  linked[i] = j
  return j

def get_groups():
  return [get_root(i) for i in range(1, n + 1)]

for i in range(m):
  a, b = map(int, input().split())
  ra, rb = get_root(a), get_root(b)
  if ra == rb: continue
  linked[ra] = gid
  linked[rb] = gid
  gid += 1

g = get_groups()
print(len(set(g)) - 1)
exit()

n_connected = 0
n_group = 0
for s in linked.values():
  s = s[0]
  if s:
    n_group += 1
    n_connected += len(s)
    s.clear()
print((n - n_connected) + (n_group - 1))


Measured memory_bytes: 116376
import sys
from bisect import bisect_left, bisect_right
from collections import deque
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())

    """
            (連結成分) = (頂点数) - (辺の数)

    これが全て。シグマはそれぞれに分解するとして前者はO(1)で計算可能。
    後者は「各辺に対してそれが何回足されるか」を考えればよく、
    これはすなわち「各辺の両端の頂点を含むSの取り方は何通りあるか」を数えれば良い。
    """

    first = N * (N + 1) * (N + 2) // 6
    second = 0
    for _ in range(N - 1):
        u, v = map(int, input().split())
        if u > v: u, v = v , u
        second += u * (N - v + 1)
    print(first - second)


if __name__ == "__main__":
    main()


Measured memory_bytes: 74504
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);

int main() {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    b -= a;

    rep(i, n) {
        if(i*c - (n-1-i)*d <= b && b <= i*d - (n-1-i)*c) {
            out("YES");
            re0;
        }
    }
    
    out("NO");
    re0;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    ll Q, H, S, D, N; cin >> Q >> H >> S >> D >> N;
    if(H > 2*Q) H = 2*Q;
    if(S > 2*H) S = 2*H;
    if(D > 2*S) D = 2*S;
    ll ans = 0;
    if(N&1) ans += N/2*D + S;
    else ans += N/2*D;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 100005;
char S[MAX_N];
int N;

int main() {
  scanf("%s", S + 1);
  int N = strlen(S + 1);
  int l = 1, r = N, res = 0;

  while (l < r) {
    if (S[l] == S[r]) l++, r--;
    else if (S[l] == 'x') l++, res++;
    else if (S[r] == 'x') r--, res++;
    else {
      puts("-1");
      return 0;
    }
  }

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


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

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

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

struct Edge
{
	int u,v,a,b;
	Edge(int u, int v, int a, int b) : u(u),v(v),a(a),b(b) {}
};

struct Station
{
	int c,d;
	Station(int c, int d) : c(c),d(d) {}
};

signed main() {
	int n,m,s;
	std::cin >> n >> m >> s;
	std::vector<Edge> edges;
	rep(i,m) {
		int a,b,c,d;
		std::cin >> a >> b >> c >> d;
		a--;b--;
		edges.emplace_back(a,b,c,d);
	}
	std::vector<Station> nodes;
	rep(i,n) {
		int c,d;
		std::cin >> c >> d;
		nodes.emplace_back(c,d);
	}
	int X=n*2*50+1;
	std::vector<std::vector<int> > dp(n,std::vector<int>(X,INF));
	dp[0][std::min(X-1,s)]=0;
	//rep(xx,n*2) {
	while(true) {
		bool changed=false;
		for(auto e:edges) {
			// connect two stations
			rep(xxx,2) {
				for(int i=0;i<X;i++) {
					if(i+e.a>=X) break;
					int o=dp[e.v][i];
					dp[e.v][i]=std::min(dp[e.v][i],dp[e.u][i+e.a]+e.b);
					if(o!=dp[e.v][i]) changed=true;
				}
				std::swap(e.u,e.v);
			}
		}
		// trade
		rep(i,n) {
			for(int j=0;j<X;j++) {
				int o=dp[i][std::min(X-1,j+nodes[i].c)];
				dp[i][std::min(X-1,j+nodes[i].c)]=std::min(dp[i][std::min(X-1,j+nodes[i].c)],dp[i][j]+nodes[i].d);
				if(o!=dp[i][std::min(X-1,j+nodes[i].c)]) changed=true;
			}
		}
		if(!changed) break;
	}
	for(int i=1;i<n;i++) {
		int min=INF;
		for(int x:dp[i]) {
			min=std::min(min,x);
		}
		print(min);
	}
	return 0;
}


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

int n, a, b;

bool ver(int x) {
	int intern_sum = 0;
	while (x != 0) {
		intern_sum += x % 10;
		x /= 10;
	}
	if (intern_sum >= a && intern_sum <= b) {
		return true;
	}
	return false;
}

int main() {
	
	int i;
	long long sum = 0;;
	cin >> n >> a >> b;
	for (i = 1; i <= n; ++i) {
		if (ver(i)) {
			sum += i;
		}
	}
	cout << sum;
}

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

#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

vi graph[200000];

int dp[200000];

int vis[200000];

void dfs(int v)
{
    vis[v]=1;
    for(int i=0;i<graph[v].size();i++)
    {
    	if(vis[graph[v][i]]==0)
    		dfs(graph[v][i]);
    	dp[v] = max(dp[v],dp[graph[v][i]]);
    }
    dp[v]+=1;
}

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("test.txt","r",stdin);
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int u,v;
		cin>>u>>v;
		graph[u].pb(v);
	}
	for(int i=1;i<=n;i++)
	{
		if(vis[i]==0)
			dfs(i);
	}
	int output = 0;
	for(int i=1;i<=n;i++)
	  output = max(output,dp[i]);
	cout<<output-1; 
	return 0;
}

Measured memory_bytes: 10880
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

const ll INF=1ll<<60;
ll n,c,h[200010],HT[200010],idx[200010];
pair<ll,ll> H[200010];

struct line{
  ll a,b;
};

line dat[400010];
bool vis[400010];

void init(ll k=1,ll l=1,ll r=n){
  vis[k]=0;
  if(l!=r){
    init(k*2,l,(l+r)/2);
    init(k*2+1,1+(l+r)/2,r);
  }
  return;
}

void ud(line L,ll k=1,ll l=1,ll r=n){
  if(!vis[k]){
    vis[k]=1;
    dat[k]=L;
    return;
  }
  ll a=L.a,b=L.b,A=dat[k].a,B=dat[k].b,m=(l+r)/2;
  bool f[3]={a*h[l]+b>A*h[l]+B,a*h[m]+b>A*h[m]+B,a*h[r]+b>A*h[r]+B};
  if((!f[0])&&(!f[1])&&(!f[2])){dat[k]=L;return;}
  if(f[0]&&f[1]&&f[2]) return;
  if(f[0]&&f[1]){ud(L,2*k+1,m+1,r);return;}
  if(f[1]&&f[2]){ud(L,2*k,l,m);return;}
  if(f[0]){ud(dat[k],2*k,l,m);dat[k]=L;return;}
  if(f[2]){ud(dat[k],2*k+1,m+1,r);dat[k]=L;return;}
}

ll mn(ll i,ll k=1,ll l=1,ll r=n){
  if(!vis[k]) return INF;
  ll A=dat[k].a,B=dat[k].b,m=(l+r)/2,an=A*h[i]+B;
  if(l==i&&r==i) return an;
  if(i>m) return min(an,mn(i,k*2+1,m+1,r));
  else return min(an,mn(i,k*2,l,m));
}

void vl(ll k=1,ll l=1,ll r=n){
  cout<<k<<" "<<dat[k].a<<" "<<dat[k].b<<endl;
  if(l!=r){
    vl(k*2,l,(l+r)/2);
    vl(k*2+1,1+(l+r)/2,r);
  }
  return;
}

int main(){
  cin>>n>>c;
  Fr(i,n){cin>>h[i];HT[i]=h[i];H[i]=make_pair(h[i],i);}
  sort(h+1,h+n+1);
  sort(H+1,H+n+1);
  Fr(i,n) idx[H[i].second]=i;
  init();
  ll dp[200010]={0,0};
  Fr(i,n-1){
    ud((line){-2*HT[i],dp[i]+HT[i]*HT[i]});
    dp[i+1]=mn(idx[i+1])+c+HT[i+1]*HT[i+1];
    //cout<<i<<" "<<dp[i+1]<<endl;
    //vl();
    //cout<<endl;
  }
  cout<<dp[n]<<endl;
}

Measured memory_bytes: 16256
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    s = inputs[0]
    counts = {}
    for c in s:
        if c in counts:
            counts[c] += 1
        else:
            counts[c] = 1

    if len(counts) != 2:
        return "No"

    for k, v in counts.items():
        if v != 2:
            return "No"
    return "Yes"


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

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

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

    cout << (a - b * 2 + c == 0 ? "YES" : "NO") << '\n';

    return 0;
}

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

int main()
{
	vector<int> vec(3);
	for (int i = 0; i < 3; i++)
	{
		cin >> vec.at(i);
	}
	sort(vec.begin(), vec.end());
	cout << vec.at(0) + vec.at(1) << endl;
}


Measured memory_bytes: 256
#include <complex>
#include <cstdio>
#include <iostream>
#include <vector>
#define X real()
#define Y imag()
#define EPS 1e-10
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
typedef vector<P> Poly;

double cross(P a, P b){
  return a.X*b.Y - a.Y*b.X;
}

double area(Poly p){
  int n = p.size();
  double s = 0;
  for(int i = 0; i < n; ++i){
    s += cross(p[i],p[(i+1)%n])/2;
  }
  return s;
}

int main(){
  int n;
  cin >> n;
  double x, y;
  Poly p(n);
  for(int i = 0; i < n; ++i){
    cin >> x >> y;
    p[i] = P(x,y);
  }
  printf("%.1lf\n", area(p));
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

ll gcd(ll x, ll y)
{
  return y ? gcd(y, x % y) : x;
}
ll lcm(ll x, ll y)
{
  return x * y / gcd(x, y);
}
bool is_prime(int x)
{
  for (int i = 2; i * i <= x; i++)
  {
    if (x % i == 0)
      return 0;
  }
  return true;
}
vector<bool> prime_table(int n)
{
  vector<bool> prime(n + 1, 1);
  prime[0] = 0;
  prime[1] = 0;
  for (int i = 2; i * i <= n; i++)
  {
    if (!prime[i])
      continue;
    for (int j = i * i; j <= n; j++)
      prime[j] = 0;
  }
  return prime;
}
map<int, int> prime_factor(int n)
{
  map<int, int> res;
  for (int i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n]++;
  return res;
}
ll modpow(ll a, ll n, ll mod)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
ll modinv(ll a, ll mod)
{
  return modpow(a, mod - 2, mod);
}

int main()
{
  int n,k;
  cin>>n>>k;
  vector<int> h(n);
  REP(i,n) cin>>h[i];

  if(n<=k){
    cout<<0<<endl;
    return 0;
  }
  sort(ALL(h));
  ll ans=0;
  REP(i,n-k) ans+=h[i];

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


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;




int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n;
    scanf("%d", &n);
    long long ans = 0;
    long long rem = 0;
    for (int i = 0; i < n; i++)
    {
        long long cur;
        scanf("%lld", &cur);
        if (rem && cur)
        {
            cur--;
            ans++;
        }
        long long x = cur / 2;
        ans += x;
        cur -= 2 * x;
        rem = cur;
    }
    printf("%lld\n", ans);




	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n];
    ll ans=0;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans+=(lower_bound(a,a+n,a[i]+a[j])-a)-j-1;
        }
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 256
def readinput():
    n=int(input())
    return n

def main(n):
    stock=[]
    for _ in range(10):
        stock.append([])

    stock[0].append('')
    for m in range(1,10):
        for i in range(len(stock[m-1])):
            stock[m].append(stock[m-1][i]+'3')
            stock[m].append(stock[m-1][i]+'5')
            stock[m].append(stock[m-1][i]+'7')
    #print(stock)
    count=0
    for m in range(3,10):
        for i in range(len(stock[m])):
            if int(stock[m][i]) <= n and '3' in stock[m][i] and '5' in stock[m][i] and '7' in stock[m][i]:
                count+=1
                #print(stock[m][i])
    return count

S=[]
def dfs(s):
    global S
    if len(s)>10:
        return
    S.append(s)
    for c in '753':
        dfs(s+c)
    return

def main2(n):
    global S
    dfs('')
    count=0
    for s in S:
        if s!='' and int(s)>n:
            continue
        if '3' in s and '5' in s and '7' in s:
            count+=1
    return count

if __name__=='__main__':
    n=readinput()
    ans=main2(n)
    print(ans)


Measured memory_bytes: 15416
/*
 * Pawan Harendra Mishra
 */

/*
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
*/

/*
 * Windows Powershell
 * Get-Content input.txt | ./a.exe > output.txt
 */

#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mod 1000000007
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll n, k;

ll flips(ll score) {
    ll ans = 0;
    while (score<k) {
        score*=2;
        ans++;
    }
    return ans;
}

ll exponentiate(ll e) {
    ll ans = 1;
    while (e) {
        ans*=2;
        e--;
    }
    return ans;
}

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

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // //freopen("output.txt", "w", stdout);
    // #else
    // // online submission
    // #endif

    cin >> n >> k;
    vector<ll> din;
    vector<ll> num;
    for (ll i=1; i<=n; i++) {
        if (i<k) din.push_back(flips(i));
        else din.push_back(0);
    }
    
    sort(din.begin(), din.end(), greater<ll>());
    ll mx = din[0];
    for (ll i=0; i<din.size(); i++)
        num.push_back(mx - din[i]);
    
    ll sm = 0;
    for (ll i=0; i<num.size(); i++)
        sm += exponentiate(num[i]);
    
    ld ans = sm/ld(n*exponentiate(mx));
    cout.precision(12);
    cout << fixed << ans << endl;
    return 0;
}

Measured memory_bytes: 2548
N, M = map(int, input().split())
D = [list() for i in range(N)]
A = []
B = []
for i in range(M):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
    D[a-1].append(b-1)
    D[b-1].append(a-1)
d = [0]*N
d[0] = 1
cnt = 0


def dfs(x):
    for i in D[x]:
        if d[i] == 0:
            d[i] = 1
            dfs(i)


for i in range(M):
    D[A[i] - 1].remove(B[i] - 1)
    D[B[i] - 1].remove(A[i] - 1)

    d = [0]*N
    d[0] = 1
    dfs(0)

    if all(d) is False:
        cnt += 1
    D[A[i] - 1].append(B[i] - 1)
    D[B[i] - 1].append(A[i] - 1)

print(cnt)


Measured memory_bytes: 3064
c_i_j = [list(map(int, input().split())) for _ in range(3)]

a1 = 0
b1 = c_i_j[0][0] - a1
b2 = c_i_j[0][1] - a1
b3 = c_i_j[0][2] - a1
b = [b1, b2, b3]

flag = False
for i in range(1, 3):
    if len(set([c_i_j[i][j]-b[j] for j in range(3)])) != 1:
        print("No")
        break
else:
    print("Yes")


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

/* {{{ */
#define PI(N) ((M_PI * (N)) / 180) //?§???????????????¢??????????????????
#define CL(N) (cout << (N) << endl)
#define DCT(N) (cout << "debug " << (N) << endl)
#define REP(i, N) for (int i = 0; i < (N); i++)
/* }}} */

bool f[1000001] = {false};

int main()
{
	for (int i = 2; i * i < 1000001; i++){
    	for (int j = i * i; j < 1000001; j += i){
            f[j] = true;
        }
    }

	int n;
    while (cin >> n){
        int c = 0;
        for (int i = 2; i <= n; i++){
            if (!f[i])c++;
        }
        CL(c);
    }

	return (0);
}

Measured memory_bytes: 4064
li = [11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381]
N = int(input())
print(*li[:N])

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

#define INF 0x7fffffff;

int main() {
  vector<int> a(3);

  cin >> a[0] >> a[1] >> a[2];

  sort(a.begin(), a.end());

  if ((a[0]==5)&&(a[1]==5)&&(a[2]==7)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

struct Data {
    int x, y;
};

int main() {
    int h, w, m;
    cin >> h >> w >> m;
    vector<int> hvec(h, 0);
    vector<int> wvec(w, 0);
    vector<Data> data(m);
    for(int i = 0; i < m; ++i) {
        int ch, cw; cin >> ch >> cw;
        ch--; cw--;
        data[i].x = cw; data[i].y = ch;
        hvec[ch]++; wvec[cw]++;
    }

    int hmax = 0;
    for(int i = 0; i < h; ++i) {
        if(hmax < hvec[i]) hmax = hvec[i];
    }
    int wmax = 0;
    for(int i = 0; i < w; ++i) {
        if(wmax < wvec[i]) wmax = wvec[i];
    }
    int ans = hmax+wmax;
    
    set<int> hc;
    for(int i = 0; i < h; ++i) {
        if(hmax == hvec[i]) hc.insert(i);
    }
    set<int> wc;
    for(int i = 0; i < w; ++i) {
        if(wmax == wvec[i]) wc.insert(i);
    }

    int hlen = hc.size();
    int wlen = wc.size();
    int cnt = hlen*wlen;
    int ccc = 0;
    for(int i = 0; i < m; ++i) {
        if(hc.find(data[i].y) != hc.end() && wc.find(data[i].x) != wc.end()) {
            ccc++;
        }
    }

    if(cnt == ccc) cout << ans-1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 35872