akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1000000000
#define MAXN 110000
using namespace std;

int dp[5];
int N;

int main()
{
    cin >> N;
    int a, b, c, t1, t2, t3;
    for (int i = 0; i < N; i++)
    {
        cin >> a >> b >> c;
        t1 = max(dp[2], dp[3]) + a;
        t2 = max(dp[1], dp[3]) + b;
        t3 = max(dp[1], dp[2]) + c;
        dp[1] = t1;
        dp[2] = t2;
        dp[3] = t3;
    }
    int maxx = max(dp[1], dp[2]);
    cout << max(maxx, dp[3]);
    return 0;
}

Measured memory_bytes: 256
#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 (long long i = j; i < (long long)(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; }
//(a+b-1)/b

signed main(){
	int a,b,c; cin>>a>>b>>c;
	cout<<b/c-(a-1)/c<<endl;
	
	return 0;
}

Measured memory_bytes: 3628
a,b,h,m = gets.chomp.split(/ /).map {|i| i.to_i}

hrad = (h*30.0+m/2.0)*Math::PI/180.0
mrad = m*6.0*Math::PI/180.0

hx = Math.sin(hrad)*a
hy = Math.cos(hrad)*a

mx = Math.sin(mrad)*b
my = Math.cos(mrad)*b

d = Math.sqrt(((hx-mx)**2) + ((hy-my)**2))
puts d


Measured memory_bytes: 14824
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        System.out.println(solve(in));
        
      }
      
      public static String solve(Scanner in) {

        int N = in.nextInt();
        int[] SQ = new int[N];

        for (int i = 0; i < N; i++) {
            SQ[i] = in.nextInt();
        }
        int count = 0;
        int curSum = 0;
        for (int i = 1; i < SQ.length; i++) {
            if (SQ[i-1] >= SQ[i]) {
                curSum++;
                count = Math.max(curSum, count);
            } else {
                curSum = 0;
            }
        }

        return String.valueOf(count);
      }
}

