akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[100005], sum[100005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 0; i <= n; i++) cin >> a[i];
	for(int i = n; i > 0; i--) sum[i] = sum[i+1] + a[i];
	
	llint cnt = 1, ans = 0;
	for(int i = 0; i <= n; i++){
		ans += cnt;
		if(cnt < a[i]){
			cout << -1 << endl;
			return 0;
		}
		cnt -= a[i];
		cnt = min(cnt*2, sum[i+1]);
		//cout << cnt << endl;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 5204
#include <iostream>
#include <string>
#include <algorithm> 
using namespace std;


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

	string name = "";
	while (N)
	{
		--N;
		name += (char)('a' + (N % 26));
		N /= 26;
	}

	reverse(name.begin(), name.end());
	cout << name << endl;
}


Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        boolean latitude0, longitude0;
        //if one day he go north and another day go south, he can make plan to end with the latitude where he started
        //if he don't go north or south any day,  the terminal will have the same latitude
        if((line.contains("N")&&line.contains("S")) || (!line.contains("N")&&!line.contains("S"))) latitude0=true;
        else latitude0 = false;
        if((line.contains("E")&&line.contains("W")) || (!line.contains("E")&&!line.contains("W"))) longitude0=true;
        else longitude0 = false;
        
        if(latitude0&&longitude0)System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 8020
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int col[114514];
vector<int> nex[114514],dis[114514];
void dfs( int pos, int prv ){
	for(int i=0;i<nex[pos].size();i++){
		if( nex[pos][i] != prv ){
			col[ nex[pos][i] ] = ( dis[pos][i] + col[pos] ) % 2;
			dfs( nex[pos][i], pos );
		}
	}
	return ;
}
signed main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b,c;
		cin>>a>>b>>c;
		nex[a].pb(b); dis[a].pb(c);
		nex[b].pb(a); dis[b].pb(c);
	}
	dfs(1,-1);
	for(int i=1;i<=n;i++){
		cout<<col[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 15488
#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include<vector>
#include<iomanip>
#include<math.h>
#include<deque>
#include<set>
typedef long long ll;
ll inf = 1e10;
using namespace std;
ll dp[10000000] = {};
ll a[100005];
ll ans[100005] = {};
pair<int, int>v[100005];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll count = 1;
	ll ans = 0;
	sort(a, a + n);
	
	for (int i = 0; i < n-1; i++) {
		if (a[i] == a[i + 1]) {
			count++;
		}
		else {
			if (count % 2 != 0) {
				ans++;
			}
			count = 1;
		}
	}
	if (count % 2 != 0) {
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

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

const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

int main(){
    int r; cin >> r;
    if (r < 1200){
        cout << "ABC" << endl;
    }else if (r < 2800){
        cout << "ARC" << endl;
    }else{
        cout << "AGC" << endl;
    }
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = [list(map(int, input().split())) for _ in range(N)]
    ans = 0
    for i in range(N):
        A[i][i] = float('INF')
    for i in range(N):
        for j in range(i):
            if i == j:
                A[i][j] = float('INF')
                continue
            b = min(map(sum, zip(A[i], A[j])))
            if A[i][j] > b:
                print(-1)
                return
            if b > A[i][j]:
                ans += A[i][j]
    print(ans)


main()


Measured memory_bytes: 6644
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
#define mo 1000000007
#define ull unsigned long long 
int main(){ 
  int h,a;cin>>h>>a;
  int ans=0,d=0;
  while(d<h)
  {
    d+=a;
    ans++;
  }
  cout<<ans;
}
    

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = list(input())
LR = [list(map(int, input().split())) for _ in range(Q)]

AC = 0
flagA = 0
cumAC = []

for n in range(N):
    if flagA==1 and S[n]=='C':
        flagA = 0
        AC += 1
    elif S[n] == 'A':
        flagA = 1
    else:
        flagA = 0
    cumAC.append(AC)
    
for i in range(Q):
    print(cumAC[LR[i][1]-1] - cumAC[LR[i][0]-1])

Measured memory_bytes: 31372
import java.util.*;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        System.out.println(N / 3);
    }










    public static Integer min(List<Integer> ar){
        int min = 10000;
        int index = 0;
        for(int i = 0; i< ar.size();i++){
            if(min > ar.get(i)){
                min = ar.get(i);
                index = i;
            }
        }
        return min;
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int a[100005],ans1,ans2;
int b[100005];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int x;
		string s;
		cin>>x>>s;
		if(s=="WA"){
			a[x]+=!b[x];
		}else{
			ans1+=!b[x];
			b[x]=1;
		}
	}
	for(int i=1;i<=n;i++){
		if(b[i]) ans2+=a[i];
	}
	cout<<ans1<<" "<<ans2<<endl;
	return 0;
}

Measured memory_bytes: 1024
#! usr/bin/env python
# -*- coding: utf-8 -*-

from collections import deque
import heapq
import bisect
import math


def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    if sum(a) < sum(b):
        print(-1)
        exit()

    need = cnt = 0
    ex = []
    for i in range(n):
        if a[i] < b[i]:
            need += b[i] - a[i]
            cnt += 1
        elif a[i] > b[i]:
            ex.append(a[i]-b[i])

    ex.sort(reverse=True)

    if cnt == 0:
        print(0)
        exit()

    cur = 0
    for i in range(len(ex)):
        cur += ex[i]
        if cur >= need:
            print(cnt+i+1)
            exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 81072
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

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

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

    int Odd = n%2;

    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    sort(all(a)); sort(all(b));

    int min, max, ans;
    if (Odd) {
        min = a[(n-1)/2];
        max = b[(n-1)/2];
    } else {
        min = (a[n/2-1]+a[n/2]);
        max = (b[n/2-1]+b[n/2]);
    }
    ans = max - min + 1;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4844
N = int(input())
S = input()
ans = 0

for i in range(10):
    ind_i = S.find(str(i))
    if ind_i != -1:
        S2 = S[ind_i + 1:]
        for j in range(10):
            ind_j = S2.find(str(j))
            if ind_j != -1:
                S3 = S2[ind_j + 1:]
                for k in range(10):
                    cnt_k = S3.count(str(k))
                    if cnt_k > 0:
                        ans += 1


print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define forr(i,a,n) for (int i = (a); i < (n); ++i)
#define rforr(i,a,n) for (int i = (a); i > (n); --i)
#define ALL(x) x.begin(),x.end()
#define LEN(X) ((int)(X).size())
#define CASET int _T; cin >> _T; forr(caset,0,_T)
//#define int long long



int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    ll n; cin >> n;
    ll ans = n*(n+1)/2;
    ll f = n/5;
    ll t = n/3;
    ll ft = n/15;
    ans += -5*f*(f+1)/2 -3*t*(t+1)/2 + 15*ft*(ft+1)/2;
    cout << ans << '\n';

    return 0;       
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    rep(i, n) scanf("%d", &a[i]);
    a.insert(a.begin(), 0);
    a.insert(a.end(), 0);

    int cost = 0;
    rep(i, n + 1) {
        cost += abs(a[i] - a[i + 1]);
    }

    for(int i = 1; i < n + 1; i++) {
        int ans = 0;
        ans = cost + abs(a[i + 1] - a[i - 1]) - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]);
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 4076
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int n;
  string s;
  cin>>n>>s;
  vector<int> w(n);
  vector<int> b(n);
  w[0]=!(s[0]=='.');
  b[0]=!(s[0]=='#');
  repeat(i,1,n) {
      w[i]=w[i-1]+!(s[i]=='.');
      b[i]=!(s[i]=='#')+min(w[i-1],b[i-1]);
  }
  cout << min(w[n-1],b[n-1]) << endl;
  return 0;
}


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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int n, m;
    cin >> n >> m;

    int ans = 1;
    for (int i = 1; i * i <= m; i++) {
        if (m % i == 0) {
            if (m / i >= n)
                ans = max(ans, i);
            if (i >= n)
                ans = max(ans, m / i);
        }
    }
    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

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

