akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 int n;
 cin>>n;
 vector<ll> x(n);
 for(ll i=0;i<n;i++){
  cin>>x[i];
 }
 ll cost = inf;
 for(ll y=1;y<=100;y++){
  ll sum = 0;
  for(ll i=0;i<n;i++) sum += ( x[i]-y )*(x[i]-y);
  cost = min( cost , sum );
 }
 cout<<cost<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  string S, T, U;
  cin >> S >> T;
  int A, B;
  cin >> A >> B;
  cin >> U;
  if (S == U) {
    --A;
  }
  else if (T == U) {
    --B;
  }
  printf("%d %d\n", A, B);
  return 0;
}

Measured memory_bytes: 256
///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pf2(a,b) printf("%d %d",a,b)
#define pf3(a,b,c) printf("%d %d %d",a,b,c)
#define sfl(a) scanf("%lld",&a)
#define sfl2(a,b) scanf("%lld %lld",&a,&b)
#define sfl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pfl(a) printf("%lld",a)
#define pfl2(a,b) printf("%lld %lld",a,b)
#define pfl3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
#define tz 100000
#define clr0(a) memset(a,0,sizeof(a))
#define clr1(a) memset(a,-1,sizeof(a))
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
main()
{
    timesave;
    string s;
    cin>>s;
    int i,f=0;
    for(i=0;i<s.size();i++)
    {
        if(s[i]=='7')
            f=1;
    }
    if(f==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}






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

typedef long long ll;
ll N, T;
ll R;

int main() {
  cin >> N >> T;
  ll start = 0, end = T;
  for (ll i = 0; i < N; ++i) {
    ll t;
    cin >> t;
    if (end < t) {
      R += end - start;
      start = t;
    }
    end = max(end, t + T);
  }
  R += end - start;
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 256
def dijkstra(n, s):
    inf = float('inf')
    color = ['white' for _ in range(n)]
    D = [inf for _ in range(n)]             
    P = [0 for i in range(n)]        
    M = [[inf for _ in range(n)] for _ in range(n)]

    for i in range(n):  
        weight = list(map(int, input().split()))[2:]    
        for j in range(len(weight)//2):
            M[i][weight[2*j]] = weight[2*j+1]   

    D[s] = 0
    P[s] = -1

    while True:
        cost, u = inf, 0
        for i in range(n):
            if color[i] != 'black' and D[i] < cost:  
                cost = D[i]
                u = i
        
        if cost == inf:                         
            break

        color[u] = 'black'                          

        for i in range(n):
            if color[i] != 'black' and M[u][i] != inf:             
                if D[u] + M[u][i] < D[i]:                           
                    D[i] = D[u] + M[u][i]                              
                    color[i] = 'gray'                            
                    P[i] = u                          

    return D

n = int(input())
distance = dijkstra(n, 0)
for i in range(n):
    print(i, distance[i])


Measured memory_bytes: 5776
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
Y = [list(map(int, input().split())) for _ in range(N)]
X.sort(key=lambda x:x[1], reverse=True)
Y.sort()
ans = 0
xf = [0] * N
yf = [0] * N
C = []
i = 0
while i < N:
    if yf[i] == 1:
        i+= 1
        continue
    for j in range(N):
        if xf[j] == 0:
            if Y[i][0] > X[j][0] and Y[i][1] > X[j][1]:
                ans += 1
                xf[j] = 1
                yf[i] = 1
                i = 0
                break

    i += 1
print(ans)

Measured memory_bytes: 3064
s = str(input())
K = int(input())

T = []
#for i in range(1,min(K,len(s))):
#  T.append(s[:i+1])
#print(T)

for i in range(len(s)): #i文字目スタート
  for j in range(i+1,min(len(s)+1,i+K+1)): #j文字
    temp = s[i:j]
    if temp in T:
      continue
    if len(T) < K:
      T.append(temp)
      T.sort()
    else:
      Flag = False
      for t in range(K):
        if temp < T[t]:
          #print(temp,T[t],T)
          T.insert(t,temp)
          Flag = True
          break
      if Flag:
        T.pop()
print(T[K-1])
    

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  Int n;
  F f;
  T ti;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(F f,T ti):f(f),ti(ti){}
  void init(Int n_){    
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }
  void build(const vector<T> &v){
    Int n_=v.size();
    init(n_);
    for(Int i=0;i<n_;i++) dat[n+i]=v[i];
    for(Int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  void set_val(Int k,T x){
    dat[k+=n]=x;
    while(k>>=1)
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);    
  }
  T query(Int a,Int b){
    T vl=ti,vr=ti;
    for(Int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }
  template<typename C>
  Int find(Int a,Int b,C &check,Int k,Int l,Int r){
    if(!check(dat[k])||r<=a||b<=l) return -1;
    if(k>=n) return k-n;
    Int m=(l+r)>>1;
    Int vl=find(a,b,check,(k<<1)|0,l,m);
    if(~vl) return vl;
    return find(a,b,check,(k<<1)|1,m,r);
  }
  template<typename C>
  Int find(Int a,Int b,C &check){
    return find(a,b,check,1,0,n);
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  auto f=[&](Int x,Int y){return __gcd(x,y);};
  SegmentTree<Int> seg(f,0);
  seg.build(a);
  Int ans=0;
  for(Int i=0;i<n;i++){
    Int x=seg.query(0,i);
    Int y=seg.query(i+1,n);
    Int z=f(x,y);
    chmax(ans,z);
  }  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	int a, b, c;
	cin >> a >> b >> c;
	if ((a + b == c) || (a + c == b) || (b + c == a)) cout << "Yes";
	else cout << "No";

	return 0;
}



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

int main()
{
    int n, m;
    int taro[100];
    int hana[100];
    int taro_sum;
    int hana_sum;
    int taro_ans, hana_ans;
    cin >> n >> m;
    while(n && m){
        taro_sum = 0;
        hana_sum = 0;
        taro_ans = -1;
        hana_ans = -1;
        for(int i=0;i<n;++i){
            cin >> taro[i];
            taro_sum += taro[i];
        }
        for(int i=0;i<m;++i){
            cin >> hana[i];
            hana_sum += hana[i];
        }
        for(int i=0;i<n;++i){
            for(int j=0;j<m;++j){
                if(hana_sum - hana[j] + taro[i] == taro_sum - taro[i] + hana[j] && (taro_ans == -1 || taro_ans + hana_ans > taro[i] + hana[j])){
                        taro_ans = taro[i];
                        hana_ans = hana[j];
                }
            }
        }
        if(taro_ans == -1){
            cout << -1 << endl;
        }else{
            cout << taro_ans << " " << hana_ans << endl;
        }
        cin >> n >> m;
    }
    return 0;
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    pair<long long int,long long int> p[n];
    for(int i = 0;i < n;i++)
    {
        long long int x,l;
        cin >> x >> l;
        p[i] = make_pair(x + l,x - l);
    }
    sort(p,p + n);
    int ans = 0;
    int temp = -1000000000;
    for(int i = 0;i < n;i++)
    {
        if(temp <= p[i].second)
        {
            ans++;
            temp = p[i].first;
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 1920
import math

N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N - 1)]

for i in range(N - 1):
    t = CSF[i][0] + CSF[i][1]
    for ii in range(i + 1, N - 1):
        if t <= CSF[ii][1]:
            t = CSF[ii][1] + CSF[ii][0]
        else:
            t = CSF[ii][1] + CSF[ii][2] * math.ceil((t - CSF[ii][1]) / CSF[ii][2]) + CSF[ii][0]
    print(t)
print(0)

Measured memory_bytes: 3188
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

// constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
// constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    LL n,x,m;
    cin >> n >> x >> m;
    LL a1 = sqr(x) % m;
    LL ans = x;
    --n;
    // n -= 631;
    if (n < m) {
        REP(i,0,n) {
            // dump(a1);
            ans = (ans + a1);
            a1 = sqr(a1) % m;
        }
        cout << ans << endl;
        return;
    }

    map<LL,int> ma;
    VLL ss;
    LL sum = 0;
    REP(i,0,m) {
        if (ma.count(a1) > 0) break;
        ma[a1] = i;
        sum = (sum + a1);
        ss.push_back(sum);
        if (a1 == 0) break;
        a1 = sqr(a1) % m;
    }
    if (a1 == 0) {
        cout << ans + sum << endl;
        return;

    }
    int len = ma.size() - ma[a1];
    // dump(ss[ma[a1]-1]);
    if (ma[a1] > 0) sum -= ss[ma[a1]-1];
    // --len;
    if (ma[a1] > 0) {
        ans += ss[ma[a1]-1];
        n -= ma[a1];
    }
    dump(len);
    dump(sum);
    sum = sum * (n / len);
    ans = (ans + sum);
    n %= len;
    dump(n);
    dump(ans);
    // if (n > 0) {
    //     ans += ss[n-1];
    //     cout << ans << endl;
    //     return;
    // }
    // a1 = sqr(x) % m;
    REP(i,0,n) {
        ans = (ans + a1);
        a1 = sqr(a1) % m;
    }
    cout << ans << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 6776
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
//プロトタイプ宣言
int gcd(int , int);
void often(void);
int get_digent(int);


int main(){
  often();
  int n,maximum=0;
  cin >> n;
  vi a(n),left(n),right(n),ans(n);
  rep(i,n) cin >> a[i];
  rep(i,n){
    maximum = max(maximum,((i!=0)?a[i-1]:0));
    left[i] = maximum;
  }
  maximum = 0;
  for(int i=n-1;i>=0;i--){
    maximum = max(maximum,((i!=n)?a[i+1]:0));
    right[i] = maximum;
  }
  rep(i,n){
    ans[i] = max(right[i],left[i]);
  }
  rep(i,n) cout << ans[i] << endl;
}








































//以下、ライブラリ

int gcd(auto a, auto b) {
  return b ? gcd(b, a%b) : a;
}  //ユークリッドの互除法

void often(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int get_digent(int x){
  string s;
  s = to_string(x);
  int digent = s.size();
  return digent;
} 

Measured memory_bytes: 4736
#include <bits/stdc++.h> //library
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //for-loop (from 0)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++) //for-loop (from 1)
#define all(x) (x).begin(),(x).end() //start-to-end iteration, mainly in upper_bound, lower_bound
#define SZ(x) ((int)(x).size()) //unsigned to signed

using namespace std;
using ll = long long; //long long
ll M = 1000000000 + 7;
const ll INF = 1LL << 60;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } //compare a,b and replace by greater
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //compare a,b and replace by smaller
ll qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; } //power
ll qp(int a, ll b, ll Mod) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%Mod; a = 1ll * a*a%Mod; } while (b >>= 1); return ans; } //power(mod)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } //gcd
int dx[4] = { 1,0,-1,0 }; //path
int dy[4] = { 0,1,0,-1 }; //path
ll RS(ll N, ll P) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2); return sq*sq; } else { return N*RS(N, P - 1); } } //power(repeat-square,fast)
ll nPr(ll n, ll r) { ll ans = 1; rep(i, r) { ans = ans * (n - i); } return ans; } //permutation
ll nCr(ll n, ll r) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1); bunshi = bunshi * (n - i); } return bunshi / bunbo; } //combination
ll RS(ll N, ll P, ll Mod) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2, Mod); return sq*sq%Mod; } else { return N*RS(N, P - 1, Mod) % Mod; } } //power(mod)(repeat-square,fast)
ll nPr(ll n, ll r, ll Mod) { ll ans = 1; rep(i, r) { ans = ans * (n - i) % Mod; } return ans; } //permutation
ll nCr(ll n, ll r, ll Mod) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1) % Mod; bunshi = bunshi * (n - i) % Mod; } return bunshi * RS(bunbo, Mod - 2, Mod) % Mod; } //combination

