akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

#define INF 1000000007

int main(){
  long long n;
  cin >> n;
  vector<long long> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

  vector< vector<int> > bt(61, vector<int>(n, 0));
  for(long long i = 0; i < n; i++){
    long long tmp = a[i];
    for(long long j = 0; j < 61; j++){
      bt[j][i] = bt[j][i-1]*(i>0) + (tmp%2);
      tmp /= 2;
    }
  }
  long long ans = 0;
  for(long long i = 0; i < n-1; i++){
    long long p = 1;
    long long tmp = a[i];
    for(long long j = 0; j < 61; j++){
      if(tmp%2){
        ans += (((n-i-1) - (bt[j][n-1] - bt[j][i])) * (p%INF)) % INF;
        ans %= INF;
      }
      else{
        ans += ((bt[j][n-1] - bt[j][i]) * (p%INF)) % INF;
        ans %= INF;
      }
      p *= 2;
      tmp /= 2;
    }
  }
  cout << ans << endl;
}


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

struct restaurant {
  int no;
  string name;
  int pt;
};

int cmp(const void *v1, const void *v2) {
  restaurant *r1 = (restaurant*)v1;
  restaurant *r2 = (restaurant*)v2;
  if (r1->name > r2->name) return 1;
  if (r1->name < r2->name) return -1;
  if (r1->pt > r2->pt) return -1;
  if (r1->pt < r2->pt) return 1;
  return 0; 
}

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> p(n);
  rep(i, n) cin >> s[i] >> p[i];

  vector<pair<pair<string, int>, int>> r(n);
  rep(i, n) r[i] = make_pair(make_pair(s[i], -p[i]), i+1);
  sort(r.begin(), r.end());
  rep(i, n) cout << r[i].second << endl;
  return 0;
}

Measured memory_bytes: 3636
K = int(input())
S = list(input())
if len(S) <= K:
	word = ""
	for a in S:
		word += a
	print(word)
else:
	i = 0
	word =  ""
	while i < K:
		word += S[i]
		i += 1
	word += "..."
	print(word)


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  int Ans = 1;
  sort(A.begin(), A.end());
  for (int i = 0; i < N - 1; i++) {
    if(A.at(i) == A.at(i+1)) {
      Ans = 0;
    }
  }
  if (Ans == 1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int mod = 1e9+7;

int binpow(long long b, long long e) {
  if (!e) return 1;
  if (e&1) return binpow(b, e-1)*b%mod;
  return binpow(b*b%mod, e/2);
}

int mul(long long a, long long b) {
  return a*b%mod;
}

int nCr(long long n, long long r) {
  n = n+r-1;
  long long res = 1;
  for (int i = n-r+1; i <= n; ++i) {
    res = res*i%mod;
  }
  for (int i = 2; i <= r; ++i) {
    res = res*binpow(i, mod-2)%mod;
  }
  return res;
}

void solve() {
  int n, k; scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; ++i) {
    int nB = k-i, nR = (n-k)-(i-1);
    int bB = i, bR = i+1;
    if (nR < 0) {
      printf("0\n");
      continue;
    }
    printf("%d\n", mul(nCr(bB, nB), nCr(bR, nR)));
  }
}

int main() {
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3796
import java.util.*;
import java.io.*;

public class Main { 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
		String s=sc.next();
        ArrayList<String> a=new ArrayList<String>();
       int n=s.length();
       for(int i=0;i<n;i++){
        	a.add(String.valueOf(s.charAt(i)));
       } 
      
      //ArrayList<Long> num=new ArrayList<Long>();
      int[] num=new int[n+1];
      for (int i=0;i<n;i++){
        if(i==0){
        	if(a.get(0).equals("<")){
              num[0]=0;
            }else{
            	continue;
            }
        }else if(a.get(i-1).equals(">")&&a.get(i).equals("<")){	//><
        	num[i]=0;
            int j=i-1;
        	while(j>=0&& a.get(j).equals(">") ){	//  >が続く限り増加
               	num[j]=Math.max(num[j+1]+1,num[j]);
               	j--;
        	}
        }else if(a.get(i).equals("<")){	//<<
        	num[i]=num[i-1]+1;
        }else if(a.get(i-1).equals("<") && a.get(i).equals(">")){		//<>
        	num[i]=num[i-1]+1;
        }   
      }
      
          	if(a.get(n-1).equals("<")){
              	num[n]=num[n-1]+1;
            }else{
            	num[n]=0;
                int j=n-1;
        	    while(j>=0&& a.get(j).equals(">") ){	//  >が続く限り増加
               		num[j]=Math.max(num[j+1]+1,num[j]);
               		j--;
        		}
            }
        
      long o=0;
      for (int i=0;i<n+1;i++){
          //System.out.println(num[i]);
          o+=num[i];
      }
      System.out.println(o);
    }  
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    string S;
    cin >> S;

    ll ans = 0;

    if(S[0] == '1') ans++;
    if(S[1] == '1') ans++;
    if(S[2] == '1') ans++;

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

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

const int MAX=1'000'000;
int n,d[MAX];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>d[i];
	}
	sort(d,d+n);
	cout<<d[n/2]-d[n/2-1];
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
    int n,k;
    cin>>n>>k;
    int sum=0;
    for(int i=k; i<=n+1; i++){
    sum=(sum+((LL)n*(n+1)/2-(LL)(n-i)*(n-i+1)/2-(LL)i*(i-1)/2+1))%(1000000007);
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979323846

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





int main() {
  int L, R, d;
  cin >> L >> R >> d;

  int ans = 0;

  for(int i = L; i <= R; i++){
    if(i % d == 0) ans++;
  }

  cout << ans << endl;
  


  // cout << setprecision(8) << ans << endl;  // For double
}



Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j, k;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  k=A[0];
  for(i=0;i<n;i++){
    if(k<A[i]){
      k=A[i];
    }
  }

  for(i=0;i<10001;i++){
    C[i]=0;
  }


  for(j=0;j<n;j++){
    C[A[j]]++;
  }

  for(i=1;i<10001;i++){
    C[i]=C[i]+C[i-1];
  }

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

  printf("%d\n",B[n]);

  return 0;
}