my_list = []
for i in range(N):
    if i == 0:
        my_list.append("a")
        continue
    new_list = []
    while my_list:
        s = my_list.pop(0)
        for j in range(ord("a"), ord(max(s)) + 2):
            new_list.append(s + chr(j))
    my_list += new_list
my_list.sort()

[print(s) for s in my_list]


Measured memory_bytes: 14512
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))
a.sort(key=lambda x: abs(x))
print(abs(a[-1]-a[0]))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int mod = 1e9+7;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(2e5);

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1), used(n + 1, -1);
  int r = 0, l = 0;
  rep(i,n + 1) {
    cin >> a[i];
    if (used[a[i]] != -1) {
      r = n - i;
      l = used[a[i]];
    }
    used[a[i]] = i;
  }

  for (int k = 1; k <= n + 1; k++) {
    cout << comb(n + 1, k) - comb(l + r, k - 1) << endl; 
  }
  return 0; 
} 

Measured memory_bytes: 5120
#include<iostream>
#include<cstdio>
#include<vector>
#include<set>
using namespace std;
const int N=100005;
int n;
int a[N];
int deg[N];
set<int>S;
set<pair<int,int> >e;
bool book[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),deg[a[i]]++;
	if(n==2) return printf("-1"),0;
	for(int i=1;i<=n;i++)
		S.insert(i),e.insert(make_pair(-deg[i],i));
	int pre=0;
	vector<int>ans;
	for(int i=1;i<=n-3;i++)
	{
		int u;
		if(-(e.begin()->first)==n-i) u=e.begin()->second;
		else if(*S.begin()!=pre) u=*S.begin();
		else if(S.size()>=2) u=*(++S.begin());
		else return printf("-1"),0;
		S.erase(u);
		e.erase(make_pair(-deg[u],u));
		book[u]=true;
		if(!book[a[u]])
		{
			e.erase(make_pair(-deg[a[u]],a[u]));
			deg[a[u]]--;
			e.insert(make_pair(-deg[a[u]],a[u]));
		}
		pre=a[u];
		ans.push_back(u);
	}
	vector<int>d;
	for(int u:S)
		d.push_back(u);
	bool flag=false;
	for(int i=0;i<d.size();i++)
		for(int j=i+1;j<d.size();j++)
			if(a[d[i]]==d[j]&&a[d[j]]==d[i]&&!flag)
			{
				flag=true;
				int k;
				for(k=0;k<d.size();k++)
					if(k!=i&&k!=j) break;
				if(pre!=d[i]&&a[d[i]]!=d[k]&&a[d[k]]!=d[j]) ans.push_back(d[i]);
				else if(pre!=d[j]&&a[d[j]]!=d[k]&&a[d[k]]!=d[i]) ans.push_back(d[j]);
				else return printf("-1"),0;
				ans.push_back(d[k]);
				if(pre!=d[i]&&a[d[i]]!=d[k]&&a[d[k]]!=d[j]) ans.push_back(d[j]);
				else if(pre!=d[j]&&a[d[j]]!=d[k]&&a[d[k]]!=d[i]) ans.push_back(d[i]);
				else return printf("-1"),0;
				break;
			}
	if(!flag)
	{
		for(int i=n-2;i<=n;i++)
		{
			int u;
			if(-(e.begin()->first)==n-i) u=e.begin()->second;
			else if(*S.begin()!=pre) u=*S.begin();
			else if(S.size()>=2) u=*(++S.begin());
			else return printf("-1"),0;
			S.erase(u);
			e.erase(make_pair(-deg[u],u));
			book[u]=true;
			if(!book[a[u]])
			{
				e.erase(make_pair(-deg[a[u]],a[u]));
				deg[a[u]]--;
				e.insert(make_pair(-deg[a[u]],a[u]));
			}
			pre=a[u];
			ans.push_back(u);
		}
	}
	for(int u:ans)
		printf("%d ",u);
	return 0;
}

