akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n;

int main() {
    cin >> n;
    vector< vector<string> > ansvec(10, vector<string>());
    ansvec.at(0).emplace_back("a");
    if(n == 1) cout << "a" << endl;
    else {
        for(int i = 1; i < n; ++i) {
            int veclen = ansvec.at(i-1).size();
            for(int j = 0; j < veclen; ++j) {
                string check = ansvec.at(i-1).at(j);
                int chlen = check.length();
                int alp = 0;
                for(int k = 0; k < chlen; ++k) {
                    int cha = (int)(check.at(k));
                    chmax(alp, cha);
                }

                for(int k = 97; k <= alp+1; ++k) {
                    string ansc = check + (char)k;
                    ansvec.at(i).emplace_back(ansc);
                }
            }
        }

        for(int i = 0; i < (int)ansvec.at(n-1).size(); ++i) {
            cout << ansvec.at(n-1).at(i) << endl;
        }
    }
}

Measured memory_bytes: 11380
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}

vector<vector<int>> graph;
vector<int> bipartite;
int dfs(int v, int p, int b){
	bipartite[v] = b;
	for(int u: graph[v]){
		if(u==p) continue;
		if(bipartite[u]==b) return -1;
		if(bipartite[u]==1-b) continue;
		if(dfs(u, v, 1-b)<0) return -1;
	}
	return 0;
}

