akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int h, w;
  cin >> h >> w;
  string s[h];
  for (int i = 0; i < h; ++i) cin >> s[i];
  
  int ans[h][w] = {};
  
  for (int i = 0; i < h; ++i) {
    int c = 0;
    int buf = 0;
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '#') {
        for (int k = buf; k < j; ++k) {
          ans[i][k] += c;
        }
        c = 0;
        buf = j+1;
      }
      else {
        if (j < w-1) ++c;
        else {
          for (int k = buf; k < w; ++k) {
            ans[i][k] += (c+1);
          }
        }
      }
    }
  }
  
  for (int i = 0; i < w; ++i) {
    int c = 0;
    int buf = 0;
    for (int j = 0; j < h; ++j) {
      if (s[j][i] == '#') {
        for (int k = buf; k < j; ++k) {
          ans[k][i] += c;
        }
        c = 0;
        buf = j+1;
      }
      else {
        if (j < h-1) ++c;
        else {
          for (int k = buf; k < h; ++k) {
            ans[k][i] += (c+1);
          }
        }
      }
    }
  }
  
  int max = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (ans[i][j] > max) {
        max = ans[i][j];
      }
    }
  }
  
  cout << max-1 << endl;
  return 0;
}

Measured memory_bytes: 19968
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define display(v) for (auto x : v) cout << x << ", "
#define print(x) cout << (#x) << " = [ ";display(x); cout << "]\n"
#define endl '\n'
#define pb push_back
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
 
// DEBUG TEMPLATE by livw
void __print(int x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifdef INCLUDEWHENOFFLINE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


map <ll, ll> mp;

ll calc(ll n)
{
    if (mp[n]) return mp[n];
    ll ans = 0;
    if (n == 1) ans = 1;
    else
    {
        ll a = n / 2, b = n / 2;
        ans += calc(a);
        ans += calc(b);
        ans++;
    }
    mp[n] = ans;
    return ans;
}

int main()
{
    fastio;
    
    ll h;
    cin >> h;
    ll ans = calc(h);
    cout << ans;
    
    return 0;
}


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

def main():
    n = int( input() )
    input_a = list ( map( int, input().split() ) )
    a = deque( input_a )

    while( len(a) != 1 ):
        x = a.popleft()
        y = a.popleft()
        z = x ^ y
        a.append(z)
    sum = a.popleft()
    ans = []
    for i in input_a:
        x = i ^ sum
        ans.append(x)

    for i in ans:
        print( i , end = ' ' )



main()

Measured memory_bytes: 31636
#include "bits/stdc++.h"
#define ll long long
#define PI 3.1415926535897932384626433832795l
#define MAX_NUM 1000000000
#define line printf("-----------------\n");
using namespace std;
int SET(int N, int pos) { return N = N | (1 << pos); }
int RESET(int N, int pos) { return N = N & ~(1 << pos); }
bool CHECK(int N, int pos) { return (bool)(N & (1 << pos)); }
template <typename T>
inline T __lcm(T a, T b)
{
    return (a * b) / __gcd(a, b);
}
struct node
{
    int x, y, i;
};
int dx[] = {0, 1, 0, -1, -1, 1, 1, -1};
int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};

void solve()
{
    string s;
    cin >> s;
    stack<char> st;
    st.push(s[0]);
    int ans = 0;

    for (int i = 1; i < s.size(); i++)
    {
        if (!st.empty())
        {
            if (s[i] == st.top())
            {
                st.push(s[i]);
            }
            else
            {
                ans++;
                st.pop();
            }
        }
        else
        {
            st.push(s[i]);
        }
    }
    cout << ans * 2 << endl;
}

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("inputf.txt", "r", stdin);
    //freopen("outputf.txt", "w", stdout);
#endif // ONLINE_JUDGE
    solve();
    return 0;
}

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

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    int max = 0;
    int c = 0;

    for (int i = 0; i < 3; i++) {
        if (s[i] == 'S') {
            if (c > max) max = c;
            c = 0;
        } else {
            ++c;
        }
    }
    
    if (c > max) max = c;
    cout << max;

    return 0;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