Measured memory_bytes: 14104
#pragma GCC optimize ("O3")
    #include<bits/stdc++.h>
    using namespace std;



    /// Info.
    ///****************************************************************************************************************************************///
    /// author                : BAHAA El_DEEN OSAMA .
    /// Problem name          : Knapsack 1
    /// Method                : IM
    /// Online judge          : VC
    /// Date                  : 20/7/2020
    ///****************************************************************************************************************************************///


    #define ll               long long
    #define RE0              return 0
    #define loop(x)          while(x--)
    #define repRot0(i,n)     for(int i=0;i*i<=n;++i)
    #define all(v)           ((v.begin()),((v.end())
    #define mm(v,d)          memset(v,d,sizeof(v))
    #define MP               make_pair
    #define SZ(v)            ((int) ( (v).size() ) )
    #define ull              unsigned long long
    #define pi               3.1415926536
    #define oo               1e9
    #define OO               1e18
    #define Fx(n)            fixed<<setprecision(n)
    #define FasterIO           std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
    #define RE1              return 1
    #define mp(a,b)          make_pair(a,b)
    #define X                first
    #define Y                second
    #define pii              pair(int a, int b)
    #define rep(i,x,xx)        for(int i=x;i<xx;i++)
    #define RE               return
    #define LD               long double
    ///#define all(v) ((v).begin()),((v).end())
    #define revLoop(i,x)     for(int i=x-1 ;i>=0;--i)

    const  int   N  = (int) 1e6;
  /*const  int   M  = (int) 1e4+4;
    const  int  INF = (int) 0x3f3f3f3f;
    const double ESP = 1e-7;
    const ll MOD=4*1e4;
  */


 ll n,ans,w;
