akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int N, K; cin >> N >> K;

    vector<int> A(N);
    for (int i = 0; i < N; ++i)
        cin >> A[i];

    vector<bool> answer(K + 1, false);
    for (int i = 1; i <= K; ++i) {
        for (auto &x : A)
            if (x <= i)
                answer[i] = answer[i] | (!answer[i - x]);
    }

    cout << (answer[K] ? "First" : "Second") << "\n";
}


Measured memory_bytes: 256
n = int(input())
S = []
for i in range(n):
    s = input()
    li = sorted(list(s))
    S.append(li)
ans = 0
S.sort()
fac = S[0]
cnt = -1
for i in range(n):
    if S[i] == fac:
        cnt += 1
    else:
        fac = S[i]
        ans += max((cnt+1)*cnt//2,0)
        cnt = 0
ans += max((cnt+1)*cnt//2,0)
print(ans)

Measured memory_bytes: 24624
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <utility>
#include <algorithm>
#include <math.h>

using namespace std;

#define ll long long

int main(){
    int S, W;
    cin >> S >> W;
    cout << (S - W > 0 ? "safe" : "unsafe") << endl;
    return 0;
}


Measured memory_bytes: 3640
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 2e5+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
	string s;
	cin >> s;
	if(s.back() == 's')
		cout << s << "es" << '\n';
	else
		cout << s + "s" << "\n";

}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define F first
#define S second
#define X real()
#define Y imag()
#define PB push_back 
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef complex<int> cld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut,pr> ppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
typedef vector<ppr> Vppr;
const int SIZE=100+2*1e+6;
const int INF=1<<30;
int dist[SIZE];
Vpr edge;
PQ qu;
int plusminus(int x){
	if(x)
	return x/abs(x);
	return 0;
}
int main(){
	int N,x,d,c;
	FOR(i,1,SIZE)
		dist[i]=INF;
	cin >> N>> x;
	REP(i,N){
		cin >> d>> c;
		edge.PB(pr(d,c));
		edge.PB(pr(-d,c));
	}
	qu.push(pr(0,0));
	while(!qu.empty()){
		int now=qu.top().S;
		int d=qu.top().F;
		qu.pop();
		if(d!=dist[now]) continue;
		REP(i,N*2){
			int next=now+edge[i].F;
			int nd=d+edge[i].S;
			if(next>0 && next<SIZE){
				if(dist[next]>nd){
					dist[next]=nd;
					qu.push(pr(nd,next));
				}
			}
		}
	}
	if(dist[x]==INF) cout << -1 << endl;
	else cout << dist[x] << endl;
}


Measured memory_bytes: 19024
import math
a, b, x = map(float, input().split())
 
half = a * a * b / 2
if x >= half:
  tan = 2 * (b - x / (a**2)) / a
else:
  tan = a * b**2 / (2*x)
 
 
print(math.degrees(math.atan(tan)))

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

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

void setPrecision(int num = 10) {
    std::cout << std::fixed << std::setprecision(num);
}

struct Point {
    int x;
    int y;
    double dist(Point a) {
        return sqrt((x - a.x) * (x - a.x) + (y - a.y) * (y - a.y));
    }
};

int main() {
    setPrecision();
    int n;
    cin >> n;
    vector<Point> points;
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        Point p = {x, y};
        points.push_back(p);
    }
    double sum = 0;
    rep(i, n) {
        for (int j = i + 1; j < n; j++)
            sum += points[i].dist(points[j]);
    }
    cout << sum * 2 / n << endl;
}


Measured memory_bytes: 256
r, c =map(int, raw_input().split())
m = []
for i in range(r):
    m.append(map(int, raw_input().split()))
for i in range(r):
    m[i].append(sum(m[i]))
n = []
for j in range(c + 1):
    k = 0
    for i in range(r):
        k += m[i][j]
    n.append(k)
m.append(n)
for i in range(r + 1):
    print ' '.join(map(str,m[i]))

Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  long long position = 0;
  long long tmp=0;
  long long count = 0;
  long long answer = 0;
  
  while(position < s.size()-1){
    if(s.at(position) == 'A'){
      tmp++;
      position++;
    }else if(s.at(position) == 'B'){
      if(s.at(position+1) == 'C'){
        count += tmp;
        position += 2;
      }else{
        answer += count;
        tmp = 0;
        count = 0;
        position++;
      }
    }else if(s.at(position) == 'C'){
      answer += count;
      tmp = 0;
      count = 0;
      position++;
    }
  }
  
  answer += count;
 
  cout << answer << endl; 
}

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

using namespace std;

const int MAX_N = 105;

int N;

long long gcd(long long a, long long b)
{
  if (b == 0) return a;
  return gcd(b, a % b);
}

