akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	n := readInt()
	a := make([]int, n)
	for i := range a {
		a[i] = readInt()
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	var score [2]int
	i := 0
	for _, v := range a {
		score[i] += v
		i = 1 - i
	}
	println(score[0] - score[1])
}


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

class UnionFind
{
public:
    vector<int> parent;
    vector<int> rank;
    vector<int> size;
    
    UnionFind(int n): parent(n), rank(n), size(n)
    {
        for(int i=0;i<n;i++)
            parent[i] = i,
            rank[i] = 0,
            size[i] = 1;
    }

    int root(int x)
    {
        return parent[x]==x ? x : parent[x] = root(parent[x]);
    }

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

    void unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x != y)
        {
            if (rank[x] < rank[y])
            {
                size[root(y)] += size[root(x)];
                parent[x] = y;
            }
            else
            {
                size[root(x)] += size[root(y)];
                parent[y] = x;
            }
            if (rank[x]==rank[y])
                rank[x]++;
        }
    }
};

#include <iostream>

int main()
{
    int N, M;
    cin>>N>>M;
    vector<int> A(M);
    vector<int> B(M);
    for (int i=0; i<M; i++)
    {
        cin>>A[i]>>B[i];
        A[i]--;
        B[i]--;
    }

    long long c = (long long)N*(N-1)/2;
    UnionFind UF(N);
    vector<long long> ans(M);
    ans[M-1] = c;
    for (int i=M-1; i>=1; i--)
    {
        if (!UF.same(A[i], B[i]))
        {
            c -= (long long)UF.size[UF.root(A[i])] * UF.size[UF.root(B[i])];
            UF.unite(A[i], B[i]);
        }
        ans[i-1] = c;
    }
    for (int i=0; i<M; i++)
    {
        cout<<ans[i]<<endl;
    }
}


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

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

Measured memory_bytes: 3616
#include<stdio.h>
#define N 101

int main(void){
    int n, x;
    int l[N] = {0};
    int i;
    int d = 0;

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

    for(i = 0; i < n + 1 && d <= x; i++){
        d += l[i];
    }

    printf("%d", i);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll; 
const ll mod = 1e9+7;
#define fo(i, n) for (int i = 0; i < n; i++)
#define sc(n) scanf("%d", &n) 
using namespace std;

ll n;

void solve() {
    cin >> n;
    ll count[n+1] = {0};
    ll a[n];
    ll regular[n+1];
    ll oneGone[n+1];
    fo(i, n) {
        cin >> a[i];
        count[a[i]]++;
    } 
    fo(i, n) {
        regular[i+1] = (count[i+1] * (count[i+1] - 1))/2;
        oneGone[i+1] = max(((count[i+1]-1) * (count[i+1]-2))/2, (ll) 0);
    }
    ll sumRegular = 0;
    fo(i, n) sumRegular += regular[i+1];
    fo (i, n) {
        cout << sumRegular-regular[a[i]]+oneGone[a[i]] << '\n';
    }
}

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

Measured memory_bytes: 8832
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	double n,x;
	scanf("%lf%lf",&n,&x);
	double ans=n/x;
	printf("%0.9lf\n",ans);
}


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

#define INFTY (1 << 30);
typedef long long ll;

