akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
struct RollingHash {
    const Int M1 = 1000000007, M2 = 1000000009;
    const Int BASE = 131;
    vector<Int> hash1, hash2, power1, power2;
    RollingHash(const string& s) {
        hash1.resize(s.size() + 1);
        hash2.resize(s.size() + 1);
        power1.resize(s.size() + 1);
        power2.resize(s.size() + 1);
        power1[0] = power2[0] = 1;
        for (int i = 0; i < s.size(); i++) {
            hash1[i+1] = (hash1[i] * BASE + s[i]) % M1;
            hash2[i+1] = (hash2[i] * BASE + s[i]) % M2;
            power1[i+1] = (power1[i] * BASE) % M1;
            power2[i+1] = (power2[i] * BASE) % M2;
        }
    }
    Int get(int l, int r) {
        Int h1 = (hash1[r] + (M1 - hash1[l]) * power1[r - l]) % M1;
        Int h2 = (hash2[r] + (M2 - hash2[l]) * power2[r - l]) % M2;
        return (h1 << 32) + h2;
    }
};
int main()
{
    string S, T; cin >> S >> T;
    string U;
    while (U.size() < max(S.size(), T.size())*3) U += S;
    auto rh = RollingHash(U);
    auto t = RollingHash(T).get(0, T.size());
    vector<int> dp(U.size()+1);
    for (int i = 0; i+T.size() <= U.size(); i++) {
        bool b = rh.get(i, i+T.size()) == t;
        if (b) {
            dp[i] = (i >= T.size() ? dp[i-T.size()] : 0) + b;
        }
    }
    int maxval = *max_element(begin(dp), end(dp));
    if (maxval * T.size() >= S.size()*2) {
        cout << -1 << endl;
    } else {
        cout << maxval << endl;
    }
    return 0;
}

Measured memory_bytes: 81480
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {
    int p, l, r;
};

Node T[MAX];
int n, D[MAX];

