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

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define ll long long
#define ld long double

const int INF = 2e9 + 1;
const ll INFLL = 1e18 + 1;
const int mod = 998244353;

vector<int> t;

int get(int v, int vl, int vr, int l, int r) {
    if (vr <= l || vl >= r) return 0;
    if (vl >= l && vr <= r) return t[v];
    int vm = (vl + vr) / 2;
    return max(get(2 * v + 1, vl, vm, l, r), get(2 * v + 2, vm, vr, l, r));
}

void modify(int v, int vl, int vr, int ind, int val) {
    if (vr - vl == 1) {
        t[v] = val;
        return;
    }
    int vm = (vl + vr) / 2;
    if (ind < vm) modify(2 * v + 1, vl, vm, ind, val);
    else modify(2 * v + 2, vm, vr, ind, val);
    t[v] = max(t[2 * v + 1], t[2 * v + 2]);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    t.resize(4 * n);
    vector<pair<int, int>> x1(n);
    vector<int> d1(n);
    for (int i = 0; i < n; i++) {
        cin >> x1[i].fi >> d1[i];
        x1[i].se = i;
    }
    sort(all(x1));
    vector<int> x(n), d(n);
    for (int i = 0; i < n; i++) {
        x[i] = x1[i].fi;
        d[i] = d1[x1[i].se];
    }
    vector<int> last(n);
    last[n - 1] = n - 1;
    modify(0, 0, n, n - 1, n - 1);
    for (int i = n - 2; i >= 0; i--) {
        int left = i, right = n;
        while (right - left > 1) {
            int mid = (left + right) / 2;
            if (x[mid] >= x[i] + d[i]) right = mid;
            else left = mid;
        }
        last[i] = max(i, get(0, 0, n, i, left + 1));
        modify(0, 0, n, i, last[i]);
    }
    vector<vector<int>> dp(n, vector<int>(2));
    dp[n - 1][0] = dp[n - 1][1] = 1;
    for (int i = n - 2; i >= 0; i--) {
        dp[i][0] = (dp[i + 1][0] + dp[i + 1][1]) % mod;
        if (last[i] == n - 1) dp[i][1] = 1;
        else dp[i][1] = (dp[last[i] + 1][0] + dp[last[i] + 1][1]) % mod;
    }
    cout << (dp[0][0] + dp[0][1]) % mod;
    return 0;
}


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

int main()
{
   int a;
   cin>>a;
   double n;
   n=a;
   if(a%2==0)
   {
       printf("%.10lf\n",(a/2)/n);
   }
   else
   {
        printf("%.10lf\n",((a/2)+1)/n);
   }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if((b*10+c)%4==0){
		cout<<"YES"<<endl;
	}
	
	else if((b*10+c)%4!=0){
	 cout<<"NO"<<endl;
}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

long long int memo[1 << 20];
long long int getans(bitset<20>&bs, vector<int>&nums, vector<vector<int>>&edges) {
	if (memo[bs.to_ulong()] != -1)return memo[bs.to_ulong()];
	if (bs.count()) {
		long long int ans = 0;
		for (int i = 0; i < nums.size(); ++i) {
			if (!nums[i] && !bs[i]) {
				bs[i] = true;
				for (auto e : edges[i]) {
					nums[e]--;
				}
				ans += getans(bs, nums, edges);
				bs[i] = false;
				for (auto e : edges[i]) {
					nums[e]++;
				}
			}
		}
		return memo[bs.to_ulong()] = ans;
	}
	else {
		return memo[bs.to_ulong()]=1;
	}
}
vector<int>topo_sort(const vector<vector<int>>&edges) {
	int size_ = edges.size();
	vector<int>nums(size_);
	for (const auto& es : edges) {
		for (auto e : es) {
			nums[e]++;
		}
	}
	queue<int>que;
	for (int i = 0; i < size_; ++i) {
		if (!nums[i]) {
			que.push(i);
		}
	}
	vector<int>topo;
	while (!que.empty()) {
		int ver(que.front());
		topo.push_back(ver);
		que.pop();
		for (auto e : edges[ver]) {
			nums[e]--;
			if (!nums[e])que.push(e);
		}
	}
	if (topo.size() == size_)return topo;
	else return vector<int>();
}

int main() {
	for (int i = 0; i < (1 << 20); ++i) {
		memo[i] = -1;
	}
	int M, N; cin >> M >> N;
	vector<vector<int>>edges(M);
	vector<int>nums(N);
	for (int i = 0; i < N; ++i) {
		int x, y; cin >> x >> y; x--; y--;
		edges[x].push_back(y);
		nums[y] ++;
	}
	bitset<20>bs((1 << N) - 1);
	//long long int ans = getans(bs, nums, edges);
	auto v=topo_sort(edges);
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i] + 1 << endl;
	}
	return 0;
}

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

