akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)(1e9)+7)

bool is_prime(ull n){
	for(ull i=2; i*i<=n; i++){
		if(n%i==0) return false;
	}
	return true;
}

void make_prime(vector<ull> &prime){
	prime.push_back(2);
	for(ull i=3; i<=1000; i+=2){
		if(is_prime(i)) prime.push_back(i);
	}
}

int main(){
	ull n;
	cin >> n;
	if(n==1){
		cout << 1 << endl;
		return 0;
	}
	vector<ull> prime;
	make_prime(prime);

	ull cnt[prime.size()];
	for(ull i=0; i<prime.size(); i++) cnt[i]=0;
	for(ull i=2; i<=n; i++){
		ull k=i;
		for(ull j=0; j<prime.size(); j++){
			while(k%prime[j]==0){
				cnt[j]++;
				k/=prime[j];
			}
		}
	}
	ull ans=1;
	for(int i=0; i<prime.size(); i++){
		ans*=cnt[i]+1;
		ans%=mod;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int n, S = 1;
  cin >> n;
  string s;
  cin >> s;
  char a = s[0];
  REP(i, n) {
    if(a != s[i]) {
      S++;
      a = s[i];
    }
  }
  cout << S << endl;
}

Measured memory_bytes: 3744
from sys import stdin
input = stdin.readline

# map(int, input().rstrip().split())

def VI(N, init=0):
  return [init for _ in range(N)]
def VVI(N, M, init=0):
  return [[init for _ in range(M)] for _ in range(N)]

def VD(N, init=0.0):
  return [init for _ in range(N)]
def VVD(N, M, init=0.0):
  return [[init for _ in range(M)] for _ in range(N)]

def Divisor(n):
  ret = []
  for i in range(1, n+1):
    if i*i > n:
      break
    else:
      if n % i == 0:
        ret.append(i)
        if i*i != n:
          ret.append(n//i)
  ret.sort()
  return ret

def digit(x):
  ret = 0
  while (x):
    x //= 10
    ret += 1
  return ret

N = int(input().rstrip())

divs = Divisor(N)

ans = int(1e18)
for div in divs:
  ddiv = N / div
  ans = min(ans, max(digit(div), digit(ddiv)))

print(ans)


Measured memory_bytes: 41328
/*
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
*/
#include <bits/stdc++.h>

#define rep(i,n)  for(int i=0; i<(n); i++)
using ll = long long;
using namespace std;

int main()
{
    int a,b,ans;
    cin >> a >> b;
    double max[2],min[2];
    max[0] = (a+1) / 0.08;
    min[0] = a / 0.08;

    max[1] = (b+1) / 0.1;
    min[1] = b / 0.1;

    if(min[0] <= min[1]){
      if(min[1] < max[0]){
        ans = ceil(min[1]);
      }else{
        ans = -1;
      }
    }else{
      if(min[0] < max[1]){
        ans = ceil(min[0]);
      }else{
        ans = -1;
      }
    }

    cout << ans;
    return 0;
}


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

void swap(int* a, int* b);

int main()
{
    int a,b,c;
    cin >> a >> b >> c;

    if(a>b) swap(&a,&b);
    if(a>c) swap(&a,&c);
    if(b>c) swap(&b,&c);

    cout << a << " " << b << " " << c << endl;
    return 0;
}

void swap(int* a, int* b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using v = vector<T>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

inline ll inl() {
    ll x;
    cin >> x;
    return x;
}

inline string ins() {
    string x;
    cin >> x;
    return x;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif

        ll n = inl();
        vl a(n);

        rep(i, n) cin >> a[i];
        vl d;

        rep(i, n) {
            auto itr = lower_bound(d.rbegin(), d.rend(), a[i]);
            if (itr == d.rbegin()) {
                d.eb(a[i]);
            } else {
                itr--;
                *itr = a[i];
            }
        }
        cout << d.size() << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#define LL long long
LL n;
int u = 0, v = 0;
vector <int> A, B;
int main()
{
    cin >> n; n ++;
    for (int i = 0; (1ll << i) <= n; ++ i)
        if ((1ll << i) & n)
            u ++;
    for (int i = 0; (1ll << (i + 1)) <= n; ++ i)
    {
        if ((1ll << i) & n)
            B.push_back(++ v);
        A.push_back(u + i);
        B.push_back(u + i);
    }
    cout << A.size() + B.size() + u - 1 << endl;
    for (int i = 1; i < u; ++ i) cout << i << " ";
    for (int i = A.size() - 1; ~i; -- i) cout << A[i] << " ";
    for (int i = B.size() - 1; ~i; -- i) cout << B[i] << " ";
}


Measured memory_bytes: 384
/*
貪欲
後ろから見る
DP
順位表をチェック
二分探索


*/
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include<tuple>
#include<set>
using namespace std;
#define INF 1100000000000000000
#define MAX 110000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
//typedef pair< pair<int,int>,pair<int,int> > p;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());


int main(){
    int N;
    string s0;
    cin>>N;
    cout<<0<<endl;
    cin>>s0;
    if(s0=="Vacant") return 0;
    int ng=0,ok=N,count=0;
    while(true){
        count++;
        if(count>20) return 1;
        int mid=(ng+ok)/2;
        cout<<mid<<endl;
        string s; cin>>s;
        if(s=="Vacant") return 0;
        if((mid%2==0 && s==s0) || (mid%2==1 && s!=s0)){
            ng=mid;
        }else ok=mid;
    }
}


Measured memory_bytes: 852
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int main()
{
	string a;
	cin>>a;
	long long int ans=1e18;
	int i,j;
	int lt;
	for(i='a';i<='z';i++)
	{
		lt=0;
		string b=a;
		for(j=0;j<b.size();j++)
			if(b[j]!=i)
			{
				lt=1;
				break;
			}
		if(!lt)
		{
			ans=0;
			break;
		}
		while(1)
		{
			lt=0;
			string d="";
			for(j=0;j<b.size()-1;j++)
			{
				if(b[j]==i||b[j+1]==i)
					d.pb(i);
				else
					d.pb(b[j]),lt++;
			}
			if(!lt)
			{
				ans=min(ans,(long long int)a.size()-(long long int)d.size());
				break;
			}
			else if(lt==b.size()-1||d==b)
				break;
			b=d;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll N, K;
    cin >> N >> K;
    ll count{0};
    ll c{0};
    for (auto &&b: irange(max(K, 1LL), N+1)){
        count += (b-K) * (N/b) + max(0LL, N % b - K + 1);
    }
    if (K==0LL){
        count = count - N;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
// #define mod 998244353
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, x;
	cin >> n >> x;
	ll a[n + 1];
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	ll ans = 0;
	if (a[1] > x)
	{
		ans += a[1] - x;
		a[1] = x;
	}
	for (int i = 2; i <= n; i++)
	{
		if (a[i] + a[i - 1] <= x)
		{
			continue;
		}
		ll dec = a[i] + a[i - 1] - x;
		a[i] -= dec;
		ans += dec;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
#define inf 0x3f3f3f3f
#define ll long long
int main() 
{
	int n;
	cin>>n;
	int mn=inf,mx=0;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		mn=min(mn,x);
		mx=max(mx,x);
	}
	cout<<mx-mn<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long plusCardNum = Long.parseLong(sc.next());
		long zeroCardNum = Long.parseLong(sc.next());
		long minusCardNum = Long.parseLong(sc.next());
		long chooseCardNum = Long.parseLong(sc.next());

		//
		if (chooseCardNum <= plusCardNum) {
			System.out.println(chooseCardNum);
		} else if (chooseCardNum <= plusCardNum + zeroCardNum) {
			System.out.println(plusCardNum);
		} else {
			System.out.println(plusCardNum - (chooseCardNum - plusCardNum - zeroCardNum));
		}

	}

}


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

using namespace std;

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

vector<vi> e;
int v[100000];
void rec(int c, int col, bool &bi, int &x, int &y){
	if(col > 0) x++; else y++;
	v[c] = col;
	for(int i : e[c]){
		if(v[i]){
			if(v[i] == col) bi = 0;
		}
		else rec(i, -col, bi, x, y);
	}
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, m; cin >> n >> m;
	e.resize(n);
	rep(i, m){
		int a, b; cin >> a >> b; a--; b--;
		e[a].pb(b);
		e[b].pb(a);
	}
	vector<pi> bigraph;
	vi graph;
	int point = 0;
	
	rep(i, n) if(!v[i]){
		bool bi = 1;
		int x = 0, y = 0;
		rec(i, 1, bi, x, y);
		if(bi){
			if(x + y == 1) point++;
			else bigraph.emplace_back(x, y);
		}
		else graph.pb(x + y);
	}
	//dbg(bigraph);dbg(graph);dbg(point);
	
	ll ans = 0;
	for(pi a : bigraph){
		/*
		for(pi b : bigraph){
			ans += 2;
		}
		for(int b : graph){
			ans++;
		}*/
		ans += bigraph.size() * 2;
		ans += graph.size();
		ans += (ll)point * (a.first + a.second);
	}
	dbg(ans);
	for(int a : graph){
		/*
		for(pi b : bigraph){
			ans++;
		}
		for(int b : graph){
			ans++;
		}*/
		ans += bigraph.size();
		ans += graph.size();
		ans += (ll)point * a;
	}
	dbg(ans);
	{
		for(pi b : bigraph){
			ans += (ll)point * (b.first + b.second);
		}
		for(int b : graph){
			ans += (ll)point * b;
		}
		ans += (ll)point * point;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11776
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map>       // pair
#include <string>
#include <stdio.h>
using namespace std;

int main(int argc, const char *argv[])
{   
    string str;
    cin>>str;
    int N = str.size();

    int count = 0;

    for(int i = 0; i < N ; i ++)
    {
        if( i % 2 == 0)
        {
            if(str[i] == '1')
            {
                count ++;
            }
        }
        else
        {
            if(str[i] == '0')
            {
                count++;
            }
        }
    }
    cout<<min(count,N - count);


    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

char s[110];
int cnt[256];

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  int n;
  scanf("%d%s", &n, s + 1);
  for (int i = 1; i<= n; ++i)
    ++cnt[s[i]];
  puts(cnt['R'] > cnt['B'] ? "Yes" : "No");

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 256
/*==============================================*\
ID:          shahidul_brur

Name:     Md. Shahidul Islam
Study:      CSE, BRUR
Address:  Rangpur, Bangladesh

 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com(in Bengali),
       shahidul-brur-en.blogspot.com(in English)
\*===============================================*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = (int)1e9+7;
const int MAX = 1000002;
const int logn = 20;
bool v[MAX];
int len, sp[MAX], a[MAX];

void Sieve(){
	for (int i = 2; i < MAX; i += 2)	sp[i] = 2;//even numbers have smallest prime factor 2
	for (ll i = 3; i < MAX; i += 2){
		if (!v[i]){
			sp[i] = i;
			for (ll j = i; (j*i) < MAX; j += 2){
				if (!v[j*i])	v[j*i] = true, sp[j*i] = i;
			}
		}
	}
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
//    freopen("in_a.txt", "r", stdin);
//    freopen("out_a.txt", "w", stdout);
    Sieve();
    int n; cin>>n;
    set<int> s;
    bool pairwise = 1;
    f0(i,n)
    {
        cin>>a[i];
        int x = a[i];
        while(x!=1){
            int p = sp[x];
            if(s.count(p)){
                pairwise = 0;
                break;
            }
            s.insert(p);
            while(x%p==0) x/=p;
        }
    }
    if(pairwise){
        cout << "pairwise coprime\n";
        return 0;
    }
    int g = a[0];
    f1(i,n-1) {
        g =__gcd(g,a[i]);
    }
    if(g==1) cout << "setwise coprime\n";
    else cout << "not coprime\n";
    return 0;
}


Measured memory_bytes: 16028
#include <iostream>
#include <iterator>
#include <cstdio>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <chrono>
#include <functional>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No")
	{
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	int ncr(int left, int right)
	{
		right = min(left - right, right);
		int ans = 1;
		for (int i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000256;
	const int tenfive = 100100;
}

using namespace atcoder;

int main()
{
	int a, b;
	cin >> a >> b;
	judge_outer(!(a % 2 == 0 || b % 2 == 0));
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int L, R, d, i, count = 0;
	scanf("%d", &L);
	scanf("%d", &R);
	scanf("%d", &d);

	for(i = L; i <= R; i++)
	{
		if(i % d == 0)
		{
			count++;
		}
	}

	printf("%d", count);
}

Measured memory_bytes: 1732
import math
n = int(input())
def prime(i):
    if i < 2:
        return False
    for j in range(2,int(math.sqrt(i))+1):
        if i % j == 0:
            return False
    return True

ans = []
for i in range(11,55556,10):
    if prime(i):
        ans.append(i)
        n -= 1
    if n == 0:
        break
print(*ans)


Measured memory_bytes: 3060
N,L = map(int,input().split())
S = [input() for i in range(N)]

S.sort()
print("".join(S))
# 文字列にもsortが使える。デフォルトでは辞書順で昇順となる
# [dxx,axx,cxx]⇒[axx,cxx,dxx]

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		String s[] = sc.next().split("");
		String s1 = "";
		String s2 = "";
		
		
		for (int i = 0 ; i < n ; i++ ) {
			if(i < n/2) {
				s1 += s[i];
			}else {
				s2 += s[i];
			}
			
		}
		
		String ans = "No";
		
		if(s1.equals(s2)) {
			ans = "Yes";
		}
		
		System.out.println(ans);

	}

}

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

#define pb push_back
#define fi first
#define SZ(x) (int((x).size()))
#define se second
#define ll long long
#define pq priority_queue
#define MP make_pair
#define pii pair<int,int>
#define mod 998244353
#define debug(x) cerr<<#x<<"="<<x<<'\n'

const int maxn=3010;

int n,s;
int a[maxn];
int f[maxn][maxn][2];
ll ans=0;

int main(){
	scanf("%d%d",&n,&s);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) 
		for (int j=1;j<=s;j++) {
			f[i][j][0]=f[i-1][j][0];
			if (j>=a[i]) f[i][j][1]=f[i-1][j-a[i]][0];
			if (j==a[i]) f[i][j][1]=((ll)f[i][j][1]+(ll)i)%mod;
			(f[i][j][0]+=f[i][j][1])%=mod;
			if (j==s) ans=((ll)ans+(ll)f[i][j][1]*(ll)(n-i+1))%mod;
		}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 70784
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)1e9+7)
#define MAX ((ull)1e6)

ull pow3(ull n){
	return n*n*n;
}

int main(){
	ull n, k;
	cin >> n >> k;
	if(k%2==1) cout << pow3(n/k) << endl;
	else{
		ull m=n/(k/2);
		cout << pow3(m/2)+pow3((m+1)/2) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
s = input()
e = int(s.count('E'))
ans = e

a = 0
for i in range(n):
    if s[i] == 'W':
        a += 1
    b = e - ((i+1)-a)
    ans = min(ans, a+b)


print(ans)

Measured memory_bytes: 72256
n, k = map(int, input().split())
tel = list(map(int, input().split()))
log = [1]
record = [0] * n
while(True):
    log.append(tel[log[-1] - 1])
    if(record[log[-1] - 1] == 1):
        break
    record[log[-1] - 1] += 1
for i in range(len(log) - 1):
    if(log[i] == log[-1]):
        star = i
        mod = len(log) - star - 1
        break
if(k < len(log)):
    print(log[k])
else:
    print(log[(k - star) % mod + star])

Measured memory_bytes: 95248
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

std::string s;
int32_t N;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> s;
	in >> N;

	for (int32_t i = 0; i < s.size(); i+=N)
	{
		out << s[i];
	}
	out << endl;

	return 0;
}
#endif


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

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

  int ct = 1;
  for(int i=0; i<n-1; i++){
    if(s[i]!=s[i+1]){
      ct++;
    }
  }
  
  cout << ct << endl;
  return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

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

int h, w;
char b[444][444];
int group[444][444];

int rec(int y, int x, int g) {
  group[y][x] = g;

  int ans = 0;
  rep (i, 4) {
    int ny = y + dy[i], nx = x + dx[i];
    if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
    if (b[y][x] == b[ny][nx]) continue;
    if (group[ny][nx] != 0) continue;
    int cost = (b[ny][nx] == '.' ? 1 : 0);
    ans += rec(ny, nx, g) + cost;
  }

  return ans;
}

signed main() {
  cin >> h >> w;
  rep (i, h) {
    cin >> b[i];
  }

  int ans = 0;
  int cnt = 1;
  map<int, int> mp;
  rep (i, h) {
    rep (j, w) {
      if (b[i][j] == '#') {
        if (group[i][j] == 0) {
          int t = rec(i, j, cnt);
          ans += t;
          mp[cnt] = t;
          cnt++;
        } else {
          ans += mp[group[i][j]];
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 14336
A, B = list(map(int, input().split()))
res = 0


def is_palindoromic(num):
    tmp = str(num)
    n_len = len(tmp) // 2
    length = len(tmp)
    for i in range(n_len):
        if tmp[i] != tmp[length - i - 1]:
            return False
    return True


for i in range(A, B + 1):
    if is_palindoromic(i):
        res += 1

print(res)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 100005;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global */
vector<vector<int> > G(MAX, vector<int>());
int N, M;
/* function */
void bfs(int st) {
    queue<int> q;
    q.push(st);
    vector<int> visited(N, NIL);
    vector<int> road(N, NIL);
    visited[st] = 0;
    while (!q.empty()) {
        int from = q.front();
        q.pop();
        for (int to : G[from]) {
            if (visited[to] != NIL) continue;
            road[to] = from;
            visited[to] = visited[from] + 1;
            q.push(to);
        }
    }

    cout << "Yes" << '\n';
    for (int i = 1; i < N; i++) cout << road[i] + 1 << '\n';
}
/* main */
int main() {
    cin >> N >> M;
    int a, b;
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b); G[b].push_back(a);
    }
    bfs(0);
}

Measured memory_bytes: 10572
# -*- coding: utf-8 -*-

N = int(input())
T, A = map(int, input().split())
Hs = list(map(int, input().split()))


def kion_sa(x):
    return abs((T - x * 0.006) - A)


kionsa_list = list()
for i, x in enumerate(Hs):
    kionsa_list.append((kion_sa(x), i))

kionsa_list.sort()
print(kionsa_list[0][1]+1)


Measured memory_bytes: 3188
#include<stdio.h>
int main(void){
    char s[2];

    scanf("%s",&s); 
    if(s[0]=='9'||s[1]=='9'){       //９（値）ではなく’９’（文字）で表記
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;    
}

Measured memory_bytes: 128
#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 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int A, B;
  cin >> A;
  cin >> B;
  if(B*2>=A){
    cout << 0 << endl;
  } else {
    cout << A-2*B << endl;
  }
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<algorithm>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define For(i,x,y) for(int i=((int)x);i<=((int)y);i++)
#define Dep(i,y,x) for(int i=((int)y);i>=((int)x);i--)
#define Rep(i,x) for (int y,i=head[x];i;i=E[i].nxt)
using namespace std;

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

int rd() {
	char c=getchar(); int t=0,f=1;
	while (!isdigit(c)) f=(c=='-')?-1:1,c=getchar();
	while (isdigit(c)) t=t*10+c-48,c=getchar(); return t*f;
}
void wt(int x) {
	if (x<0) putchar('-'),wt(-x);
	else { if (x>9) wt(x/10); putchar(x%10+48); }
}

const int N=200035;

ll n,K,hs[N],a[N],ans,c[N];

int ask(int x) {
	int t=0;
	for (;x;x-=x&-x) t+=c[x];
	return t;
}

void add(int x) {
	for (;x<N;x+=x&-x) c[x]++;
}

int main() {
	n=rd(),K=rd();
	For (i,1,n) a[i]=hs[i]=rd()-K+a[i-1];
	sort(hs,hs+n+1);
	For (i,0,n) a[i]=lower_bound(hs,hs+n+1,a[i])-hs+1;
	For (i,0,n) {
		ans+=ask(a[i]);
		add(a[i]);
	}
	printf("%lld\n",ans);
	return 0;
}






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

int main(){
  int N,K,Q;
  cin >> N >> K >> Q;
  vector<int> A(Q);
  for(int i=0;i<Q;i++){
    cin >>A[i];
  }
  vector<int>ans(N,(K-Q));
  for(int i=0;i<Q;i++){
    ans[A[i]-1]++;
  }
  for(int i=0;i<N;i++){
    if(ans[i]>0){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  
}
      
    
      


Measured memory_bytes: 1408
// Problem : F - Bracket Sequencing
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

vector<pii> dod, uje;

bool cmp(pii& p1, pii& p2) {
	return p1.st - p1.nd < p2.st - p2.nd;
	// if (p1.st == p2.st) {
	// 	return p1.nd > p2.nd;
	// }
	// return p1.st < p2.st;
}

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
    int all = 0;
	cin >> n;
	REP(i, n) {
		string s;
		cin >> s;
		int ile = 0, mn = 0;
		for (auto x: s) {
			if (x == ')') {
				ile--;
				mn = min(mn, ile);
			} else {
				ile++;
			}
		}
        all += ile;
		if (ile >= 0) {
			dod.pb({mn, ile});
		} else {
			uje.pb({mn, ile});
		}
	}
    if (all != 0) {
      cout << "No\n";
      return 0;
    }
	sort(dod.begin(), dod.end(), greater<pii>());
	sort(uje.begin(), uje.end(), cmp);
	int sum = 0;
	for (auto x:dod) {
		if (sum + x.st < 0) {
			cout << "No";
			return 0;
		}
		sum += x.nd;
		//cout << sum << endl;
	}
	for (auto x: uje) {
		//cout << x.st << " " << x.nd << endl;
		if (sum + x.st < 0) {
			cout << "No";
			return 0;
		}
		sum += x.nd;
	//	cout << sum << endl;
	}
	if (sum != 0) cout << "No\n";
	else cout << "Yes\n";
	return 0;
}
 


Measured memory_bytes: 11328
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#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 MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#pragma endregion

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N; cin >> N;
    VI w(N);
    ll sum = 0;
    REP(i, N) {
        cin >> w[i];
        sum += w[i];
    }
    ll total = 0;
    ll ans = INF;
    REP(i, N) {
        total += w[i];
        ans = min(ans, abs(sum - total - total));
    }
    cout << ans << endl;
    getchar(); getchar();
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <stack>
#include <string>
#include <utility>
#include <vector>

class Info {
  public:
    int n;
    bool is_end;
    int children[26];
    int step, link;
    Info(int n = 0) {
      this->n = n;
      is_end = false;
      for (int i = 0; i < 26; ++i) {
        children[i] = -1;
      }
      step = 0;
      link = -1;
    }
};

int main() {
  int n, q, k;
  char sin[400001];
  std::string s[100000];
  std::string p;
  std::vector<Info> trie;
  std::stack<int> st;
  trie.push_back(Info());
  st.push(0);
  std::scanf("%d", &n);
  for (int ni = 0; ni < n; ++ni) {
    int ptr = 0;
    std::scanf("%s", sin);
    s[ni] = sin;
    for (char c : s[ni]) {
      if (trie[ptr].children[c - 'a'] < 0) {
        trie[ptr].children[c - 'a'] = trie.size();
        st.push(trie.size());
        trie.push_back(Info());
      }
      ++trie[ptr].n;
      ptr = trie[ptr].children[c - 'a'];
    }
    ++trie[ptr].n;
    trie[ptr].is_end = true;
  }
  while (not st.empty()) {
    int id = st.top();
    st.pop();
    if (not trie[id].is_end) {
      int num = 0;
      int one;
      for (int i = 0; i < 26; ++i) {
        int x = trie[id].children[i];
        if (x >= 0) {
          ++num;
          one = x;
        }
      }
      if (num == 1) {
        if (trie[one].link < 0) {
          trie[id].step = 0;
          trie[id].link = one;
        } else {
          trie[id].step = 1 + trie[one].step;
          trie[id].link = trie[one].link;
        }
      }
    }
  }
  std::scanf("%d", &q);
  for (int qi = 0; qi < q; ++qi) {
    int ans = 1;
    int idx[26];
    int ptr = 0;
    std::scanf("%d%s", &k, sin);
    p = sin;
    for (int i = 0; i < 26; ++i) {
      idx[p[i] - 'a'] = i;
    }
    for (std::size_t pos = 0; pos < s[k - 1].length(); ++pos) {
      char c = s[k - 1][pos];
      int end = idx[c - 'a'];
      for (int i = 0; i < end; ++i) {
        int cid = trie[ptr].children[p[i] - 'a'];
        if (cid >= 0) {
          ans += trie[cid].n;
        }
      }
      if (trie[ptr].is_end) {
        ++ans;
      }
      if (trie[ptr].link < 0) {
        ptr = trie[ptr].children[c - 'a'];
      } else {
        pos += trie[ptr].step;
        ptr = trie[ptr].link;
      }
    }
    std::printf("%d\n", ans);
  }
  return 0;
}

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

#define BUF_SIZE 10

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

#define VMAX 8

char used[VMAX];
int p[VMAX+1];
static char table[VMAX+1][VMAX+1];

void perm1(int *arr, int pos, int size, int *ans) {
    int i;
    if(pos == size) {
        int flag = 1;
#ifdef DEBUG
        for(i = 0; i < size; i++) {
            printf("%d ", arr[p[i]]);
        }
        putchar('\n');
#endif
        if(arr[p[0]] != 1) return;
        for(i = 0; i < size-1; i++) {
            int cur = arr[p[i]];
            int next = arr[p[i+1]];
            if(!table[cur][next]) {
                flag = 0;
                break;
            }
        }
        if(flag) {
            (*ans)++;
        }
        return;
    }
    for(i = 0; i < size; i++) {
        if(used[i]) continue;
        used[i] = 1;
        p[pos] = i;
        perm1(arr, pos+1, size, ans);
        used[i] = 0;
    }
    return;
}

int perm(int size) {
    int arr[] = {1,2,3,4,5,6,7,8};
    int ans = 0;
    perm1(arr, 0, size, &ans);
    return ans;
}

int main(void) {
    int vs, es;
    get_int2(&vs, &es);

    int i;
    for(i = 0; i < es; i++) {
        int v1, v2;
        get_int2(&v1, &v2);
        table[v1][v2] = table[v2][v1] = 1;
    }

    int ans = perm(vs);
    printf("%d\n", ans);
    return 0;
}

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

int main(){
    double df = 1e9;
    double n, t, a;
    int ans;
    cin >> n >> t >> a;
    for(int i=0; i<n; i++){
        double h;
        cin >> h;
        if(df > abs(a - (t - h * 0.006))){
            ans = i+1;
            df = abs(a - (t - h * 0.006));
            }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def primeFactorization(n):
    ans = []
    temp = n
    while temp%2 == 0:
        ans.append(2)
        temp //= 2
    for i in range(3, int(n**0.5)+1, 2):
        while temp%i == 0:
            ans.append(i)
            temp //= i
    if temp > 1:
        ans.append(temp)
    return collections.Counter(ans)

def resolve():
    N = I()

    # N!の素因数を求める
    pf_N_fact = collections.Counter()
    for i in range(1, N + 1):
        pf = primeFactorization(i)
        for k, v in pf.items():
            pf_N_fact[k] += v
    l = list(pf_N_fact.values())
    l.sort()
    pf_num = len(pf_N_fact)

    # 約数75個: 素因数の個数+1の積が75になるように組み合わせる
    # 素因数の個数を以下の組み合わせで何通り取れるかを調べる
    # (2, 4, 4), (2, 24), (4, 14), (74)
    ans = 0
    num_2 = pf_num - bisect.bisect_left(l, 2)
    num_4 = pf_num - bisect.bisect_left(l, 4)
    num_14 = pf_num - bisect.bisect_left(l, 14)
    num_24 = pf_num - bisect.bisect_left(l, 24)
    num_74 = pf_num - bisect.bisect_left(l, 74)
    ans += num_4 * (num_4 - 1) // 2 * max(num_2 - 2, 0)
    ans += num_24 * max(num_2 - 1, 0)
    ans += num_14 * max(num_4 - 1, 0)
    ans += num_74
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10388
#include <stdio.h>

int main(void) {

    int i, x;
    int n;

    scanf("%d", &n);

    for (i = 1; i <= n; i++) {
        if (i % 3 == 0) {
            printf(" %d", i);
        } else {
            x = i;
            while (x) {
                if (x % 10 == 3) {
                    printf(" %d", i);
                    break;
                }
                x /= 10;
            }
        }
    }
    printf("\n");

    return 0;

}

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

using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define forn(i, n) for (int i = 0; i < n; i++)
#define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in)
#define rforn(i, n) for (int i = n; i >= 0; i--)
#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>()
const double pi = acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int, int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int search;
    cin >> search;
    
    bool done = false;
    for (int i = 1; i < 10 && !done; i++)
    {
        if (search % i == 0 && (search / i) <= 9)
        {
            done = true;
        }
    }
    if (done)
    {
        cout << "Yes" << "\n";
    }
    else
    {
        cout << "No\n";
    }

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

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

	char flag[1005][1005];
	int cnt[1005][1005][3];
	int cnt2[1005][1005];
	int ans = 0;

	for (int i = 0;i < m;i++){
		for (int j = 0;j < n;j++){
			cin >> flag[i][j];
			cnt2[i][j] = 0;
			for (int k = 0;k < 3;k++){
				cnt[i][j][k] = 0;
			}
		}
	}

	char sq[2][2];

	for (int i = 0;i < 2;i++){
		for (int j = 0;j < 2;j++){
			cin >> sq[i][j];
		}
	}

	for (int i = 0;i < m-1;i++){
		for (int j = 0;j < n-1;j++){
			int c = 0;
			int tmp1,tmp2;
			for (int k = 0;k < 2;k++){
				for (int l = 0;l < 2;l++){
					if(flag[i+k][j+l] == sq[k][l]){
						c++;
					} else {
						tmp1 = i+k; tmp2 = j+l;
					}
				}
			}
			if(c == 3){
				if(sq[tmp1-i][tmp2-j] == 'J') cnt[tmp1][tmp2][0]++;
				if(sq[tmp1-i][tmp2-j] == 'O') cnt[tmp1][tmp2][1]++;
				if(sq[tmp1-i][tmp2-j] == 'I') cnt[tmp1][tmp2][2]++;
			}
			if(c == 4){
				cnt2[i][j]++; cnt2[i+1][j]++; cnt2[i][j+1]++; cnt2[i+1][j+1]++;
				ans++;
			}
		}
	}

	int MAX = 0;

	for (int i = 0;i < m;i++){
		for (int j = 0;j < n;j++){
			for (int k = 0;k < 3;k++){
				MAX = max(MAX, cnt[i][j][k]-cnt2[i][j]);
			}
		}
	}

	cout << ans+MAX << endl;

	return 0;

}



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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

ll pla = 0;
ll ans = 0;
ll n,x;
ll mp[55];
ll pa[55];
bool flag;

void seica(){
	if(!flag){
		cout << ans << endl;
	}
	flag = true;
}

void dfs(int depth){
	pla++;
	if(pla >= x){
		seica();
		return;
	}
	if(depth == 0 || x - pla >= mp[depth-1]){
		pla += mp[depth-1];
		ans += pa[depth-1];
	}
	else{
		dfs(depth - 1);
	}
	if(pla >= x){
		seica();
		return;
	}
	pla++;
	ans++;
	if(pla >= x){
		seica();
		return;
	}
	if(depth == 0 || x - pla >= mp[depth-1]){
		pla += mp[depth-1];
		ans += pa[depth-1];
	}
	else{
		dfs(depth - 1);
	}
	if(pla >= x){
		seica();
		return;
	}
	pla++;
	if(pla >= x){
		seica();
		return;
	}
}

int main(){

	mp[0] = 1;
	pa[0] = 1;
	REP(i,54){
		mp[i+1] = mp[i] * 2 + 3;
		pa[i+1] = pa[i] * 2 + 1;
	}

	cin >> n >> x;
	dfs(n);

	return 0;
}


Measured memory_bytes: 256
d = [_ for _ in input().split()]

commands = input()

for c in commands:
  if c == 'E':
    d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2]
  elif c == 'W':
    d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3]
  elif c == 'N':
    d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4]
  elif c == 'S':
    d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1]

print(d[0])

Measured memory_bytes: 7536
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

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

#define REPI(i, a, b) for (int(i) = int(a); (i) < int(b); ++(i))

using namespace std;

int main()
{
    int Z;           //入力待ち
    int j, k;        //for文用
    string to = ","; //デバッグ用
    int e_count = 0; //演算回数を数える
    int count = 0;   //よくあるカウント
    //----------

    int n;
    cin >> n; //最大で10000
    int a, b;
    cin >> a >> b;

    int wa = 0;
    REP(i, n + 1) //1から"Nまで"探す
    {
        //各桁を取り出して和をとる
        string str = to_string(i);
        REP(ii, str.size())
        {
            //cout << str[ii] - '0' << endl;
            wa += str[ii] - '0';

            //cout << "wa=" << wa << endl;
        }

        //和が条件を満たしていたらカウント
        if (wa >= a && b >= wa)
        {
            //cout << "満たしている" << i << endl;
            count += i;
        }
        wa = 0;
    }
    cout << count << endl;

    //-----------
    cin >> Z;
    return 0;
}

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

using namespace std;

int main()
{
	int n[1000][3];
	int len=0,m;
	cin >> m;
	while (cin >> n[len][0] >> n[len][1] >> n[len][2]) {
		n[len][0] *= n[len][0];
		n[len][1] *= n[len][1];
		n[len][2] *= n[len][2];
		len++;
	}
	for (int i = 0; i < len; i++) {
		if (n[i][0] == (n[i][1] + n[i][2]))
			cout << "YES" << endl;
		else if (n[i][1] == (n[i][2] + n[i][0]))
			cout << "YES" << endl;
		else if (n[i][2] == (n[i][0] + n[i][1]))
			cout << "YES" << endl;
		else 
			cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<cstring>

typedef struct slobj_{
    slobj_* prev;
    slobj_* next;
    int key;
} slobj;

typedef struct slist_{
    slobj* head;
    slobj* tail;
} slist;

slobj* slobj_new(int a){
    slobj* p = new slobj[1];
    p -> prev = NULL;
    p -> next = NULL;
    p -> key = a;
    return p;
}

slist* slist_new(){
    slist* L = new slist[1];
    L -> head = NULL;
    L -> tail = NULL;
    return L;
}

void slist_insert(slist* L, int a){
    slobj* p = L -> head;
    slobj* r = slobj_new(a);
    if(p == NULL){
        L -> head = r;
        L -> tail = r;
    }else{
        p -> prev = r;
        L -> head = r;
        r -> next = p;
    }
}

void slist_delete(slist* L, int a){
    slobj* p = L -> head;
    while(p != NULL && p -> key != a){
        p = p -> next;
    }
    if(p == NULL){
    }else if(p == L -> tail && p == L -> head){
        L -> head = NULL;
        L -> tail = NULL;
        free(p);
    }else if(p == L -> head){
        L -> head = p -> next;
        free(p);
    }else if(p == L -> tail){
        L -> tail = p -> prev;
        p -> prev -> next = NULL;
        free(p);
    }else{
        p -> prev -> next = p -> next;
        p -> next -> prev = p -> prev;
        free(p);
    }
}

void slist_delete_first(slist* L){
    slobj* p = L -> head;
    if(p != NULL && p == L -> tail){
        L -> head = NULL;
        L -> tail = NULL;
        free(p);
    }else if(p != NULL){
        L -> head = p -> next;
        p -> next -> prev = NULL;
        free(p);
    }
}

void slist_delete_last(slist* L){
    slobj* p = L -> tail;
    if(p != NULL && p == L -> head){
        L -> head = NULL;
        L -> tail = NULL;
        free(p);
    }else if(p != NULL){
        p -> prev -> next = NULL;
        L -> tail = p -> prev;
        free(p);
    }
}

void slist_print(slist* L){
    slobj* p = L -> head;
    while(p != NULL){
        printf("%d", p -> key);
        p = p -> next;
        if(p != NULL){
            printf(" ");
        }
    }
    printf("\n");
}

int main(){
    int n;
    scanf("%d", &n);
    slist* L = slist_new();
    int x;
    for(int i = 0; i < n; i++){
        char* command = new char[20];
        scanf("%s", command);
        if(strcmp(command, "insert") == 0){
            scanf("%d", &x);
            slist_insert(L, x);
        }else if(strcmp(command, "delete") == 0){
            scanf("%d", &x);
            slist_delete(L, x);
        }else if(strcmp(command, "deleteFirst") == 0){
            slist_delete_first(L);
        }else if(strcmp(command, "deleteLast") == 0){
            slist_delete_last(L);
        }else{
            printf("I don't have that option.\n");
        }
    }

    slist_print(L);
    return 0;
}


Measured memory_bytes: 71872