akhauriyash/Code-Regression huggingface dataset:
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

bool solve() {

	
	int n;
	cin >> n;
	vector<pair<int, int>> v(n + 1);
	v[0].first = 0; v[0].second = 0;
	for (int i = 1; i <= n; i++) {
		int t;
		cin >> t;
		v.push_back(make_pair(t, i));
	}
	
	sort(v.rbegin(), v.rend());

	for (int i = 1; i <= n; i++) {
		if (v[0].second == i) {
			cout << v[1].first << endl;
		} else {
			cout << v[0].first << endl;
		}
	}


	return true;
}

signed main() {
	solve();

	return 0;
}

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

bool isMonth(int);

int main(){
  int a;
  cin >> a;
  int f=a/100,e=a%100;
  if (isMonth(f)){
    if (isMonth(e)){
      cout << "AMBIGUOUS" << endl;
    } else {
      cout << "MMYY" << endl;
    }
  } else {
    if (isMonth(e)){
      cout << "YYMM" << endl;
    } else {
      cout << "NA" << endl;
    }
  }
}

bool isMonth(int a){
  if (a < 1 || a>12) return false;
  return true;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n;cin>>n;
  string s;cin>>s;
  set<char> t;
  rep(i,n){
  	t.insert(s[i]);
  }
  ll ans=0,temp=0;
  rep(i,n){
  	set<char> l,r;
  	rep(j,i+1){
  		l.insert(s[j]);
  	}
  	FOR(j,i+1,n){
  	  r.insert(s[j]);
  	}
  	temp=0;
  	reps(x,t){
  		if(l.count(x)&&r.count(x)){
  			temp++;
  		}
  	}
  	ans=max(ans,temp);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
 
const int inf = (int)1e9; 
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

ll n,k;
vector<ll>a(n);

bool check(ll x){
    ll t = 0;
    if(x==0){
        return false;
    }
    for(int i=0;i<n;i++){
        if(a[i]%x==0)t+=a[i]/x-1;
        else t+=a[i]/x;
    }
    return (t<=k);
}

int main(void){
	n,k;
    cin>>n>>k;
    a.resize(n);
    ll ng = -1,ok = 0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        ok = max(ok,a[i]);
    }
    while(ok-ng>1){
        ll mid = (ok+ng)/2;
        if(check(mid))ok = mid;
        else ng = mid;
    }
    cout<<ok<<endl;
	return 0;
}

Measured memory_bytes: 4732
#D問題
N = int(input())
work_list =[]
for i in range(N):
    A,B = map(int,input().split())
    work_list.append([A, B])
work_list.sort(key=lambda x:x[1])
count = 0
ans = "Yes"
for i in range(N):
    count = work_list[i][0]+count
    if count > work_list[i][1]:
        ans = "No"
        break;
print(ans)

Measured memory_bytes: 38056
// https://github.com/PabloMessina/Competitive-Programming-Material/blob/master/Codejam_template.cpp
#pragma GCC optimize("Ofast") // OPTIONAL: for faster execution
#include <bits/stdc++.h>      // import everything in one shot
using namespace std;
// defines
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define invrep(i, a, b) for (int i = b - 1; i >= a; --i)
#define umap unordered_map
#define uset unordered_set
// typedefs
typedef unsigned int uint;
typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
// -------------------------------

int main()
{
    // OPTIONAL: for faster input/output (only if using cin/cout)
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int N;
    cin >> N;
    string words[N], tmp;
    rep(i, 0, N)
    {
        cin >> tmp;
        sort(tmp.begin(), tmp.end());
        words[i] = tmp;
    }
    sort(words, words + N);
    // rep(i, 0, N)
    // {
    //     cout << words[i] << endl;
    // }
    ll c = 1;
    ll ans = 0;
    rep(i, 1, N)
    {
        if (words[i] == words[i - 1])
            c++;
        else
        {
            ans += c * (c - 1) / 2;
            c = 1;
        }
    }
    ans += c * (c - 1) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n) 
{ v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i]; }
template<class T, class U> void read_n(vector<pair<T, U>>& v, size_t n)
{ v = vector<pair<T, U>>(n); 
  for (lli i=0; i<n; ++i) cin >> v[i].first >> v[i].second; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

struct P { lli x, y, d; 
  P(lli x, lli y, lli d) : x(x), y(y), d(d) {}
};

lli n;
vector<string> s;
char ini[5] = { 'M', 'A', 'R', 'C', 'H' };
lli cnt[256];
int main() {
  cin >> n; read_n(s, n);
  fill(cnt, cnt+256, 0);
  for (auto&& t : s) {
    cnt[t[0]]++;
  }
  lli ans = 0;
  for (lli i=0; i<5; ++i) {
    for (lli j=i+1; j<5; ++j) {
      for (lli k=j+1; k<5; ++k) {
	ans += cnt[ini[i]] * cnt[ini[j]] * cnt[ini[k]];
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  string s[n];
  rep(i,n){
    cin>>s[i];
    sort(s[i].begin(),s[i].end());
  }
  sort(s,s+n);
  int ans=0;
  int now=0;
  rep(i,n-1){
    if(s[i]==s[i+1]){now++;ans+=now;}
    else now=0;
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    double answer = v[0];
    for (int i = 1;i < n; ++i) {
        answer = (answer + v[i]) / 2.0;
    }
    cout << setprecision(9) << answer << endl;
}


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

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

int main() {
    cin >> n >> s;
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++){
        cin >> a;
        for (int j = 0; j <= s; j++){
            dp[i][j] = dp[i-1][j]*2;
            dp[i][j] %= mod;
            if (j >= a){
                dp[i][j] += dp[i-1][j-a];
                dp[i][j] %= mod;
            }
        }
    }
    cout << dp[n][s] << "\n";
}


Measured memory_bytes: 74016
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct card{char suit;int value;};



int main(){
 
  struct card C1[100],C2[100];
  struct card t;
  char buf[3];
  char temp[2];
  int i,j,a=0;
  int N;
  char ch;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%s",buf);
    temp[1]='\0';
    memcpy(temp,&buf[0],1);
    C1[i].suit=temp[0];
    memcpy(temp,&buf[1],1);
    C1[i].value=atoi(temp);
 
    
  }
  for( i=0;i<N;i++)
    C2[i]=C1[i];

  for( i=0;i<N;i++){
    for( j=N-1;j>=i+1;j--){
      if(C1[j].value<C1[j-1].value){
	 t=C1[j];
	C1[j]=C1[j-1];
	C1[j-1]=t;

      }}}




for(i=0;i<N;i++){
  int min=i;
  for(j=i;j<N;j++){
    if(C2[j].value<C2[min].value)
      min=j;}
  t=C2[i];
  C2[i]=C2[min];
  C2[min]=t;
 }


 
  
  for( i=0;i<N;i++){
    if(i>0)
      printf(" ");
    printf("%c%d",C1[i].suit,C1[i].value);
  }
  printf("\n");
  printf("Stable\n");


  for( i=0;i<N;i++){
    if(i>0)
      printf(" ");
    printf("%c%d",C2[i].suit,C2[i].value);
  }
  printf("\n");
  for( i=0;i<N;i++){
    if(C1[i].suit!=C2[i].suit){
      a=0;
      break;}
      a=1;}
    
  if(a==1)
    printf("Stable\n");
  
  else
    printf("Not stable\n");

  return 0;}
    



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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
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; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int a, b, k;
    cin >> a >> b >> k;
    if (k <= a)
        print(a - k, b);
    else if (k <= a + b)
        print(0, b - (k - a));
    else
        print(0, 0);

    return 0;
}


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

void program(); 
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    program();
}

#define INF 0x7fffffffffffffff
#define UINF 0xffffffffffffffff
#define MOD 1000000007

#define int long long
#define unsigned unsigned long long
#define double long double

#define endl "\n"

int pow(int a, int b, int m) {
    a %= m;
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

class UF{
public:
    int n;
    vector<int> par, sz;
    UF(int size) : n(size), par(size), sz(size){
        for(int i=0; i<n; i++){
            par[i] = i;
            sz[i] = 1;
        }
    }
    void join(int x, int y){
        if ((x = find(x)) == (y = find(y))) return;
        if (sz[y] < sz[x]) std::swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        sz[x] = 0;
    }
    int find(int x){ return par[x] = (x == par[x] ? x : find(par[x])); }
    bool connected(int x, int y){ return find(x) == find(y); }
};

template<class Iter> void _print_range(ostream& o, Iter s, Iter e){
    for(;s != e;s++) o << *s << " ";
} 
template<class T> std::ostream& operator<<(ostream& o, const std::vector<T> &ds)
{
    _print_range(o,ds.begin(),ds.end()); 
    return o;
}
template<class T> std::ostream& operator<<(ostream& o, const std::set<T> &ds)
{
    _print_range(o,ds.begin(),ds.end()); 
    return o;
}
template<class T, class U> std::ostream& operator<<(ostream& o, const std::pair<T,U> &ds)
{
    o << "<" << ds.first << "," << ds.second << ">" << endl;
    return o;
}
template<typename ...Args>
void print(Args&&... args) {
    for(auto&& x: {args...})
        cout << x << " ";
    cout << endl;
}

#define debug(x) cout << "DEBUG    " <<  #x << ": " << x << endl;

#define fr(i, a, b) for(int i = a; i != (b); i += (a<b ? 1 : -1))
#define rep(i, a) for(decltype(a) i = 0; i < (a); i++)

#define trav(x, a) for(auto& x : a)
#define all(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define vi vector<int>
#define si set<int>
#define pii pair<int,int>

#define N 100005
#define M 105
int dp[N], w[M], v[M]; 
void program(){
    rep(i,N) dp[i] = INF;
    dp[0] = 0;
    int n, W;
    cin>>n>>W;
    rep(i,n) cin>>w[i]>>v[i];
    for(int j=0;j<n;j++)
        for(int i=N-1; i>=0; i--)
            if(i-v[j]>=0 && dp[i-v[j]] != INF)
                dp[i] = min(dp[i], dp[i-v[j]]+w[j]);
    int mx=0;
    for(int i=0; i<N; i++) if(dp[i]<=W)
        mx = max(mx, i);
    cout << mx << endl;
}

/*
WA:
-bounds on loops
-truncating
-intialization
-0 vs 1 indexing

TLE:
-might need unordered_set/map
-infinite while loop

Stuck:
-bruteforce?
-reduce dimensionality with problem contraints?
*/


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
template<typename T> bool chmax(T &a, T b) {if(a <= b){a = b; return true;}return false;}
template<typename T> bool chmin(T &a, T b) {if(a >= b){a = b; return true;}return false;}


int main(void){
    int a[5];
    rep(i,5)cin >> a[i];
    int n;
    rep(i, 5){
        if(a[i] == 0){
            if(i != 0){
                cout << a[i-1] + 1 << endl;
                return 0;
            }else{
                cout << a[i+1] - 1 << endl;
                return 0;
            }
        }
    }
}

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

using namespace std;

int main(){
    long n;
    scanf("%ld", &n);
    if(n % 2 == 1 || n == 0){
        printf("%d", 0);
    } else {
        long nCount = 0;
        nCount += n / 10;
        n /= 10;
        while(n >= 5){
            nCount += n / 5;
            n /= 5;
        }
        printf("%ld",nCount);
    }
    
    
    return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define trace(x) clog<<#x<<": "<<x<<endl
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define pb push_back
#define mod 1000000007
#define vi vector<int>
#define si set<int>
#define pi pair<int,int>
#define li list<int>
#define fi first
#define in insert
#define se second
#define mkp make_pair
#define fr(i,n) for(i = 0 ; i < n ; i++)
#define  test int t; cin>>t; while(t--)
vector<vector<int> >adj;
vector<int> vis;
vector<int> indegree;
vector<int> dp;
void dfs(int root)
{
    vis[root] = 1;
   // cout<<"\nroot = "<<root;
    for(int i = 0 ; i < adj[root].size() ; i++)
    {
        int v = adj[root][i];
        indegree[v]--;
        dp[v] = max(dp[v],dp[root]+1);
        if(indegree[v] == 0 && !vis[v])
            {
                dfs(v);
            }
    }
}

int main()
{
    fio
    int n,m,i,j,k,x,y;
    cin>>n>>m;
    indegree.resize(n+1);
    dp.resize(n+1);
    adj.resize(n+1);
vis.resize(n+1);
    fr(i,m)
    {
        cin>>x>>y;
        adj[x].pb(y);
        indegree[y]++;
    }

    for(i = 1; i <= n; i++)
    {
        if(indegree[i]==0 && vis[i]==0)
            {dp[i] = 0;
            dfs(i);}
    }
//for(i = 1; i <= n; i++)
  //  cout<<dp[i]<<" ";
//cout<<"\nMAX = ";
    cout<<*max_element(dp.begin(),dp.end());
return 0;
}



Measured memory_bytes: 9984
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 100000
 
int main()
{
    vector<int> p;
    bool prime[MAX];
    fill(prime, prime + MAX, 1);
    prime[0] = prime[1] = 0;
    for (int i = 2; i < MAX; i++) {
        if (prime[i]) {
            p.push_back(i);
            for (int j = 2*i; j < MAX; j += i) {
                prime[j] = 0;
            }
        }
    }
 
    int N;
    while (cin >> N) {
        cout << *(lower_bound(p.begin(), p.end(), N) - 1) << " " <<
                *upper_bound(p.begin(), p.end(), N) << endl;
    }
    return 0;
}

Measured memory_bytes: 3360
#include<bits/stdc++.h>
//using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb emplace_back
#define mp std::make_pair
//
#define endl "\n"
//using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
//
constexpr ll MOD=1e9+7;
//constexpr ll MOD=998244353;
//constexpr ll MOD=10000000;
//constexpr ll MOD=1e5;
constexpr ll MAX=1e7;
constexpr ll INF=(1ll<<62);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
const ll N=26;
ll solve(ll D,vii &A,vi &C,vi &S){
    vi last(N,-1);
    ll a=0;
    rep(i,0,D){
        ll memo; memo=S[i];
        last[memo]=i;
        a+=A[i][memo];
        rep(j,0,N) a-=(i-last[j])*C[j];
    }
    return a;
}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    srand((unsigned)time(NULL));
    ll D; cin>>D;
    vi C(N);
    rep(i,0,N) cin>>C[i];
    vii A(D,vi(N));
    rep(i,0,D){
        rep(j,0,N) cin>>A[i][j];
    }
    vi last(N,-1);
    vi ans(D);
    rep(i,0,D){
        ll max=0,memo=0;
        rep(j,0,N){
            if(max<A[i][j]+(i-last[j])*C[j]){
                max=A[i][j]+(i-last[j])*C[j];
                memo=j;
            }
        }
        last[memo]=i;
        ans[i]=memo;
    }
    ll max=solve(D,A,C,ans);
    rep(i,0,D){
        rep(j,0,N){
            vi S=ans;
            S[i]=j;
            ll X=solve(D,A,C,S);
            if(max<X){
                max=X;
                ans=S;
            }
        }
    }
    rep(i,0,D) cout<<ans[i]+1<<endl;
}


Measured memory_bytes: 3760
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		
		outside: for (int i = n;; i++) {
			for (int j = 2; j < i; j++) {
				if (i % j == 0) {
					continue outside;
				}
			}
			System.out.println(i);
			break;
		}
		
		
	}
}


