akhauriyash/Code-Regression huggingface dataset:
n = int(input())
mod = 10 ** 9 + 7
dp = [[[[1 if i==0 else 0 for i in range(n-2)] for j in range(4)] for k in range(4)] for l in range(4)]
dp[0][1][2][0] = 0
dp[0][2][1][0] = 0
dp[2][0][1][0] = 0
for i in range(n - 3):
    for j in range(4):
        for k in range(4):
            for l in range(4):
                if dp[j][k][l][i] == 0:
                    continue
                for m in range(4):
                    if k == 0 and l == 2 and m == 1:
                        continue
                    if k == 0 and l == 1 and m == 2:
                        continue
                    if k == 2 and l == 0 and m == 1:
                        continue
                    if j == 0 and l == 2 and m == 1:
                        continue
                    if j == 0 and k == 2 and m == 1:
                        continue
                    dp[k][l][m][i + 1] += dp[j][k][l][i]
                    dp[k][l][m][i + 1] %= mod
ans = 0
for j in range(4):
    for k in range(4):
        for l in range(4):
            ans += dp[j][k][l][n - 3]

print(ans % mod)

Measured memory_bytes: 3188
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  string W[N];
  REP(i,N)cin>>W[i];
  bool flag=1;
  map<string,int> m;
  m[W[0]]+=1;
  FOR(i,1,N){
    if(W[i].front() != W[i-1].back())flag=0;
    m[W[i]]+=1;
  }
  auto itr=m.begin();
  for(itr;itr!=m.end();++itr){
    // cout<<itr->second<<endl;
    if(itr->second>1)flag=0;
  }
  if(flag)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define int long long