int main(void) {

  int S;
  cin >> S;

  int front = S / 100;
  int back = S % 100;

  int front_month_possible = false;
  if (front >= 1 && front <= 12) {
    front_month_possible = true;
  }

  int back_month_possible = false;
  if (back >= 1 && back <= 12) {
    back_month_possible = true;
  }

  if (front_month_possible & back_month_possible){
    cout << "AMBIGUOUS" << endl;
  } else if (front_month_possible) {
    cout << "MMYY" << endl;
  } else if (back_month_possible) {
    cout << "YYMM" << endl;
  } else {
    cout << "NA" << endl;
  }
  
  
  
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T x=0,f=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	char s[209];int n;
	int main(){
		scanf("%s",s+1);
		n=strlen(s+1);

		int len=(n-1)/2;
		for(int i=1;i<=len;i++)
			if(s[i]!=s[len-i+1]) puts("No"),exit(0);
		int tmp=(n+3)/2-1;
		for(int i=1;i<=len;i++)
			if(s[tmp+i]!=s[tmp+len-i+1]) puts("No"),exit(0);
		for(int i=1;i<=n;i++)
			if(s[i]!=s[n-i+1]) puts("No"),exit(0);
		puts("Yes");
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

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

int  LinearSearch(int S[],int n,int T[],int q){

    int count=0;

    for(int i=0;i<q;i++){
        for(int j=0;j<n;j++){
            if(S[j] == T[i]){
                count++;
                break;
            }
        }
    }

    return count;
}

int main(){
    
    int n=0,q=0;

    cin >> n;
    int* S = new int[n];
    for(int i=0;i<n;i++){
        cin >> S[i];
    }

    cin >> q;
    int* T = new int[q];
    for(int i=0;i<q;i++){
        cin >> T[i];
    }

    cout << LinearSearch(S,n,T,q) << endl;

    return 0;
}

Measured memory_bytes: 3108
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static List<int>[] from;
    static List<int>[] to;
    static int[] answer;

    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int m = sc.NextInt();

        from = new List<int>[n + 1];

        for (int i = 0; i < n + 1; i++)
        {
            from[i] = new List<int>();
        }

        for (int i = 0; i < m; i++)
        {
            int a = sc.NextInt();
            int b = sc.NextInt();

            from[a].Add(b);
            from[b].Add(a);
        }

        answer = new int[n + 1];
        answer[0] = -1;

        Queue<int> que = new Queue<int>();
        que.Enqueue(1);
        while (que.Count > 0)
        {
            var num = que.Dequeue();

            var nextList = from[num];
            foreach (var next in nextList)
            {
                if (answer[next] == 0)
                {
                    answer[next] = num;
                    que.Enqueue(next);
                }
            }
        }

        Console.WriteLine("Yes");
        for (int i = 2; i <= n; i++)
        {
            Console.WriteLine(answer[i]);
        }
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 50684
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

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

    for(int i = 0; i < t.length(); i++){
        if(t[i] == '?'){
            t[i] = 'D';
        }
    }

    cout << t << endl;

    return 0;
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
    int n, k;
    cin >> n >> k;
    int eat;
    if (k < 0) {
        eat = min(0, k + n - 1);
    } else {
        eat = k;
    }
    int ans = 0;
    rep(i, n) {
        ans += k + i;
    }
    ans -= eat;
    out(ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n;
  cin >> n;
  int h[n];
  for(int i = 0; i<n;++i){
    cin >> h[i];
  }

  bool enable = true;
  int tmp = h[0] - 1;
  for(int i = 1; i<n;++i){
    if(h[i] < tmp){
      enable = false;
      break;
    }else if(h[i] > tmp){
      tmp = h[i] - 1;
    }
  }
  if(enable){printf("Yes\n");}
  else{printf("No\n");}
  
  
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a<b){
        System.out.println("a < b");
        }else if(a>b){
        System.out.println("a > b");
        }else if(a==b){
        System.out.println("a == b");
        }
    }
}
 

Measured memory_bytes: 26072
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;

bool AC[100010];
int WA[100010];