int ans=0;
bool Vis[105];
int main()
{
	int M,D;
	scanf("%d%d",&M,&D);
	for(int i=1;i<=M;i++)
	{
		for(int j=2;j<=9;j++)
		{
			for(int jj=2;jj<=9;jj++)
			{
				if(jj*j==i&&j*10+jj<=D&&Vis[j*10+jj]==false)ans++,Vis[j*10+jj]=true;
			}
		} 
	} 
	cout<<ans;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 2e5 + 7;
vector <int> g[N];
bool c[N];
void dfs(int u, int p) {
    for (int v : g[u])
        if (v != p) {
            c[v] = c[u] ^ 1;
            dfs(v, u);
        }   
}   
int ans[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    for (int i = 0; i < N; ++i)
        ans[i] = -1;
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].app(v); g[v].app(u);
    }   
    dfs(1, 1);
    vector <int> a, b;
    for (int i = 1; i <= n; ++i)
        if (c[i])
            a.app(i);
        else
            b.app(i);
    if (b.size() < a.size())
        swap(a, b);
    vector <int> v1, v2;
    for (int i = 1; i <= n; ++i)
        if (i % 3 == 1)
            v1.app(i);
        else if (i % 3 == 2)
            v2.app(i);
    if (v2.size() < v1.size())
        swap(v1, v2);
    if (v1.size() <= a.size()) {
        for (int i = 0; i < v1.size(); ++i)
            ans[a[i]] = v1[i];
        for (int i = 0; i < v2.size(); ++i)
            ans[b[i]] = v2[i];            
    }
    else {
        for (int i = 0; i < v1.size(); ++i)
            ans[b[i]] = v1[i];
        for (int i = 0; i < v2.size(); ++i)
            ans[b[i + v1.size()]] = v2[i];                    
    }   
    int ptr = 3;
    for (int i = 1; i <= n; ++i) 
        if (ans[i] == -1) {
            ans[i] = ptr;
            ptr += 3;
        }
    for (int i = 1; i <= n; ++i)
        cout << ans[i] << ' ';
    cout << endl;
}   

