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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  rep(i,n) {
    cin >> s[i];
  }
  sort(all(s));
  rep(i,n) cout << s[i];
  cout << endl;
}

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

void solve(long long A, long long P)
{
    P += A * 3;
    long long Pi = floor(P / 2);
    cout << Pi << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
   long N,A,B;
   cin >> N >> A >> B;
   long ans;
   if((A+B)%2==0){
       ans=(B-A)/2;
   }else if(A-1<=N-B){
       ans=(A-1)+1+(B-(A-1)-1+1)/2-1;
   }else if(A-1>N-B){
   	   ans=(N-B)+1+N-(A+(N-B)+1+N)/2;
   }
   cout << ans << endl;
}


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

int NumberPass(int &CookieNumber) {
  int ret = 0;
  if (CookieNumber % 2 == 1) {
    CookieNumber--;
  }
  ret = CookieNumber / 2;
  CookieNumber /= 2;
  return ret;
}

void solve() {
  int A, B, K;
  std::cin >> A >> B >> K;

  for (int i = 0; i < K; i++) {
    if (i % 2 == 0) {
      B += NumberPass(A);
    } else {
      A += NumberPass(B);
    }
  }

  std::cout << A << " " << B << "\n";
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
typedef long long ll;
using namespace std;

const double PI=3.14159265358979323846;

int main() {
    int a, b;
    double h, m;
    cin >> a >> b >> h >> m;
    double ra,sa,ang=0,ans=0;
    sa=(h*60.0+m)/2.0;
    ra=m*6;
    ang=(PI*abs(sa-ra))/180.0;
    ans=sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(ang));
    printf("%.10f\n",ans);
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
      if(b-a == c-b){
    System.out.println("YES");
      }else{
	System.out.println("NO");
      }
}
}

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

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct Edge
{
	int f;
	int t;
	int c;
	Edge(int from, int to, int cost)
		:f(from), t(to), c(cost)
	{}
};

vector<Edge> e;

int main()
{
	ll L;
	cin >> L;
	int r = 0;
	while (pow(2, r + 1) <= L)
	{
		r++;
	}

	int n = r;
	REP(i, n)
	{
		e.push_back(Edge(i + 1, i + 2, 0));
		e.push_back(Edge(i + 1, i + 2, pow(2, i)));
	}

	IREP(i, n)
	{
		if (L - pow(2, i) >= pow(2, n))
		{
			e.push_back(Edge(i + 1, n + 1, L - pow(2, i)));
			L -= pow(2, i);
		}
	}

	cout << n + 1 << " " << e.size() << endl;
	REP(i, e.size())
	{
		cout << e[i].f << " " << e[i].t << " " << e[i].c << endl;
	}
	return 0;
}

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

int n;
char s[15];
int ndA, stB, pairs;

int main() {
	scanf("%d", &n);

	int ans = 0;
	for(int i = 1; i <= n; i++) {
		scanf("%s", s);

		int l = strlen(s);

		for(int j = 0; j < l - 1; j++) {
			if(s[j] == 'A' && s[j + 1] == 'B')
				ans++;
		}

		if(s[l - 1] == 'A')
			ndA++;

		if(s[0] == 'B')
			stB++;

		if(s[l - 1] == 'A' && s[0] == 'B')
			pairs++;
	}

	if(pairs > 0) {
		ans += pairs - 1;

		ndA -= pairs;
		stB -= pairs;

		if(ndA >= 1) {
			ans++;
			ndA--;
		}

		if(stB >= 1) {
			ans++;
			stB--;
		}

		ans += min(ndA, stB);
	}

	else {
		ans += min(ndA, stB);
	}

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

Measured memory_bytes: 256
l=list(map(int,input().split()))
ll=[]

for i in range(2):
    if l[i]==2:
        ll.append("A")
    elif l[i]==4 or l[i]==6 or l[i]==9 or l[i]==11:
        ll.append("B")
    else:
        ll.append("C")
print("YNeos"[ll[0]!=ll[1]::2])


Measured memory_bytes: 3060
a, b, c, d, e, f = map(int, input().split())

Water = []
Sugar = []

for i in range(0,31):
    for j in range(0,16):
        w = 100*a*i + 100* b*j
        if w <= f:
            Water.append(w)

Water = set(Water)
Water.remove(0)

for k in range(0,3001):
    for l in range(0,1501):
        s = c*k + d*l
        if s <= f:
            Sugar.append(s)

Sugar = set(Sugar)

ans_conc = 0
ans_water = 0
ans_sugar = 0
max_conc = (100*e)/(100+e)

for w in Water:
    for s in Sugar:
        conc = (100 * s) /(w + s)
        if (conc <= max_conc) and (w+s <= f) and (ans_conc <= conc):
            ans_conc = conc
            ans_water = w
            ans_sugar = s 
            
print(str(ans_water+ans_sugar) + ' ' + str(ans_sugar))

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

const int INF = 1e9;
vector<vector<int>> to(100001);

void solve() {
  int N;
  int M;
  cin >> N >> M;

  rep(i, 0, M) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    to[u].push_back(v);
    to[v].push_back(u);
  }

  queue<int> q;
  vector<int> d(N, INF);
  vector<int> p(N, -1);
  d[0] = 0;
  q.push(0);

  while (!q.empty()) {
    int v = q.front();
    q.pop();

    for (auto u : to[v]) {
      if (d[u] != INF) continue;
      d[u] = d[v] + 1;
      p[u] = v;
      q.push(u);
    }
  }

  cout << "Yes" << endl;
  rep(i, 1, N) { cout << (p[i] + 1) << endl; }
}

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