ll dp[20200]; // dp[h]:体力をh減らすのに必要な最小魔力

int main(void) {
  int H,N; cin >> H >> N;
  vector<int> a(N),b(N);
  int max_A = 0;
  rep(i,N){
    cin >> a[i] >> b[i];
    chmax(max_A,a[i]);
  }
  rep(h,20200) dp[h]=INF;
  
  dp[0] = 0;
  
  rep(i,N){
    rep(h,H+max_A+1){
      if (h-a[i] > 0) chmin(dp[h], dp[h-a[i]]+b[i]);
      else chmin(dp[h], dp[0]+b[i]);
    }
  }
  
  cout << dp[H] << "\n";
  
  return 0;
}

Measured memory_bytes: 384
import sys
n,yen = map(int,input().split())

for x in range(n+1):
    for y in range(n+1):
        z = n - x - y
        if z >= 0:
            if 10000*x + 5000*y + 1000*z == yen:
                print(x,y,z)
                sys.exit()
                
print(-1,-1,-1)

Measured memory_bytes: 40940
// #pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define IMAX 2147483647
#define LMAX 9223372036854775807
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);
#define fou(i,a,n) for(int i=a;i<n;i++)
#define fod(i,a,n) for(int i=n-1;i>=a;i--)
#define rep(n) fou(_,0,n)
#define tra(a,x) for(auto& a : x)
#define elif(c) else if(c)
#define VI vector<int>
#define VD vector<double>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVD vector<VD>
#define VVC vector<VC>
#define VVS vector<VS>
#define emb emplace_back
#define pub push_back
#define pob pop_back
#define mp make_pair
#define fi first
#define se second
#define si(vec) ((int)(vec).size())
#define all(vec) vec.begin(),vec.end()
#define lla(vec) vec.rbegin(),vec.rend()
#define range(vec,x,y) vec.begin()+x,vec.begin()+y
#define sortup(vec) sort(all(vec))
#define sortdown(vec) sort(lla(vec))
#define eraseif(vec,condition_VAR) vec.erase(remove_if(all(vec),[&](auto VAR){return condition_VAR;}),vec.end())
#define countif(vec,condition_VAR) count_if(all(vec),[&](auto VAR){return condition_VAR;})
#define replaceif(vec,condition_VAR,n) replace_if(all(vec),[&](auto VAR){return condition_VAR;},n)
#define erase_unique(vec) vec.erase(unique(all(vec)),vec.end())
#define calcvec(vec,calc_VAR) for_each(all(vec),[&](auto&VAR){VAR=calc_VAR;});
#define calc2vec(vec1,op,vec2) {rep(1){int s=min(si(vec1),si(vec2));fou(i,0,s)vec1[i]=vec1[i] op vec2[i];}}
template<class C>void mini(C &a,C b){a=min(a,b);}
template<class C>void maxi(C &a,C b){a=max(a,b);}
#define in(T,...) T __VA_ARGS__;_cin(__VA_ARGS__);
#define out(...) _cout(__VA_ARGS__);
void _cin(){}template<class Head,class...Tail>void _cin(Head&head,Tail&&...tail){cin>>head;_cin(forward<Tail>(tail)...);}
template<class Head>void _cout(Head head){cout<<head<<endl;}template<class Head,class...Tail>void _cout(Head head,Tail...tail){cout<<head<<" ";_cout(forward<Tail>(tail)...);}
template<class C>void outvec(vector<C> vec){int vecsize=si(vec);fou(i,0,vecsize-1)cout<<vec[i]<<" ";out(vec[vecsize-1]);}
template<class C> C gcd(C a,C b){if(a&&b)return gcd(min(a,b),max(a,b)%min(a,b));else return a;}
template<class C> C lcm(C a,C b){return a/gcd(a,b)*b;}
template<class C>int binarysearch(vector<C> vec,C n,char c){int left=-1;int right=si(vec);bool outleft=(c=='d'||c=='U');int getmin=(c=='u'||c=='d')?1:-1;while(right-left>1){int mid=left+(right-left)/2;bool OK=vec[mid]*getmin>=n*getmin;if(outleft==OK) left=mid;else right=mid;}return outleft?left:right;}