Measured memory_bytes: 9564
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<ll,P> PP;
int main() {
	int x, a, b; cin >> x >> a >> b;
	if (abs(x - a) < abs(x - b))cout << "A" << endl;
	else cout << "B" << endl;
	return 0;
}

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

x0, x1 = -1, -1
cnt = 0
flag = False

for i in range(N):
    if flag == False:
        if i > 0 and S[i] != S[i-1]:
            cnt += 1
            flag = True
    else:
        flag = False
    x0 = x1

print(cnt)


Measured memory_bytes: 5792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
using namespace __gnu_pbds;
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
using pl = pair<ll, ll>;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

vector<ll> v, anw;
ll n;
vector<ll> bs[64];

int hob (ll num) {
    if (!num)
        return 0;

    int ret = 1;

    while (num >>= 1)
        ret += 1;

    return ret;
}


int main() {
  ios::sync_with_stdio(0);
  cout.precision(10);

  cin >> n;
  ll even=0, odd=0;
  for (int i = 0; i < n; i++) {
    ll x; cin >> x;
    if (x%2==0) even++;
    else odd++;
  }
  if (even==0 || odd%2==0) {
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
}

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

using namespace std;

#define int         long long
#define ld          double
#define vi          vector <int>
#define vp          vector <pair<int,int>>
#define vvi         vector <vector <int>>
#define pb          push_back
#define mp          make_pair
#define pi          pair<int,int>
#define all(a)      a.begin(),a.end()
#define sz(a)       a.size()
#define sl(a)       a.length()
#define rev(a)      sort(all(a),greater<int>())
#define ff          first
#define ss          second
#define minel(a)	*min_element(all(a))
#define maxel(a)	*max_element(all(a))
#define Mod         1000000007
#define deb(x)      cout << x << endl;
#define o(x)        for(auto a:x)cout << a <<" ";cout << endl;
#define o2(x,n,m)   for(int i =0;i<n;i++){for(int j=0;j<m;j++)cout << x[i][j] << " ";cout << endl; } 
#define i(x,n)      for(int i=0;i<n;i++)cin >> x[i];
#define i2(x,n,m)   for(int i =0;i<n;i++){for(int j=0;j<m;j++)cin >> x[i][j]; }
int inf = 1e18;

//vvi a(n, vi(10));

int power(int a,int b, int m);

signed main()
{
    int n,W;
    cin >> n >> W;

    vi weight,value;weight.pb(0);value.pb(0);
    for(int i=0;i<n;i++)
    {
        int v,w;
        cin >> w >> v;
        weight.pb(w);
        value.pb(v);
    }

    int dp[n+1][W+1];
    for(int i=0;i<n+1;i++)
    {
        for(int j=0;j<W+1;j++)
        dp[i][j] = 0;
    }

    for(int i=0;i<n+1;i++)
    {
        for(int j=0;j<W+1;j++)
        {
            if(i == 0 || j == 0){continue;}
            if(j-weight[i] >= 0)
            {
                dp[i][j] = max(dp[i-1][j],dp[i-1][j-weight[i]]+value[i]);
            }
            else
            {
                dp[i][j] = dp[i-1][j];
            }
        }
    }

   // o2(dp,n+1,W+1);
    cout << dp[n][W] <<endl;
}

//utility function

int power(int a,int b,int m)
{
    int ans = 1;
    while(b > 0)
    {
        if(b&1){ans *= a;ans %= m;}
        a *= a;
        a %= m;
        b >>= 1;
    }
    return ans;
}



Measured memory_bytes: 82484
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  string s;
  cin >> s;
  int out = 0;
  for (int i = 0; i < s.length() / 2; i++)
  {
    if (s[i] != s[s.length() - 1 - i])
    {
      out++;
    }
  }
  cout << out << endl;
}