int main (){
  int N, M;
  cin >> N >> M;
  int p[M];
  string S[M];
  for (int i = 0; i < M; ++i) {
    cin >> p[i] >> S[i];
    p[i] -= 1;

    if (S[i] == "AC") {
      AC[p[i]] = true;
    } else {
      if (!AC[p[i]]) {
        ++WA[p[i]];
      }
    }
  }

  int ac = 0, wa = 0;
  for (int i = 0; i < N; ++i) {
    if (AC[i]) {
      ++ac;
      wa += WA[i];
    }
  }

  cout << ac << " " << wa << endl;

  return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define int long long
#define INT_MAX INT64_MAX
#define INT_MIN INT64_MIN
#define PI 3.14159265358979323846
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define MOD 1000000007
/* DEFINE cout */
#define pln cout << "===============================\n"
#define on cout<<"\n"
#define os cout<<" "
#define o2(a,b) cout<<a<<" "<<b
#define o(a) cout << a
#define bitcount __builtin_popcountll
/* DEFINE cout */
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int x,int y){
    int res = 1;
    int p = MOD;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
signed main(){
    int n;
    cin >> n;
    if(n >= 30){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
}






Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>

int n;
char inpt[1001][1001];
char pre;

int main(){
    int i,j,cmp,dab=0;
    scanf("%d",&n);
    scanf("%s",&inpt[1]);
    pre=inpt[1][strlen(inpt[1])-1];
    for(i=2; i<=n; i++){
        scanf("%s",&inpt[i]);
        for(j=1; j<i; j++){
            cmp=strcmp(inpt[j],inpt[i]);
            if(cmp==0) dab=1;
        }
        if(pre!=inpt[i][0]) dab=1;
        pre=inpt[i][strlen(inpt[i])-1];
    }
    if(dab==1) printf("No");
    else printf("Yes");
    return 0;
}


Measured memory_bytes: 256
program main
  implicit none
  integer(8) N,i,j,k,xi,yi,p,q,score,TOP
  integer(8),allocatable :: X(:),Y(:)

  read(*, *) N
  allocate(X(N),Y(N))
  do i = 1,N
    read(*, *)xi, yi
    X(i) = xi
    Y(i) = yi
  end do
  !score = 0
  TOP = 0
  do xi = 1,N
    do yi = 1,N
      if (xi /= yi) then
        p = X(xi)-X(yi)
        q = Y(xi)-Y(yi)
        score = 0
        do i = 1,N
          do j = 1,N
            if (X(i)-X(j) == p .and. Y(i)-Y(j) == q) then
              score = score + 1
            end if
          end do
        end do
        if (TOP < score) then
          TOP = score
        end if
      end if
    end do
  end do 
  write(*,*) N-TOP
end program main


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
// #include "debug.h"
#define debug(...) 42

const int mod = 1e9 + 7;

string get(string s, string t, int idx) {
   for(int i = idx; i < idx + t.length(); i++) {
      if(s[i] == '?') {
         s[i] = t[i - idx];
      } else if(s[i] == t[i -idx]) {
         continue;
      } else {
         return "";
      }
   }
   for(auto &c: s) {
      if(c == '?') {
         c = 'a';
      }
   }
   return s;
}

void solve() {
   string s, t;
   cin >> s >> t;
   string ans(51, 'z');

   int n = s.length();
   int m = t.length();
   
   for(int i = 0; i + m - 1 < n; i++) {
      string t_ans = get(s, t, i);
      if(!t_ans.empty()) {
         ans = min(ans, t_ans);
      }
   }

   debug(ans);
   if(ans == string(51, 'z')) 
      ans = "UNRESTORABLE";
   cout << ans << endl;
} 

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;

   for(int i = 0; i < testcase; i++) {
      solve();
   }
   return 0;
}


Measured memory_bytes: 3652
def solve():
    K, A, B = map(int, input().split())

    if K < (A - 1):
        return 1 + K
    else:
        if (B - A) >= 2:
            K -= (A - 1)
            q, r = divmod(K, 2)
            return A + q * (B - A) + r
        else:
            return 1 + K


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 2940
#include<stdio.h>
#include<algorithm>
#include<string.h>
#define N 3005
using namespace std;
char strOne[N], strTwo[N];
int dp[N][N];
int process[N][N];
int m,n;
void root(int m,int n)
{
	if (m == 0 || n == 0)
		return;
	if (process[m][n] == 1)
	{
		root(m - 1, n - 1);
		printf("%c", strOne[m]);
	}
	else if (process[m][n] == 0)
		root(m - 1, n);
	else
		root(m, n - 1);
}
int main()
{
	while(scanf("%s %s",strOne + 1,strTwo + 1 )!= EOF)
	{
		m = strlen(strOne + 1);
		n = strlen(strTwo + 1);
		memset(dp, 0, sizeof(dp));
		for (int i = 1; i <= m; i++)
			for (int j = 1; j <= n; j++)
				if (strOne[i] == strTwo[j])
				{
					if (dp[i][j] < dp[i - 1][j - 1] + 1)
						dp[i][j] = dp[i - 1][j - 1] + 1, process[i][j] = 1;
				}
				else if (dp[i - 1][j] > dp[i][j - 1])
					dp[i][j] = dp[i - 1][j], process[i][j] = 0;
				else
					dp[i][j] = dp[i][j - 1], process[i][j] = -1;
		if (dp[m][n] == 0)
			printf(" \n");
		else root(m,n);
	}
	return 0;
}

Measured memory_bytes: 70784
s1 = input()
r1 = "Yes"

for i1 in range(len(s1)):
    if i1 % 2 == 0:
        if s1[i1] == "L":
            r1 = "No"
    else:
        if s1[i1] == "R":
            r1 = "No"

print(r1)

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <map>


using namespace std;

int main(void) {

	int N, A[100010], B[100010], tmp = 0, ans;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
		if (tmp < A[i]) {
			tmp = A[i];
			ans = A[i] + B[i];
			//if (tmp == N) {
			//	break;
			//}
		}
	}
	   	  
	cout << ans;

	return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin>>n){
    vector<int> v;
    for(int i=10;i>=0;i--){
      if(n>=(1<<i)){
	n-=(1<<i);
	v.push_back(1<<i);
      }
    }
    sort(v.begin(),v.end());
    cout << v[0];
    for(int i=1;i<v.size();i++) cout << " " << v[i];
    cout << endl;
  }
}

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

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;

    for (int i = 0; i < s.length(); ++i) {
        rotate(s.rbegin(), s.rbegin() + 1, s.rend());
        if (s == t) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

	for (int i = 0; true; i++) {
		int x, y;
		cin >> x >> y;
		if (!(x | y))
			return 0;
		if (x > y)
			swap(x, y);
		cout << x << ' ' << y << endl;
	}

	return 0;

}