Measured memory_bytes: 21996
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    while(1){
        int a,b;
        cin>>a>>b;
        if(a==0&b==0)break;
        for(int i=0;i<a;i++){
            for(int o=0;o<b;o++){
                cout<<"#";
            }
            cout<<endl;
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3116
#include <iostream>
#include <vector>

int main()
{
  unsigned W, H, N;
  std::cin >> W >> H >> N;
  
  std::vector<std::vector<bool>> f(H);
  for(unsigned h=0; h<H; ++h)
  {
    f[h] = std::vector<bool>(W, false);
  }
  
  for(unsigned n=0; n<N; ++n)
  {
    unsigned x, y, a;
    std::cin >> x >> y >> a;
    
    switch(a)
    {
    case 1:
      for(unsigned h=0; h<H; ++h)
      {
        for(unsigned w=0; w<x; ++w)
        {
          f[h][w] = true;
        }
      }
      break;
    case 2:
      for(unsigned h=0; h<H; ++h)
      {
        for(unsigned w=x; w<W; ++w)
        {
          f[h][w] = true;
        }
      }
      break;
    case 3:
      for(unsigned w=0; w<W; ++w)
      {
        for(unsigned h=0; h<y; ++h)
        {
          f[h][w] = true;
        }
      }
      break;
    case 4:
      for(unsigned w=0; w<W; ++w)
      {
        for(unsigned h=y; h<H; ++h)
        {
          f[h][w] = true;
        }
      }
      break;
    default:
      break;
    }
  }
  
  unsigned c = 0;
  for(unsigned h=0; h<H; ++h)
  {
    for(unsigned w=0; w<W; ++w)
    {
      if(!f[h][w])
      {
        ++c;
      }
    }
  }
  std::cout << c << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    cost = 10**10

    for a in range(-200, 201):
        c = 0
        for i in range(N):
            c += (a - A[i])**2
        if c < cost:
            cost = c
    print(cost)
if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>
int main(){
    int n;scanf("%d",&n);
    double x[n],y[n];
    for(int i=0;i<n;i++) scanf("%lf",&x[i]);
    for(int i=0;i<n;i++) scanf("%lf",&y[i]);
    double d1=0,d2=0,d3=0,di=0;
    for(int i=0;i<n;i++) d1+=fabs(x[i]-y[i]);
    for(int i=0;i<n;i++) d2+=(x[i]-y[i])*(x[i]-y[i]);
    d2=sqrt(d2);
    for(int i=0;i<n;i++) d3+=pow(fabs(x[i]-y[i]),3);
    d3=cbrt(d3);
    di=fabs(x[0]-y[0]);
    for(int i=1;i<n;i++){
        if(di<fabs(x[i]-y[i])) di=fabs(x[i]-y[i]);
    }
    printf("%.8lf\n",d1);
    printf("%.8lf\n",d2);
    printf("%.8lf\n",d3);
    printf("%.8lf\n",di);
}


Measured memory_bytes: 2920
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <string>
#include <list>
#include <bitset>

using namespace std;

#define CVector CPoint
typedef long long LL;
typedef unsigned long long ULL;

const LL mod=1e9+7;
const double PI=acos(-1);
const double EPS=1e-6;
const int INF=0x3f3f3f3f;
inline int readint(){int sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;}
inline LL readLL(){LL sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;}

LL a[55];

int main(){//ios_base::sync_with_stdio(0);cin.tie(0);
    LL k;k=readLL();
    LL s=k/50;
    LL t=k%50;
    for(int i=1;i<=t;i++) a[i]=s+49+50-t;
    for(int i=t+1;i<=50;i++) a[i]=s+49-t;
    printf("50\n");
    for(int i=1;i<=50;i++){
        printf("%lld",a[i]);
        if(i<50) printf(" ");
        else printf("\n");
    }
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


Measured memory_bytes: 256
dplist = [(5, 3), (7, 5), (13, 11), (19, 17), (31, 29), (43, 41), (61, 59), (73, 71), (103, 101), (109, 107), (139, 137), (151, 149), (181, 179), (193, 191), (199, 197), (229, 227), (241, 239), (271, 269), (283, 281), (313, 311), (349, 347), (421, 419), (433, 431), (463, 461), (523, 521), (571, 569), (601, 599), (619, 617), (643, 641), (661, 659), (811, 809), (823, 821), (829, 827), (859, 857), (883, 881), (1021, 1019), (1033, 1031), (1051, 1049), (1063, 1061), (1093, 1091), (1153, 1151), (1231, 1229), (1279, 1277), (1291, 1289), (1303, 1301), (1321, 1319), (1429, 1427), (1453, 1451), (1483, 1481), (1489, 1487), (1609, 1607), (1621, 1619), (1669, 1667), (1699, 1697), (1723, 1721), (1789, 1787), (1873, 1871), (1879, 1877), (1933, 1931), (1951, 1949), (1999, 1997), (2029, 2027), (2083, 2081), (2089, 2087), (2113, 2111), (2131, 2129), (2143, 2141), (2239, 2237), (2269, 2267), (2311, 2309), (2341, 2339), (2383, 2381), (2551, 2549), (2593, 2591), (2659, 2657), (2689, 2687), (2713, 2711), (2731, 2729), (2791, 2789), (2803, 2801), (2971, 2969), (3001, 2999), (3121, 3119), (3169, 3167), (3253, 3251), (3259, 3257), (3301, 3299), (3331, 3329), (3361, 3359), (3373, 3371), (3391, 3389), (3463, 3461), (3469, 3467), (3529, 3527), (3541, 3539), (3559, 3557), (3583, 3581), (3673, 3671), (3769, 3767), (3823, 3821), (3853, 3851), (3919, 3917), (3931, 3929), (4003, 4001), (4021, 4019), (4051, 4049), (4093, 4091), (4129, 4127), (4159, 4157), (4219, 4217), (4231, 4229), (4243, 4241), (4261, 4259), (4273, 4271), (4339, 4337), (4423, 4421), (4483, 4481), (4519, 4517), (4549, 4547), (4639, 4637), (4651, 4649), (4723, 4721), (4789, 4787), (4801, 4799), (4933, 4931), (4969, 4967), (5011, 5009), (5023, 5021), (5101, 5099), (5233, 5231), (5281, 5279), (5419, 5417), (5443, 5441), (5479, 5477), (5503, 5501), (5521, 5519), (5641, 5639), (5653, 5651), (5659, 5657), (5743, 5741), (5851, 5849), (5869, 5867), (5881, 5879), (6091, 6089), (6133, 6131), (6199, 6197), (6271, 6269), (6301, 6299), (6361, 6359), (6451, 6449), (6553, 6551), (6571, 6569), (6661, 6659), (6691, 6689), (6703, 6701), (6763, 6761), (6781, 6779), (6793, 6791), (6829, 6827), (6871, 6869), (6949, 6947), (6961, 6959), (7129, 7127), (7213, 7211), (7309, 7307), (7333, 7331), (7351, 7349), (7459, 7457), (7489, 7487), (7549, 7547), (7561, 7559), (7591, 7589), (7759, 7757), (7879, 7877), (7951, 7949), (8011, 8009), (8089, 8087), (8221, 8219), (8233, 8231), (8293, 8291), (8389, 8387), (8431, 8429), (8539, 8537), (8599, 8597), (8629, 8627), (8821, 8819), (8839, 8837), (8863, 8861), (8971, 8969), (9001, 8999), (9013, 9011), (9043, 9041), (9241, 9239), (9283, 9281), (9343, 9341), (9421, 9419), (9433, 9431), (9439, 9437), (9463, 9461), (9631, 9629), (9679, 9677), (9721, 9719), (9769, 9767), (9859, 9857), (9931, 9929)]

while(True):
    N = int(input())
    if N == 0:
        break
    for i in range(len(dplist)-1, -1, -1):
        if dplist[i][0] <= N:
            print(dplist[i][1], dplist[i][0])
            break



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

using namespace std;

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

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

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

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

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

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

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

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

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

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

    cin>>n;
    for (int i = 1; i <= n; i++)
    {
        S.pb((char)(i+48));
    }
    f0(i,n)
    {
        cin>>x;
        T.pb((char)(x+48));
    }
    f0(i,n)
    {
        cin>>x;
        U.pb((char)(x+48));
    }

    do
    {
        cnt++;
        M="";
        f0(i,S.sz)
        {
            M.pb(S[i]);
        }
        if(M==T)
        {
            a=cnt;
        }
        if(M==U)
        {
            b=cnt;
        }
    }
    while (next_permutation(all(S)));

    cout<<abs(a-b)<<endl;
    return 0;
}


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

typedef long long ll;

const ll M = 998244353;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

int main() {
  ll N,A,B,K;
  cin >> N >> A >> B >> K;
  ll sum=0;
  fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
  for(int i=0;i<max(K/A,N);i++){
    ll x=K-A*i;
    if(x>=0 && x%B==0 && x/B<=N){
      sum+=((comb(N,i)%M)*(comb(N,x/B))%M)%M;
      sum=sum%M;
    }
  }
  cout << sum;
}

Measured memory_bytes: 4992
"use strict";
function main(input) {
    const line = input.split("\n");
    let arr = line[0].split(" ");
    const A = parseInt(arr[0]);
    const B = parseInt(arr[1]);
    console.log(A <= 9 && B <= 9 ? A * B : -1);
    return;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29904
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  int A,B;
  cin >> A >> B;
  if(A == 1){
    A = A + 13;
  }
  if(B == 1){
    B = B + 13;
  }
  if(A == B){
    cout << "Draw" << endl;
  }
  else if(A > B){
    cout << "Alice" << endl;
  }
  else{
    cout << "Bob" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <climits>
#include <cstring>

using namespace std;

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

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

int div_up(int a, int b)
{
    return (a + b - 1) / b;
}

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

    int h, w, k, fh, fw;
    string a[810];

    cin >> h >> w >> k;
    REP(i, h)
    cin >> a[i];

    REP(i, h)
    REP(j, w)
    if (a[i][j] == 'S')
        fh = i, fw = j;

    vector<P> v;
    v.push_back(make_pair(fh, fw));

    int dis[810][810];
    memset(dis, -1, sizeof(dis));
    dis[fh][fw] = 0;

    queue<P> q;
    q.push(make_pair(fh, fw));

    while (q.size())
    {
        P p = q.front();
        q.pop();

        bool add = false;

        REP(i, 4)
        {
            P p_ = p;
            p_.first += dy[i];
            p_.second += dx[i];

            if (p_.first < 0 || h <= p_.first || p_.second < 0 || w <= p_.second)
                continue;

            if (dis[p_.first][p_.second] != -1)
                continue;

            if (a[p_.first][p_.second] == '#')
                continue;

            int d = dis[p.first][p.second] + 1;

            dis[p_.first][p_.second] = d;

            v.push_back(p_);

            if (d < k)
                q.push(p_);
        }
    }

    int res = INT_MAX;

    for (P p : v)
    {
        res = min(res, div_up(p.first, k));
        res = min(res, div_up(h - p.first - 1, k));
        res = min(res, div_up(p.second, k));
        res = min(res, div_up(w - p.second - 1, k));
    }

    cout << res + 1 << endl;

    return 0;
}

Measured memory_bytes: 13684
n=int(input())
s=input()
la=[0]
lb=[0]
for i in s:
    if i==".":
        la.append(la[-1]+1)
        lb.append(lb[-1])
    if i=="#":
        la.append(la[-1])
        lb.append(lb[-1]+1)

ans=1000000000000
for i in range(n+1):
    ans=min(ans,lb[i]-lb[0]+la[-1]-la[i])
print(ans)

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a <= 0 && 0 <= b) {
    cout << "Zero" << endl;
  } else if (b < 0 && (b - a) % 2 != 0 || 0 < a) {
    cout << "Positive" << endl;
  } else {
    cout << "Negative" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]

def main():
    n, m = MII()
    if n > 2 and m > 2:
        print((n-2)*(m-2))
    elif n == 1 and m > 2:
        print(m-2)
    elif n > 2 and m == 1:
        print(n-2)
    elif n == 2 or  m == 2:
        print(0)
    else:
        print(1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
N, K, Q = map(int, input().split(' '))
P = [0 for _ in range(N)]

for i in range(Q):
    a = int(input()) - 1
    P[a] += 1

for i in range(N):
    if K - (Q - P[i]) > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 4672
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define ll long long
using namespace std;

map<ll,ll> mem;
vector<vector<ll>> adjList;
ll longestPath(ll node)
{

    if(adjList[node].size()==0)
        return 0;

    if(mem.count(node)==1)
        return mem[node];
    ll ret = 0;

    for(auto child : adjList[node])
    {
        ret = max(ret , 1+longestPath(child));
    }
    mem[node] = ret;
    return ret;
}


int main()
{
    ll n,m; cin>>n>>m;
    adjList = vector<vector<ll>>(n);
    for(int i = 0 ; i<m ; i++)
    {
        int frm,to; cin>>frm>>to; frm--; to--;
        adjList[frm].push_back(to);
    }

    ll ans = 0 ;
    for(int i = 0 ; i<n ; i++)
    {
        ans = max(ans,longestPath(i));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 15360
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <utility>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;++a) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define int_maxvalue numeric_limits<int>::max()
#define print_double(val,a) cout << fixed << setprecision(a) << val << endl;
ll mod = 1e9 + 7;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	if (a > b) {
		cout << a-1  << endl;
	}
	else {
		cout << a <<endl;
	}
	return 0;
}


Measured memory_bytes: 256
A,B,C,K = map(int,input().split())

koa = 0
if A<K:
  koa = A
else :
  koa = K
kob = 0
if B<K-koa:
  kob = B
else :
  kob = K-koa
#print (koa)
#print (kob)
sum = koa+0*kob+(K-(koa+kob))*-1
print (sum)

Measured memory_bytes: 9168
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int t;
//解説AC;
long long gcd(ll x,ll y){
    ll r = x % y;
    while(r != 0){
        x = y;
        y = r;
        r =x % y;
    }
    return y;
}
void check(ll a,ll b,ll c,ll d){
    if(a < b){
        cout << "No" << endl;
        return;
    }
    if(b > d){
        cout << "No" << endl;
        return;
    }
    ll g = gcd(d,b);
    ll mx = b - g + (a%g);
    if(mx > c){
        cout << "No" << endl;
        return;
    }
    cout << "Yes" << endl;
    return;
}
ll A,B,C,D;
int main(){
    cin >> t;
    for(int i = 0; i < t; i++){
        cin >> A >> B >> C >> D;
        check(A,B,C,D);
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <vector>
#include <valarray>
#include <queue>
#include <iostream>
#include <numeric>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(int i = (a); i >= (b); --i)
#define rREP(i, n) rFOR(i, n-1, 0)
#define AND &&
#define OR ||
#define IN(x, min, max) (min <= x AND x < max)
#define VEC(type) vector<type>
#define DVEC(type) vector<vector<type>>
#define VAL(type) valarray<type>
#define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
#define HOGE printf("%s\n", "hoge");
#define DUMP(p) cout << p << endl;
const int INF = 2323232323;
using namespace std;
typedef pair<int, int> P;

int main(){
    char Sa[102];
    char Sb[102];
    char Sc[102];
    scanf(" %101s", Sa);
    scanf(" %101s", Sb);
    scanf(" %101s", Sc);
    char turn = 'a';
    char ans;
    int a = 0, b = 0, c = 0;
    while (true) {
        if (turn == 'a') {
            if ((turn = Sa[a++]) == '\0') {
                ans = 'A';
                break;
            }
        }
        if (turn == 'b') {
            if ((turn = Sb[b++]) == '\0') {
                ans = 'B';
                break;
            }
        }
        if (turn == 'c') {
            if ((turn = Sc[c++]) == '\0') {
                ans = 'C';
                break;
            }
        }
    }
    printf("%c\n", ans);
    return 0;
}


Measured memory_bytes: 256
a, b, k = list(map(int, input().split()))
a_l = [i for i in range(a, a + k) if i <= b]
b_l = [i for i in range(b - k+1, b+1) if i >= a]
for i in b_l:
    a_l.append(i)
ans = sorted(list(set(a_l)))
for i in ans:
    print(i)


Measured memory_bytes: 3060
n = int(input())
a = list(map(int, input().split()))

A_score = 0
B_Score = 0

a = sorted(a, reverse=True)

for i in range(n):
    if i % 2 == 0:
        A_score += a[i]
    else:
        B_Score += a[i]

print(A_score - B_Score)

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

bool b[ 11000 ];

int main()
{
int i;
int j;
int N;
int s;
int iMax;

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

	cin >> N;

	iMax = 0;
	b[ 0 ] = true;
	for( i = 0; i < N; i++ )
	{
		cin >> s;

		for( j = iMax; j >= 0; j-- )
		{
			if( b[ j ] ) b[ j + s ] = true;
		}

		iMax += s;
	}

	for( j = iMax; j > 0; j-- )
	{
		if( b[ j ] && ( j % 10 != 0 ) ) break;
	}

	cout << j << endl;

	return 0;
}




Measured memory_bytes: 256
(defun factorize (N)
  (loop for x from 1 to (isqrt N) with q and r
        do (multiple-value-setq (q r) (floor N x))
        if (zerop r) collect x
        if (and (zerop r) (/= x q)) collect q))

(defvar N (read))

(loop named outer for x in (factorize N) do
      (loop for a from (floor x 2)
            for b from (- (floor x 2) x)
            with y = (/ N x) with z
            do (setf z (+ (* a a a a)
                          (* a a a b)
                          (* a a b b)
                          (* a b b b)
                          (* b b b b)))
            if (= y z)
            do (return-from outer (format t "~A ~A" a b))
            if (< y z)
            return nil))

Measured memory_bytes: 24584
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "D"
int n, k, l;
vector <int> g[200001][2];
bool done[200001][2];
int cc[200001][2];
vector <int> c[400001];
int f[400001];
int ans[200001];
int cnt=0;
void dfs(int u, int i){
    done[u][i]=1;
    cc[u][i]=cnt;
    c[cnt].pb(u);
    for(int v: g[u][i]) if(!done[v][i]) dfs(v, i);
}
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    read(n);
    read(k);
    read(l);
    int u, v;
    FOR(i, 1, k){
        read(u);
        read(v);
        g[u][0].pb(v);
        g[v][0].pb(u);
    }
    FOR(i, 1, l){
        read(u);
        read(v);
        g[u][1].pb(v);
        g[v][1].pb(u);
    }
    FOR(i, 1, n) if(!done[i][0]){
        cnt++;
        dfs(i, 0);
    }
    int m=cnt;
    FOR(i, 1, n) if(!done[i][1]){
        cnt++;
        dfs(i, 1);
    }
    FOR(i, 1, m){
        for(int x: c[i]) f[cc[x][1]]++;
        for(int x: c[i]) ans[x]=f[cc[x][1]];
        for(int x: c[i]) f[cc[x][1]]--;
    }
    FOR(i, 1, n){
        write(ans[i]);
        putchar(' ');
    }
}

Measured memory_bytes: 37120
#include<iostream>
#include<vector>
using namespace std;
int main(){
        int n,q;
        cin >>n;
        vector<int>s;
        for(int i = 0;i< n;++i){
                int tomato;
                cin >> tomato;
                s.push_back(tomato);
        }
        int ans = 0;
        cin >> q;
        for(int i = 0;i<q;++i){
                int tomato;
                cin >> tomato;
                int l =0;
                int u = n-1;
                while(u-l>1){
                        int temp =0;
                        temp = (l+u)/2;
                        if(s[temp]>=tomato)
                                        u=temp;
                        else

                                l=temp;
                }
                        if(s[u]==tomato)ans++;
        }
        cout << ans<<endl;
        return 0;
}


Measured memory_bytes: 3284
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	public static int hash(int ... nums){
		return (nums[0] << 21) + (nums[1] << 18) + (nums[2] << 15) + (nums[3] << 12) + (nums[4] << 9) + (nums[5] << 6) + (nums[6] << 3) + nums[7];
	}
	
	public static int swap(int h, int k){
		int from = 0;
		
		for(int i = 0; i < 8; i++){
			if(((h >> ((7 - i)*3)) & (0x0000000f >> 1)) == 0){
				from = i;
				break;
			}
		}
		
		int to = -1;
		
		switch(k){
		case 0: //hidari
			if(from % 4 == 0){
				break;
			}
			
			to = from - 1;
			break;
		case 1: //ue
			if((from / 4) == 0){
				break;
			}
			
			to = from - 4;
			break;
		case 2: //migi
			if(from % 4 == 3){
				break;
			}
			
			to = from + 1;
			break;
		case 3: //shita
			if(from / 4 == 1){
				break;
			}
			
			to = from + 4;
			break;
		}
		
		if(to == -1){
			return h;
		}
		
		int num = (h >> (7 - to)*3) & (0x0000000f >> 1);
		return h + (num << ((7 - from)*3)) - (num << ((7 - to)*3));
	}
	
	public static final int ANS = hash(0,1,2,3,4,5,6,7);
	
	public static void main(String[] args){
		
		LinkedList<Integer> list = new LinkedList<Integer>();
		HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
		list.add(ANS);
		map.put(ANS, 0);
		
		int step = 1;
		while(!list.isEmpty()){
			LinkedList<Integer> tmp_list = new LinkedList<Integer>();
			
			for(int hash_num : list){
				for(int i = 0; i < 4; i++){
					int new_hash = swap(hash_num,i);
					if(hash_num == new_hash){
						continue;
					}
					
					if(map.containsKey(new_hash)){
						continue;
					}
					
					map.put(new_hash, step);
					tmp_list.add(new_hash);
				}
			}
			
			list.clear();
			list.addAll(tmp_list);
			step++;
		}
		
		Scanner sc = new Scanner(System.in);
		
		
		while(sc.hasNext()){
			
			String str = sc.nextLine();
			
			String[] params = str.split(" ");
			int[] array = new int[params.length];
			for(int i = 0; i < params.length; i++){
				array[i] = Integer.parseInt(params[i]);
			}
			
			System.out.println(map.get(hash(array)));
			
		}
		
		
	}
	
}

Measured memory_bytes: 14000
import java.util.*;
import java.math.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int k=sc.nextInt(); 
		int x=sc.nextInt();
		if(x<=k*500){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public class Robot
	{
		public long Pos {get;set;}
		public long Arm {get;set;}
	}
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var robots = new Robot[n];
		for(int i = 0; i < n; i++)
		{
			var p = Input();
			var robot = new Robot(){Pos = p[0].ToLong(), Arm = p[1].ToLong()};
			robots[i] = robot;
		}
		
		Array.Sort(robots, (s, t)=>(int)(s.Pos+s.Arm - t.Pos - t.Arm));
		
		long cur = 0;
		long wa = 0;
		for(int i = 0; i < n; i++)
		{
			long k = robots[i].Pos - robots[i].Arm;
			if(i != 0 && k < cur)
				continue;
			cur = robots[i].Pos + robots[i].Arm;
			wa++;
		}
		Console.WriteLine(wa);
	}


	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 23100
#include<bits/stdc++.h>
#define N 600050
const int mod=998244353,inv2=mod+1>>1;
using namespace std;
int n,al,a[N],b[N],bin[30];
inline int qpow(int d,int z){
	int ret=1;
	for(;z;z>>=1,d=1ll*d*d%mod)
		if(z&1)ret=1ll*ret*d%mod;
	return ret;
}
inline void fwt(int *a,int n,int tag){
	for(int i=1;i<n;i<<=1){
		for(int j=0,I=i<<1;j<n;j+=I){
			for(int k=0;k<i;++k){
				int x=a[j+k],y=a[j+k+i];
				a[j+k]=(x+y)%mod;
				a[j+k+i]=(x+mod-y)%mod;
				if(tag==-1)a[j+k]=1ll*inv2*a[j+k]%mod,a[j+k+i]=1ll*inv2*a[j+k+i]%mod;
			}
		}
	}
}
int main(){
	for(int i=0;i<=25;++i)bin[i]=1<<i;
	scanf("%d",&n);
	for(int i=0;i<bin[n];++i)scanf("%d",&a[i]),al+=a[i];
	al=qpow(al,mod-2);
	for(int i=0;i<bin[n];++i)a[i]=1ll*al*a[i]%mod;a[0]=(a[0]+mod-1)%mod;
	for(int i=1;i<bin[n];++i)b[i]=mod-1;b[0]=bin[n]-1;
	fwt(a,bin[n],1);fwt(b,bin[n],1);
	for(int i=0;i<bin[n];++i)a[i]=1ll*qpow(a[i],mod-2)*b[i]%mod;
	fwt(a,bin[n],-1);a[0]=mod-a[0];
	puts("0");
	for(int i=1;i<bin[n];++i)printf("%d\n",(a[i]+a[0])%mod);
	return 0;
}

Measured memory_bytes: 5776
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;

int main() {
	int N, K; cin >> N >> K;
	vi a(N); rep(i, N) cin >> a[i];

	int cnt = 0;
	for (int q = 0; q < N - K; q++) {
		if (a[K + q] > a[q]) {
			pYes;
		}
		else {
			pNo;
		}
	}


}

Measured memory_bytes: 4048
/**
 *    author:  tourist
 *    created: 08.01.2020 23:09:07       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == 'S') {
        vector<pair<int, int>> que(1, make_pair(i, j));
        vector<int> dist(1, 0);
        s[i][j] = 'T';
        for (int b = 0; b < (int) que.size(); b++) {
          if (dist[b] == k) {
            break;
          }
          for (int di = -1; di <= 1; di++) {
            for (int dj = -1; dj <= 1; dj++) {
              if (di * di + dj * dj != 1) {
                continue;
              }
              int ni = que[b].first + di;
              int nj = que[b].second + dj;
              if (ni >= 0 && nj >= 0 && ni < h && nj < w) {
                if (s[ni][nj] == '.') {
                  que.emplace_back(ni, nj);
                  s[ni][nj] = 'T';
                  dist.push_back(dist[b] + 1);
                }
              }
            }
          }
        }
      }
    }
  }
  int ans = (int) 1e9;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == 'T') {
        int d = min(i, min(j, min(h - 1 - i, w - 1 - j)));
        ans = min(ans, 1 + (d + k - 1) / k);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 15340
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;


public class Main {

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;

        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }
}

class Task {

    boolean check(int k, int[] a) {
        for (int i = 0; i < a.length; i++) {
            if (a[i] != k && a[i] != k - 1)
                return false;
        }
        int nc = 0;
        for (int i = 0; i < a.length; i++) {
            if (a[i] == k - 1) nc++;
        }
        if (nc > k) return false;
        if (k == nc && a.length - nc > 0) return false;
        if (k != nc && (a.length - nc) / (k - nc) < 2) return false;
        return true;
    }

    public void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        int x = a[0], y = a[0] + 1;
        boolean ok = check(x ,a) | check(y, a);
        out.println(ok ? "Yes" : "No");
    }


}


class InputReader {

    private final BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

}


Measured memory_bytes: 36532
n, m = gets.chomp.split.map(&:to_i)
a = Array.new(n) {gets.chomp}
b = Array.new(m) {gets.chomp}

judge = (0..n-m).inject("No"){|flag, i|
    (0..n-m).each{|j| 
        c = Array.new(m) {|k| a[k+i][j..j+m-1]}
        flag = "Yes" if b == c
    }
    flag
}

puts judge

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

int main() 
{
    int n;
    int b, f, r, v;                          //b棟 f階 r番めの部屋 v人

    int House[4][3][10];                     //4棟 3階 10部屋 格納されるのが人数

    for( int i = 0; i < 4; i++ )             //Houseの初期化。人数を0にする。
        for( int j = 0; j < 3; j++ )
            for( int k = 0; k < 10; k++ )
                House[i][j][k] = 0;

    cin >> n;

    for( int i = 0; i < n; i++ )             //入力者の情報が与えられる
    {
        cin >> b >> f >> r >> v;

        House[b-1][f-1][r-1] += v;           //-1をしているのは配列の番号との関係
    }

    for( int i = 0; i < 4; i++ )             //出力
    {
        for( int j = 0; j < 3; j++ )
        {
            for( int k = 0; k < 10; k++ )
                cout << " " << House[i][j][k];
            cout << endl;
        }
        if( i != 3)
            cout << "####################" << endl;     
    }

    return 0;
}


Measured memory_bytes: 3128
N = int(input())
A_list = list(map(int,input().split()))
A_list.sort()
#print(A_list)
if A_list[0]==0:
    answer = 0
else:      
    answer = 1
    for a in A_list:
        answer *= a
        if len(str(answer-1)) > 18:
            answer = -1
            break
print(answer)

Measured memory_bytes: 21796
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string s_m = "abcdefghijklmnopqrstuvwxyz";
    // rep(i,s.size()) cout << s_m[s[i] - 'A'] << endl;
    int n,k; cin >> n >> k;
    string S;cin >> S;
    S[k-1] = s_m[S[k-1] - 'A'];
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003;
const ll INF=1LL<<60;

int main(){
    
    int N;ll K;cin>>N>>K;
    ll sum=0;
    vector<ll> A(N),F(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
    }
    for(int i=0;i<N;i++) cin>>F[i];
    
    sort(all(F));
    reverse(all(F));
    sort(all(A));
    
    if(sum<=K){
        cout<<0<<endl;
        return 0;
    }
    
    ll left=0,right=INF;
    
    while(right-left>1){
        ll mid=(left+right)/2;
        ll cnt=0;
        
        for(int i=0;i<N;i++){
            if(A[i]*F[i]<=mid) continue;
            cnt+=A[i]-mid/F[i];
            
            if(cnt>K) break;
        }
        
        if(cnt>K) left=mid;
        else right=mid;
        
    }
    
    cout<<right<<endl;
}



Measured memory_bytes: 3328
f = []
for w in input():
    if w == "A" or w == "C" or w == "G" or w == "T":
        f += "1"
    else:
        f += " "
if "1" in f:
    acgt = [i for i in list("".join(f).split())]
    acgt.sort()
    print(len(acgt[-1]))
else:
    print(0)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
typedef pair<int, int> P;

template<typename T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return (a * b) / gcd(a, b);
}

int main()
{
    int n, m; cin >> n >> m;
    cout << (n - 1)*(m - 1) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define INF 1000000000


int main(){
  int i,j,n,l,k;
  int REN[101][101];
  int p[101];
  
  scanf("%d",&n);
  for(i=1; i<=n; i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }
  
  for(i=1; i<=n; i++)REN[i][i]=0;
  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j=i+l-1;
      REN[i][j]=INF;
      for(k=i; k<j; k++){
	REN[i][j] = fmin(REN[i][j],REN[i][k] + REN[k+1][j] + p[i-1]*p[k]*p[j]);
      }
    }
  }
  
  printf("%d\n",REN[1][n]);
  
  return 0;
}



Measured memory_bytes: 2052
def merge(A, left, mid, right):

    inf = float('inf')
    L = A[left:mid]+[inf]
    R = A[mid:right] + [inf]
    cnt = 0
    n1 = len(L)-1
    i = j = 0
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
            cnt += n1-i
    return cnt


def mergeSort(A, left, right, count = 0):
    if left+1 < right:
        mid = (left + right)//2
        cnt1 = mergeSort(A, left, mid, count)
        cnt2 = mergeSort(A, mid, right, count)
        cnt3 = merge(A, left, mid, right)
        return cnt1+cnt2+cnt3
    else:
        return 0
n  = int(input())
A = list(map(int, input().split()))
ans = mergeSort(A, 0, n)

print(ans)



Measured memory_bytes: 27484