Measured memory_bytes: 23764
str = gets.split
N,K = str[0].to_i, str[1].to_i
a = Array.new(N)
sum = 0
str = gets.split
for i in 0...N do
    a[i] = str[i].to_i
    sum += a[i]
end
b = Array.new(0)

x = 1
l = 0
r = 0
ll = Array.new(0)
rr = Array.new(0)
c = 0
y = 0
z = 0
while sum/x >= x
    if sum % x == 0
        y = sum/x
        if x != y
            b.push(x) 
        end
        l = 0
        r = 0
        ll.clear
        rr.clear
        for i in 0...N do
            z = a[i] % y
            if z*2 == y
                c += 1
            elsif z*2 < y
                l += z
                ll.push(y-z)
            else
                r += (y-z)
                rr.push(z)
            end
        end
        while c > 0
            if l < r
                l += y/2
            else
                r += y/2
            end
            c -= 1
        end
        z = (l-r).abs/y
        if l>r
            ll.sort!
            ll.reverse!
            while z > 0
                r += ll.pop
                z -= 1
            end
        else
            rr.sort!
            rr.reverse!
            while z > 0
                l += rr.pop
                z -= 1
            end
        end
        if l<=K || r<=K
            puts y
            exit
        end
    end
    x += 1
end

while !b.empty?
    y = b.pop
    l = 0
    r = 0
    ll.clear
    rr.clear
    for i in 0...N do
    z = a[i] % y
        if z*2 == y
            c += 1
        elsif z*2 < y
            l += z
            ll.push(y-z)
        else
            r += (y-z)
            rr.push(z)
        end
    end
    while c > 0
        if l < r
            l += y/2
        else
            r += y/2
        end
        c -= 1
    end
    z = (l-r).abs/y
    if l>r
        ll.sort!
        ll.reverse!
        while z > 0
            r += ll.pop
            z -= 1
        end
    else
        rr.sort!
        rr.reverse!
        while z > 0
            l += rr.pop
            z -= 1
        end
    end
    if l<=K || r<=K
        puts y
        exit
    end
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
using std :: vector;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

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

  if(a - b == 0){
    cout << "Yes" << endl;


  }else{
    cout << "No" << endl;
  }
    return 0;
      
    

    
    }




