akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)

const int INF = 1 << 24;

typedef unsigned long long ull;

const int MAX_N = 1 << 18;

class SegmentTree{
public:
    SegmentTree(int n){
        size = 1;
        while(size < n){
            size *= 2;
        }

        REP(i, 2*n-1){
            data[i] = 0;
        }
    }

    void push(int k, int v){
        k += size - 1;
        data[k] = v;

        while(k > 0){
            int parent = (k - 1) / 2,
                c1 = parent * 2 + 1, c2 = parent * 2 + 2;

            data[parent] = data[c1] + data[c2];
            k = parent;
        }
    }

    int query(int l, int r){
        return _query(l, r, 0, 0, size);
    }

    int _query(int l, int r, int k, int a, int b){
        if(r <= a || b <= l){return 0;}

        if(l <= a && b <= r){return data[k];}
        
        int mid = (a + b) / 2;
        return _query(l, r, 2*k+1, a, mid) + _query(l, r, 2*k+2, mid, b);
    }

private:
    int data[MAX_N], size;
};

int main(){
    int N, K;
    while(std::cin >> N >> K, N){
        SegmentTree st(N);

        REP(i, N){
            int n;
            std::cin >> n;

            st.push(i, n);
        }

        int res = 0;
        REP(i, N){
            if(i + K <= N){
                res = std::max(res, st.query(i, i+K));
            }
        }

        std::cout << res << std::endl;
    }
}

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