// #define int int64_t
// #define double long double


// map,makepair



signed main(){
  IOS;

  in(int,n,k);
  VI a(n);
  fou(i,0,n)cin>>a[i];

  sortup(a);

  int now=0;
  VI number(n);
  fou(i,0,n){
    while(i==a[now]){
      number[i]++;
      now++;
    }
  }
  sortdown(number);

  int ans=0;
  int nochange=0;
  fou(i,0,k) nochange+=number[i];
  ans=n-nochange;
  out(ans);
}

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

int main(){
    long long  n, a, b;
    cin >> n >> a >> b;/*
    if(a == 0){cout << 0 << endl;return 0;}
    else if(b == 0){std::cout << n << std::endl; return 0;}
    */
    long long sum = n/(a+b) * a;
    long long par = n%(a+b);
    sum += min<long>(par, a);
    std::cout << sum  << std::endl;
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>

int main(void){
  int a,b,c,s;

  scanf("%d %d %d",&a,&b,&c);

  s = a+b;

  if(s>b+c)
    s=b+c;
  if(s>a+c)
    s=a+c;

  printf("%d\n",s);

  return 0;
}



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

using namespace std;

typedef long long ll;

ll get_gcd(ll B, ll A){
    if(A == 0){
        return B;
    }else{
        return get_gcd(A, (B % A));
    }
}

ll get_lcm(ll B, ll A){
    return (B*A) / get_gcd(B, A);
}

int main()
{
    ll A = 0, B = 0;
    cin >> A >> B;
    if(A > B){
        ll t = A;
        A = B;
        B = t;
    }
    // 最小公倍数 LCM(B, A)を求める
    // 素因数分解できるならそっちが一番素朴
    cout << get_lcm(B, A) << endl;

    return 0;
}


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

#define ll long long
#define all(x) (x).begin(),(x).end()
#define SZ(x) (x).size()
#define fir first
#define sec second

void scan() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}