Measured memory_bytes: 49840
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
using lint = long long;
int main() {
	string N;
	cin >> N;
	if (N.at(0) == N.at(1) && N.at(1) == N.at(2) && N.at(0) == N.at(2)) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

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

int main(){
  for(int i = 0; i < 4; i++){
    int t, n;
    cin >> t >> n;

    int ans;

    switch(t){
      case 1: ans = 6000 * n; break;
      case 2: ans = 4000 * n; break;
      case 3: ans = 3000 * n; break;
      case 4: ans = 2000 * n; break;
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 1164
# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))

abs = [abs(a) for a in A]
neg = len([1 for a in A if a < 0])
if neg % 2 == 0:
    print(sum(abs))
else:
    print(sum(abs) - 2 * min(abs))


Measured memory_bytes: 15020
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define int ll
#define endl "\n"
#define all( x ) x.begin(), x.end()
#define rev_all( x ) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(0);cin.tie(0);

typedef unsigned long long ull;

const int mod = 1e9 + 7;
const int inf = 1e11 + 5;
const long double PI = 3.141592653589793;

void solve(){
  int a, b, c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b <<endl;
  return;
}
signed main(){
  fast;
  int t;
  t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}

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

int dataset_count;
int sudoku[9][9];
bool wrong[9][9];
int main() {
	cin >> dataset_count;
	while (dataset_count--) {
		memset(wrong, 0, sizeof(wrong));
		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < 9; j++) {
				cin >> sudoku[i][j];
			}
		}
		
		// 横
		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < 9; j++) {
				for (int k = 0; k < 9; k++) {
					if (sudoku[i][j] == sudoku[i][k] && j != k) {
						wrong[i][j] = wrong[i][k] = true;
					}
				}
			}
		}
		
		// 縦
		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < 9; j++) {
				for (int k = 0; k < 9; k++) {
					if (sudoku[j][i] == sudoku[k][i] && j != k) {
						wrong[j][i] = wrong[k][i] = true;
					}
				}
			}
		}

		// ブロック
		for (int i = 0; i < 9; i+=3) {
			for (int j = 0; j < 9; j+=3) {
				for (int k = i; k < i+3; k++) {
					for (int l = j; l < j+3; l++) {
						for (int m = i; m < i+3; m++) {
							for (int n = j; n < j+3; n++) {
								if (sudoku[k][l] == sudoku[m][n] && k != m && l != n) {
									wrong[k][l] = wrong[m][n] = true;
								}
							}
						}
					}
				}
			}
		}

		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < 9; j++) {
				if (wrong[i][j]) cout << '*';
				else cout << ' ';
				cout << sudoku[i][j];
			}
			cout << endl;
		}
		if (dataset_count != 0) {
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

#define M 1299709

bool tbl[M + 1];

int main(){
	vector<int> p;
	p.reserve(100005);

	for(int i = 2; i * i <= M; ++i){
		if( !tbl[i] ){
			for(int j = i * i; j <= M; j += i){
				tbl[j] = true;
			}
		}
	}

	for(int i = 2; i <= M; ++i){
		if( !tbl[i] ){	p.push_back(i);	}
	}
	
	int k;
	while( scanf("%d", &k), k != 0 ){
		printf("%d\n", *lower_bound(p.begin(), p.end(), k) - *(upper_bound(p.begin(), p.end(), k) - 1));
	}
}

Measured memory_bytes: 2592
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1234567890
#define pii pair<int,int>
#define LL long long
using namespace std;

int main () {
    //clock_t start = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s,t;
    cin >> s >> t;
    int ans = 0;
    for (int i=0;i<s.size();i++) {
        if (s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    //cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 3772
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    boolean ans;
    int n = Integer.parseInt(stdIn.next());
    String s = stdIn.next();

    if (n % 2 != 0) {
      ans = false;
    } else {
      String t1 = s.substring(0, n / 2);
      String t2 = s.substring(n / 2, n);
      if (t1.equals(t2)) {
        ans = true;
      } else {
        ans = false;
      }
    }

    if (ans) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 21716
#include<iostream>
#include<cctype>

using namespace std;

int main(){
    char x;
    int a[1200] = {};
    int i;
    
    while(cin >> x){
        if(islower(x)){
            a[x - 'a']++;
        }if(isupper(x)){
            a[x - 'A']++;
        }
    }
    
    for(int i = 0; i < 26; i++){
        char y = 0;
        y = 'a' + i;
        cout << y << " : " << a[i] << endl;
    }return 0;
}


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N,M; cin>>N>>M;
	vector<int> H(N);
	for (int i=0; i<N; i++)
		cin>>H[i];
	vector<vector<int>> adj(N);
	for (int i=0; i<M; i++) {
		int A,B; cin>>A>>B; A--; B--;
		adj[A].push_back(B);
		adj[B].push_back(A);
	}
	int ret=0;
	for (int i=0; i<N; i++) {
		int cur=0;
		for (auto x : adj[i])
			cur=max(cur,H[x]);
		if(H[i]>cur)
			ret++;
	}
	cout<<ret<<"\n";
	return 0;
}

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

int main(){
  	int n;
  	cin>>n;
  		long long sum=0;
  	for(int i=1;i<=n;i++){
    	if(i%3==0 ||i%5==0)continue;
      	else{
        	sum +=i;
        }
    }
	cout<<sum<<endl;
}

Measured memory_bytes: 3636
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
const int N = 1e5 + 10;
const int logN = 60;

ll basis[logN];
int cnt[logN];

void gauss(ll mask) {
  for (int i = logN; i >= 0; i--) {
    if (!(mask & (1LL << i))) continue;
    if (!basis[i]) {
      basis[i] = mask;
      return;
    }
    mask ^= basis[i];
  }
}
 
int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> a(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = logN - 1; j >= 0; j--) {
      if (a[i] & (1LL << j)) {
        cnt[j]++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    ll res = 0;
    for (int j = logN - 1; j >= 0; j--) {
      if ((a[i] & (1LL << j) and cnt[j] > 0 and cnt[j] % 2 == 0)) {
        res |= (1LL << j);
      }
    }
    gauss(res);
  }
  ll ans = 0;
  for (int i = logN - 1; i >= 0; i--) {
    if (!basis[i]) continue;
    if (ans & (1LL << i)) continue;
    ans ^= basis[i];
  }
  ans *= 2;
  for (int i = logN - 1; i >= 0; i--) {
    if (cnt[i] % 2 != 0) {
      ans += (1LL << i);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll n=in(),k=in();
    vector<ll>h(n);
    for(ll i=0;i<n;++i)h[i]=in();
    sort(h.begin(),h.end());
    ll sum=0;
    for(ll i=0;i<n-k;++i)sum+=h[i];
    cout<<sum<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define PUT(x) cout << x << endl
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };

int main(void)
{
	int n,a,b;
	string s;
	cin >> n >> a >> b >> s;

	for (int i = 0; i < n; i++) {
		if (s[i] == 'a') {
			if (a + b > 0) {
				cout << "Yes" << endl;

				if (a > 0)
					a--;
				else
					b--;
				continue;
			}
		}
		else if (s[i] == 'b') {
			if (b > 0) {
				cout << "Yes" << endl;
				b--;
				continue;
			}

		}
		cout << "No" << endl;
	}

	return 0;
}


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

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

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

int main(void)
{
	int r1,r2;
	double r3;
	scanf("%d %d",&r1,&r2);
	
	r3=(double)(r1*r2)/(double)(r1+r2);
	
	printf("%.10f\n",r3);
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

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

    queue<string> Q;
    Q.push("a");
    REP(i,1,N) {
        queue<string> R = Q;
        while(!Q.empty()) Q.pop();
        while(!R.empty()) {
            string S = R.front(); R.pop();
            char m = 'a';
            REP(i,0,SZ(S)) m = MAX(m,S[i]);
            REP(i,'a',m+2) Q.push(S+(char)i);
        }
    }
    
    while(!Q.empty()) {
        PR(Q.front());
        Q.pop();
    }

    return 0;
}

/*



*/

Measured memory_bytes: 6880
// IN THE NAME OF ALLAH
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define F fisrt
#define S second


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



Measured memory_bytes: 3724
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int n;
  cin >> n;
  vector<int> f(n);
  f[0] = 1;
  f[1] = 2;
  for (int i = 2; i < n; i++) {
    f[i] = f[i - 1] + f[i - 2];
  }
  cout << f[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 3116
def prime_factor(n):
    ret, p = {}, 2
    while p*p <= n:
        while n % p == 0:
            ret[p] = ret.get(p, 0) + 1
            n //= p
        p += 1
    if n != 1: ret[n] = 1
    return ret


def mod_inverse(x, mod):
    return pow(x, mod-2, mod)


def mod_comb(n, k, mod):
    numer, denom = 1, 1
    for i in range(k):
        numer = numer * ((n-i) % mod) % mod
        denom = denom * ((i+1) % mod) % mod

    return numer * mod_inverse(denom, mod) % mod


def main():
    n, m = map(int, input().split())
    prime = prime_factor(m)
    mod = 1000000007
    ans = 1
    for (p, e) in prime.items():
        ans = ans * mod_comb(n+e-1, e, mod) % mod

    print(ans)

main()

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

int N;
int dp[100010];
vector<int> V[100010];
int depth[100010] = {0};

int DP(int n)
{
    if(n == 1)
    {
        if(V[1].size() == 1)return DP(V[1][0]) + 1;
        int res = -1;
        for(int i = 0; i < V[1].size(); i++)
        {
            if(res == -1)res = DP(V[1][i]) + 1;
            else res ^= DP(V[1][i]) + 1;
        }
        return res;
    }
    if(V[n].size() == 1)return 0;
    if(V[n].size() == 2)
    {
        for(int i = 0; i < V[n].size(); i++)
        {
            if(depth[n] < depth[V[n][i]])return DP(V[n][i]) + 1;
        }
    }
    int res = -1;
    for(int i = 0; i < V[n].size(); i++)
    {
        if(depth[n] > depth[V[n][i]])continue;
        if(res == -1)res = DP(V[n][i]) + 1;
        else res ^= DP(V[n][i]) + 1;
    }
    return res;
}

void DFS(int n,int d)
{
    if(depth[n] != 0)return;
    depth[n] = d;
    for(int i = 0; i < V[n].size(); i++)
    {
        DFS(V[n][i],d + 1);
    }
}

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)dp[i] = -1;
    for(int i = 0; i < N - 1; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        V[a].push_back(b);
        V[b].push_back(a);
    }
    DFS(1,1);
    if(DP(1))printf("Alice\n");
    else printf("Bob\n");
    return 0;
}


Measured memory_bytes: 11136
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		System.out.println((a == b) ? c : (b == c) ? a : b);

		sc.close();


	}

}




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


int main()
{
    long long int t;
    long long int ac=0,tle=0,wa=0,re=0;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        if(s=="AC")
        {
            ac++;
        }
        else if(s=="WA")
        {
            wa++;
        }
        else if(s=="TLE") {
            tle++;
        }
        else if(s=="RE"){
            re++;
        }
    }
    cout<<"AC x"<<' '<<ac<<endl;
    cout<<"WA x"<<' '<<wa<<endl;
    cout<<"TLE x"<<' '<<tle<<endl;
    cout<<"RE x"<<' '<<re<<endl;

}



Measured memory_bytes: 3644
A, B, C, D, E, F = map(int, input().split())

density = -1
ans = (0, 0)

for a in range(31):
  for b in range(31):
    for c in range(101):
      for d in range(101):
        water = 100*a*A + 100*b*B
        suger = c*C + d*D
         
        if water + suger > F or water == 0:
          break

        if (water / 100) * E >= suger:
        
          tmp = (100 * suger)  / (water + suger)

          if tmp > density:
            density = tmp
            ans = (water+suger, suger)

print(*ans)

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

int main() {
    int n,count=0,ans=0;
    cin>>n;
    vector<int> h(n);
    rep(i,n) cin>>h.at(i);

    for (int i=1; i<n; i++) {
        if (h[i-1]>=h[i]) {
            count++;
        } else {
            count=0;
        }
        ans=max(ans,count);
    }

    cout<<ans<<endl;
}



Measured memory_bytes: 768
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, m, v, p;
  cin >> n >> m >> v >> p;
  vll as(n);
  rep(i, n) cin >> as[i];
  rSort(as);

  vll csum(n + 1);
  csum[0] = 0;
  rep(i, n) csum[i + 1] = csum[i] + as[i];

  ll crescent1997 = 0;
  rep(i, n) {
    if (i + 1 <= p) {
      crescent1997++;
      continue;
    }
    if (as[p - 1] > as[i] + m) continue;
    ll vp = v - (p - 1) - (n - i);
    chmax(vp, 0LL);
    ll lhs = (as[i] + m) * (i - p + 1) - (csum[i] - csum[p - 1]);
    ll rhs = vp * m;
    if (lhs >= rhs) crescent1997++;
  }

  cout << crescent1997 << endl;

  return 0;
}