void print(int u) {
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";
    
    if(T[u].p == NIL) cout << "root, ";
    else if(T[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";
    
    cout << "[";
    for (i=0, c=T[u].l; c!= NIL; i++, c=T[c].r) {
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
} 

int rec(int u, int p) {
    D[u] = p;
    if (T[u].r != NIL) rec(T[u].r, p);
    if (T[u].l != NIL) rec(T[u].l, p+1);
}

int main() {
    int i, j, d, v, c, l, r;
    cin >> n;
    for (i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
    
    for (i=0; i<n; i++) {
        cin >> v >> d;
        for (j=0; j<d; j++) {
            cin >> c;
            if(j==0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    
    for (i=0; i<n; i++) {
        if(T[i].p == NIL) r=i;
    }
    
    rec(r, 0);
    
    for (i=0; i<n; i++) print(i);
    
    return 0;
}


Measured memory_bytes: 7704
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
 
using namespace std;
typedef long long ll;
 
int main()
{
  string s;
  cin >> s;
  int size = s.size();
  int ans = 1000;
  for (int i = 0; i < size - 2; i++)
  {
    int a = stoi(s.substr(i, 3));
    ans = min({ans, abs(a - 753)});
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
inf = 10**20
n,m = map(int, input().split())
flist = []
wbrnum = {}
for i in range(n):
    a = list(str(input()))
    flist.append(a)
    b = []
    b.append(a.count('W'))
    b.append(a.count('B'))
    b.append(a.count('R'))
    wbrnum[i] = b
cnt = inf
for i in range(n-2):
    cnti = 0
    for l in range(i+1):
        cnti += (wbrnum[l][1]+wbrnum[l][2])
    for j in range(i+1,n-1):
        cntj = 0
        cnto = 0
        for o in range(i+1,j+1):
            cntj += (wbrnum[o][0]+wbrnum[o][2])
        for o in range(j+1,n):
            cnto += (wbrnum[o][0]+wbrnum[o][1])
        cnt = min(cnt,(cnti+cntj+cnto))
        #print(i,j,cnti,cntj,cnto,cnt)
print(cnt)



Measured memory_bytes: 5608
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    const double pi = acos(-1);
    double R;
    cin >> R;

    printf("%.8f\n", 2*R*pi);

    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef pair <int,int> P;
string mp[501];
int m,n,used[30];
vector <P>  a[30];

int saiki(int);

bool check_x(int y,int x1,int x2){
  for(int i=x1+1;i<x2;i++)
    if(mp[y][i]!='.'&&!saiki(mp[y][i]-'A'))return 0;
  return 1;
}

bool check_y(int y1,int y2,int x){
  for(int i=y1+1;i<y2;i++)
    if(mp[i][x]!='.'&&!saiki(mp[i][x]-'A')) return 0;
  return 1;
}


int saiki(int ch){  
  int x1=a[ch][0].x,x2=a[ch][1].x;
  int y1=a[ch][0].y,y2=a[ch][1].y;
  int res=0;
  if(used[ch])return 0;
  used[ch]=1;
  
  if(x1==x2&&y2-y1!=1) res=check_y(y1,y2,x1);
  if(y1==y2&&x2-x1!=1) res=check_x(y1,x1,x2);

  if(x1!=x2&&y1!=y2) {
    if(x1<x2){
      res=check_x(y1,x1,x2+1)&check_y(y1,y2,x2);
      res|=check_y(y1,y2+1,x1)&check_x(y2,x1,x2);
    }
    else{
      swap(x1,x2);
      res=check_x(y1,x1-1,x2)&check_y(y1,y2,x1);
      res |=check_y(y1,y2,x2)&check_x(y2,x1,x2+1);
      swap(x1,x2);
    }
  }
    

  if(res) mp[y1][x1]=mp[y2][x2]='.',a[ch].clear();
  used[ch]=0;
  return res;
}

int main(){

  cin>>m>>n;
  for(int i=0;i<m;i++)cin>>mp[i];

  int ans=0;
  for(int i=0;i<m;i++)
    for(int j=0;j<n;j++)
      if(mp[i][j]!='.')a[mp[i][j]-'A'].push_back(P(j,i)),ans++;
  
  int flg=1;
  //  while(flg--)
    for(int i=0;i<30;i++)if(a[i].size() && saiki(i))flg=1;
  

  for(int i=0;i<m;i++)
    for(int j=0;j<n;j++) if(mp[i][j]!='.') ans--;

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

Measured memory_bytes: 1480
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <utility>
#include <numeric>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))

#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

static sl N;
static string S;

void solve(void) {
  if (N % 2 == 1) {
    cout << "No" << endl;
    return;
  }
  FOR0(i, N / 2) {
    if (S[i] != S[i + N / 2]) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
}

int main(void) {
  cin >> N;
  cin >> S;
  solve();
  return 0;
}

Measured memory_bytes: 764
N = int(input())
A = list(map(int, input().split()))
B = [0]*60
mod = 10 ** 9 + 7

for x in A:
  for i in range(60):
    B[i] += (x >> i) & 1

ans = 0
p = 1

for i in range(60):
  if i >= 1:
    p *= 2
    p %= mod
  ans += (N-B[i])*B[i]*p
  ans %= mod

print(ans)

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

#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d",&a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;


int32_t main()
{
    int n = in(), k = in();
    vector<int> a(n);
    for(auto &x: a) x = in();
    sort(a.rbegin(), a.rend());
    ll ans = 0;
    for(int i = k; i < n; i++) ans += a[i];
    cout << ans << nl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int n,k;
int c[55];
int dp[55][50005];
const int inf=1000000000;
int main(){
	cin>>n>>k;
	for(int i=1;i<=k;i++)cin>>c[i];
	memset(dp,0x7f,sizeof(dp));
	for(int j=1;j<=n;j++)dp[0][j]=inf;
	for(int i=0;i<=k;i++)dp[i][0]=0;
	for(int i=1;i<=k;i++)
		for(int v=0;v<=n;v++)
			dp[i][v]=min(dp[i-1][v],dp[i][v-c[i]]+1);
	cout<<dp[k][n]<<endl;
	return 0;
}


Measured memory_bytes: 13848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*既に塗った色の配列　tuple(親、子、その間の辺の色)の配列
  を用意
*/
struct edge{
    int to,color;
};

using Graph = vector<vector<edge>>;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<int> vecE(N);//vecE[i] = i番目までで右Eを見ている人数
    vector<int> vecW(N);//vecW[i] = i番目までで左Wを見ている人数
    
    if(S[0] == 'W'){ 
        vecW[0] = 1;
        vecE[0] = 0;
    }
    else {
        vecW[0] = 0;
        vecE[0] = 1;
    }
    

    for(int i = 1;i<N;i++){
        if(S[i] == 'W') vecW[i] = vecW[i-1] + 1;
        else vecW[i] = vecW[i-1];
    }
    for(int i = 1;i<N;i++){
        if(S[i] == 'E') vecE[i] = vecE[i-1] + 1;
        else vecE[i] = vecE[i-1];
    }
    int ans = 1000000;
    for(int i = 0;i<N;i++){
        int W = vecW[i-1];//i-1番目までの左Wを見ている人数
        int E = vecE[N-1] - vecE[i];//i+1~N-1番目までの右Eを見ている人数
        ans = min(ans,W+E); 
    }
    cout << ans << endl;
    
  }

Measured memory_bytes: 3076
input = gets.split.map(&:to_i)
ans = 3000
if input[1] - input[0] > 2020 then
  print 0
else
  (input[1] - input[0]).times{|t|
    n = t + input[0]
    k = n + 1
  while k <= input[1] and (k-input[0]) <=2020 do
   if ans > (n*k)%2019 then
      ans = (n*k)%2019
    end
    k+=1
  end
  }
  print ans
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<pii> R;
    for (int i = 0 ; i < a ; i++) {
        int v; cin >> v;
        R.push_back({v, 0});
    }
    for (int i = 0 ; i < b ; i++) {
        int v; cin >> v;
        R.push_back({v, 1});
    }
    for (int i = 0 ; i < c ; i++) {
        int v; cin >> v;
        R.push_back({v, 2});
    }
    sort(all(R));
    reverse(all(R));
    int sum = x + y;
    LL ans = 0;
    for (auto &p : R) {
        if (sum == 0)
            break;
        if (p.S == 2) {
            sum--;
            ans += p.F;
        } else if (p.S == 1 && y) {
            y--;
            sum--;
            ans += p.F;
        } else if (p.S == 0 && x) {
            x--;
            sum--;
            ans += p.F;
        }
    }
    cout << ans << '\n';
}


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

//最小公倍数lcm
static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return (long)(c/b);
}
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		long a = stdIn.nextLong();
		long b = stdIn.nextLong();
		long c = stdIn.nextLong();
		long d = stdIn.nextLong();
		
		long cnt = b-b/c-b/d+b/lcm(c,d);
		
		long ccnt = (a-1)-(a-1)/c-(a-1)/d+(a-1)/lcm(c,d);
		
		long ans = cnt - ccnt;
		System.out.println(ans);
		
	}

}


Measured memory_bytes: 21204
#include<cstdio>
#include<cstring>
#include<algorithm>
#define gt getchar()
#define ll long long
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
inline int in()
{
	int k=0;char ch=gt;
	while(ch<'-')ch=gt;
	while(ch>'-')k=k*10+ch-'0',ch=gt;
	return k;
}
const int N=1e5+5,inf=1e9;
char a[N],b[N];
int sum[2][27];
ll G;
int main()
{
	int n=in(),m=in();
	G=1ll*n*m/std::__gcd(n,m);
	scanf("%s%s",a+1,b+1);
	int an=G/m,am=G/n;
	for(int i=1,j=1;i<=n;i+=an,j+=am)if(a[i]!=b[j])return puts("-1"),0;
	printf("%lld\n",G);
	return 0;
}


Measured memory_bytes: 384
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<bitset>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<sstream>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int n,m;
int a[305][305];
int sum[305];
int now[305];
bool check(int x)
{
    int i;
    memset(sum,0,sizeof(sum));
    memset(now,0,sizeof(now));
    for (i=0;i<n;i++)
    {
        sum[a[i][0]]++;
    }
    for (;;)
    {
        for (i=0;i<m;i++)
        {
            if (sum[i]>x) break;
        }
        if (i==m) return true;
        //delete i
        sum[i]=-1;
        for (i=0;i<n;i++)
        {
            if (sum[a[i][now[i]]]!=-1) continue;
            for (;;)
            {
                if (sum[a[i][now[i]]]!=-1) break;
                now[i]++;
                if (now[i]==m) return false;
            }
            sum[a[i][now[i]]]++;
        }
    }
}
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    scanf("%d%d",&n,&m);
    int i;
    for (i=0;i<n;i++)
    {
        int j;
        for (j=0;j<m;j++)
        {
            scanf("%d",&a[i][j]);
            a[i][j]--;
        }
    }
    int ans;
    for (ans=1;ans<=n;ans++)
    {
        if (check(ans)) break;
    }
    printf("%d\n",ans);
    return 0;
}


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

int main()
{
	long long int n,k;cin>>n>>k;
	vector<long long int> v,b;
	for(long long int i=0;i<n;i++)
	{
		long long int p;cin>>p;
		v.push_back(p);
	}
	long long int count=0,cnt=0,a=0;
	b.push_back(0);
	for(long long int i=1;i<n;i++)
	{
		long long int mini=1e12+1;
		for(long long int j=(0>=i-k?0:i-k);j<i;j++)
		{
			if(mini>=(b[j]+abs(v[i]-v[j])))
				mini=b[j]+abs(v[i]-v[j]);
		}
		//cout<<v[i]<<" "<<mini<<endl;
		b.push_back(mini);
	}
	cout<<b[b.size()-1];
	return 0;
}

Measured memory_bytes: 2548
#include<stdio.h>

int main(){
  int h[100000];
  int w[100000];
  int count = 0;
  while(true){
    scanf("%d %d", &h[count], &w[count]);
    if(h[count] == 0 && w[count] == 0) break;
    count ++;
  }

  for(int i=0; i < count; i++){
    for(int tate=0; tate < h[i]; tate++){
      for(int yoko=0; yoko < w[i]; yoko++){
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  
  return 0;
}



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

using namespace std;

template<typename T>
long long modpow(const T n,const T p,const T mod);
template<typename T>
long long modinv(const T n,const T mod);
template<typename T>
bool chmax(T &a,const T &b);
template<typename T>
bool chmin(T &a,const T &b);

long long inf=1000000007;

int main(){
	string s;
	cin>>s;
	long long ans=0;
	for(long long i=0;i<3;i++){
		if(s.at(i)=='R') ans=1;
		if(i>0 && s.at(i)=='R' && s.at(i-1)=='R') ans=2;
	}

	if(s=="RRR") ans=3;

	cout<<ans<<endl;

	return 0;
}

template<typename T>
long long modpow(const T n,const T p,const T mod){
	if(p==0) return 1;
	if(p%2==0){
		long long a=modpow(n,p/2,mod);
		return a*a%mod;
	}
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}

template<typename T>
long long modinv(const T n,const T mod){
	return modpow(n,mod-2,mod);
}

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

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


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int n,T;
int x[10005],y[10005];
int ans=0x3f3f3f3f;
int main(){
	scanf("%d%d",&n,&T);
	for(int i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]);
	for(int i=1;i<=n;i++)
		if(y[i]>T) continue;
		else ans=min(ans,x[i]);
	if(ans==0x3f3f3f3f) printf("TLE\n");
	else printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,k,x,y;
  cin >> n >> k >> x >> y;
  int sum = 0;
  if(n > k){
    cout << k * x + (n-k) * y;
  }else{
    cout << n * x;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int H, W, h, w, Hh, Ww, a;
  
  scanf("%d %d", &H, &W);
  scanf("%d %d", &h, &w);
  Hh = H - h;
  Ww = W - w;
  a = Hh * Ww;
  printf("%d\n", a);
  return 0;
}



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

#define max 100001

typedef struct pp{
    char Name[12];
    long Time;
} TASK;

TASK Queue[max];
long head=0,tail=0;
long N,QT;

void Enqueue(TASK in){
    Queue[tail] = in;
    tail = (tail+1)%max;
}

TASK Dequeue(){
    TASK x = Queue[head];
    head = (head+1)%max;
    return x;
}

int main(){
    
    cin >> N >> QT;
    
    for (int i=0; i<N; i++) {
        TASK ii;
        cin >> ii.Name >> ii.Time;
        Enqueue(ii);
    }
    
    long time=0;
    
    while (head != tail) {
        TASK ii = Dequeue();
        
        if (ii.Time <= QT ){
            time += ii.Time;
            cout << ii.Name << " " << time << endl;
        }else{
            time += QT;
            ii.Time -= QT;
            Enqueue(ii);
        }
    }
    
    
    return 0;
}

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

#define ll long long int

#define cord(x, y) ((1000 * (x)) + (y))

using namespace std;

struct UnionFind {
    vector<ll> par;

    UnionFind(ll N) : par(N) {
        for(ll i = 0; i < N; i++) par[i] = i;
    }

    ll root(ll x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main() {
    ll h, w, ch, cw, dh, dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    --ch; --cw; --dh; --dw;

    UnionFind uf(1000000);

    vector<string> S(h);

    for (auto & s : S) {
        cin >> s;
    }

    for (ll i = 0; i < h; ++i) {
        for (ll j = 0; j < w; ++j) {
            if (S[i][j] == '#') continue;
            if (i+1 < h && S[i+1][j] == '.') uf.unite(cord(i,j), cord(i+1,j));
            if (i-1 >= 0 && S[i-1][j] == '.') uf.unite(cord(i,j), cord(i-1,j));
            if (j+1 < h && S[i][j+1] == '.') uf.unite(cord(i,j), cord(i,j+1));
            if (j-1 >= 0 && S[i][j-1] == '.') uf.unite(cord(i,j), cord(i,j-1));
        }
    }

    unordered_map<ll, set<pair<ll,ll>>> m;

    for (ll i = 0; i < h; ++i) {
        for (ll j = 0; j < w; ++j) {
            if (S[i][j] == '#') continue;
            ll r = uf.root(cord(i,j));
            if (m.find(r) == m.end()) {
                m[r] = set<pair<ll,ll>>();
            }
            m[r].insert(make_pair(i,j));
        }
    }

    unordered_map<ll, ll> dist;

    for (const auto& p : m){
        dist[p.first] = 1000001;
    }

    dist[uf.root(cord(ch, cw))] = 0;

    queue<ll> V;
    V.push(uf.root(cord(ch,cw)));

    while (!V.empty()) {
        ll t = V.front(); V.pop();
        ll cur = dist[t];
        for (const auto & p : m[t]) {
            //cerr << "checking from (" << p.first << "," << p.second << ") ";
            for (ll i = (p.first - 2)<0?0:p.first-2; i <= p.first + 2 && i < h; ++i) {
                for (ll j = (p.second - 2)<0?0:p.second-2; j <= p.second + 2 && j < w; ++j) {
                    if (S[i][j] == '#') continue;
                    //cerr << " (" << i << "," << j << ")";
                    if (dist[uf.root(cord(i,j))] > cur + 1) {
                        dist[uf.root(cord(i,j))] = cur + 1;
                        V.push(uf.root(cord(i,j)));
                    }
                }
            }
            //cerr << endl;
        }
    }

#if 0
    for (ll i = 0; i < h; ++i) {
        for (ll j = 0; j < w; ++j) {
            ll d = dist[uf.root(cord(i,j))];
            if (S[i][j] == '#') {
                cerr << "#"; continue;
            }
            if (d != 1000001) {
                cerr << d;
            } else {
                cerr << "-";
            }
        }
        cerr << endl;
    }
#endif

    ll res = dist[uf.root(cord(dh,dw))];
    if (res == 1000001) res = -1;
    cout << res << endl;
}


Measured memory_bytes: 53736
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;

int main() {
  int l;
  cin >> l;
  long double s=(l+0.1-0.1)/3;
  cout << fixed << setprecision(10);
  cout << s*s*s << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<algorithm>
typedef long long int ll;
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,a) for (int i=1;i<=(a);i++)
const ll MOD = (10*10*10*10*10*10*10*10*10+7);

    int A,B,C;
    int N,M,K,X,Y;
    int ans;
    bool f=true;

int main(){
    cin>>N>>K>>X>>Y;
    EREP(i,N){
        if(i<=K)ans+=X;
        else ans+=Y;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC
{
    class ProgramC
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            var n = long.Parse(inputs[0]);
            var m = long.Parse(inputs[1]);

            if (Math.Abs(n - m) > 1)
            {
                Console.WriteLine(0);
                return;
            }

            long nn = 1, nm = 1;
            for (var i = n; i > 1; i--)
            {
                nn = (nn * i) % (long)(1e9 + 7);
            }

            for (var i = m; i > 1; i--)
            {
                nm = (nm * i) % (long)(1e9 + 7);
            }

            var key = nn == nm ? 2 : 1;

            Console.WriteLine((nn * nm) % ((long)1e9 + 7) * key % ((long)1e9 + 7));
        }
    }
}


Measured memory_bytes: 27312
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m; cin >> n >> m;
  map<int,int> pc;
  for(int i = 0; i < n; i++){
    int k; cin >> k;
    for(int j = 0; j < k; j++){
      int x; cin >> x;
      pc[x]++;
    }
  }
  int ans = 0;
  for(auto it : pc) if(it.second == n) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include "stdio.h"

int main(int argc, char const *argv[]) {
  long long int K,A,B,m,ans;
  scanf("%lld%lld%lld", &K,&A,&B);
  if (B-A<=2 || K<A+1) {printf("%lld", K+1);return 0;}
  if ((K-A)%2==1) {
    m=(K-A-1)/2;
    ans=(B-A)*(m+1)+A;
  }else{
    m=(K-A-2)/2;
    ans=(B-A)*(m+1)+A+1;
  }
  printf("%lld", ans);
  return 0;
}


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

int main() {
	int r, c;

	while (cin >> r >> c, r || c) {
		if ((r * c) % 2 == 0) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2988
def read():
  return list(map(int,input().split()))

while 1:
  try:
    n,w,h=read()
    bases=[(0,0,0)]*n
    for i in range(n):
      bases[i]=read()
  except: break
  
  res1=True
  ls,rs=zip(*sorted([(x-w,x+w) for x,y,w in bases],key=lambda lr:lr[0]))
  x=0
  for l,r in zip(ls,rs):
    res1&=l<=x
    x=max(x,r)
  res1&=w<=x
  
  res2=True
  ls,rs=zip(*sorted([(y-w,y+w) for x,y,w in bases],key=lambda lr:lr[0]))
  x=0
  for l,r in zip(ls,rs):
    res2&=l<=x
    x=max(x,r)
  res2&=h<=x
  
  print("Yes" if res1 or res2 else "No")

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

int main(void){
    int n;
    std::cin >> n;
    std::vector<std::string> s(n);
    for(int i = 0; i < n; i++){
        std::cin >> s[i];
    }

    int m;
    std::cin >> m;
    std::vector<std::string> t(m);
    for(int i = 0; i < m; i++){
        std::cin >> t[i];
    }

    
    int counter;
    int maxv = 0;
    for(int i = 0; i < n; i++){
        counter = 0;
        for(int j = 0; j < n; j++){
            if(s[i] == s[j]){
                counter++;
            }
        }
        for(int ij = 0; ij < m; ij++){
            if(s[i] == t[ij]){
                counter--;
            }
        }
        maxv = std::max(maxv,counter);

    }
    if(maxv < 0){
        maxv = 0;
    }
    std::cout << maxv;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(){
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  string S;
  cin >> S;
  bool flag = true, flag_rep = false;
  for (int i=0; i<N; i++){
    if (i >= max(B - 1, 1) && i <= min(D - 1, (int)(S.size() - 1))){
      if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.'){
        flag_rep = true;
      }
    }
    if (i <= max(C - 3, D - 3) && i >= min(A - 1, B - 1) && i <= S.size() - 3){
      if (S[i + 1] == '#' && S[i + 2] == '#'){
        flag = false;
      }
    }
  }
  if (C < D) flag_rep = true;
  cout << (flag && flag_rep ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
    string s;
    cin>>s;
    cout<<s.substr(0,s.size()-8);
    system("pause");
    return 0;
}


Measured memory_bytes: 504
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue 优先队列
#include <map>
#include <set> //multiset  
#include <vector>
#include <stack>
#include <cmath>
#include <sstream>
#include <string>
#define mod 1000000007
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
const db eps=1e-6;
const int INF=0x3f3f3f3f;
const int N=2e5+5;
using namespace std;

ll n,m;
ll x;
int s=0;
bool check(ll y){
	for(ll i=2;i*i<=y;i++){
		if(y%i==0) return false;
	}
	return true;
}

int main(){
	cin>>n>>m;
	x=__gcd(n,m);
	for(ll i=1;i*i<=x;i++){
		if(x%i==0){
			if(check(i)) s++;
			if(check(x/i)) s++;
		}
		if(i*i==x&&check(i)) s--;
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 888
H,W = map(int,input().split())
L = []
blank = ['.' for _ in range(W+2)]
L.append(blank)

def cnt(x):
    if x == '#':
        return 1
    else:
        return 0

for _ in range(H):
    L.append(['.']+list(input())+['.'])
L.append(blank)

for i in range(1,H+1):
    for j in range(1,W+1):
        if L[i][j] == '#':
            print('#',end='')
        else:
            c = 0
            for x in [-1,0,1]:
                for y in [-1,0,1]:
                    if not (x==y==0):
                        c += cnt(L[i+x][j+y])
            print(c,end='')
    print()


Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {

	public static void main(String args[])
	{
		long dp[][][][]=new long[110][5][5][5];
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		
			if(n==1)System.out.println(4);
			else if(n==2)System.out.println(16);
			else {
				for(int i=0;i<4;i++)
				{
					for(int j=0;j<4;j++)
					{
						for(int k=0;k<4;k++)
						{
							dp[3][i][j][k]=1;
						}
					}
				}
				//AGCT
				dp[3][0][1][2]=0;
				dp[3][1][0][2]=0;
				dp[3][0][2][1]=0;
				long mod=1000000000+7;
				for(int cur=4;cur<=n;cur++)
				{
					for(int i=0;i<4;i++)
					{
						for(int j=0;j<4;j++)
						{
							for(int k=0;k<4;k++)
							{
								for(int l=0;l<4;l++)
								{
									
									if(j==0 && k==1 && l==2)continue;
									if(j==1 && k==0 && l==2)continue;
									if(j==0 && k==2 && l==1)continue;
									if(i==0 && j!=0 && k==1 && l==2)continue;
									if(i==0 && j==1 && k!=2 && l==2)continue;
									dp[cur][j][k][l]+=dp[cur-1][i][j][k];
									dp[cur][j][k][l]%=mod;
								}
							}
						}
					}
				}
				long sum=0;
				for(int i=0;i<4;i++)
				{
					for(int j=0;j<4;j++)
					{
						for(int k=0;k<4;k++)
						{
							sum+=dp[n][i][j][k];
							sum%=mod;
						}
					}
				}
				System.out.println(sum);
			}
		}
		
	
}


Measured memory_bytes: 21844
import sys
input = sys.stdin.readline
from collections import Counter

def main():
    n = int(input())
    a = map(int, input().split())
    counter = Counter(a)
    yield sum(1 for v in counter.values() if v%2==1)
    evens = sum(1 for v in counter.values() if v%2==0)
    if evens % 2 == 0:
        yield evens
    else:
        yield evens - 1


print(sum(main()))



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

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

int main()
{
    int n;
    cin >> n;
    vector<ll> h(n);
    vector<ll> d(n);
    int ma = 0;
    int now;
    cin >> now;
    int tmp = 0;
    rep(i, n-1) {
        int tm;
        cin >> tm;
        if (tm <= now) {
            tmp++;
        }else{
            ma = max(ma, tmp);
            tmp = 0;
        }
        now = tm;
    }
    ma = max(ma, tmp);
    cout << ma << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
typedef vector<ll> vll;
typedef pair<ll, ll> Pll;

ll N;

int main() {
    ll N, Z, W;
    cin >> N >> Z >> W;
    vll nums(N);
    for (int i = 0; i < N; ++i) {
        cin >> nums[i];
    }
    if (N == 1) {
        cout << abs(nums[0] - W) << endl;
    } else {
        cout << max(abs(nums[N - 1] - W), abs(nums[N - 2] - nums[N - 1])) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N= int(input())
h= list(map(int, input().split()))
 
dp = [0 for i in range(N)]
onedp = [0 for i in range(N)]
seconddp = [0 for i in range(N)]
 
for i in range(N-1):
    if onedp[i]<seconddp[i]:
        dp[i]=onedp[i]
    else:
        dp[i]=seconddp[i]
    if i!=N-2:
        seconddp[i+2]=dp[i]+abs(h[i+2]-h[i])
    onedp[i+1]=dp[i]+abs(h[i+1]-h[i])
    if i==0:
        seconddp[1]=onedp[1]
 
if onedp[N-1]<seconddp[N-1]:
    dp[N-1]=onedp[N-1]
else:
    dp[N-1]=seconddp[N-1]
print(dp[N-1])

Measured memory_bytes: 56764
fun main(args: Array<String>) {
    val input = readLine()!!.split(" ")
    var a = input[0].toInt() * 2 - 1
    var b= input[0].toInt() + input[1].toInt()
    var c = input[1].toInt() * 2 - 1
    println(
        if(a>b || c>b){
            if(a>c)a
            else c
        }else{
            b
        }
    )
}


Measured memory_bytes: 37708
#include<bits/stdc++.h>
using namespace std;
int n,m;
char s[200010];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k,l;
	scanf("%d%d%s",&n,&m,&s);
	for(i=1,j=0,k=0,l=0;i<=m;i++)
	  {
       if(k==0 && s[j]=='A')
         s[j]='B';
       else if(k==1 && s[j]=='B')
         s[j]='A';
       else
         {
          j=(j+1)%n;
          k^=1;
         }
       if(j)
         l=1;
       if(!j && l)
         break;
      }
    if(i<m)
      if(n&1)
        {
         if(m-i&1)
           printf("B");
         else
           printf("A");
         for(i=1;i<=n/2;i++)
           printf("BA");
        }
      else
        for(i=1;i<=n/2;i++)
          printf("BA");
    else
      for(i=j,l=0;!l || i!=j;i=(i+1)%n)
        {
         if(k)
           printf("%c",s[i]^'A'^'B');
         else
           printf("%c",s[i]);
         if(i!=j)
           l=1;
        }
	return 0;
}


Measured memory_bytes: 640
/* AtCoder My Practice
 * author: Leonardone @ NEETSDKASU
 */
#include <stdio.h>
#include <stdlib.h>

#define N_MAX (200001)

typedef struct _range {
    int upper, lower;
    struct _range *ubound, *lbound;
} Range;

Range *newRange(int lower, int upper) {
    Range *range = (Range*)malloc(sizeof(Range));
    range->lower = lower;
    range->upper = upper;
    return range;
}

int idx[N_MAX];
long long sum;
Range range;

void calc(int value, int index) {
    Range *tmp = &range;
    long long len1, len2, len3;
    for (;;) {
        if (tmp->lower <= index && index <= tmp->upper) {
            len1 = (long long)(tmp->upper - tmp->lower + 1);
            len2 = (long long)(tmp->upper - index);
            len3 = (long long)(index - tmp->lower);
            sum += (len1 * (len1 + 1LL) - (len2 * (len2 + 1LL)) - (len3 * (len3 + 1))) / 2LL * (long long)value;
            if (tmp->lower == index) {
                tmp->lower++;
            } else if (tmp->upper == index) {
                tmp->upper--;
            } else {
                tmp->lbound = newRange(tmp->lower, index - 1);
                tmp->ubound = newRange(index + 1, tmp->upper);
                tmp->lower = tmp->upper = index;
            }
            break;
        } else if (index < tmp->lower) {
            tmp = tmp->lbound;
        } else {
            tmp = tmp->ubound;
        }
    }
}


int main(void){
    int i, n;
    
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        idx[a] = i;
    }
    
    range.upper = n - 1;
    
    for (i = 1; i <= n; i++) {
        calc(i, idx[i]);
    }
    
    printf("%lld\n", sum);

    return 0;
}


Measured memory_bytes: 5120
#!python3

# input
K = int(input())


def solve(dp, i, j, s):
    if i == 0:
        return
    for k in range(max(0, j - 1), min(10, j + 2)):
        if s + dp[i][k] >= K:
            print(k, end="")
            return solve(dp, i - 1, k, s)
        else:
            s += dp[i][k]


def main():
    if K < 10:
        print(K)
        return
    dp = [[None], [1] * 10]
    sn = [[0] * 10, [i for i in range(10)]]
    i = 2
    while True:
        l = [0] * 10
        sl = [0] * 10
        l[0] = dp[i-1][0] + dp[i-1][1]
        sl[0] = sn[i-1][9]
        for j in range(1, 10):
            if j == 9:
                l[9] = dp[i-1][8] + dp[i-1][9]
            else:
                l[j] = dp[i-1][j-1] + dp[i-1][j] + dp[i-1][j+1]
            sl[j] = sl[j-1] + l[j]
            if sl[j] >= K:
                print(j, end="")
                solve(dp, i - 1, j, sl[j-1])
                return
        dp.append(l)
        sn.append(sl)
        i += 1


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int bit = 0;
    for(int i=0;i<N;i++){
      bit |= sc.nextInt();
    }
    System.out.println(Integer.numberOfTrailingZeros(bit));
  }
}

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

int main(){
	int A, B, c=0;
	cin >> A >> B;
	for(int i=A/10000; i<B/10000+1; i++){
		for(int j=0; j<10; j++){
			for(int k=0; k<10; k++){
				int x=10001*i+1010*j+100*k;
				if(A<=x&&x<=B) c++;
			}
		}
	}
	cout << c;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll)(a.size())
#define pll pair<ll,ll>
ll a[2005][2005];
ll count1[5000005];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll i,j,k,n,x,y;
	cin>>n>>x>>y;
	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			if(j <= x)
				a[i][j] = j-i;

			else if(i<=x && j >= x && j<=y)
				a[i][j] = min(j-i, x-i+1+y-j);

			else if(i<=x && j >= x && j >= y)
				a[i][j] = x-i+1+j-y;

			else if(i>=x && j >= x && j<=y)
				a[i][j] = min(j-i, i-x+1+y-j);

			else if(i>=x && j>=x && j>=y)
				a[i][j] = min(j-i, i-x+1+j-y);

			else if(i>=y && j>=y)
				a[i][j] = j-i;
			count1[a[i][j]]++;
		}
	}
	for(i=1;i<n;i++)
		cout<<count1[i]<<endl;
	return 0;
}

Measured memory_bytes: 31232
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define max1 100005
#define sz1 100001
#define mod 1000000007
#define moda 421412341324321ll
#define inf 1e18
#define ll long long int
#define debug(x) cout<<#x<<" "<<x<<endl
typedef pair<ll,ll> pr;
#define rte cout<<"Correct";exit(0);

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif*/
    ll x,y;
  cin>>x>>y;
  if(y<x)
  {
    cout<<"No\n";
  }
  else
  {
    cout<<"Yes\n";
  }
} 


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll X, Y;
  cin >> X >> Y;

  if(abs(X-Y)<=1){
    cout << "Brown" << endl;
  }else{
    cout << "Alice" << endl;
  }

  return 0;
}


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

int main() {
    int K, X;
    cin >> K >> X;
    int min, max;
    min = X - K + 1;
    max = X + K - 1;
    for (int i = min; i <= max; i++) {
        cout << i << " ";
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, gcd, lcm 
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string
#include <vector> // vector
#include <queue> // queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

int gcd(int a, int b) {
  if (b==0) return a;
  return gcd(b,a%b);
}

signed main() {
  int n;
  std::cin >> n;
  int ans;
  std::cin >> ans;
  rep(i,n-1) {
    int a;
    std::cin >> a;
    ans = gcd(ans,a);
  }
  std::cout << ans << ENDL;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>


using namespace std;

int main() {
    int n, p1, p2, cnt=0;
    cin >> n >> p1 >> p2;
    for (int i=2; i<n; i++) {
        int p3;
        cin >> p3;
        if (min(p1, p3) < p2 && p2 <= max(p1, p3)) cnt++;
        p1 = p2;
        p2 = p3;
    }
    cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut aseq = vec![0 as i32; n + 2];
    aseq[0] = 0;
    for i in 0..n {
        aseq[i + 1] = read();
    }
    aseq[n + 1] = 0;
    let mut dist_sums = vec![0; n + 2];
    for i in 0..n+1 {
        dist_sums[i + 1] = dist_sums[i] + (aseq[i] - aseq[i + 1]).abs();
    }
    for i in 1..n+1 {
        let dist = dist_sums[n + 1] - dist_sums[i + 1] + dist_sums[i - 1] + (aseq[i - 1] - aseq[i + 1]).abs();
        println!("{}", dist);
    }
}

Measured memory_bytes: 5244
attrs = Array.new
while line = $stdin.gets
  attrs << line.chomp.split
end

N, A, B = attrs[0].map{|a| a.to_i}
x = A + B
z = N / x
y = N % x
cnt = z * A
if y >= A then
  cnt += A
else
  cnt += y
end
puts cnt

Measured memory_bytes: 3836
#include<stdio.h>

int main(){

  int u,k,x,n,a[200][200],i,j,v;

  scanf("%d",&n);
  
  
  for(i = 1 ; i <= n ; i++)
    for(j = 1 ; j <= n ; j++)
      a[i][j] = 0;


  for(i = 1 ; i <= n ; i++){
    scanf("%d%d",&u,&k);

    for(j = 1 ; j <= k ; j++){
      scanf("%d",&v);
      a[i][v] = 1;
    }
  }

  for(i = 1 ; i <= n ; i++){
    for(j = 1 ; j <= n ; j++){
      
      if(j == n) printf("%d",a[i][j]);
      else printf("%d ",a[i][j]);
    }
  
  printf("\n");

  }
  return 0;
}

Measured memory_bytes: 684
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <limits.h>
#include <math.h>
#include <iomanip>
using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;

vector<int> A;
vector<int> MAXF, MAXB;

void solve() {
	int N;
	cin >> N;
	A.resize(N + 1);
	for (int n = 1; n <= N; n++)cin >> A[n];
	MAXF.resize(N + 2);
	MAXB.resize(N + 2);
	MAXF[1] = A[1];
	for (int n = 2; n <= N; n++)MAXF[n] = max(A[n], MAXF[n - 1]);
	MAXB[N] = A[N];
	for (int n = N - 1; n >= 1; n--)MAXB[n] = max(A[n], MAXB[n + 1]);
	MAXF[0] = 0; MAXF[N + 1] = 0;
	MAXB[0] = 0; MAXB[N + 1] = 0;
	for (int n = 1; n <= N; n++)cout << max(MAXF[n - 1], MAXB[n + 1]) << endl;
	return;
}

Measured memory_bytes: 3968
#include <iostream>
#include <cstring>
using namespace std;
int N;
char Str[300005];
int Partial[2][300005];
void Read()
{
    cin >> N;
    cin.get();
    cin.getline(Str + 1, 300005);
    for(int i = 1; Str[i] != 0; i++)
    {
        Partial[0][i] = Partial[0][i - 1];
        if(Str[i] == 'W')
            ++Partial[0][i];
    }
    int len = strlen(Str + 1);
    for(int i = len; i >= 1; i--)
    {
        Partial[1][i] = Partial[1][i + 1];
        if(Str[i] == 'E')
            ++Partial[1][i];
    }
}

void Solve()
{
    int ans = N + 5;
    for(int i = 1; i <= N; i++)
    {
        ans = min(ans, Partial[0][i - 1] + Partial[1][i + 1]);
    }
    cout << ans << "\n";
}
int main()
{
    Read();
    Solve();
    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
    string s;
    string t;
    cin >> s;
    cin >> t;
    int t_size = t.size();
    s = s + t[t_size-1];
    if (s == t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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

    int A, B, M;
    cin>>A>>B>>M;
    vector<int> as(A), bs(B);
    rep(i, A) cin>>as[i];
    rep(i, B) cin>>bs[i];
    vector<int> x(M), y(M), c(M);
    rep(i, M) {
        cin>>x[i]>>y[i]>>c[i];
        x[i]--; y[i]--;
    }

    int ans = INT_MAX;
    rep(i, M) {
        int cur = as[x[i]] + bs[y[i]] - c[i];
        if (cur < ans) ans = cur;
    }

    int mina = *min_element(as.begin(), as.end());
    int minb = *min_element(bs.begin(), bs.end());
    if (mina + minb < ans) ans = mina + minb;

    cout<<ans<<endl;
}

Measured memory_bytes: 2176
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  string s;
  cin >> s;
  for (char &x : s) x = (x - 'A' + 23) % 26 + 'A';
  cout << s << endl;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N,K;
  string S;
  cin>>N>>K>>S;
  S[K-1]-='A'-'a';
  cout<<S<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

#define INF 1 << 29
#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++)

using namespace std;

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

int abs(int x){
  return x > 0 ? x : -x;
}

int length(char c[]){
  int cnt=0;
  for(cnt=0;c[cnt]!='\0';cnt++){
  }
  return cnt;
}

int n;
int d[1000000];
int a;
int mx=0;
int ax=0;

int main(){
  scanf("%d",&n);
  REP(i,n){
    scanf("%d",&a);
    d[a-1]++;
    d[a]++;
    d[a+1]++;
    ax = max(ax,a+1);
  }
  REP(i,ax){
    mx = max(mx,d[i]);
  }
  printf("%d\n",mx );
}


Measured memory_bytes: 512
X = list(str(input()))
n = len(X)

s = []
for x in X:
    if x == 'S':
        s.append(x)
    if x == 'T':
        if s:
            if s[-1] == 'S':
                s.pop()
            else:
                s.append(x)
        else:
            s.append(x)
print(len(s))


Measured memory_bytes: 11988