#if DEBUG && !ONLINE_JUDGE
    #include "/home/tushar_garg/Desktop/cpp/debug.h"
#else
    #define dbg(x...)
#endif

typedef     long long                            ll; 
typedef     pair<ll, ll>                         pl; 
typedef     vector<ll>                           vl;
typedef     vector<char>                         vc;
typedef     vector<bool>                         vb; 
typedef     vector<vl>                           vvl; 
typedef     vector<pl>                           vll; 
typedef     map<ll, ll>                          dict; 
typedef     map<ll, ll, greater <ll> >           sdict; 
typedef     map<char, ll>                        mcl;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pl>                   pqii;
typedef     priority_queue<ll, vl, greater<ll>>  pqmini;

#define rep(i, a, n) for (auto i=a-(a>n); i!=n-(a>n); i+=1-2*(a>n))
#define trav(i, a) for(auto &i:a)
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back
#define eb emplace_bac
#define flash ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define QuickSilver cin.exceptions(cin.failbit),setprecision(12),cout.precision(12)
#define get(a) rep(i,0,sz(a))cin>>a[i];
#define sz(a) (ll)(a.size())
#define all(a) a.begin(), a.end()
#define mod 1000000007

int main(){
	flash; QuickSilver;
	int a, b; cin>>a>>b;
  if(a>b) swap(a,b);
  rep(i,0,b) cout<<a;
  cout<<"\n";
	return 0;
}

Measured memory_bytes: 384
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		int D = nextInt();
		int X = nextInt();
		int[] A = new int[N];
		for(int i=0;i<N;i++){
			A[i]=nextInt();
		}

		long ans = 0;
		for(int k=0;k<N;k++){
			int i=1;
			while(i<=D){
				ans++;
				i+=A[k];
			}
		}

		System.out.println(ans+X);
	}

	public static boolean isExpN(long a,int base){
		int x=1;
		while((int)Math.pow(x, 2) <= a){
			if((int)Math.pow(x, 2) == a){
				return true;
			}
			x*=base;
		}
		return false;
	}
	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21204
#include <iostream>
#include <vector>

using namespace std;

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

    vector <int> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    
    if (n == 1){
        cout << a[0] << endl;
    }else if (n % 2 != 0){
        for (int i = n - 1; i >= 0; i -= 2){
            cout << a[i] << " ";
        }
        for (int i = 1; i < n; i+= 2){
            cout << a[i] << " ";
        }
        cout << endl;
    }else{
        for (int i = n - 1; i >= 0; i -= 2){
            cout << a[i] << " ";
        }
        for (int i = 0; i < n; i += 2){
            cout << a[i] << " ";
        }
        cout << endl;
    }

    return 0;
}

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

int gethead(int n) {
	if(0 < n && n < 10)
		return n;
	return gethead(n/10);
}
int gettail(int n) {
	return n%10;
}

int main(void) {
	int n, i, j;
	scanf("%d", &n);
	int **count = malloc(sizeof(int *)*9);
	for(i = 0; i < 9; i++) {
		*(count + i) = malloc(sizeof(int)*9);
		for(j = 0; j < 9; j++)
			*(*(count + i) + j) = 0;
	}
	for(i = 1; i <= n; i++) {
		int head = gethead(i);
		int tail = gettail(i);
		if(head > 0 && tail > 0)
			(*(*(count + head - 1) + tail - 1))++;
	}
	int ans = 0;
	for(i = 0; i < 9; i++)
		for(j = 0; j < 9; j++)
			ans += (*(*(count + i) + j))*(*(*(count + j) + i));
	free(count);
	printf("%d\n", ans);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  string output = "Three";
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (S == "Y") {
      output = "Four";
      break;
    }
  }
  cout << output << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

string s;

map <char,int> mp;

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	cin >> s;
	for (int i = 0; i < s.size(); ++i)
		mp[s[i]]++;

	for (auto i : mp)
		if(i.second != 2)
		{
			cout << "No" << endl;
			return 0;
		}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    vector<ll> x;
    REP(i, N+1){
        if(i%3 != 0 && i%5 != 0){
            x.push_back(i);
        }
    }
    
    ll ans = 0;
    REP(i, SIZE(x)){
        ans += x[i];
    }
    cout << ans << endl;
}

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