Measured memory_bytes: 10604
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k;
	cin>>n>>k;
	ll ans = n%k;
	n = ans;
	ll h = k -n;
	ans = min(ans,h);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define N 2000001
#define k 10000

int main(){

    int n,i,j;
    int *A,*B,C[N];

    scanf("%d",&n);

    A = malloc(sizeof(int) *n+1);
    B = malloc(sizeof(int) *n+1);

    for(i=0 ; i<k ; i++) C[i]=0;

    for(i=0 ; i<n ; i++){
      scanf("%d",&A[i]);
      C[A[i]]++;
    }

    for (i=1; i <=k ; i++) {
      C[i]+=C[i-1];
    }

    for(j=n-1 ; j>=0 ; j--){
      B[C[A[j]]]=A[j];
      C[A[j]]--;
    }

    for(i=1 ; i<=n ; i++){
      printf("%d",B[i]);
      if(i<n) printf(" ");
    }

    printf("\n");

    return 0;

}

Measured memory_bytes: 16280
import sys
import itertools

sys.setrecursionlimit(10**6)
input = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()

    if N < 3:
        print(0)
        return
    
    ans = 0
    for i,j,k in itertools.combinations(L, 3):
        if len(set([i, j, k])) != 3:
            continue
        if i + j <= k:
            continue
        ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9216