using namespace std;
const int maxn = 2e5 + 7;
int a[maxn], pre[maxn];

int main() {
    //scan();

    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int a,b,c;cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;

    return 0;
}




















Measured memory_bytes: 256
k = int(input())
if k <= 100 * 1000:
    if k % 2:
        print(2)
        print(k // 2, 2 + k // 2)
    else:
        print(2)
        print(1 + k // 2, 1 + k // 2)
else:
    mn = k // 50
    md = k % 50
    print(50)
    ok = 49 + mn
    for i in range(50):
        if i < md:
            print(ok + 50 - (md - 1), end=" ")
        else:
            print(ok - md, end= " ")


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


void solve(long long A, long long B, long long C, long long K){
  cout << (((K%2) == 0) ? (A - B) : ((B+C) - (A+C))) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  long long C;
  scanf("%lld",&C);
  long long K;
  scanf("%lld",&K);
    solve(A, B, C, K);
    return 0;
}


Measured memory_bytes: 256
n = int(input())
v = list(map(int, input().split()))
v1 = []
v2 = []
for i in range(n):
	if i%2 == 0:
		v1.append(v[i])
	else:
		v2.append(v[i])
v1.sort()
v2.sort()

cnt1 = []
cnt2 = []
now = v1[0]
con = 1
for i in range(1, len(v1)):
	if now == v1[i]:
		con += 1
	else:
		cnt1.append([con, now])
		now = v1[i]
		con = 1
cnt1.append([con, now])
now = v2[0]
con = 1
for i in range(1, len(v2)):
	if now == v2[i]:
		con += 1
	else:
		cnt2.append([con, now])
		now = v2[i]
		con = 1
cnt2.append([con, now])

cnt1.sort()
cnt2.sort()
if cnt1[len(cnt1)-1][1] != cnt2[len(cnt2)-1][1]:
	p1 = [cnt1[i][0] for i in range(len(cnt1))]
	p2 = [cnt2[i][0] for i in range(len(cnt2))]
	print(sum(p1[:len(p1)-1])+sum(p2[:len(p2)-1]))
else:
	p1 = [cnt1[i][0] for i in range(len(cnt1))]
	p2 = [cnt2[i][0] for i in range(len(cnt2))]
	ans = min(sum(p1[:len(p1)-2])+p1[len(p1)-1]+sum(p2[:len(p2)-1]), sum(p1[:len(p1)-1])+p2[len(p2)-1]+sum(p2[:len(p2)-2]))
	print(ans)

Measured memory_bytes: 19212
N = int(input())
h_s = list(map(int, input().split()))+[0]*10
# print(h_s)
dp = [float("inf")]*(N+10)
dp[0] = 0

for i in range(N):
    for j in range(1, 3):
        dp[i+j] = min(dp[i+j], dp[i]+abs(h_s[i]-h_s[i+j]))

print(dp[N-1])

Measured memory_bytes: 13980
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"

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

	int n,m;
	cin>>n>>m;
	vs in(n);
	rep(i,n)cin>>in[i];
	vvi co(n+1,vi(m+1));
	co[0][1]=1;
	int MOD=1000000007;
	rep(i,n)rep(j,m)if(in[i][j]=='.')
		co[i+1][j+1]=(co[i][j+1]+co[i+1][j])%MOD;
	
	cout<<co[n][m]<<endl;
}






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

typedef long long LL;
const int N = 5005, mod = 1000000007;

int inv[N];
void init(int n) {
	inv[1] = 1;
	for (int i = 2; i <= n; ++i)
		inv[i] = (LL) inv[mod % i] * (mod - mod / i) % mod;
}

int n, head[N], tot, G;
struct edge { int to, nxt; } e[N << 1];
void link(int x, int y) {
	e[++tot] = (edge) {y, head[x]}, head[x] = tot;
	e[++tot] = (edge) {x, head[y]}, head[y] = tot;
}

int dfs(int x, int f = 0) {
	int max = 0, size = 1;
	for (int i = head[x]; i; i = e[i].nxt) if (e[i].to != f) {
		int ret = dfs(e[i].to, x); max = std::max(max, ret), size += ret;
		if (ret << 1 == n) {
			int ans = 1;
			for (int i = 1; i <= ret; ++i) ans = (LL) ans * i % mod;
			std::cout << (LL) ans * ans % mod << '\n', std::exit(0);
		}
	}
	max = std::max(max, n - size);
	if (max << 1 < n) G = x;
	return size;
}

int f[N], g[N], h[N], deg;
int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n, init(n);
	for (int i = 1, x, y; i < n; ++i)
		std::cin >> x >> y, link(x, y);
	dfs(1), deg = 0, f[0] = 1;
	for (int i = head[G]; i; i = e[i].nxt) {
		int k = dfs(e[i].to, G); g[0] = 1;
		for (int j = 0; j < k; ++j)
			g[j + 1] = (LL) g[j] * (j - k + mod) % mod * (k - j) % mod * inv[j + 1] % mod;
		for (int j = 0; j <= deg + k; ++j) h[j] = 0;
		for (int j = 0; j <= deg; ++j)
			for (int l = 0; l <= k; ++l) h[j + l] = (h[j + l] + (LL) f[j] * g[l]) % mod;
		for (int j = 0; j <= deg + k; ++j) f[j] = h[j]; deg += k;
	}
	int ans = 0;
	for (int i = 0; i <= n; ++i)
		ans = (ans * (n - i + 1LL) + f[i]) % mod;
	std::cout << ans << '\n';
	return 0;
}

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