Measured memory_bytes: 3144
n,m = gets.chomp.split(' ').map(&:to_i)
a = readlines.map{|line| line.chomp.split(' ').map(&:to_i)}.sort_by{|x| x[0]}
price = 0
a.each do |y|
  break if m == 0
  price += [y[1],m].min * y[0]
  m -= [y[1],m].min
end
puts price

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

#ifdef pr16
  #define pr(x)                 cerr << #x << ": " << x << endl;
  #define pr2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
  #define pr3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
  #define pr4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
  #define pr5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
  #define pr6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prc(a) tr(a, it) cerr<<*(it)<<" "; cerr<<endl
  #define pra(a,n) for(int i=0; i<(n); i++) cerr<<((a)[i])<<" "; cerr<<"\n"
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl; 
  #define prddd(a,x,y,z) for(int i=0;i<x;i++) {cerr<<"layer "<<i<<":\n";prdd(a[i],y,z)}
 
#else
  #define pr(x)
  #define pr2(x, y)
  #define pr3(x, y, z)
  #define pr4(a, b, c, d)
  #define pr5(a, b, c, d, e)
  #define pr6(a, b, c, d, e, f)
  #define prc(a)
  #define pra(a,n)
  #define prdd(a, r, c)
  #define prddd(a,x,y,z)
#endif


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int cnt = 0;
    while (a >= b or b >= c) {
    	if (a >= b) {
    		b *= 2;
    		cnt ++;
    	} else if (b >= c) {
    		c *= 2;
    		cnt ++;
    	}
    }

    if (cnt <= k)
    	cout<<"Yes";
    else 
    	cout<<"No";

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) begin(v), end(v)
#define allg(v) begin(v), end(v), greater<int>()

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> is(n);
  rep(i, 0, n)
    cin >> is.at(i);
  rep(k, 0, n-1)
    cout << is.at(k) << " ";
  cout << is.at(n-1) << "\n";
  
  rep(i, 1, n) {
    int v = is.at(i);
    int j = i-1;
    while (j >= 0 and is.at(j) > v) {
      is.at(j+1) = is.at(j);
      j--;
    }
    is.at(j+1) = v;
    
    rep(k, 0, n-1)
      cout << is.at(k) << " ";
    cout << is.at(n-1) << "\n";
  }

}


Measured memory_bytes: 3124
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here

        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int K = in.nextInt();
        long ans = 0;

//        ans  = gcd(1,2);

        for (int i = 1; i <= K; i++) {
            for (int j = 1 ; j <=K; j++) {
                for (int k = 1; k <= K; k++) {
                    ans += gcd(i,j,k);
                }
            }
        }

        out.println(ans);

        in.close();
        out.close();
    }

    public static int gcd(int a, int b, int c){
        return gcd(gcd(a,b),c);
    }

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


Measured memory_bytes: 35816
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define rep(x, a, b) for(int x = (a); x <= (b); ++x)
#define rop(x, a, b) for(int x = (a); x < (b); ++x)
#define per(x, a, b) for(int x = (a); x >= (b); --x)
using namespace std;
typedef long long LL;
typedef double DB;
struct node {
	int x, y;
}q[1000005];
queue<int> Q;
int n, tt, as, f[1000005];
char S[1000005], T[1000005];
int main() {
	scanf("%d", &n);
	scanf("%s", S + 1);
	scanf("%s", T + 1);
	rep(i, 1, n) {
		if(S[i] != T[i]) break;
		if(i == n) {puts("0"); return 0;}
	}
	int p = n;
	per(i, n, 1) {
		if(T[i] == T[i + 1] && i >= p) continue;
		while(i < p || (p > 1 && S[p] != T[i])) --p;
//		if(T[i] == T[i + 1] && i >= p) continue;
		if(S[p] != T[i]) {puts("-1"); return 0;}
		q[++tt] = (node) {p, i};
	}
	int S = 0;
	q[tt + 1].y = 0;
	rep(i, 1, tt) {
//		if(q[i - 1].x != q[i].y + 1) Q.push(q[i - 1].x - S);
		S--;
		Q.push(q[i].x - S);
		while(Q.size() && Q.front() + S >= q[i + 1].y + 1) Q.pop();
		as = max(as, (int) Q.size());
	}
	
	cout << as + 1 << endl;
	return 0;


}


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

#define pb push_back
#define ff first
#define ss second

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

int n, a, g, k, mx;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a, g = __gcd(g, a), mx = max(mx, a);
	if (k % g || mx < k)
		cout << "IMPOSSIBLE\n";
	else
		cout << "POSSIBLE\n";
	return 0;
}


