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

int main(){
    int w, a, b;
    cin >> w >> a >> b;
    if(a-w <= b && b <= a+w){
        cout << 0;
    }else if(a+w < b){
        cout << b-a-w;
    }else{
        cout << a-b-w;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=200010;
int n,m,minn=1<<30;
int a[N],sum[N];
int main()
{
    scanf("%d%d",&n,&m);
    for(int k=1;k<=n;k++)
        scanf("%d",&a[k]),minn=min(minn,a[k]);
    for(int k=1;k<=m&&minn<n;k++)
    {
        memset(sum,0,sizeof sum);
        for(int i=1;i<=n;i++)
        {
            sum[max(1,i-a[i])]++;
            sum[min(i+a[i]+1,n+1)]--;
        }
        for(int i=1;i<=n;i++)
            sum[i]+=sum[i-1];
        minn=1<<30;
        for(int i=1;i<=n;i++)
            a[i]=sum[i],minn=min(minn,a[i]);
    }
    for(int k=1;k<=n;k++)
        printf("%d ",a[k]);
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int a = N / 1000;
  int b_1 = N / 100, b = b_1 % 10;
  int c_1 = N / 10, c = c_1 % 10;
  int d = N % 10;

  if ((a == b) && (b == c)) {
    cout << "Yes" << endl;
  }
  else if ((b == c) && (c == d)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import sys
from collections import deque

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def topological_sort(N, dag):

    degree = [0] * N
    for i in range(N):
        for v in dag[i]:
            degree[v] += 1

    ret = [v for v in range(N) if degree[v] == 0]
    q = deque(ret)

    while q:
        v = q.popleft()
        for nv in dag[v]:
            degree[nv] -= 1
            if degree[nv] == 0:
                q.append(nv)
                ret.append(nv)

    return ret


def main():

    N, M = in_nn()

    edge = [[] for _ in range(N)]
    for i in range(M):
        x, y = in_nn()
        x, y = x - 1, y - 1
        edge[x].append(y)

    dp = [0] * N
    vs = topological_sort(N, edge)
    for v in vs:
        for nv in edge[v]:
            dp[nv] = max(dp[nv], dp[v] + 1)

    print(max(dp))


if __name__ == '__main__':
    main()


Measured memory_bytes: 92652
N,K=map(int,input().split())
cnt=N // K
ch=N % K

if K%2==1:
  print(cnt**3)
else:
  ans=cnt**3
  cnt=0
  for i in range(1,N+1):
    if i % K== K//2:
      cnt+=1
  ans+=(cnt**3)
      
  print(ans)

Measured memory_bytes: 3060
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(){
    int n;
    cin >> n;
    vector<int> a(100010, 0);
    set<int> st;
    REP(i, n) {
        int ai;
        cin >> ai;
        a[ai]++;
        st.insert(ai);
    }
    int cnt=0;
    REP(i, a.size()) {
        if(a[i]%2==0&&a[i]>1){
            a[i]=2;
            cnt++;
        }
        else
            a[i]=1;

    }
    if(cnt%2==1)
        cout << st.size()-1 << endl;
    else
        cout << st.size() << endl;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6;
long double a[N];


int32_t main()
{
   int n; cin>>n;
    vector<int>a(n); 
    for(int i=0;i<n;i++) cin>>a[i];
    for (int i=n-2;i>=0;i--) 
    {
        if (a[i]>a[i + 1]) 
        {
            a[i]-=1; if (a[i]>a[i + 1]) {  cout<<"No"<<endl;  return 0;  }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

                        

                            

Measured memory_bytes: 1024
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    n,x,t = map(int,input().split())
    if n % x == 0:
        print((n//x) * t)
    else:
        print((n//x + 1) * t)

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=200050;
ll a[N],cnt[N];
int main()
{
	int n,i,m;
	scanf("%i",&n);
	for(i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+1+n);
	cnt[1]=1;m=1;
	for(i=2;i<=n;i++)
	{
		if(a[i]==a[m]) cnt[m]++;
		else m++,cnt[m]=1,a[m]=a[i];
	}
	ll ans=0;
	for(ll j=((ll)1)<<32;j>0;j>>=1)
	{
		int l,r=m;
		for(l=1;l<=m;l++)
		{
			while(r>0 && a[l]+a[r]>j) r--;
			if(r!=0 && a[l]+a[r]==j)
			{
				ll get;
				if(r==l) get=cnt[l]/2;
				else get=min(cnt[l],cnt[r]);
				ans+=get;
				cnt[l]-=get;
				cnt[r]-=get;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    A = tuple(map(int, input().split()))

    for a in A:
        if a % 2 == 0:
            if a % 3 != 0 and a % 5 != 0:
                print('DENIED')
                exit()
    print('APPROVED')

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	VI num(10003);
	num[1] = 2;
	int x = 2;
	for (int i = 2; i <= 10000; i++) {
		num[i] = num[i - 1] + x;
		x++;
	}

	int n;
	while (cin >> n) {
		Cout(num[n]);
	}
}


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


#5(1)
#2(1) 2(1)
#1(1) 1(1) 1(1) 1(1)
def count(H:int):
    if H == 1:
        return 1
    else:
        return 2 * count(H // 2) + 1

def solve(H: int):
    print(count(H))


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <cstdio>
#include <map>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

int N, M;
std::map<int, int> cnt;

int main()
{
  scanf( "%d%d", &N, &M );
  rep( i, M )
  {
    int a, b;
    scanf( "%d%d", &a, &b );
    ++cnt[a];
    ++cnt[b];
  }

  bool fl = true;
  for( auto it = cnt.begin(); it != cnt.end(); ++it )
    fl &= it->second%2==0;

  puts( fl ? "YES" : "NO" );

  return 0;
}

Measured memory_bytes: 4352
import sys

def BFS(K,edges,N):
  roots=[ [] for i in range(N)]
  for a,b,c in edges:
    roots[a]+=[(b,c)]
    roots[b]+=[(a,c)]
  dist=[-1]*N
  stack=[]
  stack.append(K)
  dist[K]=0
  while stack:
    label=stack.pop(-1)
    for i,c in roots[label]:
      if dist[i]==-1:
        dist[i]=dist[label]+c
        stack.append(i)
  return dist
      
      
a = []
edge = []
for l in sys.stdin:
    a.append(l.split())
V = int(a[0][0])
for i in range(V-1):
  buf = [int(a[i+1][0])-1, int(a[i+1][1])-1, int(a[i+1][2])]
  edge.append(buf)
n = int(a[V][0])
s = int(a[V][1])-1
ques = []
for i in range(n):
  buf = [int(a[V+i+1][0])-1, int(a[V+i+1][1])-1]
  ques.append(buf)
dist = BFS(s, edge, V)
for a, b in ques:
  res = dist[a] + dist[b]
  print(res)

Measured memory_bytes: 137524
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      StringBuilder buf = new StringBuilder();
      while(true) {
        int n = Integer.parseInt(in.readLine());

        if(n == 0) break;

        int[] p = new int[n];
        int min = 100_000_000;
        int max = 0;
        for(int i=0; i<n; i++) {
          p[i] = Integer.parseInt(in.readLine());
          if(min > p[i]) min = p[i];
          if(max < p[i]) max = p[i];
        }

        int ans=0;
        boolean isExcutedMin = false;
        boolean isExcutedMax = false;
        for (int i : p) {
          if(!isExcutedMax && i == max) {
            isExcutedMax = true;
            continue;
          }
          if(!isExcutedMin && i == min) {
            isExcutedMin = true;
            continue;
          }

          ans += i;
        }
        ans /= (n-2);

        buf.append(ans).append("\n");
      }

      System.out.print(buf);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}


Measured memory_bytes: 24636
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<deque>
#include<stdlib.h>
#include <algorithm>
#include<set>
#include<map>
#include <limits>
#include<iomanip>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_5 100000
#define d9_7 1000000007
//木構造グラフ
struct edge{
  struct treev* to;
  ll length;
};
struct treev{
  int num;
  vector<edge> nexts;
};
struct input{
  int u;
  int v;
  ll w;
};
vector<treev*> vs;
treev* createtreenode(int num){
  treev* newt=new treev;
  if(newt==NULL){
    cout << "memory error" << endl;
    while(1){
      num=1;//メモリエラー対策
    }
  }
  newt->num=num;
  newt->nexts={};
  //cout << "fff" << endl;
  return newt;
}
void insertree(ll len,int Va,int Vb){//結ぶ頂点を
  vs[Va]->nexts.push_back({vs[Vb],len});
  vs[Vb]->nexts.push_back({vs[Va],len});
  return;
}
void search(treev* root,ll depth,treev* pre){
  //cout << "eee" << endl;
  //ここにやりたい処理を書く
  for(auto i:root->nexts){
    if(pre==i.to){
      continue;
    }
    search(i.to,depth+i.length,root);
  }
  return;
}

  
int main(void){
  ll k,n;
  cin>>n>>k;
  rep(i,n){
    vs.push_back(createtreenode(i));
  }
  if((((n-1)*(n-2))/2)<k){
    cout<<-1<<endl;
    return 0;
  }
  cout<<(n-1 + (((n-1)*(n-2))/2-k))<<endl;
  rep(i,n-1){
    cout<<1<<" "<<i+2<<endl;
  }
  int cnt=0;
  for(int i=2;i<n;i++){
    for(int j=i+1;j<=n;j++){
      if(cnt>=((n-1)*(n-2))/2-k){
        return 0;
      }
      cnt++;
      cout<<i<<" "<<j<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(){
    int Map[101][101];
    int N, u, k, temp;
    scanf("%d\n",&N);
    for (int ix = 0; ix < N; ix++)
        for (int jx = 0; jx < N; jx++)
            Map[ix][jx] = 0;
    for (int ix = 0; ix < N; ix++){
        scanf("%d %d",&u,&k);
        for (int kx = 0; kx < k; kx++){
            scanf("%d",&temp);
            Map[u-1][temp-1] = 1;
        }
    }
    for (int ix = 0; ix < N; ix++)
        for (int jx = 0; jx < N; jx++){
            if (jx == N-1) printf("%d\n",Map[ix][jx]);
            else printf("%d ",Map[ix][jx]);
        }
    return 0;
}


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

using namespace std;

int main()
{
  int n, c, sum = 0;
  cin >> n >> c;
  for (int i = 0; i < c; i++)
  {
    int p;
    cin >> p;
    sum += p;
  }
  cout << (sum + n) / (n + 1) << endl;

  return 0;
}




Measured memory_bytes: 3092
function dice(num) {
  this.n = num;  // array
  this.rotate = function(dir) {
    if(dir == 'N') this.n = [this.n[1], this.n[5], this.n[2], this.n[3], this.n[0], this.n[4]];
    else if(dir == 'E') this.n = [this.n[3], this.n[1], this.n[0], this.n[5], this.n[4], this.n[2]];
    else if(dir == 'S') this.n = [this.n[4], this.n[0], this.n[2], this.n[3], this.n[5], this.n[1]];
    else if(dir == 'W') this.n = [this.n[2], this.n[1], this.n[5], this.n[0], this.n[4], this.n[3]];
  }
}
function Main(input) {
  input = input.split("\n");
  var dice_a = new dice(input[0].split(" "));
  input[1].split("").forEach(function(d){dice_a.rotate(d);});
  console.log(dice_a.n[0]);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

#define MAXN 20010
using namespace std;

int n,x,y,ans[MAXN];

int main() {	
	cin >> n >> x >> y;
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j) {
			if (i <= x) {
				if (j <= x)
					ans[j - i]++;
				else if(j <= y)
					ans[min(j - i, (x - i) + 1 + (y - j))]++;
				else
					ans[x - i  + 1 + j - y]++;
			}
			else if (i <= y)
			{
				if (j <= y)
					ans[min(j - i, i - x + 1 + y - j)]++;
				else
					ans[min(j -  i, j - y + 1 + i - x)]++;
			}
			else
				ans[j - i]++;
		}
	for(int i = 1; i < n; ++i)
		cout << ans[i] << endl;
	return 0;
}

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

const int MOD = 1000000007;
int main() {
  ll n;
  cin >> n;
  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    ll ni = n / i;
    sum += i * ni * (ni + 1) / 2;
  }

  cout << sum << endl;
  return 0;
}

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

int main(){
	int n, tmp;
	std::cin >> n;
	std::vector<long long> a(n);
	std::vector<long long> s(n);
	for(int i=0; i<n; i++){
		std::cin >> a[i];
		a[i] *= 2;
		if(i==0) s[0] = a[0];
		else s[i] = s[i-1] + a[i];
	}

	long long total = s[n-1];
	long long half = total/2;

	for(int i=0; i<n-1; i++){
		if(s[i]<=half and half<s[i+1]){
			long long l = half - s[i];
			long long r = s[i+1] - half;
			std::cout << std::min(l, r) << std::endl;
			return 0;
		}
	}
}


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

int main()
{
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;

    if((0>x-r || x+r>W ) || (0>y-r || y+r>H)) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;

    return 0;
}

Measured memory_bytes: 3108
//header{{{
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/math/common_factor_rt.hpp>
  
using namespace std;
//using namespace boost;
//using namespace multiprecision;  

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

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

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

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

    multiset<int, greater<int> > s;

    rep(i,n){
        int a;
        cin >> a;
        s.insert(a);
    }

    rep(i,m){
        auto v = *s.begin();
        s.erase(s.begin());
        v /= 2;
        s.insert(v);
    }

    int sum = 0;
    for(auto e : s){
        sum += e;
    }

    cout << sum << '\n';

    return 0;
}


Measured memory_bytes: 4992
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

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

		int a;

		Scanner sc = new Scanner(System.in);

		a = sc.nextInt();

		String[] ArrayA = new String[a];
		HashMap<String, Integer> hm = new HashMap<>();

		for(int i = 0; i < ArrayA.length; i++) {
			String b = sc.next();
			char[] c = b.toCharArray();
			Arrays.sort(c);
			hm.put(String.valueOf(c), hm.getOrDefault(String.valueOf(c), 0) + 1);
		}

		long ans = 0;
		for (String s : hm.keySet()) {
			ans += nc2(hm.get(s));
		}

		System.out.println(ans);
	}

	private static long nc2(long x) {
		return (x * (x - 1)) / 2;
	}


}


Measured memory_bytes: 62132
#include <iostream>
#include <vector>
#include <tuple>
#include <unordered_map>
#include <algorithm>
#include <queue>

using namespace std;
using ll = long long;
struct Edge{
    Edge(ll src, ll tgt, ll cost) : src_(src),tgt_(tgt),cost_(cost) {}
    ll src_{};
    ll tgt_{};
    ll cost_{};
};

struct C {
    ll N_{};
    vector<ll> r_{};
    vector<vector<Edge>> graph_{};
    unordered_map<ll, unordered_map<ll, ll>> cost_between_r_{};
    explicit C(ll N, vector<ll> r,vector<tuple<ll,ll,ll>> v) : N_(N) {
        graph_.resize(N_);
        r_.resize(r.size());
        transform(r.begin(), r.end(), r_.begin(), [](auto c) { return c-1; });
        for(auto&& t : v) {
            graph_[get<0>(t)-1].emplace_back(Edge(get<0>(t)-1, get<1>(t)-1, get<2>(t)));
            graph_[get<1>(t)-1].emplace_back(Edge(get<1>(t)-1, get<0>(t)-1, get<2>(t)));
        }
        ll R = r_.size();
        for(ll r1 : r_) {
            for(ll r2 : r_) {
                cost_between_r_[r1][r2] = calculate_cost_from_cur_to_tgt(r1, r2);
            }
        }
    }

    ll calculate_cost_from_cur_to_tgt(ll cur, ll tgt) {
        ll R = r_.size();
        vector<ll> cost{};
        cost.resize(N_, INT64_MAX);
        auto cmp = [&cost](auto a, auto b) { return cost[a] > cost[b]; };
        priority_queue<ll, vector<ll>, decltype(cmp)> q{cmp};
        cost[cur] = 0;
        q.push(cur);
        while(!q.empty()) {
            ll f = q.top();
            q.pop();
            for (auto t : graph_[f]) {
                auto newCost = cost[f] + t.cost_;
                if (newCost < cost[t.tgt_]) {
                    cost[t.tgt_] = newCost;
                    q.push(t.tgt_);
                }
            }
        }
        return cost[tgt];
    }

    ll resolve() {
        ll mi = INT64_MAX;
        std::sort(r_.begin(), r_.end());
        do {
            ll cost = 0;
            for(int i=0; i < r_.size()-1; ++i) {
                cost += cost_between_r_[r_[i]][r_[i+1]];
            }
            mi = min(mi, cost);
        } while(next_permutation(r_.begin(), r_.end()));

        return mi;
    }
};

int main() {
    ll N, M, R;
    cin >> N >> M >> R;
    vector<ll> r{};
    for (int i=0; i < R; ++i) {
        ll x;
        cin >> x;
        r.emplace_back(x);
    }
    vector<tuple<ll,ll,ll>> v{};
    for (int i=0; i < M; ++i) {
        ll a,b,c;
        cin >> a >> b >> c;
        v.emplace_back(make_tuple(a,b,c));
    }
    C c{N, move(r), move(v)};
    cout << c.resolve() << endl;
    return 0;
}


Measured memory_bytes: 2040
sc = iter(open(0).read().split())

N = int(next(sc))
Q = int(next(sc))

S = "_" + next(sc) + "_"

TD = tuple(zip(sc, sc))

l, r = 0, N + 1
for t, d in reversed(TD):

    if t == S[l + 1] and d == "L":
        l += 1
    elif t == S[l] and d == "R":
        l -= 1

    if t == S[r - 1] and d == "R":
        r -= 1
    elif t == S[r] and d == "L":
        r += 1

print(max(0, r - l - 1))

Measured memory_bytes: 22764
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll s;
  cin >> s;
  map<ll,ll> mp;
  ll cnt = 1;
  while(1){
    if(mp.find(s)!=mp.end()) break;
    mp[s] = cnt;
    s = (s%2==0) ? s/2 : 3*s+1;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long ll;

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
    string S;
    cin >> S;
    string bb = S.substr(0, 2);
    string aa = S.substr(2, 2);
    if (bb < "13" && bb> "00") {
        if (aa < "13" && aa > "00") cout << "AMBIGUOUS" << endl;
        else cout << "MMYY" << endl;
    }
    else {
        if (aa > "00" && aa < "13") cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }
}


Measured memory_bytes: 3568
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define pushb push_back
#define popb pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};

void detect(intl i,intl j,vvi &seki,vvi &iya, intl &N){
  Rep(k,4){
    if(i+dx[k] < 0 || i+dx[k] >= N || j + dy[k] < 0 || j+dy[k] >= N){continue;}
    if( iya[i+dx[k]][j+dy[k]] - iya[i][j]>seki[i+dx[k]][j+dy[k]] ){
      iya[i+dx[k]][j+dy[k]] -=1 ;
      detect(i+dx[k],j+dy[k],seki,iya,N);
    }
  }
  return;
}
       


int main(){
  intl N;
  cin >>N;
  vvi seki(N,vi(N,1));
  vvi iya(N,vi(N));
  Rep(i,N){
    Rep(j,N){
      iya[i][j]=min(
        min(i,N-1-i),min(j,N-1-j)
        );
    }
  }
  vi P(N*N);
  Rep(i,N*N){
    cin >> P[i];
  }
  intl cnt =0;
  
  for (auto p : P){
    intl i = (p-1)/N;
    intl j = (p-1)%N;
    
    seki[i][j]=0;
    cnt += iya[i][j];
    iya[i][j] --;
    detect(i , j , seki , iya, N);
    /*Rep(m,N){
      Rep(n,N){
        cout << iya[m][n];
      }
      cout <<endl;
    }*/
  }
  
  cout << cnt;
}

Measured memory_bytes: 47676
/*
ID: seekho
PROG: friday
LANG: C++14                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */

#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;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(998244353)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

//////////////////////
const int N = 100005;

int n,k;
int cost[N];
int ans[N];

int go(int i) {
	if(i == n-1)
		return 0;
	if(ans[i] != -1) return ans[i];

	// ans[i] = go(i+1) + abs(cost[i+1]-cost[i]);
	// if(i+2 <= n-1)
	// 	ans[i] = min(ans[i],go(i+2) + abs(cost[i+2]-cost[i]));
	ans[i] = inf;
	repA(j,1,k) {
		if(i + j > n-1) break;
		ans[i] = min(ans[i], go(i+j) + abs(cost[i] - cost[i+j]));
	}

	return ans[i];
}

int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(0); 
    cout.tie(0);
    cin >> n >> k;
    rep(i,n) {
    	cin >> cost[i];
    	ans[i] = -1;
    }

    cout << go(0) << '\n';
}

Measured memory_bytes: 4992
def g_c_d(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    else:
        return g_c_d(y, x % y)


a = int(input())
b = list(map(int, input().split()))
b.append(0)
b.insert(0, 0)
c = [0]*(len(b))
d = [0]*(len(b))
for i in range(1, len(b)):
    c[i] = (g_c_d(b[i], c[i-1]))
    d[-i-1] = (g_c_d(b[-i-1], d[-i]))
e = 0
for i in range(0, len(c)-2):
    e = max(g_c_d(c[i], d[i+2]), e)
print(e)



Measured memory_bytes: 14400
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};
int main(){
  ll n,m;cin>>n>>m;
  UnionFind tree(n);
  rep(i,m){
    ll x,y,z;cin>>x>>y>>z;
    tree.unite(x-1,y-1);
  }
  ll count=0;
  rep(i,n){
    if(tree.root(i)==i)count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
using namespace std;
#define ll long long

ll n, h, w;
ll a[1050] = {};
ll b[1050] = {};
ll ans = 0;

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

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

	for (int i = 0; i < n; i++)
	{
		if (a[i] >= h && b[i] >= w) {
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
string str;
void print(int a, int b){
    for(int i = a; i <= b; i++) cout << str[i];
    cout << endl;
}
void reverse(int a, int b){
    for(int i = 0; i <= (b - a) / 2; i++) swap(str[a + i], str[b - i]);
}
void replace(int a, int b, string p){
    for(int i = a, j = 0; i <= b; i++, j++) str[i] = p[j];
}
int main(){
    cin >> str;
    int q, a, b;
    string command, p;
    cin >> q;
    for(int i = 0; i < q; i++){
        cin >> command >> a >> b;
        if(command == "print") print(a, b);
        else if(command == "reverse") reverse(a, b);
        else if(command == "replace"){
            cin >> p;
            replace(a, b, p);
        }
    }
}



Measured memory_bytes: 3172
#include <stdio.h>

int main()
{
	long a, b, x, y, tmp;
	while(scanf("%ld %ld", &x, &y) != EOF) {
		if(x < y) {
			tmp = x;
			x = y;
			y = tmp;
		}
		a = x;
		b = y;
		do {
			tmp = x % y;
			x = y;
			y = tmp;
		} while(y != 0);
		printf("%ld %ld\n", x, a * b / x);
	}
	return 0;
}

Measured memory_bytes: 596
import sys
while(True):
    items=[]
    max=0
    n, m = map(int, input().split())
    if (n == 0 & m == 0):exit()
    items = list(map(int, input().split()))
    for i in range(n):
        for j in range(n):
            sum = items[i] + items[j]
            if (i != j and sum <= m and sum > max):
                max = sum
    if (max == 0):
        print("NONE")
    else:
        print(max)



Measured memory_bytes: 5632
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <cassert>
#include <iostream>
using namespace std;
typedef long long ll;

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

#define MEMSET(v,h) memset((v),(h),sizeof(v))

int main() {
    int n;
    while (scanf("%d", &n), n) {
      map<int, pair<int, int> > open;
      open.insert(make_pair(0, make_pair(0, 0)));
      int minx = 0;
      int maxx = 0;
      int miny = 0;
      int maxy = 0;
      REP(i, n - 1) {
          int nindex = i + 1;
          int index, dir;
          scanf("%d %d", &index, &dir);
          const int dx[4] = { -1, 0, 1, 0 };
          const int dy[4] = { 0, 1, 0, -1 };
          int x = open[index].first;
          int y = open[index].second;
          int nx = x + dx[dir];
          int ny = y + dy[dir];
          open[nindex] = make_pair(nx, ny);
          minx = min(minx, nx);
          maxx = max(maxx, nx);
          miny = min(miny, ny);
          maxy = max(maxy, ny);
      }
      printf("%d %d\n", maxx - minx + 1, maxy - miny + 1);
    }
}

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

double a,b,x;
const double PI=3.14159265358979323846;

double cal(double sita){
	if(b*tan(PI/2 - sita) <= a){
		return b * b * a * tan(PI/2 - sita) / 2.0;
	}else{
		return a* a * b - (a * a * a * tan(sita) / 2.0);
	}
}

int main(){
	cin >> a >> b >> x;
	bool pat;
	double start = 0;
	double end = PI/2;

	while(start + 0.00000001 < end){
		double mid = (start + end)/2;
		if(cal(mid) > x){
			start = mid;
		} else {
			end = mid;
		}
	}
	printf("%.12f\n", 180 * start/PI);
}


Measured memory_bytes: 256
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  char a[4], b[4];
  scanf("%s%s", a, b);
  if (a[0] == b[2] && a[1] == b[1] && a[2] == b[0])
    puts("YES");
  else
    puts("NO");

  return 0;
}


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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
vector<pii> T[N];
int sign[N];
ll ss[N];
int dep[N];

int u[N], v[N];
ll w[N];

int main(){
  fastIO;
  int n, m;
  cin >> n >> m;
  for(int i = 0 ; i < m ; i ++ ){
    cin >> u[i] >> v[i] >> w[i];
    T[u[i]].push_back(mp(v[i],w[i]));
    T[v[i]].push_back(mp(u[i],w[i]));
  }
  queue<int> bf;
  bf.push(1);
  ss[1]=0;
  sign[1]=+1;
  int node;
  ll L = 0, R = (ll)1e10;
  while(!bf.empty()){
    node = bf.front();
    bf.pop();
    for(auto x : T[node]){
      if(sign[x.fi] == 0){
        sign[x.fi] = -sign[node];
        ss[x.fi] = x.se - ss[node];
        dep[x.fi] = dep[node] + 1;
        bf.push(x.fi);
      }
      else if(dep[x.fi] == dep[node] + 1){
        if(ss[x.fi] != x.se - ss[node]){
          cout << 0 << "\n";
          return 0;
        }
      }
    }
  }
  ll vl;
  for(int i = 0 ; i < m ; i ++ ){
    if(dep[u[i]] == dep[v[i]]){
      vl = w[i] - ss[u[i]] - ss[v[i]];
      if(sign[u[i]] == -1) vl = -vl;
      if(vl % 2 == 1 || vl < 0){
        cout << 0 << "\n";
        return 0;
      }
      else{
        vl /= 2;
        L = max(L, vl);
        R = min(R, vl);
      }
    }
  }
  for(int i = 1; i <= n; i ++ ){
    if(sign[i] == +1){
      L = max(L, 1-ss[i]);
    }
    else{
      R = min(R, ss[i]-1);
    }
  }
  cout << max(0ll,R-L+1) << "\n";
  return 0;
}


Measured memory_bytes: 10100
class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod

    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod

mod = 998244353

N, M, K = map(int, input().split())

mc = ModComb(N, mod)

ans = 0
for k in range(K + 1):
    ans += M * pow(M - 1, N - 1 - k, mod) * mc.nCk(N - 1, k)
    ans %= mod

print(ans)

Measured memory_bytes: 32912
#include <bits/stdc++.h>
using namespace std;
char c[1000];
int cnt, num[1000], x[1000];
char s[1000][2000], now[2000];
typedef pair<int, int> pii;
priority_queue<pii, vector<pii>, greater<pii> >q;
int main() {
    for(int i = 0; i <= 9; ++i) c[++cnt] = i + '0';
    for(int i = 0; i < 26; ++i) c[++cnt] = i + 'a';
    for(int i = 0; i < 26; ++i) c[++cnt] = i + 'A';
    int len = 128;
    for(int i = 1; i <= cnt; ++i) {
        printf("? ");
        for(int j = 1; j <= len; ++j) printf("%c", c[i]);
        printf("\n");
        fflush(stdout);
        scanf("%d", &num[i]);
        num[i] = len - num[i];
        for(int j = 1; j <= num[i]; ++j)
            s[i][j] = c[i];
        if(num[i]) q.push(make_pair(num[i], i));
    }
    len = 0;
    for(int i = 1; i <= cnt; ++i) len += num[i];
    while(q.size() > 1) {
        int u = q.top().second; q.pop();
        int v = q.top().second; q.pop();
        int nc = 0, nownum = 0;
        for(int i = 0, j = 1; i <= num[u]; ++i) {
            int f = 1;
            if(i) now[++nownum] = s[u][i];
            while(f && j <= num[v]) {
                printf("? ");
                for(int k = 1; k <= nownum; ++k) printf("%c", now[k]);
                printf("%c", s[v][j]);
                for(int k = i + 1; k <= num[u]; ++k) printf("%c", s[u][k]);
                printf("\n");
                fflush(stdout);
                int t;
                scanf("%d", &t);
                if(nownum + num[u] - i + t + 1 == len) 
                    now[++nownum] = s[v][j], ++j;
                else f = 0;
            }
        }
        num[u] = nownum;
        for(int i = 1; i <= nownum; ++i)
            s[u][i] = now[i];
        q.push(make_pair(nownum, u));
    }
    int u = q.top().second;
    printf("! ");
    for(int i = 1; i <= num[u]; ++i)
        printf("%c", s[u][i]);
    printf("\n");
    fflush(stdout);
    return 0;
}


Measured memory_bytes: 3932
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <map>

using namespace std;

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

    map<string, int> S;
    int cmd, x;
    string key;
    while (q--)
    {
        cin >> cmd;
        if (cmd == 0)
        {
            cin >> key >> x;
            S[key] = x;
            // cout << S.size() << endl;
        }
        else if (cmd == 1)
        {
            cin >> key;
            // cout << (S.find(x) != S.end()) << endl;

            if (S.find(key) != S.end())
                cout << S[key] << endl;
            else
                cout << 0 << endl;

            //由于不存在键时，会以默认值插入,之后则无法插入相同键，所以不可用
            //  cout << S[key] << endl;
        }
        else if (cmd == 2)
        {
            cin >> key;
            S.erase(key);
            // remove(S.begin(), S.end(), x);
        }
        else
        {
            string L, R;
            cin >> L >> R;

            map<string ,int>::iterator it1 = S.lower_bound(L), it2 = S.upper_bound(R);
            while (it1 != it2)
            {
                cout << it1->first << ' ' << it1->second << endl;
                it1++;
            }

            //法2， 超时
            // map<string, int>::iterator it = S.begin();
            // while (it != S.end())
            // {
            //     if (it->first >= L && it->first <= R)
            //     cout << it->first << ' ' << it->second << endl;
            //     it++;                
            // }

        }

    }
}


Measured memory_bytes: 27820
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define ll long long
const int MAXN=300+10;
int A[MAXN][MAXN],n,P[MAXN][MAXN];
ll ans;
inline void read(int &x)
{
	int data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=(data<<3)+(data<<1)+(ch^'0'),ch=getchar();
	x=data*w;
}
int main()
{
	read(n);
	for(register int i=1;i<=n;++i)
		for(register int j=1;j<=n;++j)read(A[i][j]),ans+=A[i][j];
	for(register int k=1;k<=n;++k)
		for(register int i=1;i<=n;++i)
			for(register int j=1;j<=n;++j)
				if(i==j||j==k||i==k)continue;
				else if(A[i][k]+A[k][j]<A[i][j])
				{
					printf("-1\n");
					return 0;
				}
				else if(A[i][k]+A[k][j]==A[i][j])P[i][j]=P[j][i]=1;
	for(register int i=1;i<=n;++i)
		for(register int j=1;j<=n;++j)
			if(P[i][j])ans-=A[i][j];
	printf("%lld\n",ans>>1);
	return 0;
}


Measured memory_bytes: 1024
/**
*    author:  yuya1234
*    created: 08.07.2020 14:31:17
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define ALL(v) (s).begin(), (s).end()
#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

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

  string s[h];
  REP(i,h)cin>>s[i];

  vector<string> v;
  bool flg;
  REP(i,h)
  {
    flg=true;
    REP(j,w)
    {
      if(s[i][j]=='#')flg=false;
    }
    if(!flg)v.emplace_back(s[i]);
  }

  vector<string> ans(SZ(v),"");
  REP(i,w)
  {
    flg=true;
    REP(j,SZ(v))
    {
      if(v[j][i]=='#')flg=false;
    }
    if(!flg)
    {
      REP(k,SZ(v))ans[k]+=v[k][i];
    }
  }

  REP(i,SZ(ans))cout<<ans[i]<<endl;

  return 0;
}

Measured memory_bytes: 3716
#include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
#include<cmath>
#include<iostream>
using namespace std;
typedef long long LL;

map<pair <string,string>,LL> cnt;
const int maxn = 50;
char s[maxn];

int main(){
	int n; scanf("%d",&n);
	scanf("%s",s);
	for(int i = 0;i < (1 << n);i++){
		string s1 = "",s2 = "";
		for(int j = 0;j < n;j++){
			if(i & (1 << j)) s1 += s[j];
			else s2 += s[j];
		}
		cnt[make_pair(s1,s2)]++;
	}
	LL sum = 0;
	for(int i = 0;i < (1 << n);i++){
		string s1 = "",s2 = "";
		for(int j = n - 1;j >= 0;j--){
			if(i & (1 << j)) s1 += s[j + n];
			else s2 += s[j + n];
		}
		sum += cnt[make_pair(s1,s2)];
	}
	printf("%lld\n",sum);
}

Measured memory_bytes: 91904
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int X = sc.nextInt();
        
        int[] map = new int[M];
        for (int i = 0; i < M; i++) {
        	map[i] = sc.nextInt();
        }
        
        int max = 0;
        for (int i = X; i < N; i++) {
        	for (int cost : map) {
        		if (i == cost) {
        			max++;
        		}
        	}
        }
        
        int min = 0;
        for (int i = X; 0 < i; i--) {
        	for (int cost : map) {
        		if (i == cost) {
        			min++;
        		}
        	}
        }
        
        System.out.println(Math.min(max, min));
    }
}

Measured memory_bytes: 21716
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

class Main {
    public static void main(String[] args){
        try{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            String[] ss=br.readLine().split(" ");
            long A=Long.parseLong(ss[0]);
            long B=Long.parseLong(ss[1]);
            long N=Long.parseLong(ss[2]);
            long ans=0;
            if(B==1){
                System.out.println(0);
                return;
            }
            if(B>N){
                ans=(A*N)/B;
            }else{
                long p=B-1;
                while(p<=N){
                    ans=Math.max(ans,(A*p)/B-A*(p/B));
                    p+=B;
                }
            }
            System.out.println(ans);
        }catch(Exception e){
            System.out.println("KKKK "+e.getMessage());
        }
    }
    static int mod(int a,int b){
        if (a>b){
            return a-b;
        }
        return b-a;
    }
    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }
}


Measured memory_bytes: 32580
from itertools import accumulate
N, K = map(int, input().split())
p = [int(i) for i in input().split()]

expected = []
for i in range(N):
    expected.append((p[i]+1)/2)
m = [0] + list(accumulate(expected))
ans = 0
for i in range(1, len(m)-K+1):
    ans = max(ans, m[i+K-1] - m[i-1])
print(ans)

Measured memory_bytes: 26184
n = gets.to_i
t, a = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
ans = 0
min = 1000000
n.times do |i|
  tmp = (t-a-h[i]*0.006).abs
  if min > tmp
    ans = i+1
    min = tmp
  end
end
puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;
 
    // construct
    RollingHash(const string &S) {
        int n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }
    
    // get hash of S[left:right)
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }

    // get lcp of S[a:) and T[b:)
    inline int getLCP(int a, int b) const {
        int len = min((int)hash1.size()-a, (int)hash1.size()-b);
        int low = -1, high = len;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (get(a, a+mid) != get(b, b+mid)) high = mid;
            else low = mid;
        }
        return low;
    }
};

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    ll m = t.length();
    ll n = s.length();
    RollingHash T(t);
    RollingHash S(s);
    for(ll i=0;i<=n-m;i++){
    	if(S.get(i,i+m)==T.get(0,m)) cout << i << endl;
    }
    return 0;
}



Measured memory_bytes: 35572
#include <stdio.h>

int main(void){
  int N, X, count = 1, D = 0;
  scanf("%d %d", &N, &X);
  int L[N];

  int i;
  for(i=0 ; i<N ; i++)
    scanf("%d", &L[i]);

  for(i=0 ; i<N ; i++){
    D += L[i];
    if(D <= X)
      count++;
    else
      break;
  }
  printf("%d\n", count);

  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        scan.close();

        if (n == 1) {
            System.out.println(0);
        } else {
            System.out.println(1);
        }

    }
}


Measured memory_bytes: 35564
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
using namespace std;

int INF=1<<29;

int main(void){
    int n,m,r;
    cin>>n>>m>>r;
    vector<int> R(r);
    for(int i=0;i<r;i++){
        cin>>R[i];
    }
    
    sort(R.begin(),R.end());
    
    int w[300][300];//コスト
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            w[i][j]=INF;
            if(i==j)w[i][j]=0;
        }
    }
    
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        w[a][b]=c;
        w[b][a]=c;
    }

    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                w[i][j]=min(w[i][j],w[i][k]+w[k][j]);
            }
        }
    }
    
    int ans=INF;
    
    do{
        int sum=0;
        
        for(int i=0;i<r-1;i++){
            sum+=w[R[i]][R[i+1]];
        }
        
        ans=min(ans,sum);
        
    }while(next_permutation(R.begin(),R.end()));
    
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 512
/*
* @Author: 王文宇
* @Date:   2018-03-11 20:25:23
* @Last Modified by:   王文宇
* @Last Modified time: 2018-03-11 20:39:51
*/
#include <bits/stdc++.h>
using namespace std;
#define _for(i,a,b) for(int i=a;i<=b;i++)
int n,k;
int main(int argc, char const *argv[])
{
	long long ans = 0;
	cin>>n>>k;
	int g = 0;
	if(k==0)cout<<(long long)n*n<<endl;
	else
	{
		for(int i=k+1;i<=n;i++)
		{
			int now = i - k;
			int num = n/i;
			int xx = num*i;
			int kk = n-xx;
			int gg = 0;
			if(kk>=k)gg = kk-k+1;
			ans+=gg;
			ans+=now*num;
		}
		cout<<ans<<endl;		
	}

	return 0;
}

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

int main(){
  string S;
  cin >> S;
  if(S.size()%2==1){
    cout << "No" << endl;
    return 0;
  }
  for(int i=0;i<S.size();i++){
    if(i%2==0){
      if(S[i]!='h'){
        cout << "No" << endl;
        return 0;
      }
    }
    else{
      if(S[i]!='i'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,i,j,z=0,y=0,x=0,ma=0,mi=0x3f3f3f3f;
	char s[200005];
	int a,b,c,d,e,flag=0;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	if(a==0)
	printf("1\n");
	else if(b==0)
	printf("2\n");
	else if(c==0)
	printf("3\n");
	else if(d==0)
	printf("4\n");
	else
	printf("5\n");
} 

Measured memory_bytes: 3656
#include<iostream>
#include<map>

using namespace std;

map<long long, long long> cnt;
long long ps[200005];

int main(){
    int N;
    long long ans = 0;
    cin >> N;
    ps[0] = 0;
    cnt[0] = 1;
    for(int i=1; i<=N; i++){
        long long num;
        cin >> num;
        ps[i] = num + ps[i-1];
        cnt[ps[i]]++;
        if(cnt[ps[i]] > 1){
            ans+= cnt[ps[i]] - 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 14336