akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, x, y;
    cin>>n>>x>>y;
    vector<int> ans(n,0);
    int t2 =0;
    for(int  i=1; i<n; i++){
        for(int j=i+1; j<n+1; j++){
            if(i<=x){
                if(j<y&&x<j)    ans.at(min( j-x,y-j+1)+x-i)++;
                else if(j<=x) ans.at(j-i)++;
                else if(j>=y) ans.at(1+x-i+j-y)++;
            }
            else if(i>x&&i<y){
                if(j<y) ans.at(min(j-i, y-x-(j-i)+1))++;
                else if(j>=y) ans.at(j-y +min( y-i, i-x+1 ))++;
            }
            else if(i>=y){
                ans.at(j-i)++;
            }
        }
    }
    for(int i=1; i<n; i++) cout<<ans.at(i)<<endl;
}

Measured memory_bytes: 384
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N, Q;

	public static void main(String[] args) {
		while (true) {
			N = sc.nextInt();
			if (N == 0) break;
			int S = sc.nextInt();
			int W = sc.nextInt();
			Q = sc.nextInt();
			int[] A = new int[N];
			int g = S;
			for (int i = 0; i < N; ++i) {
				A[i] = (g / 7) % 10;
				if (g % 2 == 0) {
					g = g / 2;
				} else {
					g = (g / 2) ^ W;
				}
			}
			System.out.println(solve(A));
		}
	}

	static long solve(int[] A) {
		long ans = 0;
		if (Q == 2 || Q == 5) {
			int nonzero = 0;
			for (int i = 0; i < N; ++i) {
				if (A[i] != 0) ++nonzero;
				if (A[i] % Q == 0) {
					ans += nonzero;
				}
			}
			return ans;
		}
		HashMap<Long, Integer> map = new HashMap<Long, Integer>();
		long sum = 0;
		long base = 1;
		for (int i = 0; i < N; ++i) {
			sum += A[N - 1 - i] * base;
			sum %= Q;
			base *= 10;
			base %= Q;
			int c = map.containsKey(sum) ? map.get(sum) : 0;
			if (A[N - 1 - i] != 0) {
				ans += c;
				if (sum == 0) ans++;
			}
			if (c != 0) {
				map.put(sum, c + 1);
			} else {
				map.put(sum, 1);
			}
		}
		return ans;
	}

}

Measured memory_bytes: 94036
#include <iostream>
#include <algorithm>
#include <array>

using namespace std;

static void printArray(int A[], int N) {
  for (int i = 0; i < N; i++) {
    cout << (i != 0 ? " " : "") << A[i];
  }
  cout << endl; 
}

static void inputArray(int A[], int num) {
  for (int i = 0; i < num; i++) {
    scanf("%d", &A[i]);
  }
}

static int selectionSort(int A[], int N) {
  int minj, count = 0;
  for (int i = 0; i < N; i++) {
    minj = i;
    for (int j = i; j < N; j++) {
      if (A[j] < A[minj]) {
    	minj = j;
      }
    }
    if (A[i] != A[minj]) {
        swap(A[i], A[minj]);
        count++;
    }
  }
  return count;
}

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

  array<int, 100> A;
  inputArray(A.data(), N);

  int count = selectionSort(A.data(), N);

  printArray(A.data(), N);
  cout << count << endl;
  
  return 0;
}



Measured memory_bytes: 3172
package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scan(&n)

    ps := make([]float64, n)
    for i := range ps {
        var p float64
        fmt.Scan(&p)
        ps[i] = p
    }

    // dp[i][j] i枚なげてj枚表の確率
    dp := make([][]float64, n+1)
    for i := range dp {
        dp[i] = make([]float64, n+1)
    }

    dp[0][0] = 1

    for i := 1; i <= n; i++ {
        for j := range dp[i] {
            if j > 0 {
                dp[i][j] += dp[i-1][j-1] * ps[i-1]
            }
            dp[i][j] += dp[i-1][j] * (1 - ps[i-1])
        }
    }

    var sum float64
    for j := (n + 1) / 2; j <= n; j++ {
        sum += dp[n][j]
    }

    fmt.Println(sum)
}


Measured memory_bytes: 75392
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x1,y1,x2,y2,x3,y3,x4,y4,p,q;
  cin>>x1>>y1>>x2>>y2;
  p=x2-x1,q=y2-y1;
  x3=x2-q,y3=y2+p;
  x4=x3-p,y4=y3-q;
  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4;
  return 0;
}

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

#define INF (1001001001)

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

using namespace std;