Measured memory_bytes: 3040
def isprime x
    prime = true
    2.upto(Math.sqrt(x)){|y|
        if x % y == 0
            prime = false
            break
        end
    }
    prime
end

primes, twin_primes, max_twin_primes = [], [], []
2.upto(10000){|x| primes << x if isprime x}
prev = primes[0]
primes[1..-1].each{|x|
    twin_primes << [prev, x] if x - prev == 2
    prev = x
}
twin_primes.each{|x, y| max_twin_primes[y] = [x, y]}
5.upto(10000){|i| max_twin_primes[i] = max_twin_primes[i - 1] if max_twin_primes[i].nil?}

while true
    n = gets.to_i
    break if n == 0
    puts max_twin_primes[n].join(" ")
end


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

using namespace std;

using int64 = long long;

string div2(string x) {
  string ret;
  int add = 0;
  for(int i = 0; i < x.size(); i++) {
    add += x[i] - '0';
    ret += (add / 2) + '0';
    add %= 2;
    add *= 10;
  }
  return ret;
}

string add(string x, string y) {
  string z = x;
  int add = 0;
  for(int i = x.size() - 1; i >= 0; i--) {
    add += x[i] - '0';
    add += y[i] - '0';
    z[i] = add % 10 + '0';
    add /= 10;
  }
  return z;
}

int64 beet(int64 x, int64 y) {
  return min(x + y, 1LL << 60);
}


string S;
int64 dp[61][10][10][2][2][2];

int64 rec(int idx, int x, int y, bool x_used, bool y_used, bool lim, bool zero) {
  if(idx == S.size()) return x_used && y_used;
  if(!lim && ~dp[idx][x][y][x_used][y_used][zero]) return dp[idx][x][y][x_used][y_used][zero];
  int64 ret = 0;
  for(int i = 0; i <= (lim ? S[idx] - '0' : 9); i++) {
    if(x != i && (i > 0 || !zero) && y != i) continue;
    ret = beet(ret, rec(idx + 1, x, y, x_used | (i == x && (x > 0 || !zero)), y_used | (i == y), lim & (i == S[idx] - '0'), zero & (i == 0)));
  }
  if(!lim) dp[idx][x][y][x_used][y_used][zero] = ret;
  return ret;
}

int64 check(string x) {
  S = x;
  int64 sub = 0;
  for(int i = 0; i < 10; i++) {
    for(int j = i + 1; j < 10; j++) {
      sub = beet(sub, rec(0, i, j, false, false, true, true));
    }
  }
  return sub;
}

int main() {
  memset(dp, -1, sizeof(dp));
  int64 N;
  while(cin >> N, N) {
    string ok = string(60, '0'), ng = string(60, '9');
    string one = string(60, '0');
    one.back() = '1';
    while(add(ok, one) < ng) {
      string mid = div2(add(ok, ng));
      if(check(mid) < N) ok = mid;
      else ng = mid;
    }
    int ptr = 0;
    ok = add(ok, one);
    while(ptr < ok.size() && ok[ptr] == '0') ++ptr;
    while(ptr < ok.size()) cout << ok[ptr++];
    cout << endl;
  }
}


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

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int X = sc.nextInt();
		int L = Math.max(-1000000, X - K + 1);
		int R = Math.min(1000000, X + K - 1);
		for (int i = L; i <= R; ++i) {
			System.out.print(i + (i == R ? "\n" : " "));
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


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

int main() {
    int N;
    cin >> N;
    vector <int> A(N+10,0);
    int S = 0;
    for(int i=0;i<N;i++){
        cin >> A[i];
        S ^= A[i];
    }

    for(int i=0;i<N;i++){
        cout << (A[i]^S) << " ";
    }
    return 0;
}

Measured memory_bytes: 3996
/*----------------
     Smit Patel
     DA-IICT
----------------*/
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// #define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ins insert
#define fori(i,a,n) for(int i=a; i<n; i++)
#define ford(i,a,n) for(int i=a; i>n; i--)
#define clr(a,b) memset(a,b,sizeof(a))
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define debug(x,y) cout<<#x<<" : "<<x<<"  "<<#y<<" : "<<y<<endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define bp __builtin_popcount
#define mod 1000000007
#define eps 1e-6
#define infi 1000000002
#define infll 1e18+5
#define N 200005
#define LN 23

typedef long double ld;
typedef long long ll;
typedef map<ll,ll> mll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef set<ll> sll;

ll choose(ll n,ll k);
bool isprime(ll n);
ll power(ll x,ll y,ll p);
ll power(ll x,ll y);
ll gcd(ll a,ll b);

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll t=1;
  // cin>>t;
  while(t--)
  {
    ll n;
    cin>>n;
    string s;
    set<string> st;
    fori(i,0,n)
    {
      cin>>s;
      st.ins(s);
    }
    cout<<st.size()<<endl;
  }
  return 0;
}

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

