akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pow107 int(pow(10,9) + 7)
#define F(i,x,n) for(int i = x; i < n ; ++i)

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

inline bool pn(long int x){
    if(x <= 1)return false;
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i <= (3 + int(sqrt(x)))/2; ++i){
        if((x != i && x % i == 0) || (x != (3 + int(sqrt(x)) - i) && x % (3 + int(sqrt(x)) - i) == 0))
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

void warfl(vector<vector<int> > &dist, int n){
  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  return;
}
//#define long long long

const int MAX = 1000000;
const int MOD = 1e9+7;

long mpow(long x, long n){
    long ans = 1;
    while(n != 0){
        if(n%2==1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n/2;
    }
    return ans;
}

long mfact(long n){
  long ans = 1;
  for(long i=2; i<=n; i++){
    ans = ans*i % MOD;
  }
  return ans;
}

long mcomb(long n, long m){ //aCbをmod計算
    if(n == 0 && m == 0) return 1;
    if(n < m || n < 0) return 0;
    long ans = mfact(n)*mpow(mfact(m), MOD-2) %MOD;
    ans = ans*mpow(mfact(n-m), MOD-2) %MOD;
    return ans;
}

long int jjjjj(long int n){
    long int x = 1;
    for(int i = 1; i <= n; ++i){
        x *=i;
    }
    return x;
}

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

    int ans = 0;

    for(int i = 0; i <= a; ++i){
        for(int j = 0; j <= b; ++j){
            for(int k = 0; k <= c; ++k){
                if(500 * i + 100 * j + 50 * k == x) ans++;
            }
        }
    }

    cout << ans << endl;

}

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

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())

#define REP(a, b) for (int a = 0; a < (b); a++)
#define FOR(a, b, c) for (int a = (b); a <= (c); a++)
#define REPD(a, b) for (int a = (b) - 1; a >= 0; a--)
#define FORD(a, b, c) for (int a = (b); a >= (c); a--)

#define MIN(a, b) (a) = min((a), (b))
#define MAX(a, b) (a) = max((a), (b))

#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2> &p) {
  return is >> p.fi >> p.se;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s, t;
  cin >> s >> t;
  int n = SZ(s), m = SZ(t);
  VV<int> dp(n + 1, vi(m + 1, -1));
  VV<pii> opt(n + 1, V<pii>(m + 1, pii(-1, -1)));
  dp[0][0] = 0;
  auto relax = [&](int i, int j, int v, int ni, int nj) {
                 if (dp[ni][nj] < v) {
                   dp[ni][nj] = v;
                   opt[ni][nj] = pii(i, j);
                 }
               };
  REP(i, n) REP(j, m) if (dp[i][j] > -1) {
    relax(i, j, dp[i][j], i + 1, j);
    relax(i, j, dp[i][j], i, j + 1);
    if (s[i] == t[j]) {
      relax(i, j, dp[i][j] + 1, i + 1, j + 1);
    }
  }
  pair<int, pii> ans {-1, {-1, -1}};
  FOR(i, 0, n) FOR(j, 0, m) MAX(ans, mp(dp[i][j], mp(i, j)));
  debug cout << ">>> " << ans.fi << endl;
  string anss;
  while (ans.se.fi > 0 || ans.se.se > 0) {
    debug assert(ans.fi == dp[ans.se.fi][ans.se.se]);
    pii nans = opt[ans.se.fi][ans.se.se];
    int ni = nans.fi;
    int nj = nans.se;
    if (dp[ni][nj] != ans.fi) {
      debug assert(s[ni] == t[nj]);
      anss += s[ni];
    }
    ans.fi = dp[ni][nj];
    ans.se.fi = ni;
    ans.se.se = nj;
  }
  reverse(ALL(anss));
  cout << anss << endl;
}


Measured memory_bytes: 105984
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> a(n);
	rep(i,n){
		cin>>a[i];
		a[i]--;
	}
	int ans=0;
	rep(i,n) if(a[a[i]]==i) ans++;
	cout<<ans/2<<endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007

int N;
int A[2005];
int dp[2005][2005];
vector< pair<int,int> > AI;
signed main(){
    scanf("%lld",&N);
    rep(i,N){
        scanf("%lld",&A[i]);
        AI.pb(mp(A[i],i));
    }
    sort(AI.begin(),AI.end(),greater<pair<int,int>>());
    rep(i,N)rep(j,N+1)dp[i][j]=-LLINF;
    rep(i,N){
        rep(j,N+1){
            if(i==0){//j=0;
                //右に置く
                dp[i][j]=AI[i].first*abs((N-1)-AI[i].second);
                //左に置く
                dp[i][j+1]=AI[i].first*abs(j-AI[i].second);
                break;
            }else{
                 //右に置く
                dp[i][j]=max(dp[i][j],dp[i-1][j]+AI[i].first*abs((N-1-(i-j))-AI[i].second));
                //左に置く
                dp[i][j+1]=max(dp[i][j+1],dp[i-1][j]+AI[i].first*abs(j-AI[i].second));
            }
        }
    }
    /*rep(i,N){
        rep(j,N+1){
            printf("%lld ",dp[i][j]);
        }
        printf("\n");
    }*/
    int ans=0;
    rep(i,N+1)ans=max(ans,dp[N-1][i]);
    printf("%lld\n",ans);
    return 0;
}


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