int main()
{
  //freopen("in.txt", "r", stdin);
  while (scanf("%d", &N) != EOF) {
    long long lcm;
    scanf("%lld", &lcm);
    for (int i = 1; i < N; ++i) {
      long long tmp;
      scanf("%lld", &tmp);
      lcm = lcm / gcd(lcm, tmp) * tmp;
    }
    printf("%lld\n", lcm);
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<set>

using namespace std;

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

 int n = 0;
 cin >> n;

 set<string> dic;

 for(int i = 0; i < n; i++){
  string buf1,buf2;
  cin >> buf1 >>buf2;
  if(buf1[0] == 'i'){
    dic.insert(buf2);
  }else{
   if(dic.find(buf2) != dic.end()){
    cout << "yes" << endl;
   }else{
    cout << "no" << endl;
   }
  }
 }
 return 0;
}

Measured memory_bytes: 27052
#!/usr/bin/env python3
# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N, K, Q = list(map(int, input().split()))
    if Q < K:
        for n in range(N):
            print('Yes')
    else:
        s = [K-Q for n in range(N)]
        for q in range(Q):
            ai = int(input())
            s[ai -1] += 1
        for n in range(N):
            print('Yes') if s[n] > 0 else print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 7892
#include <stdio.h>

int n, A[100];

int solve(int i, int m)
{
  int res;
  if(m == 0) return 1;
  if(i >= n) return 0;
  res = solve(i+1, m) || solve(i+1, m-A[i]);
  return res;
}

int main()
{
  int i, q, m;
  scanf("%d", &n);
  for(i = 0; i < n; i++) scanf("%d", &A[i]);
  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &m);
    if(solve(0, m) == 1) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int N,tmp=0,cnt=0;
    scanf("%d",&N);
    vector<int>d(N);
    for(int i=0; i<N; i++) scanf("%d",&d[i]);
    sort(d.begin(),d.end());
    for(int i=0; i<N; i++){
        if(tmp==d[i]){
        }else{
            cnt++;
            tmp=d[i];
        }
    }
    printf("%d\n",cnt);
    return 0;
}

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

using Graph=vector<vector<int>>;

int dfsA(int v,int pre,Graph &g){
    int sum=0;
    int res=0;
    for(int i=0;i<g[v].size();i++){
        if(g[v][i]!=pre){
            sum++;
            res+=dfsA(g[v][i],v,g);
        }
    }
    if(v==0){
        return (sum+1)/2+res;
    }
    else{
        return sum/2+res;
    }
}

int dfsB(int v,int pre,int bound,Graph &g){
    vector<int> len;
    for(int i=0;i<g[v].size();i++){
        if(g[v][i]!=pre) len.push_back(dfsB(g[v][i],v,bound,g)+1);
    }
    if(len.size()==0) return 0;
    sort(len.begin(),len.end());
    if(v!=0){
        if(len.size()%2==0){
            bool isbad=false;
            for(int i=0;i<len.size();i++){
                isbad|=(len[i]+len[len.size()-1-i]>bound);
            }
            if(!isbad) return 0;
            if(len.back()>bound) return bound+1;
            len.pop_back();
        }
        int lb=-1;
        int ub=len.size();
        while(ub-lb>1){
            int mid=(ub+lb)/2;
            int l=-1,r=len.size();
            bool isbad=false;
            while(true){
                if(l+1!=mid) l++;
                else l+=2;
                if(r-1!=mid) r--;
                else r-=2;
                assert(l!=r);
                if(len.size()<=l) break;
                isbad|=(len[l]+len[r]>bound);
            }
            if(isbad) lb=mid;
            else ub=mid;
        }
        if(ub==len.size()) return bound+1;
        else return len[ub];
    }
    else{
        if(len.size()%2==1){
            if(len.back()>bound) return bound+1;
            len.pop_back();
        }
        bool isbad=false;
        for(int i=0;i<len.size();i++){
            isbad|=(len[i]+len[len.size()-1-i]>bound);
        }
        if(isbad) return bound+1;
        else return 0;
    }
}
int main(){
    int n;
    cin>>n;
    Graph g(n);
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int A=dfsA(0,-1,g);
    cout<<A<<" ";
    int lb=0;
    int ub=n;
    while(ub-lb>1){
        int mid=(ub+lb)/2;
        int res=dfsB(0,-1,mid,g);
        if(res<=mid){
            ub=mid;
        }
        else{
            lb=mid;
        }
    }
    cout<<ub<<endl;
    return 0;
}

Measured memory_bytes: 14976
N = int(input())
A = list(map(int, input().split()))

S = A[0]
for i in range(1, N):
    S = S ^ A[i]
# print('S', S)

# for a in A[:-1]:
#     print(S ^ a, sep='', end=' ')

S = [str(S ^ a) for a in A]
print(' '.join(S))


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

const int MaxN(503);

bool Map1[MaxN][MaxN], Map2[MaxN][MaxN];
char s[MaxN];

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++)
	{
		scanf("%s", s + 1);
		if(i & 1)
		{
			for(int j = 1; j < m; j++)
				Map1[i][j] = true;
			Map2[i][m] = true;
		}
		else
		{
			for(int j = 2; j <= m; j++)
				Map2[i][j] = true;
			Map1[i][1] = true;
		}
		for(int j = 1; j <= m; j++)
			if(s[j] == '#') Map1[i][j] = Map2[i][j] = true;
	}
	for(int i = 1; i <= n; i++, puts(""))
		for(int j = 1; j <= m; j++)
			putchar(Map1[i][j] ? '#' : '.');
	puts("");
	for(int i = 1; i <= n; i++, puts(""))
		for(int j = 1; j <= m; j++)
			putchar(Map2[i][j] ? '#' : '.');
	return 0;
}


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

const ll mod = 1000000007;

vector<long long> com;