ll choose(ll n,ll k)
{
  if(k==0)
    return 1;
  return (n* choose(n-1,k-1))/k;
}

bool isprime(ll n)
{
  for(ll i=2;i*i<=n;i++)
  {
    if(n%i==0)
      return false;
  }
  return true;
}

ll power(ll x,ll y,ll p)
{
  ll res=1;
  x=x%p;
  while(y>0)
  {
    if(y&1)
      res=(res*x)%p;
    y=y>>1;
    x=(x*x)%p;
  }
  return res;
}

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0)
  {
    if(y&1)
      res=res*x;
    y=y>>1;
    x=x*x;
  }
  return res;
}


Measured memory_bytes: 19288
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<algorithm>
#include<list>
#include<cstring>
#include <numeric>

#define ll long long
#define int long long
#define ld long double
#define endl "\n"
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
const ll MOD = 1e9 + 7;
const int N = 2e12+5;
const int demo = 10;
using namespace std;
const ll cfmod=998244353;
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

signed main(){
    int q=1;
    //cin>>q;
    while(q--) {
        int n,m,k;
        cin>>n>>m>>k;
        int a[n+1],b[m+1];
        vector<int> lol1,lol2;
        lol1.push_back(0);
        int sum=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            sum+=a[i];
            lol1.push_back(sum);
        }
        sum=0;
        lol2.push_back(0);
        for(int i=1;i<=m;i++){
            cin>>b[i];
            sum+=b[i];
            lol2.push_back(sum);
        }
        int maxi=0;
        //debugv(a1)debugv(b1)
        for(int i=0;i<=n;i++){
            int num=lol1[i];
            int diff=k-num;
            if(diff>0){
                auto itr=lower_bound(lol2.begin(),lol2.end(),diff);
                if(*itr!=diff){
                    itr--;
                }
                int j=itr-lol2.begin();
                maxi=max(maxi,i+j);
            }
            else if(diff==0){
                maxi=max(maxi,i);
            }
        }
        cout<<maxi;
    }
}

Measured memory_bytes: 10132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Vec = vector<int>;
using Graph = vector<Vec>;

int		main(void)
{
	int n, k, q;
	cin >> n >> k >> q;
	Vec hito(n, 0);
	for (int i = 0; i < q; i++)
	{
		int tmp;
		cin >> tmp;
		hito[tmp - 1]++;
	}
	for (int i = 0; i < n; i++)
	{
		if (q - hito[i] < k)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
}


Measured memory_bytes: 1024
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=1e5+4;

int main()
{
	int n,a[3];

	scn(n);

	rep(i,0,3)
	scn(a[i]);

	// /scn(n);

	string s[n];

	rep(i,0,n)
	cin>>s[i];

	//cout<<s[0]<<endl;

	vector<char> v;

	string as[]={"AB","AC","BC"};

	rep(i,0,n)
	{
		int x=s[i].at(0)-'A',y=s[i].at(1)-'A';

		if(a[x]==0 and a[y]==0)
		{
			printf("No"); return 0;
		}
		else if(a[x]==0)
		a[x]++,a[y]--,v.pb(s[i].at(0));
		else if(a[y]==0)
		a[y]++,a[x]--,v.pb(s[i].at(1));
		else
		{
			if(i+1<n)
			{
				if(a[x]==1 and a[y]==1)
				{
					int x1=s[i+1].at(0)-'A',y1=s[i+1].at(1)-'A';

					int other=3-x-y;

					if(x1==other and a[x1]==0)
					{
						if(y1==x)
						a[x]++,a[y]--,v.pb(s[i].at(0));
						else
						a[y]++,a[x]--,v.pb(s[i].at(1));
					}
					else if(y1==other and a[y1]==0)
					{
						if(x1==x)
						a[x]++,a[y]--,v.pb(s[i].at(0));
						else
						a[y]++,a[x]--,v.pb(s[i].at(1));
					}
					else
					a[x]++,a[y]--,v.pb(s[i].at(0));
				}
				else
				{
					if(a[x]>a[y])
					a[x]--,a[y]++,v.pb(s[i].at(1));
					else
					a[x]++,a[y]--,v.pb(s[i].at(0));
				}
			}
			else
			v.pb(s[i].at(0));
		}
	}

	cout<<"Yes\n";

	for(auto it:v)
	cout<<it<<"\n";

    return 0;
}

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

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

    if(a == b){
        cout << "Draw" << endl;
    }else if(a == 1 || b == 1){
        if(a == 1){
            cout << "Alice" << endl;
        }else{
            cout << "Bob" << endl;
        }
    }else{
        if(a < b){
            cout << "Bob" << endl;
        }else{
            cout << "Alice" << endl;
        }
    }
}