int main(){
  int r, D, x;
  cin >> r >> D >> x;
  vector<int> X(10);
  X.at(0) = r*x-D;
  for(int i=1;i<10;i++){
    X.at(i) = r*X.at(i-1) - D;
  }
  for(int i=0;i<10;i++){
    cout << X.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6;
int d()
{
    int ret;
    scanf("%d", &ret);
    return ret;
}
long long lld()
{
    long long ret;
    scanf("%lld", &ret);
    return ret;
}
bool cmp(pair<int, int> s, pair<int, int> f)
{
    if (f.first > s.first)
        return true;
    else if (f.first == f.second && f.second < s.second)
        return true;
    else
        return false;
}

int main()
{
    int x,y;
    cin>>x>>y;
    if(x==y || abs(x-y)==1)
    cout<<"Yay!\n";
    else
    cout<<":(\n";
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include <cmath>
#include <limits>
#include<set>
#include <queue>

using namespace std;
#define int long  long int
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int N;
	cin >> N;
	vector<int>A(N),B(N - 1);
	for (int i = 0; i < N - 1; i++)cin >> B[i];
	A[0] = A[1] = B[0];
	for (int i = 1; i < N - 1; i++)
	{
		if (A[i] > B[i])A[i] = B[i];
		A[i + 1] = B[i];

	}
	int sum = 0;
	for (auto i : A)
	{
		sum += i;
	}
	cout << sum;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	for (int i = 0; i < S.length(); i++) {
		if (S[i] == ',') {
			cout << " ";
		}
		else {
			cout << S[i];
		}
	}

	cout << endl;

}






Measured memory_bytes: 3596
#include <stdlib.h>
#include <iostream>
#include <climits>
using namespace std;

int merge_sort(int *array, int left, int right);
int merge(int *array, int left, int mid, int right);
void print_array(int *array, int size);
int main(){
	int n;

	cin >> n;

	int* array = (int*)malloc(n * sizeof(int));
	int result = 0;

	if(n < 1){
		return 0;
	}

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

	result = merge_sort(array, 0, n);
	print_array(array, n);
	cout << result <<endl;
	return 0;
}

int merge_sort(int *array, int left, int right){
	int swap_num = 0;
	if(left+1 < right){
		int mid = (left + right) >> 1;
		swap_num += merge_sort(array, mid, right);
		swap_num += merge_sort(array, left, mid);
		swap_num += merge(array, left, mid, right);
	}

	return swap_num;
}

int merge(int *array, int left, int mid, int right){
	int swap_num = 0;
	int n1 = mid - left;
	int n2 = right - mid;

	int* L = (int*)malloc((n1+1) * sizeof(int));
	int* R = (int*)malloc((n2+1) * sizeof(int));

	for(int i = 0; i < n1; ++i){
		L[i] = array[left + i];
	}
	L[n1] = INT_MAX;
	for(int i = 0; i < n2; ++i){
		R[i] = array[mid + i];
	}
	R[n2] = INT_MAX;

	int i = 0;
	int j = 0;
	for(int k = left; k < right; ++k){
		if(L[i] <= R[j]){
			array[k] = L[i];
			++i;
		}else{
			array[k] = R[j];
			++j;
		}
	}
	swap_num = right - left;
	return swap_num;
}

void print_array(int *array, int size){
	for(int i = 0; i < size; i++){
		cout <<  array[i];
		if(i != size - 1){
		cout << " " ;
		}
	}
	cout << endl;
}

Measured memory_bytes: 63932
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

int gcd(int a, int b) {
  return (b ? gcd(b, a % b) : a);
}

const int maxn = 2005;
int n;
int a[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  return true;
}

bool cmp(vector<int>::iterator a, vector<int>::iterator b) {
  while (true) {
    if (*a != *b) {
      return *a > *b;
    }
    a++;
    b++;
  }
}

void myMerge(vector<int> &a, vector<int> &b) {
  a.push_back(-1);
  b.push_back(-2);
  vector<int> ans;
  for (int i = 0, j = 0; i < sz(a) || j < sz(b);) {
    if (i >= sz(a)) {
      ans.push_back(b[j++]);
      continue;
    }
    if (j >= sz(b)) {
      ans.push_back(a[i++]);
      continue;
    }
    if (cmp(a.begin() + i, b.begin() + j)) {
      ans.push_back(a[i++]);
    } else {
      ans.push_back(b[j++]);
    }
  }
  ans.pop_back();
  ans.pop_back();
  a = ans;
}

vector<int> g[maxn];
int used[maxn];

vector<int> dfs(int v) {
  used[v] = true;
  vector<int> ans;
  while (true) {
    int u = -1;
    for (int i = 0; i < sz(g[v]); i++) {
      int w = g[v][i];
      if (!used[w] && (u == -1 || a[w] < a[u])) {
        u = w;
      }
    }
    if (u == -1) {
      break;
    }
    vector<int> cur = dfs(u);
    myMerge(ans, cur);
  }
  ans.insert(ans.begin(), a[v]);
  return ans;
}

void solve() {
  for (int i = 0; i < n; i++) {
    used[i] = false;
    for (int j = 0; j < n; j++) {
      if (j == i) {
        continue;
      }
      if (gcd(a[i], a[j]) > 1) {
        g[i].push_back(j);
      }
    }
  }
  vector<int> ans;
  while (sz(ans) < n) {
    int v = -1;
    for (int i = 0; i < n; i++) {
      if (!used[i] && (v == -1 || a[i] < a[v])) {
        v = i;
      }
    }
    vector<int> cur = dfs(v);
    myMerge(ans, cur);
  }
  for (int i = 0; i < n; i++) {
    printf("%d ", ans[i]);
  }
  printf("\n");
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 16000
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int ans=a+b;
  ans=min(ans,min(b+c,c+a));
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
static const int INF = 2000000000;
vector<int>l(300000), r(300000);
int count1=0;

void merge(vector<int>& v, int left,int mid,int right) {
	int n1 = mid - left; int n2 = right - mid;
	for (int i = 0; i <n1; i++)l[i]=v[left+i];
	for (int i = 0; i < n2; ++i)r[i] = v[mid + i];
	l[n1]=INF; r[n2]=INF;//番兵
	int i = 0; int j = 0;
	for (int k = left; k < right; ++k) {
		++count1;
		if (l[i] <= r[j]) {
			v[k] = l[i];
			i++;
		}
		else {
			v[k] = r[j];
			j++;
		}
	}
}

void mergesort(vector<int>& v, int left, int right) {
	if (left + 1 < right) {//rightは配列の最後の要素+1だから
		int mid = (left + right) / 2;
		mergesort(v, left, mid);
		mergesort(v, mid, right);
		merge(v, left, mid, right);
	}
}

int main() {
	int n;
	cin >> n;
	vector<int>v(n);
	for (int i = 0; i < n; ++i)cin >> v[i];
	mergesort(v,0,n);
	for (int i = 0; i < n; ++i) {
		if (i)cout << " ";
		cout << v[i];
	}cout << endl;
	cout << count1 << endl;
	return 0;
}


Measured memory_bytes: 6884
#include<bits/stdc++.h>
#define sl(x) scanf("%lld",&x)
#define pl(x) printf("%lld\n",x) 
using namespace std;
const int N = 1e6+5;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
typedef long long ll;
ll a[N];
int main()
{
	ll n,i;
	sl(n);
	if(n%10 == 0)
	printf("10\n");
	else
	{
		ll sum = 0;
		while(n)
		{
			sum += n%10;
			n /= 10;
		}
		pl(sum);
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <cassert>
#include <queue>
using namespace std;
using lint = long long;
const lint mod = 256;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N;
    cin >> N;
    int ans = 0;
    int H_max = 0;
    for(int i = 0; i < N; i++){
        int H;
        cin >> H;
        H_max = max(H_max, H);
        if(H_max <= H){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
	using namespace std;
	string str;
	int i = 0,tim = 0,leng = 0;
	cin >> str;
	leng = str.length();
	for (i = 0; i < leng / 2; i++) {
		if(str[i]!=str[leng-i-1]){
			tim++;
		}
	}


		cout << tim << endl;

}

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long x = sc.nextLong();
		long y = 100;
		int c = 0;
		
		while(true) {
			if(y >= x) {
				System.out.println(c);
				return;
			}
			y += y / 100;
			c++;
		}
		
	}
}

Measured memory_bytes: 35808
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s; cin >> s;
  int x = stoi(s.substr(0,4));
  int y = stoi(s.substr(5,2));
  if(x < 2019) cout << "Heisei";
  else if (x > 2019) cout << "TBD";
  else {
    if(y <= 4) cout << "Heisei";
    else cout << "TBD";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI 3.1415926535897
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


int N, K;
int a[1010];
int acc[1010];
VI bit[40];


void makeAcc(){
	acc[0] = 0;
	repe(i, 1, N) acc[i] = acc[i-1]+a[i-1];
}


void makeBit(){
	rep(i, 0, N){
		rep(j, i, N){
			int x = acc[j+1]-acc[i];
			repif(k, 0, x>>k)
				if((x>>k)&1) bit[k].pb(x);
		}
	}
}


int dfs(VI& v, int i){
	VI v2;
	repr(j, i, 0){
		for(int x : v)
			if((x>>j)&1) v2.pb(x);
		if(SIZE(v2) >= K) return (int)pow(2, i)+dfs(v2, j);
		v2.clear();
	}
	return (int)pow(2, i);
}


int solve(){
	repr(i, 40, 0){
		if(SIZE(bit[i]) < K) continue;
		return dfs(bit[i], i);
	}
	return 0;
}


signed main(){
	cin >> N >> K;
	rep(i, 0, N) cin >> a[i];

	makeAcc();
	makeBit();

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 76304
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << x << '\n'
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
//---------------------------------------------------------------------------------------------------
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
//---------------------------------------------------------------------------------------------------
lli a = 0, b = 0, c = 0, d = 0, h = 0, n = 0, w = 0, ans = 0, count = 0;
string s, t;
vector<pair<lli, lli>> pr;
map<lli, lli> mp;
set<lli> st;
//---------------------------------------------------------------------------------------------------
vlli e(200010, 0);
lli isOk(lli x, lli y)
{
  e[x] = 1;
  repe(i, x, y)
  {
    if (e[i])
    {
      rep(j, 1, 3)
      {
        if (s[i] == '.')
        {
          e[i + j] = 1;
        }
      }
    }
  }
  return e[y];
}
//---------------------------------------------------------------------------------------------------
string solve()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> a >> b >> c >> d;
  a--;
  b--;
  c--;
  d--;
  cin >> s;
  if (!isOk(a, c))
    return "No";
  if (!isOk(b, d))
    return "No";

  if (c < d)
    return "Yes";

  rep(i, b - 1, d)
  {
    if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.')
      return "Yes";
  }
  return "No";
}

//---------------------------------------------------------------------------------------------------
signed main()
{
  out(solve());
}

Measured memory_bytes: 5160
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){

  int h,w,k;
  cin >> h>> w >> k;

  
  int a[h][w];
  
  vector<string> q(h);
  for(int i=0;i<h;i++)cin >> q[i];

  //scoreの最大値
  long long int m=0;
  int p=0;
  for(int u=0;u<h;u++){
    for(int v=0;v<w;v++){
      //入力
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)a[i][j]=ctoi(q[i][j]);
      }
      //(u,v)を消す
      a[u][v]=0;

      //v列目の必要な個所を落とす
      int z=0;
      for(int j=h-1;j>=0;j--){
        if(a[j][v]==0)z++;
        else if(z!=0){
          a[j+z][v]=a[j][v];
          a[j][v]=0;
        }
      }

      long long int score=0;

      long long int c=1;
      long long int d=0; 

      while(c!=0){
        c=0;
        for(int i=0;i<h;i++){
          //左からn個目からn+l-1個目までのl個消える
          for(int n=0;n<=w-k;n++){
            if(a[i][n]==0)continue;  //左からn個目が0なら消えるわけがない
            for(int l=w-n;l>=k;l--){
              //左からn個目からl個を見て、ちゃんと全部が左からn個目と同じかを見る
              int b=0;
              for(int m=0;m<l;m++){
                if(a[i][n+m]==a[i][n])b++;
              }
              if(b==l){
                c+=l*a[i][n];
                for(int m=0;m<l;m++){
                  a[i][n+m]=0;
                }
                break;
              }
            }
          }
        }

        score += c*pow(2,d);
        d++;
        for(int i=0;i<w;i++){
          int z=0;
          for(int j=h-1;j>=0;j--){
            if(a[j][i]==0)z++;
            else if(z!=0){
              a[j+z][i]=a[j][i];
                a[j][i]=0;
            }
          }
        }

      }
      m=max(m,score);

    }
  }

  cout << m << endl;



}

Measured memory_bytes: 256
/**
 *
 * AtCoder Beginner Contest 103 - Problem B: String Rotation (https://abc103.contest.atcoder.jp/tasks/abc103_b)
 *
 * Minimize the cost to complete three tasks, according to the given rules.
 *
 * Ad-hoc solution: try all six possible permutations and return the least cost one.
 */
#include <iostream>

using namespace std;

void solve(const string& S, const string& T)
{
    auto N = T.size();
    auto x = T;

    for (int i = 0; i < N; ++i)
    {
        if (x == S)
        {
            cout << "Yes\n";
            return;
        }

        auto y = x.back() + x.substr(0, N - 1);
        x = y;
    }

    cout << "No" << endl;
}

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

    string S, T;
    cin >> S >> T;

    solve(S, T);

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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







//T: int系
template<class T> class BinaryIndexTree{
    int n;
    std::vector<unsigned long long> data;
public:
    BinaryIndexTree(): n(0){}
    BinaryIndexTree(int m): n(m), data(m){}

    void add(int k, T a){
        ++k;
        while(k <= n){
            data[k - 1] += (unsigned long long)a;
            k += k & -k;
        }
    }

    T getSum(int l, int r){
        //[l, r[
        return sum(r) - sum(l);
    }
private:
    unsigned long long sum(int r){
        unsigned long long s(0);
        while(r > 0){
            s += data[r-1];
            r -= r & -r;
        }
        return s;
    }
};

int main(){
    int N, Q; std::cin >> N >> Q;
    BinaryIndexTree<long long> fnt(N);
    {
        int a;
        for(int i(0); i < N; ++i){
            std::cin >> a;
            fnt.add(i, a);
        }
    }
    {
        int op, l, r;
        for(int i(0); i < Q; ++i){
            std::cin >> op >> l >> r;
            if(op) std::cout << fnt.getSum(l, r) << "\n";
            else fnt.add(l, r);
        }
    }
    return 0;
}


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


inline ll dist(ll x, vl& s, vl&t){
  int m=lower_bound(s.begin(),s.end(), x)-s.begin()-1;
  int n=lower_bound(t.begin(), t.end(), x)-t.begin()-1;
  ll ans=10000000000000;
  int A=s.size();
  int B=t.size();
  
  if ((m!=-1)&&(n!=-1)){
    ans=min(ans,x-min(s[m],t[n]));
  }
  if ((m!=A-1)&&(n!=B-1)){
    ans=min(ans,max(s[m+1],t[n+1])-x);
  }
  if ((m!=A-1)&&(n!=-1)){
    ans=min(ans, 2*s[m+1]-t[n]-x);
    ans=min(ans, s[m+1]-2*t[n]+x);
  }
  if ((m!=-1)&&(n!=B-1)){
    ans=min(ans, 2*t[n+1]-s[m]-x);
    ans=min(ans, t[n+1]-2*s[m]+x);
  }
  
  return ans;
}


int main(){
  int A, B, Q;cin>>A>>B>>Q;
  vl s, t, x;
  for (int i=0;i<A;i++){
    ll s_;cin>>s_;
    s.push_back(s_);
  }
  for (int i=0;i<B;i++){
    ll t_;cin>>t_;
    t.push_back(t_);
  }
  for (int i=0;i<Q;i++){
    ll x_;cin>>x_;
    x.push_back(x_);
  }

  sort(s.begin(), s.end());
  sort(t.begin(), t.end());

  for (int i=0;i<Q;i++){
    cout << dist(x[i], s, t)<< endl;
  }
  return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
using vl = vector<long>;
using vvl = vector<vector<long>>;
using pll = pair<long, long>;
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define all(vec) vec.begin(), vec.end()

long D;
vector<long> c(26);
vector<vector<long>> s(365,vector<long>(26));
vector<long> t(365);
vector<long> kari(365);
long karians = -1e15;
map<long, vector<long>> mp;

void INPUT(){
  cin >> D;
  rep(i,26) cin >> c.at(i);
  rep(i,D){
    rep(j,26) cin >> s.at(i).at(j);
  }
}

long greedy(){
  vector<long> lastday(26,-1);

  long ans = 0;
  rep(i,D){
    vector<long> tmpscore(26,ans);
    rep(j,26){
      tmpscore.at(j) += s.at(i).at(j);
      rep(k,26){
        if(j != k){
          tmpscore.at(j) -= (i - lastday.at(k))*c.at(k);
        }
      }
    }
    long day = 0;
    long maxi = tmpscore.at(0);
    rep(j,26){
      if(tmpscore.at(j) > maxi){
        maxi = tmpscore.at(j);
        day = j;
      }
    }
    ans = maxi;
    //cout << day+1 << endl;
    t.at(i) = day;
    lastday.at(day) = i;
  }
  return ans;
}

long calc(){
  vector<long> lastday(26,-1);
  long ans = 0;
  rep(i,D){
    long tt = t.at(i);
    ans += s.at(i).at(tt);
    lastday.at(tt) = i;
    rep(j,26){
      ans -= (i - lastday.at(j)) * c.at(j);
    }
    //cout << ans << endl;
  }
  return ans;
}

void OUTPUT(){
  rep(i,D){
    cout << kari.at(i)+1 << endl;
  }
}

int main(){
  long start = clock();
  INPUT();
  long now = greedy();
  karians = now;
  kari = t;
  srand(time(NULL));
  long cnt = 0;
  while((clock() - start)/(CLOCKS_PER_SEC/1000) < 1930){
    cnt++;
    long d = rand() % D;
    long q = rand() % 26;
    long prev_q = t.at(d);
    t.at(d) = q;
    long res = calc();
    if(res > now){
      now = res;
    }else if(cnt >= 10000){
      cnt = 0;
      if(now > karians){
        karians = now;
        t.at(d) = prev_q;
        kari = t;
        t.at(d) = q;
      }
      now = res;
    }else{
      t.at(d) = prev_q;
    }
  }
  if(now > karians){
    kari = t;
  }
  OUTPUT();
}

Measured memory_bytes: 3740
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class AtCoder_abcd{
  public static void Main(){

    var input = Console.ReadLine().Split();
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    int c = int.Parse(input[2]);
    int d = int.Parse(input[3]);

    int t = Math.Min(b,d) - Math.Max(a,c);
    if(t < 0) t = 0;
    Console.WriteLine(t);
    
  }
}

Measured memory_bytes: 11092
def main():
    n,m = map(int, input().split())
    PY = [list(map(int, input().split()+[i])) for i in range(m)]
    PY = sorted(PY, key=lambda x:(x[0],x[1]))

    tmp = 0
    for i in range(m):
        if tmp == PY[i][0]:
            count += 1
        else:
            count = 1
            tmp = PY[i][0]
        PY[i].append(count)

    PY = sorted(PY, key=lambda x:x[2])

    for i in range(m):
        print(str(PY[i][0]).rjust(6,'0')+str(PY[i][3]).rjust(6,'0'))


if __name__ == '__main__':
    main()


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

int main() {
int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  for(int a = 0;a < N;a++){
   cin >> A[a] >> B[a]; 
  }
  sort(A.begin(),A.end());
sort(B.begin(),B.end());
  if(N % 2 == 1){
    cout << B[(N-1) / 2] - A[(N-1) / 2] + 1 << endl;
    
  }else{
    cout << (B[N / 2] + B[(N / 2)-1])-(A[N / 2] + A[(N / 2)-1]) + 1 << endl;
  }
  
  
  

}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  
  else if (A + B < C + D) {
    cout << "Right"  << endl;
  }
  
  else {
    cout << "Balanced" << endl;
  }
}

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

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;
using std::lower_bound;
using std::upper_bound;
using std::find_if;
using std::copy;
using std::copy_if;

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

    int x=1900*m+100*(n-m);
    while(m>0){
        x*=2;
        m--;
    }

    cout << x << endl;

    return 0;
}



Measured memory_bytes: 256
N,M=map(int,input().split())
MAX=10**5+10
MOD = 10**9 + 7
def COMinit():
    """
    逆元テーブルをつくる前処理
    計算量はO(n)
    1 <= k <= n <= 1e7程度
    p: 素数
    """
    fac = [0]*MAX
    finv = [0]*MAX
    inv = [0]*MAX

    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[0], inv[1] = 1, 1
    for i in range(2, MAX):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD
    return fac, finv, inv

fac, finv, inv = COMinit()
if abs(N-M)>=2:
    print(0)
elif abs(N-M)==1:
    ans = fac[N]*fac[M]%MOD
    print(ans)
else:
    ans = 2*fac[N]*fac[M]%MOD
    print(ans)

Measured memory_bytes: 66308
#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<time.h>
#include<cstdlib>
typedef long long ll;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mm(a) memset(a,0,sizeof(a))
#define lr rt<<1
#define rr rt<<1|1
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0);
#define inf 0x3f3f3f3f
#define eqs 1e-8
#define lb(x) (x&(-x))
#define ch(a) (int(a-'0'))
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef pair<int,int> pii;
const double pi=acos(-1);
const int maxn=201000;
//const ll Mod=1000000007;
//const ll Mod=6597069766657;
using namespace std;
//const ll Mod=2e17;