int main()
{
	int N, M;

	while (scanf("%d", &N), N){
		int f[32][32] = {0};
		int cnt = 0;

		for (int i = 0; i < N; i++){
			int x, y;

			scanf("%d %d", &x, &y);

			f[y][x] = 1;
		}

		scanf("%d", &M);

		int nowx, nowy;
		nowx = nowy = 10;

		for (int i = 0; i < M; i++){
			char d;
			int x;

			scanf(" %c %d", &d, &x);

			while (x--){
				if (d == 'N'){
					nowy++;

					if (f[nowy][nowx] == 1){
						cnt++;
					}
				}
				if (d == 'S'){
					nowy--;

					if (f[nowy][nowx] == 1){
						cnt++;
					}
				}
				if (d == 'W'){
					nowx--;

					if (f[nowy][nowx] == 1){
						cnt++;
					}
				}
				if (d == 'E'){
					nowx++;

					if (f[nowy][nowx] == 1){
						cnt++;
					}
				}
				f[nowy][nowx] = 9;
			}
		}

		if (cnt == N){
			puts("Yes");
		}
		else {
			puts("No");
		}
	}

	return (0);
}

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

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

const long long int inf = 1 << 29 ;

int main(void) {
	int a,b,h,w;
	cin >> h >> w >> a >> b;

	rep1(i, h) { 
	  rep1(j,w) {
		//if(h >= 2 && w >= 2 && (a == 0 || b == 0)) {cout << "No" << endl; return 0;}

			if (h == 1) {
				if (j <= a) cout << 1;
				else cout << 0;
			}
			else if (w == 1) {
			  if (i <= b) cout << 1;
				else cout << 0;
			}
		  else if ((j <= a && i <= b) || (j > a && i > b)) cout << 1;
		  else  cout << 0;
	  }
	cout << endl;
	}

}

Measured memory_bytes: 1280
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
class Combination {
    int powmod(int a, int p) {
        int ans = 1;
        int mul = a;

        for (; p > 0; p >>= 1, mul = (mul * mul) % mod) {
            if ((p & 1) == 1) ans = (ans * mul) % mod;
        }

        return ans;
    }
public:
    int N;
    int mod;
    vector<int> fact;
    vector<int> revFact;

    Combination(int n, int m) : N(n), mod(m), fact(n+1), revFact(n+1) {
        fact[0] = 1;
        for (int i = 1; i <= N; i++) {
            fact[i] = fact[i-1] * i;
            fact[i] %= mod;
        }

        // Fermat's little theorem
        revFact[N] = powmod(fact[N], mod - 2);

        for (int i = N-1; i >= 0; i--) {
            revFact[i] = revFact[i+1] * (i+1);
            revFact[i] %= mod;
        }
    }

    int get(int a, int b) {
        if (a < 0 || b < 0) return 0;
        if (b > a) return 0;
        return (((fact[a] * revFact[b]) % mod) * revFact[a-b]) % mod;
    }
};

signed main() {
    int N, K;
    cin >> N >> K;
    Combination comb = Combination(100000, MOD);

    for (int i = 1; i <= K; i++) {
        cout << (comb.get(N-K+1, i) * comb.get(K-1, i-1)) % MOD << endl;
    }
    return 0;
}

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

#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PII pair<int, int>

int main()
{
    FAST_IO

    string s;

    cin >> s;

    if(s[2] == s[3] && s[4] == s[5])
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define pb push_back
#define si second
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  mod 1000000007
#define double long double
#define all(o) o.begin(),o.end()
using namespace std;
int power(int x, int y)
{
    int res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1; // y = y/2
        x = (x*x) % mod;
    }
    return res%mod;
}
int inv(int n)
{
    return power(n,mod-2)%mod;
}
int a[200005];
int32_t main(){
	fast
	int n,i,j,k;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	int ans=0;
	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++)
			for(k=j+1;k<n;k++)
				if(a[i]!=a[j] && a[j]!=a[k] && a[i]+a[j]>a[k])
					ans++;
	cout<<ans<<"\n";
}




Measured memory_bytes: 3652
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long n = scan.nextLong();
        long k = scan.nextLong();

        Pair[] p = new Pair[(int) n];
        for (int i = 0; i < n; i++) {
            p[i] = new Pair(scan.nextLong(), scan.nextLong());
        }
        Arrays.sort(p);
        long place = 0;
        for (int i = 0; i < n; i++) {
            place += p[i].times;
            if (place >= k) {
                System.out.println(p[i].num);
                break;
            }
        }
    }
}

class Pair implements Comparable<Pair> {
    long times, num;

    public Pair(long a, long b) {
        num = a;
        times = b;
    }
    @Override
    public int compareTo(Pair o) {
        return (int)(this.num - o.num);
    }
}