Measured memory_bytes: 256
N, K = gets.split(' ').map(&:to_i)
A = gets.split(' ').map(&:to_i)

require 'pp'
def debug obj
  # PP.pp obj, STDERR
end
debug [N,K]
debug A
sum = 0
sumA = A.map{|a| sum += a }
bt_list = []

(0..(N)).to_a.combination(2) do |l,r|
  bt_list.push(((sumA[r] || 0) - sumA[l]).abs)
end

bt_list.sort!.reverse!
debug bt_list

r = 0

max = sumA.last

maxlog = Math.log2(max).to_i
maxlog.downto(0) do |i|
  count = 0
  ra = r + (1 << i)
  bt_list.each_with_index do |bt, j|
    if ra == ( ra & bt )
      count += 1
      if count >= K
        r = ra
        break
      end
    end
    if (bt_list.size - j -1) < K - count
      break
    end
  end
end

puts r

Measured memory_bytes: 11568
#include<cstdio>
#include<algorithm>

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

using namespace std;

typedef long long ll;

const ll M=100000007;

const int N_BIN=3000;
ll nCr[N_BIN+1][N_BIN+1];
void binom(){
	rep(n,N_BIN+1) nCr[n][0]=1;
	rep(n,N_BIN) rep(r,n+1) nCr[n+1][r+1]=(nCr[n][r+1]+nCr[n][r])%M;
}