ll dp[110][N],a[110],b[110];
ll solve( ll i, ll r )
{
	if(r<0) return INT_MIN;
	if(i==n || r==0 ) return 0;
	if(dp[i][r]!=-1) return dp[i][r];

	dp[i][r] = max( solve(i+1,r) , solve(i+1,r-a[i])+b[i] );

	return dp[i][r];
}
    int Solve0()
    {

	cin >> n >> w ;
	for(int i=0 ; i<n ; i++)
		cin >> a[i] >> b[i];

	memset(dp,-1,sizeof(dp));

	cout << solve(0,w);

     RE0;
    }





    int main()
    {
    Solve0();
    RE0;
    }


Measured memory_bytes: 862980
def judge(x):
    if x < 1:
        print('No')
    else:
        print('Yes')

n,k,q = map(int,input().split())
#human_list = [k]*n
ok_list = [0]*n
for i in range(q):
    a = int(input())
    #human_list = list(map(lambda x: x-1,human_list))
    ok_list[a-1] += 1
    #print(human_list)
ok_list = list(map(lambda x: x+k-q,ok_list))
for i in range(n):
    judge(ok_list[i])


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

int main() {
  int N;
  cin >> N;
  
  int sum = 0;

  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
      
    sum += r - l + 1;
  }
  
    cout << sum << endl;
}



Measured memory_bytes: 256
// BEGINNING WITH NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
// ATCODER BEGINNERS PROBLEMS 
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.flush();
  	string a,b,c;
    cin >> a >> b >> c;
  	if(a[a.size()-1]==b[0] && b[b.size()-1] == c[0])
      cout<<"YES";
  	else
      cout<<"NO";
	return 0;
	// Bye Bye 2019
}

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

using namespace std;

int main(){ int N; cin >> N; vector<int> A(N);
           for(int i = 0;i < N; i++){cin >> A[i];}
           sort(A.begin(),A.end()); reverse(A.begin(),A.end());
           int Alice = 0; int Bob = 0;
for(int i = 0; i < N; i += 2){
  Alice += A[i];}
           for(int j = 1; j < N; j += 2){
             Bob += A[j];}
           
           cout << Alice - Bob << endl;
           
           return 0;}
   
             

Measured memory_bytes: 256
def resolve():
    K, N = list(map(int, input().split()))
    A = list(map(int, input().split()))
    maxdiff = 0
    idx = None
    for i in range(N):
        if i == N-1:
            diff = (K+A[0]) - A[i]
        else:
            diff = A[i+1] - A[i]
        if maxdiff < diff:
            idx = i
            maxdiff = max(maxdiff, diff)
    print(K - maxdiff)

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 100792
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  boost::for_each(vc, [&os, &vc](T value) {
    os << value;
    if (value != vc.back())
      os << ' ';
    });
  return os;
}

template<class T1, class T2>
inline
std::ostream&
operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  ui  N{}; std::cin >> N;
  ull K{}; std::cin >> K;

  typedef std::vector<ui> Vector;
  Vector A(N);
  std::map<ui, Vector> idx;
  rep(0, N)
  {
    std::cin >> A[i];
    idx[A[i]].push_back(i); // 出現位置
  }

  ui LOG_K = (ui)log2(K);
  ui LOG_N = (ui)log2(N);
  assert(LOG_K + LOG_N < 58); // 制約チェック

  typedef std::vector<ull> Vector_ull;
  std::vector<Vector_ull> dp(LOG_K + LOG_N + 1, Vector_ull(N));
  for (auto p : idx)
  {
    ui sz = p.second.size();
    p.second.push_back(p.second[0] + N);
    rep(0, sz)
    {
      dp[0][p.second[i]] = p.second[i + 1] - p.second[i] + 1; // 移動距離
    }
  }

  rep(1, dp.size())
  {
    rep_uj(0, N)
    {
      dp[i][j] = std::min(
        std::numeric_limits<ull>::max() / 3,
        dp[i - 1][j] + dp[i - 1][(dp[i - 1][j] + j) % N]);
    }
  }

  ull it{ 0 };
  ull it_max = K * N - 1;
  for(ui i = dp.size() - 1;;)
  {
    if (it + dp[i][it % N] <= it_max)
    {
      it += dp[i][it % N];
    }
    if(!i--)
      break;
  }
  assert(it <= it_max);

  Vector ans;
  ans.reserve(N);

  it %= N;
  std::set<ui> dic;
  while(it < N)
  {
    if (dic.count(A[it]))
    {
      while (true)
      {
        ui last = ans.back();
        ans.pop_back();
        dic.erase(last);
        if (last == A[it])
          break;
      }
    }
    else
    {
      ans.push_back(A[it]);
      dic.insert(A[it]);
    }
    ++it;
  }

  std::cout << ans << "\n";

  return;
}

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

  solve();

  return 0;
}


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