Measured memory_bytes: 88644
//  [amitdu6ey]
// g++ -std=c++11 -o2 -Wall filename.cpp -o filename
#include <bits/stdc++.h>
#define hell 1000000009
#define bug1(x) cout<<"$ "<<x<<" $"<<endl
#define bug2(x) cout<<"% "<<x<<" %"<<endl
#define bug3(x) cout<<"# "<<x<<" #"<<endl
#define ll long long
#define pb push_back
#define mp make_pair
#define tr(z) for(auto it=z.begin(); it!=z.end(); it++)
#define rloop(i,a,b) for(long long i=a; i>=b;i--)
#define loop(i,a,b) for(long long i=a; i<b; i++)
#define vbool vector< bool >
#define vvbool  vector< vector<bool> >
#define vchar vector<char>
#define vi vector<int>
#define vvi vector< vector<int> >
#define pll pair<long long, long long>
#define vll vector<long long>
#define vvl vector< vector<long long> >
#define ninf numeric_limits<long long>::min()
#define pinf numeric_limits<long long>::max()
#define comp(a,b) (abs(a-b)<1e-9) // to compare doubles
using namespace std;

void solve(){
    ll n;
    cin>>n;
    vll h(n);
    loop(i,0,n) cin>>h[i];
    vll dp(n);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    dp[2] = min(dp[1] + abs(h[2]-h[1]), abs(h[2]-h[0]));
    loop(i,2,n){
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }
    cout<<dp[n-1]<<endl;
    return;
}

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


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

const int coin[4] = { 10, 50, 100, 500 };


int ans;
int c[4];
int d[4];
int a[4];

int change(int m){
  int ret = 0;
  for(int i=3; i>=0; i--){
    int tmp = m / coin[i];
    if(tmp > 0 && d[i] > 0)
      return 100000;
    ret += tmp;
    m = m % coin[i];
  }
  return ret;
}

void solve(int i, int m, int cnt){
  //printf("solve(%d,%d,%d)\n",i,m,cnt);
  //REP(j,i) printf("d[%d]=%d ",j,d[j]); puts("");
  if(i == 4){
    if(m > 0) return;
    int ret = change(-m);
    int sum = cnt - ret;
    //printf("sum: %d\n",sum);
    if(ans < sum){
      ans = sum;
      REP(i,4)
        a[i] = d[i];
    }
    return;
  }

  if(i < 3){
    REP(j,c[i]+1){
      d[i] = j;
      solve(i+1, m - d[i] * coin[i], cnt + d[i]);
    }
  }else{
    if(m <= 0){
      d[i] = 0;
      solve(i+1, m, cnt);
    }else{
      d[i] = (m + 499) / 500;
      if(d[i] <= c[i])
        solve(i+1, m - d[i] * coin[i], cnt + d[i]);
    }
  }
  return;
}