Measured memory_bytes: 4776
#include<iostream>
#include<vector>

using namespace std;

int main()
{
    int N,M;
    vector<int> vec(M);
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> vec.at(i);
        //vec.push_back(i);
        N -= vec.at(i);
    }
    
    if(N >= 0) cout << N <<endl;
    else cout << "-1" << endl;

    return 0;
}

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

#define int long long

struct Combination
{
  int mod;
  vector<int> fact;
  vector<int> invf;
  vector<vector<int> > part;  

  /*
    constructor : O(sz+log(mod))    
  */
  Combination(int sz, int mod) : fact(sz+1), invf(sz+1), mod(mod) {
    fact[0] = 1;
    for ( int i = 1; i < (int)fact.size(); i++ ) {
      fact[i] = fact[i-1]*i % mod;
    }
    invf[sz] = inv(fact[sz]);
    for ( int i = sz-1; i >= 0; i-- ) {
      invf[i] = invf[i+1]*(i+1) % mod;
    }
  }

  int pow(int x, int n) const {
    int ret = 1;
    while ( n > 0 ) {
      if ( n & 1 ) (ret *= x) %= mod;
      (x *= x) %= mod;
      n >>= 1;
    }
    return (ret);
  }

  int inv(int x) const {
    return (pow(x, mod - 2));
  }