#define INFTY 1 << 30;



int Merge(int A[],int left,int mid,int right){

  int k;
  int n1 = mid-left;
  int n2 = right-mid;

  int L[n1+1];
  int R[n2+1];

  for(int i=0;i<n1;i++){
    L[i] = A[left+i];
  }

  for(int i=0;i<n2;i++){
    R[i] = A[mid+i];
  }

  L[n1] = INFTY;
  R[n2] = INFTY;

  int i=0;
  int j=0;

  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k] = L[i];
      i++;
    }else{
      A[k] = R[j];
      j++;
    }
  }
  return k - left;
}

int MergeSort(int A[],int left,int right){
  int count = 0;
  if(left+1 < right){
    int mid = (left+right)/2;
    count += MergeSort(A,left,mid);
    count += MergeSort(A,mid,right);
    count += Merge(A,left,mid,right);
  }
  return count;
}

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

  int S[500000];
  for(int i=0;i<n;i++){
    cin >> S[i];
  }

  m = MergeSort(S,0,n);

  for(int i=0;i<n-1;i++){
    cout << S[i];
    cout << " ";
  }
  cout << S[n-1];
  cout << endl;

  cout << m << endl;

  return 0;
}



Measured memory_bytes: 6976
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        int n, a, b;
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        a = sc.nextInt();
        b = sc.nextInt();

        int ans = 0;
        int tmp;
        int x;
        int t;
        for(int i = 1; i <= n; i++){
            tmp = i;
            x = 0;
            while(tmp != 0){
                x += tmp % 10;
                tmp /= 10;
            }

            if(a <= x && x <= b) ans += i;
        }

        System.out.println(ans);

        sc.close();
    }
}

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

