akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
a=int(input())
l=[]
l1=[]
p=0
for i in range(a):
    b=input()
    b=list(b)
    b=sorted(b)
    b="".join(map(str,b))
    l.append(b)
d=Counter(l)
for j in d:
        if d[j]<=2:
            p+=d[j]//2
        else:
            c=d[j]-1
            p+=(c*(c+1))//2
print(p)


Measured memory_bytes: 19828
def partition(a, p, r):
    x = a[r]  # Last
    i = p - 1
    for j in range(p, r):
        if a[j] <= x:
            i += 1
            a[i], a[j] = a[j], a[i]
    a[r], a[i + 1] = a[i + 1], a[r]
    return i + 1


# l = [3, 9, 1, 5, 10, 0, 2]
# print(partition(l, 0, len(l) - 1))
# print(l)

n = int(input())
l = [int(i) for i in input().split()]
x = partition(l, 0, n - 1)

for i in range(n - 1):
    if i == x:
        char = "[" + str(l[i]) + "]"
    else:
        char = str(l[i])
    print(char, end=" ")
print(l[-1])



Measured memory_bytes: 16364
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int main(){
    fast_io

    int a, b, c;
    cin>>a>>b>>c;

    cout<<(a+b)*c/2<<endl;
    return 0;

}


Measured memory_bytes: 256
s = input()
sub_s = s.replace("eraser", "")
sub_s = sub_s.replace("erase", "")
sub_s = sub_s.replace("dreamer", "")
sub_s = sub_s.replace("dream", "")
if len(sub_s) == 0:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3188
#include<stdio.h>
#include<math.h>

 static int A=100;

int main(){
  int i, j, l, k, n, s[A+1], t[A+1][A+1];
  scanf("%d", &n);
  for(i=1; i<=n; i++){
    scanf("%d", &s[i-1]);
    scanf("%d", &s[i]);
  }

  for(i=1; i<=n; i++)      t[i][i] = 0;
  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j = i+l-1;
      t[i][j] = 1<<21;
      for(k=i; k<=j-1; k++){
    t[i][j] = fmin(t[i][j], t[i][k] + t[k+1][j] + s[i-1] * s[k] * s[j]);
      }
    }
  }

  printf("%d", t[1][n]);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2112
#include<iostream>
#include <string.h>
#include<stdio.h>
#include <math.h>
using namespace std;

int main() {
	string S;
	
	cin >> S;

	int n = S.size(),ans = 0;
	if (n % 2 == 0) {
		for (int i = 0; i <= n / 2 - 1; i++) {
			if (S[i] != S[n - 1 - i]) ans++;
		}
	}
	else {
		for (int i = 0; i <= n / 2 - 1;i++) {
			if (S[i] != S[n - 1 - i]) ans++;
		}
	}
	
	cout << ans << endl;
	
	




	
	return 0;
}









Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    double X[n], Y[n], x, y, d_1{0}, d_2{0}, d_3{0}, d_inf{0};

    for(int i=0;i<n;i++){
        cin >> x;
        X[i] = x;
    }
    for(int i=0;i<n;i++){
        cin >> y;
        Y[i] = y;
    }

    for(int i=0;i<n;i++){
        d_1 += abs(X[i]-Y[i]);
        d_2 += pow(X[i]-Y[i], 2);
        d_3 += pow(abs(X[i]-Y[i]), 3);
        d_inf = max(abs(X[i]-Y[i]), d_inf);
    }
    printf("%lf\n", d_1);
    printf("%lf\n", sqrt(d_2));
    printf("%lf\n", cbrt(d_3));
    printf("%lf\n", d_inf);

}


Measured memory_bytes: 3464
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
	ll n,k;
	cin>>n;
	k = 2;
	ll arr[n+1];
	arr[0] = 0;
	REP(i,1,n+1) cin>>arr[i];
	ll dp[n+1];
	REP(i,1,n+1) dp[i] = 1e12;
	dp[0] = 0;
	dp[1] = 0;

	REP(i,2,n+1){
		REP(j,1,k+1){
			if(i-j <= 0)
				break;
			else
				dp[i] = min(dp[i],dp[i-j] + abs(arr[i] - arr[i-j]));	
		}
	}
	// REP(i,1,n+1) cout<<dp[i]<<" ";
	// cout<<endl;
	cout<<dp[n]<<endl;
	return 0;
}



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

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

    uint64_t a, ans = 0;
    for (int i = 0; i < N; ++i) {
        std::cin >> a;
        ans += (a - 1);
    }

    std::cout << ans << std::endl;

    return 0;
}


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



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

    cout << n*800 - (n/15)*200 <<endl;
    
    return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
zero_pad = '.' * (W + 2)
s = []
s.append(zero_pad)
for i in range(H):
    s.append('.' + input() + '.')
s.append(zero_pad)

for h in range(1, H + 1):
    for w in range(1, W + 1):
        if s[h][w] == '#':
            if s[h - 1][w] == '.' and s[h + 1][w] == '.' and s[h][w - 1] == '.' and s[h][w + 1] == '.':
                print('No')
                exit()

print('Yes')


