akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;

const int INF = 1e7;
struct Edge { int from, to, cost; };

int main() {
    int n;
    while (cin >> n, n) {
        vector<int> a(2*n);
        for (int i=0; i<2*n; ++i) cin >> a[i];

        vector<Edge> edges;
        for (int i=0; i<2*n; ++i) {
            if (a[i] == 0 || (a[i] == 1 && (i%n == n-1 || a[i+1] != 1))) {
                edges.push_back((Edge){i, (i+n)%(2*n), 1});
                if (i%n == n-1) continue;
                edges.push_back((Edge){i, (i+n)%(2*n)+1, 1});
                if (i%n == n-2) continue;
                edges.push_back((Edge){i, (i+n)%(2*n)+2, 1});
            } else if (a[i] == 1) {
                edges.push_back((Edge){i, i+1, 0});
            } else if (a[i] == 2) {
                edges.push_back((Edge){i, i-1, 0});
            }
        }

        int d[200];
        fill(d, d+200, INF);
        d[0] = d[n] = 0;
        for (int k=0; k<600; ++k) {
            for (int i=0; i<(int)edges.size(); ++i) {
                d[edges[i].to] = min(d[edges[i].to], d[edges[i].from] + edges[i].cost);
            }
        }

        int ans = INF;
        if (a[n-1] != 2) ans = min(ans, d[n-1]);
        if (a[2*n-1] != 2) ans = min(ans, d[2*n-1]);
        if (ans == INF) {
            cout << "NA" << endl;
        } else {
            cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#define fs first
#define se second

using namespace std;
typedef long long llong;
typedef pair<int, int> pii;

void fail() {
    printf("No\n");
    exit(0);
}

int n, a, b, c, d;
char S[200005];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> a >> b >> c >> d >> S + 1;
    if (c < d) {
        while (b < d) {
            if (S[b + 1] == '.') b += 1;
            else if (S[b + 2] == '.') b += 2;
            else fail();
        }
        while (a < c) {
            if (S[a + 1] == '.') a += 1;
            else if (S[a + 2] == '.') a += 2;
            else fail();
        }
    }
    else {
        while (b <= d) {
            if (S[b - 1] == '.' && S[b + 1] == '.') break;
            if (S[b + 1] == '.') b += 1;
            else if (S[b + 2] == '.') b += 2;
            else fail();
        }
        if (b > d) fail();
        while (a < c) {
            if (a + 1 != b && S[a + 1] == '.') a += 1;
            else if (a + 2 != b && S[a + 2] == '.') a += 2;
            else fail();
        }
        while (b < d) {
            if (S[b + 1] == '.') b += 1;
            else if (S[b + 2] == '.') b += 2;
            else fail();
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
using namespace std;
 long change(long long i,long long j) {

	        	long long k=0;
	        	k=j%i;
	        	if(k==0)
	        		return i;
	        	return change(k,i);}
	        	
int main(){
	long long a,b,c,d,result;
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	long long min = c*d/change(c,d);
	result =b-a+1-(b/c-(a-1)/c+b/d-(a-1)/d-b/min+(a-1)/min);
	printf("%lld",result);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 2e5 + 5 ; 
int n, m, a[N], Ans ; 
bool check( int x ) {
	int len = ( n - x ) / 2, fs = 0 ; 
	for( re int i = 1; i <= len; ++ i ) {
		if( a[x + i] + a[n - i + 1] < m ) return 0 ; 
		fs = max( fs, a[x + i] + a[n - i + 1] - m ) ;
	}
	for( re int i = 1; i <= x / 2; ++ i ) {
		fs = max( fs, ( a[i] + a[x - i + 1] ) % m ) ;
	}
	Ans = min( Ans, fs ) ; return 1 ; 
}
signed main()
{
	n = gi(), m = gi(), n = n * 2 ; Ans = m ; 
	rep( i, 1, n ) a[i] = gi() ; 
	sort( a + 1, a + n + 1 ) ; 
	int l = 0, r = n / 2 ; 
	while( l <= r ) {
		int mid = ( l + r ) >> 1 ; 
		if( check(mid * 2) ) r = mid - 1 ;
		else l = mid + 1 ; 
	}
	cout << Ans << endl ; 
	return 0 ;
}

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

typedef long long LL;
const int N=5005;
int pos[N],g[N],a[N];
LL f[N][N],ans;
int n,A,B;

void upmin(LL &x,const LL &y){if(y<x) x=y;}

int main()
{
	scanf("%d%d%d",&n,&A,&B);
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	for(int i=1;i<=n;i++)
	{
		pos[a[i]]=i;
		for(int j=i-1;j;j--)
			if(a[j]>a[i]) g[i]++;
	}
	memset(f,0x3f,sizeof(f));f[0][0]=0;
	for(int i=0,tmp;i<n;i++)
	{
		tmp=pos[i+1];
		for(int j=0;j<=n;j++)
			if(j>g[tmp]) upmin(f[i+1][j-1],f[i][j]+A);
			else upmin(f[i+1][j],f[i][j]+B),upmin(f[i+1][g[tmp]],f[i][j]);
	}
	ans=INT64_MAX;
	for(int i=0;i<=n;i++)
		upmin(ans,f[n][i]);
	printf("%lld\n",ans);
 	return 0;
}

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

int main(){
  double A,B,H,M;
  cin >> A >> B >> H >> M;
  double pi = 3.141592653589793;
  double hour_rad = (H*60+M)*pi/360.0;
  double min_rad = M*pi/30.0;
  
  double rad = abs(hour_rad - min_rad);
  if(rad > pi) rad = 2*pi - rad;
  
  double A_x = A*cos(rad);
  double A_y = A*sin(rad);
  
  double dis;
  dis = sqrt((A_x-B)*(A_x-B)+A_y*A_y);
  
  cout << fixed << setprecision(20) << dis << endl;
}

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

using namespace std;

int main() {
	long long L[1000];
	L[0] = 2;
	L[1] = 1;
	int n;
	cin >> n;
	for (int i = 2; i <= n; ++i)
		L[i] = L[i - 1] + L[i - 2];
	cout << L[n];
	return 0;
}

Measured memory_bytes: 256
n=int(input())
for i in range(1,10):
    if n%(10-i)==0:
        n/=(10-i)
        break
for j in range(1,10):
    if n%(10-j)==0:
        n/=(10-j)
        break
if n==1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
# coding: utf-8
import sys
import itertools


def sr(): return sys.stdin.readline().rstrip()


def ir(): return int(sr())


def lr(): return list(map(int, sr().split()))


N, M = lr()
d_list = []
for i in range(N):
    a, b = lr()
    d_list.append([a, b, i])

d_list = sorted(d_list, key=lambda x: x[0])

cnt = 0
ans = 0
for d in d_list:
    if (M - cnt) > d[1]:
        ans += d[1] * d[0]
        cnt += d[1]
    elif (M - cnt) > 0:
        ans += (M - cnt) * d[0]
        cnt += (M - cnt)
    else:
        break

print(ans)


Measured memory_bytes: 25636
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string S;
	cin >> S;
	cout << S[0] << S[1] << S[2] << endl;
}

Measured memory_bytes: 3564
//verma_ankit484

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
const int mod = (int) 1e9+7;

using namespace std;
//using namespace __gnu_pbds;

//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


int32_t main() {
  IOS
  #ifdef AV
  freopen("input.txt", "r", stdin);
  #endif
  string s;
  cin >> s;
  string ss = s;
  reverse(ss.begin(), ss.end());
  bool foo = true;
  if (ss != s) {
    foo = false;
  }
  int n = s.length();
  ss.clear();
  for (int i = 0; i < (n - 1) / 2; i++) {
    ss.pb(s[i]);
  }
  string s2 = ss;
  reverse(s2.begin(), s2.end());
  if (s2 != ss) {
    foo = false;
  }
  ss.clear();
  for (int i = ((n + 3) / 2) - 1; i < n; i++) {
    ss.pb(s[i]);
  }
  s2 = ss;
  reverse(s2.begin(), s2.end());
  if (s2 != ss) {
    foo = false;
  }
  if (foo) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

answer = 0
for i in range(a + 1):
    for j in range(b + 1):
        temp = x - 500 * i - 100 * j
        if 0 <= temp and temp <= 50 * c:
            answer += 1
print(answer)

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

dp = [10**8] * n

for i in range(n):
    if i == 0:
        dp[i] = 0
    elif i == 1:
        dp[i] = abs(li[i] - li[i-1])
    else:
        dp[i] = min(abs(li[i] - li[i-1]) + dp[i-1], abs(li[i] - li[i-2]) + dp[i-2])

print(dp[-1])


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long double lb;

const int INF=1<<27;
const int MOD=(int)1e9+7;

int cnt;

void read(int *n, int a[])
{
    cin >> *n;
    rep(i,*n) cin >> a[i];
    return;
}


void insertion_sort(int a[], int n, int g)
{
    for(int i = g; i < n; i++){
        int v = a[i];
        int j = i - g;
        while(j >= 0 && a[j] > v){
            a[j+g] = a[j];
            j = j - g;
            cnt++;
        }
        a[j+g] = v;
    }

    return;
}

void shell_sort(int a[], int n)
{
    cnt = 0;
    int m = 0;
    int g[100];
    int k = n;
    g[0] = n-1;
    for(m = 0; k > 0; k /= 2) m++;
    for(int i = 1; i < m; i++) g[i] = g[i-1]/2;
    cout << m << endl;
    rep(i,m) cout << g[i] << ' ';
    cout << endl;
    rep(i,m) insertion_sort(a, n, g[i]);
    return;
}

void print_array(int a[], int n)
{
    rep(i,n) cout << a[i] << endl;
}

int main(void)
{
    int n;
    int a[1000010];
    read(&n,a);
    shell_sort(a, n);
    cout << cnt << endl;
    print_array(a, n);
    return 0;
}

Measured memory_bytes: 6980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define d7 1000000007
#define fori(n) for( ll i=0 ; i<n; i++)


long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

int main(){

string s,t;
cin>>s>>t;
t=t+s;
cout<<t;

return 0;
}


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

using namespace std;

int main() {
    string S;
    cin >> S;
    bool ok = true;
    for (int i = 0; i < S.length(); i++) {
        if (i % 2 == 0 and S[i] == 'L') {
            ok = false;
            break;
        } else if (i % 2 == 1 and S[i] == 'R') {
            ok = false;
            break;
        }
    }
    string ans = ok ? "Yes" : "No";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n,*a=$<.map(&:to_i)
a.sort!
s = 0
res = -1
if n&1 == 1
  med = a[n/2]

  a = a[0,n/2].zip(a[n/2+1,n/2].reverse).flatten

  [a,a.rotate,a.rotate(-1)].each{|x|
    s = 0
    x.each_cons(2){|x,y|s += (x-y).abs}
    res = [res,(med-x[0]).abs+s,(x[-1]-med).abs+s].max
  }

else
  a = a[0,n/2].zip(a[n/2,n/2].reverse).flatten
  [a,a.rotate,a.rotate(-1)].each{|x|

    s = 0
    x.each_cons(2){|x,y|s += (x-y).abs}
    res = [res,s].max
  }
end
p res

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

int main(){
    string s;
    cin >> s;
    if(s == "MON"){
        cout << 6;
    }else if(s == "TUE"){
        cout << 5;
    }else if(s =="WED"){
        cout << 4;
    }else if(s =="THU"){
        cout << 3;
    }else if(s == "FRI"){
        cout << 2;
    }else if(s == "SAT"){
        cout << 1;
    }else if(s == "SUN"){
        cout << 7;
    }

    return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int a, b, c, d, p; cin >> a >> b >> c >> d >> p;
    int X = p*a;
    int Y;
    if(p <= c) Y = b;
    else Y = b + (p - c)*d;

    cout << min(X, Y) << '\n';
    return 0;
}


Measured memory_bytes: 3212
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    x1, y1, x2, y2 = nm()
    print(x2 + y1 - y2, y2 - x1 + x2, y1 - y2 + x1, y1 - x1 + x2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9200
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			long x = scanner.nextLong();
			long remander = x % 11L;
			System.out.println(x / 11L * 2L + ((remander == 0) ? 0 : (remander > 6) ? 2 : 1));
		}
	}
}


Measured memory_bytes: 21844
// /*
// power code taken from geeks for geeks
// */

#include <bits/stdc++.h>
#define MODD 1000000007LL
#define MAX_SIZE 100000000
#define MAX_N 200001
using namespace std;
typedef long long ll;
typedef long double ld;

ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
double max(double a,double b){return a>b?a:b;}
double min(double a,double b){return a<b?a:b;}

ll modd(ll a){if(a<0LL) return a*-1LL;return a;}
double modd(double a){if(a<0.0) return a*-1.0;return a;}

ll modulo(ll a){return a % MODD; }

ll power(ll k, ll p){
    if (p == 0)
        return 1LL;
 
    ll P = power(k, p/2LL);
    P = (P * P) % MODD;
 
    if (p % 2 == 1)
        P = (P * k) % MODD;
 
    return P;
}


struct p_str{
    ll a,b,c;
};


void swap(ll& s1, ll &s2){
    ll temp=s1;
    s1=s2;
    s2=temp;
}
ll gcd(ll a, ll b){
    if(b==0){
        return a;
    }
    return gcd(b, a%b);
}

void solve(){
    ll k;
    cin>>k;
    ll a, b;
    cin>>a>>b;
    ll i=a;
    while(i<=b){
        if(i%k==0){
            cout<<"OK"<<endl;
            return;
        }
        i++;
    }
    cout<<"NG"<<endl;
}


int main(){


    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll t=1;

    // cin>>t;
    
    while(t--){
        solve();
    }
    return 0;
}


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

int main(void) {
	string str;
	int len, pstt, pend;

	cin >> str;
	len = str.length();
	
	pstt = pend = -1;
	for (int i = 0; i < len - 2; ++i) {
		if (str[i] == str[i + 1]) {
			pstt = i + 1;
			pend = i + 2;
			break;
		}
		if (str[i] == str[i + 2]) {
			pstt = i + 1;
			pend = i + 3;
			break;
		}
	}
	if (str[len - 2] == str[len - 1]) {
		pstt = len - 1;
		pend = len;
	}

	cout << pstt << ' ' << pend << '\n';
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll a;
  cin >> a;

  ll ans = a + a * a + a * a * a;

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 3536
fn main() {
    let n: usize = read_line_as_value();
    let a_in: Vec<usize> = read_line_as_vector();
    let b_in: Vec<usize> = read_line_as_vector();
    let c_in: Vec<usize> = read_line_as_vector();

    let mut prev = 0;
    let mut ans = 0;
    for i in 0..n {
        if i == 0 {
            ans += b_in[a_in[i]-1];
        } else {
            ans += b_in[a_in[i]-1];
            if prev == a_in[i] - 1 {
                ans += c_in[prev-1];
            }
        }
        prev = a_in[i];
    }
    println!("{}", ans);
}

fn read_line_as_value<T: std::str::FromStr>() -> T {
    let mut input = String::new();
    let res = std::io::stdin().read_line(&mut input);
    if let Err(error) = res {
        panic!("io error at stdin.read_line: {}", error);
    };
    match input.trim().parse() {
        Ok(val) => val,
        _ => panic!("error while parsing input: {}", input)
    }
}

fn read_line_as_vector<T: std::str::FromStr>() -> Vec<T> {
    let mut input = String::new();
    let res = std::io::stdin().read_line(&mut input);
    if let Err(error) = res {
        panic!("io error at stdin.read_line: {}", error);
    };
    match input.trim().split_whitespace().map(|x| x.parse()).collect::<Result<Vec<T>, _>>() {
        Ok(vec) => vec,
        _ => panic!("error while parsing input: {}", input)
    }
}

Measured memory_bytes: 2116
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    s.pop_back();
    s.pop_back();
    while(1){
        if(s.substr(0, s.size()/2) == s.substr(s.size()/2, s.size()/2)){
            break;
        }
        s.pop_back();
        s.pop_back();
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 256
s=input()
a=s[0]
i=1
r=1
while(i<=len(s)-1):
  if s[i]!=a:
    r+=1
    a=s[i]
    i+=1
  else:
    if i<=len(s)-2:
      r+=1
      a="bb"
    i+=2
if len(s)==1:
   r=0
print(r)

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

int main()
{
	int n, k; 
	cin>> n ; 
	cin>> k ;
	vector<int> h(n);
	vector<int> dp(n, INT_MAX);
	dp[0]=0;
	for( int i=0 ;i<n ;i++ )
		cin>>h[i];

	for( int i=1 ; i<=n-1; i++ )
	{
		int idx = min(n-1, i+k);
		for( int j=i-1 ; j >= max(0, i-k) ; j-- )
		{
			dp[i] = min(dp[i], abs(h[i]-h[j]) + dp[j] );
		}
	}
	cout<<dp[n-1];
	return 0;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long
#define INF INT_MAX
#define mod 1000000007
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll pw(ll a, ll b) {
    if (b == 0) return 1;
    ll t = pw(a, b / 2);
    if (b % 2 == 0) return (t * t)%mod;
    else return ((t * t)%mod * a)%mod;
}
int main()
{
	int x;cin>>x;
	if(x>=30)cout<<"Yes";
	else cout<<"No";
}


Measured memory_bytes: 3592
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
	string line;
	vector<string> sd;
	cin>>line;
	for(int i=0;i<line.length();i++){
		if(line[i]=='0'){
			sd.push_back("0");
		}else if(line[i]=='1'){
			sd.push_back("1");
		}else if(line[i]=='B'){
			if(sd.size()!=0){
				sd.erase(sd.end(),sd.end()+1);
			}
		}
	}
	for(int i=0;i<sd.size();i++){
		cout<<sd[i];
	}
	cout<<endl;
    return 0;
}

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

#define pb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define vi vector
#define forn(i, l, r) for(int i = l; i <= r; i++)
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define f80 double
#define LOCAL 0
#define endl '\n'

typedef long long int ll;
#define int long long int

const int mod = 1e9 + 7;
const int N = 100005;
const int inf = 2e9;

signed main(){
    IO;
    if(LOCAL){
        freopen("inp.txt", "r", stdin);
    }
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(a, max(b, c)) - min(a, min(b, c));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
  
using namespace std;
  
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
  
typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
  
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
  
bool augment(const Graph& g, int u,
             vector<int>& matchTo, vector<bool>& visited) {
  if(u < 0) return true;
  FOR(e, g[u]) if(!visited[e->dst]) {
    visited[e->dst] = true;
    if(augment(g, matchTo[e->dst], matchTo, visited)) {
      matchTo[e->src] = e->dst;
      matchTo[e->dst] = e->src;
      return true;
    }
  }
  return false;
}
  
int bipartiteMatching(const Graph& g, int L) {
  const int n = g.size();
  vector<int> matchTo(n, -1);
  int match = 0;
  REP(u, L) {
    vector<bool> visited(n);
    if(augment(g, u, matchTo, visited)) ++ match;
  }
  
  return match;
}
  
int main() {
  int X, Y, E;
    
  cin >> X >> Y >> E;
  Graph g(X+Y);
 
  for(int i=0; i<E; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(Edge(x, X+y, 1));
    g[X+y].push_back(Edge(X+y, x, 1));
  }
   
  cout << bipartiteMatching(g, X) << endl;
   
  return 0;
}

Measured memory_bytes: 1508
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int n;
  cin >> n;

  vector<vector<int> > ans;
  queue<pair<vector<int>, int> > que;
  que.emplace(vector<int>(), 0);
  while (!que.empty()) {
    auto now = que.front();
    que.pop();
    if (now.first.size() == n) {
      ans.push_back(now.first);
      continue;
    }
    for (int i = 0; i < now.second; i++) {
      vector<int> next = now.first;
      next.push_back(i);
      que.emplace(next, now.second);
    }
    vector<int> next = now.first;
    next.push_back(now.second);
    que.emplace(next, now.second+1);
  }

  sort(ans.begin(), ans.end());

  for (auto &x: ans) {
    for (auto &y: x) {
      char next = 'a' + y;
      cout << next;
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 13552
#include <bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mr  make_pair
using namespace std;
int mod = 1e9+7;
int inf = 1e18;
const int N = 5e5+999;
int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
int n,d;

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
        int n,k;
        cin>>n>>k;
        vi arr(n);
        for(int&i:arr)
        cin>>i;
        vi dp(n+5,inf);
        dp[0] = 0;
        dp[1] = abs(arr[1]-arr[0]);
        for(int i=2;i<n;++i)
        {
            for(int j=0;j<k;++j)
            dp[i] = min(dp[max(i-j-1,0LL)]+abs(arr[i]-arr[max(i-j-1,0LL)]),dp[i]);
        }
        cout<<dp[n-1]<<el;

    }
   return 0;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] line = br.readLine().toCharArray();
		String str = "";
		for(char c : line){
			switch(c){
			case '0':
				str+="0";
				break;
			case '1':
				str+="1";
				break;
			case 'B':
				if(str.length()>0){
					str = str.substring(0, str.length()-1);
				}
				break;
			}
		}
		System.out.println(str);
	}
}


Measured memory_bytes: 8020
N,W = map(int,input().split())
items = [list(map(int,input().split())) for _ in range(N)]

dp = [[0]*(W+1010) for _ in range(N+1)]

for i in range(N):
    for j in range(1,W+1000):
        if j - items[i][1] >= 0:
            dp[i+1][j] = max(dp[i][j], dp[i][j-items[i][1]]+items[i][0])
        else:
            dp[i+1][j] = dp[i][j]

print(dp[N][W])



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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) { cin >> v[i]; }

  v[0]--;
  bool can = true;
  for (int i = 0; i < n - 1; i++) {
    if (v[i] < v[i + 1])
      v[i + 1]--;
    else if (v[i] > v[i + 1])
      can = false;
  }
  cout << ((can) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 768
//
//  main.cpp
//  ABC124
//
//  Created by hiroaki on 2019/05/07.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>


//pair sort firstに揃う

#define int long long
#define pb(n) push_back(n)
#define Rap(n,i) for(int (i)=0;(i)<(n);(i)++)
#define Pr(n) cout<<n<<endl;
#define PairV vector<pair<int , int> >
#define F first
#define S second
#define Vector1  vector<int>
#define vector2 vector<vector<int> >
#define index(v,x) find((v).begin(), (v).end(), (x))-(v).begin()
#define ctoi(c) (int)(c-'0')
#define incin(n) int (n); cin>>(n);
#define stcin(s) string (s); cin>>(s);
#define all(v) (v).begin() , (v).end()
#define PI 3.14
#define Rad2Deg  57.29578

using namespace std;
 
signed  main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b;
    cin>>n>>a>>b;
    int min = a*(n-1)+b,max=b*(n-1)+a;
    if(max-min+1<0){
        Pr(0);
    }else{
        Pr(max-min+1);
    }
    return 0;
}


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

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

int a, b;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> a >> b;
	cout << fixed << setprecision(10) << 1. * a / b;
	return 0;
}


Measured memory_bytes: 256
/*
{By GWj
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
const int MAXN=200000+20;
int fa[MAXN],is[MAXN],siz[MAXN];
int n;
mp cit[MAXN];
int root(int x){
	if(fa[x]==x) return x;
	return fa[x]=root(fa[x]);
}
void merge(int u,int v){
	if(root(u)==root(v)) return ;
	siz[root(v)]+=siz[root(u)];
	fa[root(u)]=root(v);
}
int main(){
	fastio;
	R(n);
	rb(i,1,n)
		fa[i]=i,siz[i]=1;
	rb(i,1,n){
		R2(cit[i].FIR,cit[i].SEC);
		is[i]=cit[i].FIR;
	}
	sort(cit+1,cit+1+n);
	int las=0,mi=INF;
	rb(i,1,n){
		check_min(mi,cit[i].SEC);
		if(mi==n-i+1){
			rb(j,las+1,i)
				if(j!=las+1)
					merge(j,j-1);
			las=i;
		}
	}
	rb(i,1,n)  cout<<siz[root(is[i])]<<endl;
	return 0;
}


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

typedef unsigned long long int ull;
typedef long double ldb;
typedef long long int ll;

#define for01(k,n)  for (ll i=k; i<n; i++)
#define for02(k,n)  for (ll j=k; j<n; j++)
#define for03(k,n)  for (ll k=k; k<n; k++)
#define for11(k,n)  for (ll i=k; i<=n; i++)
#define for12(k,n)  for (ll j=k; j<=n; j++)
#define for13(k,n)  for (ll k=k; k<=n; k++)

#define pb push_back
#define mp make_pair
#define pf push_front
#define popf pop_front
#define popb pop_back
#define vll vector<ll>
#define F first
#define S second
#define pp pair <ll, ll>
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define si size()
#define bk back()
#define deci(n)  fixed<<setprecision(n)
#define mll map<ll,ll>
#define mint map<int,int>
#define mll_it map<ll,ll>::iterator
#define mint_it map<int,int>::iterator

#define p0(a) cout << a << " "
#define p1(a) cout << a << "\n"

#define mem(a,n) memset(a, n, sizeof(a)); // n = 0 OR -1 only

#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define MOD 1000000007
#define MOD2 998244353


int main()
{
    //BOOST;
  string a,b;
  cin >> a >> b;
  
  if(a.length() > b.length())
    p1("GREATER");
  else if(a.length() < b.length())
    p1("LESS");
  else
  {
    char c1 = a[0];
    char c2 = b[0];
    //ll f = 0;
    ll i = 1;
    if(c1 > c2)
    {
      p1("GREATER");
      return 0;
    }
    else if(c1 < c2)
    {
      p1("LESS");
      return 0;
    }
    else
    {
    	while(c1 == c2 && i < a.length())
    	{
          c1 = a[i];
          c2 = b[i];
          i++;
          if(c1 > c2)
          {
            p1("GREATER");
            return 0;
          }
          else if(c1 < c2)
          {
            p1("LESS");
            return 0;
          }
        }
      	if(c1 > c2)
        {
            p1("GREATER");
            return 0;
        }
        else if(c1 < c2)
        {
            p1("LESS");
            return 0;
        }
      	else
        	p1("EQUAL");
    }
          
  }   
    
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int64_t n;
  cin >> n; 
  vector<int64_t> a(n);
  rep(i,n){
    cin >> a.at(i);
    if(a.at(i)==0){
      cout << 0;
      return 0;
    }
  }
  int64_t ans=1;
  bool is=true;
  rep(i,n){
    ans*=a.at(i);
    if(ans>1000000000000000000){
      is=false;
    }
  }
  int64_t t=ans;
  if(!is){
    cout << -1;
    return 0;
  }
  for(int i=1;i<n;i++){
    t/=a.at(i);
  }
   if(t!=a.at(0)){
     cout << -1;
     return 0;
   }
     
  cout << ans;
}

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

using namespace std;

int main(void) {
	int num, i = 0, p;
	long long ans = 0, a[5] = { 0 };
	cin >> num;
	string s, march = "MARCH";
	for (; i < num; i++) {
		cin >> s;
		p = march.find(s[0]);
		a[p]++;
	}
	ans += a[0] * a[1] * (a[2] + a[3] + a[4]);
	ans += a[2] * a[3] * (a[0] + a[1] + a[4]);
	ans += (a[0] + a[1]) * (a[2] + a[3]) * a[4];
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<bool> > name((h), vector<bool>(w));


#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl

signed main(){
  int N; cin >> N;
  vector<int> v(105);
  FOR1(x, 9) {
    FOR1(y, 9) {
      v.at(x * y) = true;
    }
  }
  cout << (v.at(N) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
f=lambda:map(int,input().split())
n,m=f(); a=list(f())
from fractions import *
l=1
for i in a:
  i//=2; l=l*i//gcd(l,i)
  if (l//i)%2<1 or l>m: print(0); exit()
print(m//l-m//(l*2))

Measured memory_bytes: 14244
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS


vector<int> a;
int f(int mi){
	int cost = 0;
	for(int i:a){
		cost += (i-mi)*(i-mi);
	}
	return cost;
}

void solve(){
	int n;
	cin>>n;
	int mi = INT_MAX;
	int mx = INT_MIN;
	a.resize(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		mi = min(mi,a[i]);
		mx = max(mx,a[i]);
	}
	if(mi == mx){
		cout<<0<<endl;
		return;
	}
	int lo = mi, hi = mx;
	while (hi - lo > 1){
	    int mid = (hi + lo)>>1;
	    if (f(mid) > f(mid + 1)) 
	         lo = mid; 
	    else 
	         hi = mid;
	}
	//lo + 1 is the answer
	cout<<f(lo+1)<<endl;
}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(),v end()
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1000000010;
const ll LINF = 4000000000000000000LL;
typedef pair<int, int> P;

signed main(){
  int a, b, c;
  cin >> a >> b >> c;
  cout << max({a * 10 + b + c, a + b * 10 + c,a + b + c * 10}) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int dp[51][51];
char str[50][51];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%s",str[i]);
	}
	for(int i=0;i<=a;i++)
		for(int j=0;j<=b;j++)
			dp[i][j]=99999999;
	dp[0][0]=0;
	dp[0][1]=0;
	dp[1][0]=0;
	for(int i=1;i<=a;i++)
		for(int j=1;j<=b;j++)
			dp[i][j]=min(dp[i-1][j],dp[i][j-1])+str[i-1][j-1]-'0';
	printf("%d\n",dp[a][b]);
}

Measured memory_bytes: 0
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define INF (1LL<<59)
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
    if(y==0)
        return x;
    else
        return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
        if(m%2)
            r=(r*n)%p;
        n=(n*n)%p;
        m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
 
    // This is checked so that we can skip 
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
 
    return true;
}
int32_t main()
{
   IOS;
   /*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin); 
   freopen("output.txt","w",stdout);
   #endif 
   /********************* Code starts here ***********************/   
   int n,k;
   cin>>n>>k;
   vector<int>a(n);
   for(int i=0;i<n;i++)
   {
   	cin>>a[i];
   }
   int ans=0;
   for(int i=0;i<n;i++)
   {
   	int c1=0,c2=0;
   	for(int j=i+1;j<n;j++)
   	{
   		if(a[i]>a[j])
   		{
   			c1++;
   		}
   	}
   	for(int j=0;j<n;j++)
   	{
   		if(a[i]>a[j])
   			c2++;
   	}
   	//(c1)+(c1+c2)+(c1+c2+c2)
   	//k*c1+((k-1)*k*c2)/2;
   	ans=(ans+k*c1)%mod;
   	int s=(k*(k-1))%mod;
   	s=(s*c2)%mod;
   	s=(s*expo(2,mod-2,mod))%mod;
   	ans=(ans+s)%mod;
   }
   cout<<ans<<endl;
}        

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

int main(){
    int n;
    while( cin >> n ){
        map<ll, bool>mp;
        bool flag = true;
        for( int i = 0; i < n; i++ ){
            ll a; cin >> a;
            if( mp[a] == true ){
                flag = false;
            }
            mp[a] = true;
        }
        if( flag ){
            cout << "YES";
        }else{
            cout << "NO";
        }
    }
}
/*
7 2
0 1 0 0 0 1 0
*/


Measured memory_bytes: 12800
n, l = map(int, input().split())

apple = []
for i in range(n):
    apple.append(l + i)

if apple[0] < 0:
    if apple[-1] > 0:
        taste = sum(apple)
    else:
        taste = sum(apple[:n-1])
else:
    taste = sum(apple[1:])

print(taste)


Measured memory_bytes: 3060
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll ,string> Tlls;
#define PI 3.141592

int main()
{

  long double R;
  cin >> R;
  double a = PI;
  //小数点以下を指定したい場合　https://marycore.jp/prog/cpp/stream-format-float/
  cout << fixed;
  cout << setprecision(20) << 2 * R * a << endl;

  return 0;
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
long long MOD = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    template<class T> inline bool chmin(T& a, T b) {
        if (a > b) {
            a = b;
            return true;
        }
        return false;
    }
    template<class T> inline bool chmax(T& a, T b) {
        if (a < b) {
            a = b;
            return true;
        }
        return false;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint
    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll H,W;
        cin>>H>>W;
        vvc G(W,vc(H));
        rep(i,H){
            rep(j,W)cin>>G[j][i];
        }
        ll count=0;
        queue<pll> q;
        rep(i,H){
            rep(j,W){
                if(G[j][i]=='#'){
                pll a=mp(j,i);
                q.push(a);
                }
            }
        }
        if(q.size()==H*W){
            cout<<0<<endl;
            return 0;
        }
        queue<pll> emp;
        while (!q.empty())
        {
            count++;
            while (!q.empty())
            {
                ll x=q.front().first;
                ll y=q.front().second;
                q.pop();
                rep(i,4){
                    ll nx=x+dx[i];
                    ll ny=y+dy[i];
                    if(ny<0||nx<0||ny>H-1||nx>W-1)continue;
                    if(G[nx][ny]=='#')continue;
                    pll b=mp(nx,ny);
                    emp.push(b);
                    G[nx][ny]='#';
                }
            }
            swap(q,emp);
        }
        cout<<count-1<<endl;
    }

Measured memory_bytes: 17588
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N)cin >> A[i];
    vector<int> B(3, 0);
    REP(i, N){
        int c = 0;
        while(A[i]%2==0){
            c++;
            A[i] /= 2;
        }
        c = min(2, c);
        B[c]++;
    }
    vector<int> C(N, -1);
    REP(i, B[0]){
        if(2*i>=N)continue;
        C[2*i] = 0;
    }
    REP(i, N){
        if(C[i]!=-1)continue;
        if(B[2]){
            C[i] = 2;
            B[2]--;
        }else if(B[1]){
            C[i] = 1;
            B[1]--;
        }
    }
    bool ok = true;
    REP(i, N-1){
        if(C[i]==-1 || C[i+1]==-1)ok = false;
        if(C[i]+C[i+1]<2)ok = false;
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
char C(int i){
	if(i % 4 == 0) return 'R'; 
	if(i % 4 == 1) return 'Y'; 
	if(i % 4 == 2) return 'G'; 
	if(i % 4 == 3) return 'B'; 
}
int main(){
	int H, W, D; cin >> H >> W >> D; 
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			int a = (i + j) % (2 * D); 
			int b = (i - j + W) % (2 * D); 
			int c = (a >= D ? 1 : 0) + (b >= D ? 2 : 0); 
			cout << C(c); 
		}
		cout << endl; 
	}	
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;  // or pb_ds;

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#ifndef DEBUG
#define endl "\n"
#endif
#define fff ff
#define sss ss.ff
#define ttt ss.ss
#define INF (1 << 30)
#define LLF (1ll << 60)
#define PRIME (1000000007)
#define FASTIO std::ios::sync_with_stdio(false)
#ifdef DEBUG
#define debug(x) cerr << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define rep(i, begin, end)                            \
  for (__typeof(end) i = (begin) - ((begin) > (end)); \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define FILE_INPUT                  \
  freopen("input.txt", "r", stdin); \
  freopen("output.txt", "w", stdout)

#define all(x) x.begin(), x.end()

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<string> vs;

template <typename T, typename B = null_type>
using oset =
    tree<T, B, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order / order_of_key

const ld eps = 1e-12;

ll fexp(ll b, ll e, ll p = PRIME) {
  ll res = 1;
  while (e) {
    if (e & 1) res = (res * b) % p;
    b = (b * b) % p;
    e >>= 1;
  }
  return res;
}

const int RANDOM =
    chrono::high_resolution_clock::now().time_since_epoch().count();

struct no_hack_hash {
  int operator()(int x) const { return x ^ RANDOM; }
};

struct iihash {
  int operator()(ii x) const { return x.first * 31 + x.second; }
};

// To use most bits rather than just the lowest ones:
struct ghash {  // large odd number for C
  const uint64_t C = ll(4e18 * acos(0)) | 71;
  ll operator()(ll x) const { return __builtin_bswap64(x * C); }
};

/*-----------------END TEMPLATE-----------------*/

int(((((((((((((((main)))))))))))))))() {
  FASTIO;
  ll a, b;
  cin >> a >> b;

  if (a <= 5) cout << "0" << endl;
  else if (a <= 12) cout << b/2 << endl;
  else cout << b << endl;
}


Measured memory_bytes: 256
import java.util.*;
 public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);

      int N = sc.nextInt();
      int[] A = new int[N];

      for(int i = 0;i < N;i++){
        A[i] = sc.nextInt();
      }

      int count1 = 0;
      int count2 = 0;
      
      for(int i = 0;i < N;i++){
         if(A[i] % 2 == 0){
               count1++;
            if(A[i] % 3 == 0 ||  A[i] % 5 == 0){
               count2++;
            }
         }
      }

      if(count1 == count2){
         System.out.println("APPROVED");
      }else{
         System.out.println("DENIED");
      }
      
   }
 }


Measured memory_bytes: 35900
/*
	?§£????????????:Connected Components - Bridges
	(http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_B&lang=jp)

	Status:Runtime Error(?????????????????????????????????)

	??????:
		????????????????????§????????°????????§???????????????????????¨???????????¨????°???\????????????????????????????????£?????????????????????????£????????????????????????????????????¢????????¨?????????
		http://www.npca.jp/works/magazine/2014_1/?????????????????????????????????pdf??????????????????
		??????????????????????£????????????????????????????????????§????????¨????????????????????????????????????????????£???????????????
		?????°???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????¨????±????????????????????????¨???????????§???????????¨???????????????

*/
var log = console.log;
if (typeof process != "undefined") {
    var input = "";
    process.stdin.resume();
    process.stdin.setEncoding('utf8');
    process.stdin.on('data', function(chunk) {
        input += chunk;
    });
    process.stdin.on('end', function() {
        var lines = input.split("\n");
        main(lines);
    });
}


function main(lines) {
    lines = lines.map(function(line) {
        return line.split(" ").map(function(e) {
            return Number(e);
        });
    });
    var V = lines[0][0];
    lines.shift();
    lines = lines.map(function(line) {
        return line.slice(2).map(function(e) {
            return e - 1;
        });
    })
    var visited = [0];
    var stack = [
        [0, 0]
    ];
    var list = [0];

    for (var k = 0; k < V; k++) {
        var now = stack.shift();
        if (!now) continue;
        lines[now[0]].forEach(function(e) {
            if (visited.indexOf(e) == -1) {
                //?¨??????????????????????
                stack.push([e, now[1] + 1]);
                list[e] = now[1] + 1;
                visited.push(e);
            }
        });
    }
    for (var i = 0; i < V; i++) {
        if (!list[i] && i != 0) list[i] = -1;
        log((i + 1) + " " + list[i]);
    }
}

Measured memory_bytes: 16908
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,k;cin>>n>>k;
    ll res=(n+k-3)/(k-1);
    cout<<res<<endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let a1: usize = read();
    let a2: usize = read();
    let a3: usize = read();
    println!("{}",
        if a1 + a2 + a3 >= 22 { "bust" } else { "win" });
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

int main(){
    int a[5], ans;
    for (int i = 0; i < 5; ++i){
        cin >> a[i];
        if (a[i] == 0) ans = i + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572