Measured memory_bytes: 256
/* 
    Author : Jeff Ahn
    Sun 21 Jun 2020 05:16:20 PM PDT 
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\n'

const int mxn = 2e5 + 10;
int a[mxn];

signed main() {
  fastio;
  int n;
  cin >> n;
  int sum = 0;
  rep(i,n) { cin >> a[i]; sum ^= a[i]; }
  rep(i,n) cout << (a[i] ^ sum) << endl;
}


Measured memory_bytes: 5144
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int N;
double v,tmp=0;
priority_queue <double , vector <double>, greater <double>> que;

signed main(){
  cin >> N;
  rep(i,N){
    cin >> v;
    que.push(v);
  }
  for(int i=0;i<N-1;i++){
    tmp=0;
    tmp+=que.top();
    que.pop();
    tmp+=que.top();
    que.pop();
    que.push(tmp/2.0);
    //cout << tmp << endl;
  }
  double ans=que.top();
  printf ("%.5f\n",ans);
  return 0;
}


Measured memory_bytes: 256
fun main() {
    val builder = StringBuilder()

    val (n, k) = readInputLine().split(" ").let { Pair(it[0].toInt(), it[1].toLong()) }

    val aArr = readInputLine().split(" ").map { it.toInt() - 1 }

    val visited = BooleanArray(n)

    val visitTrace = mutableListOf<Int>()

    var teleCnt = 0L
    var current = 0

    while (!visited[current]) {
        visited[current] = true
        visitTrace.add(current)

        current = aArr[current]
        teleCnt++
    }

    for ((i, a) in visitTrace.withIndex()) {
        if (i.toLong() == k) {
            builder.appendln(a + 1)
            break
        }
        if (a == current) {
            builder.appendln(visitTrace.drop(i)[((k - i.toLong()) % (teleCnt - i.toLong())).toInt()] + 1)
            break
        }
    }

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 65696
#include <bits/stdc++.h>
         
typedef long long ll;
using namespace std;
        
#define F first
#define S second
#define sqr(x) x*x
#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define repit(i, n) for(auto it = n.begin(); it != n.end(); ++it)
       
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
int lcm(int a,int b){return abs(a*b)/gcd(a,b);}
          
bool comp(pair<string, int> a, pair<string, int> b){
    return a.S < b.S;
}

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    ll n;
    cin >> n;
    ll ans[n];
    ans[0] = 2;
    ans[1] = 1;
    for(int i = 2 ; i <= n; ++i){
        ans[i] = ans[i - 2] + ans[ i - 1];
    }
    cout << ans[n];
    

}


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

int main(){
  int N,K;
  cin >> N >> K;
  int x;
  int A = 0;
  for(int i = 0; i < N; i++){
    cin >> x;
    if(x - 0 <= K - x){
      A = A + 2*(x - 0);
    }
    else{
      A = A + 2*(K - x);
    }
  }
  cout << A << endl;
}

Measured memory_bytes: 256
import Foundation
 
let N = Int(readLine()!)!
var input = readLine()!.componentsSeparatedByString(" ").map { Int($0)! }
 
input.sortInPlace()
 
var sum = 0
for i in input {
    sum += i
}
 
if input[N-1] < sum - input[N-1] {
    print("Yes\n")
} else {
    print("No\n")
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,ans = 0;
    cin >> n;
    int p[n];
    rep(i, n)cin >> p[i];
    qsort(p, n, sizeof(int), desc);
    p[0] = p[0] / 2;
    rep(i, n)ans += p[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = input()
A = [int(raw_input()) for i in xrange(n)]
B = A[0:n:2]
C = A[1:n:2]
A.sort()
B.sort()
C.sort()
ans = 0
idxB = 0
idxC = 0
for i in xrange(n):
    if i%2:
        if idxB < len(B) and B[idxB] == A[i]:
            ans += 1
    else:
        if idxC < len(C) and C[idxC] == A[i]:
            ans += 1
    if idxB < len(B) and B[idxB] == A[i]:
        idxB += 1
    if idxC < len(C) and C[idxC] == A[i]:
        idxC += 1
print ans/2



Measured memory_bytes: 7104
using System;
using System.Collections.Generic;
using System.Globalization;

class Program
 {



    static void Main(string[] args)
    {
        string nyuryoku, nyuryoku1;
        string[] temp = new string[4];
        char ch;
        char[]  input;
        nyuryoku = Console.ReadLine();
        input = new char[nyuryoku.Length];
        for(int i=0;i<nyuryoku.Length;i++)
            input[i] = nyuryoku[i];

        nyuryoku1 = Console.ReadLine();
        int count = int.Parse(nyuryoku1);

        for (int i = 0; i < count; i++)
        {
            nyuryoku1 = Console.ReadLine();
            temp = nyuryoku1.Split(' ');
            if (temp[0].Equals("replace"))
            {
  
                for(int j = 0;j<temp[3].Length;j++)
                {
                    input[j+int.Parse(temp[1])]=temp[3][j];
                }
            }
            else if (temp[0].Equals("reverse"))
            {
                char[] taihi = new char[int.Parse(temp[2]) - int.Parse(temp[1]) + 1];
                for (int j = 0; j < taihi.Length; j++)
                    taihi[j] = input[j + int.Parse(temp[1])];
                for (int j = 0; j < taihi.Length; j++)
                    input[j + int.Parse(temp[1])] = taihi[taihi.Length - j -1];
                 
            }
            else
            {
                for(int J=0;J<(int.Parse(temp[2])-int.Parse(temp[1])+1);J++)
                    Console.Write(input[J+int.Parse(temp[1])]);
                Console.Write("\n");
              
            }


        }


    
    }
 }



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

int main(){
	int n , k;
	scanf("%d %d", &n , &k);

	int array[n] , i;

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

	sort(array , array + n); // sorts the array

	int sum = 0;
	for(i = 0; i < k; i++){
		sum = sum + array[i];
	}

	printf("%d", sum);


}


Measured memory_bytes: 3844
import sys
p = [[0 for a in range(10)] for b in range(10)]
def smallink(x,y):
    return [(x+i,y+j) for i in range(-1,2,1) for j in range(-1,2,1)\
            if abs(i)+abs(j)<=1 and x+i>=0 and x+i<=9 and y+j>=0\
            and y+j<=9]
def ink(x,y):
    return [(x+i,y+j) for i in range(-1,2,1) for j in range(-1,2,1)\
            if x+i>=0 and y+j>=0 and x+i<=9 and y+j<=9]
def bigink(x,y):
    return [(x+i,y+j) for i in range(-2,3,1) for j in range(-2,3,1)\
            if abs(i)+abs(j)<=2 and x+i>=0 and y+j>=0 and x+i<=9\
            and y+j<=9]
for dataset in sys.stdin:
    x,y,size=map(int,dataset.split(","))
    if size==1:
        L=smallink(x,y)
    elif size==2:
        L=ink(x,y)
    else:
        L=bigink(x,y)
    while len(L)!=0:
        point=L.pop(0)
        p[point[0]][point[1]]+=1

count=0
max=0
for i in range(10):
    for j in range(10):
        if(p[i][j]>max):
            max=p[i][j]
        if(p[i][j]==0):
            count+=1
print count
print max

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

int main(){
  int N,M,cnt=0;
  cin >> N >> M;
  vector<int> X(M);
  rep(i,M)
    cin >> X.at(i);
  sort(X.begin(),X.end());

  if(M<=N){
    cout << cnt << endl;
  }else if(N==1){
    cout << X.at(M-1)-X.at(0) << endl;
  }else{
    vector<int> v(M-1);
    rep(i,M-1){
      v.at(i) = X.at(i+1)-X.at(i);
    }
    sort(v.begin(),v.end());
    rep(i,M-N)
      cnt += v.at(i);
    cout << cnt << endl;
  }
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
	
int a;
int b;

scanf("%d %d",&a,&b);

if(a<b){
printf("a < b\n");
}

if(a==b){
printf("a == b\n");
}

if(a>b){
printf("a > b\n");
}

return 0;

}

Measured memory_bytes: 580
using System;

namespace ABC164A
{
    class Program
    {
        static void Main(string[] args)
        {
            var target = Console.ReadLine().Split(' ');
            int S = int.Parse(target[0]);
            int W = int.Parse(target[1]);
            if(S > W) Console.WriteLine("safe");
            else Console.WriteLine("unsafe");

        }
    }
}

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

struct node {
	node *next[26] = {};
	int len[26] = {};
	int num = 0;
	int xx = 0;
	bool ok = false;
	node() {
		for (int i = 0; i < 26; i++) len[i] = 1;
	}
};

node *root = new node();

int get_num(node *x) {
	return x ? x->num : 0;
}

void add(string &s) {
	node *curr = root;
	for (char c : s) {
		if (!curr->next[c - 'a']) {
			curr->next[c - 'a'] = new node();
			curr->xx++;
		}
		curr = curr->next[c - 'a'];
	}
	curr->num++;
	curr->ok = true;
}

int dfs(node *u) {
	if (!u) return 0;
	for (int i = 0; i < 26; i++) {
		while (u->next[i] && u->next[i]->xx == 1 && !u->next[i]->ok) {
			for (int j = 0; j < 26; j++) {
				if (u->next[i]->next[j]) {
					u->next[i] = u->next[i]->next[j];
					u->len[i]++;
					break;
				}
			}
		}
		u->num += dfs(u->next[i]);
	}
	return u->num;
}

int ord(string &s, string &ls) {
	node *curr = root;
	int num = 0;
	for (int i = 0; i < s.size();) {
		char c = s[i];
		num += curr->ok;
		for (int j = 0; j < ls.size(); j++) {
			if (c == ls[j]) {
				i += curr->len[c - 'a'];
				curr = curr->next[c - 'a'];
				break;
			} else {
				num += get_num(curr->next[ls[j] - 'a']);
			}
		}
	}
	return num;
}

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

	vector<string> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		add(s[i]);
	}
	dfs(root);

	int q;
	cin >> q;
	for (int ii = 0; ii < q; ii++) {
		int k;
		string p;
		cin >> k >> p;
		k--;
		cout << ord(s[k], p) + 1 << endl;
	}
}

Measured memory_bytes: 132352
/**************************************************
 * Atcoder problems
 * Contest No :081
 * Problem No :B
 * File Name  :program.cs
 * Create date:2020/06/07
 *
 * Copyright 2020 Shunichi Sato,All Rights Reserved.
**************************************************/
//memo terinal command
//compile:mcs program.cs
//excute :mono program.exe
using System;
class Program
{
	static void Main(string[] args)
	{
        // 個数の入力
        int count = int.Parse(Console.ReadLine());
        String[] nums = Console.ReadLine().Split(' ');
        int[] num = new int[999];
        int output = 0;
        for (int i = 0; i<count;i++)
        {
            num[i] = int.Parse(nums[i]);
        }
        // 判定
        while (true)
        {
            bool exist_odd = false;
            for (int i = 0;i < count;i++)
            {
                if(num[i] % 2 != 0)
                {
                    exist_odd = true;
                }
            }
            if(exist_odd)
            {
                break;
            }

            for (int i = 0 ;i < count ; i++)
            {
                num[i] = num[i] / 2;
            }
            output++;
        }
		//出力
		Console.WriteLine(output);
	}
}


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

