akhauriyash/Code-Regression huggingface dataset:
a_list = list(map(int, input().split()))

ans = 0

a0 = min(a_list)
a_list.remove(a0)
a1 = min(a_list)
a_list.remove(a1)
ans += abs(a1 - a0)
a2 = min(a_list)
ans += abs(a2 - a1)

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x;
    cin >> x;
    int c500;
    int c5;
    c500 = ceil(x/500);
    x = x%500;
    c5 = ceil(x/5);
    x = x%5;
    cout << c500*1000+c5*5 << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
#define MAX_N 200005
class UnionFind
{
public:
  int par[MAX_N];
  int depth[MAX_N];
  int nGroup[MAX_N];
  UnionFind(int n) {
    init(n);
  }
  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }
  int root(int x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;
    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
int main() {
  int N;
  cin >> N;
  vector<ll> A(N), B(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  vector<int> idA(N), idB(N);
  rep(i, N) idA[i] = idB[i] = i;
  sort(all(idA), [&](int i, int j) { return A[i] < A[j]; });
  sort(all(idB), [&](int i, int j) { return B[i] < B[j]; });
  sort(all(A));
  sort(all(B));
  bool ok1 = true;
  bool ok2 = false;
  UnionFind uf(N);
  rep(i, N) {
    if(A[i] > B[i]) ok1 = false;
    if(i && A[i] <= B[i-1]) ok2 = true;
    uf.unite(idA[i], idB[i]);
  }
  bool ok3 = true;
  rep(i, N) if(uf.nGroup[i] == N) ok3 = false;
  cout << (ok1&&(ok2||ok3) ? "Yes" : "No") << endl;
  return 0;
}


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

int n, h[100005], dp[100005];
int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> h[i];
        dp[i] = (int) 2e9;
    }
    dp[0] = 0;
    for(int i = 0; i < n - 1; i++)
    {
        if(i < n - 2)
            dp[i + 2] = dp[i] + abs(h[i] - h[i + 2]);
        if(dp[i] + abs(h[i] - h[i + 1]) < dp[i + 1])
            dp[i + 1] = dp[i] + abs(h[i] - h[i + 1]);
    }
    cout << dp[n - 1] << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b; cin >> a >> b;
  string s; cin >> s;
  for(int i = 0; i < a+b; i++){
    if(s.at(i) == '-' and i != a){
      cout << "No";
      return 0;
    }
    else if(i == a and s.at(i) != '-'){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}
  

Measured memory_bytes: 3604
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

kills = 0
b_k = 0

for i in range(n):
    b_k = b[i]
    for j in range(2):
        if b_k - a[i+j] >= 0:
            kills += a[i+j]
            b_k -= a[i+j]
            a[i+j] = 0
        else:
            kills += b_k
            a[i+j] -= b_k
            b_k = 0

print(kills)

Measured memory_bytes: 24076
n, m = gets.split.map(&:to_i)

works = n.times.map{ gets.split.map(&:to_i) }
works.sort!{|a, b| (b[1] <=> a[1]).nonzero? || b[0] <=> a[0] }
available_day = (1..m).to_a

sum = 0
works.each do |day, salary|
  if index = available_day.bsearch_index{|e| e >= day }
    available_day.delete_at(index)
    sum += salary
  end
end

p sum


Measured memory_bytes: 12152
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);


int main(){
	int n,p,q;
	while(cin>>n>>p>>q,n|p|q){
		vi avl(2410);
		REP(i,n){
			int k;
			cin>>k;
			if(k){
				int c1;
				cin>>c1;
				FOR(j,p,c1+1){
					avl[j]=1;
				}
			}
			REP(j,k-1){
				int c2,c1;
				cin>>c2>>c1;
				FOR(l,c2,c1+1){
					avl[l]=1;
				}
			}
			if(k){
				int c2;
				cin>>c2;
				FOR(j,c2,q+1){
					avl[j]=1;
				}
			}
		}
		int ans=0;
		int cnt=0;
		REP(i,2400+1){
			ans=max(ans,cnt);
			if(i%100==60){
				i+=40;
			}
			if(avl[i]){
				cnt++;
			}else{
				cnt=0;
			}
		}
		ans=max(ans,cnt);
		cout<<ans-1<<endl;
	}
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int

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


int main()
{
  string s;
  ll k;
  cin >> s >> k;

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

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

int gcd(int x,int y){
	if(x>y) swap(x,y);
	
	if(y%x==0) return x;
	else gcd(y%x,x);
}

int main(){
	int n;
	cin>>n;
	
	vector<int> a;
	for(int i=0;i<n;++i){
		int tmp;
		cin>>tmp;
		a.push_back(tmp);
	}
	
	int ans=gcd(a[0],a[1]);
	for(int i=2;i<n;++i){
		ans=gcd(ans,a[i]);
	}
	
	cout<<ans<<endl;
}//abc118_c 解説参考.

Measured memory_bytes: 892
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    string s,t; cin>>s>>t;
    string u = t.substr(0,t.length()-1);
    if (s==u) {
        cout << "Yes" << '\n';
    }
    else {
        cout << "No" << '\n';
    }
    return 0;
}

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

struct P
{
    int x,y,z;

    bool operator<(const P &a)const{
        if(x!=a.x)
              return x>a.x;
        return y>a.y;
    }

};

vector<int> v;

//bitset<4001000> b;
int i,n,d,m,k,a,b,c;

long long o[3111][3311];
long long l[6331];
long long j[6331];
int e;


//int dx[10]={2,2,-2,-2,1,1,-1,-1},dy[10]={1,-1,1,-1,2,-2,2,-2};

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[33];
stack<int> s;
//set<int> se;
//priority_queue<int,vector<int>,greater<int> > q;
queue<int> q;
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p[222222];
/*
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> safe_map;
*/
//list<int> l;

//string r,r1;
char r[3552];
//deque<int> de;
//srand((int)time(NULL));
/*bool as(P a,P b)
{
    if(a.x!=b.x)
    return a.x<b.x;
    return a.y<b.y;
}*/



bool as(P a,P b)
{
    if(a.x!=b.x)
       return a.x<b.x;
    return a.y>b.y;


}

long long g(long long x,long long y)
{
    long long p=1;
    for(;y;y/=2,x*=x,x%=mod)
        if(y%2)
        p*=x,p%=mod;
    return p;
}

long long f(int n,int m)
{
    if(n>=m) return 1;
    long long x=l[m-n+1]*j[o[n][m]-n]%mod*j[m-o[n][m]]%mod;
    x*=f(n,o[n][m]-1),x%=mod;
    x*=f(o[n][m]+1,m),x%=mod;
    return x;
}

int main()
{
    scanf("%d",&a);

    scanf("%s",r+1);
    o[1][1]=1;
    for(int t=2;t<=a;t++)
    {
        for(int w=1;w<=t;w++)
            if(r[t-1]=='<')
            o[t][w]=o[t-1][w-1];
            else
                o[t][w]=(o[t-1][t-1]-o[t-1][w-1]+mod)%mod;
        for(int w=1;w<=t;w++)
            o[t][w]+=o[t][w-1],o[t][w]%=mod;
    }
    printf("%lld",o[a][a]);
}





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

#define int long long
#define fr(i,n) for(int i=0;i<n;i++)
#define frr(i,n) for(int i=n;i>=0;i--)
#define fra(i,a,n) for(int i=a;i<n;i++)
#define frra(i,a,n) for(int i=a;i>=n;i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second
#define endl '\n'

typedef pair<int,int> ii;
typedef map<int,int> mii;
typedef set<int> si;
typedef unordered_map<int,int> uii;
typedef unordered_set<int> usi;
typedef vector<int> vi;
typedef vector<ii> vii;

const int mod = 1e9+7;
const int inf = 1e9;
const int MAXN = 2e5+5;
const double eps = 1e-6;

void solve(){
    //CODE BEGINS
    string s;
    cin>>s;
    if(s=="ABC")cout<<"ARC\n";
    if(s=="ARC")cout<<"ABC\n";
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //~ cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#define MAX 200

int main(void)
{
  int m, n, nmin, nmax, i, j;
  int t=0, base=0, gap=0;
  int tokuten[MAX];
  
  while(t!=1)
    {
      scanf("%d %d %d",&m,&nmin,&nmax);
      if(m==0)
	{
	  t = 1;
	}
      /* ??\?????????????????§??????!!!
      if(m=0)
      {
        t = 1;
      }
      */
      else
	{
	  for(i=0;i<=m-1;i++)
	    {
	      scanf("%d",&tokuten[i]);
	    }
	  
	  for(i=nmin-1;i<=nmax-1;i++)
	    {
	      gap = tokuten[i]-tokuten[i+1];
	      
	      if(gap>=base)
		{
		  base = gap;
		  n = i + 1;
		}
	    }
	  printf("%d\n",n);
	  base = 0;
	}
    }
  return(0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
// atoi : atoi(変数名.c_str())
// to_string(数値)
// %0桁数d とすると表示桁数が「桁数」に満たない場合に0埋めされる
// find(): int i = 変数名.find(“文字列”) 何番目にあるかを得る
// cout << (条件 ? "Yes" : "No") << endl;
// printf("%02d:%02d:%02d",hour,minute,second);
// 降順 sort(a.begin(),a.end(),greater<int>());
// bitset<ビット数> 変数名;  // すべてのビットが0の状態で初期化される
// bitset<ビット数> 変数名("ビット列");  // 指定したビット列で初期化される
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  long a,b,c;
  cin >> a >> b >> c;
  if(a + b < c){
    cout << a + 2*b + 1 << endl;
    return 0;
  }else{
    cout << b + c << endl;
    return 0;
  }
}


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

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

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

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

int n;
string s1,s2;

int main(){
    cin >> n;
    cin >> s1;
    cin >> s2;

    const long M=1000000007;
    long ans=3;
    bool pre_vert=false;
    for(int i=0;i<n;i++){
        if(s1[i]!=s2[i]){
            if(i==0||pre_vert){
                ans*=2;
            }
            else{
                ans*=3;
            }
            pre_vert=false;
            i++;
        }
        else{
            if(pre_vert){
                ans*=2;
            }
            pre_vert=true;
        }

        if(ans>M){
            ans%=M;
        }
    }
    cout << ans  << endl;
    return 0;
}



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

bool isnp[10001];
int ans[10001];

int main(){
	for(int i = 2; i < 98; ++i){
		if( !isnp[i] ){
			for(int j = i * i; j <= 10000; j += i){
				isnp[j] = true;
			}
		}
	}

	vector<int> primes;
	for(int i = 2; i < 9999; ++i){
		if( !isnp[i] ) primes.push_back(i);
	}

	vector<int> sum(primes.size() + 1);
	for(int i = 0; i < primes.size(); ++i){
		sum[i+1] = sum[i] + primes[i];
	}

	for(int i = 1; i < sum.size(); ++i){
		for(int j = 0; j < i; ++j){
			if(sum[i] - sum[j] <= 10000){
				++ans[sum[i] - sum[j]];
			}
		}
	}
	
	int n;
	while(scanf("%d", &n), n != 0){
		printf("%d\n", ans[n]);
	}
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  long a, b, c=0, d=0, e, f, g, h, n;
  string s;
  cin >> n >> s;
  rep(i,0,n-2){
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') c++;
  }
  co(c);
  
  
  return 0;
}

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

using namespace std;
#define ll long long
#define ld long double

int main() 
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
	
    int n;
    string s;
    cin >> n >> s;
    cout << (s.substr(0, n/2) == s.substr(n/2) ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 256
n,T=map(int,input().split())
c=[]
t=[]
for i in range(n):
  cd,td=map(int,input().split())
  c.append(cd)
  t.append(td)

mxc=max(c)
for i in range(n):
  if t[i]>T:
    c[i]=mxc+1

if min(c)>mxc:
  print("TLE")
else:
  print(min(c))

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

int A[100100];
int dp[100100][11];
vector<int> G[100100];

int main(){
	int n,m,a,b,q;
	
	cin >> n >> m;
	for(int i=1;i<=m;i++){
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	cin >> q;
	for(int i=1;i<=q;i++){
		cin >> a >> b >> A[i];
		dp[a][b]=i;
	}
	
	for(int i=9;i>=0;i--){
		for(int j=1;j<=n;j++){
			dp[j][i]=max(dp[j][i], dp[j][i+1]);
			for(int k=0;k<G[j].size();k++){
				dp[j][i]=max(dp[j][i], dp[G[j][k]][i+1]);
			}
		}
	}
	
	for(int i=1;i<=n;i++){
		cout << A[dp[i][0]] << endl;
	}
	return 0;
}

Measured memory_bytes: 11128
#include<bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int a[4], b[4], x[4];
signed main() {
	while (1) {
		for0(i, 4) {
			cin >> a[i];
			b[i] = i;
		}
		if (a[1] == 0)return 0;
		bool k = 0;
		do {
			for0(i, 4)x[i] = a[b[i]];
			if (x[0] + x[1] + x[2] + x[3] == 10) { k = 1; printf("%d + %d + %d + %d\n", x[0], x[1], x[2], x[3]); break; }
			if (x[0] + x[1] + x[2] - x[3] == 10) { k = 1; printf("%d + %d + %d - %d\n", x[0], x[1], x[2], x[3]); break; }
			if (x[0] + x[1] - x[2] - x[3] == 10) { k = 1; printf("%d + %d - %d - %d\n", x[0], x[1], x[2], x[3]); break; }
			if (x[0] * x[1] + x[2] + x[3] == 10) { k = 1; printf("%d * %d + %d + %d\n", x[0], x[1], x[2], x[3]); break; }
			if (x[0] * x[1] + x[2] - x[3] == 10) { k = 1; printf("%d * %d + %d - %d\n", x[0], x[1], x[2], x[3]); break; }
			if (x[0] * x[1] - x[2] - x[3] == 10) { k = 1; printf("%d * %d - %d - %d\n", x[0], x[1], x[2], x[3]); break; }
			if (x[0] + x[1] - x[2] * x[3] == 10) { k = 1; printf("%d + %d - %d * %d\n", x[0], x[1], x[2], x[3]); break; }
			if (x[0] * x[1] + x[2] * x[3] == 10) { k = 1; printf("%d * %d + %d * %d\n", x[0], x[1], x[2], x[3]); break; }
			if (x[0] * x[1] - x[2] * x[3] == 10) { k = 1; printf("%d * %d - %d * %d\n", x[0], x[1], x[2], x[3]); break; }
			if ((x[0] + x[1]) * x[2] + x[3] == 10) { k = 1; printf("(%d + %d) * %d + %d\n", x[0], x[1], x[2], x[3]); break; }
			if ((x[0] + x[1]) * x[2] - x[3] == 10) { k = 1; printf("(%d + %d) * %d - %d\n", x[0], x[1], x[2], x[3]); break; }
			if ((x[0] - x[1]) * x[2] + x[3] == 10) { k = 1; printf("(%d - %d) * %d + %d\n", x[0], x[1], x[2], x[3]); break; }
			if ((x[0] - x[1]) * x[2] - x[3] == 10) { k = 1; printf("(%d - %d) * %d - %d\n", x[0], x[1], x[2], x[3]); break; }
			if ((x[0] + x[1]) * (x[2] + x[3]) == 10) { k = 1; printf("(%d + %d) * (%d + %d)\n", x[0], x[1], x[2], x[3]); break; }
			if ((x[0] + x[1]) * (x[2] - x[3]) == 10) { k = 1; printf("(%d + %d) * (%d - %d)\n", x[0], x[1], x[2], x[3]); break; }
			if ((x[0] - x[1]) * (x[2] - x[3]) == 10) { k = 1; printf("(%d - %d) * (%d - %d)\n", x[0], x[1], x[2], x[3]); break; }
		} while (next_permutation(b, b + 4));
		if (!k)printf("0\n");
	}
}


Measured memory_bytes: 3152
var x = require('fs').readFileSync('/dev/stdin', 'utf8').split(" ")
var r = "";
if(x[0]*1 == x[1]*1) r += "a == b";
if(x[0]*1 > x[1]*1) r += "a > b";
if(x[0]*1 < x[1]*1) r += "a < b"
console.log(r);


Measured memory_bytes: 15096
n = int(input())
A = [int(i) for i in input().split()] # input:"1 2 3 4 5"
B = [int(i) for i in input().split()] # input:"1 2 3 4 5"
C = [int(i) for i in input().split()] # input:"1 2 3 4 5"

ans=0
ans += B[A[0]-1]
tmp = A[0]

for i in range(1,n):
  
  ans += B[A[i]-1]
  
  if A[i]==tmp+1:
    ans +=C[A[i]-2]
  tmp = A[i]
  
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
using namespace std;
int main(){
    string S; cin >> S;
    vector<int> d(26);
    for (int i=0;i<S.size();i++){
        d[S[i]-'a']++;
        if (d[S[i]-'a']==2) {
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;

}



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

#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>

using namespace std;


int main() {
  int N,D;
  cin>>N>>D;
  vector<vector<int>> W(N,vector<int>(D));
  vector<vector<int>> S(N,vector<int>(N,0));
  int t=0;
  
  
  for (int i=0;i<N;i++) {
    for (int j=0;j<D;j++) {
      cin>>W[i][j];
    }
  }
  
    
  for (int k=0;k<N-1;k++)  {
      
    for (int i=k+1;i<N;i++) {
      for (int j=0;j<D;j++)  {
          S[k][i]+=(W[k][j]-W[i][j])*(W[k][j]-W[i][j]);
      }
      for (int Q=1;Q<127;Q++) {
        if (S[k][i]==Q*Q) t++;
        else continue;
      }
    }
    
  }
  cout<<t<<endl;
}

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  ll n;
  cin >> n;
  if(n%2==1){
    cout << 0 << endl;
  }
  else{
    n /=10;
    ll cnt=n;
    while(n>4){
      n /=5;
      cnt +=n;
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 256
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define close std::ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define CASET           \
    int ___T;           \
    scanf("%d", &___T); \
    for (int __CS = 1; __CS <= ___T; __CS++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x; }
LL bin(LL x, LL n, LL MOD)
{
    LL ret = MOD != 1;
    for (x %= MOD; n; n >>= 1, x = x * x % MOD)
        if (n & 1)
            ret = ret * x % MOD;
    return ret;
}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
const double PI = acos(-1.0);
constexpr int maxn = 1e6 + 10;
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr int mod = 1e9 + 7;
constexpr int N = 25;
int n, a[N][N], dp[1 << N];
int main()
{
    cin>> n;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cin >> a[i][j];
        }
    }
    dp[0] = 1;
    int mx = 1 << n;
    for(int mj = 0; mj < mx; mj++){
        int i = __builtin_popcount(mj);
        for(int j = 1; j <= n ; j++){
            if(mj & (1 << (j-1)) && a[i][j]){
                dp[mj] = (dp[mj] + dp[mj ^ (1 << (j-1))]) % mod;
            }
        }
    }
    cout << dp[mx - 1] <<endl;  
}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const ll mod=1000000007,MAX=400005,INF=1<<30;

ll inv[MAX],fac[MAX],finv[MAX];

void make(){
    
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    
    for(int i=2;i<MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll)i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
    
}

ll comb(ll a,ll b){
    if(a<b) return 0;
    return fac[a]*(finv[b]*finv[a-b]%mod)%mod;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    make();
    
    int N,K;cin>>N>>K;
    if(K>=N-1){
        cout<<comb(N+N-1,N-1)<<endl;
    }else{
        ll ans=comb(N+N-1,N-1);
        
        for(int i=N-1;i>=K+1;i--){
            ans+=mod;
            int use=N-i;
            ans-=comb(N-use+use-1,use-1)*comb(N,i)%mod;
            ans%=mod;
        }
        
        cout<<ans<<endl;
    }
    
}



Measured memory_bytes: 9600
#include<iostream>
using namespace std;
int main(){
  int Q;
  int d[3];
  cin >> Q;
  for(int i=0;i<Q;i++){
    int count=0;
    cin >> d[0] >> d[1] >> d[2];
    while(d[0]>0){
      if(d[2]>=1&&d[1]>=1){
	d[2]--;
	d[1]--;
	d[0]--;
	count++;
      }
      else if(d[1]>=1&&d[0]>=2){
	d[1]--;
	d[0]-=2;
	count++;
      }
      else{
	if(d[0]<3) break;
	d[0]-=3;
	count++;
      }
    }
    cout << count << endl;
  }
  return 0;
}  

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(i, n) a[idx][i] = v[i]; idx++; PER = a;} while(next_permutation(ALL(v)));} while(0); // int fact(), VVI PERを宣言しておく
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using VD = vector<double>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

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

void END(){cout << 1 << endl; exit(0);}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k, r, s, p;
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  int ans = 0;
  map<char, int> pt;
  pt['r'] = p; pt['s'] = r; pt['p'] = s;
  REP(i, k)
  {
    string tmp = "";
    for (int j = i; j < n; j += k) tmp += t[j];
    int d = 0;
    char rsp = '0';
    REPx(x, tmp)
    {
      if (d == 0)
      {
        d++;
        rsp = x;
        ans += pt[x];
      }
      else
      {
        if (rsp == x)
        {
          if (d % 2 == 0) ans += pt[x];
          d++;
        }
        else
        {
          ans += pt[x];
          d = 1;
          rsp = x;
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}


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

long long calc(long long i) {
  return (1 + i);
}
void solve(long long N, long long K, std::vector<long long> p){
  long long acc = accumulate(p.begin(), p.begin()+K, 0.0, [](auto loacc, auto i){
    return loacc + calc(i);
  });

  long long mymax = acc;
  for(long long i = K; i < N; i++){
    acc += (calc(p[i]) - calc(p[i-K]));

    mymax = max(mymax, acc);
  }

  cout << setprecision(12) << ((long double)mymax/2) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  long long K;
  scanf("%lld",&K);
  std::vector<long long> p(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&p[i]);
  }
    solve(N, K, std::move(p));
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
	int N;
	string ptr;
	cin>>N>>ptr;
	if(N%2!=0){
		cout<<"No"<<endl;
	}else{
		string ptr1,ptr2;
		for(int i=0;i<N/2;i++){
			ptr1=ptr1+ptr[i];
		}
		for(int i=N/2;i<N;i++){
			ptr2=ptr2+ptr[i];
		}
		if(ptr1==ptr2){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc150c()
}

fun abc150c() {
    val n = readLine()!!.toInt()
    val p = readLine()!!.split(' ').map { it.toInt() }.joinToString("")
    val q = readLine()!!.split(' ').map { it.toInt() }.joinToString("")

    val perms = permutations((1..n).joinToString("")).map { it.toString() }

    val a = perms.indexOf(p)
    val b = perms.indexOf(q)

    val answer = Math.abs(a - b)

    println(answer)
}

fun permutations(base: String, add: String = "", ret: MutableList<Int> = mutableListOf()): List<Int> {
    if (base.length == 1) {
        ret.add((add + base).toInt())
    } else {
        for (i in base.indices) {
            permutations(
                base.substring(0, i) + base.substring(i + 1, base.length),
                add + base[i],
                ret
            )
        }
    }
    return ret
}


Measured memory_bytes: 63768
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll A[(1LL<<18) + 10];
lpair dp[(1LL<<18) + 1][19];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll M = (1LL<<N);
    rep(i,0,M) cin >> A[i];
    rep(i,0,M){
        dp[i][0] = {A[i], 0};
    }
    rep(j,0,N){
        rep(i,0,M){
            if(i & (1LL<<j)){
                ll arr[4];
                arr[0] = dp[i][j].first;
                arr[1] = dp[i][j].second;
                arr[2] = dp[i & ~(1LL<<j)][j].first;
                arr[3] = dp[i & ~(1LL<<j)][j].second;
                sort(arr, arr+4);
                // printa(arr,4);
                dp[i][j+1] = {arr[2], arr[3]};
            }else{
                dp[i][j+1] = dp[i][j];
            }
        }
    }
    ll ans = 0;
    rep(i,1,M){
        ans = max(ans, dp[i][N].first + dp[i][N].second);
        print(ans);
    }
}

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

using namespace std;

int main(){
    int N,K;
    string num;
    bool flag = true;
    cin >> N >> K;
    vector<char> D(K);
    for(int i=0;i<K;i++){
        cin >> D[i];
    }

    for(int i=N;;i++){
        num =to_string(i);
        for(int i=0;i<num.size();i++){
            for(int j=0;j<K;j++){
                if(num[i] == D[j]){
                    flag = false;
                    break;
                }
            }
            if(!flag){
                break;
            }
        }
        if(flag){
            cout << i << endl;
            break;
        }
        flag = true;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <map>
//#include <set>
//#include <list>
//#include <cmath>
//#include <ctime>
//#include <deque>
//#include <queue>
//#include <stack>
//#include <string>
//#include <bitset>
//#include <cstdio>
//#include <limits>
//#include <vector>
//#include <climits>
//#include <cstring>
//#include <cstdlib>
//#include <fstream>
//#include <numeric>
//#include <sstream>
//#include <iomanip>
//#include <iostream>
//#include <algorithm>
//#include <unordered_map>

using namespace std;

#define file freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define PI 3.141592653589793238462643383279502884
#define MAX 1000100
#define mod 1000000007
#define EPS 1E-9
#define int long long
#define endl "\n"

int fix(int cur, int m)
{
    return ((cur%m) + m) % m;
}

int fast_power(int x, int y,int m)
{
    if (y == 0)
        return 1;
    int temp = fast_power(x, y / 2, m) ;
    temp = (temp*temp)% m;
    if (y % 2 != 0)
        temp = (temp*x)% m;
    return temp;

}


int32_t main()
{
    //freopen("C:/Users/Joe/Desktop/tests/in11.txt", "r", stdin);
    //freopen("C:/Users/Joe/Desktop/tests/out11.txt", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.tie(0);

    int t=1;
    //cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        int arr[n];
        int sum=0;
        for(int i=0;i<n;i++)
        {
            cin >> arr[i];
            sum+=arr[i];
        }
        double num=sum/(double)n;
        double f1=ceil(num);
        double f=floor(num);
        int res=0,res2=0;
        for(int i=0;i<n;i++)
        {
            res+=(arr[i]-f1)*(arr[i]-f1);
            res2+=(arr[i]-f)*(arr[i]-f);

        }
        cout << min(res2,res) << endl;


    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
const long long mod = 998244353;

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

  vector<int> D_cnt(N);
  int d_max = 0;
  for(int i = 0; i < N; i++){
    int d;
    cin >> d;
    if(d >= N || (i == 0 && d != 0) || (i != 0 && d == 0)){
      cout << 0 << endl;
      return 0;
    }
    D_cnt[d]++;
    d_max = max(d_max, d);
  }

  long long ans = 1;
  for(int i = 1; i <= d_max; i++){
    for(int j = 0; j < D_cnt[i]; j++){
      ans *= D_cnt[i - 1];
      ans %= mod;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 640
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
const int INF = 0x7fffffff;

int gcd(int x,int y){
  int mi,ma;
  ma = max(x,y);
  mi = min(x,y);
  if(ma % mi == 0){
    return mi;
  }
  else{
    return gcd(mi,ma % mi);
  }
}

using Graph = vector<vector<int>>;

int g[101][101];
int seen[101];
int stamp[2][101];
int n;
int t;

void dfs(int v){
  seen[v] = 1;
  int ii;

  //cout << v << endl;
  
  stamp[0][v] = t;
  t++;

  //for(ii=1;ii<=n;ii++){
  //  cout << seen[ii] << endl;
  //}
  
  for(ii=1;ii<=n;ii++){
    //cout << "v:"<< v << "ii:" << ii << " " << g[v][ii] << endl;

    if(seen[ii] == 1){continue;}
    //cout << "v:"<< v << "ii:" << ii << " " << g[v][ii] << endl;

    if(g[v][ii] == 1){
      dfs(ii);
    }
  }
  
  stamp[1][v] = t;
  t++;
}

int main(){
  long ii,jj,kk;
  vector<int> a;


  memset(g,0,sizeof(g));

  memset(stamp,0,sizeof(stamp));
  
  cin >> n;

  int v,vn,r;
  
  for(ii=0;ii<n;ii++){
    cin >> v;
    cin >> vn;
    for(jj=0;jj<vn;jj++){
      cin >> r;
      g[v][r] = 1;
    }
  }

  //for(ii=1;ii<=n;ii++){
  //  for(jj=1;jj<=n;jj++){
  //    cout << g[ii][jj] ;
  //    if(jj!=n){
  //      cout << " ";
  //    }
  //  }
  //  cout << endl;
  //}  
  
  t = 1;
  memset(seen,0,sizeof(seen));

  for(ii=1;ii<=n;ii++){
    if(seen[ii] == 0){
      dfs(ii);
    }

  }


  for(ii=1;ii<=n;ii++){
    cout << ii << " " << stamp[0][ii] << " " << stamp[1][ii] << endl;
  }
  return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define fr(i,f,t) for(ll i=(f);i<t;i++)
#define fb(i,f,t) for(ll i=(f);i>=t;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    string s;
    cin>>s;
    int n = s.size();
    // vector<vector<int>> vec(n,vector<int>(2019,0));
    vector<int> vec(2019,0);
    vec[int(s[0]) - 48] = 1;
    int cnt = 0;
    for(int i=1;i<n;i++){
    	vector<int> temp(2019,0);
    	for(int m=0;m<2019;m++){
    		if(vec[m]>0){
    			int num = m*10+int(s[i])-48;
    			temp[num%2019] = vec[m];
    		}
    	}
    	temp[int(s[i])-48]++;
    	cnt+=temp[0];
    	vec = temp;
    }
    cout<<cnt<<endl;
    // int cnt = 0;
    // for(int i=0;i<n;i++){
    // 	cnt+=vec[i][0];
    // }
    // cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3748
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    A, B = LI()
    print(A*B - A - B + 1)

main()


Measured memory_bytes: 6476
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll,ll>
#define PP pair<P,P>
using namespace std;

int main(){
    int x,n; cin >> x >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    int ans=0;
    int now=INF;
    for(int j=-101; j<=200; j++){
        bool check=true;
        rep(i,n){
            if(j+1==p[i]){
                check=false;
                break;
            }
        }
        if(check==false) continue;
            if(abs(x-(j+1))<now){
                ans=j+1;
                now=abs(x-(j+1));
            }
    }
    cout << ans << endl;
return 0;
}



Measured memory_bytes: 3632
N = int(input())
a = 0
w = 0
t = 0
r = 0
for i in range(N):
    x = input()
    if x == "AC":
        a += 1
    elif x == "WA":
        w += 1
    elif x == "TLE":
        t += 1
    else:
        r += 1
print("AC x " + str(a))
print("WA x " + str(w))
print("TLE x " + str(t))
print("RE x " + str(r))

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

int main(){
  string a,b;
  cin >> a >> b;
  vector<char> s(a.begin(), a.end());
  vector<char> t(b.begin(), b.end());
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  
  vector<int> sdata, tdata;
  char tmp;
  tmp = s[0];
  sdata.push_back(1);
  for(int i = 1; i < s.size(); i++){
    if(tmp == s[i]) sdata[sdata.size() - 1] += 1;
    else{
      tmp = s[i];
      sdata.push_back(1);
    }
  }
  
  tmp = t[0];
  tdata.push_back(1);
  for(int i = 1; i < t.size(); i++){
    if(tmp == t[i]) tdata[tdata.size() - 1] += 1;
    else{
      tmp = t[i];
      tdata.push_back(1);
    }
  }
  
  sort(sdata.begin(), sdata.end());
  sort(tdata.begin(), tdata.end());
  
  if(sdata == tdata) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl

//-----
const int N = 1e3 + 7, MOD = 1e9 + 7;
int add(int a, int b) { if ((a += b) >= MOD) a -= MOD; return a; }
int mul(int a, int b) { return ll(a) * b % MOD; }
int qpow(int a, int b) { int r = 1; for (;b;b>>=1) {if (b&1)r=mul(r,a);a=mul(a,a);}return r; }
int n, k, dp[N];
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
  cin >> n >> k;
  vi v;
  for (int i = 1; i * i <= n; i++) if (n % i == 0) {
  	v.pb(i);
  	if (i * i <= n) v.pb(n / i);
	}
	sort(all(v));
	int ans = 0;
	rep(i, 0, sz(v)) {
		dp[i] = qpow(k, v[i] + 1 >> 1);
		rep(j, 0, i) if (v[i] % v[j] == 0) dp[i] = add(dp[i], MOD - dp[j]);
		if (v[i] & 1) ans = add(ans, mul(dp[i], v[i]));
		else ans = add(ans, mul(dp[i], v[i] >> 1));
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import sys
import math

input = sys.stdin.readline# 最小公倍数
 
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)    
a, b, c, d = map(int, input().split())
e = lcm(c, d)
#print("e: {}".format(e))
#print("c: {} - {}".format(b // c, (a - 1) // c))
#print("d: {} - {}".format(b // d, (a - 1) // d))
#print("e: {} - {}".format(b // e, (a - 1) // e))
count_c = b // c - (a - 1) // c
count_d = b // d - (a - 1) // d
count_e = b // e - (a - 1) // e
# b - a の中から d の倍数の個数を取得
#print("count_c: {}".format(count_c))
#print("count_d: {}".format(count_d))
#print("count_e: {}".format(count_e))
print(b - a + 1 - (count_c + count_d - count_e))

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>

int main(void){
    int i, N, V, j, k;
    int *In;
    
    scanf("%d",&N);
    In = (int*)malloc(sizeof(int)*N);
      for(k=0 ; k<N ; k++){
            scanf("%d",&In[k]);
        }
  printf("%d",In[0]);
             for(k=1 ; k<N ; k++){
            printf(" %d",In[k]);
        }
        printf("\n");
  
    
    for(i=1 ; i<N ; i++){
        V=In[i];
        j=i-1;
        while(j>=0 && In[j]>V){
            In[j+1] = In[j];
            j--;
            In[j+1]=V;
        }
        printf("%d",In[0]);
        for(k=1 ; k<N ; k++){
            printf(" %d",In[k]);
        }
        printf("\n");
    }
    
    return 0;
}



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

int main(){
  int ans,f=0;cin>>ans;
  REP(i,9)REP(j,9) if((i+1)*(j+1)==ans) f=1;
  cout<<(f?"Yes":"No");  
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	FOR(i, 0, h) {
		string s;
		cin >> s;
		cout << s << endl;
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int h,n;
pair<int,long long> p[1010];
bool f[1010];
long long dp[30001];
int main()
{
    cin>>h>>n;
    for(int i=0;i<n;i++)
    {
    	int a;
    	long long b;
    	cin>>a>>b;
    	p[i]=make_pair(a,b);
	}
	sort(p,p+n);
	for(int i=0;i<n-1;i++){
		if(p[i].first==p[i+1].first)
		f[i+1]=true;
	}
	long long mn=LONG_LONG_MAX;
	for(int i=n-1;i>=0;i--){
		if(p[i].second>mn)
		f[i]=true;
		else mn=p[i].second;
	}
	for(int i=0;i<2*h+1;i++)
	{
		dp[i]=1000000000000;
	}
	dp[0]=0;
	long long ans=LONG_LONG_MAX,mi;
	for(int i=0;i<n;i++)
	{
		if(f[i]) continue;
		int a=p[i].first;
		long long b=p[i].second;
		if(a>h)
		{
			ans=min(ans,b);
		}
		int na=a;
		long long nb=b;
		while(na<=2*h)
		{
			dp[na]=min(dp[na],nb);
			if(dp[na]==nb&&h>na)
			{
				for(int j=1;j<=2*h-na;j++)
				{
					dp[j+na]=min(dp[j+na],dp[j]+dp[na]);
				}
			}
			na+=a;
			nb+=b;
		}
	}
	for(int i=h;i<=2*h;i++)
	{
		if(ans>dp[i]) mi=i;
		ans=min(ans,dp[i]);
	}
	cout<<ans;
	return 0;
}

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

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String[] line;
      MyList list = new MyList();

      for(int i=0; i<n; i++) {
        line = br.readLine().split(" ");
        switch( line[0] ) {
          case "insert" :
            list.insertFirst( Integer.parseInt(line[1]) );
            break;
          case "delete" :
            list.delete( Integer.parseInt(line[1]) );
            break;
          case "deleteFirst" :
            list.deleteFirst();
            break;
          case "deleteLast" :
            list.deleteLast();
            break;
          default :
            System.out.println("n:" + i + " is failed.");
        }
      }

      System.out.println ( list.getAllElements() );
    }
  }
}

class Node {
  Node next,prev;
  int key;

  public Node(int key) {
    this.key = key;
  }
}

class MyList {
  Node nil;
  Node current;
  int size;

  public MyList() {
    nil = new Node(0);
    nil.next = nil.prev = nil;
    size = 0;
  }

  public String getAllElements() {
    StringBuilder buf = new StringBuilder(size*2);

    if(size > 0){
      current = nil.next;
      for(int i=0; i<size; i++){
        buf.append(current.key).append(" ");
        current = current.next;
      }
    }
    buf.setLength(buf.length()-1);

    return buf.toString();
  }
  public void insertFirst(int x) {
    if(size == 0) {
      current = new Node(x);
      nil.next = current;
      nil.prev = current;
      current.prev = nil;
      current.next = nil;
      size++;
    }
    else {
      Node add = new Node(x);
      
      current.prev.next = add;
      add.prev = current.prev;

      add.next = current;
      current.prev = add;

      current = add;
      size++;
    }
  }
  public void deleteFirst() {
    nil.next = current.next;
    current.next.prev = current.prev;

    current = current.next;
    size--;
  }
  public void deleteLast() {
    current = nil.prev;

    nil.prev = current.prev;
    current.prev.next = current.next;

    current = nil.next;
    size--;
  }
  public void delete(int x) {
    Node target = findFirst(x);

    if(target == nil) current = current.next;
    else {
      current.prev.next = target.next;
      current.next.prev = target.prev;
      current = nil.next;
      size--;
    }
  }
  private Node findFirst(int x) {
    while(current != nil) {
      if(current.key == x) break;
      current = current.next;
    }

    return current;
  }
}


Measured memory_bytes: 188900
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; i++)
static const long long INF = 1000000;
using p = pair<int64_t,int64_t>;

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

int main(){
    string s;
    cin >> s;
    int l = s.length();
    vector<int> vec(l);
    rep(i,l){
        int x = s[i] - '0';
        vec[i] = x;
    }
    reverse(vec.begin(),vec.end());
    //動的計画法。下n-1桁までのみを考えたときの使った紙幣の最小値。次の位から繰り下がりが発生するのかによって場合分け。
    //繰り上がりが発生した場合、次の桁に影響が出る。
    //最後一桁の処理をどうするのか。
    vector <vector<int>> dp(l,vector<int>(2,0));
    dp[0][0] = vec[0];
    dp[0][1] = 10 - vec[0];
    for (int i = 1; i < l; i++){
        dp[i][0] = min(dp[i-1][0] + vec[i],dp[i-1][1] + vec[i] +1);
        dp[i][1] = min(dp[i-1][0] + 10 - vec[i],dp[i-1][1] + 9 - vec[i]);
        
    }
    dp[l-1][1]++;
    int64_t x = min(dp[l-1][0], dp[l-1][1]);
    cout << x << endl;

}

Measured memory_bytes: 62852
#include<bits/stdc++.h>
using namespace std;
int a[50][50];
int vis[50];
int to1=0,to2=0;
int main(){
	for(int i=1;i<=3;i++){
		int u,v;
		cin>>u>>v;
		vis[u]++;vis[v]++;
	}
	for(int i=1;i<=4;i++){
		if(vis[i]>2){
			puts("NO");
			return 0;
		}
		if(vis[i]==1) to1++;
		if(vis[i]==2) to2++;
	}
	if(to1==2&&to2==2){
		puts("YES");
	}else puts("NO");
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();

    List<Integer> list = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      list.add(sc.nextInt());
    }

    Integer max = Collections.max(list);

    list.remove(list.indexOf(max));

    int sum = list.stream()
      .mapToInt(v -> v)
      .sum();

    if(max < sum) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 28628