using namespace std;

using ll = long long int;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	string s;
	cin >> s;

	int res = 0;
	for (auto c : s) {
		if (c == '1') {
			res++;
		}
	}

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


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

MOD = 10 ** 9 + 7

X = 0

for i in range(N):
    for j in range(i+1,N):
        if A[i] > A[j]:
            X += 1

Y = 0

for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            Y += 1

ans = (X * K + K*(K-1)//2 * Y) % MOD

print(ans)


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

int main(){
    string s; cin>>s;
    int q; cin>>q;
    int rev=0;
    string r="", l="";
    for (int i=0; i<q; i++){
        int t; cin>>t;
        if(t==1) rev++;
        else if(t==2){
            int f; cin>>f; char c; cin>>c;
            if((f+rev)%2==1) l=l+c;
            else if((f+rev)%2==0) r=r+c;
        }
    }
    if(rev%2==1){
        s = s+r;
        reverse(s.begin(), s.end());
        s = s+l;
    }
    else{
        reverse(l.begin(), l.end());
        s = l + s + r;
    }
    cout << s << endl;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

ll c[3333];
int main()
{
	int n, k;
	cin >> n >> k;
	ll r, s, p;
	cin >> r >> s >> p;
	string a;
	cin >> a;
	string b(n, '*');
	vector<pair<ll, char> > v;
	v.pb(M(r, 's'));
	v.pb(M(s, 'p'));
	v.pb(M(p, 'r'));
	sort all(v);
	reverse all(v);
	for(auto it : v)
	{
		for(int i = 0; i < n; i ++)
		{
			if(a[i] == it.S)
			{
				if(i - k >= 0)
				{
					if(b[i - k] != it.S)	
						b[i] = it.S;
				 }
				 else
					b[i] = it.S;
			}
		}
	}
	c['s'] = r;
	c['p'] = s;
	c['r'] = p;
	ll ans = 0;
	for(int i = 0; i < n; i ++)
		if(b[i] != '*')
			ans += c[b[i]];
	cout << ans;


	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 512
class fenwick_tree:
    """
    区間の一点更新と，区間和の取得がO(log n)で可能なデータ構造
    1-indexedで実装
    """

    def __init__(self, N):
        self.size = N
        self.tree = [0] * (N+1)

    def sum_until(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & (-i)
        return s

    def sum_acc(self, i, j):
        """ [i,j] の和を返す """
        return self.sum_until(j) - self.sum_until(i-1)

    def add(self, i, x):
        if i <= 0:
            return
        while i <= self.size:
            self.tree[i] += x
            i += i & (-i)


def main():
    N, Q = (int(i) for i in input().split())
    C = [int(i) for i in input().split()]
    Query = [[] for _ in range(N+1)]
    for j in range(Q):
        le, ri = (int(i) for i in input().split())
        Query[ri].append((le, j))

    Query.append((-1, -1, -1))

    lastappend = [-1] * (N + 1)
    bit = fenwick_tree(N)
    ans = [0]*Q

    for i, a in enumerate(C, start=1):
        if lastappend[a] != -1:
            bit.add(lastappend[a], -1)
        lastappend[a] = i
        bit.add(i, 1)
        for (le, j) in Query[i]:
            ri = i
            ans[j] = bit.sum_acc(le, ri)

    print(*ans, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 203352
import sys
input = sys.stdin.readline

(n, k), (r, s, p), t = map(int, input().split()), map(int, input().split()), input()[:-1]
d, res = {'r': p, 's': r, 'p': s}, 0
for i in range(k):
    b = False
    for j in range(i, n, k):
        if i == j: res += d[t[j]]; b = False; continue
        if (t[j] != t[j-k]) | b: res += d[t[j]]; b = False
        else: b = True
print(res)

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n,T;
  cin >> n >> T;
  vector<pll> dish(n);
  REP(i,n){
    ll a,b;
    cin >> a >> b;
    dish[i] = make_pair(a,b);
  }
  vector<vector<bool>> DP(T+1,vector<bool>(n,false));
  vl scores(T+1,0);
  REP(t,T+1){
    //cout << "po" << endl;
    if(t==0){
      scores[t] = 0;
      continue;
    } else {
      scores[t] = scores[t-1];
    }

    ll candi = -1;
    REP(i,n){
    //cout << "yo" << endl;
      ll prev = t-dish[i].first;
      if(prev>=0 && !DP[prev][i] && scores[t]<scores[prev]+dish[i].second){
        candi = i;
        scores[t] = scores[prev]+dish[i].second;
      }
    }
    if(candi == -1) {
      REP(i,n) DP[t][i] = DP[t-1][i];
      continue;
    }
    REP(i,n) DP[t][i] = DP[t-dish[candi].first][i];
    DP[t][candi] = true;
  }
  //cout << "po" << endl;
  //REP(t,T+1){
  //  cout << t << ": ";
  //  REP(i,n) cout << (DP[t][i]?"1,":"0,");
  //  cout << "score = " << scores[t] << endl;
  //}
  ll ans = 0;
  ll additional = 0;
  REP(i,n){
    if(DP[T-1][i]){
      ans += dish[i].second;
    }else{
      CHMAX(additional,dish[i].second);
    }
  }
  ans += additional;

  ll cand = 0;
  REP(i,n){
    if(DP[T][i]){
      cand += dish[i].second;
    }
  }

  cout << max(ans,cand) << endl;
  return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

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

    const int W = 100, H = 40;
    const int WHITE = 0, BLACK = 1;
    vector<vector<int>> grid(H, vector<int>(W));

    for (int y=H/2; y<H; y++) {
        for (int x=0; x<W; x++) {
            grid[y][x] = BLACK;
        }
    }

    int A, B;
    cin >> A >> B;
    A--, B--;
    for (int y=0; y<H/2 && B; y+=2) {
        for (int x=0; x<W && B; x+=2) {
            grid[y][x] = BLACK;
            B--;
        }
    }

    for (int y=H-1; y>=H/2 && A; y-=2) {
        for (int x=0; x<W && A; x+=2) {
            grid[y][x] = WHITE;
            A--;
        }
    }

    cout << H << " " << W << endl;
    rep(y, H) {
        rep(x, W) {
            cout << ".#"[grid[y][x]];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;

int n;
int field[3][3];
int goal_i,di[4] = {1,-1,0,0};
int goal_j,dj[4] = {0,0,1,-1};
double ans;

typedef struct{
	int i,j,n;
}Info;

int getI(char x){
	return (x - 'A') / 3;
}

int getJ(char x){
	return (x - 'A') % 3;
}

void solve(queue<Info> q,int now,int before[3][3]){
	int sum[3][3];

	memset(sum,0,sizeof(sum));

	while(1){
		Info tmp = q.front();
		if(tmp.n >= now) break;
		q.pop();

		for(int k=0;k<4;k++){
			Info next;
			int ni = tmp.i + di[k];
			int nj = tmp.j + dj[k];

			if(ni<0 || ni>=3 || nj<0 || nj>=3 || field[ni][nj]==2){
				next.i = tmp.i;
				next.j = tmp.j;
			}
			else{
				next.i = ni;
				next.j = nj;
			}
			next.n = tmp.n + 1;

			if(sum[next.i][next.j] == 0){
				q.push(next);
			}
			sum[next.i][next.j] += before[tmp.i][tmp.j];
		}
	}

	if(now < n){
		solve(q,now+1,sum);
	}
	else{
		ans = sum[goal_i][goal_j] * pow(0.25,n);
	}
}

int main(void){
	char s,t,b;
	int sum[3][3];

	while(1){
		cin>>n;
		if(!n) break;

		cin>>s>>t>>b;

		memset(field,0,sizeof(field));
		memset(sum,0,sizeof(sum));

		goal_i = getI(t);
		goal_j = getJ(t);
		field[goal_i][goal_j] = 1;
		field[getI(b)][getJ(b)] = 2;
		sum[getI(s)][getJ(s)] = 1;
		ans = 0;
		Info tmp = {getI(s),getJ(s),0};
		queue<Info> q;
		q.push(tmp);

		solve(q,1,sum);
		printf("%.8lf\n",ans);
	}

  return 0;
}

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

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,k;
    cin>>n>>k;
    vector<ll> h(n);
    for(int i=0; i<n; i++){
        cin>>h[i];
    }
    sort(h.begin(),h.end());
    ll num = n-k;
    ll sum = 0;
    for(int i=0;i<num;i++){
        sum += h[i]; 
    }
    cout<< sum <<endl;
    return 0;
}

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

int main (){
	long x;
	cin >>x;
	string kq;
	long n=0;
	while (x){
		x-=1;
		kq += 'a' + x%26;
		x/=26;
		n++;
	}
	for (int i=n-1; i>=0; i--){
		cout <<kq[i];
}
	return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF=1000000000000000;
int A[100100];
signed main(){
  int N;
  cin>>N;
  for(int i=0;i<N;i++)A[i]=INF;
  int ans=0;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    int it=upper_bound(A,A+N,-a)-A;
    if(A[it]==INF)ans++;
    A[it]=-a;
  }
  cout<<ans<<endl;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int uf[100000];

struct point{
  int x;
  int y;
};

struct X{
  int x;
  int num;
  bool operator<(const struct X & right) const{
    return x<right.x;
  }
};

struct edge{
  int c;
  int s;
  int g;
  bool operator<(const struct edge & right) const{
    return c>right.c;
  }
};

int par(int a){
  if(uf[a]==a) return a;
  else return uf[a]=par(uf[a]);
}

void uni(int a,int b){
  a=par(a);
  b=par(b);
  if(a==b) return;
  uf[a]=uf[b];
  return;
}

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    uf[i]=i;
  }
  vector<struct point> town(n);
  vector<struct X> x(n),y(n);
  for(int i=0;i<n;i++){
    cin >> town[i].x >> town[i].y;
    x[i]={town[i].x,i};
    y[i]={town[i].y,i};
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  priority_queue<struct edge> que;
  for(int i=1;i<n;i++){
    que.push({x[i].x-x[i-1].x,x[i-1].num,x[i].num});
    que.push({y[i].x-y[i-1].x,y[i-1].num,y[i].num});
  }
  struct edge now;
  LL ans=0;
  while(!que.empty()){
    now = que.top();
    que.pop();
    if(par(now.s)!=par(now.g)){
      uni(now.s,now.g);
      ans+=now.c;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7668
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

vector<vl> g;
vl c, ans;
ll i = 0;
vb seen;

void dfs(ll j) {
  for(auto v : g[j]) {
    if(seen[v]) continue;
    seen[v] = true;
    dfs(v);
  }
  ans[j] = c[i];
  i++;
}

int main() {
  ll n;
  cin >> n;
  g = vector<vl>(n);
  rep(i, n - 1) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  c = vl(n);
  ans = vl(n);
  seen = vb(n, false);
  rep(i, n) cin >> c[i];
  sort(all(c));
  seen[0] = true;
  dfs(0);
  cout << accumulate(all(c), 0) - c[n - 1] << endl;
  rep(i, n) cout << ans[i] << ' ';
  cout << endl;
}

Measured memory_bytes: 1408
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter


val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val target = charArrayOf('M', 'A','R','C','H')
    val initialMap = mutableMapOf<Char, Long>()
    for (c in target) {
        initialMap[c] = 0
    }

    repeat(n) {
        val c = br.readLine()!!.first()
        if (c in target) {
            initialMap[c] = initialMap[c]!! + 1
        }
    }

    var ans = 0L
    for (i in target.indices) {
        for (j in i + 1 until target.size) {
            for (k in j + 1 until target.size) {
                ans += initialMap[target[i]]!! * initialMap[target[j]]!! * initialMap[target[k]]!!
            }
        }
    }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

using namespace std;

typedef short sho;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str; 
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 
typedef pair<ld,ld> pld;
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define STDIO
#define mp make_pair 
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define begin(x) (x).begin() 
#define end(x) (x).end()
#define rbegin(x) (x).rbegin()
#define rend(x) (x).rend()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front 
#define pb push_back
#define pp push
#define lb lower_bound 
#define ub upper_bound

inline void checkmin(int &x, int y){x = min(x, y);}
inline void checkmax(int &x, int y){x = max(x, y);}

const int maxn=1e5+10;

int n,m,x,y;

vector<int> edge[maxn];
int in[maxn],dp[maxn];

int main() {
	#ifndef STDIO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /* start code */
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
    	cin>>x>>y;
    	edge[x].pb(y);
    	in[y]++;
	}
	queue<int> que;
	for(int i=1;i<=n;i++)
	{
		if(in[i]==0)
		{
			que.pp(i);
		}
	}
	while(!que.empty())
	{
		int t=que.front();
		que.pop();
		for(auto i : edge[t])
		{
			checkmax(dp[i],dp[t]+1);
			in[i]--;
			if(!in[i])
			{
				que.pp(i);
			}
		}
	}
	cout<<*max_element(dp+1,dp+1+n)<<endl;
    /* end code */
	return 0;
}

Measured memory_bytes: 6528
from collections import Counter
C = Counter(input())
if ((C["N"] == 0 and C["S"] == 0) or (C["N"] != 0 and C["S"] != 0)) and ((C["W"] == 0 and C["E"] == 0) or (C["W"] != 0 and C["E"] != 0)):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1] * n

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
        else:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

n, m = map(int,input().split())
edges = []
for i in range(m):
    a,b = map(int,input().split())
    edges.append([a-1,b-1])

uf = UnionFind(n)
point = n*(n-1)//2
ans = []

while edges:
    ans.append(point)
    a, b = edges.pop()
    pa = uf.find(a)
    pb = uf.find(b)
    if not uf.same_check(pa, pb):
        point -= (uf.size[pa] * uf.size[pb])
    uf.union(a,b)
print(*ans[::-1],sep="\n")

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

int N;
vector<int> H, W;
string Area[4];

int d[1<<16];

int main(){
    cin >> N;
    H.resize(N); W.resize(N);
    for(int i=0; i<N; i++)
        cin >> H[i] >> W[i];
    
    vector<set<int>> edges(N);
    for(int k=0; k<N; k++){
        for(int h=-4; h<=4; h++){
            for(int w=-4; w<=4; w++){
                int t = 0;
                for(int i=0; i<H[k]; i++){
                    for(int j=0; j<W[k]; j++){
                        int nh = h+i;
                        int nw = w+j;
                        if(0<=nh && nh<4 && 0<=nw && nw<4){
                            t |= 1<<(4*nh + nw);
                        }
                    }
                }
                edges[k].insert(t);
            }
        }
    }
    
    int RGB[3] = {};
    for(int i=0; i<4; i++){
        cin >> Area[i];
        for(int j=0; j<4; j++){
            if(Area[i][j] == 'R')
                RGB[0] |= (1<<(4*i + j));
            if(Area[i][j] == 'G')
                RGB[1] |= (1<<(4*i + j));
            if(Area[i][j] == 'B')
                RGB[2] |= (1<<(4*i + j));
        }
    }
    
    queue<int> que;
    memset(d, -1, sizeof(d));
    d[0] = 0;
    que.push(0);
    
    while(!que.empty()){
        auto x = que.front(); que.pop();
        
        for(int i=0; i<N; i++){
            for(auto v: edges[i]){
                for(int j=0; j<3; j++){
                    int y = x;
                    for(int k=0; k<3; k++){
                        if(j == k){
                            y |= RGB[k] & v;
                        }else{
                            y &= ~(RGB[k] & v);
                        }
                    }
                    if (d[y] < 0){
                        que.push(y);
                        d[y] = d[x] + 1;
                    }
                }
            }
        }
    }
    
    cout << d[RGB[0] | RGB[1] | RGB[2]] << endl;
    
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    int train = A * N;
    int taxi = B;
    int ans = min(train, taxi);

    cout << ans << endl;
}


Measured memory_bytes: 256
from heapq import heappush, heappop

X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
P.sort(reverse=True)
Q = list(map(int, input().split()))
Q.sort(reverse=True)
R = list(map(int, input().split()))
R.sort(reverse=True)

ans = sum(P[:X]) + sum(Q[:Y])


apples = []
for p in P[:X]:
    heappush(apples, [p, 0])

for q in Q[:Y]:
    heappush(apples, [q, 1])

for r in R:
    amin, rg = heappop(apples)
    if r >= amin:
        heappush(apples, [r, rg])
        ans += (r - amin)
    else:
        break

print(ans)

Measured memory_bytes: 34352
import java.util.*;

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

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		boolean flag = false;
		outside:for(int a=0;a<=N;a+=4){
			for(int b=0;b<=N;b+=7){
				if(a+b == N){
					flag = true;
					break outside;
				}
			}
		}

		if(flag) System.out.println("Yes");
		else System.out.println("No");

	}
}

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

int main()
{
  int N, dig=0;
  cin >> N;
  int a = N;
  while(a>0){
    a /= 10;
    dig ++;
  }
  int ans;
  if(dig == 2)
    ans = 9;
  else if(dig == 4)
    ans = 909;
  else if(dig == 1)
    ans = N;
  else if(dig == 3)
    ans = N - 90;
  else if(dig == 5)
    ans = N - 9090;
  else ans = 90909;
  cout << ans << endl;
  
  
}

Measured memory_bytes: 256
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

const int N = 1e6 + 10;
char s[N], t[N];
int main() {
  scanf("%s%s", s, t);
  int n = strlen(s);
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    ret += (s[i] != t[i]);
  }
  printf("%d\n", ret);
  return 0;
}


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

int main()
{
	int N;
	cin >> N;
	for (int i = 0; i <= N; i++) if (i * 27 / 25 == N) {
		cout << i << endl;
		return 0;
	}
	cout << ":(" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastio;
    int a, b;
    cin >> a >> b;
    cout << (((a + b) * 10 / 2) + 5) / 10 << endl;
}

Measured memory_bytes: 3604
# coding: utf-8
N = int(input())
X = [int(i) for i in input().split()]

X.sort()
s1 = sum([(X[i] - 1)**2 for i in range(N)])

c = 2
while c <= max(X):
    s2 = sum([(X[i] - c)**2 for i in range(N)])
    if s2 < s1:
        s1 = s2
    c += 1
print(s1)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int N = 1e5+5;
int n, a[N];
vector<int>vp;
ll cnt[N];
int b[N];
int bit[N+N];
void upd(int x, int v){
  for(int i = x + 1; i < N + N; i += i & -i)
    bit[i] += v;
}
int get(int x){
  int ret = 0;
  for(int i = x + 1; i; i -= i & -i)
    ret += bit[i];
  return ret;
}
ll getCnt(ll limit){
  memset(bit,0,sizeof bit);
  for(int i = 0; i < n; i++){
    if(a[i] <= limit)b[i] = 1;
    else b[i] = -1;
  }
  int cur = 0;
  upd(N, 1);
  ll ret = 0;
  for(int i = 0; i < n; i++){
    cur += b[i];
    /// cur >= x
    /// cur-1 >= x
//    cout << cur+N-1 << '\n';
    ret += get(cur+N-1);
//    if(limit == 0){
//      cout << i << ' ' << cur << ' ' << ret << '\n';
//    }
    upd(cur+N,1);
  }

  return ret;
}
int main(){

  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", a + i);
    vp.push_back(a[i]);
  }

  sort(vp.begin(),vp.end());  vp.resize(unique(vp.begin(),vp.end())-vp.begin());

  for(int i = 0; i < n; i++){
    a[i] = lower_bound(vp.begin(),vp.end(),a[i]) - vp.begin();
  }

  ll segments = n * 1ll * (n + 1) / 2;

  int lo = 0, hi = vp.size()-1;

//  cout << getCnt(0) << '\n';

  while(lo < hi){

    int md = lo + (hi-lo)/2;

    if(getCnt(md) >= segments/2 + 1)
      hi=md;
    else
      lo=md+1;


  }

  cout << vp[lo] << '\n';








}


Measured memory_bytes: 2296
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#define rep(i, n) for (int i=0; i<n; i++)
#define ll long long
using namespace std;

int main() {
  int n; cin>>n;
  map<string, int> m;
  rep(i, n) {
    string s; cin>>s;
    m[s]++;
  }
  int res=m.size();
  cout<<res<<endl;
}


Measured memory_bytes: 19224
N = int(input())
TT = [[0]*10 for i in range(10)]

for i in range(N+1):
    top = int(str(i)[0])
    tail = int(str(i)[-1])
    TT[top][tail] += 1
#print(TT)
y = 0
for i in range(1,10):
    for j in range(1,10):
        y += TT[i][j]*TT[j][i]
print(y)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
#define all(obj) obj.begin(), obj.end()
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);

using namespace std;

typedef unsigned long long ull;
typedef int long long ll;
constexpr ll bigNum = 1000000007;

signed main()
{
    fast;
    int n = 0;
    cin >> n;
    vector<int> b(n - 1);
    REP(i, n - 1)
    cin >> b[i];

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <climits>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for(int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for(int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
typedef long long int ll;
typedef unsigned long long int  ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main(){

    int N; cin >> N;
    int MAX = 55555;

    vector<int> primes;
    vector<int> __primes;
    primes.push_back(2);

    for(int i = 3; i <= MAX; i+=2) {
        bool isfound = false;
        for(int j = 0; j < primes.size(); ++j) {
            if ((i % primes[j]) == 0) {
                isfound = true;
                break;
            }
        }
        if (!isfound) primes.push_back(i);
    }

    // int c = 0;
    REP(i, primes.size()){
        if (primes[i] % 5 == 1) {
            __primes.push_back(primes[i]);
            // cout << c++ << " " << primes[i] << endl;
        }
        // cout << i << " " << primes[i] << endl;
    }

    REP(i, N) cout << __primes[i] << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1);
using namespace std;

int n, l, arr[201], mn = 1e9, ans, sm;
int main() {
    IOS
    cin >> n >> l;
    for (int i = 0; i < n; ++i) {
        arr[i] = l+i;
        sm += arr[i];
    }
    for (int i = 0; i < n; ++i) {
        if (abs(sm - (sm-arr[i]))<mn) {
            mn = abs(sm-(sm-arr[i]));
            ans = sm-arr[i];
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;

vector<int> cost(1000000);
vector<vector<int>> data(1000000);


int main(){
    int N, answer = 0;
    cin >> N;
    for(int i = 1; i <= N; i++){
        int a;
        cin >> a;
        if(i % 2 == 1 && a % 2 == 1){
            answer++;
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 30528
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}


int main(void){
    int n, m;
    scanf("%d %d", &n, &m);
    printf("%d\n", (n-1)*(m-1));
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    X = Scanner.int()
    L = [(0, 0) for _ in range(1000)]
    for i in range(0, 1000):
        L[i] = (i, i ** 5)
    for l1 in L:
        for l2 in L:
            a, b = l1[1], l2[1]
            c, d = l1[0], l2[0]
            if a < b:
                continue
            if a - b == X:
                print(c, d)
                return
            elif a + b == X:
                print(c, -d)
                return


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 10732
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
ll mod=1000000007;

int main(){
    std::ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a*b,a-b));

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int n,k;
char s[200005];
bool v[200005];
int main(){
	scanf("%d%d%s",&n,&k,s);
	for(int i=0;i<n;++i)v[i]=s[i]=='A';
	int cur=0,t=0;
	while(k--)
	if(v[t]^cur)v[t]=cur;else cur^=1,t=(t+1==n)?0:t+1;
	for(int i=0;i<n;++i)
	putchar((v[(i+t)%n]^cur)?'A':'B');
	return 0;
}

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

#define lint long long

const int N = 16 ;
lint cost[N][N] ;
int n ;
lint subsetCost[1 << N] ;
lint dp[1 << N] ;

lint solve(int mask)
{
    if(__builtin_popcount(mask) == n) return 0;
    if(dp[mask] != -1) return dp[mask] ;
    lint sum = 0 ;

    vector < int > indices ; indices.clear();
    for(int i = 0; i < n; i++)
        if(!(mask & (1 << i)))
            indices.push_back(i);
    int sz = indices.size();

    for(int bitmask = 1; bitmask < (1 << sz); bitmask++)
    {
        int num = 0;
        for(int i = 0; i < sz; i++)
            if((1 << i) & bitmask)
                num += (1 << indices[i]);

        if(!(num & mask))
            sum = max(sum, subsetCost[num] + solve(mask | num));
    }
    return dp[mask] = sum ;
}

int main()
{
    cin >> n ; vector < int > subset ;
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> cost[i][j] ;

    for(int mask = 0; mask < (1 << n); mask++)
    {
        subset.clear();
        for(int i = 0; i < n; i++)
            if(mask & (1 << i))
                subset.push_back(i);
        lint c = 0 ;
        for(int x : subset)
            for(int y : subset)
                c += cost[x][y] ;
        subsetCost[mask] = c/2 ;
    }
    //cout << "DONE!" << endl ;
    dp[0] = 0;
    for(int mask = 1; mask < (1 << n); mask++)
    {
        lint sum = 0;
        vector < int > indices ; indices.clear();
        for(int i = 0; i < n; i++)
            if((mask & (1 << i)))
                indices.push_back(i);
        int sz = indices.size();

        for(int bitmask = 0; bitmask < (1 << sz); bitmask++)
        {
            int num = 0;
            for(int i = 0; i < sz; i++)
                if((1 << i) & bitmask)
                    num += (1 << indices[i]);

            sum = max(sum, subsetCost[num] + dp[num^mask]);
        }
        dp[mask] = sum ;
    }
    //memset(dp, -1, sizeof(dp));
    cout << dp[(1 << n) - 1] ; // cout << solve(0);
}


Measured memory_bytes: 1280