akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<string>
#include<deque>
using namespace std;

struct Command {
    string command;
    int x;
};

int main(){

    int n;
    cin >> n;

    deque<int> deq;
    deque<int>::iterator p;
    Command A;
    int count=0;

    for(int i=0; i<n; i++){
        cin >> A.command;
        if(A.command=="insert"){
            cin >> A.x;
            deq.push_front(A.x);
        }else if(A.command=="delete"){
            cin >> A.x;
            p = deq.begin();
            for(p; p!=deq.end(); p++){
                if(*p==A.x) {
                p = deq.erase(p);
                break;
                }
            }
        }else if(A.command=="deleteFirst"){
            deq.pop_front();
        }else if(A.command=="deleteLast"){
            deq.pop_back();
        }
        count++;
    }

    for(int i=0; i<deq.size(); i++){
        if(i==deq.size()-1) printf("%d\n", deq[i]);
        else printf("%d ", deq[i]);
    }

    return 0;
}


Measured memory_bytes: 7040
n = int(input())
spade = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
hart = set(spade)
club = set(spade)
diamond = set(spade)
trump = [spade, hart, club, diamond]
suit_def = ['S', 'H', 'C', 'D']

for i in range(n):
    card = list(input().split())
    suit = card[0]
    number = int(card[1])
    if suit == 'S':
        spade.remove(number)
    elif suit == 'H':
        hart.remove(number)
    elif suit == 'C':
        club.remove(number)
    else:
        diamond.remove(number)

for i, j in zip(trump, suit_def):
    for k in i:
        print(j, k)