int main()
{
    ll x, a;
    cin >> x >> a;
    if (x < a)
        cout << 0 << endl;
    else
        cout << 10 << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#pragma warning (disable: 4996)
using namespace std;

int H, W, cnt;
int dp[9][9];
char c[9][9];

int main() {
	cin >> H >> W;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cin >> c[i][j];
			if (c[i][j] == '#') cnt++;
		}
	}
	if (cnt != H + W - 1) {
		cout << "Impossible" << endl;
		return 0;
	}

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (i >= 2) dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			if (j >= 2) dp[i][j] = max(dp[i][j], dp[i][j - 1]);
			if (c[i][j] == '#') dp[i][j] += 1;
		}
	}
	
	if (dp[H][W] == cnt) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>

using namespace std;

int main(){
    int n;
    string ws;
    cin >> n;
    cin >> ws;
    string es = ws;
    reverse(ws.begin(), ws.end());
    int en[n];
    int wn[n];
    for(int i = 0; i < n; i++){
        if(i == 0){
            en[i] = 0;
            wn[i] = 0;
        }else{
            if(es[i - 1] == 'W'){
                en[i] = en[i - 1] + 1;
            }else{
                en[i] = en[i - 1];
            }
            if(ws[i - 1] == 'E'){
                wn[i] = wn[i - 1] + 1;
            }else{
                wn[i] = wn[i - 1];
            }
        }
    }
    vector<int> ans;
    for(int i = 0; i < n; i++){
        ans.push_back(en[i] + wn[n - 1 - i]);
    }
    
    cout << *min_element(ans.begin(), ans.end());
}


Measured memory_bytes: 5500
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