Measured memory_bytes: 256
def check(x,y,d)
  return (y - x).abs <= d
end

def main
  a,b,c,d=gets.split(" ").map(&:to_f)
  res = check(a,b,d) && check(b,c,d) || check(a,c,d)
  puts res ? 'Yes' : 'No'
end
main

Measured memory_bytes: 1916
n=int(input())
a=list(map(int,input().split()))
a.sort()
xy=[]
for i in range(n-2,0,-1):
  y=a[i]
  if y>0:
    x=a[0]
    a[0]-=y
  else:
    x=a[n-1]
    a[n-1]-=y
  xy.append((x,y))
print(a[n-1]-a[0])
xy.append((a[n-1],a[0]))
print('\n'.join([' '.join(map(str,t)) for t in xy]))

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

string s;

int main() {
    cin >>s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '?') s[i] = 'D';
    }
    cout << s << endl;
    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int main()
{
    int A,B;
    cin >>A >>B;

    vector<int> a(A),b(B);
    rep(i,A) scanf(" %d", &a[i]);
    rep(i,B) scanf(" %d", &b[i]);

    int ans=0;
    //B???????????????????????????
    rep(i,B)
    {
        int tmp=0;

        int now=i;
        //A????????????????????????????????????????????§???????????????????????¶
        rep(j,A)
        {
            if(b[now]==a[j])
            {
                ++now;
                ++tmp;
            }

            if(now==B) break;
        }

        ans=max(ans,tmp);
    }

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

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

int main(){
  int64_t N;
  cin >> N;
  int64_t ans;
  for(int64_t i=sqrt(N);i>=1;i--){
    if(N%i==0){
      int64_t j=N/i;
      ans=i+j-2;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val p = (1..n).map { sc.nextInt() }
  val q = (1..n).map { sc.nextInt() }

  println(abc150c(n, p, q))
}

private fun abc150c(n: Int, p: List<Int>, q: List<Int>): Int {
  val pStr = p.joinToString("")
  val qStr = q.joinToString("")
  val array = (1..n).map { it }.toIntArray()

  var count = 1
  var a = 0
  var b = 0
  do {
    val arrayStr = array.joinToString("")
    if (arrayStr == pStr) a = count
    if (arrayStr == qStr) b = count

    count++
  } while (findNextPermutation(array))

  return Math.abs(a - b)
}

private fun findNextPermutation(array: IntArray): Boolean {
  if (array.size <= 1) return false

  var last = array.size - 2
  while (last >= 0) {
    if (array[last] < array[last + 1]) break
    last--
  }
  if (last < 0) return false

  var nextGreater = array.size - 1
  var i = array.size - 1
  while (i > last) {
    if (array[i] > array[last]) {
      nextGreater = i
      break
    }
    i--
  }
  swap(array, nextGreater, last)
  reverse(array, last + 1, array.size - 1)

  return true
}

private fun swap(array: IntArray, left: Int, right: Int): IntArray {
  val tmp = array[left]
  array[left] = array[right]
  array[right] = tmp
  return array
}

private fun reverse(array: IntArray, left: Int, right: Int): IntArray {
  var l = left
  var r = right
  while (l < r) {
    val tmp = array[l]
    array[l++] = array[r]
    array[r--] = tmp
  }
  return array
}


Measured memory_bytes: 41524
from collections import defaultdict as dd

# 定数
INF = float("inf")
MOD = int(1e9 + 7)

# エントリーポイント
def main():
    S = input()
    N = len(S)

    class solve:
        def __init__(self):
            self.v = [0, 0]
    count = dd(solve)
    for i, s in enumerate(S):
        count[i % 2].v[int(s)] += 1
    # for k, v in count.items():
    #     print(k, v.v)
    print(min(count[0].v[0] + count[1].v[1], count[0].v[1] + count[1].v[0]))

main()


Measured memory_bytes: 3564
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
N,M = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(M)]
es = [[] for _ in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

prev = [-1] * N
visited = [0] * N
visited[0] = 1
from collections import deque
q = deque([0])
while q:
    v = q.popleft()
    for to in es[v]:
        if visited[to]: continue
        visited[to] = 1
        prev[to] = v
        q.append(to)

print('Yes')
for p in prev[1:]:
    print(p+1)

Measured memory_bytes: 62448
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  rep(i,n)
    cin>>a.at(i);
  sort(all(a));
  int ans=0;
  rep(i,k){
    ans+=a.at(i);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n,la=0,now=0,c,ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&c);
		if(c==la)
			now++;
		else
		{
			ans+=now/2;
			now=1;
			la=c;
		}
	}
	ans+=now/2;
	printf("%d",ans);
	return 0;
}

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

using namespace std;

int main(void)
{
    int N, Q;
    string S;
    cin >> N >> Q >> S;
    vector<pair<int, int>> q(Q);
    for (auto &i: q) cin >> i.first >> i.second;
    vector<int> sum(N + 1, 0);
    for (int i = 1; i < N; i++)
    {
        sum[i + 1] = sum[i] + int(S[i - 1] == 'A' && S[i] == 'C');
    }
    for (auto i: q) cout << sum[i.second] - sum[i.first] << endl;
    return 0;
}

Measured memory_bytes: 2176
def abc096_b():
    import numpy as np
    abc = list(map(int, input().split()))
    k = int(input())
    num = np.max(abc)
    argnum = np.argmax(abc)
    abc.remove(abc[argnum])

    return np.sum(abc) + num * (2 ** k)


print(abc096_b())

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
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; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) { 
        cin >> A[i];
    }
    ll ans = 0;
    A.push_back(0);
    rep(i, N) {
        ans += A[i] / 2;
        if (A[i] % 2 == 1 && A[i+1] > 0) {
            ans++;
            A[i+1] --;
        }
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
    char s[6];
    scanf("%s",s);
    if(s[0]=='S') printf("Cloudy\n");
    else if(s[0]=='C') printf("Rainy\n");
    else if(s[0]=='R') printf("Sunny");
    return 0;
}
       