void swap(int &a, int &b) {
	int tmp = a;
	a = b;
	b = tmp;
}

int main(void) {
	string S, T;
	cin >> S >> T;
	string answer = "No";
	for (int i = 0; i < S.length(); i++) {
		for (int j = S.length() - 1; j > 0; j--) {
			swap(S[j], S[j - 1]);
		}
		if (S == T) {
			answer = "Yes";
			break;
		}
	}
	cout << answer << "\n";
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
 
int A[100000],n;
int binarySearch(int key){ //二分探索
  int mid;
  int left = 0;
  int right = n;
  while( left < right ){
    mid = (left + right ) / 2;
    if( A[mid] == key ) return 1;
    else if( key < A[mid] ) right = mid;
    else left = mid + 1;
  }
  return 0;
}
 
 
int main(){
  cin >> n;
  int i,cnt = 0;
  for( i = 0; i < n; i++ ) cin >> A[i];
  int t; cin >> t;
  for( i = 0; i < t; i++ ){
    int q; cin >> q;
    if( binarySearch(q) ) cnt++; //判定
  }
  cout << cnt << endl;
  return 0;
}

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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) int(x.size())
const int INF = 1001001001;
const ll mod = 998244353;
const ll INFL = 1001001001001001000;

vector<ll> divisor(ll N) {
    vector<ll> RES;
    for (ll I = 1; I*I <= N; I++) {
        if (N%I == 0) {
            RES.push_back(I);
            if (I != N/I) RES.push_back(N/I);
        }
    }
    return RES;
}