int main() {
    int k,n,ans=0;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    ans = max(k-a[n-1]+a[0],ans);
    rep(i,n-1){
        ans = max(ans,a[i+1]-a[i]);
    }
    cout << k-ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int findsum(int n){
int sum=0;
  while(n>0){
  sum=sum+n%10;
   n=n/10;
  }
	return sum;
}
int main(){
int N,A,B;
  cin>>N>>A>>B;
  int total=0;
  for(int i=1;i<=N;i++){
  	int sum=findsum(i);
    if(sum >=A && sum<= B){
    	total = total +i;
    }
  }
  cout<<total<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, k, r, s, p;
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  ll ans = 0;
  vb v(n, false);
  rep(i, n) {
    if(i >= k && t[i - k] == t[i] && v[i - k]) {
      if(i < 2 * k || (t[i - 2 * k] != t[i - k]) || !v[i - 2 * k]) continue;
    }
    if(t[i] == 'r')
      ans += p;
    else if(t[i] == 's')
      ans += r;
    else
      ans += s;
    v[i] = true;
  }
  cout << ans << endl;
}

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

int main(){
  int A[3][3];
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
        cin >> A[i][j];
    }
  }
  bool B[3][3];
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
        B[i][j]=false;
    }
  }
  int N;
  cin >> N;
  for(int i=0; i<N; i++){
    int b; cin >> b;
    for(int j=0; j<3; j++){
      for(int k=0; k<3; k++){
        if(A[j][k]==b) B[j][k]=true;
      }
    }
  }
  for(int i=0; i<3; i++){
    if(B[i][0] && B[i][1] && B[i][2]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  for(int i=0; i<3; i++){
    if(B[0][i] && B[1][i] && B[2][i]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  if(B[0][0]&&B[1][1] &&B[2][2]){
    cout << "Yes" << endl;
    return 0;
  }
  if(B[0][2]&&B[1][1] &&B[2][0]){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby

if $0 == __FILE__
  gets
  strs = gets.chomp.split('')

  stack = 0
  ans = ''

  strs.each do |s|
    case s
    when '('
      stack += 1
    when ')'
      if stack > 0
        stack -= 1
      else
        ans += '('
      end
    end
  end

  ans += strs.join('') + ')'*stack

  puts ans
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define inf 1000000000 //1E+9
#define mod 1000000007
using namespace std;

int main(){
	string s, t; cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='A')t+='T';
		if(s[i]=='T')t+='A';
		if(s[i]=='G')t+='C';
		if(s[i]=='C')t+='G';
	}
	cout<<t<<endl;

    return 0;
}



Measured memory_bytes: 256
/*2281*/
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
using namespace std;

void swap(char& a,char& b){
	char t=a;
	a=b;
	b=t;
}

int main(void){
	int n;
	while(cin>>n,n){
		char s[10000];
		int c[1000],d[1000];
		int a,b;
		scanf("%s",s);
		for(int i=0;i<n;i++){
			cin>>a>>b;
			a--;b--;
			c[i]=a;d[i]=b;
		}
		for(int i=n-1;i>=0;i--){
			s[c[i]]=(s[c[i]]-'a'+(d[i]-c[i]))%26+'a';
			s[d[i]]=(s[d[i]]-'a'+(d[i]-c[i]))%26+'a';
			swap(s[d[i]],s[c[i]]);
		}
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;

int main()
{
    long long H, W, temp;
    cin >> H >> W;
    temp = 0;

    if (H == 1 || W == 1)
    {
        cout << 1;
    }
    else
    {
        if (H % 2 == 1 && W % 2 == 1)
        {
            temp = 1;
        }
        cout << (H * W) / 2 + temp;
    }
}

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

int main(){
  int N,Y;
  cin >>N>>Y;
  int maxM=Y/N+1;
  int i,j,k;
  for(int i=0;i<maxM+1;i++){
    for (int j=0;j<N+1-i;j++){
      k=N-i-j;
        if(Y==i*10000+j*5000+k*1000){
          cout<<i<<" "<<j<<" "<<k<<endl;
          return 0;
      }
    }
  }
  cout<<-1<<" "<<-1<<" "<<-1<<endl;
  return 0;
}

  

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int A = in.Int();
            int V = in.Int();
            int B = in.Int();
            int W = in.Int();
            int T = in.Int();

            long l = Math.abs(B - A);
            long d = V - W;

            String ans = "YES";
            if (d <= 0 || l > d * T) {
                ans = "NO";
            }
            out.println(ans);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

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

    }
}



Measured memory_bytes: 32816
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())


S=input()
last=S[0]
res = 'Good'
for c in S[1:]:
    if c == last:
        res = 'Bad'
    last = c

print(res)

Measured memory_bytes: 3064
N = int(input())

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

print(str((num2alpha(N))).lower())

Measured memory_bytes: 9116
x, y = list(map(int, input().split()))
bola = 0
bola1 = 0
quick = 1

l1 = input().split()

for c in range(x):
    bola1 = int(l1[c])

    bola += bola1

    if bola <= y:
        quick += 1

print(quick)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(a,n) rep(i,0,n){ cout<<(i ? " ":"")<<a[i]; }cout<<endl;
#define pprint(a,m,n) rep(j,0,m){ print(a[j],n); }
const int mod = 1e9+7;
const int size=1e5;
const int INF=1e9;
int main(){
	int N,C;cin>>N>>C;
	int s,t;int c;
    vector<pair<int,int>> count[C];
    map<int,int> calc;
	rep(i,0,N){
		cin>>s>>t>>c;
		count[c-1].push_back({s,t});
	}
	rep(i,0,C){
        if(count[i].empty()) continue;
		sort(count[i].begin(),count[i].end());
        int a,b;
        calc[count[i][0].first-1]++;
		rep(j,0,count[i].size()-1){
            a=count[i][j].second;
            b=count[i][j+1].first;
			if(b-a>1){
              calc[a]--;
              calc[b-1]++;
            }
		}calc[count[i].back().second]--;
	}
    int sum=0;int ans=0;
    for(pair<int,int> p:calc){
      sum+=p.second;
      //cout<<p.first<<p.second<<endl;
      ans=max(ans,sum);
    }
	cout<<ans<<endl;
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;


int power(int a,int b){
    int r=1;
    while(b){
        if(b & 1){
            r=r*a;
            b--;
        }
        a=a*a;
        b>>=1;
    }
    return r;
}


int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>k;

	vi v;

	rf(i,32,1){
        int l=1;
        int r=10;
        while(r-l>1){
            int mid=(l+r)/2;
            int x=power(i,mid);
            if(x>k) r=mid;
            else{
                v.pb(x);
                l=mid;
            }
        }
	}

	auto z=max_element(v.bb,v.ee);

	cout<<*z<<endl;
}



Measured memory_bytes: 3644
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <limits>
#include <math.h>
#include <string>
#include <map>

using namespace std;
typedef long long unsigned int ll;

int main() {
  vector<ll> abc(3);
  cin >> abc[0] >> abc[1] >> abc[2];
  for (int i = 0; i < 3; ++i) {
    if (abc[i] % 2 == 0) {
      puts("0");
      return 0;
    }
  }
  int max_idx = max_element(abc.begin(), abc.end()) - abc.begin();
  ll ans = 1;
  for (int j = 0; j < 3; ++j) {
    if (j != max_idx) ans *= abc[j];
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    string S;
    cin>>S;
    int ans = 0, tmp = 0;
    for(int i=0;i<S.size();++i){
        if(S[i]=='A' | S[i]=='G' | S[i]=='C' | S[i]=='T')tmp++;
        else {
            if(ans < tmp)ans = tmp;
            tmp = 0;
        }
    }
    if(ans<tmp)ans = tmp;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)
#define MAX 10000000
#define MOD 1000000007
 
 
vector<long> fac(MAX);
vector<long> finv(MAX);
vector<long> inv(MAX);
 
//template functions
/////////////////////////
void Cominit(){
  fac.at(0)=fac.at(1)=1;
  finv.at(0)=finv.at(1)=1;
  inv.at(1)=1;
  for(long i=2;i<MAX;i++){
      fac.at(i)=(fac.at(i-1)*i)%MOD;
      inv.at(i)=MOD-inv.at(MOD%i)*(MOD/i)%MOD;
      finv.at(i)=finv.at(i-1)*inv.at(i)%MOD;
  }
}

long facComb(long N,long M){// nCm%
if(N<M) return 0;
if(N<0||M<0) return 0;
return fac.at(N)*(finv.at(M)*finv.at(N-M)%MOD)%MOD;
}

long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}

long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}

long GCM(long A,long B){
            long W,r;
    if(A<B){

        W=B;
        B=A;
        A=W;
    }
    while(A%B!=0){
        r=A%B;
        A=B;
        B=r;
    }
    return B;
}
long LCM(long A,long B){
    return (A*B)/GCM(A,B);
}

long upDiv(long a,long b){
  return (a+b-1)/b;
}

/////////////////////////


//Answer


int main() {

long N,X,T;
cin>>N>>X>>T;
long c=upDiv(N,X);
cout<<c*T<<endl;



}



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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    char ls[s.size()];
    for (int i=0;i<s.size();i++) ls[i]=s[i];
    for (int i=0;i<s.size();i++){
        if(ls[i]=='?')
            ls[i]='D';
    }
    for (int i=0;i<s.size();i++)
        cout<<ls[i];
        cout<<"\n";
 	return 0;
}