Measured memory_bytes: 128
using System;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        var c = sc.Next()[0];
        Console.WriteLine((char) (c + 1));
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

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

using namespace std;

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

  sort(m.begin(), m.end());
  long long ans = n;
  for(int i = 0; i < n; i++) {
    x -= m[i];
  }
  ans += x / m[0];
  cout << ans << endl;
}

Measured memory_bytes: 256
h,w = map(int, input().split())

for i in range(h):
	t = list(map(str,input().split()))
	for j in range(w):
		if t[j] == "snuke":
			hh = str(i+1)
			ww = chr(65+j)
			break

print("".join([ww,hh]))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,m,n) for(int i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
const ll INF=1LL<<60;
const ll mod=1E9+7;


int main(){
  int a,b,c,d,i=0;
  cin >> a >> b >> c >> d;
  while(1){
    if(a<=0||c<=0)break;
    if(i%2==0)c-=b;
    else a-=d;
    i++;
  }
  if(c<=0)cout << "Yes";
  else cout << "No";

}


Measured memory_bytes: 3632
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }


int main() {
	
	long N; cin >> N;
	//1の位が1であるような55555以下の素数を55個見つければよい。
	bool isprime[60000]; for (int i = 2; i <= 55555; i++) isprime[i] = true;
	
	for (int i = 2; i <= 55555; i++) {
		if (isprime[i] == true) {
			for (int j = 2; i * j <= 55555; j++)isprime[i * j] = false;
		}
	}

	long A[100] = {};
	long aindex = 1;
	for (int i = 2; i <= 55555; i++) {
		if (isprime[i] == true && i % 10 == 1) { A[aindex] = i; aindex++; }
		if (aindex == 56) break;
	}


	for (int i = 1; i <= N; i++) cout << A[i] << " ";
	cout << endl;
}

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




 
public class Main 
{
	