  /*
    permutation
  */
  int P(int n, int r) const {
    if ( r < 0 || n < r ) return (0);
    return (fact[n]*invf[n-r] % mod);    
  }

  /*
    combination
  */
  int C(int n, int r) const {
    if ( r < 0 || n < r ) return (0);    
    return (fact[n]*invf[r]%mod * invf[n-r] % mod);    
  }  

  /*
    combination with repetition
  */
  int H(int n, int r) const {
    if ( n < 0 || r < 0 ) return 0;
    if ( n == 0 && r == 0 ) return 1;
    return C(n+r-1, n);    
  }

  /*
    stirling number
  */
  int S(int n, int r) const {
    int ret = 0;
    for ( int i = 1; i <= r; i++ ) {
      int add = C(r, i)*pow(i, n)%mod;      
      if ( (r-i)&1 ) ret += mod-add;
      else ret += add;
      ret %= mod;      
    }
    (ret *= invf[r]) %= mod;
    return ret;
  }

  /*
    bell number
  */
  int B(int n, int r) const {
    int ret = 0;
    for ( int i = 1; i <= r; i++ ) {
      (ret += S(n, i)) %= mod;      
    }
    return ret;
  }

  /*
    calc partition number
    return partition number table
  */
  vector<vector<int> > built_part(int n, int r) {
    part = vector<vector<int> >(n+1, vector<int>(r+1, 0));
    part[0][0] = 1;
    for ( int i = 0; i <= n; i++ ) {
      for ( int j = 1; j <= r; j++ ) {
	if ( i-j >= 0 ) {
	  (part[i][j] = part[i][j-1]+part[i-j][j]) %= mod;	  
	} else {
	  part[i][j] = part[i][j-1];
	}
      }
    }
    return part;    
  }  
};

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, k;
  cin >> n >> k;

  int MOD = 1e9+7;
  Combination c(2000, MOD);

  c.built_part(n, k);
  cout << c.part[n][k] << endl;  
  
  return 0;
}



Measured memory_bytes: 18716
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n;
  cin>>n;
  long long int a[n];
  for(long long int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  sort(a,a+n);
  for(long long int i=0;i<n-1;i++)
  {
    if(a[i]==a[i+1])
    {
      cout<<"NO";
      return 0;
    }
  }
  cout<<"YES";
  return 0;
}

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

using namespace std;