int main(){
  int n; cin >> n;
  int x = 100;
  int f = n/x;
  int q = n%10;
  n /= 10;
  int y = n%10;
  if(y > f)cout << f + 1 << f + 1 << f + 1 << '\n';
  else if(y == f && q > f) cout << f + 1 << f + 1 << f + 1 << '\n';
  else cout << f << f << f << '\n';
}

Measured memory_bytes: 3560
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;   
}

int main() {
    int a;
    cin>>a;
    if(a<1000){
        cout<<"ABC"<<endl;
    }
    else
    {
        cout<<"ABD"<<endl;
    }
    
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 10000
using namespace std;
typedef long long ll;

int main(){
  int n;  cin >> n;
  vector<int> a(200010);
  vector<int> f, b;
  rep(i, 0, n){
    cin >> a[i];
  }
  for(int i=0; i<n; i+=2){
    b.push_back(a[i]);
    if(i+1<n) f.insert(f.begin(), a[i+1]);
  }
  if(n&1){
    reverse(all(b));
    reverse(all(f));
    b.insert(b.end(), all(f));
  }
  else{
    b.insert(b.begin(), all(f));
  }
  rep(i, 0, n){
    cout << b[i] << " ";
  }
  cout << endl;
  return 0;
}

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

using namespace std;
using ll = long long;

vector<int> PrimeFactoring(int N){
    vector<int> ans;
    while(N != 1){
        for(int a = 2;a <= N;a++){
            if(N%a == 0){
                N/=a;
                ans.push_back(a);
                break;
            }
        }
    }
    return ans;

}

int main()
{
    int N;cin >> N;
    map<int, int> mp;
    vector<int> v;
    for(int i = 1;i <= N;i++){
        vector<int> b = PrimeFactoring(i);
        for(auto a : b){
            mp[a]++;
        }
    }
    for(auto a : mp){
        v.push_back(a.second);
    }
    ll ans = 0;
    for(int i = 0;i < v.size();i++){
        for(int j = 0;j < v.size() - 1;j++){
            for (int k = j + 1;k < v.size();k++){
                if(i == k || i == j || k == j){
                    continue;
                }
                if(v.at(i) >= 2 && v.at(j) >= 4 && v.at(k) >= 4){
                    ans++;
                }
            }
        }
    }
    for(int i = 0;i < v.size();i++){
        for(int j = 0;j < v.size();j++){
            if(i == j)continue;
            if(v.at(i) >= 2 && v.at(j) >= 24){
                ans++;
            }
            if(v.at(i) >= 4 && v.at(j) >= 14){
                ans++;
            }
        }
    }
    for(int i = 0;i < v.size();i++){
        if(v.at(i) >= 74)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

//binary search to get the left and right boundary
using namespace std;
int main()
{
	int N, Q;
	cin >> N >> Q;
	string s;
	cin >> s;
	vector<char> t(Q);
	vector<char> d(Q);
	for(int i = 0; i < Q; i += 1)
	{
		cin >> t[i] >> d[i];
	}

	int L = -1;
	int left = 0, right = N - 1;
	while(left <= right)
	{
		int mid = (left + right) >> 1;
		int inx = mid;
		for(int i = 0; i < Q; i += 1)
		{
			if(s[inx] == t[i])
			{
				if(d[i] == 'L')
					inx -= 1;
				else
					inx += 1;
			}
			if(inx < 0 || inx > N - 1) break;
		}

		if(inx < 0)
		{
			L = mid;
			left = mid + 1;
		}
		else
			right = mid - 1;
	}

	int R = N; 
	left = 0, right = N - 1;
	while(left <= right)
	{
		int mid = (left + right) >> 1;
		int inx = mid;
		for(int i = 0; i < Q; i += 1)
		{
			if(s[inx] == t[i])
			{
				if(d[i] == 'R')
					inx += 1;
				else
					inx -= 1;
			}
			if(inx < 0 || inx > N - 1) break;
		}

		if(inx > N - 1)
		{
			R = mid;
			right = mid - 1;
		}
		else
			left = mid + 1;
	}

	std::cout << std::to_string(R - L - 1) << std::endl;

	return 0;
}



Measured memory_bytes: 900
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

#define int long long

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> d(N);
  REP(i, N) cin >> d[i];
  sort(all(d));
  if(d[N / 2] == d[N / 2 - 1]) {
    cout << 0 << endl;
    return 0;
  }
  int ans = d[N / 2] - d[N / 2 - 1];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
mod = 10 ** 9 + 7

memo = {}
def solve(L, R):
    if (L, R) in memo:
        return memo[(L, R)]

    if L > R:
        res = 0
    elif L == 1:
        res = 1 + solve(2, R)
    else:
        res = (
            solve(L // 2, (R - 1) // 2) +
            solve((L + 1) // 2, R // 2) +
            solve((L + 1) // 2, (R - 1) // 2)
        )

    res %= mod
    memo[(L, R)] = res
    return res

L, R = map(int, input().split())
print(solve(L, R) % mod)

Measured memory_bytes: 9188
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

typedef pair<int,int>pi;
typedef vector<int>vi;

const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	char c;cin>>c;
	if (isupper(c)){
		cout<<'A';
	}
	else cout<<'a';
}


Measured memory_bytes: 3564
#include <iostream>
using namespace std;
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	long long ans=0;
	for (int b=k+1;b<=n;b++)
	ans+=n/b*(b-k)+max(n%b-k+1,0);
	if (!k)
	ans-=n;
	printf("%lld",ans);
}

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

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

    int p = 0;
    vector<bool> ans(N + 1, false);
    for (int i = 1; i <= N; i++)
    {
        if (p + i < N)
        {
            p += i;
            ans.at(i) = true;
        }
        else if (p + i >= N)
        {
            ans.at(p + i - N) = false;
            ans.at(i) = true;
            break;
        }
    }

    rep(i, ans.size())
    {
        if (ans.at(i))
        {
            cout << i << endl;
        }
    }

    return 0;
}

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

using namespace std;

const int N = 1234567;

int a[N], d[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  a[n] = a[0];
  int mx = 0;
  for (int i = 0; i < n; i++) {
    d[i] = a[i + 1] - a[i];
    mx = max(mx, d[i]);
  }
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
  }
  int foo = mx;
  for (int i = 0; i < n; i++) {
    if ((foo - d[i]) % n) {
      puts("NO");
      return 0;
    }
  }
  long long bar = n * (long long) (n + 1) / 2;
  long long need = foo * bar;
  long long useless = n * bar;
  if (need > sum || ((sum - need) % useless)) {
    puts("NO");
    return 0;
  }
  puts("YES");
  return 0;
}


Measured memory_bytes: 2688
import copy
a=int(input())
b=int(input())
w=b
d=[0]*3
count=0
c=[int(i) for i in str(b)]
for i in range(a-len(c)):
    c.insert(0,0)
for i in range(0,1000,1):
    for j in range(2,-1,-1):
        d[j]=i%10
        i=i//10#ここまでは「０，０，０」とか
    for x in range(a-2):
        if d[0]==c[x]:
            for y in range(x+1,a-1):
                if d[1]==c[y]:
                    for z in range(y+1,a):
                        if d[2]==c[z]:
                            count+=1
                            break
                    break
            break
print(count)    

Measured memory_bytes: 44412
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] ms = new int[m];
        for (int i = 0; i < n; i++) {
            int k = sc.nextInt();
            for (int j = 0; j < k; j++) {
                int a = sc.nextInt();
                ms[a - 1]++;
            }
        }

        int ans = 0;
        for (int i = 0; i < m; i++) {
            if (ms[i] >= n) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23252
#include <iostream>
#include <list>
#include <string>
#include <algorithm>
using namespace std;
void output(list<int> a);
int main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	
	
	int n;
	int entersuji;
	cin >> n;
	list<int> suji;
	std::string command;
	for(int i=0 ; i < n; i++){
		cin >> command;
		if(command == "insert"){
			cin >> entersuji;
			suji.insert(suji.begin() , entersuji);
		}
		if(command == "delete"){
			cin >> entersuji;
			list<int>::iterator itr = std::find(suji.begin(), suji.end(), entersuji);
			if( itr != suji.end()){
				suji.erase(itr);
				
			}
			
			
		}
		if(command == "deleteLast"){
			suji.pop_back();
		}
	
		if(command == "deleteFirst"){
			suji.pop_front();
		}
	
	}
	
	list<int>::iterator It = suji.begin();
	std::cout << *It;
	for(++It; It !=suji.end() ; ++It ){
		std::cout << " "<< *It;

	}
	cout << endl;
	
	return 0;
}

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

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

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<mint> fact(n + 1, 1);
  for (int i = 0; i < n; i++) fact[i + 1] = fact[i] * (i + 1);

  mint res = 0;

  for (int i = 0; i <= k; i++) {
    int r = n - i - 1;
    res += comb(n - 1, i) * mint(m - 1).pow(r) * m;
  }

  cout << res << endl;

  return 0;
} 