Measured memory_bytes: 3980
# https://atcoder.jp/contests/agc024/tasks/agc024_b
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    # 入力
    n = input_int()
    dp = [0] * (n + 1)
    # 解法 -> 最長の連続部分列を求めればよい
    # {1,3,4,5,2,7,6} => {3,4,5}

    for _ in range(n):
        a = input_int()
        dp[a] = dp[a - 1] + 1

    ans = n - max(dp)
    print(ans)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 69152
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

template<int64_t MOD> struct Mint {
    int64_t v;
    Mint() { v = 0; }
    Mint(int64_t x) { v = x % MOD; if(v < 0)  v += MOD; }

    Mint operator-() { return Mint{-v}; };
    Mint operator+(Mint x) { return Mint(v + x.v); };
    Mint operator-(Mint x) { return Mint(v - x.v); };
    Mint operator*(Mint x) { return Mint(v * x.v); };
    Mint operator/(Mint x) { return Mint(v * pow(x.v, MOD-2).v); };

    Mint& operator+=(Mint x) { return *this = (*this + x); };
    Mint& operator-=(Mint x) { return *this = (*this - x); };
    Mint& operator*=(Mint x) { return *this = (*this * x); };
    Mint& operator/=(Mint x) { return *this = (*this / x); };

    static Mint pow(Mint base, int64_t exp) {
        if(exp == 0)  return Mint(1);
        return pow(base*base, exp/2) * (exp&1 ? base : Mint(1));
    }

    friend ostream& operator<<(ostream& os, Mint x) { return os << x.v; }
};
using mint = Mint<1000000007>;

template<class T> struct Counting {
    Counting(int64_t n) {
        _fact.assign(n+1, 1);
        for(int64_t i = 1; i <= n; i++)  _fact[i] = T(i) * _fact[i-1];
    }

    T fact(int64_t n) {
        assert(0 <= n && n < (int)_fact.size());
        return _fact[n];
    }

    T perm(int64_t n, int64_t k) {
        if(n < k)  return 0;
        return fact(n) / fact(n-k);
    }

    T comb(int64_t n, int64_t k) {
        if(n < k)  return 0;
        return fact(n) / (fact(k) * fact(n-k));
    }

    private:
        vector<T> _fact;
};

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

    vector<lint> x(n);
    for(auto& elem : x)  cin >> elem;

    vector<mint> d(n-1);
    for(lint i=0; i+1<n; i++)  d[i] = x[i+1] - x[i];

    vector<mint> c(n, 1);
    for(lint i=0; i+1<n; i++)  c[i+1] = c[i] + mint(1)/mint(i+2);

    mint ans = 0;
    for(lint i=0; i<n-1; i++)  ans += c[i] * d[i];

    Counting<mint> cnt(1e6);
    cout << ans * cnt.fact(n-1) << endl;
}

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

