akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;
int main(){
    int i,b=0,c=0,e=1;
    char a,d;
    string s[2],t;
    for (i=0; i<2; i++){
        cin >> s[i];
    }
    t = s[0] + s[1];


    for (i =t.length()-1; i>=0; i--){
        b = b + int(t[i] -'1'+1)*e;
        e = e*10;
    }
    for(i = 1; i<=100100; i++){
        if(i*i == b){
            cout << "Yes";
            c++;
        }
    }
    if(c == 0){
        cout << "No";
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define nl "\n"
#define pb push_back
#define E esit(0)
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
const int N=1e5+5;
const int INF=1e9+7;

vector<int> g[N];
int d[N],in_degree[N];
bool used[N];

void dfs (int v) {
    used[v]=true;
    for (auto e: g[v]) {
        d[e]=max(d[e],d[v]+1);
        in_degree[e]--;
        if (in_degree[e]==0) {
            dfs(e);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    for (int i=1;i<=m;i++) {
        int x,y;
        cin>>x>>y;
        g[x].pb(y);
        in_degree[y]++;
    }
    for (int i=1;i<=n;i++){
        if (!used[i] && in_degree[i]==0) {
            dfs(i);
        }
    }
    int ans=0;
    for (int i=1;i<=n;i++) {
        ans=max(ans,d[i]);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 14644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main() {
  int N,M;
  cin >> N >> M;
  int A[M];
  int sum=0;
  for(int i=0;i<M;i++){
    cin >> A[i];
    sum+=A[i];
  }
  if(sum>N){
    cout << "-1";
  }
  else{
    cout << N-sum;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long a, b, c, d;
  cin >> a >> b >> c >> d;
  
  long sum = b - a + 1;
  sum -= ( b / c - ( a - 1 ) / c );
  sum -= ( b / d - ( a - 1 ) / d );
  
  long x = c * d;
  
  long tmp;
  if ( d < c ) {
    tmp = c;
    c = d;
    d = tmp;
  }
  
  tmp = d % c;
  while ( tmp != 0 ) {
    d = c;
    c = tmp;
    tmp = d % c;
  }
  x /= c;
  
  sum += ( b / x - ( a - 1 ) / x );

  cout << sum << endl;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)

ll N;
ll A[100005];
ll pgcd[100005];
ll sgcd[100005];
ll gcd(ll a,ll b){
if(a<b) swap(a,b);
if(a%b==0) return b;
else return gcd(a%b,b);
}
ll ans;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;

rep(i,N) cin>>A[i];

pgcd[0]=A[0];
rep1(i,N){
	pgcd[i]=gcd(pgcd[i-1],A[i]);
}
sgcd[N-1]=A[N-1];
rep1(i,N){
	ll j=N-i;
	sgcd[j-1]=gcd(sgcd[j],A[j-1]);
}

rep(i,N){
	if(i==0){
		ans=max(ans,sgcd[1]);
	}else if(i==N-1){
		ans=max(ans,pgcd[N-2]);
	}else{
		ans=max(ans,gcd(pgcd[i-1],sgcd[i+1]));
	}
}

cout<<ans<<endl;


}
	


Measured memory_bytes: 2560
N,T = map(int, input().split())
c = []
t = []

for i in range(N):
    a,b = map(int, input().split())
    c.append(a)
    t.append(b)
m = 10000
for i in range(N):
    if t[i] <= T:
        m = min(m, c[i])

if m == 10000:
    print("TLE")
else:
    print(m)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{

    ll N,K;
    cin >> K >> N ;
    vector<ll> A;
    for(int i=0; i<N; ++i)
    {
        ll tmp;
        cin >> tmp;
        A.push_back(tmp);
    }
    ll mxDist = min(A[N-1]-A[0],K-A[N-1]+A[0]);
    for(int i=0; i<N-1; ++i)
    {
        if(mxDist<A[i+1]-A[i]) mxDist = A[i+1]-A[i];
    }

    cout << K-mxDist << endl;

    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, M;
    vector<ll> dp;
    vector<bool> ok;
    cin >> N >> M;
    dp.resize(N + 1);
    ok.resize(N + 1, true);
    rep(i, M) {
        ll temp;
        cin >> temp;
        ok[temp] = false;
    }
    dp[0] = 1;
    rep(i, N) {
        repi2(j, i + 1, min(i + 2, N)) {
            if(ok[j]) {
                dp[j] += dp[i];
                dp[j] %= MOD;
            }
        }
    }
    cout << dp[N] << endl;
    return 0;
}


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

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;
 
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;

int main() {
  
  int a,b;
  cin >> a >> b;
  
  string s;
  cin >> s;
  
  for ( int i = 0; i < s.size(); i++){
    if ( i < a  || i > a){
      if ( s[i] == '-' ){
        cout << "No" << endl;
        return 0;
      }
    }else if ( i == a ){
      if ( s[i] != '-' ){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  
  cout << "Yes" << endl;

}

Measured memory_bytes: 256
s = input().split()
N = int(s[0])
A = int(s[1])
B = int(s[2])

if A == 0:
    print(0)
elif B == 0:
    print(N)
else:
    # A+Bの組がいくつ存在するか
    set_count = N // (A+B)
    # 余り
    mod = N % (A+B)
    
    if mod == 0:
        print(A*set_count)
    else:
        if mod < A:
            print(A*set_count+mod)
        else:
            print(A*set_count+A)

Measured memory_bytes: 3064
import java.util.*;

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

class Solver {

    private String minimize(String s) {
        String buf = new String(s);
        char[] a = buf.toString().toCharArray();
        Arrays.sort(a);
        return new String(a);
    }

    private String maximize(String s) {
        String buf1 = new String(s);
        char[] a = buf1.toString().toCharArray();
        Arrays.sort(a);
        return new StringBuilder(new String(a)).reverse().toString();
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();

        String sd = minimize(s);
        String td = maximize(t);

        int ret = sd.compareTo(td);
        if (ret < 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

        return;
    }

}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    begin(v), end(v)
#define in        []{lint n; cin>>n; return n;}()

int main(){ cin.tie(0); ios::sync_with_stdio(false);
    int N = in;
    vector<int> A(N);
    rep( i, N ) A[i] = in;
    int M = INT_MIN;
    rep( i, N ) M = max( M, A[i] );
    int R = INT_MIN;
    rep( i, N ) if( A[i] != M && abs(M/2-A[i]) < abs(M/2-R) ) R = A[i];
    cout << M << " " << R << "\n";
}


Measured memory_bytes: 640
A, B, C, X, Y = map(int, input().split())
ans = 0
ans = A * X + B * Y
tmp_ans = C * (X + Y) * 2
if tmp_ans < ans:
    ans = tmp_ans

tmp_ans = (Y * 2) * C
tmp_ans += max((X - Y), 0) * A
if tmp_ans < ans:
    ans = tmp_ans

tmp_ans = (X * 2) * C
tmp_ans += max((Y - X), 0) * B
if tmp_ans < ans:
    ans = tmp_ans
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	vector<int> a[n];
	for(int i = 0,j,k;i<m; i++)
	{
		cin>>j>>k , --j,--k;
		a[k].push_back(j);
		a[j].push_back(k);
	}
	if(n==2)
	{
		cout<<1<<endl;
		return 0;
	}
	vector<int> v(n-1);
	iota(v.begin(),v.end(),1);
	int count = 0;
	int fact = 1;
	for(int i = 1;i<n;i++)
		fact *= i;
	int ans = 0;
	while(count<fact)
	{
		count++;
		if(find(a[0].begin(),a[0].end(),v[0])!=a[0].end())
		for(int i = 1; i<n-1; i++)
		{
			if(find(a[v[i]].begin(),a[v[i]].end(),v[i-1])==a[v[i]].end())
				break;
			else if(i==n-2)
				ans++;
		}
		next_permutation(v.begin(),v.end());
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 414514
set<int> G[MAX];
int indeg[MAX];
bool V[MAX];
vector<int> p;
void bfs(int s){
  queue<int> q;
  q.push(s);
  V[s]=1;
  while(!q.empty()){
    int u=q.front();q.pop();
    p.push_back(u);
    for(int v:G[u]){
      indeg[v]--;
      if(indeg[v]==0&&!V[v]){
	V[v]=1;
	q.push(v);
      }
    }
  }
}
void tsort(int n){
  memset(V,0,sizeof(V));
  memset(indeg,0,sizeof(indeg));
  for(int u=0;u<n;u++)
    for(int v:G[u])
      indeg[v]++;
  for(int u=0;u<n;u++)
    if(indeg[u]==0&&!V[u]) bfs(u);

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

signed main(){
  int n,e;
  cin>>n>>e;
  for(int i=0;i<e;i++){
    int s,t;
    cin>>s>>t;
    G[s].insert(t);
  }
  tsort(n);
  return 0;
}

/*
verified on 2017/04/28
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_4_B&lang=jp
*/

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

int main(void){
   long long a,b,x;
   cin>>a>>b>>x;
   long long L,R;
   if(a%x==0){
      L=a/x;
   }else{
      L=a/x+1;
   }
   if(b%x==0){
      R=b/x;
   }else{
      R=b/x;
   }
   long long ans=R-L+1;
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
import collections
import numpy as np
import sys
import copy
N=int(input())
#W,H,X,Y=map(int,input().split())
A=list(map(int,input().split()))
B=[0 for i in range(N-1)]
for i in range(N-1):
    B[i]=abs(A[i+1]-A[i])
A=[0]+A+[0]
B=[abs(A[1])]+B+[abs(A[-2])]
tot=sum(B)
for i in range(1,N+1):
    if (A[i+1]-A[i])*(A[i]-A[i-1])>=0:
        print(tot)
    else:
        print(tot-min(B[i-1],B[i])*2)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B, C, D, E;
  cin >> A >> B;
  C=A+B;
  D=A-B;
  E=A*B;
  cout << max(max(C,D),E) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int a[3][3],b[3][3]={0};
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
			cin>>a[i][j];
	}
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int b1;
		cin>>b1;
		for(int j=0;j<3;j++)
		{
			for(int k=0;k<3;k++)
				if(a[j][k] == b1)
					b[j][k] = 1;
		}
	}
	bool isok = false;
	if(((b[0][0] == b[0][1]&&b[0][1] == b[0][2]&&b[0][0]&&b[0][1]&&b[0][2])||
	  (b[1][0] == b[1][1]&&b[1][1] == b[1][2]&&b[1][0]&&b[1][1]&&b[1][2])||
	  (b[2][0] == b[2][1]&&b[2][1] == b[2][2]&&b[2][0]&&b[2][1]&&b[2][2]))
	  )
	  isok = true;
	if((b[0][0] == b[1][0]&&b[1][0] == b[2][0]&&b[0][0]&&b[1][0]&&b[2][0])||
	(b[0][1] == b[1][1]&&b[1][1] == b[2][1]&&b[0][1]&&b[1][1]&&b[2][1])||
	(b[0][2] == b[1][2]&&b[1][2] == b[2][2]&&b[0][2]&&b[1][2]&&b[2][2]))
	 isok = true;
	 if((b[0][0] == b[1][1]&&b[1][1] == b[2][2]&&b[0][0]&&b[1][1]&&b[2][2])||
	   (b[0][2] == b[1][1]&&b[1][1] == b[2][0]&&b[0][2]&&b[1][1]&&b[2][0]))
	   isok = true;
	if(isok)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n, x;
  cin >> n >> x;
  int count = 0;
  while(n!=0 || x!=0){
    for(int i=1; i<=n; i++)
      for(int j=i+1; j<=n; j++)
        for(int k=j+1; k<=n; k++)
          if(i+j+k == x)
            count++;
    cout << count << endl;
    count = 0;
    cin >> n >> x;
  }

  return 0;
}


Measured memory_bytes: 3092
from collections import deque


def main():
    h, w = map(int, input().split())
    ch, cw = map(int, input().split())
    dh, dw = map(int, input().split())

    """
    l = [list(input().strip()) for i in range(h)]
    ans = [[-1]*w for i in range(h)]
    for i in range(h):
        for j in range(w):
            if l[i][j] == "#":
                ans[i][j] = -2
    ch -= 1
    cw -= 1
    dh -= 1
    dw -= 1
    """

    base = ["#" * (w + 4)]
    base.append("#" * (w + 4))
    for n in range(h):
        base.append("##" + input() + "##")
    base.append("#" * (w + 4))
    base.append("#" * (w + 4))
    ans = [[-1] * (w + 4) for _ in range(h + 4)]
    for i in range(h + 4):
        for j in range(w + 4):
            if base[i][j] == "#":
                ans[i][j] = -2
    ch += 1
    cw += 1
    dh += 1
    dw += 1
    
    ans[ch][cw] = 0
    move1 = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    move2 = [
        [-2, -2], [-2, -1], [-2, 0], [-2, 1], [-2, 2], [-1, -2], [-1, -1],
        [-1, 1], [-1, 2], [0, -2], [0, 2], [1, -2], [1, -1], [1, 1],
        [1, 2], [2, -2], [2, -1], [2, 0], [2, 1], [2, 2]
    ]
    q1 = deque([[ch, cw]])
    q2 = deque([])

    while q1:
        x1, y1 = q1.popleft()
        q2.append([x1, y1])
        for i, j in move1:
            nx, ny = x1 + i, y1 + j
            """
            if nx < 0 or h <= nx or ny < 0 or w <= ny:
                continue
            """
            if ans[nx][ny] == -1:
                ans[nx][ny] = ans[x1][y1]
                q1.append([nx, ny])
        if len(q1) == 0:
            while q2:
                x2, y2 = q2.popleft()
                for i, j in move2:
                    mx, my = x2 + i, y2 + j
                    """
                    if mx < 0 or h <= mx or my < 0 or w <= my:
                        continue
                    """
                    if ans[mx][my] == -1:
                        ans[mx][my] = ans[x2][y2] + 1
                        q1.append([mx, my])
    print(ans[dh][dw])


if __name__ == "__main__":
    main()




Measured memory_bytes: 23492
H, W = map(int, input().split())
S = [input() for _ in range(H)]

res = [[float('inf')]*(W) for _ in range(H)]

if S[0][0] == '#':
    res[0][0] = 1
else:
    res[0][0] = 0

for h in range(H):
    for w in range(W):
        if h == 0:
            if w == 0:
                continue
            else:
                res[h][w] = res[h][w-1] + (1 if S[h][w] == '#' and S[h][w-1] == '.' else 0)
        else:
            if w == 0:
                res[h][w] = res[h-1][w] + (1 if S[h][w] == '#' and S[h-1][w] == '.' else 0)
            else:
                f_t = res[h-1][w] + 1 if S[h][w] == '#' and S[h-1][w] == '.' else res[h-1][w]
                f_l = res[h][w-1] + 1 if S[h][w] == '#' and S[h][w-1] == '.' else res[h][w-1]
                res[h][w] = min(f_t, f_l)

print(res[H-1][W-1])


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ll long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fr(i, a, b) for(int i=a; i>=b; i--)
#define l long int
#define endl '\n'
#define pb push_back
#define pf pop.front()
using namespace std;


void solve()
{
string s;
cin>>s;

int n =s.length();
if(s[n-1] == 's')
{
	cout<<s<<"es";
}
else
cout<<s<<"s";
}


int32_t main()
{
FAST
l T=1;
//cin>>T;
while(T--)
{
solve();
}
}










Measured memory_bytes: 3660
N, M = map(int, input().split())
xyz = []
for _ in range(N):
    x, y, z = map(int, input().split())
    xyz.append((x, y, z))

ans = 0

# 綺麗さ、美味しさ、人気度について、
# 正の方向に最大化するか、負の方向に最大化するか
# 2*2*2 = 8通り

# ex. 正、正、負の場合
# x + y - z を計算してソートし、上からM個の総和を取る

for a in [-1, 1]:
    for b in [-1, 1]:
        for c in [-1, 1]:
            tmp = []
            for i in range(N):
                tmp.append(a * xyz[i][0] + b * xyz[i][1] + c * xyz[i][2])
            tmp.sort(reverse=True)

            tmp2 = sum(tmp[:M])
            ans = max(ans, tmp2)

print(ans)


Measured memory_bytes: 74020
fun main(args: Array<String>) {
    val (n,d) = readLine()!!.split(" ").map { it.toInt()}
    val range = (d * 2) + 1
    if (n % range == 0) {
        println (n / range)
    } else {
        println ((n / range) + 1)
    }
}

Measured memory_bytes: 35900
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int arr[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin>>n;
    cout<<arr[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N,A,B,C; cin>>N>>A>>B>>C;
  vi L(N);
  rep(i,0,N) cin>>L[i];
  int ans=MOD;
  rep(i,1,(1<<N)){
    bitset<8> X(i);
    int K=X.count();
    if(K>N-2)
      continue;
    int b=MOD;
    int sum=0;
    vi P;
    rep(j,0,N){
      if(X.test(j))
        sum+=L[j];
      else
        P.push_back(j);
      }
    sum=abs(sum-A)+(X.count()-1)*10;
    int sum1=MOD;
    rep(j,1,(1<<(int)P.size())-1){
      bitset<8> Y(j);
      int KK=Y.count();
      int sum2=0;
      vi Q;
      rep(k,0,P.size()){
        if(Y.test(k))
          sum2+=L[P[k]];
        else
          Q.push_back(P[k]);
        }
      sum2=abs(sum2-B)+(Y.count()-1)*10;
      int sum3=MOD;
      rep(l,1,(1<<((int)Q.size()))){
        bitset<8> Z(l);
        int sum4=0;
        rep(a,0,Q.size()){
          if(Z.test(a))
            sum4+=L[Q[a]];
          }
        sum4=abs(sum4-C)+(Z.count()-1)*10;
        sum3=min(sum4,sum3);
        }
      sum1=min(sum1,sum2+sum3);
      }
    ans=min(sum+sum1,ans);
    }
  cout<<ans<<endl;
  }

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String S = sc.next();
		char[] c = S.toCharArray();
		
		int count = 0;
		long ans = 0;
		
		for(int i = 0; i < S.length(); i++) {
			if(c[i]=='W') {
				ans += i-count;
				count++;
			}
		}
		System.out.println(ans);
		
		
	}
	

}


Measured memory_bytes: 40952
#include<iostream>
#include<string>
#include<cstring>
#include<cctype>


using namespace std;
int main(void)
{


    string a,b;
    int x;
    int ans = 0;

    cin >> a >> x;

    for(int i = 0; i < x; i++){
        cin >> b;
        b += b;
        if(b.find(a) != string::npos)ans++;
    }

    cout << ans << endl;

    return 0;

}

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

int main() {
  long n; cin >>n;
  long ans = 10000000000000;
  long buf = 0;
  
  for (long i=1; i<n; i++){
    if (i*i > n){ break;}
    if (n%i == 0){
      buf = i + (n/i) - 2;
      if (buf < ans){
        ans = buf;
      }
    }
  }
  cout <<ans <<endl;
      
      
}


Measured memory_bytes: 384
H,W = map(int,input().split())
if H%3 == 0 or W%3 == 0:
    print(0)
else:
    ans = min(H,W)
    if W%2 == 0:
        ans = min(ans,W//2)
    else:
        if H%3 == 1:
            ans = min(ans,(W+1)//2+(H-1)//3)
        else:
            ans = min(ans,(W+1)//2+(H-2)//3)
    if H%2 == 0:
        ans = min(ans,H//2)
    else:
        if W%3 == 1:
            ans = min(ans,(H+1)//2+(W-1)//3)
        else:
            ans = min(ans,(H+1)//2+(W-2)//3)
    print(ans)

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

int base;
int tod(int b,int ka,int t,int w,int ki){
	ka+=b*20;t+=ka*20;w+=18*t;ki+=20*w;
	return base+ki;
}
bool is_uruu(int y){
	return y%4==0&&(y%100!=0||y%400==0);
}
int mn[]{31,28,31,30,31,30,31,31,30,31,30,31};
int calc(int y,int m,int d){
	int res=(y-1)*365+(y-1)/4-(y-1)/100+(y-1)/400;
	for(int i=1;i<m;i++){
		res+=mn[i-1];if(is_uruu(y)&&i==2)res++;
	}
	return res+d;
}
int tod(int y,int m,int d){
	return calc(y,m,d)-base;
}
void tom(int day){
	int b,ka,t,w,ki;
	ki=day%20;day/=20;
	w=day%18;day/=18;
	t=day%20;day/=20;
	ka=day%20;day/=20;
	b=day%13;
	printf("%lld.%lld.%lld.%lld.%lld\n",b,ka,t,w,ki);
}
void tos(int day){
	int y,m;
	for(y=1;365+is_uruu(y)<day;y++)day-=365+is_uruu(y);
	for(m=1;mn[m-1]+(m==2&&is_uruu(y))<day;m++)day-=mn[m-1]+(m==2&&is_uruu(y));
	printf("%lld.%lld.%lld\n",y,m,day);
}
signed main() {
	base=calc(2012,12,21);
	string s;
	while(cin>>s,s!="#"){
		s+='.';
		vector<int>v;
		string t;
		for(char c:s){
			if(c=='.')v.push_back(stoi(t)),t="";
			else t+=c;
		}
		if(v.size()==3)tom(tod(v[0],v[1],v[2]));
		else tos(tod(v[0],v[1],v[2],v[3],v[4]));
	}
}

Measured memory_bytes: 3232
n = int(input())
a = list(map(int, input().split()))
tmp = a[0] - 1
ans = "Yes"
for i in range(1, n):
    if a[i] < tmp:
        ans = "No"
        break
    elif a[i] == tmp:
        tmp = a[i]
    else:
        tmp = a[i] - 1
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  vector<int> l(Q);
  vector<int> r(Q);
  for (int i = 0; i < Q; i++){
    cin >> l.at(i) >> r.at(i);
  }
  vector<int> num(N);
  num.at(0) = 0;
  for (int i = 0; i < N-1; i++){
    if(S.at(i) == 'A' && S.at(i+1) == 'C'){
      num.at(i+1) = num.at(i) + 1;
    } else {
      num.at(i+1) = num.at(i);
    }
  }
  for (int i = 0; i < Q; i++){
    int ans =num.at(r.at(i)-1) - num.at(l.at(i)-1);
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;
using ll = long long;
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
template<class T, class S>
ostream &operator <<(ostream& out,const map<T,S>& a){
    out<<'['; for(auto i: a) {out<<i<<',';} out<<']'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const set<T>& a){
    out<<'['; for(auto i: a) {out<<i<<',';} out<<']'; return out;
}
template<class T, class S>
ostream &operator <<(ostream& out,const unordered_map<T,S>& a){
    out<<'['; for(auto i: a) {out<<i<<',';} out<<']'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const unordered_set<T>& a){
    out<<'['; for(auto i: a) {out<<i<<',';} out<<']'; return out;
}

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

    ll a, b;
    cin >> a >> b;

    ll t = a;
    vector<ll> v;
    for(ll i=2; i*i<=t; ++i) {
        if(t%i==0 && b%i==0) v.push_back(i);
        while(t%i==0) t /= i;
    }
    if(t>1 && b%t==0) v.push_back(t);

    // cerr << v << endl;
    cout << v.size()+1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<string,int>> vpsi;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

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

int a,b;
cin >> a >> b;
if(a%2==b%2){
    fin((a+b)/2);
}else{
    fin("IMPOSSIBLE");
}

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
import math

a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

k=min((a-1)%10,(b-1)%10,(c-1)%10,(d-1)%10,(e-1)%10)+1

sum=(math.ceil(a/10)*10+math.ceil(b/10)*10+math.ceil(c/10)*10+math.ceil(d/10)*10+math.ceil(e/10)*10)

print(sum-10+k)

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

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

  int p, c;
  while(n != 0 && r != 0){
    vector<int> v(n);
    vector<int> v1(n);
    for(int i = 0; i < n; i++){
      v[i] = n - i;
    }

    for(int i = 0; i < r; i++){
      cin >> p >> c;
      p--;

      for(int j = 0; j < n; j++){
        v1[j] = v[j];
      }

      for(int j = 0; j < c; j++){
        v[j] = v1[p + j];
      }

      for(int j = c; j < p + c; j++){
        v[j] = v1[j - c];
      }
        
      for(int j = 0; j < n; j++){
        //cerr << v[j] << " ";
      }
      //cerr << endl;
    }
    cout << v[0] << endl;
    cin >> n >> r;
  }

}

Measured memory_bytes: 2976
import numpy as np
N = int(input())
hs = [int(i) for i in input().split()]
dp = np.zeros(N)
for i,h in enumerate(hs):
    if i == 0:        
        # 0は初期化されている
        dp[i] = 0
        continue
    elif i == 1:
        # 1は1通りしか無い
        dp[i] = dp[i-1] + abs(hs[i-1]-h)
    else:
        # 1個前か2個前で、コストが最小になるやつ
        dp[i] = min(dp[i-1]+abs(hs[i-1]-h),dp[i-2]+abs(hs[i-2]-h))
# print(dp)
print(int(dp[-1]))

Measured memory_bytes: 23092
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

bool square(int n){
    int p = sqrt(n);
    if(ceil(p) == floor(p)){ return true;} else { return false;}
}

int main(void){
    string a, b;
    cin >> a >> b;
    int s = stoi(a + b);
    for(int i=1;i<=1000;i++){
        if(i*i == s){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        char[] S = Console.ReadLine().ToCharArray();

        if (N % 2 != 0)
        {
            Console.WriteLine("No");
            return;
        }
        for (int i = 0; i < N / 2; i++)
        {
            if (S[i] != S[N / 2 + i])
            {
                Console.WriteLine("No");
                return;
            }
        }
        Console.WriteLine("Yes");
    }
}


Measured memory_bytes: 11092
package main

import (
	"fmt"
	"os"
	"strconv"
	"bufio"
	"strings"
)

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func main(){
	arr := scanIntSplit(3)
	N, A, B := arr[0], arr[1], arr[2]
	ans := 0
	for i:=1; i<=N; i++{
		sum, num := 0, i
		for dig:=10000; dig>0; dig/=10{
			ai := num/dig
			num -= ai*dig
			sum += ai
			if sum > B {
				break
			}
		}
		if A <= sum && sum <= B {
			ans += i
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 640
n = int(input())
t = [int(i) for i in input().split()]
m = int(input())
px = []
for i in range(m):
	array = list(map(int,input().split()))
	px.append(array)

for i in px:
	print(int(sum(t)-t[i[0]-1] + i[1]))

Measured memory_bytes: 3060
def f(n, m):
    s = list(map(int,input().split()))
    t = list(map(int,input().split()))
    dp = [[1] * (m + 1) for _ in range(n + 1)]
    for i, sk in enumerate(s):
        dpi1 = dp[i + 1] = dp[i][:]
        cs = 0
        for j, tk in enumerate(t):
            if sk == tk:
                cs = (cs + dp[i][j]) % md
            dpi1[j + 1] = (dpi1[j + 1] + cs) % md
#    for x in dp:
#        print(*x)
    print(dp[-1][-1])

md = 10 ** 9 + 7
n, m = map(int, input().split())
f(n, m)


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N, M;
int A[101];
int scores[101];

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

    std::cin >> N >> M;

    for(int i=0;i<M;++i){
        std::cin >> A[i];
    }

    for(int i=0;i<M;++i){
        int miss_n = 0;
        
        for(int j=0;j<N;++j){
            int b;
            std::cin >> b;

            if(b == A[i]){
                ++scores[j];
            }else{
                ++miss_n;
            }
        }

        scores[A[i]-1] += miss_n;
    }

    for(int i=0;i<N;++i){
        std::cout << scores[i] << std::endl;
    }
}



Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ll mod = 998244353;
  ll N, S;
  cin >> N >> S;
  vector<ll> dp(S + 1, 0);
  dp.at(0) = 1;
  for (ll i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    for (ll j = S; j >= 0; --j) {
      dp.at(j) += dp.at(j);
      dp.at(j) %= mod;
      if (j - a >= 0) {
        dp.at(j) += dp.at(j - a);
        dp.at(j) %= mod;
      }
    }
  }
  cout << dp.at(S) << "\n";
}


Measured memory_bytes: 3652
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define DUMP(n,a) for(long long dump=0; dump<n; ++dump) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	cout<<s.substr(0,s.size()-8)<<endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    }
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! chmax {
    ($x:expr, $e:expr) => {
        if $x < $e {
            $x = $e;
        }
    };
}
macro_rules! chmin {
    ($x:expr, $e:expr) => {
        if $x > $e {
            $x = $e;
        }
    };
}

const INF: i64 = 1 << 60;

fn main() {
    input!{
        A: usize,
        B: usize,
    }
    let mut ans = HashSet::new();
    ans.insert(1);
    ans.insert(2);
    ans.insert(3);
    ans.remove(&A);
    ans.remove(&B);
    for i in ans {
        println!("{}", i);
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
 
class Dice4{
public:
    int number[6];
 
    void roll(char dst){
        switch(dst){
        case 'E':
            setNumber(number[3],number[1],number[0],number[5],number[4],number[2]);
            break;
        case 'N':
            setNumber(number[1],number[5],number[2],number[3],number[0],number[4]);
            break;
        case 'S':
            setNumber(number[4],number[0],number[2],number[3],number[5],number[1]);
            break;
        case 'W':
            setNumber(number[2],number[1],number[5],number[0],number[4],number[3]);
            break;
        }
    };
 
    bool isSameDice(int inputed[]){
        char order[25] = "NNNNWNNNWNNNENNNENNNWNNN";
        for(int i = 0; i < 24; i++){
            roll(order[i]);
            for(int j = 0; j < 6; j++){
                if(inputed[j] != number[j])
                    break;
                if(j == 5)
                    return true;
            }
        }
        return false;
    }
 
private:
    void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
        number[0] = n0;
        number[1] = n1;
        number[2] = n2;
        number[3] = n3;
        number[4] = n4;
        number[5] = n5;
    }
 
};
 
int main(){
    int n,k,j;
    scanf("%d",&n);
    Dice4 array[n];
    for(int i = 0; i < n; i++){
        scanf("%d %d %d %d %d %d",&array[i].number[0],&array[i].number[1],&array[i].number[2],
                &array[i].number[3],&array[i].number[4],&array[i].number[5]);
    }
    for(k = 0; k < n-1; k++){
        for(j = k+1; j < n; j++){
            if(array[k].isSameDice(array[j].number))
                break;
        }
        if(j < n) break;
    }
    if(k == n-1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}


Measured memory_bytes: 2580
#include<stdio.h>

int main()
{
	int n, m, q, min, max, l, r, table[501][501]{};

	scanf("%d%d%d", &n, &m, &q);
	for (int i = 0; i < m; ++i)
	{
		scanf("%d%d", &l, &r);
		table[l][r]++;
	}

	for (int i = 1; i < n + 1; ++i)
		for (int j = i; j < n + 1; ++j)
			table[i][j] += table[i][j - 1];

	for (int i = 1; i < n + 1; ++i)
		for (int j = i; j < n + 1; ++j)
			table[i][j] += table[i - 1][j];

	for (int i = 0; i < q; ++i)
	{
		scanf("%d%d", &min, &max);
		printf("%d\n", table[max][max] - table[min - 1][max]);
	}

	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main() {
	int N, L;
	cin >> N >> L;
	int ans = 0;
	for (int i = L; i < N + L; i++) {
		ans += i;
	}
	if (N + L - 1 < 0) {
		ans -= N + L - 1;
	}
	else if (L > 0){
		ans -= L;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String,
    }
    let pattern = ["eraser", "erase", "dreamer", "dream"];
    let remain = pattern.iter().fold(s, |st, pa| st.replace(pa, ""));
    println!("{}", if remain.is_empty() { "YES" } else { "NO" });
}


Measured memory_bytes: 4352
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "vector"
#include "string"
#include "map"
#include "algorithm"
#include "functional"
#include "set"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;



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

	cin >> N >> M;
	vector<long long int>v(N);
	vector<long long int>num(N);
	for (int i = 0; i < N; i++)cin >> v[i] >> num[i];
	if (M <= v.front()) {
		cout << v.back() - M << endl;
		return 0;
	}
	if (v.back() <= M) {
		cout << M - v.front() << endl;
		return 0;
	}
	long long int ans = 0;
	L = 0;
	R = N - 1;
	vector<long long int>visit;
	while (v[L]<M&&v[R]>M) {
		if (num[L] >= num[R]) {
			visit.push_back(v[R]);
			num[L] += num[R];
			R--;
		}
		else{
			visit.push_back(v[L]);
			num[R] += num[L];
			L++;
		}
	}
	if(L==R)visit.push_back(v[L]);
	else if (v[L] < M)visit.push_back(v[L]);
	else visit.push_back(v[R]);
	visit.push_back(M);
	for (int i = 1; i < visit.size(); i++)ans += abs(visit[i] - visit[i - 1]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define dbg(x) cout << #x << ": " << (x) << '\n'
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

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

   int n, k;
   cin >> n >> k;
   vector <int> a(n);
   for (auto &i: a)
      cin >> i;
   sort(a.begin(), a.end());
   int ans = 0;
   for (int i = 0; i < k; i++) {
      ans += a[i];
   }
   cout << ans << '\n';


   return 0;   
}

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

using namespace std;

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  double a, b, c;
  std::cin >> a >> b >> c;
  double const s = (a + b + c) / 2;
  int const ret = int(round(sqrt(s * (s - a) * (s - b) * (s - c))));
  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n,change;
  int yen=1000;
  cin>>n;
  if(n>=1 && n<=10000)
  {
    change=n%yen;
    if(change==0)
      cout<<change;
    else
    {
      change=yen-change;
      cout<<change;
    }
  }
  return 0;
}

Measured memory_bytes: 3620
from math import *
from collections import *
from itertools import *
from bisect import *
from heapq import *
from operator import *
from sys import *
setrecursionlimit(100000000)


n=int(input())
l=list(map(int,input().split()))
x=0
for i in l:
   x^=i
ans=[x^y for y in l]
print(*ans)





Measured memory_bytes: 33376
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,kk;
int main()
{
    cin>>a>>b>>c;
    if(b>=a)
    {
        cout<<1<<endl;
        return 0;
    }
    if(c>=b)
    {
        cout<<-1<<endl;
        return 0;
    }
    if((a-b)%(b-c)>=1)kk=1;
    cout<<((a-b)/(b-c)+kk)*2+1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
    
int main(){
    long long a,b,v,w,t;
    cin >> a >> v >> b >> w >> t;
    long long l = abs(a-b);
    
    if((w-v) >= 0){
        cout << "NO" << endl;
    }
    else{
        if((v-w)*t >= l){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define INF 1123456789012
using namespace std;

void dfs(ll a, ll b, ll c, ll ans){
	if (a & 1 || b & 1 || c & 1){
		cout << ans << endl;
		exit(0);
	}dfs((b + c) / 2, (a + c) / 2, (a + b) / 2,ans+1);
}

int main(){
	ll a, b, c; cin >> a >> b >> c;
	if (a & 1 || b & 1 || c & 1){
		cout << 0 << endl;
		exit(0);
	}
	if (a == b && b == c) cout << -1 << endl;
	else dfs(a, b, c, 0);
	return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W));
  vector<int> B(H), C(W);
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> A.at(i).at(j);
      if(A.at(i).at(j) == '#'){
        B.at(i) = 1;
        C.at(j) = 1;
      }
    }
  }
  
  bool a = false;
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(B.at(i) == 1 && C.at(j) == 1){
        cout << A.at(i).at(j);
        a = true;
      }
    }
    
    if(a){
      cout << endl;
    }
    a = false;
  }

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
    using namespace std;
     
    const int INF = 2e9;
    const int N = 1e5 + 10;
     
    vector<pair<int, int> > g[N];
    int x[N];
    bool ok = true;
     
    void dfs(int v) {
    	for(auto& uu : g[v]) {
    		int u = uu.first, d = uu.second;
    		if(x[u] == INF) {
    			x[u] = x[v] + d;
    			dfs(u);
    		} else if(x[u] != x[v] + d) {
    			ok = false;
    		}
    	}
    }
     
    int main() {
    	int n, m;
    	scanf("%d %d", &n, &m);
    	while(m--) {
    		int l, r, d;
    		scanf("%d %d %d", &l, &r, &d);
    		g[l].push_back({r, -d});
    		g[r].push_back({l, d});
    	}
    	fill(x, x+N, INF);
    	for(int i = 1; i <= n; i++) {
    		if(x[i] == INF) {
    			x[i] = 0;
    			dfs(i);
    		}
    	}
    	if(ok) {
    		printf("Yes\n");
    	} else {
    		printf("No\n");
    	}
    }

Measured memory_bytes: 11008
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#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;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
long long gcd( long long m, long long n ){

  if ( n == 0) return m;
  return gcd(n,m%n);
}//gcd

long long lcm( long long m, long long n ){
  // 引数に０がある場合は０を返す
  if ( ( 0 == m ) || ( 0 == n ) ) return 0;

  return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm

int main(){
  long long N,T,ans=1;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> T;
    ans = lcm(ans,T);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <unordered_map>

using namespace std;

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

const ll mod = 998244353;

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

  int n, s;
  cin >> n >> s;
  vector<int> a(n);
  for (auto &x: a) cin >> x;

  vector<vector<ll> > dp(n+1, vector<ll>(s+1));
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= s; j++) {
      if (j+a[i] <= s) dp[i+1][j+a[i]] = (dp[i][j] + dp[i+1][j+a[i]]) % mod;
      dp[i+1][j] = (dp[i][j] + dp[i+1][j]) % mod;
    }
    if (a[i] <= s) dp[i+1][a[i]] = (dp[i+1][a[i]] + i) % mod;
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans = (ans + dp[i+1][s]) % mod;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 70784
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define beg begin()
#define end end()


void _main(){
    ll n; cin >> n;
    string name="";
    char a = 'a';
    n--;
    while(n>=0){
        int per = n%26;
        n = n/26-1;
        name += a+per;
    }
    reverse(name.beg,name.end);
    cout << name << endl;
    return;
}
int main() {
    cout << fixed << setprecision(10);
    _main();
    return 0;
}
    

Measured memory_bytes: 3132