template <class T> void mini(T &l, T r) {l = min(l, r);}
template <class T> void maxi(T &l, T r) {l = max(l, r);}

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(bool a) {
  return a ? "T" : "F";
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = long long;
using ld = long double;

const int N = 1e5 + 10, K = 1010;

int n, k;
int x[N], y[N];
string color[N];
int cnt[2 * K][2 * K], a[2 * K][2 * K];

void add(int lx, int rx, int ly, int ry) {
  debug(lx, rx, ly, ry);
  rx++;
  ry++;
  cnt[lx][ly]++;
  cnt[lx][ry]--;
  cnt[rx][ly]--;
  cnt[rx][ry]++;
}

int sub(int x, int y, int md) {
  int t = (x - y) % md;
  if (t < 0) t += md;
  return t;
}

void go(vector < pair <int, int> > &v, int l, int r, int x, int md) {
  //x >= l && x <= r;
  int tl = sub(l, x, md);
  int tr = sub(r, x, md);
  if (tl <= tr) {
    v.push_back(make_pair(tl, tr));
  } else {
    v.push_back(make_pair(tl, md - 1));
    v.push_back(make_pair(0, tr));
  }
}

void run() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i] >> color[i];
  }

  for (int i = 0; i < n; ++i) {
    vector < tuple <int, int, int, int> > tmp;
    int lx, ly, rx, ry;
    if (color[i] == "W") {
      lx = k, rx = 2 * k - 1;
      ly = 0, ry = k - 1;
      tmp.emplace_back(lx, rx, ly, ry);
      lx = 0, rx = k - 1;
      ly = k, ry = 2 * k - 1;
      tmp.emplace_back(lx, rx, ly, ry);
      //x[i] >= k, x[i] < 2 * k;
      //y[i] >= 0, y[i] < k;
    } else {
      lx = 0, rx = k - 1;
      ly = 0, ry = k - 1;
      tmp.emplace_back(lx, rx, ly, ry);
      lx = k, rx = 2 * k - 1;
      ly = k, ry = 2 * k - 1;
      tmp.emplace_back(lx, rx, ly, ry);
      //x[i] >= 0, x[i] < k;
      //y[i] >= 0, y[i] < k;
    }
    for (auto t : tmp) {
      tie(lx, rx, ly, ry) = t;
      vector < pair <int, int> > vx, vy;
      go(vx, lx, rx, x[i], 2 * k);
      go(vy, ly, ry, y[i], 2 * k);
      for (auto p : vx) {
        for (auto py : vy) {
          add(p.first, p.second, py.first, py.second);
        }
      }
    }
  }
  for (int i = 0; i < 2 * k; ++i) {
    for (int j = 0; j < 2 * k; ++j) {
      a[i][j] = cnt[i][j] + (j == 0 ? 0 : a[i][j - 1]) + (i == 0 ? 0 : a[i - 1][j]) - ((i == 0 || j == 0) ? 0 : a[i - 1][j - 1]);
    }
  }

  int ans = 0;
  for (int i = 0; i < 2 * k; ++i) {
    maxi(ans, *max_element(a[i], a[i] + 2 * k));
  }
  cout << ans << endl;
}

int main() {
  run();
  return 0;
}


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

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

    bool ans = false;
    for(int i = 0; i < s.size(); i++){
        if(s == t){
            ans = true;
        }
        s = s.back() + s.substr(0, s.size() - 1);
    }

    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
#define pll pair<ll,ll>
#define pii pair<int,int>
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
 
ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b) ;} 

template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}
 
void solve(){
	ll n,x,t;
	cin>>n>>x>>t;
	if(n%x==0){
		cout<<t*(n/x)<<endl;
	}
	else{
		cout<<t*(n/x +1)<<endl;
	}
}
 
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	ll t;
	// cin>>t;
	t=1;
	while(t--){
		solve();
	}    
    return 0;
}

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


#define ll long long


using namespace std;


int main()
{
  ll n, t, tmp, sumv, i_1;
  vector<ll> v;

  cin >> n >> t;
  for (ll i; i<n; i++){
    cin >> tmp;
    v.push_back(tmp);
  }

  vector<ll>::iterator it_f = v.begin(), it_l = v.end(), i;

  sumv = t;
  i_1 = *it_f;
  for (i = it_f; i != it_l; i++){
    if (i_1+t <= *i) sumv += t;
    else sumv += *i - i_1;
    i_1 = *i;
  }
  cout << sumv << endl;
  
  return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b; 
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b; 
        return true;
        
    }
    return false;
}

struct UnionFind {
    vector<int> d;
    UnionFind(int N) : d(N, -1){}