ll modpow(ll a, ll n, ll p) {
  if (n == 0) return 1;
  if (n == 1) return a % mod;
  if (n % 2 == 1) return (a * modpow(a, n - 1, mod)) % p;
  ll t = modpow(a, n / 2, mod);
  return (t * t) % mod;
}

ll inverse(ll a, ll p) {
  return modpow(a, p-2, p);
}

void comInit(long long n, long long k, long long p) {
  com.resize(k+1);
  com.at(0) = 1;
  long long tmp = 1;
  for (int i = 1; i <= k; i++) {
    tmp = ((tmp * (n-i+1) % p) * inverse(i, p)) % p;
    com.at(i) = tmp;
  }
}

long long MOD(long long val, long long p) {
  long long res = val % p;
  if (res < 0) res += p;
  return res;
}


int main(){
 ll n; cin >> n;
 int a,b; cin >> a >> b;
 ll ans=-1;
 ll p=modpow(2,n,mod); ans+=p;
 comInit(n, 200000, mod);
 ll d=MOD(com[a]+com[b],mod);

  cout  << MOD(ans-d,mod) << endl;
 }


Measured memory_bytes: 1920
#include<stdio.h>
#include<stdlib.h>
int main(){
  int i,j,z,N;
  int v;
  int *A; 
  scanf("%d",&N);
 
  A = malloc(N * sizeof(int)); 

  for(i=0;i<N;i++){
  scanf("%d",&A[i]);
  }
 for(z=0;z<N;z++){
      printf("%d",A[z]);
      if(z != N -1){
	printf(" ");
      }
    }
    printf("\n");
  
  for(i=1;i<N;i++){
    v = A[i];
    j = i - 1;
    while(j>=0&&A[j]>v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
      
      
    }
    for(z=0;z<N;z++){
      printf("%d",A[z]);
      if(z != N -1){
	printf(" ");
      }
    }
    printf("\n");
  }
  return 0;
}



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

#define y1 as214
#define ii pair < int , ll >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define fr front()
#define pb push_back

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

#define ll long long
#define oo INT_MAX

/// dp[i][j] là trọng lượng nhỏ nhất có thể được khi xét i vât đầu tiên và tổng giá trị của i vật đó là j.

const int N = 1e2 + 5;
const int M = 1e5 + 5;
ll n , w;
ll W[N] , V[N];
ll dp[N][M];

int main()
{
    //freopen("E.inp","r",stdin);
    cin >> n >> w;
    FOR(i , 1 , n)
        cin >> W[i] >> V[i];
    FOR(i , 0 , n)
        FOR(j , 1 , 1e5)
            dp[i][j] = 1e18;
    dp[0][0] = 0;
    FOR(i , 1 , n)
        FOR(j , 1 , 1e5)
        {
            if(dp[i - 1][j] != 1e18)
                dp[i][j] = dp[i - 1][j];
            if(j >= V[i])
                dp[i][j] = min(dp[i][j] , dp[i - 1][j - V[i]] + W[i]);
        }
    for(int i = 1e5 ;  i >= 1 ; i--)
        if(dp[n][i] <= w)
    {
        cout << i;
        exit(0);
    }
}


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

typedef long long ll;
typedef vector<int> vi;
#define PB push_back
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int n,k;
int arr[100005];
int dp[100005];

int f(int indx)
{
    if(indx>=n-1)
        return 0;

    if(dp[indx]!=-1)
        return dp[indx];
     int x=INT_MAX;
     for(int i=1;i<=k;i++)
     {
         if(indx+i<=n-1)
            x=min(x,abs( arr[indx]-arr[indx+i])+f(indx+i));
     }
    return dp[indx]=x;
}

int main()
{
    optimize();
    cin>>n>>k;
    for(int i=0; i<n; i++)
        cin>>arr[i];

   memset(dp,-1,sizeof(dp));
    cout<<f(0)<<endl;
    return 0;
}


Measured memory_bytes: 12208
/** Which of the favors of your Lord will you deny ? **/

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

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define F first
#define S second

#define ALL(x)      (x).begin(), (x).end()
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#ifndef ONLINE_JUDGE
#define DBG(x)      cout << __LINE__ << " says: " << #x << " = " << (x) << endl
#else
#define DBG(x)
#define endl "\n"
#endif

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

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

#define int long long

const int nmax = 2e5+7;
const int MOD = 1e9+7;

int add(int a,int b)
{
    return (a+b) % MOD;
}

int mul(int a,int b)
{
    return (1LL*a*b) % MOD;
}

int32_t main()
{
    optimizeIO();

    int n;
    cin>>n;

    vector<int>v(n+10);
    for(int i=1;i<=n;i++) cin>>v[i];

    vector<int>p(n+10);
    for(int i=1;i<=n;i++) p[i] = add(p[i-1] ,v[i]);

    int ans = 0;

    for(int i=1;i<=n;i++)
    {
        int sum = (p[n] - p[i] + MOD)%MOD;
        DBG(sum);
        int ad = mul(v[i],sum);

        ans = add(ans,ad);
        ans %= MOD;
    }

    cout<<ans<<endl;


    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}