int main(){
int n=0,x=0,ans=0;
while(true){
cin>>n>>x;
if(n==0&&x==0){break;}
for (int i = 1; i <= n; ++i) {
	for (int j = i+1; j <= n; ++j) {
		for (int k = j+1; k <= n; ++k) {
			if(i+j+k==x){ans+=1;}
		}
	}
}
cout<<ans<<endl;
ans=0;
}

}

Measured memory_bytes: 3084
### constant

MAX_N = 40
MAX_INT = 1 << 30

### subroutines

def o_prod(v0x, v0y, v1x, v1y)
  v0x * v1y - v0y * v1x
end

### main

n = gets.strip.to_i

pts = n.times.map{|i| gets.strip.split(' ').map{|s| s.to_i} + [i]}
pts.sort!{|a, b| (cmp = a[1] <=> b[1]) != 0 ? cmp : a[0] <=> b[0]}
#p pts

q = gets.strip.to_i

ks = q.times.map{gets.strip.to_i}
#p ks


min_area = n.times.map{n.times.map{n.times.map{n.times.map{MAX_INT}}}}

ppts = n.times.map{n.times.map{n.times.map{n.times.map{nil}}}}

for a in (0...n)
  ax, ay = pts[a]

  for b in ((a + 1)...n)
    bx, by = pts[b]
    abx = bx - ax
    aby = by - ay

    for c in ((a + 1)...n)
      next if b == c

      cx, cy = pts[c]
      acx = cx - ax
      acy = cy - ay

      s = o_prod(abx, aby, acx, acy)
      if s > 0
        min_area[2][a][b][c] = s
        ppts[2][a][b][c] = [a, b, c]
        #p [2, [a, b, c], s]
      end
    end
  end
end

for k in (2...(n - 1))
  for a in (0...n)
    ax, ay = pts[a]

    for b in ((a + 1)...n)
      bx, by = pts[b]

      for c in ((a + 1)...n)
        next if b == c

        cx, cy = pts[c]

        s0 = min_area[k][a][b][c]
        next if s0 >= MAX_INT

        bcx = cx - bx
        bcy = cy - by

        ptsk = ppts[k][a][b][c]

        for i in ((a + 1)...n)
          next if ptsk.include? i

          ix, iy = pts[i]

          cix = ix - cx
          ciy = iy - cy

          next if o_prod(bcx, bcy, cix, ciy) <= 0 ||
            o_prod(cix, ciy, ax - ix, ay - iy) <= 0

          s1 = min_area[2][a][c][i]
          next if s1 >= MAX_INT

          sum = s0 + s1
          if min_area[k + 1][a][c][i] > sum
            min_area[k + 1][a][c][i] = sum
            ppts[k + 1][a][c][i] = ptsk + [i]
          end
        end
      end
    end
  end
end

#p min_area
#p ppts

n3 = n ** 3

for k in ks
  min_ar = MAX_INT
  min_a = min_b = min_c = -1

  for a in (0...n)
    for b in (0...n)
      for c in (0...n)
        ar = min_area[k - 1][a][b][c]
        if min_ar > ar
          min_ar = ar
          min_a = a
          min_b = b
          min_c = c
        end
      end
    end
  end

  if min_ar >= MAX_INT
    puts 'NA'
  else
    pptsk = ppts[k - 1][min_a][min_b][min_c]
    pts0 = pptsk.map{|i| pts[i][2] + 1}
    puts pts0.join(' ')
  end
end

Measured memory_bytes: 79632
#include <stdio.h>
#include <string.h>
int main(void)
{
        int a[10010],b,m,n,i,j=0,k=0,l=0,p=0,x=0,y=0,c=0;
        char s[1000];

        scanf("%d",&n);

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

        for(i=0; i<n; i++){
                if(a[i]%2==0){
                if((a[i]%3!=0)&&(a[i]%5!=0)){
                        printf("DENIED\n");
                        return 0;}
                }
        }
        printf("APPROVED\n");
            //155
         return 0;
}

Measured memory_bytes: 128
def solve(n, c):
    num = len(list(filter(lambda _: _=="R", c)))
    if num in [0,n]:
        return 0
    w = [0] * n
    w[0] = int(c[0] == "W")
    for i in range(1, n):
        w[i] = w[i-1] + int(c[i] == "W")
    return min(max(w[i], num+w[i]-i-1) for i in range(n))

n = int(input())
c = input()
print(solve(n, c))

Measured memory_bytes: 16828
#include <iostream>
#include <vector> 
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <cerrno>
#include <cfenv>
#include <math.h>
#include <iomanip>
#include <limits>
#define ll long long int

using namespace std;