using namespace std;
signed main(){
  int h;
  cin>>h;
  int ans = 0, mo = 1;
  while (h > 0)
  {
    ans += mo;
    mo *= 2;
    h /= 2;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1<<30;
const int mod=1000000007;    
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

int main(){
  int n;cin>>n;
  pint p[n];
  rep(i,n){
    cin>>p[i].first;
    p[i].second=i;
    }
  sort(p,p+n);
  int check[n];
  rep(i,n)check[p[i].second]=i;
  int cnt=0;
  rep(i,n){
    if((check[i]-i)&1)cnt++;
    }
  cout<<cnt/2<<endl;
  return 0;  
  }


Measured memory_bytes: 1408
N = int(input())
*A, = [(int(input()),1) for _ in [0]*N]
*B, = [(int(input()),-1) for _ in [0]*N]

mod = 10**9+7
fact = [1]*(N+1)
for i in range(N):
    fact[i+1] = fact[i]*(i+1)%mod

AB = A+B
AB.sort()
ans = 1
c = 0
d = 0
for l,ab in AB:
    if d*ab<0:
        ans *= abs(d)
        ans %= mod
    d += ab
    c += 1
print(ans)

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

#define ios ios_base::sync_with_stdio(false)
#define endl '\n'
#define max(a, b) ((a < b) ? b : a)
#define min(a, b) ((a< b) ? a : b)
#define int long long

using namespace std;

long long mod = 998244353;

int32_t main() {
    ios;

    int whiteSums = 0LL;
    int whites = 0LL;
    int counter = 1;

    char a[200001];
    cin >> a;
    for (int i = 0; i < 200001; ++i) {
        if (a[i] == 'W') {
            whiteSums += i + 1;
            whites++;
        } else if (a[i] != 'B') {
            break;
        }
    }

    cout << (whiteSums - (whites * (whites + 1)) / 2);

}



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

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

    int ai, idx1;
    for (int i=1; i<=N; i++) {
        cin >> ai;
        if (ai == 1) idx1 = i;
    }

    int ans;
    ans = (N-1 + (K-1)-1) / (K-1);
    // ans = ((idx1-1) + (K-1)-1) / (K - 1) + ((N-idx1) + (K-1)-1) / (K - 1);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second


//aacabaab
//aaaaacba

// 0 0 0 0 0 0 0 0              +0
//               |\
//   0 0 0 0 0 0 1 0            +1
//             | |\ \
//     0 0 0 0 1 2 1 0          +2
//           | | |\ \ \
//       0 0 1 2 3 2 1 0        +3


// h[i + offset] + add = H[i]

const int N = 1010101;
char s[N] , t[N];
int n , add[N] , h[N];
int x[N];

int main(){
    scanf("%d",&n);
    scanf("%s%s",s + 1 , t + 1);
    if(strcmp(s + 1 , t + 1) == 0) return puts("0") , 0;
    int offset = 0 , cur = n , sum = 0;
    for(int i=n,j=n;i>=1;--i) if(t[i] != t[i-1]){
        j = min(j , i);
        while(j >= 1 && s[j] != t[i]) --j;
        if(j == 0) return puts("-1") , 0;
        for(int k=cur+offset;cur>=i;)
            h[cur--] = sum += add[k--];
        //for(int k=j;k<=i-1;++k) x[k] = x[k + 1] + 1;
        sum -= add[i + offset];
        if(j != i){
            add[i + offset]++ , add[j + offset]--;
        }
        offset++;
        //cout << i << " " << j << " " << offset << " " << sum << endl;
    }
    for(int k=cur+offset;cur>=1;)
        h[cur--] = sum += add[k--];
    //rep(i,1,n+1) printf("%d%c",h[i]," \n"[i==n]);
    //rep(i,1,n+1) printf("%d%c",x[i]," \n"[i==n]);
    printf("%d\n",*max_element(h + 1 , h + n + 1) + 1);
    return 0;
}


Measured memory_bytes: 9728
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>

using namespace std;

bool DEBUG = false;

bool cmp(pair<int,int> a, pair<int,int> b) {
    return a.second > b.second || a.second == b.second && a.first > b.first;
}

int main(){
    int n,a,b;
    priority_queue<pair<int,int>, vector<pair<int,int> >, bool(*)(pair<int,int>,pair<int,int>)> pq(cmp);
    cin >>n;
    for(int i=0; i<n; i++){
        cin >>a >>b;
        pq.push(make_pair(a,b));
    }
    
    int time = 0;
    bool success = true;
    while(!pq.empty()){
        pair<int,int> task = pq.top();
        pq.pop();
        
        if(DEBUG){
            cout <<"Time=" <<time <<endl;
            cout <<"Task=" <<task.first <<" " <<task.second <<endl;
        }
        
        if(task.second < time + task.first){
            success = false;
            break;
        }
        else{
            time += task.first;
        }
    }
    
    if(success) cout <<"Yes";
    else cout <<"No";
    cout <<endl;
}

Measured memory_bytes: 2420
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class T, class U> inline T GCD_L(T a, U b){
  T r;
  while(b){
    r=a;
    a=b;
    b=r%a;
  }
  return a;
}
int main(){
  int X;
  int res;
  rd(X);
  res = 360 /GCD_L(360, X);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// {
//   int X, res;
//   rd(X);
//   res = 360 / gcd(360, X);
//   wt(res);
// }


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

int main(){
    int L;
    cin >> L;
    vector<int> C(L);
    for(int i = 0; i < L; i++) cin >> C[i];
    vector<int> in(L+1,0);
    stack<int> s;

    int ans = 1e9;
    for(int i = 0; i< L; i++){
        if(C[i] > 0){
            if(in[C[i]]) ans = min(ans, i+1);
            else in[C[i]] = 1, s.push(C[i]);
        } 
        if(C[i] < 0){
            if(s.size() == 0) ans = min(ans, i+1);
            else if(in[-C[i]] && s.top() != -C[i]) ans = min(ans, i+1);
            else if(!in[-C[i]]) ans = min(ans, i+1);
            else in[-C[i]] = 0, s.pop();
        }
    }

    if(ans == 1e9) cout << "OK" << endl;
    else cout << ans << endl;
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

ll gcd(ll a, ll b) {
  return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int a[3], m[3];
  while (cin >> a[0] >> m[0]) {
    for (int i = 1; i < 3; i++) {
      cin >> a[i] >> m[i];
    }
    if (!a[0]) break;
    int cnt[3];
    for (int i = 0; i < 3; i++) {
      int p = a[i] % m[i];
      cnt[i] = 1;
      while (p != 1) {
        (p *= a[i]) %= m[i];
        cnt[i]++;
      }
    }
    cout << lcm(cnt[0], lcm(cnt[1], cnt[2])) << endl;
  }

  return 0;
}


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

int main() {
  int n; cin >> n;
  vector<int> a(n);
  
  long long parsum = 0;
  long long sum = 0;
  
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    sum += a.at(i);
  }
  
  long long min_dif = LONG_LONG_MAX;
  
  for(int i = 0; i < n - 1; i++){
    parsum += a.at(i);
    long long dif = abs(2 * parsum - sum);
    if(dif < min_dif){
      min_dif = dif;
    }
  }
    
      
  cout << min_dif << endl;
  
    

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
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;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

// Convex Hull Trick
// verify: https://atcoder.jp/contests/dp/tasks/dp_z
// 直線 ax+b 追加 O(1)
// x における最小値取得 O(1)
struct ConvexHullTrick {
    struct Line {
        long long a, b;
        long long get(long long x) { return a * x + b; }
    };
    deque<Line> que;
    bool check(Line a, Line b, Line c) {
        return (b.b - c.b) * (b.a - a.a) <= (a.b - b.b) * (c.a - b.a);
    }
    void add(long long a, long long b) {
        Line l{a, b};
        while(que.size() > 1 && check(que[que.size() - 2], que.back(), l))
            que.pop_back();
        que.push_back(l);
    }
    long long query(long long x) {
        if(que.empty()) return INT64_MAX;
        while(que.size() > 1 && que[0].get(x) >= que[1].get(x))
            que.pop_front();
        return que[0].get(x);
    }
};

int main() {
    cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(20);

    ll N, C; cin >> N >> C;
    vll h(N);
    rep(i,N) cin >> h[i];

    vll dp(N, 0);
    ConvexHullTrick ch;
    ch.add(-2*h[0], dp[0] + h[0]*h[0]);
    for(ll i = 1; i < N; i++) {
        dp[i] = ch.query(h[i]) + h[i]*h[i] + C;
        ch.add(-2*h[i], dp[i] + h[i]*h[i]);
    }
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 5632
import math

n, d = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

cnt = 0
for i in range(n):
    distance = math.sqrt((a[i][0] ** 2) + (a[i][1] ** 2))
    if distance <= d:
        cnt += 1

print(cnt)

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

int main() {
    std::string s, t;
    std::cin >> s >> t;
    int a, b;
    std::cin >> a >> b;

    std::string u;
    std::cin >> u;
    if (u == s) {
        a--;
    } else {
        b--;
    }

    std::cout << a << " " << b << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n;
  char a;
  cin>>n;
  rep(i,n){
    cin>>a;
    if(a=='Y'){cout<<"Four"<<endl;return 0;}
  }
  cout<<"Three"<<endl;
  return 0;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  for(int i=N*0.9; i*1.08 < N+1; ++i) {
    if(floor(i*1.08) == N) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (int argc, char** argv)
{
    int a, b, c;
    char s[4];

    scanf("%d %d %d", &a, &b, &c);
    memset(s, '\0', sizeof(s));

    if ((a < b) && (b < c)) {
        sprintf(s, "%s", "Yes");
    }
    else {
        sprintf(s, "%s", "No");
    }

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

Measured memory_bytes: 580
#include<cstdio>
#define M 524288
#define N 200001
#define p 924844033
inline int calc(int x,int y)
{
	int z=1;
	for(;y;x=1ll*x*x%p,y>>=1)if(y&1)z=1ll*z*x%p;
	return z;
}
int a[N],b[N<<1],c[N<<1],d[N],e[N],f[M],l[M],m,n,r[M],s[N],t,w[M|1],x,y;
inline void NTT(int*o,int u)
{
	for(int i=0;i<m;i++)if(f[i]>i)t=o[f[i]],o[f[i]]=o[i],o[i]=t;
	for(int j=1,v=m&u;j<m;j<<=1,u>>=1)for(int i=0;i<m;i++)x=o[i],y=1ll*w[v]*o[i+j]%p,o[i]=(x+y)%p,o[i+j]=(p+x-y)%p,(i&j-1)==j-1?i+=j,v=m&u:v+=u;
}
void dfs(int u,int v)
{
	for(int i=a[u];i;i=b[i])if(c[i]!=v)dfs(c[i],u),s[u]+=s[c[i]],l[n-s[c[i]]]++,l[s[c[i]]]++;
}
int main()
{
	scanf("%d",&n),s[n]=1;
	for(int i=1,u,v;i<n;i++)s[i]=1,scanf("%d%d",&u,&v),b[++t]=a[u],c[a[u]=t]=v,b[++t]=a[v],c[a[v]=t]=u;
	dfs(m=1,0),t=0;
	while(m<=n<<1)m<<=1,t++;w[*d=d[1]=*e=e[1]=*w=w[m]=1]=calc(5,p>>t--),f[1]=1<<t;
	for(int i=2;i<m;i++)f[i]=f[i>>1]>>1|(i&1)<<t,w[i]=1ll*w[i-1]*w[1]%p;
	for(int i=2;i<=n;i++)d[i]=1ll*d[i-1]*i%p,e[i]=1ll*(p-p/i)*e[p%i]%p;
	for(int i=2;i<=n;i++)e[i]=1ll*e[i-1]*e[i]%p;
	for(int i=0;i<=n;i++)l[i]=1ll*l[i]*d[i]%p,r[i]=e[n-i];
	NTT(l,m>>1),NTT(r,m>>1);
	for(int i=0;i<m;i++)l[i]=1ll*l[i]*r[i]%p;
	NTT(l,-m>>1),t=calc(m,p-2);
	for(int i=1;i<=n;i++)printf("%lld\n",(1ll*d[n]*e[n-i]%p*e[i]%p*n%p+p-1ll*l[n+i]*t%p*e[i]%p)%p);
	return 0;
}

Measured memory_bytes: 24448
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>]
#include <map>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;


int main(){
char aa,bb,cc,dd;
cin>>aa>>bb>>cc>>dd;
int a=aa-'0',b=bb-'0',c=cc-'0',d=dd-'0';
if(a+b+c+d==7){
    cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<"=7";
}
else if(a+b+c-d==7) cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<"=7";
else if(a+b-c+d==7) cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<"=7";
else if(a-b+c+d==7) cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<"=7";
else if(a-b-c-d==7) cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<"=7";
else if(a+b-c-d==7) cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<"=7";
else if(a-b+c-d==7) cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<"=7";
else if(a-b-c+d==7) cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<"=7";



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int m = 0;
  int max_count = 0;
  for(int i = 1; i < N+1; i++){
    int count = 0;
    int P = i;
    while(P%2 == 0){
      count++;
      P = P/2;
    }
    if(max_count <= count){
      max_count = count;
      m = i;
    }
  }
  cout << m << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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 (a>b) { a=b; return 1; } return 0; }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

const ll INF = (1ll<<60);

vector<ll> greedy(ll D, vector<ll> &c, vector<vector<ll>> &s){
    vector<ll> t(D, -1);
    vector<ll> last(26, -1);
    ll res = 0;
    REP(d, D){
        ll ma = -INF;
        ll ma_cont = -1;
        REP(cont, 26){
            ll tmp_res = res + s[d][cont];
            auto tmp_last = last;
            tmp_last[cont] = d;
            REP(i, 26){
                tmp_res -= c[i] * (d  - tmp_last[i]);
            }
            if(chmax(ma, tmp_res)) ma_cont = cont;
        }
        
        res += s[d][ma_cont];
        last[ma_cont] = d;
        REP(i, 26){
            res -= c[i] * (d  - last[i]);
        }
        t[d] = ma_cont;
    }
    return t;
}

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

    ll D;
    cin >> D;
    vector<ll> c(26);
    vector<vector<ll>> s(D, vector<ll>(26, 0));

    REP(i, 26) cin >> c[i];
    REP(i, D){
        REP(j, 26){
            cin >> s[i][j];
        }
    }

    auto t = greedy(D, c, s);

    REP(i, D){
        cout << t[i]+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100009;
ll a,b;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>a>>b;
    cout<< a * b - a - b + 1;
    return 0;
}

Measured memory_bytes: 764
using System;
using System.Linq;

namespace Volume0
{
    class Program
    {
        static void Main(string[] args)
        {
            string s;
            while((s = Console.ReadLine()) != null)
            {
                double[] i = s.Split(' ')
                            .Select(e => double.Parse(e))
                            .ToArray();
                double x = (i[2] * i[4] - i[1] * i[5]) 
                              / (i[0] * i[4] - i[1] * i[3]);
                double y = (i[5] * i[0] - i[2] * i[3])
                              / (i[0] * i[4] - i[3] * i[1]);
                Console.WriteLine("{0:F3} {1:F3}", x, y);
            }
        }
    }
}

Measured memory_bytes: 9692
import sys
readline = sys.stdin.readline
read = sys.stdin.read


k = int(input())
a,b = (int(x) for x in input().split())
flag = False
for i in range(a,b+1):
    if i%k==0:
        flag = True
if flag:
    print("OK")
else:
    print("NG")

Measured memory_bytes: 9180
S = list(input())
T = list(input())
ans = len(T)

for i in range(len(S)-len(T)+1):
    count = 0
    
    for j in range(len(T)):
        if S[i+j] != T[j]:
            count += 1
        
    if count < ans:
        ans = count

print(ans)

Measured memory_bytes: 9072
#include <iostream>
using namespace std;
int main(void){
  long long int a,b,c;
  cin >> a >> b >> c;
  if ((a%2)*(b%2)*(c%2)==0){
    cout << 0 << endl;
    return 0;
  }
  if (a<=c&&b<=c) cout << a*b << endl;
  else if (b<=a&&c<=a) cout << b*c << endl;
  else cout << c*a << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=111;
int dp[maxn][maxn][maxn],A[maxn];
int main()
{
	int N,K;scanf("%d%d",&N,&K);
	for(int i=1;i<=N;++i) scanf("%d",A+i);
	for(int k=1;k<=K;++k)
	{
		memcpy(dp[k],dp[k-1],sizeof(dp[k]));
		for(int i=N;i;--i)
		{
			for(int l=1,r=i;r<=N;++l,++r)
			{
				dp[k][l][r]=max(dp[k][l][r],max(dp[k][l][r-1]+A[r],dp[k][l+1][r]+A[l]));
				if(k>1) dp[k][l][r]=max(dp[k][l][r],max(dp[k-2][l][r-1],dp[k-2][l+1][r]));
//				printf("dp[%d][%d][%d] : %d\n",k,l,r,dp[k][l][r]);
			}
		}
	}
	printf("%d",dp[K][1][N]);
	return 0;
}

Measured memory_bytes: 5120
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        new Main().run();
    }
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			String game1 = scan.nextLine();
			if(game1.equals("0")){
				break;
			}
			String game2 = scan.nextLine();
			String game3 = scan.nextLine();
			int Ascore = 0;
			int Bscore = 0;
			for(int i = 1;i < game1.length();i++){
				if(game1.charAt(i) == 'A'){
					Ascore++;
				}else{
					Bscore++;
				}
			}
			if(game2.charAt(0) == 'A'){
				Ascore++;
			}else{
				Bscore++;
			}
			System.out.println(Ascore + " " + Bscore);
			Ascore = 0;
			Bscore = 0;
			for(int i = 1;i < game2.length();i++){
				if(game2.charAt(i) == 'A'){
					Ascore++;
				}else{
					Bscore++;
				}
			}
			if(game3.charAt(0) == 'A'){
				Ascore++;
			}else{
				Bscore++;
			}
			System.out.println(Ascore + " " + Bscore);
			Ascore = 0;
			Bscore = 0;
			for(int i = 1;i < game3.length();i++){
				if(game3.charAt(i) == 'A'){
					Ascore++;
				}else{
					Bscore++;
				}
			}
			if(Ascore > Bscore){
				Ascore++;
			}else{
				Bscore++;
			}
			System.out.println(Ascore + " " + Bscore);
		}
	}
}

Measured memory_bytes: 17128
n = int(input())
a = [input() for i in range(n)]
b = []
b.append(a[0])
res = True
for i in range(1,n):
    if a[i-1][-1] != a[i][0]:
        res = False
        break
    if a[i] in b:
        res = False
        break
    b.append(a[i])

if res:
    print('Yes')
else:
    print('No')

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

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

    int N;
    cin >> N;
    map<ll, int> map1;
    for(int i=0;i<N;i++) {
        int D;
        cin >> D;
        map1[D] += 1;
    }

    int M;
    cin >> M;
    map<ll, int> map2;
    for(int i=0;i<M;i++) {
        int T;
        cin >> T;
        map2[T] += 1;
    }
    for(auto itr=map2.begin();itr!=map2.end();itr++){
        ll tmp;
        tmp = (*itr).first;
        if(map2[tmp] > map1[tmp]){
            cout <<"NO"<<endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 25216
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int s[] = new int[n];
        for (int i = 0; i < n; i++)
            s[i] = sc.nextInt();
        int q = sc.nextInt();
        int t[] = new int[q];
        for (int i = 0; i < q; i++)
            t[i] = sc.nextInt();

        int cnt = 0;
        for (int query = 0; query < q; query++) {
            int index = Arrays.binarySearch(s, t[query]);
            if (index < 0) {
                continue;
            } else {
                cnt++;
            }
        }
        System.out.println(cnt);

        sc.close();
    }
}


Measured memory_bytes: 80468
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>() % 10;
    if n == 3 {
        println!("bon");
    } else if n == 0 || n == 1 || n == 6 || n == 8 {
        println!("pon");
    } else {
        println!("hon");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2148
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {
    int A, B;
    cin >> A >> B;
    if(A > B) swap(A, B);
    if((B-A)%2) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << (B+A) / 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
#define fori(i,a,b) for(int i=(a);i<(int)(b);i++)
#define repi(i,n) fori(i,0,n)
#define forr(i,a,b) for(int i=int(b-1);i>=int(a);i--)
#define repr(i,n) forr(i,0,n)
#define all(x) (x).begin(),(x).end()
#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mp make_pair
#define pcnt __builtin_popcount
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;}

void solve(ll n, string s, string t){
    string ans;
    repi(i,n){
        ans+=s[i];
        ans+=t[i];
    }
    cout<<ans<<endl;
}

int main(){
    ll n;
    scanf("%lld",&n);
    string s;
    cin >> s;
    string t;
    cin >> t;
    solve(n, s, t);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cassert>
#include <cstring>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int a[100000], b[100000];

int main(void) {
    int i, n, h;
    scanf("%d%d",&n,&h);
    REP (i,n) scanf("%d%d",&a[i],&b[i]);

    int mx = *max_element(a,a+n);
    sort(b,b+n);
    int ans = 0;
    for (i = n-1; i >= 0 && h > 0 && b[i] > mx; i--,ans++) {
        h -= b[i];
    }
    if (h > 0) ans += (h + mx - 1) / mx;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1024
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     setbits(x)  __builtin_popcountll(x)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=1e5+5;
const int mod=1e9+7;

int x,y,a,b,c;
vector<ll>r,g,col;
signed main(){
    FastIO;
    cin>>x>>y>>a>>b>>c;
    r.resize(a);
    g.resize(b);
    col.resize(c);
    rep(i,1,a) cin>>r[i-1];
    rep(i,1,b) cin>>g[i-1];
    rep(i,1,c) cin>>col[i-1];
    sort(all(r),greater<int>());
    sort(all(g),greater<int>());
    sort(all(col),greater<int>());
    ll ans=0;
    rep(i,0,x-1) ans+=r[i];
    rep(i,0,y-1) ans+=g[i];
    int curr=0;
    x--,y--;
    while((x>=0 or y>=0) and curr<c){
        if(min(r[x],g[y])>col[curr]) break;
        if(r[x]>g[y] and y>=0){
            ans-=g[y--];
        }
        else if(x>=0){
            ans-=r[x--];
        }
        ans+=col[curr++];
        if(x<0 and y<0) break;
        if(x<0) x=0,r[0]=1e15;
        if(y<0) y=0,g[0]=1e15;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 2560
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
from collections import deque

class Dinic:
    def __init__(self,n,edges):
        self.n=n
        self.edges=[[] for _ in range(n)]
        self.iter=[0]*n
        self.level=None
        self.graph(edges)
    def graph(self,E):
        edges=self.edges
        for fr,to,cap in E:
            edges[fr].append([to,cap,len(edges[to])])
            edges[to].append([fr,0,len(edges[fr])-1])
    def maxflow(self,source,sink):
        max_flow=0
        while True:
            self.bfs(source)
            if self.level[sink]<0:
                return max_flow
            self.iter=[0]*self.n
            flow=self.dfs(source,sink,float('inf'))
            while flow:
                max_flow+=flow
                flow=self.dfs(source,sink,float('inf'))
    def bfs(self,source):
        edges=self.edges
        level=[-1]*self.n
        level[source]=0
        q=deque([source])
        while q:
            fr=q.popleft()
            for to,cap,_ in edges[fr]:
                if cap>0>level[to]:
                    level[to]=level[fr]+1
                    q.append(to)
        self.level=level
    def dfs(self,source,sink,flow):
        if source==sink:
            return flow
        while self.iter[source]<len(self.edges[source]):
            to,cap,rev=self.edges[source][self.iter[source]]
            if cap>0 and self.level[source]<self.level[to]:
                f=self.dfs(to,sink,min(flow,cap))
                if f:
                    self.edges[source][self.iter[source]][1]-=f
                    self.edges[to][rev][1]+=f
                    return f
            self.iter[source]+=1
        return 0

inf=float('inf')
h,w=map(int,input().split())
Edges=[]
for x in range(h):
    s=list(input())
    for y in range(w):
        if s[y]=='S':
            Edges.append((0,x+1,inf))
            Edges.append((0,y+1+h,inf))
        elif s[y]=='T':
            Edges.append((x+1,h+w+1,inf))
            Edges.append((y+1+h,h+w+1,inf))
        elif s[y]=='o':
            Edges.append((x+1,y+1+h,1))
            Edges.append((y+1+h,x+1,1))
dinic=Dinic(h+w+2,Edges)
mf=dinic.maxflow(0,h+w+1)
print(-1 if mf==inf else mf)

Measured memory_bytes: 9040
#include <stdio.h>

int main (){
	int n;
	
	scanf("%d", &n);
	
	if (n % 10 == 7){
		printf("Yes");
	}
	else if ((n/10) %10 == 7){
		printf("Yes");
	}
	else if (n/100 == 7){
		printf("Yes");
	}
	else {
		printf("No");
	}
	
	return 0;
}

Measured memory_bytes: 1700
n = int(input())
summit=[int(i) for i in input().split()]
#print(List)
max = summit[0]
sum = 1
for i in range(n-1):
    if max <= summit[i+1]:
        #print(max,summit[i+1])
        max = summit[i+1]
        sum = sum + 1
print(sum)


Measured memory_bytes: 2940
#include <stdio.h>

int main(){
  char number[1001];
  int sum, num;
  int i, j;

  while(1){
    for(i=0; i<1001; i++){
      number[i]='0';
    }
    sum=0;
    j=0;
    scanf("%s", number);
    if(number[0]=='0' && number[1]=='\0'){
      break;
    }
    while(number[j]!='\0'){
      num=number[j]-'0';
      sum=sum+num;
      j=j+1;
    }
    printf("%d\n", sum);
  }
  return 0;

}

Measured memory_bytes: 536
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  ll n; cin>> n;
  vector<pair<ll,ll>> v;
  for(ll i=0;i<n;++i){
    ll val;cin >> val;
    v.push_back(make_pair(i, val));
  }
  sort(all(v),[](pair<ll,ll>& a, pair<ll,ll>& b){return a.second < b.second;});
  ll maxele = v[n-1].second;
  ll maxele2 = v[n-2].second;
  sort(all(v),[](pair<ll,ll>& a, pair<ll,ll>& b){return a.first < b.first;});
  for(ll i=0;i<n;++i){
    if(v[i].second==maxele){
      cout << maxele2 << endl;
    } else {
      cout << maxele << endl;
    }
  }

  return 0;
}


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

int main(){
  int N,x,ans=0;
  cin >> N >> x;
  int a[N];
  for(int i=0;i<N;i++)
    cin >> a[i];
  sort(a,a+N);
  for(int j=0;j<N;j++){
    if(0<=x-a[j]){
      x -= a[j];
      ans++;
    }
    else break;
  }
  if(ans < N||(ans == N&&x==0))
  	cout << ans << endl;
  else 
    cout << ans-1 << endl;
}

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

int N, M;
vector<int> G[8];

int f(int x, int b) {
  if (b == (1<<N)-1) return 1;
  int s = 0;
  for (int t : G[x]) {
    if (b & (1<<t)) continue;
    s += f(t, b | (1<<t));
  }
  return s;
}

int main() {
  cin >> N >> M;
  for (int i=0; i<M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  cout << f(0, 1) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

constexpr int MOD = 1e9+7;
struct mint
{
	int v;
	mint():v(0){}
	mint(int v):v((v+MOD)%MOD){}
	mint operator-()const{ return mint(0) - *this; }
	mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
	mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
	mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
	mint& operator/=(const mint& a){ (*this) *= a.inv(); return *this; }
	mint operator+(const mint& a)const{ return mint(*this) += a; }
	mint operator-(const mint& a)const{ return mint(*this) -= a; }
	mint operator*(const mint& a)const{ return mint(*this) *= a; }
	mint operator/(const mint& a)const{ return mint(*this) /= a; }
	bool operator<(const mint& a)const{ return v < a.v; }
	bool operator==(const mint& a)const{ return v == a.v; }
	mint pow(int k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
	mint inv()const{ return pow(MOD-2); }
	static mint comb(int n, int k) {
		if(n-k<k) k=n-k;
		mint num(1), dom(1);
		for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; }
		return num/dom;
	}
};
std::istream& operator>>(std::istream&i,mint&a){ int t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }


signed main() {
	int n,m;
	std::cin >> n >> m;
	std::vector<mint> xx(n);
	std::vector<mint> yy(m);
	rep(i,n) std::cin >> xx[i];
	rep(i,m) std::cin >> yy[i];
	n--;
	m--;
	std::vector<mint> x(n);
	std::vector<mint> y(m);
	rep(i,n) {
		x[i] = xx[i+1] - xx[i];
	}
	rep(i,m) {
		y[i] = yy[i+1] - yy[i];
	}

	mint a = 0;
	{
		std::vector<mint> ac(n);
		ac[0] = x[0];
		rep(i,n-1) {
			ac[i+1] = ac[i] + x[i+1];
		}
		{
			mint sum = 0;
			for(auto c:ac) sum+=c;
			for(int i=0;i<n;i++) {
				a+=sum;
				sum-=mint(n-i)*x[i];
			}
		}
	}
	mint b = 0;
	{
		std::vector<mint> ac(m);
		ac[0] = y[0];
		rep(i,m-1) {
			ac[i+1] = ac[i] + y[i+1];
		}
		{
			mint sum = 0;
			for(auto c:ac) sum+=c;
			for(int i=0;i<m;i++) {
				b+=sum;
				sum-=mint(m-i)*y[i];
			}
		}
	}
	print(a*b);
	return 0;
}


Measured memory_bytes: 4208
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define inf (1LL<<60)
#define N (300005)

using namespace std;

ll sum[N],tmp[N],f1[N],f2[N],h[N],g[N],y[N],a[N],res;
int q[N],n,m,top;

il int gi(){
  RG int x=0,q=1; RG char ch=getchar();
  while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
  if (ch=='-') q=-1,ch=getchar();
  while (ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
  return q*x;
}

il ll max(RG ll a,RG ll b){ return a>b ? a : b; }

il void solve(ll *f,ll *g,RG int l,RG int r){
  if (l==r){ h[l]=max(h[l],f[l-1]+g[l+1]-a[l]+1); return; } RG int mid=(l+r)>>1; top=0;
  for (RG int i=l-1;i<mid;++i){
    while (top>1 && (y[i]-y[q[top-1]])*(q[top]-q[top-1])>=(y[q[top]]-y[q[top-1]])*(i-q[top-1])) --top;
    q[++top]=i;
  }
  for (RG int i=mid;i<=r;++i){
    while (top>1 && (y[q[top]]-y[q[top-1]])<=1LL*i*(q[top]-q[top-1])) --top;
    tmp[i]=(1LL*i*(i+1)>>1)-sum[i]+y[q[top]]-1LL*i*q[top]+g[i+1];
  }
  for (RG int i=r-1;i>=mid;--i) tmp[i]=max(tmp[i],tmp[i+1]);
  for (RG int i=mid;i<=r;++i) h[i]=max(h[i],tmp[i]);
  solve(f,g,l,mid),solve(f,g,mid+1,r); return;
}

int main(){
  n=gi(); for (RG int i=1;i<=n;++i) a[i]=gi(); q[top=1]=0;
  for (RG int i=1;i<=n;++i){
    sum[i]=sum[i-1]+a[i],f1[i]=f1[i-1],res=(1LL*i*(i+1)>>1)-sum[i];
    while (top>1 && (y[q[top]]-y[q[top-1]])<=1LL*i*(q[top]-q[top-1])) --top;
    f1[i]=max(f1[i],res+y[q[top]]-1LL*i*q[top]),y[i]=f1[i]+sum[i]+(1LL*i*(i-1)>>1);
    while (top>1 && (y[i]-y[q[top-1]])*(q[top]-q[top-1])>=(y[q[top]]-y[q[top-1]])*(i-q[top-1])) --top; q[++top]=i;
  }
  reverse(a+1,a+n+1),q[top=1]=0;
  for (RG int i=1;i<=n;++i){
    sum[i]=sum[i-1]+a[i],f2[i]=f2[i-1],res=(1LL*i*(i+1)>>1)-sum[i];
    while (top>1 && (y[q[top]]-y[q[top-1]])<=1LL*i*(q[top]-q[top-1])) --top;
    f2[i]=max(f2[i],res+y[q[top]]-1LL*i*q[top]),y[i]=f2[i]+sum[i]+(1LL*i*(i-1)>>1);
    while (top>1 && (y[i]-y[q[top-1]])*(q[top]-q[top-1])>=(y[q[top]]-y[q[top-1]])*(i-q[top-1])) --top; q[++top]=i;
  }
  reverse(a+1,a+n+1),reverse(f2+1,f2+n+1);
  for (RG int i=1;i<=n;++i) sum[i]=sum[i-1]+a[i],y[i]=f1[i]+sum[i]+(1LL*i*(i-1)>>1),h[i]=-inf;
  solve(f1,f2,1,n),reverse(a+1,a+n+1),reverse(f1+1,f1+n+1),reverse(f2+1,f2+n+1),reverse(h+1,h+n+1);
  for (RG int i=1;i<=n;++i) sum[i]=sum[i-1]+a[i],y[i]=f2[i]+sum[i]+(1LL*i*(i-1)>>1);
  solve(f2,f1,1,n),reverse(a+1,a+n+1),reverse(f1+1,f1+n+1),reverse(f2+1,f2+n+1),reverse(h+1,h+n+1),m=gi();
  while (m--){
    RG int p=gi(),x=gi();
    printf("%lld\n",max(f1[p-1]+f2[p+1],h[p]+a[p]-x));
  }
  return 0;
}


Measured memory_bytes: 19328
#include <stdio.h>

int main(void){

  long  a,b;
  scanf("%ld %ld", &a, &b);
	long sum = a+b;
  if (sum%2 != 0) {
    printf("IMPOSSIBLE\n");
  } else {
    printf("%ld\n", sum/2);
  }

  return 0;
}

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

int main(){
    string s;
    int count=0;
    cin >> s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='+'){
            count++;
        }else{
            count--;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define MAXN 500005

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
ll fac[MAXN], rev[MAXN];

ll fexp(ll x, ll y) {
  ll ans = 1;
  while (y) {
    if (y & 1)
      ans = ans * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return ans;
}

ll A(ll n, ll k) { return fac[n] * rev[n - k] % MOD; }

ll C(ll n, ll k) { return A(n, k) * rev[k] % MOD; }

int main() {
  int n, m;
  cin >> n >> m;
  fac[0] = 1, rev[0] = 1;
  for (int i = 1; i <= m; ++i) {
    fac[i] = fac[i - 1] * i % MOD;
    rev[i] = fexp(fac[i], MOD - 2);
  }
  ll tot = A(m, n) * A(m, n) % MOD;
  int sign = 1;
  for (int i = 1; i <= n; ++i) {
    sign = -sign;
    ll now = C(n, i) * A(m, i) % MOD;
    now = now * A(m - i, n - i) % MOD;
    now = now * A(m - i, n - i) % MOD;
    now = now * sign % MOD;
    if (now < 0)
      now += MOD;
    tot = (tot + now) % MOD;
  }
  cout << tot;
}

Measured memory_bytes: 11260
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

int H;
int N;
int Sum = 0;
int Temp;

int main()
{
    scanf("%d %d", &H, &N);
    for(int i=1; i<=N; i++)
    {
        scanf("%d", &Temp);
        Sum += Temp;
    }
    if(Sum < H)
    {
        printf("No");
    }
    else
    {
        printf("Yes");
    }
    
    return 0;
}

Measured memory_bytes: 256
import sys

N=int(input())
L=[['a']]
moji=['a','b','c','d','e','f','g','h','i','j']

if N==1:
    print('a')
    sys.exit()

def rank(l):
    return len(set(list(l)))

for i in range(N-1):
    L.append([])
    for j in L[i]:
        for k in range(rank(j)+1):
            #print(i,j,k,rank(j))
            #print(j+moji[k])
            L[i+1].append(j+moji[k])

#print(L)

for i in L[N-1]:
    print(i)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  if( n <= 0 && m >= 0) {
    cout << "Zero\n";
  } else if( n > 0) {
    cout << "Positive\n";
  } else {
    if( (min(m, -1)-n+1)&1) {
      cout << "Negative\n";
    } else {
      cout << "Positive\n";
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)					// repeat
#define repr(i, begin, end) for (ll i = begin - 1; end <= i; i--)		// repeat reverse

std::chrono::system_clock::time_point  start;

void TimeStart(void)
{
	start = std::chrono::system_clock::now();
}

void TimeEnd(void)
{
	auto time = std::chrono::system_clock::now() - start;
	auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(time).count();
	cerr << endl << msec << " msec " << endl;
}

#endif


int main(void)
{

	ll n; cin >> n;
	ll k; cin >> k;
	string s; cin >> s;

	if (65 <= s[k-1] && s[k-1] <= 90)
		s[k-1] = (char)((int)s[k-1] + 32);

	cout << s;


	return 0;
}

Measured memory_bytes: 256
import numpy as np
from copy import deepcopy

S = str(input())
T = str(input())

line_S = deepcopy(S)
line_T = deepcopy(T)

while True:
  if len(line_S) == 0:
    ans = 'Yes'
    break
  else:
    char_S = line_S[0]
    char_T = line_T[0]
    bool_S = [(s == char_S) for s in line_S]
    bool_T = [(t == char_T) for t in line_T]
    if bool_S == bool_T:
      line_S = line_S.replace(char_S, "")
      line_T = line_T.replace(char_T, "")
    else:
      ans = 'No'
      break
   
print(ans)



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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, a; cin>>h>>a;
    int cnt=0;
    while(h>0){
        h-=a;
        cnt++;
    }
    print(cnt);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int i , max = 0 , count = 0 , buf , num[101] = {0} , c_num[101] = {0};
	while(scanf("%d" , &buf)!=EOF){
		num[buf]++;
	}
	for(i=1;i<=100;i++){
		if(num[i] > max){
			count++;
			c_num[i] = count;
			max = num[i];
		}else if(num[i] == max){
			c_num[i] = count;
		}
	}
	for(i=1;i<=100;i++){
		if(c_num[i] == count) printf("%d\n" , i);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#define MAX 1000000
using namespace std;

bool prime[MAX+1];

bool hurui(){
  for(int i=0;i<MAX;i++){prime[i]=true;}
  prime[0]=prime[1]=prime[2]=true;
  
  for(int i=2;i<MAX;i++){
    if(prime[i]){
      for(int j=2*i;j<MAX;j+=i)prime[j]=false;
    }
  }
}


int main(){
  hurui();
  
  for(;;){
    int n,x;
    cin >> n >> x;
    if(n==0)return 0;
    
    int kane[n];
    for(int i=0;i<n;i++)
      cin >> kane[i];
    
    bool dp[x+1];
    for(int i=0;i<=x;i++)dp[i]=false;
    dp[0]=true;
    
    for(int i=0;i<=x;i++){
      if(dp[i]){
	for(int j=0;j<n;j++){
	  if(i+kane[j]<=x)dp[i+kane[j]]=true;
	}
      }
    }

    //cout << "aa";
    for(int i=x;i>=0;i--){
      if(i==0){
	cout << "NA" << endl;
	break;
      }
      if(dp[i]&&prime[i]){
	cout << i << endl;
	break;
      }
    }
  } 
  
}

Measured memory_bytes: 3108