    int root(int x) {
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false; 
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    int size(int x) {
        return -d[root(x)];
    }
};

void Main(){
    int n; cin >> n;
    vector<string> s(n);
    vvi to(n);

    // 二部グラフ判定
    UnionFind two(2*n);
    
    rep(i, n) {
        cin >> s[i];
        rep(j, n){
            if(s[i][j] == '1') {
                to[i].pb(j);
                two.unite(i, n+j);
                two.unite(j, n+i);
            }
        }
    }
    
    bool ok = true;
    rep(i, n){
        if(two.same(i, n+i)) ok = false;
    }
    if(!ok){
        cout << -1 << endl;
        return;
    }
    
    // Warshall–Floyd
    const int INF = 1e9;
    vvi d(n, vi(n, INF));
    rep(i, n) {
        for(auto j : to[i]){
            d[i][j] = 1;
        }    
    } 
    rep(k, n) rep(i, n) rep(j, n){
        chmin(d[i][j], d[i][k] + d[k][j]);
    }
    int ans = 0;
    rep(i, n) rep(j, n){
        if(i == j) continue;
        chmax(ans, d[i][j]);
    }
    cout << ans + 1 << endl;
    return;
}

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

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

int main() {
	string s;
	cin >> s;
	sort(s.begin(),s.end());
	reverse(s.begin(),s.end());
	int a = 0;
	for(int i = 0;s.at(i) == 'p';i++){
		a++;
	}
	cout << s.size() / 2 - a << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long 
using namespace std;
typedef pair<int,int> ii;

const int B = 512;
int V[270000];
int W[270000];


int dp[B + 3][100005];

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int n; cin >> n;
	
	for(int i = 1;i <= n;i++) cin >> V[i] >> W[i];
	
	for(int i = 0;i <= B+1;i++){
		fill(dp[i],dp[i]+100003,-10234567890123423);
		dp[i][0] = 0;
	}
	
	for(int i = 1;i <= B;i++){
		for(int j = 100003;j >= 0;j--){
			dp[i][j] = dp[i>>1][j];
			if(j >= W[i]) dp[i][j] = max(dp[i][j], dp[i>>1][j-W[i]] + V[i]);
		}
	}
	
	for(int i = 1;i <= B;i++){
		for(int j = 1;j <= 100003;j++){
			dp[i][j] = max(dp[i][j], dp[i][j-1]);
		}
	}
	
	
	int Q; cin >> Q;
	while(Q--){
		int v, L; cin >> v >> L;
		vector<ii> P = {{0,0}};
		
		while(v > B){
			int sz = P.size();
			for(int i = 0;i < sz;i++){
				ii a = P[i];
				ii b = ii(a.first + V[v], a.second + W[v]);
				if(b.second <= L) P.push_back(b);
			}
			v >>= 1;
		}
		
		int ans = 0;
		for(ii x : P){
			int leftover = L - x.second;
			ans = max(ans, dp[v][leftover] + x.first);
			//cout << x.first << " " << x.second << ", ";
		}
		cout << ans;
		cout << "\n";
	}
	
}



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

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

    int answer = 0;

    for ( int i =0; i<3 ; i++) {
        
        if ( s.at(i) == '1' ) {
            answer++;
        }

    }

    cout << answer << endl;

}

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

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

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <cstring>
#define N 1000000
using namespace std;

int main()
{
	int a, d, n, i;
	bool prime[N];
	
	memset(prime, true, sizeof(prime));
	prime[0] = prime[1] = false;
	for (i = 2; i < sqrt(N) + 1; i++) {
		if (prime[i]) {
			for (int j = 2 * i; j < N; j += i) {
				prime[j] = false;
			}
		}
	}
	
	while (cin >> a >> d >> n, a) {
		for (i = a; n; i += d) {
			if (prime[i]) n--;
		}
		cout << i - d << endl;
	}
	
	return 0;
}

Measured memory_bytes: 2140
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    long n,x,m;
    scanf("%ld %ld %ld", &n, &x, &m);
    vector<long> viNum(m, -1);
    long nAns = 0;
    long aTmp = x;
    
    if(n <= m){
        for(long i = 0; i < n; i++){
            nAns += aTmp;
            aTmp = aTmp * aTmp;
            aTmp %= m;
        }
        printf("%ld", nAns);
        return 0;
    }
    
    long nSum = 0;
    int iLoop = 0;
    int iStart = 0;
    for(long i = 0; i < m; i++){
        nSum += aTmp; //1~i+1まで
        if(viNum[aTmp] == -1){
            viNum[aTmp] = i;
            aTmp = aTmp * aTmp;
            aTmp %= m;
            continue;
        } else {
            iLoop = i - viNum[aTmp];
            iStart = i;
            break;
        }        
    }

    long iLoopCount = (n-iStart-1) / iLoop;
    long iRemain = (n-iStart-1) % iLoop;
    long iLoopSum = 0;
    long iRemainSum = 0;
    for(long i = 0; i < iLoop; i++){
        aTmp = aTmp * aTmp;
        aTmp %= m;
        iLoopSum += aTmp;
        if(i == iRemain - 1){
            iRemainSum = iLoopSum;
        }
    }
    
    printf("%ld", nSum + iLoopSum * iLoopCount + iRemainSum);
    return 0;
}