	public static void main(String[] args) throws IOException 
	{ 
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		long k=s.nextLong();
		
		int ar[]=new int[n];
		for(int i=0;i<n;i++) {
			int u=s.nextInt();
			u--;
			ar[i]=u;
		}
		if(k<n) {
			int count=0;
			int next=0;
			while(count<k) {
				int val=ar[next];
				count++;
				next=val;
			}
			System.out.println(next+1);
		}else {
			// if the size is greater than k that means there is always cycle
			//so our task is to find the no of nodes in cycle so that we can mod with because we don't want to traverse again and again
			//but it is possible that some node are not included in cycle so we have to subtract those to k
			int pos=0;
			int next=0;
			int noofnode=-1;
			HashMap<Integer,Integer>hm=new HashMap<>();
			hm.put(next, pos);
			while(true ) {
				pos++;
				int val=ar[next];
				if(hm.containsKey(val)) { //if visit again that means cycle is exit
					noofnode=hm.get(val);
					break;
				}
				hm.put(val, pos);
				next=val;
			}
				k-=noofnode;
				int nodeincycle=hm.size()-noofnode;
				k%=nodeincycle;
				if(k==0)    //no of node in cycle
					k=nodeincycle;
				next=ar[next]; // start from the starting point of cycle
				int count=0;
				while(count<k) {
					int val=ar[next];
					count++;
					next=val;
				}
				System.out.println(next+1);
			
			
			
		}
	}

	
}




Measured memory_bytes: 66160
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdlib.h>

using namespace std;


int main() {
	int K;
	cin >> K;
	vector<long long> num = { 1,2,3,4,5,6,7,8,9 };
	while (num.size() < K) {
		long long x = num[0];
		num.erase(num.begin());
		K--;
		long long a = x % 10;
		if (a != 0) {
			num.push_back(10 * x + a - 1);
		}
		num.push_back(10 * x + a);
		if (a != 9) {
			num.push_back(10 * x + a + 1);
		}
	}
	cout << num[K - 1] << endl;
	return 0;
}


Measured memory_bytes: 988
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

	Scanner sc = new Scanner(System.in);

	void run() {

		int n = sc.nextInt();
		int k = sc.nextInt();


		System.out.println(solve(n,k));
	}
	
	long solve(long n, long k){
		
		if(k == 0){
			return n*n;
		}
		

		long sum = ((long) n - k) * ((long) n - k + 1);

		for( long i = k+1; i <=n;i++){
			long a = n%i;
			long b = n/i;
			
			sum -= b * k;
			if(a < k){
				sum += (k - 1 - a );
			}
		}
		return sum;
	}
}


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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

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

int main() {
    lli n;
    cin1(n);
    priority_queue<lli> que;
    lli a[n];
    ncin1(n, a);

    REP(i, 0, n) {
        que.push(a[i]);
    }
    lli max1 = que.top();
    que.pop();
    lli max2 = que.top();
    REP(i, 0, n) {
        if (a[i] == max1)
            cout << max2 << endl;
        else
            cout << max1 << endl;
    }
}


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

int main() {
  ll n=0;
  cin>>n;
  vector<ll> a(100009);
  rep(i,0,n){
    ll in=0;
    cin>>in;
    a.at(in)++;
  }
  int q=0;
  cin>>q;
  
  vector<pair<int,int>> shiji(q);
  
  rep(i,0,q){
    cin>>shiji.at(i).first>>shiji.at(i).second;
  }
  ll sum=0;
  
  rep(i,0,100009){
    sum+=(ll)a.at(i)*i;
  }
  
    rep(i,0,q){
      sum+=a.at(shiji.at(i).first)*shiji.at(i).second;
      sum-=a.at(shiji.at(i).first)*shiji.at(i).first;
      a.at(shiji.at(i).second)+=a.at(shiji.at(i).first);
      a.at(shiji.at(i).first)=0;
      
      cout<<sum<<endl;
  }
}

Measured memory_bytes: 4824
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
string S[int(2e5 + 5)];

int main(){
  scanf("%d", &N);
  for (int i = 0; i < N; i++) cin >> S[i];
  sort(S, S + N);

  int ans = 1;
  for (int i = 1; i < N; i++){
    if (S[i] != S[i - 1]) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9996
n = int(input())
H = list(map(int, input().split()))
DP = [0 for i in range(n)]

DP[0] = 0
DP[1] = abs(H[1] - H[0])
for i in range(2, n):
    a = DP[i - 2] + abs(H[i] - H[i - 2])
    b = DP[i - 1] + abs(H[i] - H[i - 1])
    if a <= b:
        DP[i] = a
    else:
        DP[i] = b
print(DP[n - 1])

Measured memory_bytes: 20600