int main(){

    int n,m;

    vector<int> a(1000);

    while(true){

        cin >> n >> m;

        if(n==0&&m==0){
            break;
        }

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

        int max = -1;

        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                if(max < a[i]+a[j] && a[i]+a[j] <= m){
                    //cout << i << " " << j << endl;
                    max = a[i]+a[j];
                }
            }
        }

        if(max==-1){
            cout << "NONE" << endl;
        }
        else {
            cout << max << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv){
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	int a,b,c; cin >> a >> b >> c;
	out(max(0,c-(a-b)));
}




Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(X: int):
    def eratos(n :int):
        isPrimeList = [True] * (n+1)
        isPrimeList[0] = isPrimeList[1] = False
        
        for i in range(2, int(n**0.5+1)):
            if(isPrimeList[i]):
                j = i+i
                while(j <= n):
                    isPrimeList[j] = False
                    j = j+i
                    
        return isPrimeList

    t = eratos(10**6)
    # print(t[:10])
    l = [i for i,v in enumerate(t) if t[i] == True] 
    
    for i in l:
        if i >= X:
            print(i)
            exit()
            
    

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F            first
#define S            second
#define pb(x)        push_back(x)
#define mp(a,b)      make_pair(a,b)
#define mt(a,b,c)    make_tuple(a,b,c)
#define sz           size()
#define all(A)       A.begin(), A.end()
#define mem(a, b)    memset(a, b, sizeof(a))   // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b)      for(ll i=0;i<(b);i++)
#define f1(i,b)      for(ll i=1;i<=(b);i++)
#define f2(i,a,b)    for(ll i=(a);i<=(b);i++)
#define f3(i,b,a)    for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))

#define mod          10000007
#define PI           acos(-1.0)
#define MAX3(a,b,c)  max(a,max(b,c))

/*------------------------Bitmask-------------------------------*/
#define bitOn(N,pos)      (N | (1LL<<(pos)))
#define bitOff(N,pos)     (N & (~(1LL<<(pos))))
#define bitCheck(N,pos)   ((bool)(N & (1LL<<(pos))))
#define bitFlip(a,k)      (a^(1LL<<(k)))

#define whilee(i,t)  while(i!=t)
#define  sl(a)       scanf("%lld",&a)
#define  pl(a)       printf("%lld\n",a)

//x = 1e18 means 10^18
//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end()); //sort(A, +n, greater<int>());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%lld",&x);
//printf("%lld\n",x);
//printf("%I64d\n", a);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);

/*----------------------- Graph Moves---------------------------*/
// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1};  // 4 Direction
// int dx[] = {0,0,1,-1,-1,1,-1,1} , dy[] = {-1,1,0,0,1,1-1,-1};  // 8 Direction // Kings Move
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};  // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};  // Hexagonal Direction

//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
//set <ll> A;
//map <ll,ll> A;
//unordered_map <ll, ll> A;
//pair <ll,ll> A ;
//tuple <ll, ll, ll> A;
//vector <pair <ll,ll>> A;
//bitset<32> bset1;
//bool ok = true;
//char ch;
string S, T, U;

ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, flag=0, cnt=0;

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

    cin>>S>>T;

    f0(i,S.sz)
    {
        if(S[i]!=T[i])
            cnt++;
    }

    cout<<cnt<<endl;
    return 0;
}



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

typedef long long ll;

ll N, M;

int main() {
	scanf("%lld%lld", &N, &M);

	if (N == 1 && M == 1) {
		printf("1\n");
	} else if (min(N, M) == 1) {
		printf("%lld\n", N * M - 2);
	} else {
		printf("%lld\n", (N - 2) * (M - 2));
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
using namespace std;


#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>



int main() {
	ll n;
	cin >> n;
	for (__int128 i = -1010; i < 1100; i++){
		for (__int128 j = -1010; j < 1100; j++) {
			if (i * i * i * i * i - j * j * j * j * j == n) {
				cout << (ll)i << " " << (ll)j << endl;
				return 0;
			}
		}
	}
}



Measured memory_bytes: 3552
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,n)
#define PER(i,n)  ROF(i,0,n)
#define SIZE(a) int((a).size())

#define ALL(a)  (a).begin(),(a).end()

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_LARGE = 1000000100;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

void Main()
{
	int n;
	cin >>n;
	VI a(n);
	REP(i, n) cin >> a[i];
	
	VI lis(n,-1);

	REP(i,n){
		*(lower_bound(ALL(lis), a[i]) -1) = a[i];
	}

	PER(i,n){
		if(lis[i] == -1){
			cout << n-i-1 << endl;
			return;
		}
	}

	cout << n << endl;
	

	return;
}

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  string S;
  cin >> S;
  
  vector<int> dp(13);
  dp[0] = 1;

  for (auto c: S) {
    vector<int> dp_nxt(13);
    REP(i, 10) if (c == '?' || c == (char)('0' + i)) {
      REP(d, 13) (dp_nxt[(d * 10 + i) % 13] += dp[d]) %= MOD;
    }
    dp = dp_nxt;
  }
  
  cout << dp[5] << endl;
  return 0;
}

Measured memory_bytes: 512
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
#include <memory>
#include <time.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

ll number(string &s,int &p){
	ll ret=0;
	while(isdigit(s[p])){
		ret=ret*10+s[p]-'0';
		p++;
	}
	return ret;
}