Measured memory_bytes: 6364
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;
  vector<double> A(N);
  vector<double> B(N);
  double ans;
  for(int i=0; i<N; ++i){
    cin >> A[i];
  }
  for(int i=0; i<N; ++i){
    B[i]=1.0/A[i];
  }
  ans = 1.0 / accumulate(B.begin(),B.end(),0.0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 998244353;
const int INF = 9e18;

signed main() {
    int N, W;
    cin >> N >> W;
    map<int, vector<int>> input;
    for (int i = 0; i < N; i++) {
        int w, v;
        cin >> w >> v;
        input[w].push_back(v);
    }
    int base = input.begin()->first;
    for (int i = 0; i <= 3; i++) input[base + i].push_back(INF);
    auto itr = input.begin();
    while (itr != input.end()) {
        sort(itr->second.rbegin(), itr->second.rend());
        itr->second[0] = 0;
        for (int i = 1; i < itr->second.size(); i++) {
            itr->second[i] += itr->second[i - 1];
        }
        ++itr;
    }
    int ans = 0;
    for (int i = 0 ; i < input[base].size(); i++) {
        for (int j = 0; j < input[base + 1].size(); j++) {
            for (int k = 0; k < input[base + 2].size(); k++) {
                for (int l = 0; l < input[base + 3].size(); l++) {
                    int w = i * base + j * (base + 1) + k * (base + 2) + l * (base + 3);
                    if (w <= W) {
                        ans = max(ans, input[base][i] + input[base + 1][j] + input[base + 2][k] + input[base + 3][l]);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <iterator>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

int n;
int v[ten(5) + 1], memo[ten(5) + 1];

int dfs(int t){
	if (t >= n - 1) return n - 1;
	if (memo[t] != 0x80808080) return memo[t];

	memo[t] = -1;
	if (v[t] == 0) return memo[t] = t;
	return memo[t] = dfs(t + v[t]);
}

int dp[ten(5) + 1];

int main(){
	cin >> n;
	FOR(i, n) cin >> v[i];
	memset(memo, 0x80, sizeof(memo));

	memset(dp, -1, sizeof(dp));
	queue<int> q;
	q.push(0);
	dp[0] = 0;
	while (!q.empty()) {
		int p = q.front(); q.pop();
		FOR(i, 6){
			int np = dfs(p + i + 1);
			if (dp[np] == -1) {
				dp[np] = dp[p] + 1;
				q.push(np);
			}
		}
	}

	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 3688
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {

	int N;
	int K;
	string S;
	string ABC = "ABC";
	string abc = "abc";

	cin >> N;
	cin >> K;
	cin >> S;

	S[K - 1] = abc[ABC.find(S[K - 1], 0)];
	
	cout << S << endl;

	return 0;
}


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

using namespace std;


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

	int n, i, j, k, ans, ct, x;
	cin >> n;
	ans = 10000;
	while (n--) {
		cin >> x;
		ct = 0;
		while (x % 2 == 0) {
			x /= 2;
			ct++;
		}
		ans = min(ans, ct);
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
s = input()
l = s[k-1].lower()
# print(l)
if k==1:
    ans = l + s[1:]
elif k==n:
    ans = s[:-1] + l
else:
    ans = s[:k-1] + l + s[k:]
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll a, b;
    cin >> a >> b;
    if (a + b == 15) {
        cout << "+\n";
    } else if (a * b == 15) {
        cout << "*\n";
    } else {
        cout << "x\n";
    }
    return 0;
}

Measured memory_bytes: 3604
fun main(args: Array<String>) {
    fun read() = readLine()!!
    fun readInt() = read().toInt()
    fun readInts() = read().split(" ").map { it.toInt() }
    val n = readInt()
    if(n % 2 == 0) {
        println(0.5)
    } else {
        println((n / 2 + 1) / n.toDouble())
    }
}

Measured memory_bytes: 31748
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  n <- readLn :: IO Int
  as <- map (read::String->Int) . words <$> getLine
  print $ maximum [abs (x-y)|(i,x)<-zip [1..] as, (j,y)<-zip [1..] as, i<j]

Measured memory_bytes: 4896
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define lo long long 
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 200005
using namespace std;
lo int n,a,A[55],dp[55][2505][55];
lo int dfs(int node,int sayi,int kac){
	lo int cev=0;
	if(node==n+1){
		if(sayi==kac*a && kac>=1) return 1;
		return 0;
	}
	if(~dp[node][sayi][kac]) return dp[node][sayi][kac];
	cev+=dfs(node+1,sayi,kac);
	cev+=dfs(node+1,sayi+A[node],kac+1);
	return dp[node][sayi][kac]=cev;
}
int main(){
	memset(dp,-1,sizeof(dp));
	scanf("%lld %lld",&n,&a);
	for(int i=1;i<=n;i++) scanf("%lld",&A[i]);
	lo int ty=dfs(1,0,0);
	printf("%lld\n",ty);
	return 0;
}


Measured memory_bytes: 59392
<?php
fscanf(STDIN, "%d%d", $n, $m);
for($i = 0; $i < $m; $i++){
    fscanf(STDIN, "%d%d%d", $l, $r, $d);
    $link[$l][$r] =  $d;
    $link[$r][$l] = -$d;
}

for($i = 1; $i <= $n; $i++){
    if(!isset($pos[$i]))dfs($i, 0);
}
echo "Yes\n";

function dfs($i, $p){
    global $pos;
    global $link;
    if(isset($pos[$i])){
        if($pos[$i] != $p){
            echo "No\n";exit;
        }
    }else{
        $pos[$i] = $p;
        foreach($link[$i]??[] as $to => $d){
            dfs($to, $p + $d);
        }
    }
}

Measured memory_bytes: 88568
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;

public class Main {
	
	public static class Item{
		String name;
		int weight, strong;
		
		public Item(String name, int weight, int strong) {
			super();
			this.name = name;
			this.weight = weight;
			this.strong = strong;
		}
		
		public String toString(){
			return name;
		}
		
	}
	
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while (true) {
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			ArrayList<Item> input = new ArrayList<Item>(n);
			
			for(int i = 0; i < n; i++){
				input.add(new Item(sc.next(), sc.nextInt(), sc.nextInt()));
			}
			
			HashSet<Item> collect = new HashSet<Item>(n);
			LinkedList<Item> list = new LinkedList<Item>();
			Stack<Integer> stack = new Stack<Integer>();
			stack.add(0);
			
			LinkedList<Item> answer = null;
			double min = Double.MAX_VALUE;
			
			LOOP:
			while(!stack.isEmpty()){
				//System.out.println(stack);
				//System.out.println("using : " +  collect);
				
				int cur = stack.pop();
				
				if(collect.size() == n){
					double g = 0;
					int up = 0;
					int down = 0;
					int count = 1;
					for(Item item : list){
						up += count * item.weight;
						down += item.weight;
						count++;
					}
					g = up / (double)down;
					
					if(min > g){
						min = g;
						answer = (LinkedList<Item>) list.clone();
					}
					collect.remove(list.removeLast());
					continue LOOP;
				}
				
				for(int i = cur; i < n; i++){
					if(!collect.contains(input.get(i))){
						int w = 0;
						for(Item item : list){
							w += item.weight;
						}
						w += input.get(i).weight;
						
						boolean flag = true;
						for(Item item : list){
							w -= item.weight;
							if(item.strong < w){
								flag = false;
								break;
							}
						}
						
						if(flag){
							collect.add(input.get(i));
							stack.push(i + 1);
							stack.push(0);
							list.add(input.get(i));
							continue LOOP;
						}
					}
				}
				
				
				//System.out.println(list);
				
				if(list.size() != 0){
					collect.remove(list.removeLast());
				}
			}
			
			for(Item item : answer){
				System.out.println(item.name);
			}
		}			

	}
}

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

int main(){
    ll q,h,s,d,n; cin>>q>>h>>s>>d>>n;
    h=min(h,2*q);
    s=min(s,2*h);
    d=min(d,2*s);
    cout<<n/2*d+n%2*s<<endl;
}


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

#define      ll      long long int

const int N = 3005;
ll ara[N];
ll n;

ll val(ll x)
{
    ll s = 0, i;
    for (i = 1; i <= n; i++) {
        s += (x % ara[i]);
    }
    return s;
}

int main( )
{
    ll s = 0, i, j, k;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> ara[i];
        s += (ara[i] - 1);
    }
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[][] player = new int[3][n];
		int[][] num = new int[3][101];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < 3; j++) {
				int a = scanner.nextInt();
				player[j][i] = a;
				num[j][a]++;
			}

		for (int i = 0; i < n; i++) {
			int ans = 0;
			for (int j = 0; j < 3; j++) {
				if (num[j][player[j][i]] == 1)
					ans += player[j][i];
			}
			System.out.println(ans);

		}
	}
}

Measured memory_bytes: 20812
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
inline int read() {
    int x=0;
    char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return x;
}
#define N 310
int fac[N],inv[N],d[N],f[N][N][2];
int main() {
    int n=read(),flg=true; fac[0]=inv[0]=fac[1]=inv[1]=1;
    for (int i=1;i<=n;i++) fac[i]=1LL*fac[i-1]*i%mod;
    for (int i=2;i<=n;i++) inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
    for (int i=1;i<=n;i++) inv[i]=1LL*inv[i]*inv[i-1]%mod;
    for (int i=1;i<=n;i++) d[i]=read(),flg&=(d[i]==2);
    if (flg) return printf("%d\n",1LL*fac[n-1]*inv[2]%mod),0;
    f[0][0][0]=1;
    for (int i=1;i<=n;i++)
        for (int j=0;j<=i;j++)
            for (int k=0;k<=1;k++) {
                if (d[i]>0) (f[i][j][k]+=1LL*f[i-1][j][k]*inv[d[i]-1]%mod)%mod;
                if (d[i]>1) (f[i][j][k]+=1LL*f[i-1][j-1][k]*inv[d[i]-2]%mod)%=mod;
                if (d[i]>2 && k) (f[i][j][k]+=1LL*f[i-1][j-1][0]*inv[d[i]-3]%mod)%=mod;
            }
    int ans=0;
    for (int i=3;i<=n-1;i++)
        (ans+=1LL*f[n][i][1]*fac[i-1]%mod*fac[n-i-1]%mod*inv[2]%mod)%=mod;
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    int x, y;
    cin >> x >> y;

    rep(i,100) {
        rep(j,100) {
            if ((2*i + 4 *j == y) && i + j == x) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;

}


Measured memory_bytes: 3632
# input
a_n, b_n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [input().split() for i in range(m)]

# calc
min_price = min(a) + min(b)
for p in x:
   tmp_price = int(a[int(p[0])-1]) + int(b[int(p[1])-1]) - int(p[2])
   if tmp_price < min_price:
       min_price = tmp_price
print(min_price)       

Measured memory_bytes: 95484
#pragma GCC optimize("Ofast")   //Comment optimisations for an interative problem/use endl
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;  
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss;  
typedef vector<pll> vpll; 
typedef vector<ll> vll; 
typedef vector<vll> vvll; 
typedef unordered_map<ll,ll> um;

#define fastio ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define sqr(x) ((ll)(x) * (x)) 
#define reset(a, b) memset(a, b, sizeof(a)) 
#define f first 
#define s second 
#define mp make_pair 
#define pb push_back 
#define all(v) v.begin(), v.end() 
#define alla(arr, sz) arr, arr + sz 
#define showv(v) for(auto it: (v))cout<<it<<" ";newl;
#define newl cout<<"\n"

const ll MAXN=1e+2+7;
const ll MOD=1e+9+7, INF=0x7f7f7f7f7f7f7f7f;const int INFi=0x7f7f7f7f;
double EPS = 1e-9;  
double PI = acos(-1); 

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
ll t,n;
ll i,j;
ll dp[100][100];
ll a,b,ans;
//<<-----Implement Functions Here---->>//
 
 
//<<-----Start of Main--------------->>//

int main()
{
	

	cin  >> n;

	for(i=1;i<=n;i++)
	{
		a = i;
		while(a>=10)a = a/10;
		b = i%10;dp[a][b]++;
	}
	for(a =1;a<=9;a++)
	{
		for(b = 1;b<=9;b++)
		{
			ans+=dp[a][b]*dp[b][a];
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll M =1e9+7;
const int N = 1e5+7;
ll ME(ll x,ll n)
{
	ll res=1;
	
	while(n)
	{
		if(n&1)
		res=res*x;

		x=x*x;

		n/=2;

	}

	return res;

}

int main()
{
       
       string s;
       cin>>s;
       
        ll v=0;
       
       rep(i,0,s.size())
        {
            
            v+=(s[i]-'0');
            
            v%=9;
    
        }
        
        if(v%9==0)
        printf("Yes\n");
		
		else
	    printf("No\n");
            
}


Measured memory_bytes: 3748
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

		int num = sc.nextInt();
		String slimeStr = sc.next();
		List<Character> slime = new ArrayList<Character>();

		for (int i = 0; i < slimeStr.length(); i++) {
			slime.add(slimeStr.charAt(i));
		}

		char color = slime.get(0);
		int ans = 1;

		for (int i = 1; i < num; i++) {
			if (color == slime.get(i)) {
				continue;
			}
			color = slime.get(i);
			ans += 1;
		}
		System.out.println(ans);
	}
}

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


namespace Test1 {

    


    class ClassMain {


        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                //int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                //int n = ints[0];
                if (line.Equals("END OF INPUT")) { break; }

                string[] strs = line.Split(' ');

                for (int i = 0; i < strs.Length; i++) {
                    Console.Write(strs[i].Length);
                }
                Console.WriteLine();
            }
            
        }

        
    }

    

    
}

Measured memory_bytes: 5584
import java.util.Scanner;
 class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
int d;
d=a;
a=b;
b=d;
int e;
e=a;
a=c;
c=e;
System.out.println(a+" "+b+" "+c);

	}

}


Measured memory_bytes: 21716
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
    int k;
    cin>>k;
    if(k%2==0||k%5==0){
        cout<<-1<<endl;
        return 0;
    }
    int ji=1;
    int p=1;
    int sum=7;
    while(true){
        if(sum%k==0){
            break;
        }
        ji++;
        sum = (sum*10+7)%k;
        p=p*10%k;
    }
    cout<<ji;

}

Measured memory_bytes: 3616
import sys
import numpy as np
TYPE_NUM = 26

def resolve():

    inp = sys.stdin.readlines()
    D = int(inp[0])
    c = np.array(list(map(int, inp[1].split(' '))))
    s = []
    last = np.zeros(TYPE_NUM, dtype=int)
    types = []

    for i in range(2, len(inp)):
        s.append(list(map(int, inp[i].split(' '))))
    s = np.array(s, dtype=int)

    for d in range(D):
        temp_delta_satis = np.zeros([TYPE_NUM, TYPE_NUM], dtype=int)
        for idx in range(TYPE_NUM):
            val = s[d, idx]
            org = last[idx]
            last[idx] = d+1
            temp_delta_satis[:, idx] = (np.sum(-c*(d+1-last)) + val)*4
            if D != d+1:
                for idx2 in range(TYPE_NUM):
                    val2 = s[d+1, idx2]
                    org2 = last[idx2]
                    last[idx2] = d+2
                    temp_delta_satis[idx2, idx] += np.sum(-c*(d+2-last)) + val2
                    last[idx2] = org2
            last[idx] = org
        opt_idx = np.unravel_index(np.argmax(temp_delta_satis), temp_delta_satis.shape)[1]
        types.append(opt_idx+1)
    print(*types, sep='\n')

resolve()

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    string t;cin>>t;
    rep(i,t.size()){
        if(t[i]=='?')t[i]='D';
    }
    cout<<t<<endl;
}

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

int main() {
  int N;
  cin>>N;
  vector<char> S(N);
  int count=0;
  
  for(int i=0;i<N;i++){
    cin>>S.at(i);
  }
  
  for(int i=0;i<N-2;i++){
   	if(S.at(i)=='A'){
     	if(S.at(i+1)=='B'){
         	if(S.at(i+2)=='C'){
             	count++; 
            }
        }
    }
  }
  cout<<count<<endl;
  
  
}


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n;
  cin >> n;
  
  vector<int> l(n);
  REP(i,n) cin >> l[i];
  int sum = 0;
  sort(ALL(l));
  REP(i,n) {
    
    FOR(j,i+1,n-1) {
      
      int lb = j;
      int rb = n;
      int mid;
      int two = l[i] + l[j];
      while ( rb - lb > 1){
        mid = (lb + rb)/2;
        
        if(l[mid] < two){
          lb = mid;
        }else{
          rb = mid;
        }
      }
      
      sum += lb - j;
    }
    
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int64_t n,k,i,j;
    cin>>n>>k;
    vector<long double> p(n);
    for(i=0;i<n;i++){ cin>>p[i]; p[i]=((long double)p[i]+1.0)/2.0;}
    long double ans=0.0,tmp;
    for(i=0;i<k;i++){
        ans+=p[i];
    }
    tmp=ans;
    for(i=0;i<n-k;i++){
        tmp+=-p[i]+p[i+k];
        if(tmp>ans) ans=tmp;
   }
    printf("%.6f\n",(double)ans);
  return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
int main(){
    int n,R,i;
    int max,min;
    
    scanf("%d",&n);
    scanf("%d",&min);
    scanf("%d",&R);
    max=R-min;
    
    if(R<min){
        min=R;
    }


    for(i=2;i<n;i++){
        scanf("%d",&R);
        if(R-min>max){
            max=R-min;
        }
        if(R<min){
            min=R;
        }
    }
    printf("%d\n",max);
    return 0;
}



Measured memory_bytes: 1992
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	arr := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		arr[i], _ = strconv.Atoi(sc.Text())
	}

	result := make([]int, 0)
	for _, el := range arr {
		if len(result) == 0 || result[len(result)-1] >= el {
			result = append(result, el)
		} else {
			left := 0
			right := len(result)
			for left < right {
				current := (left + right) / 2
				if result[current] < el {
					right = current
				} else {
					left = current + 1
				}
			}

			result[left] = el
		}
	}

	fmt.Println(len(result))
}