int main(){
	binom();

	int h,w,a1,a2,b1,b2; scanf("%d%d%d%d%d%d",&h,&w,&a1,&a2,&b1,&b2);

	int y=min(abs(b1-a1),h-abs(b1-a1));
	int x=min(abs(b2-a2),w-abs(b2-a2));

	ll coef=1;
	if(abs(b1-a1)==h-abs(b1-a1)) coef*=2;
	if(abs(b2-a2)==w-abs(b2-a2)) coef*=2;
	printf("%lld\n",coef*nCr[x+y][y]%M);

	return 0;
}

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

using namespace std;
using LL = long long int;
const LL mod = 1000000007;

#define int long long

const int MAX_H = 2005;
const int MAX_W = 2005;
int H, W;
char C[MAX_H][MAX_W];

struct Rect{
    int height, pos;
};

int HMap[MAX_H][MAX_W];

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

int counter(int x, int y)
{
    int ret = 0;
    for(int d = 0; d < 4; d++) {
        int nx = x + dx[d];
        int ny = y + dy[d];
        if(C[ny][nx] == '#') {
            ret++;
        }
    }
    return ret;
}

signed main()
{
    cin >> H >> W;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> C[i][j];
        }
    }

    for(int x = 0; x < W; x++) {
        int h = 1;
        for(int y = 0; y < H; y++) {
            if(x == W-1) {
                HMap[y][x] = y+1;
            } else {
                if(y == 0) {
                    h = 1;
                } else {
                    if(counter(x+1, y)%2 == 0) {
                        h++;
                    } else {
                        h = 1;
                    }
                }
                HMap[y][x] = h;
            }
        }
    }

    // for(int y = 0; y < H; y++) {
    //     for(int x = 0; x < W; x++) {
    //         cerr << HMap[y][x] << " ";
    //     }
    //     cerr << endl;
    // }

    int ans = max(H,W);

    for(int y = 0; y < H; y++) {
        stack<Rect> S;
        for(int x = 0; x < W; x++) {
            Rect rect; rect.pos = x; rect.height = HMap[y][x];
            if(S.empty()){
                S.push(rect);
            } else if(S.top().height <= rect.height) {
                S.push(rect);
            } else { //長方形最大値を求める
                while(S.size() > 0) {
                    Rect r = S.top(); 
                    if(r.height > rect.height) {
                        S.pop();
                        ans = max(ans, r.height * (x-r.pos+1));
                        rect.pos = r.pos;
                    } else {
                        break;
                    }
                }
                S.push(rect);
            }
        }
        while(S.size() > 0) {
            Rect r = S.top(); 
            S.pop();
            ans = max(ans, r.height * (W-r.pos));
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 35584
def main() :
    X = int(input())
    testing_number = X
    while(True) :
        is_prime = True
        while(True) :
            for i in range(2,testing_number) :
                if (testing_number % i == 0) :
                    is_prime = False
                    testing_number += 1
                    break
            break

        if(is_prime) :
            break

    print(testing_number)

main()

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

#define int long long

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
template<typename T>bool maxup(T& a, T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

map<int, int> mp;
void soin(int n) {
	for (int i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) {
		mp[n]++;
	}
}
const int mod = 1000000007;
signed main() {
	int n; cin >> n;
	rep(i, 2, n + 1) {
		soin(i);
	}
	int ans = 1;
	for (P p : mp) {
		int x = p.second;
		ans = (ans * (x + 1)) % mod;
	}
	cout << ans << endl;
	system("pause");
}

Measured memory_bytes: 504
import bisect
import sys
from collections import defaultdict
N,M=map(int,input().split())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
dd=defaultdict(int)
for a in A:
    dd[a]+=1
for b in B:
    dd[b]+=1
for d,n in dd.items():
    if n>=3:
        print(0)
        sys.exit()
A=sorted(A)
B=sorted(B)
ans=1
mod=10**9+7
for i in range(N*M,0,-1):
    x=bisect.bisect_left(A,i)
    y=bisect.bisect_left(B,i)
    if x>=N or y>=M:
        print(0)
        sys.exit()
    if A[x]==i and B[y]==i:
        #print(i)
        continue
    elif A[x]==i:
        ans*=(M-y)
        ans%=mod
    elif B[y]==i:
        ans*=(N-x)
        ans%=mod
    else:
        ans*=((N-x)*(M-y)-(N*M-i))
        ans%=mod
    #print(x,y,i,ans)
print(ans)

Measured memory_bytes: 43372
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
//#define all(v) v.begin(), v.end()
//bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
//bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
//const ll MAX_N=500010;
ll a, b, c, d, e, f, h, k, l, m, n, p, q, r, t, w, x, y, z, ans;
int main() {
  string S, A="", B="";
  char s;
  cin >> S >> q;
  a=0;
  rep(i, q) {
    cin >> t;
    if(t == 1) a++;
    else if(t == 2) {
      cin >> f >> s;
      if ((f==1 && a%2==1)||(f==2 && a%2==0)) {
        A = A+s;
      }else{
        B = B+s;
      }
    }
  }
  S += A;
  reverse(S.begin(), S.end());
  S += B;
  if(a%2==0) reverse(S.begin(), S.end());
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 1752
import math
from collections import defaultdict

N=input()

C=defaultdict(lambda: 0)

#L=(2,3,5,7)
L=range(2,101)


for i in range(N,0,-1):
	for l in L:
		while i%l==0:
			i/=l
			C[l]+=1

D=defaultdict(lambda: 0)

for x,y in C.items():
	if y>=4:	D[4]+=1
	if y>=2:	D[2]+=1
	if y>=24:D[24]+=1
	if y>=14:D[14]+=1
	if y>=74:D[74]+=1

ans=0

ans+=D[4]*(D[4]-1)/2*(D[2]-2)
ans+=D[24]*(D[2]-1)
ans+=D[14]*(D[4]-1)
ans+=D[74]
print ans


Measured memory_bytes: 29292
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    lint N,M,K;
    cin >> N >> M >> K;
    bool ans=false;
    for(int i=0;i<=N;i++) for(int j=0;j<=M;j++){
        lint num=(i*M)+(j*N)-i*j*2;
        if(num==K) ans=true;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3532
import java.util.*;

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

        int n = scanner.nextInt();

        int[] arr = new int[n];

        for (int i = 0; i < n; ++i) {
            arr[i] = scanner.nextInt();
        }

        boolean flag = true;
        int swapCnt = 0;
        while (flag) {
            flag = false;
            for (int i = n - 1; i > 0; --i) {
                if (arr[i] < arr[i - 1]) {
                    int tmp = arr[i];
                    arr[i] = arr[i - 1];
                    arr[i - 1] = tmp;

                    flag = true;
                    ++swapCnt;
                }
            }
        }

        for (int i = 0; i < n; ++i) {
            System.out.printf("%d%s", arr[i], i == n - 1 ? "" : " ");
        }
        System.out.println();
        System.out.println(swapCnt);
    }
}



Measured memory_bytes: 26488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int M = 1e9;
const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 21;
char dn[dm], *di = dn;

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


	int N = getint();
	int A[500001];
	*A = getint();
	int d[500000];
	rep(i, N) {
		*(d + i) = getint();
		int ab = *(d + i) - *(A + i);
		if(*(A + i) >= *(d + i)) *(A + i + 1) = -ab;
		else if (*(A + i) >= ab) *(A + i + 1) = ab;
		else *(A + i + 1) = *(A + i);
	}
	int B[500000];
	*(B + N - 1) = 1;
	for(int i = N - 1; i >= 1; i--) {
		if (*(B + i) >= M || *(B + i) * 2 <= *(d + i)) *(B + i - 1) = *(B + i);
		else *(B + i - 1) = *(B + i) + *(d + i);
	}
	int Q = getint();
	char n[3] = { 'N', 'O', '\n' };
	char y[4] = { 'Y', 'E', 'S', '\n' };
	rep(i, Q) {
		int q = getint() - 1;
		if (*(A + q) < *(B + q)) {
			memcpy(di, n, 3);
			di += 3;
		}
		else {
			memcpy(di, y, 4);
			di += 4;
		}
	}

	fwrite_unlocked(dn, di - dn, 1, stdout);
	
	Would you please return 0;
}

Measured memory_bytes: 9600
import java.util.*;
import java.io.*;

public class Main {
    
    public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    }
    
    static int N = 1000000;
    static int NIL = -1;
    int root = NIL;
    int[] key = new int[N];
    int[] left = new int[N];
    int[] right = new int[N];
    int[] p = new int[N];
    
    private void solv() {
        Scanner input = new Scanner(System.in);
        
        for (int i = 0; i < N; i++) {
            key[i] = NIL;
            left[i] = NIL;
            right[i] = NIL;
            p[i] = NIL;
        }
        int n = input.nextInt();
        
        int z = 0;
        while (n-- > 0) {
            String op = input.next();
            if ("insert".equals(op)) {
                key[z] = input.nextInt();
                insertTree(z++);
            } else if("print".equals(op)) {
                inorder(root);
                System.out.println();
                preorder(root);
                System.out.println();
            }
        }
    }
    
    private void preorder(int node) {
        System.out.print(new StringBuilder().append(' ').append(key[node]));
        if (left[node] != NIL) preorder(left[node]);
        if (right[node] != NIL) preorder(right[node]);
    }
    private void inorder(int node) {
        if (left[node] != NIL) inorder(left[node]);
        System.out.print(new StringBuilder().append(' ').append(key[node]));
        if (right[node] != NIL) inorder(right[node]);
    }
    
    void insertTree(int z) {
        int x = root;
        int y = NIL;
        while (x != NIL) {
            y = x;
            if (key[z] < key[x]) {
                x = left[x];
            } else {
                x = right[x];
            }
        }
        p[z] = y;
        if (y == NIL) {
            root = z;
        } else {
            if (key[z] < key[y]) {
                left[y] = z;
            } else {
                right[y] = z;
            }
        }
    }
    
    private static class Scanner {
        BufferedReader r;
        StreamTokenizer st;
        
        public Scanner(InputStream in) {
            r = new BufferedReader(new InputStreamReader(in));
            st = new StreamTokenizer(r);
        }
        
        public String next() {
            nextToken();
            return st.sval;
        }
        
        public Integer nextInt() {
            nextToken();
            return (int)st.nval;
        }
        
        private int nextToken() {
            int token = st.TT_EOF;
            try {
                token = st.nextToken();
            } catch (IOException e) {
            }
            return token;
        }
    }
}

Measured memory_bytes: 161892
#include <ctype.h>
#include <stdio.h>

int main(void)
{
        int N, K;
        scanf("%d%d", &N, &K);

        char S[55];
        scanf("%s", S);

        S[K-1] = tolower(S[K-1]);

        printf("%s\n", S);
        return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
ll p[5005], c[5005];
ll chain[5005][5005];
int vis[5005];
ll len[5005];
int main() {
  IOS;
  ll n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> p[i];
  for (int i = 1; i <= n; i++)
    cin >> c[i];
  for (int i = 1; i <= n; i++) {
    int pp = i;
    int s = 1;
    do {
      chain[i][s] = chain[i][s - 1] + c[p[pp]];
      pp = p[pp];
      s++;
    } while (pp != i);
    len[i] = s - 1;
  }
  ll ans = -LINF;
  // for (int i = 1; i <= n; i++) {
  //   for (int j = 1; j <= len[i]; j++) {
  //     cout << chain[i][j] << ' ';
  //   }
  //   cout << endl;
  // }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= min(k, len[i]); j++) {
      ll val = chain[i][j];
      ans = max(ans, val);
      if (k >= len[i]) {
        val = max(val, val + ll(max(0LL, k - j) / len[i]) * chain[i][len[i]]);
      }
      ans = max(ans, val);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 199268
use std::io::*; //Not mine.
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main() {
    let n: i64 = read();
    let mut list: Vec<i64> = vec![0; 10000001];
    for i in 1..n + 1 {
        let mut k = 1;
        while i * k <= n {
            list[(i * k) as usize] += 1;
            k += 1;
        }
    }
    let mut ans: i64 = 0;
    for i in 1..n + 1 {
        ans += i * (list[i as usize]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 80116
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include <stdio.h>
#include <bitset>
#include<math.h>
#include<list>
#include<map>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
#define PI 3.14159265358979323846  
typedef pair<int, int> P;

int main() {
	int n = 0, ans = 0;
	string s;
	cin >> s;
	for (int i = 0; i < 3; i++) {
		if (s[i] == 'R') {
			n++;
		}
		else {
			ans = max(n, ans);
			n = 0;
		}
	}
	ans = max(n, ans);
	cout << ans << endl;

}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int a[N],b[N],c[N],tt=0;
int main()
{
    int n,m;scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%2)c[++tt]=i;
    }
    if(tt>2){printf("Impossible\n");return 0;}
    else if(tt==1)swap(a[1],a[c[1]]);
    else if(tt==2)swap(a[1],a[c[1]]),swap(a[m],a[c[2]]);
    if(m==1)
    {
        if(a[1]==1)printf("1\n1\n1\n");
        else printf("%d\n2\n%d 1\n",a[1],a[1]-1);
        return 0;
    }
    else
    {
        for(int i=1;i<=m;i++)printf("%d ",a[i]);
        printf("\n%d\n%d ",m-(a[m]==1),a[1]+1);
        for(int i=2;i<m;i++)printf("%d ",a[i]);
        if(a[m]!=1)printf("%d\n",a[m]-1);
    }
}


Measured memory_bytes: 2304
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

ll fastPowMod(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

struct Combination {
    vector<ll> fac, finv, inv;

    Combination(ll maxN) {
        maxN += 100; // for safety
        fac.resize(maxN + 1);
        finv.resize(maxN + 1);
        inv.resize(maxN + 1);
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (ll i = 2; i <= maxN; ++i) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    ll operator()(ll n, ll k) {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
};

int main() {
    string l;
    cin >> l;
    int ones = 0;
    for (int i = 0; i < l.size(); ++i) {
        if (l[i] == '1')
            ones++;
    }
    Combination comb(100001);
    ll ret = 0;
    ll dp[100001][2] = {0};
    dp[0][0] = 2; // 0, 1
    dp[0][1] = 1; // 0, 0
    for (int i = 1; i < l.size(); ++i) {
        if (l[i] == '1') {
            dp[i][0] = dp[i - 1][0] * 2 % MOD;
            dp[i][1] = (dp[i - 1][1] * 3 + dp[i - 1][0]) % MOD;
        } else {
            dp[i][0] = dp[i - 1][0];
            dp[i][1] = (dp[i - 1][1] * 3) % MOD;
        }
    }
    cout << (dp[l.size() - 1][0] + dp[l.size() - 1][1]) % MOD << "\n";

    return 0;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string N;
  cin >> N;
  bool flag = false;
  rep(i, 3){
    if(N[i] == '7') flag = true;
  }
  if(flag) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

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

int dp[1001][1001];

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s1, s2; cin >> s1 >> s2;
    int n1 = s1.size(), n2 = s2.size();
    int dp[n1+1][n2+1];
    for(int i=0;i<=n1;i++) dp[i][0] = i;
    for(int j=0;j<=n2;j++) dp[0][j] = j;
    for(int i=1;i<=n1;i++){
        for(int j=1;j<=n2;j++){
            dp[i][j] = min(dp[i-1][j] + 1, dp[i][j-1] + 1);
            if(s1[i-1] == s2[j-1]){
                dp[i][j] = min(dp[i][j], dp[i-1][j-1]);
            }else{
                dp[i][j] = min(dp[i][j], dp[i-1][j-1] + 1);
            }
        }
    }
    cout << dp[n1][n2] << endl;
}


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

int main() {
	int n,m,t;
	cin>>n>>m;
	long long int dp[n+1];
	fill(dp,dp+n,INT_MAX);
	dp[n]=1;
	dp[n-1]=1;
	for(int i=0;i<m;i++){
		cin>>t;
		dp[t]=0;
	}
	for(int i=n-2;i>=0;i--){
		if(dp[i]!=0)
		dp[i]=dp[i+1]+dp[i+2];
		dp[i]=dp[i]%1000000007;
	//	cout<<dp[i]<<endl;
	}
	long long int y=dp[0];
	y=y%1000000007;
	cout<<y;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>

using namespace std;

int main()
{
	string S,T;

	cin >> S >> T;
	int size = T.size();
	int N = S.size();
	int cnt = 0;
	int ans = 1000000;

	for(int i=0;i <= N - size;i++)
	{
		string sub = S.substr(i,size);
		int cnt = 0;
		for(int j = 0;j<size;j++)
		{
			if(sub[j] != T[j])
			{
				cnt++;
			}
		}
		ans = min(ans,cnt);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3604
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func fill(a []int, x int) {
	for i := 0; i < len(a); i++ {
		a[i] = x
	}
}

func f(i int, links [][]int, dp []int) int {
	if dp[i] != -1 {
		return dp[i]
	}
	if len(links[i]) == 0 {
		dp[i] = 0
	} else {
		t := -1
		for _, j := range links[i] {
			t = max(t, f(j, links, dp))
		}
		dp[i] = t + 1
	}
	return dp[i]
}

func main() {
	defer flush()

	N := readInt()
	M := readInt()

	links := make([][]int, N)
	for i := 0; i < M; i++ {
		x := readInt() - 1
		y := readInt() - 1
		links[x] = append(links[x], y)
	}

	dp := make([]int, N)
	fill(dp, -1)

	result := -1
	for i := 0; i < N; i++ {
		result = max(result, f(i, links, dp))
	}
	println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


Measured memory_bytes: 21376
import string
n = int(input())
S = []
for _ in range(n):
    S.append(input())
alphabet = string.ascii_lowercase
summary = [{c: 0 for c in alphabet} for _ in range(n)]
for i, s in enumerate(S):
    for c in s:
        summary[i][c] += 1
ans = ''
for al in alphabet:
    ans += al * min(summary, key=lambda x: x[al])[al]
print(ans)

Measured memory_bytes: 3768
# search smallest i ( s <= i < e ) such that f(i) == True
def bisearch_smallest(f, s, e = None):
	if e == None:
		e = s - 1
		s = 0
	else:
		e -= 1
	
	while s < e:
		m = (s + e) // 2
		if f(m):
			e = m
		else:
			s = m + 1
	
	if s == e and f(s):
		return s
	else:
		return -1

N = int(input())
a_list = [int(input()) for _ in range(N)]

cols = [a_list.pop(0)]

for a in a_list:
	index = bisearch_smallest(lambda i: cols[i] < a, len(cols))
	if index == -1:
		cols.append(a)
	else:
		cols[index] = a

print(len(cols))


Measured memory_bytes: 7836
import sys
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]

INF = 10**18
best = INF
for i in range(2):
    flg = i % 2
    _sum = 0
    cnt = 0
    for a in a_ls:
        _sum += a
        if flg:
           if _sum <= 0:
               cnt += 1 - _sum
               _sum = 1
        else:
            if _sum >= 0:
                cnt += _sum + 1
                _sum = -1
        flg = 1 if flg == 0 else 0
    best = min(best, cnt)
print(best)

Measured memory_bytes: 59760