Measured memory_bytes: 9152
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li r, c, n;
    cin >> r >> c >> n;

    vector<vector<li>> vs(n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 2; ++j) {
            li x, y;
            cin >> x >> y;
            if (y == 0) {
                vs[i].emplace_back(x);
            } else if (x == r) {
                vs[i].emplace_back(r + y);
            } else if (y == c) {
                vs[i].emplace_back(r + c + (r - x));
            } else if (x == 0) {
                vs[i].emplace_back(r + c + r + (c - y));
            }
        }
    }

    vector<pair<li, li>> ranges;
    for (int i = 0; i < n; ++i) {
        if (vs[i].size() == 2) {
            li x = vs[i][0];
            li y = vs[i][1];
            if (x > y) {
                swap(x, y);
            }
            ranges.emplace_back(x, y);
        }
    }
    sort(ranges.begin(), ranges.end());

    vector<li> closes;
    bool ok = true;
    for (auto range : ranges) {
        li x = range.first;
        li y = range.second;
        while (not closes.empty()) {
            li close = closes.back();

            if (x > close) {
                closes.pop_back();
            } else {
                if (y < close) {
                    break;
                } else {
                    ok = false;
                    break;
                }
            }
        }
        if (not ok) {
            break;
        }
        closes.push_back(y);
    }
    cout << (ok ? "YES" : "NO") << endl;

    return 0;
}

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

int main()
{

    int a, b, c;
    cin >> a >> b >> c;
    int ans = 1;
    if (b != a)
    {
        ans++;
    }
    if (c != a && c != b)
    {
        ans++;
    }
    cout << ans << endl;
}

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

using namespace std;


