akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

//最後をとっている場合
// ll dptake[MAX][MAX];
//最後をとっていない場合
// ll dpnot[MAX][MAX];

int main(){
  ll N;cin>>N;
  vector<ll> a(N);
  rep(i,N) cin>>a[i];


  ll ans = 0;

  //最後をとっている場合
  ll dptake[MAX][3];

  //最後をとっていない場合
  ll dpnot[MAX][3];


  dptake[0][1] = a[0];

  for(ll i = 1; i < N; i++){
    if(i % 2 == 1){
      //notで遅れ
      dpnot[i][0] = max(dpnot[i-1][0], dptake[i-1][0]);
      //takeして進んでいる
      dptake[i][1] = dpnot[i-1][0] + a[i];
      //notして進んでいる
      dpnot[i][1] = dptake[i-1][1];
    }
    else{
      //takeで遅れている
      dptake[i][0] = dpnot[i-1][0] + a[i];
      //notで遅れ
      dpnot[i][0] = max(dptake[i-1][1] , dpnot[i-1][1]);
      //takeで進んでいる
      dptake[i][1] = dpnot[i-1][1] + a[i];
    }
  }

  // cout<<dptake[N-1][1]<<endl;
  if(N%2==0){
    cout<<max(dptake[N-1][1], dpnot[N-1][1])<<endl;
  }
  else cout<<max(dptake[N-1][0], dpnot[N-1][0])<<endl;

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N;
string S;

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

  cin>>N>>S;
  ll cnt=0;
  ll res=1;
  rep(i,2*N){
    if(cnt%2==1){
      if(S[i]=='W'){
        cnt++;
      }else{
        if(cnt==0){
          cout<<0<<endl;
          return 0;
        }
        res*=cnt;
        res%=mod;
        cnt--;
      }
    }else{
      if(S[i]=='W'){
        if(cnt==0){
          cout<<0<<endl;
          return 0;
        }
        res*=cnt; res%=mod;
        cnt--;
      }else{
        cnt++;
      }
    }
  }
  if(cnt>0){
    cout<<0<<endl;
    return 0;
  }
  repl(i,1,N+1)(res*=i)%=mod;
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 720
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

int solve()
{
    int N;

    std::cin >> N;

    int last = N % 10;

    if (last == 3)
        cout << "bon" << endl;
    else if (last == 0 || last == 1 || last == 6 || last == 8)
        cout << "pon" << endl;
    else
        cout << "hon" << endl;


    return 0;
}

int main()
{
//    std::cout << solve() << std::endl;
    solve();

    return 0;
}

Measured memory_bytes: 3656
q = sorted(list(zip(map(int, input().split()), (25, 50, 100, 200))),
           key=lambda a: a[0] / a[1])
n = int(input()) * 100
total = 0
for i in range(len(q)):
    n_buy = (n // q[i][1])
    tmp = n_buy * q[i][1]
    n -= tmp
    total += n_buy * q[i][0]
print(int(total))


Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

class UFTree {
  vector<int> m_parent;
  vector<int> m_height;
  vector<int> m_size;

 public:
  UFTree(int size) {
    for (int i = 0; i < size; i++) {
      m_parent.push_back(i);
      m_height.push_back(0);
      m_size.push_back(1);
    }
  }

  int root(int node) {
    if (m_parent[node] == node) {
      return node;
    }
    return m_parent[node] = root(m_parent[node]);
  }
  void merge(int n0, int n1) {
    int r0 = root(n0), r1 = root(n1);
    if (r0 == r1) {
      return;
    }
    if (m_height[r0] < m_height[r1]) swap(r0, r1);
    if (m_height[r0] == m_height[r1]) m_height[r0]++;
    m_parent[r1] = r0;
    m_size[r0] += m_size[r1];
  }
  int size(int node) { return m_size[root(node)]; }
};

int main() {
  int N, M;
  cin >> N >> M;
  UFTree uft(N);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    uft.merge(a, b);
  }

  int result = 0;
  vector<bool> isChecked(N, false);
  rep(i, N) {
    if (not isChecked[uft.root(i)]) {
      chmax(result, uft.size(uft.root(i)));
      isChecked[uft.root(i)] = true;
    }
  }
  cout << result << endl;
  return 0;
}

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

int main(){
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    string s;
    cin >> s;
    
    string ans = "Yes";
    int max_ = 0, count = 0;
    if(c>d){
        for(int i = b-2; i <= d; i++){
            if(s.at(i) == '.') count++;
            else count = 0;
            max_ = max(max_, count);
        }
        if(max_<3) ans = "No";
    }
    count = 0;
    for(int i = a-1; i < c; i++){
        if(s.at(i) == '#') count++;
        else count = 0;
        if(count>=2) ans = "No";
    }
    count = 0;
    for(int i = b-1; i < d; i++){
        if(s.at(i) == '#') count++;
        else count = 0;
        if(count>=2) ans = "No";
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int h,w,n;
signed main(){
	
	cin>>n;
	cout<<n/500*1000+(n%500)/5*5<<endl;
	
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include <assert.h>
typedef int64_t ll;
typedef uint64_t ull;
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (1000000000)
#define MOD (1000000007)

ll d[100000];
ll dn[100000];
ll dp[100][100000];
int main(void)
{
    ll n,k;
    scanf("%ld %ld",&n,&k);
    ll dc=1;
    d[0]=1;
    while((n/d[dc-1])!=1)
    {
        d[dc] = (n/(n/d[dc-1]))+1;
        dc++;
    }
    for(int i=0;i<dc-1;i++) dn[i] = d[i+1]-d[i];
    dn[dc-1] = n-d[dc-1]+1;
    for(int i=0;i<dc;i++) dp[0][i] = dn[i];

    for(int i=1;i<k;i++)
    {
        ll s = 0;
        for(int j=dc-1;j>=0;j--)
        {
            s = (s+dp[i-1][(dc-1)-j])%MOD;
            dp[i][j] = s * dn[j] %MOD;
        }
    }
    ll ans=0;
    for(int i=0;i<dc;i++) ans= (ans +dp[k-1][i])%MOD;
    printf("%ld\n",ans);

    return 0;
}


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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define loop(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v) rep(i,v.size()) {cin >> v[i];}

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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }


int toi(string s){
  return ctoi(s[0])*10+ctoi(s[1]);
}

int main(void){
  string s;cin >> s;
  string head,tail;
  head=s.substr(0,2);tail=s.substr(2,2);
  if(toi(head)<=12&&toi(tail)<=12&&toi(head)>0&&toi(tail)>0)
    cout << "AMBIGUOUS" << endl;
  else if(toi(head)<=12&&toi(head)>0)
    cout << "MMYY" << endl;
  else if(toi(tail)<=12&&toi(tail)>0)
    cout << "YYMM" << endl;
  else cout << "NA" << endl;


  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.string, std.array, std.math, std.range;

struct Pt {
  int x, y;
}

void main()
{
  const N = readln.chomp.to!int;
  
  auto pts = new Pt[N];
  foreach (ref pt; pts) readf(" %d %d ", &pt.x, &pt.y);
  
  const nstair = {
    long x = 1;
    foreach (i; 1..N+1) x *= i;
    return x;
  }();
  
  double avg = 0;
  foreach (perm; iota(N).permutations) {
    foreach (i; 1..N) {
      const prev = pts[perm[i-1]];
      const now  = pts[perm[i]];
      avg += sqrt((prev.x-now.x).pow(2) + (prev.y-now.y).pow(2)*1.0) / nstair;
    }
  }
  writefln("%.10f", avg);
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
vector<double> T,TT,V,Limit;
double f(double t) {
    double MAXV = 1e9;
    rep(i,N) {
        if (t > TT[i+1]) {
            chmin(MAXV,V[i]+t-TT[i]);
        } else if (TT[i] <= t && t <= TT[i+1]) {
            double L = min({V[i]+t-TT[i],V[i+1],V[i+2]+TT[i+1]-t});
            chmin(MAXV,L);
        } else {
            chmin(MAXV,V[i+2]+TT[i+1]-t);
        }
    }
    return MAXV;
} 

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> N;
    T.resize(N),V.resize(N+2);
    rep(i,N) cin >> T[i];
    rep(i,N) cin >> V[i+1];

    TT.resize(N+1);
    rep(i,N) TT[i+1] = TT[i] + T[i];
    int M = int(TT[N])*2;
    Limit.resize(M+1); 
    rep(i,M) {
        Limit[i+1] = f(double(i+1)/2.0);
    }
    double ans = 0.0;
    rep(i,M) {
        ans += (Limit[i+1]+Limit[i])/2.0*0.5;
    }

    cout << fixed << setprecision(10) << ans << endl;

}

Measured memory_bytes: 640
N, K = map(int, input().split())
P = list(map(lambda a: int(a) - 1, input().split()))
C = list(map(int, input().split()))
INF = 10**18

grp = []
visited = [False] * N

for i in range(N):
    if visited[i]:
        continue
    V = []
    while not visited[i]:
        V.append(i)
        visited[i] = True
        i = P[i]
    grp.append(V)

def solve(V, K):
    N = len(V)
    sumC = 0
    for v in V:
        sumC += C[v]

    ans = 0
    if sumC > 0 and K >= N:
        q, K = divmod(K, N)
        K += N
        ans = sumC * (q - 1)
    else:
        K = min(K, N)

    if K == 0:
        return ans

    def calc(now):
        acc = C[now]
        ret = acc
        for _ in range(K - 1):
            now = P[now]
            acc += C[now]
            ret = max(ret, acc)
        return ret

    mx = -INF
    for start in V:
        mx = max(mx, calc(start))

    return mx + ans

ans = max(C)
for V in grp:
    ans = max(ans, solve(V, K))
print(ans)




Measured memory_bytes: 74932
#include <bits/stdc++.h>
using namespace std;
int h,w,dx[]={0,1,0,-1},dy[]={-1,0,1,0};
string mp[55];
struct po{
  int x,y,dir;
  po(int y,int x,int dir): x(x),y(y),dir(dir){}
};

int check(int y,int x,int dir){
  dir=(dir+3)%4;
  return mp[y+dy[dir]][x+dx[dir]]=='#';
}

int bfs(int sy,int sx,int sdir){
  int D[55][55][4],used[55][55]={};
  memset(D,-1,sizeof(D));
  queue <po> Q;
  Q.push(po(sy,sx,sdir));
  D[sy][sx][sdir]=1;

  while(!Q.empty()){
    po t=Q.front();Q.pop();
    int x=t.x,y=t.y,dir=t.dir;
    int nx=x+dx[dir],ny=y+dy[dir];
    if(mp[y][x]=='G') return D[y][x][dir];
    used[y][x]=1;

    if(mp[ny][nx]!='#'){
      if(check(ny,nx,dir+2)&&D[ny][nx][dir]==-1){
	Q.push(po(ny,nx,dir));
	D[ny][nx][dir]=D[y][x][dir]+!used[ny][nx];
      }
      else if(D[ny][nx][(dir+1)%4]==-1){
	Q.push(po(ny,nx,(dir+1)%4));
	D[ny][nx][(dir+1)%4]=D[y][x][dir]+!used[ny][nx];
      }   
    }


    if(check(y,x,dir+1)&&check(y,x,dir+2)&&D[y][x][(dir+3)%4]==-1){
      Q.push(po(y,x,(dir+3)%4));
      D[y][x][(dir+3)%4]=D[y][x][dir];
    }
  }
  return -1;
}

int main(){
  cin>>h>>w;
  for(int i=0;i<=w+1;i++) mp[0]+='#',mp[h+1]+='#';
  for(int i=1;i<=h;i++) cin>>mp[i],mp[i]='#'+mp[i]+'#';

  int sx,sy,dir;
  for(int i=0;i<=h;i++)
    for(int j=0;j<=w;j++) {
      if(mp[i][j]=='^')dir=0,sy=i,sx=j;
      if(mp[i][j]=='>')dir=1,sy=i,sx=j;
      if(mp[i][j]=='v')dir=2,sy=i,sx=j;
      if(mp[i][j]=='<')dir=3,sy=i,sx=j;
    }

  cout <<bfs(sy,sx,dir)<<endl; 
  
  return 0;
}

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

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
vector<int> a;
int n;
vector<ll> sol[2];
vector<ll> suffix;
ll solve(int x)
{
    int i=lower_bound(a.begin(),a.end(),x)-a.begin();
    //printf("%i\n",i);
    if(i==n)
        return sol[0][n-1];
    int l=i,r=n-1;
    while(l<r)
    {
        int mid=(l+r)>>1;
        int num=mid-i+1;
        int diff=a[mid]-x;
        assert(diff>=0);
        int j=lower_bound(a.begin(),a.end(),x-diff)-a.begin();
        num=i-j+num;
        int drugi=n-mid-1;
        if(drugi<num)
            r=mid;
        else
            l=mid+1;
    }
    int num=l-i+1;
    int diff=a[l]-x;
    assert(diff>=0);
    int j=lower_bound(a.begin(),a.end(),x-diff)-a.begin();
    num=i-j+num;
    int drugi=n-l-1;
    if(num==drugi)
    {
        ll s=suffix[l+1];
        if(j>0)
            s+=sol[0][j-1];
        return s;
    }
    if(num==drugi-1)
    {
        ll s=suffix[l+1];
        if(j>0)
            s+=sol[1][j-1];
        return s;
    }
    ll s=suffix[l];
    num--;
    drugi++;
    int pos=j-1+num-drugi;
    if(pos>=0)
        s+=sol[0][pos];
    return s;
}
int main()
{
	int q;
	scanf("%i %i",&n,&q);
	a.resize(n);
	sol[0].resize(n);
    sol[1].resize(n);
    suffix.resize(n);
	for(int i=0;i<n;i++)
        scanf("%i",&a[i]);
    a.pb({INT_MAX});
    sol[0][0]=a[0];
    sol[1][0]=0;
    suffix[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--)
        suffix[i]=(ll)suffix[i+1]+a[i];
    for(int i=1;i<n;i++)
    {
        sol[0][i]=(ll)a[i]+sol[1][i-1];
        sol[1][i]=sol[0][i-1];
    }
    for(int i=0;i<q;i++)
    {
        int x;
        scanf("%i",&x);
        printf("%lld\n",solve(x));
    }
    return 0;
}


Measured memory_bytes: 4472
#include <iostream>
#include <string>
#include <algorithm>
#include <stdlib.h>
#include <iomanip>
#include <vector>
#include <cmath>
#include <bits/stdc++.h>
using namespace std;
//typedef long long unsigned int ll;
typedef long long ll;
typedef pair<ll, ll> p;
//typedef tuple<ll, ll, ll> tp;
const ll INF = 1e18;
const ll mod = 1e9+7;

int main() {
  ll n, k;
  cin >> n >> k;
  ll A[n];
  for(int i=0;i<n;i++) cin >> A[i];
  
  ll ans = 0;
  for (int d = 40; d >= -1; --d) {
    if (d != -1 && !(k & (1LL<<d))) continue;
        
    ll tmp = 0;
    for (int e = 40; e >= 0; --e) {
      ll mask = 1LL<<e;
      ll num = 0;
      for (int i = 0; i < n; ++i) if (A[i] & mask) ++num;
            
      if (e > d) {
        if (k & mask) tmp += mask * (n - num);
        else tmp += mask * num;
      }
      else if (e == d) {
        tmp += mask * num;
      }
      else {
        tmp += mask * max(num, n - num);
      }
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <cmath>
using namespace std;
typedef long long int ll;

int main()
{
 ll n,m;
 cin>>n>>m;
  ll sum=0;
  for(ll i=0;i<m;i++)
  { ll x;
  cin>>x;
      sum+=x;
  }
  if(sum>n) 
   cout<<-1;
   else {
  cout<<n-sum;
   }
 return 0;

}

Measured memory_bytes: 3636
N = int(input())

bool = False

for i in range(N//7 +1):
  for j in range(N//4 +1):
    if 7 * i + 4 * j == N:
      bool = True
      break
    else:
      continue
      
if bool == True:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = unsigned long long;
using P = pair<int, int>;
const int INF = 1e9;

int main() {
  int k;
  cin >> k;
  vector<ll> a;
  for (int i = 1; i <= 9; ++i) a.push_back(i);
  while (1) {
    if (k <= a.size()) {
      cout << a[k-1] << endl;
      return 0;
    }
    k -= a.size();
    vector<ll> old;
    swap(old, a);
    for (ll x : old) {
      for (int i = -1; i <= 1; ++i) {
        int d = x%10 + i;
        if  (d < 0 || d > 9) continue;
        ll nx = x*10 + d;
        a.push_back(nx);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1840
N,K = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

d = 40
cnt = Array.new(d){[0,0]}
memo = [0]*d
ans = []

bit = 1
d.times do |i|
	a.each do |v|
		cnt[i][v&bit == 0 ? 0 : 1] += 1 
	end 
	bit *= 2
end

#前処理
memo[0] = cnt[0].max
bit = 2
1.upto(d-1) do |i|
	memo[i] = memo[i-1] + cnt[i].max * bit
	bit *= 2
end

bit = 2 ** (d-1)
tmp = 0
(d-1).downto(0) do |i|
	if bit&K > 0
		ans << memo[i-1] + cnt[i][1] * bit + tmp if i>0
		tmp += cnt[i][0] * bit
	else
		tmp += cnt[i][1] * bit
	end
	bit /= 2
end
ans << tmp
p ans.max

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

using namespace std;
typedef long long ll;

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; }

ll fac[10000000], finv[10000000], inv[10000000];

ll MOD = ll(1e9)+7;


void COMinit()
{
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[0]=inv[1]=1;

  for(int i=2; i<10000000; 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 COM(ll n, ll k)
{
  if(n<k)
    return 0;
  else
    return fac[n]*(finv[n-k]*finv[k]%MOD)%MOD;
}
       



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

  COMinit();

  for(int i=1; i<K+1; i++)
    {      
      cout << COM(N-K+1, i)*COM(K-1, i-1)%MOD << endl;
    }
 

  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



Measured memory_bytes: 234624
#include<iostream>
#define rep(i,n) for(int i=0; i<(n); ++i)

int main(){
    std::string s; std::cin >> s;
    int sz=s.size();
    int sum=0;
    rep(i,sz) sum += s[i]-'0';
    std::cout << (sum%9 ? "No" : "Yes") << std::endl;
    return 0;
}

Measured memory_bytes: 3684
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

char ans[51];

int main(void){
	int n, m, i, j;
	char s[51], t[51];
	scanf("%s%s", s, t);
	n=strlen(s);
	m=strlen(t);
	if(n<m){
		puts("UNRESTORABLE");
		return 0;
	}
	int_fast8_t f=0;
	for(i=n-m; i>=0; i--){
		char now[51];
		for(j=0; j<i; j++){
			if(s[j]=='?') now[j]='a'; else now[j]=s[j];
		}
		int_fast8_t g=1;
		for(j=i; j<i+m; j++){
			if(s[j]!='?' && s[j]!=t[j-i]){g=0; break;}
			now[j]=t[j-i];
		}
		if(g==0) continue;
		for(j=i+m; j<n; j++){
			if(s[j]=='?') now[j]='a'; else now[j]=s[j];
		}
		if(f==0 || strncmp(now, ans, n)<0) strncpy(ans, now, n);
		f=1;
	}
	if(f==0){
		puts("UNRESTORABLE");
		return 0;
	}
	ans[n]=0;
	printf("%s\n", ans);
}


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

const int mod = 1e9 + 7;

int main() {
    int n; cin >> n;
    long long tot8 = 1;
    long long tot9 = 1;
    long long tot10 = 1;
    for(int i=0; i<n; i++){
        tot8 = (tot8 * 8) % mod;  
        tot9 = (tot9 * 9) % mod;  
        tot10 = (tot10 * 10) % mod;  
    }
    tot9 = tot9 - tot8;
    //cout << tot8 << " "  << tot9 << " " << tot10 << endl;
    long long ans = (tot10 - tot9 * 2 - tot8 + mod + mod) % mod;
    cout << ans << endl;
}


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int N, K;
	cin >>N >>K;
	vector<long> x(N+1, 0), y(N+1, 0);
	for (int i=1; i<=N; i++)
		cin >>x.at(i) >>y.at(i);
	vector<long> X=x, Y=y;
	sort(X.begin()+1, X.end());
	sort(Y.begin()+1, Y.end());
	// Table of dots, 1=dot, 0=no_dot
	vector<vector<int>> p(N+1, vector<int> (N+1, 0));
	for (int i=1; i<=N; i++) {
		int XX=lower_bound(X.begin()+1, X.end(), x.at(i))-X.begin();
		int YY=lower_bound(Y.begin()+1, Y.end(), y.at(i))-Y.begin();
		p.at(XX).at(YY)=1;
	}
	// Table of number of dots in the rectangle with the point at right top corner
	vector<vector<int>> r(N+1, vector<int> (N+1, 0));
	for (int i=1; i<=N; i++)
		for (int j=1, D=0; j<=N; j++) {
			if (1==p.at(i).at(j))
				D++;
			r.at(i).at(j)=r.at(i-1).at(j)+D;
		}
	long S=2000000000;
	S *=S;
	for (int i=1; i<=N; i++) {
		for (int j=1; j<=N; j++) {
			int ii=N;
			int jj=j;
			while((ii>=i)&&(jj<=N)) {
				int Dots=r.at(ii).at(jj)+r.at(i-1).at(j-1)-r.at(ii).at(j-1)-r.at(i-1).at(jj);
				if (K>Dots)
					jj++;
				else {
					if (K==Dots)
						S=min(S, (X.at(ii)-X.at(i))*(Y.at(jj)-Y.at(j)));
					ii--;
				}
			}
		}
	}
	cout <<S <<endl;
	return 0;
}



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

using namespace std;

struct item_t {
  int weight, value;
  bool operator<(const item_t& other) const {
    return value > other.value;
  }
};

int main() {
  int N, W;
  cin >> N >> W;
  vector<item_t> items[4];
  vector<int> w(N), v(N);
  int w0;
  for (int i = 0; i < N; i++) {
    int w, v;
    cin >> w >> v;
    if (i == 0) w0 = w;
    items[w - w0].push_back((item_t){w, v});
  }

  for (int i = 0; i < 4; i++) {
    sort(items[i].begin(), items[i].end());
  }

  int w_sum[4] = {}, v_sum[4] = {};
  int v_max = 0;
  for (int n0 = 0; n0 <= items[0].size(); n0++) {
    // printf("n0 = %d\n", n0);
    if (n0 > 0) {
      w_sum[0] += items[0][n0-1].weight;
      v_sum[0] += items[0][n0-1].value;
    }
    w_sum[1] = 0;
    v_sum[1] = 0;
    if (w_sum[0] > W) break;
    for (int n1 = 0; n1 <= items[1].size(); n1++) {
      // printf("n1 = %d\n", n1);
      if (n1 > 0) {
        w_sum[1] += items[1][n1-1].weight;
        v_sum[1] += items[1][n1-1].value;
      }
      w_sum[2] = 0;
      v_sum[2] = 0;
      if (w_sum[0] + w_sum[1] > W) break;
      for (int n2 = 0; n2 <= items[2].size(); n2++) {
        // printf("n2 = %d\n", n2);
        if (n2 > 0) {
          w_sum[2] += items[2][n2-1].weight;
          v_sum[2] += items[2][n2-1].value;
        }
        w_sum[3] = 0;
        v_sum[3] = 0;
        if (w_sum[0] + w_sum[1] + w_sum[2] > W) break;
        for (int n3 = 0; n3 <= items[3].size(); n3++) {
          // printf("n3 = %d\n", n3);
          if (n3 > 0) {
            w_sum[3] += items[3][n3-1].weight;
            v_sum[3] += items[3][n3-1].value;
          }
          if (w_sum[0] + w_sum[1] + w_sum[2] + w_sum[3] > W) break;
          if (v_sum[0] + v_sum[1] + v_sum[2] + v_sum[3] > v_max) {
            v_max = v_sum[0] + v_sum[1] + v_sum[2] + v_sum[3];
          }
        }
      }
    }
  }

  cout << v_max << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

char s[1000000]; int n; long long ans;

int main() {
	scanf("%s", s), n = strlen(s);
	for (int i = 0, j = 0; i < n; ++i)
		if (s[i] == 'W') ans += i - j, ++j;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
    }
    let mut l = vec![vec![0; 10]; 10];
    for i in 1..(n + 1) {
        let i = i.to_string();
        let first = i[..1].parse::<usize>().unwrap();
        let end = i[i.len() - 1..].parse::<usize>().unwrap();

        l[first][end] += 1
    }

    let mut ans = 0;
    for i in 0..10 {
        for j in 0..10 {
            ans += l[i][j] * l[j][i];
        }
    }
    println!("{}", ans);
}


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

using namespace std;

int main(){
    int h,w,k;
    cin >> h >> w >> k;

    int sum=0;

    vector<vector<int>> c(h,vector<int>(w));

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            char tmp;
            cin >> tmp;
            if(tmp=='#'){
                c[i][j]=1;
                //sum++;
            }else{
                c[i][j]=0;
            }
        }
    }
    /*
    vector<int> row(h,0);
    vector<int> column(w,0);

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(c[i][j]==1){
                row[i]++;
            }
        }
    }

    for(int i=0; i<w; i++){
        for(int j=0; j<h; j++){
            if(c[j][i]==1){
                column[i]++;
            }
        }
    }
    */

    for (int bith = 0; bith < (1<<h); ++bith) {
        for (int bitw = 0; bitw < (1<<w); ++bitw) {
            vector<vector<int>> tmp = c;
            int ksum=0;
            for (int i = 0; i < h; ++i) {
                if (bith & (1<<i)) { // 列挙に i が含まれるか
                    for(int l=0;l<w;l++){
                        tmp[i][l]=-1;
                    }
                }
            }
            for (int j = 0; j < w; ++j) {
                if (bitw & (1<<j)) { // 列挙に i が含まれるか
                    for(int l=0;l<h;l++){
                        tmp[l][j]=-1;
                    }
                }
            }

            for(int i=0; i<h; i++){
                for(int j=0; j<w; j++){
                    if(tmp[i][j]==1){
                        ksum++;
                    }
                }
            }

            if(ksum==k){
                sum++;
            }
        }
    }

    cout << sum << endl;

}

Measured memory_bytes: 3628
import java.util.Scanner;
public class Main {
	private static Scanner s = new Scanner(System.in);
public static void main(String[] args) {
	int n = s.nextInt();
	int[] a = new int[n+1];
	StringBuilder sb = new StringBuilder();

	for(int i = 1;i <= n;i++) {
		a[i] = s.nextInt();
	}

	for(int i = 1;i <= n;i++) {
		sb.append("node "+i+": key = "+ a[i] + ", ");
		if(i/2 >= 1) {
			sb.append("parent key = " + a[i/2] + ", ");
		}
		if(i*2 <= n) {
			sb.append("left key = " + a[i*2] +", ");
		}
		if((i*2+1) <= n) {
			sb.append("right key = " + a[i*2+1] + ", ");
		}
		sb.append("\n");
	}
	System.out.print(sb);
}
}


Measured memory_bytes: 26224
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    string s;
    cin >> s;
    bool f = true;
    for (int i = 0; i < s.length(); i++)
    {
        for (int j = i + 1; j < s.length(); j++)
        {
            if (s[i] == s[j])
            {
                f = false;
            }
        }
    }
    if (f == true)
    {
        cout << "yes" << endl;
    }
    else
    {
        cout << "no" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }


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

    if(K%2==0)cout << (K/2)*(K/2)<< endl;
    else cout << ((K+1)/2)*(K/2) << endl;
}



Measured memory_bytes: 3556
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n, xa[52], ya[52], xb[52], yb[52], xc[102], yc[102], xd[52], yd[52], xe[52], ye[52], f[103][103]; long long d[103][103];
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
void rec(int x, int y) {
	f[y][x] = true;
	for (int i = 0; i < 4; i++) {
		int tx = x + dx[i], ty = y + dy[i];
		if (0 <= tx && tx <= 2 * n + 1 && 0 <= ty && ty <= 2 * n + 1) {
			if (d[y][x] == d[ty][tx] && !f[ty][tx]) rec(tx, ty);
		}
	}
}
int main() {
	while (scanf("%d", &n), n) {
		for (int i = 0; i < n; i++) {
			scanf("%d%d%d%d", xa + i, yb + i, xb + i, ya + i);
			xc[2 * i] = xa[i], yc[2 * i] = ya[i], xc[2 * i + 1] = xb[i], yc[2 * i + 1] = yb[i];
		}
		sort(xc, xc + 2 * n);
		sort(yc, yc + 2 * n);
		memset(xd, 0, sizeof(xd));
		memset(yd, 0, sizeof(yd));
		memset(xe, 0, sizeof(xe));
		memset(ye, 0, sizeof(ye));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 2 * n; j++) {
				if (xa[i] == xc[j] && !xd[i]) xa[i] = j + 1, xd[i] = 1;
				if (ya[i] == yc[j] && !yd[i]) ya[i] = j + 1, yd[i] = 1;
				if (xb[i] == xc[j] && !xe[i]) xb[i] = j + 1, xe[i] = 1;
				if (yb[i] == yc[j] && !ye[i]) yb[i] = j + 1, ye[i] = 1;
			}
		}
		memset(d, 0, sizeof(d));
		memset(f, 0, sizeof(f));
		for (int i = 0; i < n; i++) {
			for (int j = xa[i]; j < xb[i]; j++) {
				for (int k = ya[i]; k < yb[i]; k++) {
					d[j][k] += (1LL << i);
				}
			}
		}
		int ret = 0;
		for (int i = 0; i <= 2 * n + 1; i++) {
			for (int j = 0; j <= 2 * n + 1; j++) {
				if (!f[i][j]) {
					rec(j, i); ret++;
				}
			}
		}
		printf("%d\n", ret);
	}
}

Measured memory_bytes: 3784
A, B, M = map(int, raw_input().split())
a = map(int, raw_input().split())
b = map(int, raw_input().split())

xyc = []
for i in range(M):
    xyci = map(int, raw_input().split())
    xyc.append(xyci)

a_min = min(a)
b_min = min(b)

ans = a_min + b_min

for i in range(M):
    xi = xyc[i][0]-1
    yi = xyc[i][1]-1
    ci = xyc[i][2]

    cost = a[xi]+ b[yi] -ci
    ans = min(ans, cost)

print ans



Measured memory_bytes: 30348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
ll inf=1e17,MX=1e15;
vector< pair<ll,ll> > g1[N],g2[N];
ll dist1[N],dist2[N],ans[N];
void dijkstra(vector< pair<ll,ll> > g[],ll dist[],ll s,ll n){
    for(ll i=1;i<=n;i++)dist[i]=inf;
    dist[s]=0;
    priority_queue< pair<ll,ll> , vector< pair<ll,ll> >  , greater< pair<ll,ll> >  >pq;
    pq.push({0,s});
    while(!pq.empty()){
        auto node=pq.top();
        pq.pop();
        ll u = node.second;
        if(dist[u]<node.first)continue;
        for(auto &v:g[u]){
            if(dist[u]+v.second < dist[v.first]){
                dist[v.first] = dist[u] + v.second;
                pq.push({dist[v.first] ,v.first});
            }
        }
    }
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,m,s,t;cin>>n>>m>>s>>t;
    for(ll i=1;i<=m;i++){
        ll u,v,a,b;cin>>u>>v>>a>>b;
        g1[u].push_back({v,a});
        g1[v].push_back({u,a});
        g2[u].push_back({v,b});
        g2[v].push_back({u,b});
    }
    dijkstra(g1,dist1,s,n);
    dijkstra(g2,dist2,t,n);
    for(ll u=1;u<=n;u++)ans[u]=dist1[u]+dist2[u];
    for(ll i=n-1;i>=1;i--)ans[i]=min(ans[i],ans[i+1]);
    for(ll i=1;i<=n;i++)cout<<MX-ans[i]<<"\n";
}



Measured memory_bytes: 19196
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v

n = int(input())
A = [int(input()) for i in range(n)]

cnt = 0
G = [1]
for i in range(99):
    if n < 1 + 3*G[-1]:
        break
    G.append(1 + 3*G[-1])
m = len(G)
G.reverse()
for i in range(m):
    insertionSort(A, n, G[i])

print(m)
print(*G)
print(cnt)
print(*A, sep='\n')


Measured memory_bytes: 53284
A, B = map(int, input().split())

if A <= B:
    mincolor = "."
    maxcolor = "#"
    minnum = A
    maxnum = B
else:
    mincolor = "#"
    maxcolor = "."
    minnum = B
    maxnum = A
gridmap = []
for i in range(100):
    gridmap.append([mincolor]*100)
for i in range(1,100,2):
    for j in range(1,98,2):
        gridmap[i][j] = maxcolor
        maxnum -= 1
        if maxnum == 0:
            break
    if maxnum == 0:
        break

for k in range(0,100,2):
    for l in range(0,98,2):
        if minnum == 1:
            break
        gridmap[k][l+1], gridmap[k+1][l] = maxcolor, maxcolor
        minnum -= 1
        gridmap[i][j] = maxcolor
        if j == 97:
            j = 1
            i += 2
        else:
            j += 2
    if minnum == 1:
        break

print(100,100)
for i in range(100):
    ans = ""
    for j in range(100):
        ans += gridmap[i][j]
    print(ans)


Measured memory_bytes: 3188
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int N;
	string S;
	cin >> N >> S;
	int res = 0;
	for (int i = 0;i <= N - 3;++i) {
		if (S.substr(i, 3) == "ABC") res++;
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		sc.close();
		int n = str.length();

        StringBuffer sb2 = new StringBuffer(str);
		String dst2 = sb2.reverse().toString();
		if (str.compareTo(dst2) != 0) {
			System.out.println("No");
			return;
		}

		String sub1 = str.substring(0,(n-1)/2);
		StringBuffer sb = new StringBuffer(sub1);
		String dst = sb.reverse().toString();
		if (sub1.compareTo(dst) != 0) {
			System.out.println("No");
			return;
		}
		sub1 = str.substring((n+3)/2-1, n);
        sb = new StringBuffer(sub1);
		dst = sb.reverse().toString();
		if (sub1.compareTo(dst) != 0) {
			System.out.println("No");
			return;
		}



		System.out.println("Yes");
	}
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long


void solve(long long X, long long Y){
    if (abs(X - Y) <= 1) {
        cout << "Brown" << endl;
    } else {
        cout <<"Alice" << endl;
    }
}

signed main(){
//    vector<vector<char>> dp(30, vector<char>(30));
//    for(int i = 0; i < 30; ++i) {
//        for(int j = 0; j <= i; ++j) {
//            int k = i - j;
//            dp[j][k] = 'L';
//            for(int l = 1; 2 * l <= j; ++l) {
//                if (dp[j - 2 * l][k + l] == 'L') {
//                    dp[j][k] = 'W';
//                }
//            }
//            for(int l = 1; 2 * l <= k; ++l) {
//                if (dp[j + l][k - 2 * l] == 'L') {
//                    dp[j][k] = 'W';
//                }
//            }
//        }
//    }
//    printf("   ");
//    for(int i = 0; i < 24; ++i) {
//        printf("%3lld", i);
//    }
//    cout << endl;
//    for(int i = 0; i < 30; ++i) {
//        printf("%3lld", i);
//        for(int j = 0; j < 24; ++j) {
//            printf("%3c", dp[i][j]);
//        }
//        printf("\n");
//    }
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(X, Y);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int		main()
{
	int	A,B,C;

	scanf("%d %d %d", &A, &B, &C);
	if ((A == B && B != C) || (B == C && B != A) ||(A == C && C != B))
		printf("Yes\n");
	else
		printf("No\n");
	return (0);
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int x, a, b;
/**********************************************/

int main(){
    cin >> x >> a >> b;
    
    if(abs(x-a) < abs(x-b)) cout << 'A' << endl;
    else cout << 'B' << endl;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int a,b,c,d,n;
int p(int a,int b,int c){return (char(b)=='+')?(a+c):(a-c);}
int main()
{
  scanf("%d",&n);
  a=n/1000,b=n/100-a*10,c=n/10-a*100-b*10,d=n%10;
  for(int i=0;i<2;i++)
    for(int j=0;j<2;j++)
      for(int k=0;k<2;k++)
        if(p(p(p(a,i*2+43,b),j*2+43,c),k*2+43,d)==7)
        {
          printf("%d",a);
          printf("%c%d%c%d%c%d=7\n",i*2+43,b,j*2+43,c,k*2+43,d);
          return 0;
        }
  return 0;
}

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

int main() {
	int i;
	string s;
	cin >> s;
	i=s.size()-1;
	if(s[i]=='s'){
		cout << s << "es" << endl;
	}else{
		cout << s << "s" << endl;
	}
	return 0;
}

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

int sum[100000], p[100000];
int main() {
	int n, m; scanf("%d%d", &n, &m);
	rep(i, m) {
		scanf("%d", &p[i]); p[i]--;
		if (i) {
			sum[min(p[i], p[i - 1])]++;
			sum[max(p[i], p[i - 1])]--;
		}
	}
	ll ans = 0;
	rep(i, n - 1) {
		if (i)sum[i] += sum[i - 1];
		ll a, b, c; scanf("%lld%lld%lld", &a, &b, &c);
		ans += min(sum[i] * a, c + sum[i] * b);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 3984
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>

#define INF_LL 9000000000000000000
#define INF 2000000000

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, PII> PPII;
typedef pair<int, PPII> PPPII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

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

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

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

int main(void){
	int n, k;
	while(cin >> n >> k && n && k){
	vector<int> input;
	vector<pair<pair<int, int>, ll> > con;
	bool there0 = false;
	REP(i, k){
		int a;
		cin >> a;
		if(a == 0) there0 = true;
		else input.push_back(a);
	}
	sort(input.begin(), input.end());
	int s = 0, e = 1, sz = 1;
	REP(i, input.size()-1){
		if(input[e] - input[e-1] <= 1){
			sz++;
			e++;
		}else{
			con.push_back({{input[s], input[e-1]}, sz});
			s = e;
			e++;
			sz = 1;
		}
	}
	con.push_back({{input[s], input[e-1]}, sz});
	if(con.size() == 1){
		int res = con[0].second;
		if(1 < con[0].first.first || con[0].first.second < n){
			if(there0) res++;
		}
		cout << res << endl;
		continue;
	}
	ll res = 0;
	REP(i, con.size()-1){
		int sa = con[i+1].first.first - con[i].first.second;
		if(sa == 2 && there0){
			res = max(res, con[i].second + con[i+1].second + 1);
		}else if(there0){
			res = max(res, con[i].second+1);
		}else{
			res = max(res, con[i].second);
		}
	}
	if(there0){
		res = max(res, con[con.size()-1].second+1);
	}else{
		res = max(res, con[con.size()-1].second);
	}
	cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define repd(i, a, b) for (int i = a; i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

ll dp[3005][3005][4];
int main()
{
    int r, c, k;
    cin >> r >> c >> k;
    vector<vector<int>> val(r + 1, vector<int>(c + 1, 0));
    rep(i, 0, k)
    {
        int t1, t2, v;
        cin >> t1 >> t2 >> v;
        val[t1][t2] = v;
    }
    rep(i, 1, r + 1)
    {
        rep(j, 1, c + 1)
        {
            rep(k, 0, 4)
            {
                if (k == 0)
                    dp[i][j][k] = max(dp[i][j - 1][k], *max_element(dp[i - 1][j], dp[i - 1][j] + 4));
                else if (val[i][j] != 0)
                {
                    dp[i][j][k] = max(dp[i][j - 1][k], dp[i][j - 1][k - 1] + val[i][j]);
                    if (k == 1)
                        dp[i][j][k] = max(dp[i][j][k], *max_element(dp[i - 1][j], dp[i - 1][j] + 4) + val[i][j]);
                }
                else
                    dp[i][j][k] = dp[i][j - 1][k];
            }
        }
    }
    cout << *max_element(dp[r][c], dp[r][c] + 4) << endl;
}


Measured memory_bytes: 320128