Measured memory_bytes: 7692
#include<stdio.h>
#include<string.h>
int main()
{
    char s[6];
    gets(s);
    if(s[2]==s[3] && s[4]==s[5])
    {
        printf("Yes\n");
    }
    else
        {
            printf("No\n");
        }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
///////////////////////////////////////////////

ll dp[10010];

int main() {
    int h, n; cin >> h >> n;
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i] >> b[i];

    ll inf = 1e8+10;
    rep(i,h+1) dp[i] = inf;
    dp[0] = 0;

    rep(i,n) rep(j,h) {
        int nj = min(j+a[i], h);
        chmin(dp[nj], dp[j]+b[i]);
    }

    cout << dp[h] << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef set<ii> sii;
typedef set<int> si;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;

const int INF = 1000000010;
const ll MOD = 1000000007;

vvi gf;

int dfs(vi &vis, int n) {
	vis[n] = 1;
	int s = 0;
	for (int i = 0; i < (int)gf[n].size(); i++) {
		if (vis[gf[n][i]] == 0)
			s += dfs(vis, gf[n][i]);
	}
	return 1 + s;
}

int main() {FIN
	
	int n, m, i, a, b, g = 0;
	cin >> n >> m;
	gf = vvi(n+1);
	for (i = 0; i < m; i++) {
		cin >> a >> b;
		gf[a].push_back(b);
		gf[b].push_back(a);
	}
	vi vis(n+1);
	for (i = 1; i <= n; i++) {
		if (vis[i] == 0)
			g = max(g, dfs(vis, i));
	}
	
	cout << g << "\n";
	
	return 0;
}


Measured memory_bytes: 24312
n=int(input())
inf=[10**10]
a=sorted([int(j) for j in input().split()+inf])
b=sorted([int(j) for j in input().split()])
c=sorted([int(j) for j in input().split()+inf])
ans,pa,pc=0,0,0
for j in range(n):
    while a[pa]<b[j]:
        pa+=1
    while c[pc]<=b[j]:
        pc+=1
    ans+=pa*(n-pc)
print(ans)

Measured memory_bytes: 113124
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
const int MAXN = (int) 2e5 + 10;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;

int n;
int a[MAXN];

void work(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    int cnt=0;
    for(int i=1;i<n;i++){
        for(int j=n;j>i;j--){
            if(a[j]<a[j-1]){
                swap(a[j],a[j-1]);
                cnt++;
            }
        }
    }
    for(int i=1;i<n;i++) printf("%d ",a[i]);
    printf("%d\n%d\n",a[n],cnt);
}

int main(){
    work();
    return 0;
}







Measured memory_bytes: 2772
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>

using namespace std;


/*--- Macro ---*/
#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 mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;


// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// -------------------------------------------------------------------------------------

int main() {
  int n, m;
  vector< pair<int, int> > p;
  vector< pair<int, int> > c;
  cin >> n >> m;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    p.pb(mp(a, b));
  }
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    c.pb(mp(a, b));
  }

  for(auto pi : p) {
    int min_check = 0, min_d = INF<int>;
    rep(i, m) {
      int d = abs(pi.first - c[i].first) + abs(pi.second - c[i].second);
      if(min_d > d) {
        min_check = i;
        min_d = d;
      }
    }
    cout << min_check + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int64_t N;
    cin >> N;
    
    for (int64_t i = 1; i < 3501; i++) {
        for (int64_t j = 1; j < 3501; j++) {
            if (4 * i * j - i * N - j * N == 0) {
                continue;
            }
            int64_t c = (N * i * j) / (4 * i * j - i * N - j * N);
            if (c * (4 * i * j - i * N - j * N) == (N * i * j) && c > 0){
                cout << i << " " << j << " " << c << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
struct ans
{
    int prob;
    string s;
};
int main(void)
{
    int N, M;
    cin >> N >> M;
    ans *x;
    x = new ans[M];
    int tmp;
    for (int i = 0; i < M; i++)
    {
        cin >> x[i].prob >> x[i].s;
    }
    int *count;
    count = new int[N + 1];
    //int *fin;
    //fin = new int[N + 1];
    int psum = 0;
    int acsum = 0;
    int j = 0;
    bool *acf;
    acf = new bool[N + 1];
    for (int i = 1; i <= N; i++)
    {
        acf[i] = false;
    }
    for (int i = 0; i < M; i++)
    {
        j = x[i].prob;
        if (x[i].s == "WA")
        {
            count[j]++;
        }
        else
        {
            if (acf[j] == false)
            {
                psum += count[j];

                acf[j] = true;
                acsum += 1;
            }
        }
    }
    cout << acsum << " " << psum << endl;
    return 0;
}

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

using namespace std;

typedef long long int ll;

const int N = (int) 4e2 + 10;
const ll oo = (ll) 1e18;

int n;
int a[N];
ll prefix[N];
ll memo[N][N];

ll sum(int l, int r) {
    ll ans = prefix[r];
    if(l > 0) ans -= prefix[l - 1];
    return ans;
}

ll dp(int l, int r) {
    if(l == r) return 0;
    ll &ans = memo[l][r];
    if(ans != -1) return ans;
    ans = oo;
    for(int i = l; i < r; ++i) {
        ll left = sum(l, i);
        ll right = sum(i + 1, r);
        ll cur = left + right + dp(l, i) + dp(i + 1, r);
        ans = min(ans, cur);
    }
    return ans;
}

void solve() {
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    memset(memo, -1, sizeof(memo));
    for(int i = 0; i < n; ++i) {
        prefix[i] = a[i];
        if(i > 0) prefix[i] += prefix[i - 1];
    }
    cout << dp(0, n - 1) << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    solve();
    return 0;
}

Measured memory_bytes: 1664
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
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; }
const ll INF=1e18;
const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll n;
ll dp[3010][3010];
ll a[3010];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  cin >> n;
  rep(i,n)cin >> a[i];
  rep(i,n)dp[i][i]=0;
  
  for(int width=1;width<=n;width++){
    for(int l=0;l+width<=n;l++){
      int r=l+width;
      if(width%2==n%2){
        dp[l][r]=max(dp[l+1][r]+a[l],dp[l][r-1]+a[r-1]);
      }
      else{
        dp[l][r]=min(dp[l+1][r]-a[l],dp[l][r-1]-a[r-1]);
      }
    }
  }
  cout << dp[0][n] << endl;
      
  return 0;
}

Measured memory_bytes: 70016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

vector<int> g[200005];
int d[200005];

void dfs(int x, int p) {
    d[x] = d[p] + 1;
    for (int i : g[x]) if (i != p) dfs(i, x);
}

int main() {
    ios::sync_with_stdio(false);
    int n, u, v, a = 0, b = 0;
    cin >> n;
    for (int i = 1; i < n; i++) cin >> u >> v, g[u].push_back(v), g[v].push_back(u);
    dfs(1, 1);
    for (int i = 1; i <= n; i++) if (d[i] > a) a = d[i], b = i;
    for (int i = 1; i <= n; i++) d[i] = 0;
    dfs(b, b);
    for (int i = 1; i <= n; i++) a = max(a, d[i]);
    if (a % 3 == 2) cout << "Second";
    else cout << "First";
}


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

int main(){
    int t,num;
    while(cin>>t>>num,t|num){
        int len=0,n=num;
        while(n) len++,n/=10;
        vector<int> N;
        n=num;
        while(n) N.push_back(n%10),n/=10;
        reverse(N.begin(), N.end());
        // for(auto a:N)cout<<a<<' ';
        // cout<<endl;
        int ans = -1;
        vector<int> A;
        for(int b=0;b<(1<<(len-1));b++){
            int sum=0,cur=N.front();
            vector<int> V;
            for(int i=1;i<len;i++){
                if(b&(1<<(i-1))){
                    cur*=10;
                    cur+=N[i];
                }else{
                    sum+=cur;
                    V.push_back(cur);
                    cur=N[i];
                }
            }
            sum+=cur;
            V.push_back(cur);
            if(sum<=t&&ans<=sum){
                if(ans==sum) A.clear();
                else ans=sum,A=V;
            }
        }
        if(ans==-1){
            cout<<"error"<<endl;
        }else if(!A.size()){
            cout<<"rejected"<<endl;
        }else{
            cout<<ans;
            for(auto a:A) cout<<' '<<a;
            cout<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3148
n, k = map(int, input().split())
r, s, p = map(int, input().split())
hand = list(input())

ans = []
def get_ans(h):
    if h == 'r':
        return('p')
    elif h == 's':
        return('r')
    elif h == 'p':
        return('s')

for i in range(k):
    ans.append(get_ans(hand[i]))
for i in range(k,n):
    if (hand[i] =='r' and ans[i-k] != 'p') or (hand[i] =='p' and ans[i-k] != 's') or (hand[i] =='s' and ans[i-k] != 'r'):
        # 勝てる
        ans.append(get_ans(hand[i]))
    else:
        # 勝てない
        try:
            h = ['r', 's', 'p']
            h.remove(get_ans(hand[i-k]))
            h.remove(get_ans(hand[i+k]))
            ans.append(h[0])
        except:
            ans.append(h[0])
score = 0
for i in range(n):
    if ans[i] == 'r' and hand[i] == 's':
        score += r
    if ans[i] == 'p' and hand[i] == 'r':
        score += p
    if ans[i] == 's' and hand[i] == 'p':
        score += s
print(score)


Measured memory_bytes: 4792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;


int main() {

	Int N, M;
	cin >> N >> M;

	vector<Int> dp(N + 3, 0);
	vector<Int> stair(N+3,0);
	vector<Int> a(M, 0);
	dp[0] = 1;

	for (Int i = 0; i < M; i++)cin >> a[i];

	for (Int i = 0; i < M; i++)stair[a[i]]++;

	for (Int i = 0; i < N; i++) {
		if (stair[i + 1] == 0) {
			dp[i + 1] += dp[i];
			dp[i + 1] %= 1000000007;
		}
		if (stair[i + 2] == 0) {
			dp[i + 2] += dp[i];
			dp[i + 2] %= 1000000007;
		}
	}

	cout << dp[N] << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()
int main(){
  int h,w,k;cin>>h>>w>>k;
  vector<vector<int>> c(h,vector<int>(w));
  int i,j,l,n,p;
  rep(i,h)rep(j,w){
    char ch;cin>>ch;
    c[i][j]=(ch-'0');
  }
  int ans=0;
  rep(i,h)rep(j,w){
    bool update=true;
    vector<vector<int>> m(h,vector<int>(w));
    m=c;
    m[i][j]=0;
    int score=0;
    int timev=1;
    while(update) {
      update=false;
      rep(n,w){
        int to=h-1;
        for(l=h-1;l>=0;l--){
          if(m[l][n]!=0){
            swap(m[to][n],m[l][n]);
            to--;
          }
        }
      }
      int get=0;
      rep(l,h){
        int from=0;
        int now=m[l][n];
        rep(n,w){
          if(now!=m[l][n]){
            int dis=(n-1)-from+1;
            if(dis>=k){
              for(p=from;p<n;p++) {
                get+=m[l][p];
                m[l][p]=0;
              }
            }
            from=n;
            now=m[l][n];
          }
        }
        int dis=(w-1)-from+1;
        if(dis>=k){
          for(p=from;p<n;p++){
            get+=m[l][p];
            m[l][p]=0;
          }
        }
      }
      if(get>0)update=true;
      else break;
      score+=timev*get;
      timev*=2;
    }
    ans=max(ans,score);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define maxl (ll)1e5 + 10ll

char s[maxl],t[maxl];
int main(){
    ll n,m;
    scanf("%lld%lld",&n,&m);
    scanf("%s%s",s,t);
    ll g = __gcd(n,m);
    ll n1 = n/g;
    ll m1 = m/g;
    bool ans = true;
    for(ll i=0ll;i<g;i++)
        if(s[i*n1]!=t[i*m1])
            ans=false;
    if(ans)
        printf("%lld\n",n*m/g);
    else
        puts("-1");


}



Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i, a, b) for(int i = (a);i < (b);++i)
#define FORR(i, b, a) for (int i = (b) - 1;i >= 0;--i)
#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = (n) - 1;i >= 0;--i)
#define ITER(itr, v) for(auto itr = v.begin();itr != v.end();++itr)
#define SORT(v) sort(v.begin(), v.end())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

ll c[10][10];



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

	int N;
	cin >> N;
	FOR(i, 1, N + 1) {
		int j = i;
		int tail = j % 10;
		int top;
		while (j) {
			top = j % 10;
			j /= 10;
		}
		c[top][tail] += 1;
	}
	ll res = 0;
	FOR(i, 1, 10)FOR(j, 1, 10) res += c[i][j] * c[j][i];
	cout << res << endl;

	return 0;
}

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

int hantei(int x){
	if(x%10==(x/10)%10 && x%10==x/100)
      return x;
  	
  return 0;
}

int main() {

  int a,b,c,d,sum;
  string s,t;
  cin>>a;
  
  sum=0;
  for(int i=a;i<=999;i++){
  	if(i%111==0){
    	b=i;
      break;
    }
  }
  
  cout<<b<<endl;
  return 0;
}


Measured memory_bytes: 256
X,N = list(map(int, input().split()))
p = list(map(int,input().split())) #list(map(int, input().split()))
for i in range(N + 1):
  a = X + i
  b = X - i
  if p.count(b) == 0:
    print(b)
    exit(0)
  elif p.count(a) == 0:
    print(a)
    exit(0)



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


signed main() {
  string S, T;
  cin >> S >> T;
  
  if( S.size() < T.size() ){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  
  vector<string> bubun;
  for( int i = 0; i < (int)S.size() - (int)T.size() + 1; i++ ){
    bubun.push_back( S.substr(i, (int)T.size()) );
  }
  
  bool ari = false;
  for( int i = bubun.size()-1; i >= 0; i-- ){
    bool fg = true;
    for( int j = 0; j < T.size(); j++ ){
      if( bubun.at(i).at(j) != T.at(j) && bubun.at(i).at(j) != '?' ) fg = false;
    }
    if( fg ){
      ari = true;
      for( int j = 0; j < T.size(); j++ ){
        S.at(i+j) = T.at(j);
      }
      break;
    }
  }
  
  if( ari == false ){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
    
  
  for( int i = 0; i < S.size(); i++ ){
    if( S.at(i) == '?' ) S.at(i) = 'a';
  }
  cout << S << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>

int main()
{
	int lengthes[10];
	char tmp;
	while (std::cin >> lengthes[0] >> tmp >> lengthes[1] >> tmp >> lengthes[2] >> tmp >> lengthes[3] >> tmp >> lengthes[4] >> tmp >> lengthes[5] >> tmp >> lengthes[6] >> tmp >> lengthes[7] >> tmp >> lengthes[8] >> tmp >> lengthes[9] >> tmp )
	{
		int v1, v2;
		std::cin >> v1 >> tmp >> v2;

		int sum = std::accumulate(&lengthes[0], &lengthes[10], 0);

		double sec = (double)(sum) / (v1 + v2);
		double dist = v1 * sec;

		int all = 0;
		int index = 1;
		for (auto length : lengthes)
		{
			all += length;
			if (dist <= all)
			{
				std::cout << index << std::endl;
				break;
			}
			index++;
		}
	}

	return 0;
}

Measured memory_bytes: 3048
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun main(args: Array<String>) {
    val (n, k) = readLongList()
    val res = if (n < k) {
        n.coerceAtMost(k - n)
    } else {
        val a = n % k
        a.coerceAtMost(k - a)
    }
    println(res)
}


Measured memory_bytes: 37872
#include<stdio.h>
#include<math.h>
int main()
{
    int i,n,x[1001],y=0;
    double a=0,alpha,m;

    for(i=0;; i++)
    {
    scanf("%d",&n);
        if(n!=0)
        {
            a=0;y=0;
            for(i=0; i<n; i++)
            {
                scanf("%d",&x[i]);
                y=y+x[i];
            }
            m=(double)y/n;
    //printf("%.8lf\n",m);
    for(i=0;i<n;i++)
        a=a+((x[i]-m)*(x[i]-m));
    alpha=sqrt(a/n);
    printf("%.8lf\n",alpha);
    continue;
        }
        else if(n==0)
            break;
    }
    return 0;

}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=210;
int n,g[N][N];
char s[N];
int main() {
	scanf("%d",&n);
	rep(i,0,n) rep(j,0,n) g[i][j]=(i==j)?0:(1<<29);
	rep(i,0,n) {
		scanf("%s",s);
		rep(j,0,n) if (s[j]=='1') g[i][j]=g[j][i]=1;
	}
	rep(k,0,n) rep(i,0,n) rep(j,0,n) g[i][j]=min(g[i][k]+g[k][j],g[i][j]);
	rep(k,0,n) rep(i,0,n) rep(j,0,n)
		if ((g[i][j]+g[i][k]+g[j][k])%2!=0) {
			puts("-1");
			return 0;
		}
	int md=0;
	rep(d1,0,n) rep(d2,d1+1,n) md=max(md,g[d1][d2]);
	printf("%d\n",md+1);
}


Measured memory_bytes: 384
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var L = cin.ReadInt;
            var R = cin.ReadInt;
            if(R - L + 1 >= 2019)
            {
                WriteLine(0);
                return;
            }
            var ans = 2018;
            for(int i = L; i < R; i++)
            {
                for(int j = L + 1; j <= R; j++)
                {
                    var im = i;
                    var jm = j;
                    if(L >= 2019)
                    {
                        im %= 2019;
                        jm %= 2019;
                    }
                    if((im * jm) % 2019 < ans)
                    {
                        ans = (im * jm) % 2019;
                    }
                    if(ans == 0)
                    {
                        WriteLine(0);
                        return;
                    }

                }
            }
            WriteLine(ans);

        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
bool prime(long long x)
{
	long long i;
	if(x<2)
	{
		return false;
	}
	for(i=2;i*i<=x;i++)
	{
		if(x%i==0)
		{
			return false;
		}
	}
	return true;
}
int main(){
	long long a,b,v,dv,i,ans=1;
	cin>>a>>b;
	v=__gcd(a,b);
	dv=v;
	if(v==1)
	{
		cout<<1<<endl;
		return 0;
	}
	if(prime(v))
	{
		cout<<2<<endl;
		return 0;
	}
	for(i=2;i*i<=dv;i++)
	{
		if(v%i==0)
		{
			ans++;
		}
		else
		{
			continue;
		}
		while(v%i==0)
		{
			v/=i;
		}
		if(prime(v))
		{
			ans++;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    ll k;
    cin >> k;
    rep(i, s.size())
    {
        if (s[i] == '1' && i == (k - 1))
        {
            cout << 1 << endl;
            return 0;
        }
        else if (s[i] != '1')
        {
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3600
def dfs(depth, array, sums, b):
    if depth == 3:
        sumb=0 
        for i in b:
            sumb+=i

        a=[int((sums[0]-sumb)/3), int((sums[1]-sumb)/3), int((sums[2]-sumb)/3)]
        for i in range(3):
            for j in range(3):
                if a[i]+b[j] != array[i][j]:
                    return False
        return True
    else:
        for i in range(101):
            b[depth]=i
            if dfs(depth+1, array, sums, b):
                return True
        return False

array=[]
b=[0 for i in range(3)]
sums=[0 for i in range(3)]
for i in range(3):
    array.append([int(i) for i in input().split()])

for i in range(3):
    sums[i]+=array[i][0]+array[i][1]+array[i][2]

if(dfs(0, array, sums, b)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long

using namespace std;
const int MaxN = 100005;

ll a[MaxN];
ll dp[MaxN];

int min(int x, int y){
	return x<y?x:y;
}

int main(){
	int n, ans, i;
	scanf("%d", &n);
	for(i = 1; i <= n; i++)  scanf("%d", &a[i]);
	dp[0] = 0;
	dp[1] = 0;
	dp[2] = abs(a[2]-a[1]);
	for(i = 3; i <= n; i++)  dp[i] =  min( (dp[i-1] + abs(a[i] - a[i-1])), ( dp[i-2] + abs(a[i-2] - a[i])) );
	ans = dp[n];
	printf("%d\n", ans);
	return 0;
 } 

Measured memory_bytes: 1792
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

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

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

ll modInverse(ll n, ll p)
{
    return binpowmod(n, p-2, p);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll m,n,i,f=0,j,ans=0;
    string s,t,s1;
    cin >> s >> t ;
    n=s.length();
    rep(i,n)
    {
        if(s[i]==t[i]) continue ;
        else
        {
            cout << "No" ;
            return 0 ;
        }
    }
    cout << "Yes" ;
    
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
        #define ll long long
        #define rep(i,a,b) for(i=a;i<b;i++)
        #define pb push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define vi vector < int >
        #define vii vector < long long int >
        #define CLR(a) memset((a),0,sizeof(a))
        #define mp make_pair
        #define hell 1000000007
        using namespace std;


        void solve()
        {
            ll i,j=0,r=200,p,q,k=0,ans=0,d,y=0,h,flag=0,n,m=0,a=hell,b=hell,id,c,h1,h2,a1,b1;
            cin>>n>>d;
            d*=2; d++;
            cout<<(n/(d)+ bool(n%d));



        }


        signed main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
            solve();
        }

           /*

      void bfs( int i , int j)
           {
               vis[i][j]= true;
             queue < int > que;
             que.push(k);
             while(!que.empty())
             {
                int x= que.front();
                que.pop();
                 for ( int i=1;i<=n;i++)
                 {
                     if((!g[1][n] and g[x][i] ) or (g[1][n] and ! g[x][i]))
                     {
                       if(!vis[i])
                       {
                           que.push(i);
                           level[i]=level[x]+1;
                           vis[i]= true;
                       }
                     }
                 }
             }
           }

          ll int por(ll int a,ll int b)
             {
                ll int k=1;
                while(b>0)
                {
                    if(b%2) k=k*a,k%=hell;
                    b/=2;
                    a*=a; a%=hell;
                }
                return k;
             } */


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
int n,A[200];
int main() {
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&A[i]);
	int ans=0;
	For(i,2,n-1) if((A[i]>A[i-1]&&A[i]<A[i+1])||(A[i]<A[i-1]&&A[i]>A[i+1])) ++ans;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, X;
vector <int> a;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> X >> n;
    a.resize(n);
    for(auto &i : a) cin >> i;
    sort(a.begin(), a.end());
    int ans = -1;
    for(int i = -1 ; i <= 101 ; i++){
        if(binary_search(a.begin(), a.end(), i)) continue;
        if(abs(X - i) < abs(X - ans)) ans = i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3664
import java.util.Scanner;

public class Main {
	//?????°
	public static int x;
	//????????????
	
	public static void solve(){
		Scanner sc = new Scanner(System.in);
		x = sc.nextInt();
		System.out.println(x*x*x);
	}

	public static void main(String[] args) {
		solve();
	}

}

Measured memory_bytes: 26180
#include <iostream>
#include <vector>
#include <cmath>

const int NUM_ELEM = 1e5 + 1;

int main(){
    int n;
    std::cin >> n;

    std::vector<std::vector<long long>> count(2, std::vector<long long>(NUM_ELEM, 0));
    for(int i = 0; i < n; ++i){
        int val;
        std::cin >> val;

        ++count.at(i % 2).at(val);
    }

    auto itrA = std::max_element(count.at(0).begin(), count.at(0).end());
    auto itrB = std::max_element(count.at(1).begin(), count.at(1).end());
    
    long long vari = *itrA + *itrB;
    
    int distA = std::distance(count.at(0).begin(), itrA);
    int distB = std::distance(count.at(1).begin(), itrB);

    std::sort(count.at(0).begin(), count.at(0).end());
    std::sort(count.at(1).begin(), count.at(1).end());
    
    if(distA == distB){
        long long a = count.at(0).at(NUM_ELEM - 1) + count.at(1).at(NUM_ELEM - 2);
        long long b = count.at(1).at(NUM_ELEM - 1) + count.at(0).at(NUM_ELEM - 2);
        vari = std::max(a, b);
    }

    std::cout << n - vari << std::endl;

    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
int b[5];
int c[5];
int main(){
	for(int i=0;i<5;i++)scanf("%d",b+i);
	int ret=0;
	for(int i=0;i<5;i++){
		c[i]=(10-b[i]%10)%10;
		ret+=b[i]+(10-b[i]%10)%10;
	}
	std::sort(c,c+5);
	ret-=c[4];
	
	printf("%d\n",ret);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
#define chmax(x, a)  do { x = max(x, a); } while(0)
#define chmin(x, a)  do { x = min(x, a); } while(0)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> PLL;

const ll INF = 1e17;
ll a[4000][4000];
ll dp[4000][4000][4];

void solve() {
  ll Y, X, K;
  cin >> Y >> X >> K;
  rep(i, Y) rep(j, X) rep(k, 4) dp[i][j][k] = -INF;
  rep(i, Y) rep(j, X) a[i][j] = -INF;
  rep(_, K) {
    ll y, x, v;
    cin >> y >> x >> v;
    a[y-1][x-1] = v;
  }
  chmax(dp[0][0][0], 0ll);
  chmax(dp[0][0][1], a[0][0]);
  rep(i, Y) rep(j, X) rep(k, 4) {
    // 拾わない
    if (i+1 < Y) chmax(dp[i+1][j][0], dp[i][j][k]);
    if (j+1 < X) chmax(dp[i][j+1][k], dp[i][j][k]);
    // 拾う
    if (i+1 < Y)             chmax(dp[i+1][j][1], dp[i][j][k] + a[i+1][j]);
    if (j+1 < X && k+1 <= 3) chmax(dp[i][j+1][k+1], dp[i][j][k] + a[i][j+1]);
  }
  ll ans = 0;
  rep(k, 4)
    chmax(ans, dp[Y-1][X-1][k]);
  cout << ans << endl;
}

int main() {
  //ll T;
  //cin >> T;
  //rep(_,T)
    solve();
  return 0;
}


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

using namespace std;
#define int int64_t
#define fi first
#define se second
#define endl '\n'


signed main()
{
     srand(time(nullptr));
     ios::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
     int n, k;
     cin >> n >> k;
     if (k % 2 == 1) {
          cout << (n / k) * (n / k) * (n / k);
     } else {
          int kek = (n / k) * (n / k) * (n / k);
          kek += ((n + k / 2) / k) * ((n + k / 2) / k) * ((n + k / 2) / k);
          cout << kek << endl;
     }
     return 0;
}


Measured memory_bytes: 256
a, b, c, d = map(int, input().split())
i = 0
while True:
    if i % 2 == 0:
        c -= b
    else:
        a -= d
    i += 1

    if a <= 0:
        print('No')
        break
    elif c <= 0:
        print("Yes")
        break


Measured memory_bytes: 9172
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<iomanip>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}

int N;
vector<int> graph[100010];

vector<int> path;
bool found[100010];

bool dfsPath(int rt, int t) {
    if(found[rt]) return false;
    found[rt] = true;
    path.pb(rt);
    if(rt == t) return true;
    for(int v : graph[rt]) {
        if(dfsPath(v, t)) return true;
    }
    path.pop_back();
    return false;
}

int dfsSol(int rt, int stop) {
    //cout << rt << endl;
    if(rt == stop) return 0;
    if(found[rt]) return 0;
    found[rt] = true;
    int num = 1;
    for(int v : graph[rt]) {
        num += dfsSol(v, stop);
    }
    return num;
}

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

    cin >> N;
    REP(i, N-1) {
        int a, b;
        cin >> a >> b;
        graph[a].pb(b);
        graph[b].pb(a);
    }

    dfsPath(1, N);
    int hf = SZ(path)/2 - 1;
    if(SZ(path)%2 == 1) hf++;
    int u = path[hf];
    int v = path[hf+1];
    //cout << u << " " << v << endl;
    REP(i, 100010) found[i] = 0;
    int sen = dfsSol(1, v);
    //cout << sen << endl;
    REP(i, 100010) found[i] = 0;
    int go = dfsSol(N, u);
    //cout << go << endl;

    if(sen > go) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}


Measured memory_bytes: 12536
import java.util.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    static int dx[]={-1,0,1,0};
    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}


        
//        long L=sc.nextLong();
        int n=sc.nextInt();	
        int W=sc.nextInt();
        int mx=n*1000;
        long dp[][]=new long[2][mx+1];
        long ans=0,inf=(long)1e9;
        inf*=100;
        ans=0;
        fill(dp[0],inf);
        dp[0][0]=0;
        for (int i = 1; i <= n; i++) {
        	int w=sc.nextInt(),v=sc.nextInt();
        	for (int t = 0; t <= mx; t++) {
				if(v<=t)dp[i&1][t]=min(dp[(i+1)&1][t], dp[(i+1)&1][t-v]+w);
				else dp[i&1][t] = dp[(i+1)&1][t];
	        	if(dp[i&1][t]<=W)ans = max(ans,t);
			}
		}

        out.println(ans);
        out.flush();
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//    public int compareTo(P p){
//        return d-p.d; //des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 25556
int G(x,y){return y?G(y,x%y):x;}n[3],a[3],m[3];main(i,x){for(;scanf("%d%d%d%d%d%d",a,m,a+1,m+1,a+2,m+2),*m;n[0]*=n[1]/G(n[0],n[1]),printf("%lld\n",(long long)n[2]/G(n[0],n[2])*n[0]))for(i=3;i--;)for(x=n[i]=1;(x=a[i]*x%m[i])>1;n[i]++);}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  ll n,q;
  cin>>n;
  map<ll,ll> mp;
  for (int i = 0; i < n; ++i)
  {
    ll a;
    cin>>a;
    mp[a]++;
  }
  ll ans=0;
  for(const auto& e: mp) 
  {
    ans+=e.first*e.second;
  }
  cin>>q;
  for (int i = 0; i < q; ++i)
  {
    ll b,c;
    cin>>b>>c;
    ans-=c*mp[c];
    ans-=b*mp[b];
    mp[c]+=mp[b];
    mp[b]=0;
    ans+=c*mp[c];
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 9508
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;

int main(){
	// word[s] Å ¶ñsÌo»ñªÔÁÄ­é
	map<string, int> word;
	vector<string> v;
	string s;

	while( cin >> s ){
		v.push_back(s);
		
		//üÍµ½Pêª·ÅÉ é©T·
		if( word.count(s) ){
			word[s]++;
		}else{
			word[s] = 1;
		}
	}
	// ÅpoÌPêð²×é
	int mode=0;
	for(int i=0 ; i < v.size() ; i++ ){
		mode = max( mode , word[ v[i] ] );
	}
	for(int i=0 ; i < v.size() ; i++ ){
		if( mode == word[ v[i] ] ){
			cout << v[i];
			break;
		}
	}
	// Å·ÌPêðßé
	int length = 0;
	for(int i=0 ; i < v.size() ; i++ ){
		length = max( length , (int)v[i].size() );
	}
	for(int i=0 ; i < v.size() ; i++ ){
		if( length == v[i].size() ){
			cout << " " << v[i] << endl;
		}
	}
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD=1e9+7;

//実際にgrundy数を計算すると分かる

int main(void){
	ll X,Y;
	cin>>X>>Y;
	if(abs(X-Y)<=1){
		cout<<"Brown"<<endl;
	}else{
		cout<<"Alice"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int main(){
    int n,h,w,ans=0;
    cin>>n>>h>>w;
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        if(a>=h&&b>=w) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  int n,m;
  while(cin >> n >> m){
    int a[5000],b[5000],dp[2][5000], ans = 0;
    for(int i=0;i<2;i++) for(int j=0;j<n;j++) dp[i][j] = 0;
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<m;i++) cin >> b[i];

    for(int i=0;i<m;i++){
      if(b[i] == a[0]) dp[1][0] = 1;
      for(int j=1;j<n;j++){
	if(b[i] == a[j]) dp[1][j] = dp[0][j-1] + 1;
	else dp[1][j] = dp[1][j-1];
      }

      for(int j=0;j<n;j++){
	ans = max(ans,dp[1][j]);
	dp[0][j] = dp[1][j];
	dp[1][j] = 0;
      }
    }

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

Measured memory_bytes: 944
import java.util.*;

class BaseballField {

    private boolean first;
    private boolean second;
    private boolean third;
    private int out;
    private int score;

    BaseballField () {
        this.first = false;    
        this.second = false;
        this.third = false;
        this.out = 0;
        this.score = 0;
    }

    void Homerun () {
        int run = 1;
        if (first) {
            run += 1;
            first = false;
        }
        if (second) {
            run += 1;
            second = false;
        }
        if (third) {
            run += 1;
            third = false;
        }
        this.score += run;
    }

    void Hit() {
        if (this.third) {
            this.score += 1;
            this.third = false;
        }
        if (this.second) {
            this.third = true;
            this.second = false;
        }
        if (this.first) {
            this.second = true;
        }
        this.first = true;
    }

    void Out () {
        this.out += 1;
        if (this.out == 3)  this.Change();
    }

    void Change() {
        System.out.println(this.score);
        this.first = false;
        this.second = false;
        this.third = false;
        this.out = 0;
        this.score = 0;
    }


}

class Main {

    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);

        sc.nextLine();
        BaseballField bf = new BaseballField();

        while (sc.hasNext()) {
            String line = sc.nextLine();

            if (line.equals("HIT"))     bf.Hit();
            if (line.equals("HOMERUN")) bf.Homerun();
            if (line.equals("OUT"))     bf.Out();
        }
    }
}

Measured memory_bytes: 12000
import * as fs from "fs";

let S = fs.readFileSync("/dev/stdin", "utf8").trim().split('');

let counter: Map<string, number> = new Map('abcdefghijklmnopqrstuvwxyz'.split('').map((c, i) => {return [c, 0]}));
let total: number = 0;
let answer: number = 1;


for(let c of S) {
    answer += (total-counter.get(c));
    counter.set(c, counter.get(c)+1);
    total += 1;
}

console.log(answer);


Measured memory_bytes: 37812
N=int(input())
a=list(map(int,input().split()))

base=1
count=0

if 1 in a:
    for i in range(N):
        if a[i]==base:
            count+=1
            base+=1
        else:
            pass

    #print(i)
    print((N-count)%N)
else:
    print(-1)

Measured memory_bytes: 24744
#include <stdio.h>
#define MIN(a,b) ((a) < (b)) ? (a) : (b)
int N, M;
int D[1000], C[1000];
int dp[1000 + 1][1000 + 1];

// i(現在の都市数), j(残り日数)
int s(int i, int j)
{
  int res;
  // 到着したか?
  if (i == N) return 0;
  
  // メモ化済みか?
  if (dp[i][j] != 0) return dp[i][j];
  
  // 移動する選択肢しかない場合
  if (N - i == M - j){
    res = s(i + 1, j + 1) + D[i] * C[j];
  } // 2択から選ぶ場合
  else {
    res = MIN(s(i, j + 1), s(i + 1, j + 1) + D[i] * C[j]);
  }
  return dp[i][j] = res;
}

int main(void)
{
  int i;
  scanf("%d %d", &N, &M);
  for (i = 0; i < N; i++){
    scanf("%d", &D[i]);
  }
  for (i = 0; i < M; i++){
    scanf("%d", &C[i]);
  }
  
  printf("%d\n", s(0, 0));
return(0);
}

Measured memory_bytes: 3836