void dbg(vector<vector<char>> &m, vector<vector<bool>> &d, vector<vector<int>> &l) {
    int H, W;
    H = m.size() - 2;
    W = m[0].size() - 2;

    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cout << l[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;
}


int nx[] = {-1, 0, 1, 0};
int ny[] = {0, -1, 0, 1};
int solve(vector<vector<char>> &maze, int x, int y) {
    queue<pair<int, int>> q;
    vector<vector<bool>> discovered(maze.size(), vector<bool>(maze[0].size(), false));
    vector<vector<int>> len(maze.size(), vector<int>(maze[0].size(), 0));

    int ret = 0;

    q.push(make_pair(x, y));
    discovered[y][x] = true;
    len[y][x] = 0;
    while (!q.empty()) {
        auto now = q.front();
        // cout << now.first << ", " << now.second << endl;
        q.pop();
        for (int i = 0; i < 4; i++) {
            auto next = make_pair(now.first + nx[i], now.second + ny[i]);
            if (!discovered[next.second][next.first] && maze[next.second][next.first] == '.') {
                discovered[next.second][next.first] = true;
                len[next.second][next.first] = len[now.second][now.first] + 1;
                ret = max(ret, len[next.second][next.first]);
                q.push(next);
            }
        }
    }
    // cout << endl;
    return ret;
}


int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> maze(H + 2, vector<char>(W + 2, '#'));
    for (int i = 1; i <= H; i++) {
        string l;
        cin >> l;
        for (int j = 1; j <= W; j++) {
            maze[i][j] = l[j - 1];
        }
    }

    int ans = 0;
    for (int y = 1; y <= H; y++) {
        for (int x = 1; x <= W; x++) {
            if (maze[y][x] == '.')
                ans = max(ans, solve(maze, x, y));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
S = gets.chomp.split("")
result = "Yes"
S.each_with_index do |e,i|
  if i%2 ==0
    if S[i] == "L"
      result = "No"
      break
    end
  else
    if S[i]=="R"
      result = "No"
    end
  end
end

puts result

Measured memory_bytes: 1788
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const long long llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
string s;
int main()
{
    //freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>s;
    if((s.size()%2==0)^s[0]==s[s.size()-1])cout<<"Second"<<endl;
    else cout<<"First"<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }



int main() {
	ll n, t;
	cin >> n >> t;
	ll ans = 0;
	ll xb = 0;
	ll to;
	bool isStop = false;
	rep(i, n) {
		ll x;
		cin >> x;
		if (i == 0) {
			ans += t;
			to = x + t;
		}
		else {
			if (to > x) {
				ans += (x + t - to);
				to = x + t;
			}
			else {
				ans += t;
				to = x + t;
			}
		}
		
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
while True:
  a, op, b = list(input().split())
  a = int(a)
  b = int(b)

  if op == "+":
    ans = a + b
  elif op == "-":
    ans = a - b
  elif op ==  "*":
    ans = a * b
  elif op ==  "/":
    ans = a // b
  elif op == "?":
    break

  print(ans)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;
using ll=long long;

string subsum(int* A,int n,int m){
  bitset<2010> E(1);

  rep(i,0,n){
    E |= (E<<A[i]);
  }

  if(E.test(m)) return "yes";
  else return "no";
}

vector<bool> seen;
vector<int> d;
vector<int> f;


int dfs(const G &G,int v,int& time){
    seen[v] = true; //v探索済み
    d[v]=time++;

    for(auto next_v :G[v]){
        if(seen[next_v])continue;//もう探索していた
        dfs(G,next_v,time);
    }

    f[v]=time++;
    return time;
}

int main(int argc,char **argv){
  int n; cin>>n;
  G graph(n);
  rep(i,0,n){
    int u,k; cin>>u>>k;
    rep(j,0,k){
      int vj;
      cin>>vj;
      if(i!=vj-1)graph.at(u-1).pb(vj-1);
      //graph.at(vj-1).pb(i);
    }
  }

  d.assign(n,0);
  f.assign(n,0);
  int first_ptr=1;
  seen.assign(n,false);

  rep(i,0,n){
    if(seen[i]==false){
      first_ptr=dfs(graph,i,first_ptr);
    }
  }

  rep(i,0,n){
    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  }



  
  }


Measured memory_bytes: 3164
import java.text.ParseException;
import java.util.Scanner;

public class Main {

	public static void main(String[] arges) throws ParseException {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);
		int[] vs = new int[v];
		String line2 = sc.nextLine();
		String[] lc = line2.split(" ");
		for (int i = 0; i < vs.length; i++) {
			vs[i] = Integer.parseInt(lc[i]);
		}
		System.out.println(line2);

		for (int i = 1; i < vs.length; i++) {
			int key = vs[i];
			int j = i - 1;
			while (j >= 0 && vs[j] > key) {
				vs[j + 1] = vs[j];
				j--;
			}
			vs[j + 1] = key;
			for (int j2 = 0; j2 < vs.length - 1; j2++) {
				System.out.print(vs[j2] + " ");
				if (j2 == vs.length - 2) {
					System.out.println(vs[j2 + 1]);
				}
			}

		}

	}
}

Measured memory_bytes: 31260
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int a[100];
  for(int i=0;i<n;i++) cin>>a[i];
  int ans=0;
  for(int c=1;c<101;c++){
    for(int i=0;i<n;i++){
      if(a[i]==c){
        ans++;
        break;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1000000000000
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main() {
  int n;
  cin >> n;
  int p[n] = { };
  string s;
  cin >> s;
  p[0] = 1;
  p[1] = 1;
  FOR(i, 2, n){
    if((p[i-1] == 1) ^ (s[i-1] == 'o')) p[i] = p[i-2] * (-1);
    else p[i] = p[i-2];
  }
  if(((p[0] == 1) ^ (s[0] == 'o') ^ (p[1] == p[n-1])) && ((p[n-1] == 1) ^ (s[n-1] == 'o') ^ (p[0] == p[n-2]))){
    REP(i, n) cout << (p[i] == 1 ? 'S' : 'W');
    cout << endl;
    return 0;
  }
  p[0] = 1;
  p[1] = -1;
  FOR(i, 2, n){
    if((p[i-1] == 1) ^ (s[i-1] == 'o')) p[i] = p[i-2] * (-1);
    else p[i] = p[i-2];
  }
  if(((p[0] == 1) ^ (s[0] == 'o') ^ (p[1] == p[n-1])) && ((p[n-1] == 1) ^ (s[n-1] == 'o') ^ (p[0] == p[n-2]))){
    REP(i, n) cout << (p[i] == 1 ? 'S' : 'W');
    cout << endl;
    return 0;
  }
  p[0] = -1;
  p[1] = 1;
  FOR(i, 2, n){
    if((p[i-1] == 1) ^ (s[i-1] == 'o')) p[i] = p[i-2] * (-1);
    else p[i] = p[i-2];
  }
  if(((p[0] == 1) ^ (s[0] == 'o') ^ (p[1] == p[n-1])) && ((p[n-1] == 1) ^ (s[n-1] == 'o') ^ (p[0] == p[n-2]))){
    REP(i, n) cout << (p[i] == 1 ? 'S' : 'W');
    cout << endl;
    return 0;
  }
  p[0] = -1;
  p[1] = -1;
  FOR(i, 2, n){
    if((p[i-1] == 1) ^ (s[i-1] == 'o')) p[i] = p[i-2] * (-1);
    else p[i] = p[i-2];
  }
  if(((p[0] == 1) ^ (s[0] == 'o') ^ (p[1] == p[n-1])) && ((p[n-1] == 1) ^ (s[n-1] == 'o') ^ (p[0] == p[n-2]))){
    REP(i, n) cout << (p[i] == 1 ? 'S' : 'W');
    cout << endl;
    return 0;
  }
  cout << -1 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll A, B, C, D, E, F, G, H, X, Y, Z, P, Q, M, N, T, R, K, W, L, ANS;
string S, S1, S2;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> X;
    ANS = INF;
    ll UP[N][M + 1];

    rep(i, N) {
        rep(j, M + 1) { cin >> UP[i][j]; }
    }

    rep(i, (1 << N)) {
        vl SKILL(M, 0);
        P = 0;
        rep(j, N) {

            if((1 << j) & i) {
                P += UP[j][0];
                rep(k, M) { SKILL[k] += UP[j][k + 1]; }
            }
        }
        rep(j, M) {
            if(SKILL[j] < X)
                P += INF;
        }
        // cout << i << " " << P << SKILL[0] << SKILL[1] << SKILL[2] << endl;
        ANS = min(ANS, P);
    }

    if(ANS == INF)
        cout << -1 << endl;
    else
        cout << ANS << endl;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 998244353
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll> > vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

bool prime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

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

ll addmod(ll a,ll b)
{
    if(a+b<mod)return a+b;
    else return a+b-mod;
}
ll mulmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
ll modinv(ll a)
{
    return modexp(a,mod-2,mod);
}

bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    return a.fi>b.fi;
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll k; cin>>k;
queue<ll>q;
for(ll i =1;i<=9;i++)q.push(i);

ll ans;
for(ll i =0;i<k;i++)
{
    ans = q.front();
    q.pop();

    if(ans%10!=0)q.push(ans*10+(ans%10)-1);
    q.push(ans*10+ans%10);
    if(ans%10!=9)q.push(ans*10+(ans%10)+1);
}
cout<<ans<<endl;
return 0;
}
/*
6
1 2 3 4 5 -6
*/


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
	


int main() {
	int x, a, b;
	cin >> x >> a >> b;
	int da, db;
	da = abs(x - a);
	db = abs(x - b);
	cout << (da < db ? "A" : "B") << endl;

	return 0;
}

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

#define out(t) cout << (t) << "\n"

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int uint;

int popcount(uint x) {
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

int tzcnt(uint x) {
    return popcount(~x & x - 1);
}

struct Point {
    int x, y;

    Point(int p, int q) : x(p), y(q) {}
};

ll ans[100];

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

    int a ,b, c;
    cin >> a >> b >> c;

    out(a + b >= c ? "Yes" : "No");

    int aaa;
    cin >> aaa;
}

Measured memory_bytes: 256
#pragma GCC optimize("trapv")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
//using arr = array;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 105, mod = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct bstring {
	int n;
	__int128 str = 0;
	bstring(string s = "") {
		n = s.size();
		for(int i = 0; i < n; i++) if(s[i]-'0') str|= __int128(1)<<i;
	}
	bool operator<(const bstring &o) const {
		return n < o.n || (n == o.n && str < o.str);
	}
	
	string tos() {
		string s = "";
		for(int i = 0; i < n; i++) s.pb('0' + ((str>>i)&1));
		return s;
	}
	bstring ss(int l, int r) {
		bstring t;
		t.n = n;
		t.str = str;
		t.str>>=l;
		t.n = r-l+1;
		return t;
	}
};

string s;
map<bstring, int> dp[3];
//0 - do anything
//1 - group
//2 - nothing
int f(bstring s, int mode) {
	if(dp[mode].count(s)) return dp[mode][s];
	int res = 0, n = s.n;
	if(mode == 2) {
		res = 1;
		for(int i = 0; i < n; i++) if((s.str>>i)&1) res = res*2ll%mod;
		return dp[mode][s] = res;
	}
	if(mode == 1) {
		__int128 msk = 0;
		for(int i = 1; i < n; i++) {
			msk|=__int128(1)<<(i-1);
			if(n%i) continue;
			bstring tt = s;
			for(int x = 0; x < n; x++) if(!((s.str>>x)&1)) tt.str = min(tt.str, tt.str^(__int128(1)<<(x%i)));
			tt.n = i;
			tt.str &= msk;
			res = (res + f(tt, 0))%mod; 
		}
		return dp[mode][s] = res;
	}
	{
	vector<int> dp[2];
	for(int i = 0; i < n; i++) {
		dp[0].pb(0);
		dp[1].pb(0);
		for(int j = 0; j <= i; j++) {
			(dp[1].back() += (j ? dp[0][j-1]+dp[1][j-1] : 1)*1ll*f(s.ss(j, i), 1)%mod ) %= mod;
			(dp[0].back() += (j ? dp[1][j-1] : 1)*1ll*f(s.ss(j, i), 2)%mod ) %= mod;
		}
	}
	res = (dp[0].back() + dp[1].back())%mod;
	}
	return dp[mode][s] = res;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> s;
	bstring a(s);
	cout << f(a, 0);
}


Measured memory_bytes: 100972
import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())
X = list(map(int,readline().split()))

if 0 in X: # 座標0にろうそくがあるなら一本消せる
  K -= 1
  
plus = []
minus = []
for x in X:
  if x < 0:
    minus += [-x]
  elif x > 0:
    plus += [x]
    
minus = [0] + minus[::-1]
plus = [0] + plus

ans = 10 ** 10
for m in range(K + 1):
  p = K - m
  if m < len(minus) and p < len(plus):
    dist = min(minus[m],plus[p]) * 2 + max(minus[m],plus[p])
    if ans > dist:
      ans = dist
      
print(ans)
  
  

    


Measured memory_bytes: 14656
#include<bits/stdc++.h>
#define height(i) (abs(X[i]-x)+abs(Y[i]-y)+h[i])
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> X(N),Y(N),h(N);
  for(int i=0;i<N;i++)cin>>X[i]>>Y[i]>>h[i];
  
  for(int x=0;x<=100;x++){
    for(int y=0;y<=100;y++){
      int ch=-1;
      for(int i=0;i<N;i++){
        if(h[i]==0)continue;
        if(ch==-1){ch=height(i);continue;}
        if(ch!=height(i)){ch=-2;break;}
      }
      if(ch>0){
        for(int i=0;i<N;i++)if(h[i]!=max(ch-abs(X[i]-x)-abs(Y[i]-y),0)){ch=-2; break;}
        if(ch>0){cout<<x<<" "<<y<<" "<<ch<<endl;return 0;}
      }
    }
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main()
{
  int n;
  while(cin >> n) {
    if(n == 0) return 0;
    bool ta[2*n+1]; FOR(i,0,2*n+1) ta[i] = false;
    vector<vector<int> > card(2); // taro hanako
    FOR(i,0,n) {
      int in; cin >> in;
      ta[in] = true;
    }
    FOR(i,1,2*n+1) card[!ta[i]].push_back(i);
    sort(card[0].begin(), card[0].end());
    sort(card[1].begin(), card[1].end());
    int j = 0, now = 0;
    while(card[0].size() && card[1].size()) {
      FOR(i,0,card[j%2].size()) {
        if(now < card[j%2][i]) {
          now = card[j%2][i];
          card[j%2].erase(card[j%2].begin() + i);
          break;
        }
        if(i == card[j%2].size() - 1) now = 0;
      }
      j++;
    }
    int p[2]; p[0] = p[1] = 0;
    FOR(i,0,2) FOR(j,0,card[i].size()) p[i^1]++;
    cout << p[0] << endl;
    cout << p[1] << endl;
  }
  return 0;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define Fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(n) for(int i = 0; i < n; ++i)
#define fa(a, n) for(int i = a; i < n; ++i)
#define fi(i, n) for(int i = 0; i < n; ++i)
#define mod 1000000007
#define oo 1000000000LL
int main()
{
    long long int n,m,sum=0,i;
   cin>>n>>m;
   for(i=n-1;i>=0;i--)
   {
       sum+=i;
   }
   for(i=m-1;i>=0;i--)
   {
       sum+=i;
   }
   cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <climits>
#include <functional>
#include <map>
#include <stack>
#include <cstdlib>
#include <queue>
#define endl '\n'
#define ll long long
#define NCONS 100001

using namespace std;
int c[4][4];
int a[4], b[4];

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    for(int i = 1; i <= 3; i++) for(int j = 1; j <= 3; j++) cin >> c[i][j];
    
    a[1] = 0;
    for(int i = 1; i <= 3; i++)
        b[i] = c[1][i] - a[1];
    for(int i = 1; i <= 3; i++)
        a[i] = c[i][1] - b[1];
    
    for(int i = 1; i <= 3; i++)
    {
        for(int j = 1; j <= 3; j++)
        {
            if(a[i] + b[j] != c[i][j])
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    
    return 0;
}


Measured memory_bytes: 504
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, a;
string str;

int main(){
	double sum = 0;
	cin >> n;
	for(ll i = 1; i<= n; i++){
		cin >> a;
		sum += 1.0/a;
	}
	
	cout << setprecision(10) << 1.0/sum << endl; 
	return 0;
}

Measured memory_bytes: 256
N, M = list(map(int, input().rstrip().split()))
X = list(map(int, input().rstrip().split()))
if N >= M:
    cnt = 0;
elif N == 1:
    cnt = max(X) - min(X)
else:
    X.sort()
    D = []
    for i in range(1, len(X)):
        D.append(X[i] - X[i - 1])
    D.sort()
    del D[-(N - 1):]
    cnt = sum(D)
print(cnt)

Measured memory_bytes: 13960
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(N: int):
    dp = [[[[0 for _ in range(4)] for _ in range(4)] for _ in range(4)] for _ in range(N+1)]
    # A:0, G:1, C:2, T:3
    chars = ['A', 'G', 'C', 'T']
    for i in range(4):
        for j in range(4):
            for k in range(4):
                dp[3][i][j][k] = 1
    dp[3][0][1][2] = 0
    dp[3][0][2][1] = 0
    dp[3][1][0][2] = 0
    cnt = 0
    for i in range(3, N):
        for j1, c1 in enumerate(chars):
            for j2, c2 in enumerate(chars):
                for j3, c3 in enumerate(chars):
                    for j4, c4 in enumerate(chars):
                        cs4 = c1+c2+c3+c4
                        cs3 = c2+c3+c4
                        if 'AGC'==cs3 or 'ACG'==cs3 or 'GAC'==cs3 or 'AAGC'==cs4 or 'ACGC'==cs4 or 'AGGC'==cs4 or 'ATGC'==cs4 or 'AGAC'==cs4 or 'AGGC'==cs4 or 'AGCC'==cs4 or 'AGTC'==cs4:
                            continue
                        cnt += 1
                        dp[i+1][j2][j3][j4] += dp[i][j1][j2][j3]
                        dp[i+1][j2][j3][j4] %= MOD
    ans = 0
    for i in range(4):
        for j in range(4):
            for k in range(4):
                ans += dp[N][i][j][k]
                ans %= MOD
    print(ans)

    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  int x, n, tmp;
  int c[102] = {};
  cin >> x >> n;
  REP(i, n) {
    cin >> tmp;
    c[tmp]++;
  }
  if(n == 0) {
    cout << x << endl;
    return 0;
  }

  int i = 0;
  while(true) {
    if(c[x - i] == 0) {
      cout << x - i << endl;
      break;
    } else if(c[x + i] == 0) {
      cout << x + i << endl;
      break;
    }
    i++;
  }
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#define mp make_pair
using namespace std;
typedef long long ll;
struct P{
	int a[3],x,y,z;
}a[100005];
int X,Y,Z,n;
ll tot[100005],cnt[100005];
multiset<int> s;
bool cmp(P a,P b){
	return a.x-a.y<b.x-b.y;
}
int main(){
	scanf("%d%d%d",&X,&Y,&Z);
	n=X+Y+Z;
	ll ans=-1e15;
	for(int i=1;i<=X+Y+Z;i++){
		for(int p=0;p<3;p++) scanf("%d",&a[i].a[p]);
		a[i].x=a[i].a[0]-a[i].a[2];
		a[i].y=a[i].a[1]-a[i].a[2];
		a[i].z=a[i].a[2];
	}
	sort(a+1,a+n+1,cmp);
	ll sum=0;
	for(int i=1;i<=Y;i++) sum+=a[i].y,s.insert(a[i].y);
	tot[Y]=sum;
	for(int i=Y+1;i<=n;i++){
		if((*s.begin())<a[i].y) sum+=a[i].y-(*s.begin()),s.erase(s.begin()),s.insert(a[i].y);
		tot[i]=sum;
	}
	sum=0;s.clear();
	for(int i=n;i>n-X;i--) sum+=a[i].x,s.insert(a[i].x);
	cnt[n-X+1]=sum;
	for(int i=n-X;i;i--){
		if((*s.begin())<a[i].x) sum+=a[i].x-(*s.begin()),s.erase(s.begin()),s.insert(a[i].x);
		cnt[i]=sum;
	}
	for(int i=Y;i<=n-X;i++) ans=max(ans,tot[i]+cnt[i+1]);
	for(int i=1;i<=n;i++) ans+=a[i].z;
	printf("%lld",ans);
	return 0;
}

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

int main(){
  int n, m, sum=0;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n){
    cin >> a[i];
    sum+=a[i];
  }

  double lim=(double)sum/(4.0*(double)m);
  int cnt=0;
  rep(i, n){
    if(a[i]>=lim){
      cnt++;
    }
    else{
      continue;
    }
  }

  if(cnt>=m){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=3e5+10;
int gcd(int n,int m)
{
    if(n==0)
        return m;
    else
        return gcd(m%n,n);
}
int32_t main()
{
    IOS;
	int n;
    cin>>n;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                sum+=gcd(i,gcd(j,k));
            }
        }
    }
    cout<<sum<<endl;



}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long a = sc.nextInt();
		long b = sc.nextInt();

		long ans = lcm(a, b);
		System.out.println(ans);




	}




	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}

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



}


class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}


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

int main(){
    int N, K;
    cin >> N >> K;

    int kmax = (N - 1) * (N - 2) / 2;
    if (K > kmax){
        cout << -1 << endl;
        return 0;
    }
    vector<pair<int, int>> g;
    for (int i = 2; i <= N; i++) {
        g.emplace_back(1, i);
    }
    int k = kmax;
    for (int i = 2; i <= N; i++) {
        if (k == K)
            break;
        for (int j = i + 1; j <= N; j++) {
            g.emplace_back(i, j);
            k--;
            if (k == K)
                break;
        }
    }
    cout << g.size() << endl;
    for (auto p : g) {
        printf("%d %d\n", p.first, p.second);
    }
}

Measured memory_bytes: 3732
fn read<T: std::str::FromStr>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

fn main() {
    let n: usize = read();
    let v: Vec<usize> = (0..5).map(|_| read()).collect();
    let min = v.iter().min().unwrap();
    println!("{}", (n - 1) / min + 5);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <climits>
#include <utility>
#include <deque>
#include <list>
using namespace std;

#define FOR_ALL_CIN(xs) for (auto& x : (xs)) cin >> x

int main()
{
	cout << fixed << setprecision(6);
	string s;
	cin >> s;


	cout << (s[0] == s[1] || s[1] == s[2] || s[2] == s[3] ? "Bad" : "Good") << endl;
	return 0;
}

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

using namespace std;

int main() {
	int N, P;
	cin >> N >> P;
	string s;
	cin >> s;

	reverse(s.begin(), s.end());
	if (P == 2 || P == 5) {
		Int ans = 0;
		for (int i = 0; i < N; ++i) {
			if ((s[i] - '0') % P == 0) {
				ans += N - i;
			}
		}
		cout << ans << endl;
		return 0;
	}

	vector<Int> cnt(P, 0);
	cnt[0] = 1;
	int a = 0;
	int x = 1;
	Int ans = 0;
	for (int i = 0; i < N; ++i) {
		a = (a + (s[i] - '0') * x % P) % P;
		ans += cnt[a];
		++cnt[a];
		(x *= 10) %= P;
	}
	cout << ans << endl;

	return 0;
}


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

int main(){
  string s,t;
  cin >> s >> t;
  int wrap=0,index=-1;
  for(int i=0;i<t.length();i++){
    index = s.find(t[i],index+1);
    if( index != -1) continue;
    wrap += 1;
    index = s.find(t[i]);
    if( index == -1 ){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << s.length()*wrap+index+1 << endl;
  return 0;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    S = list(input())

    ans = []
    for s in S:
        o = ord(s) + N
        if ord('Z') < o:
            o = o - ord('Z') + 64
        
        ans.append(chr(o))
    
    print("".join(ans))




if __name__ == "__main__":
    main()

Measured memory_bytes: 65484
s = raw_input()
up,down,left,right = False,False,False,False
for i in xrange(len(s)) :
    if s[i] == 'N' :
        up = True
    elif s[i] == 'S' :
        down = True
    elif s[i] == 'E' :
        left = True
    else :
        right = True
if (up!=down) or (left!=right) :
    print 'No'
else :
    print 'Yes'


Measured memory_bytes: 2572
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args) {

		ArrayList<Integer> data = new ArrayList<>();

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {

			for(int input_i = 0; input_i <= 10000; input_i++) {
				// Transelate from string of "br.readLine()" to "int" to "Integer"
				Integer num = Integer.valueOf(Integer.parseInt(br.readLine()));
				data.add(num);

				if(data.get(input_i) == Integer.valueOf(0)) {
					break;
				}
			}

			for (int case_j = 0; case_j < (data.size() - 1); case_j++) {
				System.out.println("Case " + (case_j + 1) + ": " + data.get(case_j));
			}

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}



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

int main()
{
   int i,j,t,n,m,a,b,c;
   cin >> n;
   int arr[n+1];
   for(int i = 1 ; i <=n; i++)
   cin >> arr[i];
   int dp[n+1];
   dp[0] = 0;
   dp[1] = 0;
   dp[2] = abs(arr[2] - arr[1]);
   
   for(int i = 3 ;i<=n ;i++)
   dp[i] = min((dp[i-1] + abs(arr[i] - arr[i-1])),(dp[i-2] + abs(arr[i] - arr[i-2])));
   
   cout<<dp[n]<<endl;
   
   return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
const ll MOD = (1e+9)+7;
typedef pair<ll, ll> LP;
 
ll POW(ll m,ll n)
{
  if(n<0) return 0;
  if(n==0) return 1;
  return m*POW(m,n-1)%MOD;
}
 
int main()
{
  string s;
  ll x,a[100009],c[100009],d[100009],e[100009],ans,y,z,w,l;
  cin >> s;
  ans=0;
  x=s.length();
  if(s[0]=='A')a[0]=1;
  else a[0]=0;
  FOR(i,1,x){if(s[i]=='A')a[i]=a[i-1]+1;
             else a[i]=a[i-1];
            }
  
  if(s[0]=='?')d[0]=1;
  else d[0]=0;
  FOR(i,1,x){if(s[i]=='?')d[i]=d[i-1]+1;
             else d[i]=d[i-1];
            }
  
  if(s[x-1]=='C')c[x-1]=1;
  else c[x-1]=0;
  FOR(i,1,x){if(s[x-i-1]=='C')c[x-i-1]=c[x-i]+1;
             else c[x-i-1]=c[x-i];
            }
  
  if(s[x-1]=='?')e[x-1]=1;
  else e[x-1]=0;
  FOR(i,1,x){if(s[x-i-1]=='?')e[x-i-1]=e[x-i]+1;
             else e[x-i-1]=e[x-i];
            }
  y=POW(3,d[x-1]);
  w=POW(3,d[x-1]-1);
  z=POW(3,d[x-1]-2);
  l=POW(3,d[x-1]-3);
  FOR(i,1,x-1){if(s[i]=='?')ans=(ans+w*a[i-1]*c[i+1]+l*d[i-1]*e[i+1]+z*a[i-1]*e[i+1]+z*d[i-1]*c[i+1])%MOD;
               else if(s[i]=='B')ans=(ans+y*a[i-1]*c[i+1]+z*d[i-1]*e[i+1]+w*a[i-1]*e[i+1]+w*d[i-1]*c[i+1])%MOD;
              }
  printf("%lld",ans);
}

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

int px[24],py[24],kx,ky;
int num[24][4] = {0};

int H,W,N,ans;
int field[12][12] = {0};

int dx[] = {0,-1,0,1} , dy[] = {1,0,-1,0};
bool done[12][12];

map<int,int> memo[24];

int dfs(int pos,int bit){
	if(memo[pos].find(bit) != memo[pos].end() )return memo[pos][bit];
	if(bit==(1<<N)-1){
		rep(d,4){
			int cx = px[pos]+dx[d] , cy = py[pos]+dy[d];
			while( field[cy][cx] != -1){
				if(field[cy][cx] == 64)return 1;
				cy += dy[d] , cx += dx[d];
			}
		}
		return 0;
	}
	int ans = 0;
	rep(d,4){
		int cx = px[pos]+dx[d] , cy = py[pos]+dy[d];
		while( field[cy][cx] == -2 || done[cy][cx] == 1 || field[cy][cx] == 64){
			cy += dy[d] , cx += dx[d];
		}
		if(field[cy][cx] != -1){
			done[cy][cx] = 1;
			ans += dfs(field[cy][cx],bit | (1<<field[cy][cx]) );
			done[cy][cx] = 0;
		}
	}
	if(__builtin_popcount(bit) < 19){
		return memo[pos][bit] = ans;
	}else{
		return ans;
	}
}

int main(){
	while(cin >> W >> H ,W){
		N = ans = 0;
		rep(i,24)rep(j,4)num[i][j] = -1;
		rep(i,12)rep(j,12)field[i][j] = -1;
		rep(i,H)rep(j,W){
			int t;
			cin >> t;
			switch(t){
			case 0:
				field[i+1][j+1] = -2;
				break;
			case 1:
				field[i+1][j+1] = N;
				px[N] = j+1, py[N] = i+1;
				N++;
				break;
			case 2:
				kx = j+1 , ky = i+1;
				field[i+1][j+1] = 64;
				break;
			}
		}
		px[N] = kx , py[N] = ky;
		rep(i,24)memo[i].clear();
		cout << dfs(N,0) << endl;
	}
}

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

int main() {
    string s;
    cin >> s;
    int count=0;
    for(int i=0;i<s.size();i++){
        if(s.at(i)=='o'){
            count++;
        }
    }
    if(count+15-s.size()>=8) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.Math.min;
import static java.lang.Math.max;
public class Main {
    private static void solver(InputReader sc, PrintWriter out) throws Exception {
       int x = sc.nextInt();
       int y = sc.nextInt();
       if(y%2==0){
          int max = x * 4;
          if(y > max){
              out.println("No"); return;
          }
          y -= (x * 2);
          if(y >= 0 && y/2 <= x){
              out.println("Yes");
          }else out.println("No");
       }else{
           out.println("No");
       }
    }
    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in,out);
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}
class Pair implements Comparable<Pair>{
    int x,y;
    Pair(int x, int y){
        this.x = x;
        this.y = y;
    }
    public int compareTo(Pair p){
        return (int)(this.x - p.x);
    }

}

Measured memory_bytes: 33040
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	min := 2000000000
	max := 1
	for i := 0; i < n; i++ {
		var v int
		fmt.Scan(&v)
		if v < min {
			min = v
		}
		if max < v {
			max = v
		}
	}
	fmt.Println(max - min)
}


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

int main(){
  string S;
  cin >> S;
  int y, m, d;
  y=(S[0]-'0')*1000+(S[1]-'0')*100+(S[2]-'0')*10+(S[3]-'0');
  m=(S[5]-'0')*10+(S[6]-'0');
  d=(S[8]-'0')*10+(S[9]-'0');
  if(y<2019 || ((y==2019) && m<4) || (y==2019 && m==4 && d<=30)){
    cout << "Heisei" << endl;
    return 0;
  }
  cout << "TBD" << endl;
  return 0;
}

Measured memory_bytes: 256
use std::fmt::{Debug, Display};
use std::io::{self, Read};
use std::str::{self, FromStr};


fn solve(p: Vec<usize>) -> u64 {
    let mut result = 0;
    let mut block_len = 0;

    for i in 0..p.len() {
        if i + 1 == p[i] {
            block_len += 1;
        } else {
            result += (block_len + 1) / 2;
            block_len = 0;
        }
    }
    result += (block_len + 1) / 2;
    result
}


fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    let n = sc.next();
    println!("{}", solve(sc.vec(n)));
}


struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(256),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: Debug,
    {
        self.buf.clear();
        for c in self.bytes
            .by_ref()
            .map(|c| c.unwrap())
            .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
            .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
        {
            self.buf.push(c);
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<A: FromStr, B: FromStr, C: FromStr>(&mut self, n: usize) -> Vec<(A, B, C)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
        <C as FromStr>::Err: Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.vec(m)).collect()
    }
}


#[allow(dead_code)]
fn print_foreach<T: Display>(answer: &[T]) {
    for x in answer {
        println!("{}", x);
    }
}


#[allow(dead_code)]
fn print_yn(answer: bool, yes: &str, no: &str) {
    println!("{}", if answer { yes } else { no });
}


#[allow(dead_code)]
fn print_or<T: Display>(answer: &Option<T>, or: &T) {
    match *answer {
        Some(ref x) => println!("{}", x),
        None => println!("{}", or),
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

const int N = 10 + 5;
bool f[N];
vector<int> G[N];
int ans, n, m;
void dfs(int u) {
	f[u] = 1;
	bool last = 1;
	rep(i,0,SZ(G[u])) {
		int v = G[u][i];
		if(!f[v]) dfs(v), last = 0;
	}
	if(last && accumulate(f, f + n, 0) == n) ans++;
	f[u] = 0;
}
int main(){
	cin >> n >> m;
	ans = 0;
	rep(i,0,m) {
		int a, b;
		cin >> a >> b;
		G[a-1].push_back(b-1);
		G[b-1].push_back(a-1);
	}
	memset(f, 0, sizeof(f));
	dfs(0);
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256