ll gcd(ll A, ll B) {
    return B ? gcd(B,A%B) : A;
}

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

int main() {
    ll n; cin >> n;
    if (n <= 100) {
        ll k = 1;
        while (1) {
            if ((k*(k+1)/2)%n == 0) {
                cout << k << endl;
                return 0;
            }
            k++;
        }
    }
    vector<ll> divi = divisor(2*n);
    ll ans = INFL;
    for (ll p : divi) {
        ll q = (2*n)/p;
        ll g = gcd(p,q);
        if (g != 1) continue;
        ll a,b;
        extGCD(p,q,a,b);
        a = -a;
        if (a == 0 || b == 0) continue;
        ll d = 0;
        if (a <= 0) {
            d = max(d, (-a+q-1)/q);
        }
        if (b <= 0) {
            d = max(d, (-b+p-1)/p);
        }
        a += q*d;
        //printf("a = %lld, b = %lld\n", a,b);
        ans = min(ans, p*a);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3708
#include <iostream>
using namespace std;
static int const MAX = 36;

struct Card
{
  char suit;
  char num;
};

void bubbleSort(Card C[], int N)
{
  for (int i = 0; i < N; i++)
  {
    for (int j = N - 1; j > i; j--)
    {
      if (C[j].num < C[j - 1].num)
      {
        Card temp = C[j];
        C[j] = C[j - 1];
        C[j - 1] = temp;
      }
    }
  }
}

void selectionSort(Card C[], int N)
{
  for (int i = 0; i < N; i++)
  {
    int minIndex = i;
    // より小さいものはないか探すループ
    for (int j = i; j < N; j++)
    {
      if (C[j].num < C[minIndex].num)
      {
        minIndex = j;
      }
    }
    // 最も小さいものを添え字0から順に入れていく
    Card temp = C[i];
    C[i] = C[minIndex];
    C[minIndex] = temp;
  }
}

void print(Card C[], int N)
{
  for (int i = 0; i < N; i++)
  {
    if (i > 0)
    {
      cout << " ";
    }
    cout << C[i].suit << C[i].num;
  }
  cout << endl;
}

bool isStable(Card C1[], Card C2[], int N)
{
  for (int i = 0; i < N; i++)
  {
    if (C1[i].suit != C2[i].suit)
    {
      return false;
    }
  }
  return true;
}

main()
{
  int N;
  Card CforBubble[MAX];
  Card CforSelection[MAX];

  cin >> N;
  for (int i = 0; i < N; i++)
  {
    cin >> CforBubble[i].suit >> CforBubble[i].num;
    CforSelection[i].suit = CforBubble[i].suit;
    CforSelection[i].num = CforBubble[i].num;
  }

  bubbleSort(CforBubble, N);
  selectionSort(CforSelection, N);

  print(CforBubble, N);
  cout << "Stable" << endl;

  print(CforSelection, N);
  if (isStable(CforBubble, CforSelection, N))
  {
    cout << "Stable" << endl;
  }
  else
  {
    cout << "Not stable" << endl;
  }

  return 0;
}


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

int main()
{
	set<int> s ;
	for(int i = 0 ; i < 3 ; ++i)
	{
		int x ;
		cin >> x ;
		s.insert(x) ;
	}
	cout << (s.size() == 2 ? "Yes" : "No") << endl ;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

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

using namespace std;
using ll = long long;


const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

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

int main() {
  int N;
  while(cin >> N) {
    if(N == 0) break;
    int ans = 0;
    for(int i = 1; i <= 1000; i++) {
      int sum = i;
      for(int j = i + 1; j <= 1000; j++) {
	sum += j;
	if(sum == N) ans++;
      }
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, H;
  cin >> N >> H;
  vl a(N), b(N);
  rep(i, N) cin >> a[i] >> b[i];

  stable_sort(a.begin(), a.end());
  stable_sort(b.begin(), b.end());

  ll amax = a[N - 1];
  ll cnt = (ll)(b.end() - upper_bound(b.begin(), b.end(), amax));

  if(cnt == 0){
    cout << (H / amax) + (H  % amax > 0 ? 1 : 0) << endl;
    return 0;
  }

  ll damage = 0;

  rep_inv(i, N - 1, N - cnt - 1){
    damage += b[i];
    if(damage >= H){
      cout << N - i << endl;
      return 0;
    }
  }

  H -= damage;
  cnt += (H / amax) + (H % amax > 0 ? 1 : 0);

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


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
  int N, tmp, res = 0;
  bool f = false;
  cin >> N;
  vector<int> h;
  for (int i=0; i<N; i++){
	cin >> tmp;
    h.push_back(tmp);
  }
  while (accumulate(h.begin(), h.end(), 0) > 0){
    tmp = 0;
    f = true;
    for (int i=0; i<N; i++){
      if (h[i] > 0){
        f = false;
        h[i]--;
      }
      else{
        if (!f){
			f = true;
          	tmp++;
        }
      }
    }
    if (!f) tmp++;
    res += tmp > 0 ? tmp : 1;
  }
  cout << res << endl;
  return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  double t, a;
  cin >> t >> a;
  double mi = 2e9;
  int sv = 0;
  for (int i = 1; i <= n; i++) {
    double d;
    cin >> d;
    d = t - d * 0.006;
    if (abs(a - d) < mi) {
      mi = abs(a - d);
      sv = i;
    }
  }
  cout << sv << '\n';
}


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

const int M = 1e5 + 1;

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

    int n, m, mod = 1e9 + 7, f[M], ans = 0;
    cin >> n >> m;

    f[0] = 1;
    for (int i = 1; i < M; i++)
        f[i] = (1ll * f[i - 1] * i) % mod;

    if (m > n)
        swap(n, m);
    if (n - m <= 1)
        ans = (1ll * f[n] * f[m]) % mod;
    if (n - m == 0)
        ans *= 2, ans %= mod;

    cout << ans << '\n';
}

Measured memory_bytes: 4000
def main():
    """
    1 <= N  <= 10^9

    七五三数とは以下の条件を満たす正の整数
    十進法で表記したとき、
    数字 7, 5, 3 がそれぞれ 1回以上現れ、これら以外の数字は現れない
    """
    N = int(input())

    # ans = f(N)
    ans = editorial(N)
    ans2 = editorial_movie(N)
    assert ans == ans2
    print(ans)


def editorial(N):
    def dfs(s):
        if int(s) > N:
            return 0

        ret = all(s.count(c) for c in "753")
        ret = int(ret)

        for c in "753":
            ret += dfs(s + c)

        return ret

    ans = dfs("0")
    return ans


def editorial_movie(N):
    def dfs(x):
        if x > N:
            return 0

        s = str(x)
        ret = all(s.count(c) for c in "753")
        ret = int(ret)

        for c in [7,5,3]:
            ret += dfs(x * 10 + c)

        return ret

    ans = dfs(0)
    return ans

if __name__ == '__main__':
    main()


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



Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a * b % 2 == 0)
		cout << "Even" << "\n";
	else
		cout << "Odd" << "\n";
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,t,x,y;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>t>>x>>y;
        if(x+y>t)
        {
            cout<<"No";
            return 0;
        }
        if((x+y)%2==0&&t%2==1)
        {
            cout<<"No";
            return 0;
        }
        if((x+y)%2==1&&t%2==0)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

    public static void main(String __[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int total_candy = 0;
        for(int x=1; x<=N; x++){
            total_candy = total_candy + x;
        }
        System.out.println(total_candy);

    }
}

Measured memory_bytes: 21844
#include <stdio.h>

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

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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;


const int MAXN = (int)2e5+1;
int N, dp[MAXN], powersof10[7];

int match(int a)
{
    int numDigs = log10(a)+1;
    int lastDig = a%10;
    int temp = a;
    while(a >= 10)
    {
        a/=10;
    }
    int firstDig = a;
    if(lastDig == 0 || firstDig == 0)
    {
        return 0;
    }
    if(lastDig > firstDig)
    {
        if(numDigs<3)
            return 0;
        else
            return (powersof10[numDigs-2] - 1)/9;
    }
    else if(firstDig > lastDig)
    {
            return (powersof10[numDigs-1]-1)/9;
    }
    else
    {
        if(numDigs < 2)
            return 1;
        int ans = 1;
        ans += (powersof10[numDigs-2] - 1)/9;
        ans += (temp - firstDig * powersof10[numDigs-1] - firstDig)/10+1;

        return ans;
    }

}

bool firstEqualsLast(int i)
{
    int lastDig = i%10;
    while(i >= 10)
    {
        i/=10;
    }
    return lastDig == i;
}

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    powersof10[0] = 1;
    for(int i=1; i<=7; i++)
    {
        powersof10[i] = powersof10[i-1]*10;
    }
    for(int i=1; i<=N; i++)
    {
        dp[i] = dp[i-1] + 2*match(i) - firstEqualsLast(i);
        //cout << i << " " << dp[i] << "\n";
    }
    cout << dp[N];
    return 0;
}



Measured memory_bytes: 1024
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
string s, t, u; int n, a, b;
int main() {
	cin >> s >> n;
	for(int i = 0; i < n; i++) {
		cin >> t;
		if(t == "print") cin >> a >> b, cout << s.substr(a, b - a + 1) << endl;
		if(t == "reverse") cin >> a >> b, reverse(s.begin() + a, s.begin() + b + 1);
		if(t == "replace") cin >> a >> b >> u, s.replace(a, b - a + 1, u);
	}
	return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>

int N;
int A[222222];


int kotae[222222];


int main(void) {
	int i;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 2; i <= N; i++) {
		if (scanf("%d", &A[i]) != 1) return 1;
	}

	for (i = 2; i <= N; i++) {
		kotae[A[i]]++;
	}

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

	return 0;
}


Measured memory_bytes: 3292
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define def(x) cerr << #x << " is " << x << endl;
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(ll i=a;i<n;i++)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(a) a.begin(),a.end()
const int NUM = 2e5 + 5;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
int main(){
    ios
    int num_tests=1; 
    //cin>>num_tests;
    while(num_tests-->0){
        ll n,k; cin>>n>>k;
        vector<ll> a(n);
        FOR(i,0,n) cin>>a[i];
        sort(all(a));
        ll ans = 0;
        FOR(i,0,k) ans+=a[i]; 
        cout<<ans;
    }   
}

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

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

  int ans = 1 << 30;
  rep(_, N) {
    int A;
    cin >> A;
    int count = 0;
    while (A % 2 == 0) {
      A /= 2;
      count++;
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;


int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, M; cin >> N >> M;
  if (N == M) {
    cout << "Yes\n";
  }else {
    cout << "No\n";
  }

  return 0;
}



Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <iterator>
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <regex>
#include <stdexcept>
#include <unordered_set>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <cassert>
#include <time.h>
#include <numeric>
#include <complex>
  
using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using D = double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
  
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define fill(x, y) memset(x, y, sizeof(x))
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define rep(i, x)  for(int i = 0; i < (x); i++)
#define rrep(i, x) for(int i = (x - 1); i >= 0; i--)
#define y1 y1_1234413
#define j1 j1_235
#define y0 y0_235
#define j0 j0_256
#define fi first
#define se second
#define itn int
#define re return
#define prev PREV
#define next NEXT
  
#define sz(x) ((int)x.size())
  
const int inf = 2e9;
const ld st = 0.000001;
const ld pi = acos((ld)-1);
const int MAXN = 1e5;
#define FILENAME ""
const double eps = 1e-6;
const int maxn = 1001;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    //freopen("unionday.in", "r", stdin);
    //freopen("unionday.out", "w", stdout);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = 0;
    for (int i = 0; i <= d/a; i++) {
        for (int j = 0; j <= d/b; j++) {
            int temp = d - i*a - j*b;
            if (temp < 0) continue;
            if (temp == 0) {
                ++ans;
            }
            else if (temp % c == 0) {
                ++ans;
            }
        }
    }
    cout << ans;
    return 0;
}

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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

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

  int n = 0;
  rep(i, N)
  {
    n ^= A[i];
  }

  rep(i, N - 1)
  {
    cout << (n ^ A[i]) << " ";
  }
  cout << (n ^ A[N - 1]) << endl;

  return 0;
}


Measured memory_bytes: 4020