ll p[maxn],inv[maxn];
ll a[maxn],v[maxn];

//inv[0]=inv[1]=1;
//inv[i]=1LL*(Mod-Mod/i)*inv[Mod%i]%Mod;          //这个是单个数的逆元 不是阶乘的逆元！！
//S(n,m)=S(n,m−1)+C(​​n m​​),S(n,m)=2S(n−1,m)−C(​​n−1 m​​)
ll ksm(ll x,ll y)
{
    ll res=1;
    while(y)
    {
        if(y&1)
        {
            res=res*x;
        }
        x=x*x;
        y/=2;
    }
    return res;
}
 
ll C(int n,int m)
{
    return p[n]/p[m]/p[n-m];
}
int main()
{
    sync;
    p[0]=inv[0]=1;
    int n;
    cin>>n;
    ll zd=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        v[a[i]]++;
        zd=max(v[a[i]],zd);
    }
    
    ll s=0;
    for(int i=1;i<=n;i++)
    {
        if(v[i]>=2)
        {
            s+=1ll*v[i]*(v[i]-1)/2;
//            cout<<s<<' '<<i<<' '<<' '<<v[i]<<' '<<C(v[i],2)<<endl;
//            cout<<s<<' '<<i<<endl;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(v[a[i]]<=1)
            cout<<s<<endl;
        else
        {
            ll ss=s;
            ss-=1ll*v[a[i]]*(v[a[i]]-1)/2;
            if(v[a[i]]>=3)
            {
                ss+=1ll*(v[a[i]]-1)*(v[a[i]]-2)/2;
            }
            cout<<ss<<endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 7808
#include <iostream>

using namespace std;

int n, sum = 0, maxi = -1;

int main() {
	cin >> n;
	int l;
	for (int i = 0; i < n; i ++) {
		cin >> l;
		sum += l;
		if (maxi < l) {
			maxi = l;
		}
	}

	sum = sum - maxi;

	if (maxi < sum) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int H, W, N;
int a[112345], b[112345];
int ca[112345], cb[112345];
set<pii> ss;

inline bool check(int y, int x) {
	return y > 1 && y < H && x > 1 && x < W;
}

int main() {
	cin >> H >> W >> N;
	REP(i, N) {
		scanf("%d %d", a + i, b + i);
		ss.insert(pii(a[i], b[i]));
	}
	
	set<pii> ans[10];
	REP(i, N) {
		FOR(j, -1, 2) FOR(k, -1, 2) {
			int y = a[i] + j, x = b[i] + k;
			if (!check(y, x)) continue;
			
			int cnt = 0;
			for (int yy = y - 1; yy <= y + 1; yy++) {
				for (int xx = x - 1; xx <= x + 1; xx++){
					if (ss.find(pii(yy, xx)) != ss.end()) cnt++;
				}
			}
			
			if (cnt > 0) ans[cnt].insert(pii(y, x));
		}
	}
	
	ll sum = 0;
	FOR(i, 1, 10) sum += ans[i].size();
	
	cout << (ll)(H - 2) * (W - 2) - sum << endl;
	FOR(i, 1, 10) cout << ans[i].size() << endl;
		
	return 0;
}


Measured memory_bytes: 47872
module Main where

import Data.Char
import Data.List

main :: IO ()
main = do
  num <- fmap read getLine
  str <- getLine
  if (mod num 2) == 1
    then putStrLn "No"
    else putStrLn $ discrimination num str

discrimination:: Int -> String -> String
discrimination n str = 
  let half = n `div` 2
      firstHalf = take half str
      secondHalf = reverse $ take half $ reverse str
  in if firstHalf == secondHalf
    then "Yes"
    else "No"

Measured memory_bytes: 508
# caddi2018C - Product and GCD
def prime_factorization(x: int) -> int:
    """
    Prime factorization of a number (trial division)
    
    Args: x (int): a number to be resolved
    Return: ret (dict): {prime factor: power}
    
    e.g., n = 2^a * 3^b -> {2: a, 3: b}
    """
    max_prime = 0
    ret = {}

    # Divide x by 2 as much as possible
    cnt = 0
    while x % 2 == 0:
        x //= 2
        cnt += 1
    if cnt > 0:
        max_prime = 2
        ret[max_prime] = cnt

    # x must be odd -> skip even numbers
    cnt = 0
    for i in range(3, int(x ** 0.5) + 1, 2):
        cnt = 0
        while x % i == 0:
            x //= i
            max_prime = i
            cnt += 1
        if cnt > 0:
            ret[max_prime] = cnt

    # To handle the case when x is prime greater than 2
    if x > 2:
        max_prime = x
        ret[max_prime] = 1

    return ret


def main():
    # prime factorize -> f1^(p1//n) * f2^(p2//n) ...
    n, p = list(map(int, input().rstrip().split()))
    ans = 1
    for f, p in prime_factorization(p).items():
        ans *= f ** (p // n)  # factor, power
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define N 200
int n, x[N], y[N], h[N];

int main() {
    //freopen("sample.in", "r", stdin);
    cin >> n;
    for(int i = 1; i <= n; i++) scanf("%d%d%d", &x[i], &y[i], &h[i]);
    int p = 1; while (h[p] == 0) p++;
    for(int i = 0; i <= 100; i++)
        for(int j = 0; j <= 100; j++) {
            bool pan = true; int nowh = h[p] + abs(i - x[p]) + abs(j - y[p]);
            for(int k = 1; k <= n; k++)
                if (max(nowh - abs(i - x[k]) - abs(j - y[k]), 0) != h[k]) {
                    pan = false; break;
                }
            if (pan) return cout << i << " " << j << " " << nowh << endl, 0;
        }
}

Measured memory_bytes: 256
n=int(input())
s=input()
tcnt=0
for i in range(1,n):
    tcnt+=s[i]=="E"

tmin=n
for i in range(n):
    if tmin>tcnt:
        tmin=tcnt
    if s[i]=="W":
        tcnt+=1
    try:
        if s[i+1]=="E":
            tcnt-=1
    except:
        pass
print(tmin)

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

int main()
{
    int R, G, B, N;

    cin >> R >> G >> B >> N;

    int count = 0;
    
    /*
    for (int i = 0; i <= N / R; i++)
    {
        for (int j = 0; j <= N / G; j++)
        {
            for (int k = 0; k <= N / B; k++)
            {
                if ((R * i + G * j + B * k) == N)
                {
                    count++;
                }
            }
        }
    }
    */

    for (int j = 0; j <= N / G; j++)
    {
        for (int k = 0; k <= N / B; k++)
        {
            if ((((N - (j * G + k * B)) % R) == 0) && (N - (j * G + k * B)) >= 0)
            {
                count++;
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
int main(){
    int n;
    cin >> n;
    vector<int>b(n);
    rep(i,n){
        cin >> b[i];
    }
    vector<int>a;
    a.push_back(b[0]);
    rep(i,n){
        if(b[i] == a.back())continue;
        else a.push_back(b[i]);
    }
    n = (int) a.size();
    if(n==1){
        cout << 1 << endl;
        return 0;
    }
    int ans = 1;
    for(int i = 1; i < n-1; i++){
        if((a[i-1] < a[i] and a[i] < a[i+1]) or (a[i-1]>a[i] and a[i] > a[i+1])){
        }
        else{
            i++;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1276
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;

const ll INF = 1e15;
const ld eps = 1e-15;

int main() {
	ll N;
	cin >> N;
	vector<ll> a(N);
	for (int i = 0;i < N;i++) {
		cin >> a[i];
	}
	ll ans = 0;
	for (int i = 1;i < N;i++)
		if (a[i] == a[i - 1]) {
			a[i] = 1000000 + i;
			ans++;
		}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 888
n,k=map(int, input().split())
an=[int(i) for i in input().split()]

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r=min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 5
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2,N+1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

an=sorted(an)
r_an=list(reversed(an))

max1=0
min1=0
for i in range(1,n-k+2):
    c=cmb(n-i,k-1,p)
    max1=max1 + an[-i]*c%p
    min1=min1 + r_an[-i]*c%p
print((max1-min1)%p)

Measured memory_bytes: 79016
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(sa[i]);
		}
		br.close();

		long sum = 0;
		for (int i = 0; i < n; i++) {
			sum ^= a[i];
		}
		for (int i = 0; i < n; i++) {
			a[i] &= ~sum;
		}

		Hakidasi h = new Hakidasi(a);
		long sum2 = 0;
		for (int i = 0; i < n; i++) {
			sum2 ^= h.arr[i];
		}
		System.out.println(sum + sum2 * 2);
	}

	static class Hakidasi {
		long[] arr;
		int[] msb;
		int n, rank;

		public Hakidasi(long[] a) {
			n = a.length;
			arr = Arrays.copyOf(a, n);
			msb = new int[n];

			for (int i = 62; i >= 0; i--) {
				boolean flg = false;
				for (int j = rank; j < n; j++) {
					if ((arr[j] >> i & 1) == 1) {
						long t = arr[rank];
						arr[rank] = arr[j];
						arr[j] = t;
						flg = true;
						break;
					}
				}
				if (flg) {
					msb[rank] = i;
					for (int j = 0; j < n; j++) {
						if (j != rank && (arr[j] >> i & 1) == 1) {
							arr[j] ^= arr[rank];
						}
					}
					rank++;
				}
			}
		}
	}
}


Measured memory_bytes: 52548
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    int n;
    cin >> n;

    vector<int> p(n);
    vector<int> q(n);
    vector<int> v(n);

    rep(i,n){
        int tmp;
        cin >> tmp;

        p[i] = tmp;
    }
        rep(i,n){
        int tmp;
        cin >> tmp;

        q[i] = tmp;
    }

    rep(i,n){
        v[i] = i + 1;
    }

    int a = 0;
    int b = 0;
    int count = 1;

    while(true){

        bool same = true;

        rep(i,n){
            if(p[i] != v[i]){
                same = false;
                break;
            }
        }

        if(same){
            a = count;
        }

        same = true;

        rep(i,n){
            if(q[i] != v[i]){
                same = false;
                break;
            }
        }

        if(same){
            b = count;
        }

        if(a != 0 && b != 0) break;

        next_permutation(ALL(v));
        count++;
    }

    cout << abs(a - b) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <memory>
#include <queue>

using namespace std;

int N,M;

struct Edge {
    int src, dst, weight;
    Edge *next, *prev;
    Edge(int s, int d, int w, Edge *n, Edge *p)
        : src(s), dst(d), weight(w), next(n), prev(p) {}
    Edge() : Edge(0, 0, 0, nullptr, nullptr) {}
};

vector<Edge*> first;

void add_edge(int u, int v, int d){
    Edge *next = first[u];
    first[u] = new Edge(u, v, d, next, nullptr);
    if(next != nullptr) next->prev = first[u];
}

int main(){
    int V,E,r;
    while(cin >> V >> E >> r){
        first.assign(V, nullptr);
        for(int i = 0; i < E; ++i){
            int s,t,d;
            cin >> s >> t >> d;
            add_edge(s,t,d);
        }

        using State = pair<int,int>;
        priority_queue<State> q;
        vector<long long> dist(V, 1e18);
        q.emplace(0,r);
        dist[r] = 0;

        while(q.size()){
            long long d,v;
            tie(d,v) = q.top();
            q.pop();
            d = -d;
            if(dist[v] < d) continue;
            for(Edge *e = first[v]; e != nullptr; e = e->next){
                if(dist[e->dst] > e->weight + dist[v]){
                    dist[e->dst] = e->weight + dist[v];
                    q.emplace(-dist[e->dst], e->dst);
                }
            }
        }

        for(int i = 0; i < V; ++i){
            if(dist[i] == 1e18) cout << "INF";
            else cout << dist[i];
            cout << '\n';
        }
    }
    
    // {
    //     vector<string> u, v;
    //     static char s[3000], t[3000];
    //     map<string,int> id;
    //     N = 0;
    //     M = 0;
    //     while(cin >> s >> t){
    //         u.push_back(s);
    //         v.push_back(t);
    //         if(id.count(s) == 0) id[s] = N++;
    //         if(id.count(t) == 0) id[t] = N++;
    //         ++M;
    //     }

    //     first.assign(N, nullptr);
    //     for(int i = 0; i < M; ++i){
    //         add_edge(id[u[i]], id[v[i]]);
    //     }
    // }
}

Measured memory_bytes: 28236
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
const int mod= 1e+9+7;

int main() {
    int N; cin>>N;
    string s,t; cin>>s>>t;
    int cnt=0;
    rep(i,N){
        if(s.substr(i,N-i)==t.substr(0,N-i)){
            cnt=N-i;
            break;
        }
    }
    cout<<2*N-cnt<<endl;
}


Measured memory_bytes: 256
import heapq
n,m=map(int,input().split())
a=list(map(lambda x:x*(-1),map(int,input().split())))
heapq.heapify(a)
for i in range(m):
    x=(((heapq.heappop(a))*(-1))//2)*(-1)
    heapq.heappush(a,x)
print(sum(a)*(-1))


Measured memory_bytes: 14180
def solve():
    N = int(input())
    S = [input() for N in range(N)]
    snames = ["AC", "WA", "TLE", "RE"]
    score = {"AC": 0, "TLE": 0, "WA": 0, "RE": 0}


    for st in S:
        score[st] += 1

    for sname in snames:
        print(sname + " x " + str(score[sname]))

solve()

Measured memory_bytes: 79120
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      _a: [i32; n]
   }
   let mut tot = 0;
   let mut a = vec![];
   a.push(0);
   for i in _a {
      a.push(i);
   }
   a.push(0);
   for i in 0..n + 1 {
      tot += (a[i + 1] - a[i]).abs();
   }

   for i in 1..n + 1 {
      println!(
         "{}",
         tot - (a[i] - a[i - 1]).abs() - (a[i] - a[i + 1]).abs() + (a[i - 1] - a[i + 1]).abs()
      );
   }
}


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

int main(){
  int n,k,d,a;
  cin >> n >>k;
  vector<int> cunt(n);
  for(int i =0;i<k;i++){
    cin >> d;
    for(int j=0;j<d;j++){
      cin >> a;
      cunt[a-1]++;
    }
  }
  int total = 0;
  for(int i=0;i<n;i++){
    if(cunt[i]==0){
      total++;
    }
  }
  cout << total;
  
}


Measured memory_bytes: 3604
import sys

def solve():
    input = sys.stdin.readline
    R, G, B, N = map(int, input().split())
    count = 0
    for i in range(N // R + 1):
        red = R * i
        lem = N - red
        for j in range(lem // G + 1):
            green = G * j
            if (lem - green) % B == 0: count += 1
    print(count)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
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 <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    string s;
    ll k;
	cin >> s >> k;
    int n = s.size();
    vector<int> chrs;
    int num = 1;
    rep(i,s.size()) {
        if(i) {
            if(s[i-1]==s[i]) {
                num++;
            } else {
                chrs.push_back(num);
                num = 1;
            }
        }
    }
    chrs.push_back(num);
    int chrs_n = chrs.size();
    ll cnt = 0; // sの最初と最後の文字種を除いたs内の操作回数
    rep(i,chrs_n-2) cnt += chrs[i+1] / 2;

    ll ans = 0;
    if (chrs.size() == 1) {     // 全結合
        ans = (k * s.size()) / 2;
    } else if (s[0] == s[n-1]) { // 結合あり
        ans = cnt * k + chrs[0]/2 + chrs[chrs_n-1]/2 + ((chrs[0]+chrs[chrs_n-1])/2)*(k-1);
    } else {                    // 結合なし
        ans = (cnt + chrs[0]/2 + chrs[chrs_n-1]/2) * k;
    }

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


Measured memory_bytes: 256