ll atom(string &s,int &p,map<string,int>&atoms){
	string a;
	a+=s[p];
	p++;
	if('a'<=s[p]&&s[p]<='z'){
		a+=s[p];
		p++;
	}
	if(atoms.find(a)!=atoms.end()){
		return atoms[a];
	}else{
		return INT_MAX;
	}
}
ll molecule(string &s,int &p,map<string,int>&atoms);

ll molecule2(string &s,int &p,map<string,int>&atoms){
	if(s[p]=='('){
		p++;
		ll mass=molecule(s,p,atoms);
		assert(s[p]==')');
		p++;
		ll n=number(s,p);
		return mass*n;
	}else{
		ll mass=atom(s,p,atoms);
		if(isdigit(s[p])){
			ll n=number(s,p);
			return mass*n;
		}else{
			return mass;
		}
	}
}

ll molecule(string &s,int &p,map<string,int>&atoms){
	ll mass=molecule2(s,p,atoms);
	if(p<s.size()&&(s[p]=='('||isalpha(s[p]))){
		return mass+molecule(s,p,atoms);
	}else{
		return mass;
	}
}

int main(){
	string atom;
	map<string,int> atoms;
	while(cin>>atom,atom!="END_OF_FIRST_PART"){
		int w;cin>>w;
		atoms[atom]=w;
	}
	string formula;
	while(cin>>formula,formula!="0"){
		int pos=0;
		ll ans=molecule(formula,pos,atoms);
		if(ans>=INT_MAX){
			cout<<"UNKNOWN"<<endl;
		}else{
			cout<<ans<<endl;
		}
	}
}

Measured memory_bytes: 1228
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = 0
    for a in A:
        B ^= a

    ans = []
    for a in A:
        ans.append(a ^ B)

    print(*ans, sep=" ")


if __name__ == "__main__":
    main()


Measured memory_bytes: 31372
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;

LL gcd(LL a, LL b) {
  return b ? gcd(b, a % b) : a;
}

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

  LL lcm = c * d / gcd(c, d);

  LL x = b - ((b / c) + (b / d) - (b / lcm));
  LL y = a - ((a / c) + (a / d) - (a / lcm));
  cout << x - y << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef long long ll;
#define sz(a) int((a).size()) 
#define pb push_back 
#define all(c) (c).begin(),(c).end() 
#define rep(i, n) for(int i = 0; i < n; ++i) 
#define foreach(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) 

#define TRACE(x...) x
#define watch(x) TRACE(cout << #x" = " << x << endl)
#define watcharr(i, x) TRACE(cout << #x" = "); rep(i, sz(x)) cout << x[i] << " "; cout << endl

int main() {
	
	ifstream infile("input.in");
	if(infile.good()) cin.rdbuf(infile.rdbuf());
	
    int X; cin >> X;

    vector<ll> v;
    ll a = 0, kp = 0, kn = 0;
    while(kn - kp < X) {
        kp = kn;
        kn = pow(a++, 5.0);
        v.pb(kn);
    }

    int ra = 0, rb = 0;
    rep(i, sz(v)) {
        ll b5 = v[i] - X;
        rep(j, sz(v)) 
            if(v[j] == abs(b5))
                ra = i, rb = j * (b5 >= 0 ? 1 : -1);
    }

    cout << ra << " "  << rb << endl;

	if(infile.good()) infile.close();
	return 0;
	
}


Measured memory_bytes: 4120
from collections import deque

# input
H, W = map(int, input().split())
H += 2
W += 2

S = [["#"]*W]+[list("#"+input()+"#") for _ in range(H-2)]+[["#"]*W]

# process
ans = 0

# (r,c)がスタートの場合を順に確認
for r in range(1, H-1):
    for c in range(1, W-1):
        if S[r][c] == "#":
            continue

        # スタートから該当マスまでの移動回数
        dist = [[-1]*W for _ in range(H)]
        dist[r][c] = 0

        dq = deque([(r, c)])

        while dq:
            cr, cc = dq.popleft()
            
            if dist[cr][cc] > ans:
                # 移動回数の最大値更新
                ans = dist[cr][cc]
            
            for nr, nc in ((cr+1, cc), (cr-1, cc), (cr, cc+1), (cr, cc-1)):
                if S[nr][nc] == "." and dist[nr][nc] == -1:
                    dist[nr][nc] = dist[cr][cc]+1
                    dq.append((nr, nc)) 

# output
print(ans)


Measured memory_bytes: 3316
n = int(input())
a = list(map(int,input().split()))
minus_num = 0
for i in range(n):
    if a[i] < 0:
        minus_num += 1
if minus_num % 2 == 0:
    ans = 0
    for i in range(n):
        ans += abs(a[i])
else:
    min_abs = abs(a[0])
    ans = 0
    for i in range(n):
        ans += abs(a[i])
        min_abs = min(min_abs, abs(a[i]))
    ans = ans - min_abs * 2
print(ans)


Measured memory_bytes: 14412
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n,A,a=0,b=0,c=0;
    cin>>n;
    rep(i,n){
        cin>>A;
        if(A%4==0) a++;
        else if(A%2==0) b++;
        else c++;
    }
    if(b) c++;
    if(a+1>=c) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256