#include<stdio.h>
int main()
{
    int s,a,b,c;
    scanf("%d", &s);
    if(s>=0&&s<=86400)
    {
    a=s/3600;
    b=(s%3600)/60;
    c=((s%3600)%60);
    printf("%d:%d:%d\n",a,b,c);
    }
    return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

int main(){
	int N;
	cin >> N;
	vi A(N);
	double sum=0;
	for(int i=0; i<N; i++){
		cin >> A[i];
		sum+=1/(double)A[i];
	}

	cout << fixed;
	cout << std::setprecision(7) << 1/sum << endl;

	return 0;
}

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

const ll N = 100009;
ll i,n,s;
ll a[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n;
    rep(i,0,n) cin>>a[i];
    sort(a,a + n);
    rep(i,0,n - 1) s += a[i];
    cout<<(s > a[n - 1] ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n, a[101], i;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (i = n - 1; i >=0; i--)
	{
		if (i != 0)
			cout << a[i] <<" ";
		else
			cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

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

    if((x+y)%3==0) {
        int c = (x+y)/3;
        int t = c*2 - y;
        if(t>=0 && t <= y){
            ll ans = 1;
            rep(i, c){
                ans *= i+1;
                ans %= MOD;
            }
            rep(i, c-t){
                ans *= mpow(i+1, MOD-2)%MOD;
                ans %= MOD;
            }
            rep(i, t){
                ans *= mpow(i+1, MOD-2)%MOD;
                ans %= MOD;
            }
            cout << ans << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n, k;
	cin >> n >> k;
	cout << (n - 1 + k - 2) / (k - 1) << endl;
	
	
	return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    string s;
    cin >> s;
    if(s[0] == s[s.size() - 1]) {
        if(s.size() % 2 == 0) {
            cout << "First";
        } else {
            cout << "Second";
        }
    } else {
        if(s.size() % 2 == 0) {
            cout << "Second";
        } else {
            cout << "First";
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3772
r, c = map(int, input().split())

m = []

t = [ 0 for _ in range(c+1) ]

for _ in range(r):
    row = list(map(int, input().split()))
    l = row+[sum(row)]

    m.append(l)
    for i in range(len(l)):
        t[i] += l[i]

m.append(t)

for l in m:
    sep = ''
    for e in l:
        print(sep+str(e), end='')
        sep = ' '
    print()



Measured memory_bytes: 6244
function main(s) {
	n = Number(s.split("\n")[0]);
	for (var i = Math.ceil(Math.sqrt(n)); i > 0; i--) {
		if (i * i <= n) {console.log(i * i); return;}
	}
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 7624
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<string> words;
  vector<string> memo;
  rep(i, n) {
    string s;
    cin >> s;
    words.push_back(s);
  }
  memo.push_back(words[0]);
  bool flag = true;
  for (int i = 1; i < n; i++) {
    char a, b;
    a = words[i - 1][words[i - 1].size() - 1];
    b = words[i][0];
    if (a == b) {
      rep(j, memo.size()) {
        if (words[i] == memo[j])
          flag = false;
      }
    } else {
      flag = false;
    }
    if (flag)
      memo.push_back(words[i]);
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int x ,a;
  char l [4];  

  cin >> l;
  
  for(int i=0; i<3; i++) {
    if (l[i] == l[i+1]) {
      cout << "Bad";
      return 0;
    }
  }
  
  cout << "Good";

  return 0;
}

Measured memory_bytes: 256
# coding:utf-8

N = int(input())
bricks = [a for a in map(int, input().split(' '))]
start = False
pre = 0
ans = 0

for brick in bricks:
    if not start:
        if brick == 1:
            start = True
            pre = 1
        else:
            ans += 1
    else:
        if brick == pre + 1:
            pre += 1
        else:
            ans += 1

if ans == N:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 26012
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, m = map(int, readline().split())
aa = list(map(int, readline().split()))
bb = list(map(int, readline().split()))
xyc = [list(map(int, readline().split())) for _ in range(m)]
ans = float('inf')
for x, y, c in xyc:
    ans = min(aa[x - 1] + bb[y - 1] - c, ans)
aa.sort()
bb.sort()
print(min(ans, aa[0] + bb[0]))


Measured memory_bytes: 38928
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}

int MAX_N=200000;

int main(){
    ios::sync_with_stdio(false);
    int n;
    ll boss[MAX_N+5]={};
    int a[MAX_N+5];
    cin >> n;
    rep(i,n-1){
        cin >> a[i];
        boss[a[i]]++;
    }
    for(int i=1;i<(n+1);i++){
        cout << boss[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 5988
#                         author:  kagemeka 
#                         created: 2019-11-07 13:42:36(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    s = sys.stdin.readline().rstrip()
    k = int(sys.stdin.readline().rstrip())
    n = len(s)
    
    substrings = []
    for i in range(1, k+1):
        for j in range(n-i+1):
            substring = s[j:j+i]
            substrings.append(substring)
    substrings = sorted(list(set(substrings)))
    print(substrings[k-1])


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 5084
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<(S)<<endl
#define F first
#define S second
using namespace std;

int main(){
	int N;
	cin>>N;
	REP(n,0,N){
		int H,W;
		cin>>H>>W;
		bool safe=true;
		map<char,int> xmin,xmax,ymin,ymax;
		char field[51][51];
		set<char> s;
		REP(i,0,H){
			REP(j,0,W){
				cin>>field[i][j];
				char c=field[i][j];
				if(c=='.') continue;
				if(s.find(c)==s.end()){
					s.insert(c);
					xmin[c]=xmax[c]=j;
					ymin[c]=ymin[c]=i;
				}
				else{
					xmin[c]=min(xmin[c],j);
					xmax[c]=max(xmax[c],j);
					ymin[c]=min(ymin[c],i);
					ymax[c]=max(ymax[c],i);
				}
			}
		}
		set<char> oks;
		for(char c:s){
			bool flag=true;
			REP(i,ymin[c],ymax[c]+1) REP(j,xmin[c],xmax[c]+1){
				if(field[i][j]!=c) flag=false;
			}
			if(flag) oks.insert(c);
		}
		while(s.size()!=oks.size()){
			bool flag2=false;
			for(char c:s){
				if(oks.find(c)!=oks.end()) continue;
				bool flag=true;
				REP(i,ymin[c],ymax[c]+1) REP(j,xmin[c],xmax[c]+1){
					if(field[i][j]!=c&&oks.find(field[i][j])==oks.end()) flag=false;
				}
				if(flag){
					oks.insert(c);
					flag2=true;
				}
			}
			if(!flag2) {
				safe=false;
				break;
			}
		}
		p(safe?"SAFE":"SUSPICIOUS");
	}

	return 0;
}

Measured memory_bytes: 2992
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


int n, t[100010], c, k;

int main(){
	cin >> n >> c >> k;
	for(int i = 0; i < n; i++){
		cin >> t[i];
	}
	
	sort(t, t+n);
	
	int cnt = 1, was = t[0], m = 1;
	for(int i = 1; i < n; i++){
		m++;
		if(t[i] - was > k || m > c){
			was = t[i];
			cnt++;
			m = 1;
		}
	}
	
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 640
S = input()
k=0
t=len(S)
while k<len(S):
    if(S[-(k+5):t-k] == 'dream' or S[-(k+5):t-k] == 'erase')and k+5<len(S)+1:
        k+=5
        continue
    elif(S[-(k+6):t-k] == 'eraser')and k+6<len(S)+1:
        k+=6
        continue
    elif(S[-(k+7):t-k] == 'dreamer')and k+7<len(S)+1:
        k+=7
        continue
    else:
        print('NO')
        break
else:
    print('YES')

Measured memory_bytes: 40400
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i = (s);i<(int)(n);i++)

int main(){
    int n,x,t;
    cin >> n >> x >> t;
    int l = (n + x - 1)/x;
 //  cout<<l<<endl;
   cout << l*t << endl;
}


Measured memory_bytes: 3120
N,M=map(int,input().split())
A=[input() for _ in range(N)]
B=[input() for _ in range(M)]

for i in range(N-M+1):
    for j in range(N-M+1):
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l]!=B[k][l]:
                    break
            else:
                continue
            break
        else:
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip> 

using namespace std;

#define mp make_pair
#define pb push_back
#define forn(i, n) for(int i = 0; i < (int)(n); ++i)
#define for1(i, n) for(int i = 1; i < (int)(n); ++i)
#define nfor(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define correct(x, y, n, m) (0 <= x && x < n && 0 <= y && y < m)
#define all(x) (x).begin(), (x).end()
#define fst first
#define snd second
#define endl "\n"

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<int,int,int> iii;

template<typename T> inline T abs(T a){ return ((a < 0) ? -a : a); }
template<typename T> inline T sqr(T a){ return a * a; }
template<class T> T gcd(T a, T b) { return a ? gcd (b % a, a) : b; }
template<class T> T lcm(T a, T b) { return a / gcd (a, b) * b; }
template<class T> T sign(T a) { return a > 0 ? 1 : (a < 0 ? -1 : 0); }

string to_string(string s) {
    return '"' + s + '"';
}
    
string to_string(const char* s) {
    return to_string((string) s);
}
    
string to_string(bool b) {
    return (b ? "true" : "false");
}
    
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
    
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void fastIO() {
    cin.sync_with_stdio(false);
    cin.tie(0);
}

template<typename T>
vector<T> make_unique(vector<T> v) {
    sort(all(v));
    return v.resize(unique(all(v)) - v.begin());
}

int nxt() {
    int x;
    cin >> x;
    return x;
}

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int dxKn[8] = {-2, -1, 1, 2,  2,  1, -1, -2};
const int dyKn[8] = { 1,  2, 2, 1, -1, -2, -2, -1};
const int dxK[8] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dyK[8] = {1, -1, 0, 0, 1, -1, 1, -1};

const int MOD = int(1e9) + 7;
const int INF = int(1e9) + 100;
const ll INF64 = 2e18;
const ld PI = ld(3.1415926535897932384626433832795);
const ld e = ld(2.7182818284590452353602874713527);
const ld EPS = 1e-9;

//#############################
const int MAXN = 1000005;

int main() {
    fastIO(); 
    int x = nxt();
    cout << !x << endl;
    return 0;
}

Measured memory_bytes: 3116
#include <stdio.h>
int main(){
    int h1,m1,h2,m2,k;
    int time1,time2;
    scanf("%d %d %d %d %d",&h1,&m1,&h2,&m2,&k);
    time1=h1*60+m1;
    time2=h2*60+m2;
    time2-=time1;
    if(time2<0) time2+=12*60;
    printf("%d\n",time2-k);
}

Measured memory_bytes: 1732
import java.util.Scanner;

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

        long n, a, b, c, d, e;
        long [] p = new long [6];
        long minP = 0;
        int minPC = 0;
        long time = 0;

        n = stdIn.nextLong();
        a = stdIn.nextLong();
        b = stdIn.nextLong();
        c = stdIn.nextLong();
        d = stdIn.nextLong();
        e = stdIn.nextLong();
        p[0] = n;

        minP = a;
        if(b<minP){
            minP = b;
            minPC = 1;
        }
        if(c<minP){
            minP = c;
            minPC = 2;
        }
        if(d<minP){
            minP = d;
            minPC = 3;
        }
        if(e<minP){
            minP = e;
            minPC = 4;
        }

        if(n%minP == 0){
            time = 4 + n/minP;
        }else{
            time = 5 + n/minP;
        }

        System.out.print(time);
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  vector<int> A(100,0);
  for(int i=2;i<=N;i++){
    int j=i;
    for(int k=2;k<=j/k;k++)
      for(;j%k==0;j/=k)
        A[k]++;
    if(j!=1)
      A[j]++;
  }
  vector<int> B(0);
  for(int i=0;i<50;i++)
    if(A[i])
      B.push_back(A[i]);
  int M=B.size(),ans=0;
  for(int i=0;i<M;i++){
    if(B[i]>=74)
      ans++;
    for(int j=0;j<M;j++){
      if(i==j)continue;
      if(B[i]>=24 && B[j]>=2)
        ans++;
      if(B[i]>=14 && B[j]>=4)
        ans++;
      if(i>=j)
        continue;
      for(int k=0;k<M;k++)
        if(i!=k && j!=k && B[i]>=4 && B[j]>=4 && B[k]>=2)
          ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mset(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef LOCAL
#define dmp(...) _dmp(#__VA_ARGS__, __VA_ARGS__)
#else
#define dmp(...) (__VA_ARGS__)
#endif
template<class T> using vt=vector<T>;
template<class T> using vvt=vt<vt<T>>;
template<class TA,class TB> void chmax(TA&a,TB b){if(a<b)a=b;}
template<class TA,class TB> void chmin(TA&a,TB b){if(b<a)a=b;}
template<class TA,class TB>
ostream& operator<<(ostream& os,const pair<TA,TB>& p){
	return os<<"{"<<p.fi<<","<<p.se<<"}";
}
template<class T> ostream& operator<<(ostream& os,const vt<T>& v){
	os<<"{";for(auto& e:v)os<<e<<",";return os<<"}";
}
template<class TH> void _dmp(const char *sdbg, TH h){cout<<sdbg<<"="<<h<<endl;}
template<class TH, class... TA> void _dmp(const char *sdbg, TH h, TA...a){
while(*sdbg!=',')cout<<*sdbg++;cout<<"="<<h<<","; _dmp(sdbg+1, a...);
}
template<class T> void make_unique(vt<T>& v) {
	sort(all(v));v.erase(unique(all(v)),v.end());
}
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
int ri(){int x;cin>>x;return x;}
ll rll(){ll x;cin>>x;return x;}
vi rvi(int n){vi v;rep(i,n)v.pb(ri());return v;}
int n,t;
char s[11];
void go(int pos,int cur) {
	if(pos==n) {
		cout<<s<<'\n';
		return;
	}
	for(int i=0;i<=cur;i++){ 
		s[pos]='a'+i;
		go(pos+1,cur);
	}
	s[pos]='a'+cur+1;
	go(pos+1,cur+1);
}
void MAIN() {
	n=ri();
	go(0,-1);
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	int T=1;
	//cin>>T;
	for(int tt=1;tt<=T;tt++) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 1536
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using static System.Console;

namespace AB127A
{
    static class Program
    {
        static void Main(string[] args)
        {
            var n = ReadLine().SplitTryParseToList<int>();
            int a = n[1];
            if (n[0] <= 5)
            {
                a = 0;
            }
            else if (n[0] <= 12)
            {
                a = n[1] / 2;
            }
            WriteLine(a);
        }

        public static T TryParse<T>(this String input)
        {
            try
            {
                var converter = TypeDescriptor.GetConverter(typeof(T));
                if (converter != null)
                {
                    return (T)converter.ConvertFromString(input);
                }
                else
                {
                    throw new InvalidCastException("");
                }
            }
            catch
            {
                throw new InvalidCastException(typeof(T) + " is not supported.");
            }
        }

        public static List<T> SplitTryParseToList<T>(this String input)
        {
            return input.Split().Select(n => n.TryParse<T>()).ToList();
        }

        public static List<T> ListSwap<T>(this List<T> list, Int32 index1, Int32 index2)
        {
            var t = list[index1];
            list[index1] = list[index2];
            list[index2] = t;
            return list;
        }

        public static List<Tuple<T, int>> DuplicateCount<T>(this IEnumerable<T> list)
        {
            return list
                .GroupBy(i => i)
                .Where(g => g.Any())
                .Select(g => Tuple.Create(g.Key, g.Count()))
                .ToList();
        }
        public static List<Tuple<T, int>> DuplicateSort<T>(this IEnumerable<Tuple<T, int>> list)
        {
            return list.OrderByDescending((x) => x.Item2).ToList();
        }
        public static List<T> ReadLineOne<T>(int n)
        {
            var list = new List<T>();
            foreach (var i in Enumerable.Range(1, n))
            {
                list.Add(Console.ReadLine().TryParse<T>());
            }
            return list;
        }
        public static void PrintAll<T>(this IEnumerable<T> list)
        {
            foreach (var i in list)
            {
                Console.Write($"{i} ");
            }

            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 13280
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = 45;
const int maxm = 405;

int f[maxn][maxm][maxm];
int n,a[maxn],b[maxn],c[maxn];
int ma,mb;

void pd(int&ret,int val) {
  if(ret==-1||ret>val)ret=val;
}

int main() {
  //freopen("in.cpp","r",stdin);
  cin>>n>>ma>>mb;
  for(int i=1; i<=n; i++)cin>>a[i]>>b[i]>>c[i];
  memset(f,-1,sizeof(f));
  f[0][0][0]=0;
  for(int i=0; i<n; i++)
    for(int j=0; j<maxm; j++)
      for(int k=0; k<maxm; k++) {
        if(f[i][j][k]==-1)continue;
        pd(f[i+1][j][k],f[i][j][k]);
        if(j+a[i+1]<maxm&&k+b[i+1]<maxm)
          pd(f[i+1][j+a[i+1]][k+b[i+1]],f[i][j][k]+c[i+1]);
      }
  int ret=-1;
  for(int i=1; i<maxm; i++)
    for(int j=1; j<maxm; j++)
      if(i*mb==j*ma&&f[n][i][j]!=-1)pd(ret,f[n][i][j]);
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 29056
// Problem : B - Product Max
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

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

#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define pb push_back
#define fi first
#define se second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()

const ll inf=0x3f3f3f3f3f3f3f3f;

int main() {
    SPEED;
    ll a, b, c, d;
    cin>>a>>b>>c>>d;
    cout<<max(max(a * c, a * d), max(b * c, b * d));
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
using namespace std;
#define N (123456*2+1)

int main(){
  bool isP[N];
  int k[N];

  for( int i=0;i<N;i++ )
    isP[i]=true;
  isP[0]=false;  isP[1]=false;
  k[0]=0;  k[1]=0;
  for( int i=2;i<N;i++ ){
    k[i]=k[i-1];
    if( !isP[i] ) continue;
    k[i]++;
    for( int j=2*i;j<N;j+=i )
      isP[j] = false;
  }

  int n;
  while( cin>>n && n )
    cout << (k[2*n]-k[n]) << endl;

  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int count[4][3][10]={0};
    int n,b,f,r,v,i,j,k,o;
    scanf("%d", &n);
    
    for (i=0; i<n; i++) {
        
        scanf("%d %d %d %d",&b,&f,&r,&v);
        count[b-1][f-1][r-1]+=v;
    }
    
    for (o=0; o<4;o++ ) {
        for (j=0; j<3; j++) {
            for (k=0; k<10; k++) {
                printf(" %d",count[o][j][k]);
            }printf("\n");
        }if (o<3) {
            printf("####################\n");
            
        }
    }
    
   
    return 0;
}

Measured memory_bytes: 2680
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  double_t N; cin >> N;
  auto ans = 2*N * 3.14159265359;
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 3792
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

// for i in f..<t {... : as Swift
#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;

using sword = pair<ll, ll>;

int main() {
    ll n, h;
    cin >> n >> h;
    vector<sword> swords(n);
    for (auto &s : swords) cin >> s.first >> s.second;
    ll maxa = 0;
    for (auto s : swords) {
        maxa = max(maxa, s.first);
    }
    sort(swords.begin(), swords.end(), [](sword l, sword r) {
        return l.second > r.second;
    });
    auto count = 0;
    for (auto s : swords) {
        if (h <= 0) break;
        if (s.second > maxa) {
            h -= s.second;
            count++;
        } else {
            break;
        }
    }
    if (h > 0)
        count += h / maxa + (h % maxa > 0 ? 1 : 0);
    cout << count << endl;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define DO {
#define END }
typedef long long ll;
#define MAXN 100000

ll f[MAXN];
ll weighted[MAXN];

ll init(){
    REP(i,MAXN) {   f[i]=i;weighted[i]=1;}
}

ll findu(ll a){
    return a==f[a]?(a):(f[a]=findu(f[a]));
}

ll getNumu(ll id){
    return weighted[findu(id)];
}

void unite(ll a,ll b){
    ll fa=findu(a),fb=findu(b);
    if(fa!=fb)
    {
        weighted[fb]+=weighted[fa];
        f[fa]=fb;   
    }

}

void printu(){
    REP(i,MAXN) cout<<f[i]<<" ";
    cout<<endl;
}

ll n,m,a[MAXN],b[MAXN],res[MAXN+1];

int main(){
    init();
    cin>>n>>m;
    REP(i,m)
        cin>>a[i]>>b[i];
    res[m]= n*(n-1)>>1;
    for(ll i=m-1;i>=0;i--)
        DO
            if(findu(a[i])==findu(b[i])) res[i]=res[i+1];
            else DO
                ll anum=getNumu(a[i]),bnum=getNumu(b[i]);
    unite(a[i],b[i]);
    res[i]=res[i+1]-anum*bnum;
    END 
        END
        REP1(i,m) cout<<res[i]<<endl;
    return 0;

}



Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define yes(a) printf(a ? "yes\n" : "no\n")
#define Yes(a) printf(a ? "Yes\n" : "No\n")
#define YES(a) printf(a ? "YES\n" : "NO\n") 
const long double PI = acos(-1);
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;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
	
  ll x;
  cin >> x;
  cout << (x/500*1000) + ((x-((x/500)*500))/5)*5 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int N;
string ans;
char ret[MAX_N];

char nextchr(char center, char left, char a){
	if (center == 'S' && a == 'o' && left == 'S'){ return 'S'; }
	if (center == 'S' && a == 'o' && left == 'W'){ return 'W'; }
	if (center == 'S' && a == 'x' && left == 'S'){ return 'W'; }
	if (center == 'S' && a == 'x' && left == 'W'){ return 'S'; }
	if (center == 'W' && a == 'o' && left == 'S'){ return 'W'; }
	if (center == 'W' && a == 'o' && left == 'W'){ return 'S'; }
	if (center == 'W' && a == 'x' && left == 'S'){ return 'S'; }
	if (center == 'W' && a == 'x' && left == 'W'){ return 'W'; }
}

bool check(char center, char left, char right, char a){

	if ((center == 'S' && a == 'o') || (center == 'W' && a == 'x')){
		return left == right;
	}
	else{
		return left != right;
	}

}

void print(){
	rep(i, N){
		cout << ret[i];
	}
	cout << endl;
}

bool run(char first, char second){

	ret[0] = first;
	ret[1] = second;
	for (int i = 2; i < N; i++){
		ret[i] = nextchr(ret[i - 1], ret[i - 2], ans[i - 1]);
	}

	return (check(ret[0], ret[N - 1], ret[1], ans[0]) && 
		    check(ret[N - 1], ret[0], ret[N - 2], ans[N - 1]));
}

int main() {

	cin >> N;
	cin >> ans;

	bool success = false;

	if (!success){
		success = run('S', 'S');
	}
	if (!success){
		success = run('S', 'W');
	}
	if (!success){
		success = run('W', 'S');
	}
	if (!success){
		success = run('W', 'W');
	}

	if (success){
		print();
	}
	else{
		cout << -1 << endl;
	}
	
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#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>

using namespace std;

char c[8][9];

void dfs(int x,int y){
	c[y][x] = '0';
	for (int i = -3; i <= 3; i++){
		int nx = x + i;
		if(nx >= 0 && nx < 8 && c[y][nx] == '1')
			dfs(nx,y);
	}
		for (int i = -3; i <= 3; i++){
		int ny = y + i;
		if(ny >= 0 && ny < 8 && c[ny][x] == '1')
			dfs(x,ny);
	}
}

void solve() {
	for(int i= 0; i < 8; i++) cin>>c[i];
	int x,y;
	cin>>x>>y;
	dfs(x-1,y-1);
	for(int i= 0; i < 8; i++) cout<<c[i]<<endl;
}

int main(){
	int t; cin>>t;
	for(int i = 1; i <= t; i++){
		printf("Data %d:\n",i);
		solve();
	}
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm> // sort

using namespace std ;

int main(void) {
    int n ;
    cin >> n ;

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

    sort(a, a+n) ;
    for (int i = 0; i < n; i++) {
        if (a[n-1] == b[i])
            cout << a[n-2] << endl ;
        else
            cout << a[n-1] << endl ;
    }

    delete[] a;
    delete[] b;
    return 0 ;
}

Measured memory_bytes: 3200
#include <iostream>
#include <cstdio>
#include <stack>
#include <vector>

static const int N = 101;

using namespace std;

vector<vector<int> > V;
int d[N], f[N];
int step = 1;

void dfs (int v) {
  if (d[v])
    return;

  d[v] = step++;

  for (vector<int>::iterator it = V[v].begin(); it != V[v].end(); it++) {
    if (!d[*it]) {
      dfs(*it);
    }
  }

  f[v] = step++;
}

void dfs_init (int n) {
  for (int i = 1; i <= n; i++)
    dfs(i);
}

int main () {
  int n, v, v2, k;
  // stack<int> S;
  // vector<vector<int> > V;

  for (int i = 0; i <= N; i++) {
    vector<int> A;
    V.push_back(A);
  }
  for (int i = 0; i <= N; i++)
    d[i] = f[i] = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> v >> k;

    for (int j = 0; j < k; j++) {
      cin >> v2;
      V[v].push_back(v2);
    }
  }

  // for (int i = 1; i <= n; i++) {
  //   for (int j = 1; j <= n; j++)
  //     cout << V[i][j] << (j == n ? "" : " ");
  //   cout << endl;
  // }

  // int step = 1;
  // bool breaked = false;

  // S.push(1);
  // d[S.top()] = step++;

  // while (S.size()) {
  //   // cout << "S.top = " << S.top() << endl;
  //   breaked = false;

  //   for (vector<int>::iterator it = V[S.top()].begin(); it != V[S.top()].end(); it++) {
  //     if (!d[*it]) {
  //       d[*it] = step++;
  //       S.push(*it);
  //       breaked = true;
  //       break;
  //     }
  //   }

  //   if (!breaked) {
  //     f[S.top()] = step++;
  //     S.pop();

  //     if (S.empty()) {
  //       for (int i = 1; i <= n; i++) {
  //         if (!d[i]) {
  //           S.push(i);
  //           d[i] = step++;
  //           break;
  //         }
  //       }
  //     }
  //   }
  // }

  dfs_init(n);

  for (int i = 1; i <= n; i++)
    cout << i << " " << d[i] << " " << f[i] << endl;

  return 0;
}


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

set<pair<int, int>> es;

vector<int> shrink_loop(vector<int> loop) {
    int n = loop.size();
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if ((i + 1) % n == j) {
                assert(es.count({loop[i], loop[j]}));
                continue;
            }
            if (es.count({loop[i], loop[j]})) {
                vector<int> newloop;
                if (i < j) {
                    for (int k = j; k < n; k++) {
                        newloop.push_back(loop[k]);
                    }
                    for (int k = 0; k <= i; k++) {
                        newloop.push_back(loop[k]);
                    }
                } else {
                    for (int k = j; k <= i; k++) {
                        newloop.push_back(loop[k]);
                    }
                }
                return shrink_loop(newloop);
            }
        }
    }
    return loop;
}

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

    int n, m;
    cin >> n >> m;

    vector<vector<int>> adj(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        es.insert({a, b});
        adj[a].push_back(b);
    }

    bool has_cycle = false;
    vector<int> loop;

    function<void(int, bitset<1010>, vector<int>)> dfs = [&](int v, bitset<1010> visited, vector<int> acc) {
        if (has_cycle) return;
        visited[v] = 1;
        acc.push_back(v);
        for (int s : adj[v]) {
            if (has_cycle) return;
            if (visited[s]) {
                has_cycle = true;
                acc.push_back(s);
                loop = acc;
                return;
            }
            if (has_cycle) return;
            dfs(s, visited, acc);
        }
    };

    for (int i = 0; i < n; i++) {
        dfs(i, bitset<1010>(), vector<int>());
        if (has_cycle) break;
    }
    if (!has_cycle) {
        cout << -1 << endl;
        return 0;
    }

    while (loop.front() != loop.back()) {
        loop.erase(loop.begin());
    }
    loop.erase(loop.begin());
    assert(!loop.empty());

    loop = shrink_loop(loop);
    assert(!loop.empty());

    cout << loop.size() << endl;
    for (int a : loop) {
        cout << a + 1 << '\n';
    }
}


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

int main()
{
    ll N, M;
    cin >> N >> M;

    ll ans = 0;
    if (M - N*2 > 0 ) {
        ans += N;
        ans += (M-N*2)/4;
    }else{
        ans = M/2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<string>

std::string s;

int blue,red;

int main(){

    std::cin>>s;

    for(auto&& x:s){
        if(x=='0')red++;
        if(x=='1')blue++;
    }

    std::cout<<std::min(red,blue)*2<<std::endl;

    return 0;
}

Measured memory_bytes: 512