Measured memory_bytes: 6144
N=int(input())
S=input()
x=0
r=1
m=10**9+7
for s in S:
    if s=='W':
        if x%2==1:
            x+=1
        elif x>0:
            r=(r*x)%m
            x-=1
        else:
            r=-1
            break
    else:
        if x%2==0:
            x+=1
        else:
            r=(r*x)%m
            x-=1
if r==-1 or x>0:
    print(0)
else:
    a=1
    for i in range(N):
        a=a*(i+1)%m
    print((r*a)%m)

Measured memory_bytes: 3516
import sys
sys.setrecursionlimit(10 ** 9)
while True:
    w, h = map(int, input().split())
    if w == 0 and h == 0:
        break
    c = [list(map(int, input().split())) for _ in range(h)]
    seen = [[False for _ in range(w)] for _ in range(h)]

    def dfs(x, y, seen):
        if not (0 <= x < h and 0 <= y < w):
            return
        if seen[x][y]:
            return
        if c[x][y] == 0:
            return
        seen[x][y] = True
        for dx in [-1, 0, 1]:
            for dy in [-1, 0, 1]:
                dfs(x + dx, y + dy, seen)

        return seen

    cnt = 0
    for i in range(h):
        for j in range(w):
            if c[i][j] == 1 and seen[i][j] == False:
                cnt += 1
                dfs(i, j, seen)

    print(cnt)