Measured memory_bytes: 3664
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	vi a(3);cin>>a[0]>>a[1]>>a[2];
	sort(all(a));if((a[0]==a[1]&&a[2]-a[1])||(a[2]==a[1]&&a[0]-a[1])) return cout<<"Yes\n",0;
	cout<<"No\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>

using namespace std;
using ll = long long;


void solve1() {
	ll H, n, ans;
	cin >> H;

	n = (int)log2(H);
	ans = pow(2, n + 1) - 1;

	cout << ans << endl;
}

int main(void) {
	solve1();
}

Measured memory_bytes: 384
N=int(input())
A=list(map(int,input().split()))
n=0
for i in range(len(A)):
    if A[i]<0:
        n+=1
if n%2==0:
    ans=0
    for i in range(len(A)):
        ans+=abs(A[i])
if n%2==1:
    B=A
    for i in range(len(A)):
        B[i]=abs(A[i])
    minn=min(B)
    ans=0
    for i in range(len(A)):
        ans+=B[i]
    ans-=2*minn
print(ans)
    
        

Measured memory_bytes: 15248
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int main() {
  //
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  for (int i = n - 1; i > 0; i -= 2) {
    cout << a[i] << " ";
  }
  if (n > 1) {
    cout << a[0] << " ";
  } else {
    cout << a[0] << endl;
  }
  int istart = 2;
  if (n & 1) istart = 1;
  for (int i = istart; i <= n - 2; i += 2) {
    if (i < n - 2) {
      cout << a[i] << " ";
    } else {
      cout << a[i] << endl;
    }
  }
  return 0;
}


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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
	freopen ("E.in", "r", stdin);
	freopen ("E.out", "w", stdout);
}

const int N = 1e5 + 1e3, Mod = 1e9 + 7;

int n, m, x[N], dp[N][4];

struct Matrix {

	int a[4][4];

	Matrix () { Set(a, 0); }

	inline void Unit() { Rep (i, 4) a[i][i] = 1; }

	inline friend Matrix operator * (const Matrix &lhs, const Matrix &rhs) {
		Matrix res;
		Rep (i, 4) Rep (j, 4) Rep (k, 4)
			res.a[i][j] = (res.a[i][j] + 1ll * lhs.a[i][k] * rhs.a[k][j]) % Mod;
		return res;
	}

	inline void Out() {
		puts("---------------");
		Rep (j, 4) Rep (k, 4)
			printf ("%d%c", a[j][k], k == 3 ? '\n' : ' ');
		puts("---------------");
	}

};

inline Matrix fpm(Matrix x, int power) {
	Matrix res; res.Unit();
	for (; power; power >>= 1, x = x * x)
		if (power & 1) res = res * x;
	return res;
}

Matrix f, trans1, trans2;

int main () {

	n = read(); m = read();

	For (i, 1, m)
		x[i] = read();

	f.a[0][0] = 1;
	Rep (j, 4) For (k, 0, j) if ((k & j) == k) ++ trans1.a[k][j], ++ trans2.a[k][j];
	Rep (j, 4) ++ trans1.a[j][0];

	For (i, 1, m) {
		int gap = x[i] - x[i - 1] - 1;
		f = f * fpm(trans1, gap);
		f = f * trans2;
	}
	if (x[m] < n)
		f = f * fpm(trans1, n - x[m]);

	////For (i, 1, n) {
	////	bool flag = true;
	////	For (j, 1, m)
	////		if (x[j] == i) flag = false;

	////	if (flag) f = f * trans1;
	////	else f = f * trans2;
	////}

	printf ("%d\n", f.a[0][3]);

	return 0;

}

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

using namespace std;

const int N = 500500;
const int K = 26;

#define M (l + r) / 2
#define cl 2 * i + 1
#define cr 2 * i + 2

int t[4 * N][K]; 
int arr[N];
int n;

void build(int i = 0, int l = 0, int r = n) {
    if (r - l == 1) {
        ++t[i][arr[l]];
        return;
    }
    build(cl, l, M);
    build(cr, M, r);
    for (int j = 0; j < K; ++j) {
        t[i][j] = t[cl][j] + t[cr][j];
    }
}

void ch(int x, int ind, int i = 0, int l = 0, int r = n) {
    if (r - l == 1) {
        //cout << endl << ind << ' ' << arr[ind] << endl;
        --t[i][arr[ind]];
        arr[ind] = x;
        ++t[i][arr[ind]];
        return;
    }
    if (ind < M) {
        --t[i][arr[ind]];
        ch(x, ind, cl, l, M);
        ++t[i][arr[ind]];
    } else {
        --t[i][arr[ind]];
        ch(x, ind, cr, M, r);
        ++t[i][arr[ind]];
    }
}