int main(){
	int N, M;
	cin >> N >> M;
	graph.assign(N, {});
	for(int i=0; i<M; i++){
		int a, b;
		cin >> a >> b;
		a--; b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	bipartite.assign(N, -1);
	if(dfs(0, -1, 0)<0){
		cout << (ll)N*(N-1)/2 - M << endl;
	} else {
		ll p = 0;
		for(int i=0; i<N; i++) p+=bipartite[i];
		cout << p*(N-p) - M << endl;
	}

	return 0;
}


Measured memory_bytes: 6656
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
   
    ll n;
    cin >> n;
    vector <ll> v,c;
    for (ll i=0;i<n;i++){
        ll tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    for (ll i=0;i<n;i++){
        ll tmp;
        cin >> tmp;
        c.push_back(tmp);
    }
    ll ans = 0;
    for (ll i=0;i<n;i++){
        if(v[i] > c[i]){
            ans += v[i] - c[i];
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n + 10), gl(n), gr(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(i == 0) {
            gl[i] = a[i];
        } else {
            gl[i] = __gcd(gl[i - 1], a[i]);
        }
    }
    for(int i = n - 1; i >= 0; i--) {
        if(i == n - 1) {
            gr[i] = a[i];
        } else {
            gr[i] = __gcd(gr[i + 1], a[i]);
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        if(i == 0) {
            chmax(ans, gr[i + 1]);
        } else if(i == n - 1) {
            chmax(ans, gl[i - 1]);
        } else {
            chmax(ans, __gcd(gl[i - 1], gr[i + 1]));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int n, a[300005];
LL psum[300005];

LL cmin;
bool dp[300005];

bool check(LL x)
{
	cmin = 0;
	rep1(i, n) if(i & 1) {
		dp[i] = psum[i] - x >= cmin;
		if(dp[i]) cmin = min(cmin, psum[i + 1]);
	}
	return dp[n];
}

int main()
{
	scanf("%d", &n);
	rep(i, n) scanf("%d", &a[i]);
	if(n % 2 == 0) {
		int ans0 = 0, ans1 = 0;
		rep(i, n) if(i & 1) ans1 += a[i];
		else ans0 += a[i];
		printf("%d %d\n", max(ans0, ans1), min(ans0, ans1));
		return 0;
	}
	
	psum[0] = 0;
	rep(i, n) psum[i + 1] = psum[i] + (i & 1 ? -a[i] : a[i]);
	LL ans0 = 0, ans1 = 0;
	rep(i, n) if(i & 1) ans0 += a[i];
	else ans1 += a[i];
	
	LL cl = 0, cr = 3e9;
	while(cl < cr) {
		LL mid = cl + cr + 1 >> 1;
		if(check(mid)) cl = mid;
		else cr = mid - 1;
	}
	ans0 += cr;
	ans1 -= cr;
	printf("%lld %lld\n", ans0, ans1);
	return 0;
}

Measured memory_bytes: 4096
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void run() {
		char[][] c = {{'\'',',','.','!','?'},
					  {'a','b','c','A','B','C'},
					  {'d','e','f','D','E','F'},
					  {'g','h','i','G','H','I'},
					  {'j','k','l','J','K','L'},
					  {'m','n','o','M','N','O'},
					  {'p','q','r','s','P','Q','R','S'},
					  {'t','u','v','T','U','V'},
					  {'w','x','y','z','W','X','Y','Z'}};
					  
		while (sc.hasNext()) {
			String s = sc.next();
			int len = s.length();
			int i = 0;
			StringBuilder sb = new StringBuilder();
			while (i < len) {
				int count = 0;
				while (i+count < len && s.charAt(i) == s.charAt(i+count)) count++;
				if (s.charAt(i) == '0') {
					for (int j = 0; j < count-1; j++)
						sb.append(' ');
				} else {
					int k = Integer.parseInt(""+s.charAt(i))-1;
					sb.append(c[k][(count-1)%c[k].length]);
				}
				i += count;
			}
			out.println(sb);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 16692
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long t = 1;
		long ans = 0;
		
		while (H >= t) {
			ans += t;
			t *= 2;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
from heapq import heappush, heappop
N = int(input())
AB = []

for i in range(N):
  a, b = map(int, input().split())
  heappush(AB, (b, a))


current = 0

for i in list(range(N)):
  deadline, cost = heappop(AB)

  if current + cost > deadline: # 締め切り時間を過ぎてしまっているとき
    print("No")
    exit()
  
  current += cost

print("Yes")

Measured memory_bytes: 36688
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
// clang-format off
/* }}} */

#include <bits/stdc++.h>
using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {
  REP(i, v.size()) print(v[i]);
}
template <typename T> inline void print(const vector<T>& v, string s = " ") {
  REP(i, v.size()) {
    if (i != 0) cout << s;
    cout << v[i];
  }
  cout << '\n';
}
// clang-format on
/* }}} */

signed main() {
  string s;
  cin >> s;
  int cnt = 1;
  char t = s[0];
  REPS(i, 1, s.size()) {
    if (s[i] != t) {
      cnt++;
      t = s[i];
    }
  }
  print(cnt - 1);

  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

/**
 * https://abc054.contest.atcoder.jp/tasks/abc054_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();	
		int[][] image = new int[N][N];
		int[][] template = new int[M][M];
		
		for(int y=0; y<N; y++){
			String line = sc.next();
			for(int x=0; x<N; x++)
				image[x][y] = line.charAt(x);
		}
		for(int y=0; y<M; y++){
			String line = sc.next();
			for(int x=0; x<M; x++)
				template[x][y] = line.charAt(x);
		}	
		sc.close();
		
		boolean match = false;
		for(int iy=0; iy< N-M+1 && !match ; iy++){
			for(int ix=0; ix<N-M+1 && !match ; ix++){
				match = true;
				for(int ty=0; ty<M; ty++){
					for(int tx=0; tx<M; tx++){
						if(image[ix+tx][iy+ty]!=template[tx][ty]){
							match = false;
							break;
						}
					}
					if(!match)
						break;
				}
			}
		}
		
		String ans = match ? "Yes":"No";
		System.out.println(ans);
		
	}

}


Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const string emp = "Vacant";
const string M = "Male";
const string F = "Female";

void out(int N, string &S) {
    cout << N << endl;
    fflush(stdout);
    cin >> S;
    return;
}

int main() {
    int N;
    cin >> N;
    int L = 0, R = N;
    string Sl, Sr;
    out(0, Sl);
    if (Sl == emp) return 0;
    
    while (abs(L-R) > 1) {
        int mid = (L + R) / 2;
        string Sm;
        out(mid, Sm);
        if (Sm == emp) return 0;
        if ((abs(mid-L) % 2 == 0 && Sl != Sm) || (abs(mid-L) % 2 == 1 && Sl == Sm)) {
            R = mid; Sr = Sm;
        } else {
            L = mid; Sl = Sm;
        }
    }
    
    return 0;
}

Measured memory_bytes: 852
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        final int a=scanner.nextInt();
        final int b=scanner.nextInt();
        final int c=scanner.nextInt();
        final int d=scanner.nextInt();
        if(Math.abs(a-c)<=d){
            System.out.println("Yes");
            return;
        }

        if(Math.abs(a-b)<=d&&Math.abs(c-b)<=d){
            System.out.println("Yes");
            return;
        }
        System.out.println("No");

    }

}

Measured memory_bytes: 21588
#include <stdio.h>
int main(void){
    int W,H,x,y,r,a=0,b=0;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    
    if(x-r>=0 && x+r<=W){
        a=1;
        
    }
    if(y-r>=0 && y+r<=H){
        b=1;
    }
    
    if(a==1 && b==1){
        printf("Yes\n");
        
    }
    else{
        printf("No\n");
        
    }
 
 
   
   return 0;
}

Measured memory_bytes: 1820
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 競プロ_Csharp {
    class Program {
        static void Main(string[] args) {

            int[] a = NextInts();

            int d = a[0] / a[1];
            int r = a[0] % a[1];
            double f = (double)a[0] / (double)a[1];

            Println(d + " " + r + " " + f.ToString("F5"));

        }

        public static void Println (Object o) {
            Console.WriteLine(o);
        }

        public static string NextString() {
            return Console.ReadLine();
        }

        public static int NextInt () {
            return int.Parse(Console.ReadLine());
        }

        public static int[] NextInts () {
            string[] a = Console.ReadLine().Split();
            int[] b = new int[a.Length];
            for (int i = 0; i < a.Length; i++) {
                b[i] = int.Parse(a[i]);
            }
            return b;
        }

    }
}



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

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

int main(void)
{
    string s,t;
    ll fuitti=0,saisyo=LONG_LONG_MAX;
    cin >> s;
    cin >> t;
    for(int i=0;i<=s.size()-t.size();i++)
    {
        fuitti=0;
        for(int j=0;j<t.size();j++)
        {
            if(s[i+j]!=t[j])
            {
                fuitti++;
            }
        }
        saisyo=min(saisyo,fuitti);
    }
    cout << saisyo << endl;
    return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define int  long long 
#define speedrap ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int be(int a,int b,int mod) {if(b == 0) return 1; if(b%2 == 1) return (a*be(a,b-1,mod))%mod; else return (be(a,b/2,mod)*be(a,b/2,mod))%mod;}
const int mod = 1e9+7;
#define PI 3.14159265359
#define pf push_front
#define pb push_back
#define bitcount __builtin_popcount
#define sc(a) scanf("%d", &a);
#define sz(s) (int)s.size()
#define eb emplace_back
#define pf push_front
#define mkp(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
const int siz = 2*(2500 + 1);
const int logi = 21;
const double epsilon = 1e-6;
int prime[siz];
bool cmp(const int &a,const int &b)
{
  return (abs(a-b)>1);
}

signed main()
{
	
	speedrap
	int t;
	t = 1;
	//cin>>t;
	while(t--)
	{
		int n,m;
		cin>>n>>m;
		int a[m];
		int sum = 0;

		for(int i = 0 ; i < m ; i++)
		{
			cin>>a[i];
			sum += a[i];
		}

		if(sum > n)
		{
			cout<<-1<<"\n";
		}
		else
		{
			cout<<n - sum<<"\n";
		}
	}
}


Measured memory_bytes: 3728
#include<stdio.h>
 
struct AA{
  char s;
  char v;
};
 
 
 
int main(){

  struct AA a1[100], a2[100],f;
  int n, i,j,m,x=0;
  char z;
 
  scanf("%d%c", &n, &z);

  for ( i = 0; i < n; i++ ){
    scanf("%c%c%c", &a1[i].s, &a1[i].v, &z);
  }
  for ( i = 0; i < n; i++ ){
    a2[i] = a1[i];
  }
  for(i = 0; i < n; i++){
    for(j = n-1; j >= i+1; j--){
      if(a1[j].v < a1[j-1].v){
    f = a1[j];      
    a1[j] = a1[j-1]; 
    a1[j-1] = f;
      }
    }
  }
   
  for(i = 0; i < n; i++){
    printf("%c%c",a1[i].s,a1[i].v);
    if(i< n-1){
      printf(" ");
    }
  } 
  printf("\n");
   
  printf("Stable\n");
   
  for(i = 0; i <= n-1; i++){
    m = i;
    for(j = i; j <= n-1; j++){
       
      if(a2[j].v < a2[m].v){
    m = j;
      }
    } 
     
    f = a2[i];      
    a2[i] = a2[m]; 
    a2[m] = f; 
  }
  for(i = 0; i < n; i++){
    if(a1[i].s != a2[i].s){
      x = 1;
    }
  }
   
  for(i = 0; i < n; i++){
    printf("%c%c",a2[i].s,a2[i].v);
    if(i<n-1){
      printf(" ");
    }
     
  }   
  printf("\n");
 
  if(x == 1){
    printf("Not stable\n");
  }
  else {
    printf("Stable\n");
  }
   
  return 0;
}

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

const int maxn = 1e5 + 10;
const ll inf = 1e18;
ll h[maxn];
ll DP[maxn];
int N , K;

ll dis(int i , int j){
    return abs(h[i] - h[j]);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> K;
    for(int i = 1; i <= N; ++i){
        cin >> h[i];
        DP[i] = inf;
    }
    DP[1] = 0;
    for(int i = 2; i <= N; ++i){
        for(int j = i - 1; j >= i - K && j >= 1; --j){
            DP[i] = min(DP[i] , DP[j] + dis(i , j));
        }
    }
    cout << DP[N] << endl;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std ;
int main()
{
    int n, num,digit,rev=0;
    cin>>num;
    n=num;
      while(num != 0)
        {
            digit=(num%10);
            rev=((rev*10)+digit);
            num=(num/10);
        }
    if(n==rev)
        cout <<"Yes";
    else
        cout <<"No";
    return 0;
}

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

using namespace std;
using ll = long long;
const int MAX = 3000+7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  vector<vector<int>> dp(MAX, vector<int>(MAX, 0));
  const int n = s.length();
  const int m = t.length();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i-1] == t[j-1]) {
        dp[i][j] = dp[i-1][j-1]  + 1;
      } else {
        dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
      }
    }
  }
  string ans;
  int i = n, j = m;
  while (i > 0 && j > 0) {
    if (dp[i][j] == dp[i-1][j]) {
      i--;
    }else if (dp[i][j] == dp[i][j-1]) {
      j--;
    }else {
      ans = s[i-1] + ans;
      i--, j--;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 39188
#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;

int main() {

  long long int n;
  cin >> n;

  vector< long long int > x, y;

  for ( long long int i = 0; i < n; i++ ) {

    long long int in;
    cin >> in;
    x.push_back( in );

  }

  for ( long long int i = 0; i < n; i++ ) {

    long long int in;
    cin >> in;
    y.push_back( in );

  }

  long double d[4] = {};

  for ( long long int i = 0; i < n; i++ ) {

    long long int k = x[i] - y[i];
    if ( k < 0 ) k = -k;
    d[0] += k;
    d[1] += k * k;
    d[2] += k * k * k;
    d[3] = max( d[3], 1.00L * k );

  }

  cout << fixed << setprecision(10) << d[0] << endl << pow( d[1], 1.0 / 2 ) << endl << pow( d[2], 1.0 / 3 ) << endl << d[3] << endl;;

  return 0;

}

Measured memory_bytes: 1336
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}
#define int ll
ll dp[300000];
void solve(){
	int n, t;
	cin >> n >> t;
	vector<int> inputs;
	REP(i, n) {
		int a;
		cin >> a;
		inputs.push_back(a);
	}
	sort(ALL(inputs));
	dp[1] = 1;
	for (int i = 1; i < inputs.size(); ++i) {
		auto x = lower_bound(ALL(inputs), inputs[i] - t);
		int y = x - inputs.begin();
		y = i - y;
		y++;
		dp[i + 1] = dp[i] * y;
		dp[i + 1] %= MAX_MOD;
	}
	cout << dp[n] << endl;
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 4620
#include<bits/stdc++.h>
using namespace std;
int  main()
{
  long   long int X;
    cin>>X;
   long long int a;
    a=100;
    int time=0;
    while(a<X)
    {
          a=a+a/100;
          time=time+1;
    }
    cout<<time<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <map>

using namespace std;

int64_t gcd(int64_t a, int64_t b){
	return (b > 0)? gcd(b, a % b) : a ;
}

map< int64_t, int > prime_factor(int64_t n) {
    map< int64_t, int > ret;
    for(int64_t i = 2; i * i <= n; i++) {
        while(n % i == 0) {
        ret[i]++;
        n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}


int main(void) {
    int64_t A, B;
    cin >> A >> B;
    cout << prime_factor(gcd(A, B)).size() + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long
long long n;
string a[100005];
long long ans=0;

signed main()

{
	cin>>n;
	a[n+1]="19260817";
	for (int i=1;i<=n;i++){
		cin>>a[i];
		sort(a[i].begin(),a[i].end());
		//for (int j=0;j<10;j++){
		//	hash1[i]=hash1[i]+(a[i][j]-'a'+1)*27;
		//}
	}

	sort(a+1,a+1+n);
	int cnt=1;

	for (int i=1;i<=n;i++){
		if (a[i]==a[i+1])
			cnt++;
		else{
			ans+=(cnt-1)*cnt/2;
			cnt=1;
		}
	}

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

Measured memory_bytes: 7296
import math

n=int(input())

a=list(map(int,input().split()))

L=[0]

for i in range(n):
  L.append(math.gcd(L[i],a[i]))

R=[0]
for i in range(n):
  R.append(math.gcd(R[i],a[n-1-i]))

ans=1
for i in range(n):
  ans=max(ans,math.gcd(L[i],R[n-1-i]))

print(ans)


Measured memory_bytes: 20856
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 1e6 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

ll a[MAXN], b[MAXN], c[MAXN], dp[MAXN][3];

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    for(int i = 1; i <= n; i++){
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0], dp[i- 1][1]) + c[i];
    }
    cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
    return 0;
}




Measured memory_bytes: 10496
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    print(S.count('1'))


if __name__ == '__main__':
    main()


Measured memory_bytes: 8896
require 'scanf'

s = gets.split.map(&:to_s)
ans = {};
s.each do |word|
  ans[word] = 0 if(ans[word].nil?)
  ans[word] += 1;
end
puts (ans.max_by{|_, v| v})[0] + " " + (s.max_by{|v| v.size})

Measured memory_bytes: 8904
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define popb(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
  int k,s,cnt=0;
  cin>>k>>s;
  rep(i,0,k+1){
    rep(j,0,k+1){
      if(k>=s-(i+j)&&s-(i+j)>=0){
        cnt++;
      }
    }
  }
  cout<<cnt<<endl;
}


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

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

int main(void) {
    int n, k, x[100], ans = 0;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cin >> k;
    REP(i, n) {
        cin >> x[i];
    }
    REP(i, n) {
        ans += min(x[i], k - x[i]);
    }

    cout << ans + ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, z, n) for(int64_t i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
//const int INF = 1 << 29;
//const int64_t MOD = 1000000007;
//const int64_t INF = 998244353;
using namespace std;
typedef pair<int64_t, int64_t> P;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> H(N);
    rep(i, 0, N) cin >> H.at(i);
    sort(all(H));
    int64_t ans = 0;
    rep(i, 0, N - K){
        ans += H.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long

LL mod = 998244353;
LL dp[3005][3005];
int n, s, a[3005];

int main() {
  //auto start_clock = clock();
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  scanf("%d%d", &n, &s);
  for(int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  LL ans = 0;
  for(int i = 1; i <= n; i++) {
    int x = a[i - 1];
    for(int j = x + 1; j <= s; j++) {
      dp[i][j] += dp[i - 1][j - x];
      dp[i][j] %= mod;
    }
    dp[i][x] += i;
    dp[i][x] %= mod;

    ans += dp[i][s] * (n - i + 1);
    ans %= mod;

    for(int j = 0; j <= s; j++) {
      dp[i][j] += dp[i - 1][j];
      dp[i][j] %= mod;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), dp(n + 1);
  for(int i = 0; i < m; i++) {
    cin >> a.at(i);
    if(i)
      if(a.at(i - 1) + 1 == a.at(i))
        dp.at(0) = 1;
  }
  if(dp.at(0))
    cout << 0 << endl;
  else if(m) {
    if(a.at(0) == 1)
      dp.at(2) = 1;
    else if(a.at(0) == 2)
      dp.at(1) = 1;
    else {
      dp.at(1) = 1;
      dp.at(2) = 2;
    }
    for(int i = 3; i <= n; i++)
      if(find(a.begin(), a.end(), i) == a.end())
        dp.at(i) = (dp.at(i - 1) + dp.at(i - 2)) % MOD;
    cout << dp.at(n) << endl;
  } else if(n != 1) {
    dp.at(1) = 1;
    dp.at(2) = 2;
    for(int i = 3; i <= n; i++)
      dp.at(i) = (dp.at(i - 1) + dp.at(i - 2)) % MOD;
    cout << dp.at(n) << endl;
  } else
    cout << 1 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;

int findSum(int num)
{
	int dS = 0;
	while(num)
	{
		dS+=(num%10);
		num/=10;
	}
	return dS;
}
void solve()
{
	int n, a, b;
	cin>>n>>a>>b;
	int sum = 0;
	for(int i=1; i<=n; i++)
	{
		if(findSum(i)>=a && findSum(i)<=b)
		{
			sum+=i;
		}
	}	
	cout<<sum<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3652
h,w = map(int,input().split())
C = [list(input()) for i in range(h)]

queue = []
visited = [] 
ans = 0

visited = [[0 for i in range(w)] for i in range(h)]

for i in range(h):
    for j in range(w):
        if C[i][j] == '.':
            queue.append([i,j])
            visited[i][j] = 1

            dy_dx = [[1,0],[0,1],[-1,0],[0,-1]]

            while len(queue) > 0:
                now = queue.pop(0)
                for k in range(4):
                    y = now[0]+dy_dx[k][0]
                    x = now[1]+dy_dx[k][1]
                    if 0 <= y < h and 0 <= x < w:
                        if C[y][x] != '#' and visited[y][x] == 0:
                            visited[y][x] = visited[now[0]][now[1]]+1
                            queue.append([y,x])
                    
        for l in range(h):
            for m in range(w):
                ans = max(ans,visited[l][m])
            
        queue = []
        visited = [[0 for i in range(w)] for i in range(h)]
                        
        
print(ans-1)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	ll n,k,res=0;
	cin>>n>>k;
	if(k==0)res=n*n;
	else
	{
		for(ll b=k;b<=n;b++)
		{
			//a<b
			res+=b-k;
			//b<a
			res+=(n-b)/b*(b-k)+max(0LL,n%b-k+1);
		}
	}
	cout<<res<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

int gcd(int a, int b) {
    int v0 = a, v1 = b, v2 = a % b;
    while (v2 != 0) {
        v0 = v1;
        v1 = v2;
        v2 = v0 % v1;
    };
    return v1;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N),L(N),R(N),M(N);
    for (int i=0; i<N; i++) {
        cin >> A[i];
    }
    
    
    L[0]=A[0];
    for (int i=1; i<N; i++) {
        L[i]=gcd(L[i-1], A[i]);
    }
    
    R[N-1]=A[N-1];
    for (int i=1; i<N; i++) {
        R[N-1-i]=gcd(R[N-i], A[N-1-i]);
    }
    
    M[0]=R[1];
    M[N-1]=L[N-2];
    for (int i=1; i<N-1; i++) {
        M[i]=gcd(L[i-1], R[i+1]);
    }
    
    int max=0;
    for (int i=0; i<N; i++) {
        if (max<M[i]) {
            max=M[i];
        }
    }
    cout << max << endl;
}


Measured memory_bytes: 1792
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static public final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static public final int getPair1(long v) {return (int)(v >> 32);}
	static public final int getPari2(long v) {return (int)(v & 0xFFFFFFFF);}

	static public final long quad(long a, long b, long c, long d) {
		return ((a&0xFFFF)<< 48) + ((b&0xFFFF)<< 32) + ((c&0xFFFF)<< 16) +(d&0xFFFF);}
	static public final int getQuad1(long v) {return (int)( v >> 48          );}
	static public final int getQuad2(long v) {return (int)((v >> 32) & 0xFFFF);}
	static public final int getQuad3(long v) {return (int)((v >> 16) & 0xFFFF);}
	static public final int getQuad4(long v) {return (int)( v        & 0xFFFF);}

	static public final long record(int e, int m, int i) {
		return quad(-1, e, m, i);
	}
	static public final int re(long record) {
		return getQuad2(record);
	}
	static public final int rm(long record) {
		return getQuad3(record);
	}
	static public final int ri(long record) {
		return getQuad4(record);
	}

	//------------------------------------------

	private int p;
	private int[] inv;
	private int[] fact;
	private int[] finv;
	public final int mod(long v) {
		v %= p;
		return (int)(v < 0 ? v+p : v);
	}
	public final int mul(long a, long b) {
		return mod(a*b);
	}
	public final void initFact(double limit, double p) {
		initFact((int)limit, (int)p);
	}
	public final void initFact(int limit, int p) {
		this.p = p;
		this.inv = new int[limit+1];
		this.fact = new int[limit+1];
		this.finv = new int[limit+1];
		fact[1] = finv[1] = inv[0] = inv[1] = 1;
		for(int i=2;i<=limit;i++) {
			int a = p / i;
			int b = p % i;
			inv[i]  = mul(-a, inv[b]);
			fact[i] = mul(fact[i-1], i);
			finv[i] = mul(finv[i-1], inv[i]);
		}
	}
	public final int comb(int m, int n) {
		return mul(mul(fact[m], finv[n]), finv[m-n]);
	}
	//------------------------------------------
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}

	//------------------------------------------



	public void exec() throws Exception{
		final int N = sc.nextInt();
		final int M = sc.nextInt();
		final boolean[] end = new boolean[N+1];
		final int[] wa_t = new int[N+1];
		int ac = 0;
		int wa = 0;

		for(int i=0;i<M;i++) {
			int p = sc.nextInt();
			String S = sc.next();
			if(S.equals("AC")) {
				if(!end[p]) {
					ac++;
					wa+=wa_t[p];
					end[p]=true;
				}
			}else if(S.equals("WA")) {
				if(!end[p]) {
					wa_t[p]++;
				}
			}else {
				throw new RuntimeException();
			}
		}
		out.println(ac+" "+wa);

	}
}


Measured memory_bytes: 63652
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const ll LINF = 1LL << 50;
/* global variables */
/* function */
/* main */
int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<ll> > v(N, vector<ll>(3));
    for (int i = 0; i < N; i++) for (int j = 0; j < 3; j++) cin >> v[i][j];

    ll ans = -LINF;
    for (int b = 0; b < 8; b++) {
        vector<ll> sum(N);
        for (int i = 0; i < N; i++) {
            ll tmp = 0;
            for (int j = 0; j < 3; j++) {
                if (b & (1 << j)) tmp += v[i][j];
                else tmp -= v[i][j];
            }
            sum[i] = tmp;
        }
        sort(sum.begin(), sum.end(), greater<ll>());
        ans = max(ans, accumulate(sum.begin(), sum.begin() + M, 0LL));
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */


/** Problem2019 : Princess's Marriage **/
int main()
{
	int N, M;
	while (cin>>N>>M, N) {
		vector<P> a(N);
		int sum=0;
		rep(i, N) {
			cin>>a[i].second>>a[i].first;
			sum+=a[i].first*a[i].second;
		}
		
		sort(a.begin(), a.end(), greater<P>());
		
		rep(i, N) {
			if (a[i].second<=M) {
				M-=a[i].second;
				sum -= a[i].first*a[i].second;
			} else {
				sum -= a[i].first*M;
				M=0;
			}
			if (M==0) break;
		}
		
		cout << sum << endl;
	}
}

Measured memory_bytes: 1272
if __name__ == "__main__":
    a = list()
    for i in range(3):
        a.append(list(map(int, input().split())))
    n = int(input())
    for i in range(n):
        tmp = int(input())
        for j in range(3):
            for k in range(3):
                if tmp == a[j][k]:
                    a[j][k] = 0

    # 横の判定
    for i in range(3):
        if a[i][0] == 0 and a[i][1] == 0 and a[i][2] == 0:
            print('Yes')
            exit()

    # 縦の判定
    for i in range(3):
        if a[0][i] == 0 and a[1][i] == 0 and a[2][i] == 0:
            print('Yes')
            exit()

    # 斜めの判定
    if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
        print('Yes')
        exit()
    if a[2][0] == 0 and a[1][1] == 0 and a[0][2] == 0:
        print('Yes')
        exit()

    print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define int long long
using namespace std;

typedef pair<int, int> Pii;

void readint(int N, vector<int> &a);
void readdouble(int N, vector<double> &a);
void readindex(int N, vector<int> &a);



signed main(){

    string s1, s2, s3;
    cin >> s1;
    cin >> s2;
    cin >> s3;

    cout << s1[0] << s2[1] << s3[2];

    return 0;
}








void readint(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readdouble(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}
void readindex(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str()) - 1;
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str()) - 1;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <vector>

using namespace std;
using namespace chrono;

#ifdef DEBUG
	//~ #define LOCAL_INPUT_FILE
#else
	//#define USE_FILE_IO
#endif

#ifdef USE_FILE_IO
	#define INPUT_FILE "input.txt"
	#define OUTPUT_FILE "output.txt"
	#define cin ____cin
	#define cout ____cout
	ifstream cin(INPUT_FILE);
	ofstream cout(OUTPUT_FILE);
#else
	#ifdef LOCAL_INPUT_FILE
		#define cin ____cin
		ifstream cin("input.txt");
	#endif
#endif

const int infinity = (int)1e9 + 42;
const int64_t llInfinity = (int64_t)1e18 + 256;
const int module = (int)1e9 + 7; 
const long double eps = 1e-8;

mt19937_64 randGen(system_clock().now().time_since_epoch().count());

inline void raiseError(string errorCode) {
	cerr << "Error : " << errorCode << endl;
	exit(42);
}

signed main() {
	#ifndef USE_FILE_IO
		ios_base::sync_with_stdio(false);
	#endif
	int n; int64_t k; cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	vector<int> next((int)4e5, n);
	for (int i = 0; i < n; ++i) {
		next[a[i]] = min(next[a[i]], i);
	}
	vector< pair<int, int> > jmp(n);
	for (int i = n-1; i >= 0; --i) {
		jmp[i] = {next[a[i]], next[a[i]] <= i};
		next[a[i]] = i;
	}
	int v = 0, cnt = 0;
	vector<int> res;
	res.push_back(0);
	do {
		res.back() = v;
		int to = jmp[v].first;
		if (jmp[v].second) {
			++cnt;
			res.push_back(to+1);
		}
		v = to+1;
		if (v >= n) {
			++cnt;
			break;
		}
	} while (v != 0);
	--k;
	k %= cnt;
	vector<int> qq(begin(a) + res[k], end(a));
	{
		vector<int> cnt((int)4e5);
		vector<int> s;
		for (int x : qq) {
			if (!cnt[x]) {
				++cnt[x];
				s.push_back(x);
			} else {
				while (cnt[x]) {
					assert(!s.empty());
					--cnt[s.back()];
					s.pop_back();
				}
			}
		}
		for (int i : s) {
			cout << i << " ";
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 9460
// https://atcoder.jp/contests/abc140/tasks/abc140_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, sum = 0;
    cin >> n;
    vector<int> a(n), b(n), c(n - 1);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];
    REP(i, n - 1) cin >> c[i];
    sum = accumulate(ALL(b), 0);
    REP(i, n - 1) {
        if (a[i] + 1 == a[i + 1]) {
            int t = a[i] - 1;
            sum += c[t];
        }
    }
    cout << sum << endl;

    return 0;
}


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

int main()
{
int i;
string S;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> S;

	sort( &S[ 0 ], &S[ 3 ] );
	if( S == "abc" )
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    int cnt = 0;
    for(int i=max(A, B); i>=1; i--){
        if(A%i==0 && B%i==0){
            cnt++;
            if(cnt == K){
                cout << i << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

int main(){
    using namespace std;
    int a, b, x; cin >> a >> b >> x;
    double ang;

    if(a*a*b < 2*x) ang = atan(pow(a,3)/ (2.*(a*a*b-x)));
    else ang = atan(2.*x/(a*b*b));

    cout << std::setprecision(10) << 90. - (ang * 360. / 2. / M_PI) << endl; 

}


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

int main(){
	int n;
	unordered_set<int> s;
	cin >> n;
	for(int i = 0; i<n; i++){
		int tmp;
		cin >> tmp;
		s.insert(tmp);
	}
	if(s.size() % 2) {
		cout << s.size();
	} else {
		cout << s.size() - 1;
	}
	return 0;
}

Measured memory_bytes: 4388
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

const int maxn = 1E5 + 10;

int n,m,tp,stk[maxn];
bool vis[maxn];

vector <int> v[maxn];

void Dfs(int x)
{
    for (int i = 0; i < v[x].size(); i++)
    {
        int to = v[x][i];
        if (vis[to]) continue;
        vis[to] = 1; stk[++tp] = to;
        Dfs(to); return;
    }
}

int main()
{
    #ifdef DMC
        freopen("DMC.txt","r",stdin);
    #endif

    cin >> n >> m;
    while (m--)
    {
        int x,y; scanf("%d%d",&x,&y);
        v[x].push_back(y); v[y].push_back(x);
    }
    stk[tp = 1] = 1; vis[1] = 1; Dfs(1);
    reverse(stk + 1,stk + tp + 1); Dfs(1); cout << tp << endl;
    for (int i = 1; i < tp; i++) printf("%d ",stk[i]); cout << stk[tp] << endl;
    return 0;
}


Measured memory_bytes: 6784
#include<stdio.h>
#include<string.h>
int panduan(int i)
{
	int a[5], b[5];
	a[0] = i % 10;
	i = i / 10;
	a[1] = i % 10;
	i = i / 10;
	i = i / 10;
	b[0] = i % 10;
	i = i / 10;
	b[1] = i % 10;
	//printf("%d %d %d %d\n", a[0], a[1], b[0], b[1]);
	if(a[0]==b[1]&&a[1]==b[0])
	return 1;
	return 0;
}
int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	int i,sum=0;
	for (i = a; i <= b; i++)
		if (panduan(i))
			sum++;
	printf("%d", sum);
	//getchar(); getchar();
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args){

        Scanner scan = new Scanner( System.in );

        int N = Integer.parseInt( scan.next() );
        int K = Integer.parseInt( scan.next() );

        int[] p = new int[N];

        for (int i=0; i< p.length; i++){
            p[i] = Integer.parseInt( scan.next() );
        }
        Arrays.sort(p);

        int sum = 0;
        for(int i=0; i<K; i++){
            sum += p[i];
        }
        System.out.println(sum);

    }
}

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

int main(){
  char s[10];
  
  cin >> s;
  
  if(s[0] == 'S'){
    printf("Cloudy\n");
  } else if(s[0] == 'C'){
    printf("Rainy\n");
  } else {
    printf("Sunny\n");
  }
  
  
  return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int a,b,c; cin>>a>>b>>c;
	cout<<min({a,b,c})*((a+b+c)-min({a,b,c})-max({a,b,c}))/2<<"\n"s;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 3005;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
ll dp[maxn][maxn][2];
ll a[maxn];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(int i=n;i>=1;i--)
    {
        for(int j=i;j<=n;j++)
        {
            if(i==j)
            {
                dp[i][j][0]=a[i];
                dp[i][j][1]=-a[i];
            }
            else
            {
                dp[i][j][0]=max(dp[i+1][j][1]+a[i],dp[i][j-1][1]+a[j]);
                dp[i][j][1]=min(dp[i+1][j][0]-a[i],dp[i][j-1][0]-a[j]);
            }
        }
    }
    printf("%lld\n",dp[1][n][0]);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}



Measured memory_bytes: 139648
function myOut(text){console.log(text);}//standard output
function Main(input) {
	input = input.trim();
	//input = input.trim().split(" ");
	//input = input.trim().split("\n");
	input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  
  var R = input[0];
  var G = input[1];
  var B = input[2];
  var N = input[3];
  var list = [R,G,B];
  var max = Math.max.apply(null,list);
  list.splice(list.indexOf(max), 1);
  var first = Math.floor(N / max);
  var next = Math.max.apply(null,list);
  var last = Math.min.apply(null,list);
  
  var output = 0;
  for(var i = 0; i <= first; i++){
    var tmp = N - (i * max);//残り10
    var tmp2 = Math.floor(tmp / next);
    if(i == 227){
       //console.log(tmp);
       }
    for(j = 0; j <= tmp2; j++){
      var tmp3 = tmp - (j * next);
      if(tmp3 % last == 0){
         output++
         }
    }
    
  }
  console.log(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372