int N;
const int SIZE = 100005;
long long h [SIZE];
int mem [SIZE];
int k;

int dp (int i) {
  if (i == N-1) return 0;

  if (mem[i] != -1) return mem[i];

  long long ret = LLONG_MAX;

  for (int j=1 ; j<= k ; j++){
    if (i+j >= N) break; 
    ret =min (ret,  abs (h[i] - h[i+j])  + dp (i+j)); 
  }

  return  mem[i] = ret;
}

int main (){ 

  cin  >> N >> k;
  for (int i =0; i< N; i++) {
    cin >> h[i];
  }

  memset(mem, -1, sizeof mem);

  cout << dp(0);

}

Measured memory_bytes: 6144
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: i32,
        sc: [(usize1,i32); m]
    }
    let mut buf: Vec<i32> = vec![-1;n];
    for (s,c) in sc {
        if n >= 2 && s == 0 && c == 0 {
            println!("-1");
            return;
        }
        if buf[s] == -1 || buf[s] == c {
            buf[s] = c;
        } else {
            println!("-1");
            return;
        }
    }
    let buf = buf.into_iter().map(|v| {
        if v == -1 { 0 } else { v }
    });
    let mut b = true;
    let buf = buf.map(|v| {
        if v == 0 {
            if b {
                b = false;
                if n == 1 { 0 } else { 1 }
            } else { 0 }
        } else {
            b = false;
            v
        }
    });
    for v in buf {
        print!("{}", v);
    }
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		String x = scan.nextLine();
		String s = "Sunny";
		String c = "Cloudy";
		String r = "Rainy";
		if(x.equals(s)) {
			System.out.println("Cloudy");
		}
		else if(x.equals(c)) {
			System.out.println("Rainy");
		}
		else if(x.equals(r)) {
			System.out.println("Sunny");
		}
	}
}


Measured memory_bytes: 23124
x,n=map(int,input().split())
n=list(map(int,input().split()))
n.sort
if(x not in n):
    print(x)
    exit()
finder=n.index(x)
i=1
while(True):
    if(x-i not in n):
        print(x-i)
        exit()
    if(x+i not in n):
        print(x+i)
        exit()
    i=i+1



Measured memory_bytes: 9192
import math

a, b, C = map(float, raw_input().split())

sinC = math.sin(math.radians(C))
cosC = math.cos(math.radians(C))
c = math.sqrt( a*a + b*b - 2*a*b*cosC )

print ( a * b * sinC ) / 2  # Area
print a + b + c             # Periphery
print b * sinC              # Height

Measured memory_bytes: 6716
#include <bits/stdc++.h> 
#define pb push_back
#define mp make_pair 
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a,n) a, a + n
#define f(i, n) for (int i = 0; i < int(n); i++)
#define g(i, n) for (int i = 0; i < int(n-1); i++)
#define fj(j, n) for (int j = 0; j < int(n); j++)
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

// Driver function to sort the vector elements by 
// second element of pair in descending order 
bool sortbysecdesc(const pair<int,int> &a, 
                   const pair<int,int> &b) 
{ 
       return a.second>b.second; 
} 

// Driver function to sort the vector elements by  
// first element of pair in descending order 
bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
}

// Function to return gcd of a and b 
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

//Function to return lcm of a and b
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}

// Function to find gcd of array of 
// numbers 
int findGCD(ll a[], ll n) 
{ 
    int result = a[0]; 
    for (int i = 1; i < n; i++) 
    { 
        result = gcd(a[i], result); 
  
        if(result == 1) 
        { 
           return 1; 
        } 
    } 
    return result; 
}

int32_t main() {
    fio;

    ll a,b,c;
    cin>>a>>b>>c;
    if(b*c>=a)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;

    return 0 ;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++) 
#define ALL(n) begin(n),end(n)
int main()
{
    string a, b;
    cin >> a >> b;
    cout << ( ( a == "H" && b == "H" ) || ( a == "D" && b == "D" ) ? "H" : "D" ) << endl;
    return 0;
}

Measured memory_bytes: 256