int main(){
  int n;
  int cc = 0;
  while(n = getInt()){
    if(cc++ != 0) puts("");
    REP(i,4)
      c[i] = getInt();

    ans = -100;
    solve(0,n,0);

    REP(i,4) if(a[i] != 0)
      printf("%d %d\n",coin[i],a[i]);
  }
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9+1)
#define MAXX (int)1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (ll)(1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
//printf("myco\n");//for debug
/*--------------------------------------------*/
int main(){
    int n,l;cin>>n>>l;
    int eat=inf;
    int u;
    rep(i,n){
        int tmp=abs(l+i);
        if(eat>tmp){
            eat=tmp;
            u=i;
        }
    }
    int ans=0;
    //printf("u=%d\n",u);
    rep(i,n){
        if(i==u)continue;
        ans+=l+i;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
# import sys
# input = sys.stdin.readline
n = int(input())
A = [input() for i in range(n)]
B = []

for i in range(n):
    if "." in A[i]:
        ind = A[i].index(".")
        A[i] += "0" * (10-(len(A[i]) - ind))
        B.append(int(A[i][:ind] + A[i][ind+1:]))
    else:
        B.append(int(A[i] + "0" * 9))

# print(B)

l = 100
D = [[0] * l for i in range(l)]
E = []

for i in range(n):
    a2 = 0
    a5 = 0
    while B[i] % 2 == 0:
        a2 += 1
        B[i] //= 2
    while B[i] % 5 == 0:
        a5 += 1
        B[i] //= 5
    D[a2][a5] += 1
    E.append([a2,a5])

for i in range(l-2,-1,-1):
    D[l-1][i] += D[l-1][i+1]
for i in range(l-2,-1,-1):
    D[i][l-1] += D[i+1][l-1]

for i in range(l-2,-1,-1):
    for j in range(l-2,-1,-1):
        D[i][j] += D[i+1][j] + D[i][j+1] - D[i+1][j+1]

# print(D)

ans = 0
for i in range(n):
    b2 = max(0, 18-E[i][0])
    b5 = max(0, 18-E[i][1])
    ans += D[b2][b5]
    if E[i][0]>=b2 and E[i][1]>=b5:
        ans -= 1

print(ans//2)

Measured memory_bytes: 127084
#define DBG 0 //submit 0
#define ll long long
#if DBG
    #include <algorithm>
    #include <array>
    #include <ctime>
    #include <cstdlib>
    #include <string>
    #include <vector>
    #include <unordered_map>
    #include <iostream>
    #include <cmath>
    #include <queue>
    #include <numeric>
#else
    #include <bits/stdc++.h>
#endif
 
using namespace std;
 
 
int main(){
    int k,s,ans=0;

    cin >> k >> s;

    for(int x=0;x<=k;x++){
        for(int y=0;y<=k;y++){
            if(s-x-y >= 0 && s-x-y <= k){
                ans++;
            }
        }
    }

    //cout << (flag ? "Yes" : "No") << endl;
    cout << ans << endl;
    //printf("%.10f",ans_d);cout<<endl;
}


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

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

    int m = 1e9;
    int cnt = 0;
    for(int i=0; i<N; i++){
        if(m > A[i]) cnt++;
        m = min(m, A[i]);
    }
    cout << cnt << endl;
}   

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define mod 2019
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    string s;
    cin>>s;
    int n=s.size();
    map<int,int>rel;
    int pr=1;
    rel[0]++;
    int last=0;
    int cnt=0;
    for(int i=n-1; i>=0; i--)
    {
    	int num=s[i]-'0';
    	last=(pr*num%mod+last)%mod;
    	pr=pr*10%mod;
    	cnt+=rel[last];
    	rel[last]++;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define rrep1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct SegmentTree {
    int n;
    vector<int> dat;

    SegmentTree(int n_) {
        n = 1;
        while (n < n_) n *= 2;
        dat.resize(2*n-1);
    }

    // i文字目をjにする
    void update(int i, int j) {
        i += n - 1;
        dat[i] = 1 << j;
        while (i > 0) {
            i = (i - 1) / 2;
            dat[i] = dat[2 * i + 1] | dat[2 * i + 2];
        }
    }

    // [a, b)に含まれる文字の種類数を求める
    int query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return dat[k];
        int vl = query(a, b, 2*k+1, l, (l+r)/2);
        int vr = query(a, b, 2*k+2, (l+r)/2, r);
        return vl | vr;
    }
};

int main() {
    int n, q;
    string s;
    cin >> n >> s >> q;

    SegmentTree tree(n);
    rep(i, n) {
        tree.update(i, s[i]-'a');
    }

    rep(i, q) {
        int t; cin >> t;
        if (t == 1) {
            int iq; char cq;
            cin >> iq >> cq;
            tree.update(iq-1, cq-'a');
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            cout << __builtin_popcount(tree.query(l, r, 0, 0, tree.n)) << endl;
        }
    }
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int main() {
    string a, b;
    cin >> a >> b;
    string x = a + b;
    int y = stoi(x);
    bool p = false;
    for(int i = 0;i <= y;i++) {
        p = p || i*i == y;
    }
    if(p) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
mii mm;
void solve(){
    ll n,m,chooses,lim;
    cin>>n>>m>>chooses>>lim;
    vi v(n);
    rep(i,0,n-1) cin>>v[i];
    sort(all(v),greater<ll>());
    ll temp=v[lim-1];
    ll ans=0;
    rep(i,0,lim-1){
        mm[v[i]]++;
        ans++;
    }
    ll sum=temp;
    ll cc=1;
    rep(i,lim,n-1){
        // if(v[i]==temp) {mm[v[i]]++;ans++;continue;}
        if(mm[v[i]]) {cc++;sum+=v[i];mm[v[i]]++;ans++;continue;}
        mm[v[i]]++;
        ll rem=n-i;
        // ll fk=mm[temp];
        sum+=v[i];
        cc++;
        // cout<<fk<<
        if(rem>=chooses) {if(v[i]+m>=temp) ans++; else break;}
        else if(chooses-rem<lim) {if(v[i]+m>=temp) ans++; else break;}
        else{
            if(v[i]+m<temp) break;
            ll zz=(chooses-rem-lim+1)*m;
            if((cc-1)*(v[i]+m)-(sum-v[i])>=zz) ans++;
            else break;
        }
        // else if((temp+ceil(((chooses-rem-lim+1)*m))<=(v[i]+m)) ans++;
        // else break;
    }
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

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

typedef long long ll;

ll ans = 0;

void solve(int n, string s, string S){
  if(n < S.size()){
    solve(n+1, s + S[n], S);
    solve(n+1, s + "+" + S[n] , S);
  } else { 
    cerr << s << endl;
    
    // eval部分
    vector<ll> v; 
    string num = "";
    s = s + "+";
    for(int i = 0; i < s.size(); i++){
      if(s[i] != '+'){
        num = num + s[i];
      } else { 
        v.push_back(stoll(num));
        num = "";
      }
    }
    for(auto x: v){
      ans += x;
    }
  }
}

int main(){
  string S;
  cin >> S;
  string s = "";
  s += S[0];
  solve(1,s, S);
  cout << ans << endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, A, B; cin >> N >> A >> B;
    ll a_cnt = 0, b_cnt = 0, c_cnt = 0;
    rep(i, N){
        ll p; cin >> p;
        if (p <= A){
            a_cnt++;
        } else if (A + 1 <= p && p <= B){
            b_cnt++;
        } else {
            c_cnt++;
        }
    }
    cout << min(min(a_cnt, b_cnt), c_cnt) << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

using namespace std;
const long long MOD=998244353;

long long fac[300001],finv[300001],inv[300001];

void table() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<300001;i++){
        fac[i]= fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

long long comb(int n, int k){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
  table();
  long long N,A,B,K,ans=0; cin>>N>>A>>B>>K;
  for(long long a=0;a<=N;a++){
    if(a*A>K) break;
  	if((K-a*A)%B==0 && (K-a*A)/B<=N){
      long long b=(K-a*A)/B;
    	ans+=(comb(N,a)*comb(N,b))%MOD;
      ans%=MOD;
    }
  }
 printf("%lld",ans); 
}


Measured memory_bytes: 7296
# -*- coding: utf-8 -*-
# ALDS1_2_D

def insertionSort(A, g=1):
    cnt = 0
    for i in range(g, len(A)):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
    return A,cnt

def shellSort(A):
    n = len(A)
    cnt = 0
    m = 0
    G = []
    
    # 3m + 1 間隔でGを設定
    while 1:
        m = 3*m + 1
        if m > n:
            break
        G.insert(0, m)
        
    for i in G:
        A, c = insertionSort(A, i)
        cnt += c 
    return A,G,cnt

n = int(input())
A = []
for _ in range(n):
    A.append(int(input()))
sortedA, G, cnt = shellSort(A)

print(len(G))
print(" ".join(list(map(str, G))))
print(cnt)
for i in A:
    print(i)
    


Measured memory_bytes: 45524
#import bisect
def desc_bin(a, x, lo=0, hi=None):
    """Insert item x in list a, and keep it reverse-sorted assuming a
    is reverse-sorted.

    If x is already in a, insert it to the right of the rightmost x.

    Optional args lo (default 0) and hi (default len(a)) bound the
    slice of a to be searched.
    """
    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if x > a[mid]: hi = mid
        else: lo = mid+1
    return lo
N=int(input())
ans=[]
for _ in range(N):
    num=int(input())
    
    index=desc_bin(ans,num)
    if index==len(ans):
        ans.append(num)
    else:
        ans[index]=num
    #print(ans)
print(len(ans))

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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

vector<int> p;
vector<int> r;

void init(int n) {
  p.reserve(n);
  r.resize(n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 0;
  }
}

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

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

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;

  if (r[x] < r[y])
    p[x] = y;
  else {
    p[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  init(N + 1);
  vector<int> p(N);
  for (auto &x : p)
    cin >> x;

  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    unite(x, y);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (same(i + 1, p[i]))
      ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1408
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
long long int gcd(long long int a,long long int b){
    if(!b)return a;
    return gcd(b,a%b);
}
int main(){
    long long int N,M;
    cin>>N>>M;
    long long int now=1;
    for(int i=0;i<N;i++){
        long long int a;
        cin>>a;
        a/=2ll;
        if(i==0){
            now=a;
            //printf("[%lld][%lld]\n",now,a);
            continue;

        }
        long long int papapa=(a*now)/gcd(a,now);
        if(M<papapa){
            cout<<0<<endl;
            //printf("[%lld][%lld] [%lld]\n",now,a,papapa);
            return 0;
        }
        if((papapa/now)%2==0||(papapa/a)%2==0){
            cout<<0<<endl;
            //printf("[%lld][%lld] [%lld]\n",now,a,papapa);
            return 0;
        }
        //printf("[%lld][%lld] [%lld]\n",now,a,papapa);
        now=(a*now)/gcd(a,now);
    }
    cout<<M/now-(M/(now*2ll))<<endl;
    return 0;
}


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

typedef long long ll;

int main()
{
  ll k;
  cin >> k;
  
  if(k == 0) cout << 2 << endl << 0 << " " << 0 << endl;
  else if(k == 1) cout << 2 << endl << 2 << " " << 0 << endl;
  else if(k <= 50) {
    cout << k << endl;
    for(int i = 0; i < k; i++) {
      if(i != 0) cout << " ";
      cout << k;
    }
    cout << endl;
  } else {
    ll ans[55];
    int loop = 50 - k % 50;
    for(int i = 0; i < 50; i++) {
      ans[i] = (k + 49LL) / 50LL + 49;
    }
    if(loop != 50) {
      for(int i = 0; i < loop; i++) {
	ans[i] -= k % 50 + 1;
      }
    }
    cout << 50 << endl;
    for(int i = 0; i < 50; i++) {
      if(i != 0) cout << " ";
      cout << ans[i];
    }
    cout << endl;
  }
    
  return (0);
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 2000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
int main() {
	long long n, y;
	cin >> n >> y;
	y /= 1000;
	if (y < n) {
		cout << "-1 -1 -1" << endl;
		return 0;
	}
	y -= n;
	for (long long i = 0;i <= n;++i) {
		for (long long q = 0;q <= n - i;++q) {
			long long hoge = i * 9 + q * 4;
			if (hoge == y) {
				cout << i << " " << q << " " << n - i - q << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}

Measured memory_bytes: 888
#include <iostream>

int main() {
  const unsigned long long MOD = 1000000007;
  unsigned long long N, M;
  std::cin >> N >> M;
  if (N > M + 1 || M > N + 1) {
    std::cout << 0;
    return 0;
  }
  unsigned long long fact = 1;
  for (unsigned i = 2; i <= std::min(N, M); ++i) {
    fact *= i;
    fact %= MOD;
  }
  fact *= fact;
  fact %= MOD;
  if (N != M) {
    fact *= std::max(N, M);
    fact %= MOD;
  } else {
    fact *= 2;
    fact %= MOD;
  }
  std::cout << fact;
  return 0;
}


Measured memory_bytes: 888
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int main(){

	int N,E,limit,tmp,minimum;
	scanf("%d %d",&N,&E);

	limit = pow(2,N);

	int cost[N][N];

	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++)cost[i][k] = BIG_NUM;
	}

	int from,to,value;

	for(int i = 0; i < E; i++){
		scanf("%d %d %d",&from,&to,&value);
		cost[from][to] = value;
	}

	int** dp = new int*[N];
	bool* check = new bool[limit];
	for(int i = 0; i < N; i++){
		dp[i] = new int[limit];
		for(int k = 0; k < limit; k++){
			dp[i][k] = BIG_NUM;
		}
	}

	for(int i = 0; i < limit; i++)check[i] = false;

	minimum = BIG_NUM;

	tmp = pow(2,0);

	dp[0][tmp] = 0;

	check[tmp] = true;

	for(int state = 0; state <= limit-1; state++){
		if(!check[state])continue;
		for(int k = 0; k < N; k++){
			if(dp[k][state] == BIG_NUM)continue;
			for(int a = 0; a < N; a++){
				if(state & (1 << a)){
					if(state == limit-1 && a == 0){
						if(cost[k][0] != BIG_NUM)dp[0][limit-1] = min(dp[0][limit-1],dp[k][state]+cost[k][0]);
					}
				}else{
					if(cost[k][a] != BIG_NUM){
						tmp = state + pow(2,a);

						if(dp[a][tmp] > dp[k][state]+cost[k][a]){
							dp[a][tmp] = dp[k][state]+cost[k][a];
							check[tmp] = true;
						}
					}
				}
			}
		}
	}

	minimum = min(minimum,dp[0][limit-1]);


	if(minimum == BIG_NUM){
		printf("-1\n");
	}else{
		printf("%d\n",minimum);
	}

}

Measured memory_bytes: 4784
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		double[] x = new double[n];
		String[] u = new String[n];
		double sum = 0;

		for (int i = 0;i<n ;i++ ) {
			x[i] = sc.nextDouble();
			u[i] = sc.next();
		}

		for (int i = 0;i<n ;i++ ) {
			if (u[i].equals("JPY")) {
				sum+=x[i];
			}else{
				sum +=x[i]*380000;
			}
		}

		System.out.println(sum);
	}
}


Measured memory_bytes: 23124
#![allow(dead_code, unused_imports, deprecated)]
use std::cmp::{max, min, Reverse};
use std::collections::*;
use maplit::*;
use num::Integer;
use proconio::input;
use proconio::marker::*;
use proconio::fastout;

const INF : i64 = 1000000007;

#[fastout]
fn main() {
  input! {
    n : usize, k : usize,
  };
  input! {
    h : [i64; n],
  };

  let mut dp = vec![INF; n];
  dp[0] = 0;

  for i in 0..n {
    for j in 1..=k {
      if i >= j {
        dp[i] = min(dp[i], dp[i - j] + (h[i] - h[i - j]).abs());
      }
    }
  }
  
  println!("{}", dp[n - 1]);
}


Measured memory_bytes: 4108
n, x, y = map(int, input().split())

x -= 1
y -= 1

k = [0] * n

a = y - x
for i in range(n-1):
    for j in range(i+1, n):
        temp = j - i
        b = 1 + abs(x - i) + abs(y - j)
        k[min(temp, b)] += 1

for i in range(1, n):
    print(k[i])

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

void buy (long long& money, long long& stock, int price) {
    long long count = money / price;
    stock += count;
    money -= price * count;
}

void sell (long long& money, long long& stock, int price) {
    money += stock * price;
    stock = 0;
}

int main(void){
    int N;
    
    cin >> N;
    
    vector<long long> A(N);
    
    for (int i = 0;i < N;i++) {
        cin >> A[i];
    }

    
    long long money = 1000;
    long long stock = 0;
    
    int mode = 0;
    for (int i = 0;i < N-1;i++){
        if (mode == 0) {
            if (A[i] <= A[i+1]) {
                buy(money, stock, A[i]);
                mode = 1;
            }
        } else if (mode == 1) {
            if (A[i] >= A[i+1]) {
                sell(money, stock, A[i]);
                mode = 0;
            }
        }
    }
    
    sell(money, stock, A[N-1]);
    cout << money << endl;

    return 0;    
}


Measured memory_bytes: 3632
N = int(input())
S = [input() for _ in range(N)]

dic = {'AC':0,'WA':0,'TLE':0,'RE':0}
for s in S:
    if s in dic.keys():
        dic[s] += 1

for key,value in zip(dic.keys(),dic.values()):
    print(key+' x '+str(value))

Measured memory_bytes: 16268
#include <cstdio>
using namespace std;

int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
int n,a[1000010],b[1000010],l[200];
int main(){
    for(int i=1;i<200;i++)
        l[i-1]=(i*(i+1)*(i+2))/6;
    for(int i=1;i<=1000000;i++){
        a[i]=i;
        b[i]=i;
        for(int t=0;l[t]<=i;t++){
            a[i]=min(a[i],a[i-l[t]]+1);
            if(l[t]%2)
                b[i]=min(b[i],b[i-l[t]]+1);
        }
    }
    while(scanf("%d",&n),n){
	    printf("%d %d\n",a[n],b[n]);
    }
    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N, K;
	cin >> N >> K;
	vector<int64> A(N);
	REP(i, N) cin >> A[i];
	int64 cnt[50] = {};
	
	REP(i, N){
		REP(j, 50){
			if (A[i] >> j & 1) cnt[j]++;
		}
	}
	int64 res = 0;
	for(int64 i = 49;i >= 0;i--){
		if (res + (1LL << i) > K) continue;
		if (cnt[i]*2 < N) res += (1LL << i);
	}
	int64 sum = 0;
	REP(i, N){
		sum += res ^ A[i];
	}
	cout << sum << endl;
}


Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vecll>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
#define MM " "
#define INF INT_MAX
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}


    
void go();
int n;


int f(ll x,ll y){
    int ma=-1;
    rep(i,32){
        if((x%3)==1 and (y%3)==1)chmax(ma,(int)i);
        x/=3;y/=3;
    }
    if(ma==-1)return 0;
    ll res=1;
    rep(i,ma)res*=3;
    return res;
}
vec to_3(ll x){
    vec res;
    rep(i,32){
        res.pb(x%3);x/=3;
    }
    // reverse(all(res));
    return res;
}

main(){
    ios
    ll int h=lin(),w=lin();
    if(h==1)cout<<1<<endl;
    else if(w==1)cout<<1<<endl;
    else
    cout<<(h*w+1ll)/2ll<<endl;
}




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

const long long LL_INF = (long long) 2e18 + 5;

int N;
long long K;
vector<int> A, F;

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

    cin >> N >> K;
    A.resize(N);
    F.resize(N);

    for (auto &a : A)
        cin >> a;

    for (auto &f : F)
        cin >> f;

    sort(A.rbegin(), A.rend());
    sort(F.begin(), F.end());
    long long low = 0, high = LL_INF;

    auto &&possible = [&](long long maximum) {
        long long sum = 0;

        for (int i = 0; i < N; i++) {
            long long need = maximum / F[i];

            if (A[i] > need)
                sum += A[i] - need;
        }

        return sum <= K;
    };

    while (low < high) {
        long long mid = (low + high) / 2;

        if (possible(mid))
            high = mid;
        else
            low = mid + 1;
    }

    cout << low << '\n';
}


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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE
const Int LOG = 40;
const Int MAX = 2e5;
Int dp[LOG][MAX]={};
Int sm[LOG][MAX]={};

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

  Int n,x,m;
  cin>>n>>x>>m;

  for(Int i=0;i<m;i++){
    dp[0][i]=i*i%m;
    sm[0][i]=i;
  }

  for(Int k=0;k+1<LOG;k++){
    for(Int i=0;i<m;i++){
      dp[k+1][i]=dp[k][dp[k][i]];
      sm[k+1][i]=sm[k][i]+sm[k][dp[k][i]];
    }
  }

  Int ans=0,pos=x;
  for(Int k=0;k<LOG;k++){
    if((n>>k)&1){
      ans+=sm[k][pos];
      pos=dp[k][pos];
    }
  }
  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 66316
#include <stdio.h>
#include <memory.h>

int main(){
	int i,j,k,ks,n,kard[200],kard2[200],tmp;
	scanf("%d",&ks);
	scanf("%d",&n);
	for(i = 0;i < 2 * ks;i++) kard[i] = i + 1;
	for(i = 0;i < 2 * ks;i++) kard2[i] = i + 1;
	for(i = 0;i < n;i++) {
		scanf("%d",&tmp);
		if(tmp == 0) {
			for(j = 0;j < 2 * ks;j++){
				if(j < ks) kard2[2 * j] = kard[j];
				else kard2[(j - ks) * 2 + 1] = kard[j];
			}
		}else{
			for(j = 0;j < 2 * ks;j++) {
				if(j < tmp) kard2[j + 2 * ks - tmp] = kard[j];
				else kard2[j - tmp] = kard[j];
			}
		}
		memcpy(kard,kard2,8 * ks);
	}
	for(i = 0;i < 2 * ks;i++) printf("%d\n",kard2[i]);
	return 0;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (ll)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

ll digsum(ll n){
    ll sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }

    return sum;
}

string to_binString(int val)
{
    if( !val )
        return std::string("0");
    string str;
    while( val != 0 ) {
        if( (val & 1) == 0 )  // val は偶数か？
            str.insert(str.begin(), '0');  //  偶数の場合
        else
            str.insert(str.begin(), '1');  //  奇数の場合
        val >>= 1;
    }
    return str;
}

int main()
{
    double n;
    cin >> n;
    printf("%.10f\n",(int)((n + 1) / 2) / n);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,ans,a[110];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			for(int k=j+1;k<=n;k++)
				if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]&&a[i]+a[j]>a[k]&&abs(a[i]-a[j])<a[k]) ans++;
				cout<<ans;
				return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

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

	vector<int> dp(n);
	dp[1] = abs(h[0] - h[1]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
inline int read()
{
	int x=0,t=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=-1,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return x*t;
}
int main()
{
	int n=read();
	int x=0,y=0,t=0;
	bool fl=true;
	while(n--)
	{
		int tt=read(),xx=read(),yy=read();
		int dis=abs(xx-x)+abs(yy-y);
		if(tt-t>=dis&&(tt-t-dis)%2==0)
		{
			t=tt;x=xx;y=yy;
		}
		else
		{
			fl=false;
		}
	}
	if(fl)puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
from copy import copy
def dfs_visit(node, roads, visited, used):
    if all(visited) and all(used):
        return True
    elif all(used):
        return False
    okay = False
    for i, (a, b) in enumerate(roads):
        if used[i]:
            continue
        elif node == a:
            cp_visited = copy(visited)
            cp_used = copy(used)
            cp_used[i] = True
            cp_visited[b] = True
            okay |= dfs_visit(b, roads, cp_visited, cp_used)
        elif node == b:
            cp_visited = copy(visited)
            cp_used = copy(used)
            cp_used[i] = True
            cp_visited[a] = True
            okay |= dfs_visit(a, roads, cp_visited, cp_used)
    return okay

roads = sorted([sorted([int(elem) - 1 for elem in input().split()]) for _ in range(3)])

for start in range(4):
    visited = [False] * 4
    used = [False] * 3
    visited[start] = True
    if dfs_visit(start, roads, visited, used):
        print("YES")
        exit(0)
else:
    print("NO")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	string s; cin>>s;
	int n=s.size();
	bool ok;
	int ans=0,cnt=0;
	rep(i,0,n){
		if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T'){
			++cnt;
		}
		else {
			ans=max(ans,cnt);
			cnt=0;
		}
	}
	ans=max(ans,cnt);
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 256
import java.io.{BufferedReader, InputStream, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val A = map(N)(_ => sc.nextInt())
    val ans = A.grpBy(identity).sumBy { case (num, as) =>
      val cnt = as.length
      if (cnt >= num) cnt - num
      else cnt
    }

    out.println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

  private def rep(n: Int)(f: Int => Unit): Unit = {
    (0 until n) foreach f
  }

  private def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i)) 
    res
  }

  private implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      as foreach { a =>
        val k = f(a)
        map.getOrElseUpdate(k, ArrayBuffer()) += a
      }
      map
    }

  }

  private implicit class TraversableOpts[A](val as: Traversable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }

    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      as foreach { a =>
        val k = f(a)
        map.getOrElseUpdate(k, ArrayBuffer()) += a
      }
      map
    }
  }
}


Measured memory_bytes: 54696