void ask(vector<int>& ans, int al, int ar, int i = 0, int l = 0, int r = n) {
    if (ar <= l || r <= al) {
        return;
    }
    if (al <= l && r <= ar) {
        ans.push_back(i);
        return;
    }
    ask(ans, al, ar, cl, l, M);
    ask(ans, al, ar, cr, M, r);
}

signed main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        char c;
        cin >> c;
        arr[i] = c - 'a';
    }
    build();
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int x;
        cin >> x;
        if (x == 1) {
            int a;
            char c;
            cin >> a >> c;
            ch(c - 'a', a - 1);       /*    
        cout << endl;
        for (int j = 0; j < K; ++j) {
            cout << t[0][j] << ' ';
        }
        cout << endl; */
        } else {
            int a, b;
            cin >> a >> b;
            vector<int> ans;
            ask(ans, a - 1, b);
            vector<int> res(K);
            for (auto j : ans) {
                for (int k = 0; k < K; ++k) {
                    res[k] += t[j][k];
                }
            }
            int out = 0;
            for (int j = 0; j < K; ++j) {
                if (res[j] != 0) {
                    ++out;
                }       
            }
            cout << out << '\n';
        }
    }     
}


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

typedef long long lint;
typedef long double louble;

#define so(a) ((int)((a).size()))

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const char lf = '\n';

namespace ae86
{
	const int bufl = 1 << 15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 200007 , inf = 0x3f3f3f3f;

int n,val[_]={0};

vector<pair<int,int>> make(int la,int lb,int now,int bas)
{
	vector<pair<int,int>> ret;
	if(max(la,now-lb)<=now)ret.emplace_back(bas,max(la,now-lb));
	ret.emplace_back(bas+1,max(0,min(la,now-lb)));
	ret.emplace_back(bas+2,0);

	return ret;
}

int main()
{//
	ios::sync_with_stdio(0),cout.tie(nullptr);

	n=ty();
	for(int i=1;i<=n;i++)val[i]=ty();

	pair<int,int> f[3],sf[3];
	for(int i=0;i<3;i++)f[i]=make_pair(0,0);

	for(int i=1;i<=n+1;i++)
	{
		vector<pair<int,int>> now;
		for(int j=0;j<3;j++)
		{
			auto temp=make(f[j].second,val[i-1]-f[j].second,val[i],f[j].first);
			now.insert(now.end(),temp.begin(),temp.end());
		}
		sort(now.begin(),now.end());

		int nowmi=now[0].first;

		for(int j=0;j<3;j++)sf[j]=make_pair(inf,0);
		for(auto j:now)if(j.first<=nowmi+2)sf[j.first-nowmi]=min(sf[j.first-nowmi],j);
		for(int j=0;j<3;j++)f[j]=sf[j];
	}

	cout<<f[0].first<<lf;
	
	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

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

	if (a > b) {
		for (int i = 0; i < a; i++) {
			cout << b;
		}
	}
	else {
		for (int i = 0; i < b; i++) {
			cout << a;
		}
	}
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
dic={}
wk=1
start=0
for i in range(1,n+1):
  wk=a[wk-1]
  if wk in dic:
    start=dic[wk]
    break
  dic[wk]=i
end=len(dic)
loopcnt=end-start+1
keys=list(dic.keys())
if k<start:
  print(keys[k-1])
else:
  chk=(k-start+1)%loopcnt
  if chk==0:
    chk=loopcnt
  print(keys[(start-1)+chk-1])


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

#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    int ansh, ansn, answ;
    bool end = false;
    for (int h=1;h<=3500;h++){
        for (int n=1;n<=3500;n++){
            int p = N*h*n;
            int q = 4*h*n-N*n-N*h;
            if (q <= 0) continue;
            if (p%q==0) {
                ansh = h;
                ansn = n;
                answ = p/q;
                end = true;
                break;    
            }
        }
        if (end) break;
    }
    cout << ansh << " " << ansn << " " << answ << "\n";
}

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

int main(int argc, char *argv[])
{
  int n;
  cin >> n;
  vector<int> a;
  for (; n-->0;) {
    int t; cin >> t;
    a.push_back(t);
  }

  int min = a.size(), max = 0;
  for (vector<int>::iterator ia = a.begin(); ia != a.end(); ++ia) {
    int i = *ia;
    min = (min > i)? i : min;
    max = (max < i)? i : max;
  }

  if (max - min > 1) {
    cout << "No" << endl;
    return 0;
  }

  if (max == min) {
    if (min == a.size() - 1 || min * 2 <= a.size()) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
    return 0;
  }

  // min == max - 1
  int alone = 0, notalone = 0;
  for (vector<int>::iterator ia = a.begin(); ia != a.end(); ++ia) {
    if (min == *ia) {
      alone++;
    } else {
      notalone++;
    }
  }
  if (alone < max && (max - alone) * 2 <= notalone) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 892