Measured memory_bytes: 8056
#include <bits/stdc++.h>
#include <ctime>
#include <sstream>
#define weewoo ios::sync_with_stdio(false);cin.tie(0)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ld long double
#define ll long long
#define se second
#define fi first
#define ctoi(x) (x-'0')
#define pi (acos(-1))
#define llputin(a,n) for(int i=0;i<n;i++){ll x;cin >> x;a.push_back(x);}
#define iputin(a,n) for(int i=0;i<n;i++){int x;cin >> x;a.push_back(x);}

#define MOD ((ll) 1e9 + (ll) 7)
using namespace std;

ll pw(ll x,ll a){
    if(a==0)
        return 1;
    ll t = pw(x,a/2);
    if(a%2==0)
        return (t*t);
    else
        return (t*t*x);
}

bool prime(int x)
{
    if(x < 2) return false;
        for(int i=2; i<= sqrt(x); i++) {
            if ((x%i) == 0) return false;
        }
    return true;
}

ll mx[200100];

int main()
{
    weewoo;
    ll n,d;
    cin >> n >> d;
    d*=2;
    d++;
    ll ans=0;
    while(n>0){
        n-=d;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll n,q;
char t[200010],d[200010];
string s;

bool checkleft(ll left){
    for(ll i=0;i<q;i++){
        if(t[i]==s[left]){
            if(d[i]=='R')left++;
            else left--;
        }
        if(left<0)return true;
        if(left>n-1)return false;
    }
    return false;
}

bool checkright(ll right){
    for(ll i=0;i<q;i++){
        if(t[i]==s[right]){
            if(d[i]=='R')right++;
            else right--;
        }
        if(right>n-1)return true;
        if(right<0)return false;
    }
    return false;
}

int main(void){
    cin>>n>>q;
    cin>>s;
    for(ll i=0;i<q;i++){
        cin>>t[i]>>d[i];
    }
    ll okl=-1,ngl=n;
    while(ngl-okl>1){
        ll mid=(okl+ngl)/2;
        if(checkleft(mid))okl=mid;
        else ngl=mid;
    }
    ll ngr=-1,okr=n;
    while(okr-ngr>1){
        ll mid=(okr+ngr)/2;
        if(checkright(mid))okr=mid;
        else ngr=mid;
    }
    ll ans=n;
    ans-=(n-okr);
    ans-=okl+1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 900
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

use rand::{thread_rng, Rng};

fn calc(v: &Vec<Vec<isize>>, plan: &Vec<usize>, c: &Vec<isize>) -> isize {
    let mut last = vec![0; 26];
    let mut res = 0_isize;
    for (i, &x) in plan.iter().enumerate() {
        res += v[i][x];
        last[x] = i as isize + 1;
        for (j, &y) in last.iter().enumerate() {
            res -= c[j] * (i as isize + 1 - y);
        }
    }

    res
}

fn main() {
    input! {
        d:usize,
        c:[isize;26]
    }
    let mut v = vec![];
    for _ in 0..d {
        input! {
            buf:[isize;26]
        }
        v.push(buf);
    }
    let mut rng = rand::thread_rng();
    let mut plan = vec![0; d];
    let mut prev_score = calc(&v, &plan, &c);

    let mut k = std::cmp::min(100, d);

    for q in 0..300_000 {
        let idx = vec![rng.gen_range(0, d); k];
        let to = vec![rng.gen_range(0, 26); k];
        let mut from = vec![];
        for &i in &idx {
            from.push(plan[i]);
        }
        for i in 0..idx.len() {
            plan[idx[i]] = to[i];
        }
        let next_score = calc(&v, &plan, &c);
        if next_score > prev_score {
            prev_score = next_score;
        } else {
            for i in 0..idx.len() {
                plan[idx[i]] = from[i];
            }
        }
        if k > 1 && q % 1000 == 0 {
            k -= 1;
        }
    }
    for i in plan {
        println!("{}", i + 1);
    }
}


Measured memory_bytes: 2860
#include <iostream>
using namespace std;
int main() {
	int a[] = { 1,5,10,50,100,500 }, i, sum = 0;
	for (i = 0; i < 6; i++) {
		int num;
		cin >> num;
		sum += num*a[i];
	}
	if (sum >= 1000) cout << "1" << endl;
	else cout << "0" << endl;
}

Measured memory_bytes: 3112
L, R = map(int, input().split())
 
mini = 2018
 
for i in range(L, R+1):
  for j in range(i+1, R+1):
    mini = min(mini, (i*j)%2019)
 
    if mini==0:
      break
  if mini==0:
    break
print(mini)

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

int main() {
    long long N;
    cin >> N;
    long long n = sqrt(N);
    for (long long i = n; i >= 1; i--) {
        if (N % i == 0) {
            long long j = N/i;
            cout << (i - 1) + (j - 1) << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 384
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/
#include <bits/stdc++.h>
#define newline ("\n")
#define deb(x) cerr << (#x) << " = " << (x) << '\n'
#define FOR(x, n) for (int x = 0; x < n; x++)
#define PI (3.141592653589)

#define MOD 1000000007
using namespace std;

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

    // Highly sophisticated code starts here

    int n;
    cin >> n;
    int arr[n];
    int brr[n];
    for (auto &i : arr)
    {
        cin >> i;
    }
    for (auto &i : brr)
    {
        cin >> i;
    }
    int sol[n];
    for (int i = 0; i < n; i++)
    {
        sol[i] = arr[i];
    }
    vector<pair<int, int>> m;
    for (int i = 0; i < n; i++)
    {
        if (arr[i] > brr[i])
        {
            m.push_back({arr[i] - brr[i], i});
        }
    }
    int index = 0;
    int count = 0;
    sort(m.rbegin(), m.rend());
    for (int i = 0; i < n; i++)
    {
        if (sol[i] < brr[i])
        {
            while (sol[i] < brr[i])
            {
                if (index >= m.size())
                {
                    cout << -1;
                    return 0;
                }
                int current = m[index].first;
                if (current > brr[i] - sol[i])
                {
                    int diff = brr[i] - sol[i];
                    m[index].first = m[index].first - (diff);
                    sol[m[index].second] -= diff;
                    sol[i] = brr[i];
                }
                else if (current == (brr[i] - sol[i]))
                {
                    int diff = brr[i] - sol[i];
                    m[index].first = 0;
                    sol[m[index].second] -= diff;
                    sol[i] = brr[i];
                    index++;
                }
                else
                {
                    int diff = m[index].first;
                    sol[m[index].second] -= diff;
                    sol[i] += diff;
                    index++;
                }
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (sol[i] != arr[i])
        {
            count++;
        }
    }
    cout << count;
    return 0;
}


Measured memory_bytes: 2044