Measured memory_bytes: 11128
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

ll dp[200][2][2][7];

int main(){
  clr(dp,0);
  string s1;
  ll K;
  cin>>s1>>K;
  string s;
  rep(i,0,200-(int)s1.sz){
    s += "0";
  }
  rep(i,0,s1.sz){
    s += s1[i];
  }
  dp[0][0][0][0] = 1;
  rep(i,1,200){
    ll a = s[i]-'0';
    //rep(j,0,2){
      //rep(k,0,2){
        rep(l,0,5){
          rep(m,0,10){
            if(m==a){
              if(m!=0){
                if(l>4)continue;
                dp[i][0][1][l+1] += dp[i-1][0][0][l];
                dp[i][0][1][l+1] += dp[i-1][0][1][l];
                dp[i][1][1][l+1] += dp[i-1][1][0][l];
                dp[i][1][1][l+1] += dp[i-1][1][1][l];
              }
              else{
                dp[i][0][0][l] += dp[i-1][0][0][l];
                dp[i][0][1][l] += dp[i-1][0][1][l];
                dp[i][1][0][l] += dp[i-1][1][0][l];
                dp[i][1][1][l] += dp[i-1][1][1][l];
              }
            }
            if(m<a){
              if(m!=0){
                if(l>4)continue;
                dp[i][1][1][l+1] += dp[i-1][0][0][l];
                dp[i][1][1][l+1] += dp[i-1][0][1][l];
                dp[i][1][1][l+1] += dp[i-1][1][0][l];
                dp[i][1][1][l+1] += dp[i-1][1][1][l];
              }
              else{
                dp[i][1][0][l] += dp[i-1][0][0][l];
                dp[i][1][1][l] += dp[i-1][0][1][l];
                dp[i][1][0][l] += dp[i-1][1][0][l];
                dp[i][1][1][l] += dp[i-1][1][1][l];
              }
            }
            if(m>a){
              if(m!=0){
                if(l>4)continue;
                dp[i][1][1][l+1] += dp[i-1][1][0][l];
                dp[i][1][1][l+1] += dp[i-1][1][1][l];
              }
              else{
                dp[i][0][0][l] += dp[i-1][0][0][l];
                dp[i][0][1][l] += dp[i-1][0][1][l];
                dp[i][1][0][l] += dp[i-1][1][0][l];
                dp[i][1][1][l] += dp[i-1][1][1][l];
              }
            }
          }
        }
      //}
    //}
  }
  cout << dp[199][0][1][K]+dp[199][1][1][K] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define vi vector<int>
#define pii pair<int,int>
#define vpi vector<pair<int,int>>
#define pb push_back
#define F first
#define S second
#define REP(i,a,b) for(ll i = a; i < b; i++)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define bins(v, x) binary_search(v.begin(), v.end(), x)
#define pi 2*acos(0.0)
#define INF 1e6 + 5
const int mod = 1e9 + 7;

ll modExp(ll base, ll exp, ll mod) {
   ll res = 1;
   while (exp > 0) {
    	if (exp % 2 == 1) {
        	res= (res * base) % mod;
		}
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}

ll nCr(ll n,ll k){ 
   ll C[n + 1][k + 1]; 
   
   REP(i,0,n+1){ 
      REP(j,0,min(i,k)+1) {
         if(j==0 || j==i) {
            C[i][j] = 1;  
         } else {
            C[i][j] = C[i-1][j-1] + C[i-1][j]; 
         }
      } 
   }
   return C[n][k]; 
}

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

    bool flag = 1;
    for(int i = a; i <= b; i++) {
        if(i % k == 0) {
            cout << "OK" << "\n";
            flag = 0;
            break;
        }
    }
    if(flag) p1("NG");
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define p pair<int, int>
#define endl '\n'

using namespace std;

const int INF = 1000000001;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m, x;
    cin >> n >> m >> x;
    vector<pair<int, vector<int>>> a(n);
    for (int q = 0; q < n; q++){
        cin >> a[q].first;
        a[q].second.assign(m, 0);
        for (int q1 = 0; q1 < m; q1++){
            cin >> a[q].second[q1];
        }
    }
    int ans = INF;
    for (int q = 0; q < (1 << n); q++){
        int sum1 = 0;
        vector<int> und(m, 0);
        for (int q1 = 0; q1 < n; q1++){
            if ((q >> q1) & 1){
                sum1 += a[q1].first;
                for (int q2 = 0; q2 < m; q2++){
                    und[q2] += a[q1].second[q2];
                }
            }
        }
        bool flag = true;
        for (int q1 = 0; q1 < m; q1++){
            if (und[q1] < x){
                flag = false;
                break;
            }
        }
        if (flag){
            ans = min(ans, sum1);
        }
    }
    if (ans == INF){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3664
# n = int(sys.stdin.readline())
# a, b = map(int, sys.stdin.readline().split())
# c = list(map(int, sys.stdin.readline().split()))
# s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a = 100
# b = 0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋め, 小数点出力桁指定時のときの出力
# 000100-0.987654

import math
import sys
import itertools
import queue

mod = 1000000007

if __name__ == "__main__":
    N, M = map(int, sys.stdin.readline().split())

    broken = [False for _ in range(N + 2)]
    for _ in range(M):
        broken[int(sys.stdin.readline())] = True

    dp = [0 for _ in range(N + 2)]
    dp[N] = 1
    for i in range(0, N)[::-1]:
        if not broken[i]:
            dp[i] = (dp[i + 1] + dp[i + 2]) % mod
    print(dp[0])

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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define int long long
#define mp make_pair

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;

/* main */
signed main(void)
{
    int n, k;
    int num = 1;
    cin >> n >> k;
    rep(i, n)
    {
        if (num < k)
        {
            num <<= 1;
        }
        else
        {
            num += k;
        }
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import defaultdict

def main():
	s = input().strip()
	m = defaultdict(lambda : 0)
	for c in s:
		m[c] += 1
	# print(len(m))
	v = list(m.values())
	if len(m) == 2 and v[0] == 2 and v[1] == 2:
		print('Yes')
	else:
		print('No')


if __name__ == '__main__':
	main()


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 998244353;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	VLL X(5);
	for (LL n = 0; n < 5; n++) {
		cin >> X[n];
		if (X[n] == 0) {
			cout << n+1 << "\n";
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3168
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#include<map>
#include <limits>
# include <iomanip>
#define INF 1000000009;
using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}

int main() {
	vector<int> aho;
	int a = 0, ab;
	cin >> a;
	for (int i = 1; i <= a; i++) {
		cin >> ab;
		if (i % 2 == a%2) {
			aho.insert(aho.begin(), ab);
			
		}
		else {
			aho.push_back(ab);
			
		}
	}
		for (int i = 0; i < aho.size(); i++) {
			if (i != aho.size() - 1) {
				cout << aho[i] << ' ';
			}
			else {
				cout << aho[i] << endl;
				return 0;
			}
		}
	
	return 0;
}

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
int d[400][400];
int d2[400][400];
int v;
void warshall(){
  for(int k=1;k<=v;k++){
    for(int i=1;i<=v;i++){
      for(int j=1;j<=v;j++){
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
}

void warshall2(){
  for(int k=1;k<=v;k++){
    for(int i=1;i<=v;i++){
      for(int j=1;j<=v;j++){
        d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j]);
      }
    }
  }
}

vector<P> edge[400];

signed main(){
  int n,m,l;

  cin >> n >> m >> l;
  v=n;
  REP(i,n+1){
    REP(j,n+1){
      d[i][j] = INF;
      if(i==j) d[i][j] = 0;
    }
  }
  REP(i,m){
    int a1,b1,c1;
    cin >> a1>> b1>> c1;
    edge[a1].pb(P(b1,c1));
    edge[b1].pb(P(a1,c1));
    d[a1][b1]=c1;
    d[b1][a1]=c1;
  }
  warshall();
  REP(i,n+1){
    REP(j,n+1){
      d2[i][j] = INF;
      if(d[i][j] <= l) d2[i][j]=1;
      if(i==j) d2[i][j] = 0;
    }
  }
  warshall2();
  int q;
  cin >> q;
  vector<int> ans2;
  REP(i,q){
    int s1,t1;
    cin >> s1 >> t1;
    if(d2[s1][t1]==INF) cout << -1 << endl;
    else  cout << d2[s1][t1]-1 << endl;
  }
  return 0;
}


Measured memory_bytes: 4736
#include"bits/stdc++.h"
using namespace std;
int main(){
	string x;
	cin>>x;
	map<char,int> y;
	for(auto i:x)
		++y[i];
	bool ch=false;
	for(auto i:y)
		if(i.second>1)
			ch=true;
	cout<<(ch ? "no":"yes");
}

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

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

		BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
		String str="";
		StringTokenizer stk;

		int x_kazu,y_kazu=0;

		try {
			str=bfr.readLine();
			if(str=="") {
				System.exit(0);
			}
			stk=new StringTokenizer(str," ");
			x_kazu=Integer.parseInt(stk.nextToken());
			y_kazu=Integer.parseInt(stk.nextToken());

			int gcm=0;

			for(int i=1; i<=Math.min(x_kazu,y_kazu); i++) {
				if(x_kazu%i==0 && y_kazu%i==0) {
					gcm=i;
				}
			}

			int res=((x_kazu/gcm)+(y_kazu/gcm)-1)*gcm+1;
			System.out.println(res);

		}catch(IOException e) {

		}
	}
}




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

int main(){
  int N;
  cin >> N;
  vector<double> worth(N);
  for(int i=0;i<N;i++){
    cin >> worth[i];
  }
  
  if(N == 2){
    double min1 = *std::min_element(worth.begin(), worth.end());
    //cout << min1 << endl;
    std::vector<double>::iterator minIt1 = std::min_element(worth.begin(), worth.end());;
    int minIndex1 = std::distance(worth.begin(), minIt1);
    worth.erase(worth.begin() + minIndex1);
    
    double min2 = *std::min_element(worth.begin(), worth.end());
    std::vector<double>::iterator minIt2 = std::min_element(worth.begin(), worth.end());
    int minIndex2 = std::distance(worth.begin(), minIt2);
    worth.erase(worth.begin() + minIndex2);
    
    cout << (min1+min2)/2.0 << endl;
  }else{
  
  for(int i=0;i<N-1;i++){
    double min1 = *std::min_element(worth.begin(), worth.end());
    //cout << min1 << endl;
    std::vector<double>::iterator minIt1 = std::min_element(worth.begin(), worth.end());;
    int minIndex1 = std::distance(worth.begin(), minIt1);
    worth.erase(worth.begin() + minIndex1);
    
    double min2 = *std::min_element(worth.begin(), worth.end());
    std::vector<double>::iterator minIt2 = std::min_element(worth.begin(), worth.end());
    int minIndex2 = std::distance(worth.begin(), minIt2);
    worth.erase(worth.begin() + minIndex2);
    
    worth.push_back((min1+min2)/2.0);
  }
    cout << worth[0] << endl;
  }
  
  return 0;
}

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

int main() {
    long long N;
    cin >> N;
    vector<long long> a(N);
    for (long long i = 0; i < N; i++) {
        cin >> a[i];
    }
    long long ans = 0;
    for (long long i = 0; i < N; i++) {
        if (a[a[i] - 1] == i + 1) {
            ans++;
        }
    }

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


Measured memory_bytes: 1024
import sys
input=sys.stdin.readline
n=int(input())
l=input()
q=int(input())
kl=tuple(map(int,input().split()))
for k in kl:
    d=0
    m=0
    dm=0
    ans=0
    for j in range(n):
        if l[j]=='D':
            d+=1
        elif l[j]=='M':
            m+=1
            dm+=d
        elif l[j]=='C':
            ans+=dm
        if j>=k-1:
            if l[j-k+1]=='D':
                dm-=m
                d-=1
            elif l[j-k+1]=='M':
                m-=1
    print(ans)


Measured memory_bytes: 54108
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n];
        for (int i = 0; i < n; i++) x[i] = sc.nextInt();
        int ans = 1000_000;
        for (int p = 1; p <= 100; p++) {
            int cost = 0;
            for (int i = 0; i < n; i++) cost += (x[i] - p) * (x[i] - p);
            ans = Math.min(ans, cost);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int i, N, M, P;

    while(1){
        scanf("%d %d %d", &N, &M, &P);
        if(N == 0){
            break;
        }

        int *X = (int *)malloc(N * sizeof(int));
        double sum = 0;

        for(i = 0; i < N; i++){
            scanf("%d", &X[i]);
            sum += X[i] * 100;
        }

        if(X[M - 1] == 0){
            printf("0\n");
            continue;
        }
        else{
            sum -= sum * P / 100;
            printf("%d\n", (int)(sum / X[M - 1]));
        }
    }
    
    return 0;
}

Measured memory_bytes: 632
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
using namespace std::chrono;
const int N = 1e5+4 , M=N,inf=(int)1e9;
const ll mod=1e9+7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
int ans ;
map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
void solve(){
    int n ;
    cin >> n ;
    string s ;
    cin >> s;
    vector < ll > hash(26,0);
    for( int i = 0 ; i < n ; i++) hash[s[i]-'a']++;
    vector < int > v ;
    for( int i = 0 ; i < 26 ; i++){
        if(hash[i]!=0){
            v.PB(hash[i]);
        }
    }
    n = v.size();
    vector < ll > dp(n,0);
    dp[0] = v[0];
    for( int i = 1 ; i < n  ; i++){
        dp[i] = add(add(multiply(dp[i-1],v[i]),v[i]),dp[i-1]);
    }
    //for( int i = 0 ; i < n ; i++) cout << dp[i] << " " ;
    cout << dp[n-1] << " " ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}


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

int main()
{
	int N;

	cin >> N;

	int num = N;
	int count = 0;

	while (num > 0)
	{
		num = num / 10;
		count++; //count桁
	}

	int ans = 0;

	if (count % 2 == 0)
	{
		while (count >= 0)
		{
			if (count % 2 == 1)
			{
				ans += 9 * pow(10, count - 1);
			}
			count--;
		}
	}
	else
	{
		int buf = N - pow(10, count - 1) + 1;

		count = count - 1;

		while (count > 0)
		{
			if (count % 2 == 1)
			{
				ans += 9 * pow(10, count - 1);
			}
			count--;
		}

		ans += buf;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 1;

void solve() {
    ll n; cin >> n;
    map<string, ll> mp;
    for(int i = 0; i < n; ++i){
        string s; cin >> s;
        ++mp[s];
    }
    ll M = 0;
    for(auto it : mp){
        M = max(M, it.second);
    }
    for(auto it : mp){
        if(it.second != M) continue;
        cout << it.first << endl;
    }

}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 25344
"""
自分で触ってみる    index調整の[0]をなくしてみた
                  numpy部分を分解してコメントつけた
参考
https://harutech.hateblo.jp/entry/2019/02/10/202515
PSゲーマーが惰性で競プロをするブログ    2019-02-10 
"""
import numpy as np

n, k = map(int, input().split())
h = np.array( list(map(int, input().split()))) # index調整なくしてみた
dp = np.zeros(n,dtype=np.int)


for i in range(1,n): # i:今いる足場
    start = max(0,i-k) #前の足場で一番遠い
    asiba_befor = dp[start:i] #飛ぶ前の足場での累計コスト
    jump_now = np.abs(h[i] - h[start:i]) #今回飛んだコスト
    dp[i] = min(asiba_befor + jump_now ) #最後の足場にいたときの累計コスト⇒最小値が答え
  
print(dp[n-1])

Measured memory_bytes: 22908
#include<bits//stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int c[a],d[b],e[a];
    for(int i=0;i<a;i++){
		e[i]=0;
	}
    for(int i=0;i<a;i++)
    {
        cin>>c[i];
    }
    for(int i=0;i<b;i++){
        cin>>d[i];
    }
    for(int j=0;j<b;j++){
        for(int i=0;i<a;i++){   
            if(c[i]<=d[j]){
                e[i]++;
                goto stop;
            }
        }
        stop:;
    }
    int f=0;
    int g=0;
    for(int i=0;i<a;i++){
		if(f<e[i]){
			f=e[i];
			g=i+1;
		}
	}
    cout<<g<<endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> an(n);
  for(int i=0; i<n; ++i) cin >> an[i];
  ll m1 = 1000;
  ll k = m1 / an[0], m2 = m1 - k * an[0];
  for(int i=1; i<n; ++i){
    if(an[i-1] < an[i]){
      m1 = m2 + k * an[i];
    }else{
      k = m1 / an[i];
      m2 = m1 - k * an[i];
    }
  }
  cout << m1 << endl;
}

Measured memory_bytes: 3624
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <boost/xpressive/xpressive_static.hpp>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;
using namespace boost::xpressive;

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

  const ll N = S.size();
  const sregex re = (s1 = +lower) >> s1;
  for (ll i = 1; i < N; i++) {
    const auto ss = S.substr(0, N - i);
    if (regex_match(ss, re)) {
      cout << ss.length() << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3740
#include<stdio.h>
#define N 100000

int A[N];
int Partition(int A[],int p,int r);

int main(){

  int i,j,n,a;

  scanf("%d",&n);

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

  a=Partition(A,0,n-1);
  for(i=0;i<a;i++){
    printf("%d ",A[i]);
  }

  printf("[%d] ",A[a]);

  for(i=a+1;i<n;i++){
    printf("%d",A[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n");
  return 0;
}


int Partition(int A[],int p,int r){
  int x,i,j,n;
  x=A[r];
  i=p-1;
  for(j=p;j<=r-1;j++){
    if(x>=A[j]){
      i=i+1;
      n=A[j];
      A[j]=A[i];
      A[i]=n;
    }
  }
  n=A[r];
  A[r]=A[i+1];
  A[i+1]=n;
  return i+1;
}

Measured memory_bytes: 992
n = gets.chomp.to_i

dams = gets.chomp.split(" ").map(&:to_i)
total = dams.inject(:+)

ans = Array.new(n, 0)
temp_total = 0
n.times do |i|
    next if i % 2 == 0
    temp_total += dams[i]
end
ans[0] = total - 2 * temp_total
(n - 1).times do |i|
    ans[i + 1] = 2 * dams[i] - ans[i]
end

puts ans.join(" ")


Measured memory_bytes: 15108
#include<stdio.h>
#include<stdlib.h>
#define PI 3.141592653589793238
int main()
{ double r,a,c;
    scanf("%lf",&r);
    a=r*r*PI;
    c=2.00000*r*PI;
    printf("%lf %lf",a,c);
    return 0;
    
}



Measured memory_bytes: 2112
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define maxn 520
using namespace std;
int n,mod,ans,f[maxn][maxn];
struct point{
	int l,r,num,pos;
	friend bool operator <(point a,point b)
	{
		return a.pos<b.pos;
	}
}a[maxn];
int main()
{
	scanf("%d%d",&n,&mod);
	for(int i=0;i<2*n;i++)
	{
		a[i].num=i; a[i].r=min(2*n-1,(int)floor(sqrt(4*n*n-i*i)));
		if(i<n) a[i].l=ceil(sqrt(n*n-i*i)),a[i].pos=a[i].l-1;
		else a[i].pos=a[i].r;
	}
	sort(a,a+2*n);
	int ans=0;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=2*n;j++)
			for(int k=0;k<=2*n;k++) f[j][k]=0;
		f[0][0]=1; int c1=0;
		for(int j=0;j<2*n;j++)
		{
			c1+=(a[j].num<n);
			for(int k=0;k<=min(c1,i);k++)
				if(a[j].num<n){
					f[j+1][k]=(f[j+1][k]+1ll*f[j][k]*(a[j].r+1-(2*n-1-a[j].num+i-k)))%mod;
					f[j+1][k+1]=(f[j+1][k+1]+1ll*f[j][k]*(a[j].pos+1-(j-(c1-k-1))))%mod;
				}
				else f[j+1][k]=1ll*f[j][k]*(a[j].pos+1-(j-(c1-k)))%mod;
		}
		if(i&1) ans=(0ll+ans-f[2*n][i]+mod)%mod;
		else ans=(ans+f[2*n][i])%mod;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 4768
//Kyokai no Kanata //
#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector< VI > VVI;
typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
  const char* comma=strchr(names+1,',');
  cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...)
#endif
#define M(x) ((x)%mm)
const int mm = (int)1e9 +7;
string s[2];
int isver(int p){
  return s[1][p] == s[0][p];
}
int main()
{
  int n,st;si(n);
  cin >> s[0] >> s[1];
  LL ans;
  if(isver(0)) ans=3,st=1;
  else ans=6,st=2;
  for(int i=st;i<n;){
    if(isver(i)){
     if(isver(i-1))ans=M(ans*2);
     i+=1;
    }else {
      if(isver(i-1)) ans=M(ans*2);
      else ans=M(ans*3);
      i+=2;
    }
  }
  lldout(ans);
  return 0;
}



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

const int INF = 1000000000;
int main() {
    int N, M;
    cin >> N >> M;
    vector<int> req(N + 1, INF);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        req[a] = min(req[a], b);
    }

    int ans = 0, right = 0;
    for (int i = 1; i <= N; i++) {
        if (req[i] != INF) {
            if (i >= right) {
                ans++;
                right = req[i];
            } else {
                right = min(right, req[i]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

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


Measured memory_bytes: 1664
#include<stdio.h>
#include<string.h>
char ha[1<<21],k[256];
int main(int argc,char *argv[]){
  int i,flg;
  int val,s,t;
  char c;
  k['T'] = 1;
  k['G'] = 2;
  k['C'] = 3;
  k['A'] = 4;
  
  scanf("%d", &val);
  getchar();
  for(i=0;i<val;i++){
    s = 0;
    t = 1;
    flg = ( c = getchar() ) == 'i';
    while ( ( c = getchar() ) != ' ' );
    while ( ( c = k[getchar()] ) != 0 ) {
      s += c * t;
      t *= 4;
    }
    if (flg) ha[s] = 1; else puts( ha[s] ? "yes" : "no" );
  }
  return 0;
}

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

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

  bool flag = false;

  for(int i = a; i < 10000; i += a){
    if(i % b == c){
      flag = true;
      break;
    }
  }

  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;

}


Measured memory_bytes: 256
I = input().split()
A, B = [int(i) for i in I]

cnt = 0
for i in range(A, B + 1):
    s = str(i)
    l = 0
    r = len(s) - 1
    while l < r and s[l] == s[r]:
        l += 1
        r -= 1
    if l >= r:
        cnt += 1
print(cnt)


Measured memory_bytes: 8900