akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

template <typename T>
struct Graph {
    int V, E;
    struct Edge {
        int from, to;
        T cost;
    };
    vector<vector<Edge>> edge;
    vector<vector<T>> dist;
    vector<Edge> es;

    Graph(int V, int E) : V(V), E(E) {
        edge.assign(V, vector<Edge>(0));
        dist.assign(V, vector<T>(0));
    }

    void input(bool is_direct, bool inputc, bool index0 = false) {
        int a, b;
        T c = 0;
        for (int i = 0; i < E; i++) {
            cin >> a >> b;
            if (inputc) cin >> c;
            if (!index0) a--, b--;
            edge[a].push_back((Edge){a, b, c});
            es.push_back((Edge){a, b, c});
            if (!is_direct) {
                edge[b].push_back((Edge){b, a, c});
                es.push_back((Edge){b, a, c});
            }
        }
        if (!is_direct) E *= 2;
    }

    void add_edge(int from, int to, T cost, bool is_direct) {
        edge[from].push_back({from, to, cost});
        es.push_back({from, to, cost});
        if (!is_direct) {
            edge[to].push_back({to, from, cost});
            es.push_back({to, from, cost});
            E++;
        }
        E++;
    }

    typedef pair<T, int> P;  // (first,second) := (最短距離,頂点番号)
    // 頂点rからの最小距離
    void dijkstra(int r = 0) {
        dist[r].assign(V, INF);

        priority_queue<P, vector<P>, greater<P>> que;
        que.push(P(0, r));
        dist[r][r] = 0;

        while (que.size()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (dist[r][v] < p.first) continue;
            for (int i = 0; i < edge[v].size(); i++) {
                Edge e = edge[v][i];
                if (dist[r][v] + e.cost < dist[r][e.to]) {
                    dist[r][e.to] = dist[r][v] + e.cost;
                    que.push(P(dist[r][e.to], e.to));
                }
            }
        }
    }
};

struct Circle {
    double x, y, r;

    double dist(Circle& c) {
        double d = sqrt((c.x - x) * (c.x - x) + (c.y - y) * (c.y - y));
        return max(d - (c.r + r), 0.0);
    }
};

int main() {
    Circle cs, ct;
    int N;
    cin >> cs.x >> cs.y >> ct.x >> ct.y >> N;
    cs.r = ct.r = 0;
    vector<Circle> p(N + 2);
    p[0] = cs, p[N + 1] = ct;
    for (int i = 1; i <= N; i++) {
        Circle c;
        cin >> c.x >> c.y >> c.r;
        p[i] = c;
    }
    Graph<double> g(N + 2, 0);
    for (int i = 0; i < N + 2; i++) {
        for (int j = i + 1; j < N + 2; j++) {
            g.add_edge(i, j, p[i].dist(p[j]), false);
        }
    }
    g.dijkstra();
    cout << setprecision(12) << g.dist[0][N + 1] << endl;
    return 0;
}

Measured memory_bytes: 40676
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int k,a,b; cin >> k >> a >> b;
  bool ok = false;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) { ok = true; }
  }
  COUT(ok ? "OK" : "NG");
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

using namespace std;

ll cal(ll k){
    ll sum = 0;
    for (ll i = 1; i <= k; ++i)
    {
        sum += i;
    }
    if(k <= 0) return 0;
    else return sum;
}

int main() {

    ll n; cin >> n;
    ll ans = 0;

    rep(i,n) ans += i;

    cout << ans;


    return 0;
}











Measured memory_bytes: 3632
n,x = map(int,input().split())
l = list(map(int,input().split()))
d = [0]*(n+1)
ans = 1

for i in range(1,n+1):
    d[i] = d[i-1]+l[i-1]
    if x < d[i]:
        break
    ans += 1

print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;

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

		String line = sc.nextLine();
		String[] lines = line.split(" ");

		int N = Integer.parseInt(lines[0]);
		int M = Integer.parseInt(lines[1]);
		long K = Long.parseLong(lines[2]);
		long[] A = new long[N];
		long[] B = new long[M];

		line = sc.nextLine();
		lines = line.split(" ");
		for (int i = 0; i < N; i++) {
			A[i] = Long.parseLong(lines[i]);
		}

		line = sc.nextLine();
		lines = line.split(" ");
		for (int i = 0; i < M; i++) {
			B[i] = Long.parseLong(lines[i]);
		}

		long t = 0;
		for(int i = 0; i < M; i++) {
			t = t + B[i];//先にBをすべて読んだ時の時間を足しておく
		}

		int count = 0;
		int j = M;
		for(int i = 0; i < A.length+1; i++) {//Aがi冊で、Bがj冊
			while(j > 0 &&  t > K) {
				j--;
				t = t - B[j];
			}

			if(t > K) {
				break;
			}
			count = Math.max(count, i+j);
			if(i == N) {
				break;
			}
			t = t + A[i];
		}

		System.out.println(count);
	}
}

Measured memory_bytes: 105840
#include<stdio.h>
int main(void)
{
    int n,a,s,x,i;
    while(1)    {
        scanf("%d",&a);
        if(a==0)    break;
        s=0;
        for(i=0;i<9;i++){
            scanf("%d",&n);
            s+=n;
        }
        x=a-s;
        printf("%d\n",x);
    }
    return 0;
}


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

using namespace std;

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

#define pb push_back
#define mp make_pair

int n;
int mas[50][26];

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        for(auto u: s){
            mas[i][u - 'a']++;
        }
    }
    string res;
    for(int i = 0; i < 26; i++){
        int mn = 50;
        for(int j = 0; j < n; j++){
            mn = min(mn, mas[j][i]);
        }
        for(int j = 0; j < mn; j++) res.pb(i + 'a');
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()

r = 0
for i in range(1,N):
    if S[i] == "E":
        r += 1
ans = r
l = 0
for i in range(1,N):
    if S[i-1] == "W":
        l += 1
    if S[i] == "E":
        r -= 1
        
    ans = min(ans, l + r)

print(ans)

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
const ll mod=998244353;
int main()
{
	ll n,cou=2;
	scl(n);
	if(n==2){
		pf("1\n");return 0;
	}
	for(ll i=2;i*i<=n;i++){
		ll u=n;
		if(u%i==0){
			while(u%i==0)u/=i;
			if(u%i==1)cou++;
		}else {
			if(u%i==1)cou+=2;
			if(i*i==n-1)cou--;
		}
	}
	pf("%lld\n",cou);
}


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

int main () {
  int k,s;cin >> k >> s;
  int ans=0;
  for(int i=0;k>=i;++i){
    for(int j=0;k>=j;++j){
      int z = s - i - j;
      if (z>k || z < 0) continue;
      ++ans;
    }
  }
  cout << ans << endl;
  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();
        int A=sc.nextInt();
        int B=sc.nextInt();
        int C=A*N;
        if (C <= B){
            System.out.println(C);
        }else{
            System.out.println(B);
        }
    }
}


Measured memory_bytes: 22612
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	int N,M;
	cin>>N>>M;
	vint A;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		A.pb(a);
	}
	//ax+b
	//xの係数を格納する
	ll a[SIZE]={};
	//定数を格納する
	ll b[SIZE]={};
	for(int i=1;i<N;i++){
		int s=A[i-1],t=A[i];
		//s<t
		if(s<t){
			//s以下のところに定数を足す
			b[1]+=t-s;
			b[s+1]-=t-s;
			//s超過t以下のところに線形と定数を足す
			a[s+1]+=-1;
			a[t+1]-=-1;
			b[s+1]+=1+t;
			b[t+1]-=1+t;
			//t超過のところに定数を足す
			b[t+1]+=t-s;
		}
		//t<s
		else{
			//t以下のところに線形と定数を足す
			a[1]+=-1;
			a[t+1]-=-1;
			b[1]+=1+t;
			b[t+1]-=1+t;
			//t超過s以下のところに定数を足す
			b[t+1]+=M-s+t;
			b[s+1]-=M-s+t;
			//s超過のところに線形と定数を足す
			a[s+1]+=-1;
			b[s+1]+=1+M+t;
		}
	}
	//累積和を取る
	for(int i=1;i<SIZE;i++){
		a[i]+=a[i-1];
		b[i]+=b[i-1];
	}
	//線形をx倍する
	for(int i=0;i<SIZE;i++)
		a[i]*=i;
	ll ans=INFLL;
	for(int i=1;i<=M;i++)
		ans=min(ans,a[i]+b[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2296
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    int ans = 0;
    rep(i,n){
        int j = 1;
        while(i+j<n){
            if(a[i]==a[i+j]){
                j++;
            }else{
                break;
            }
        }
        ans +=j/2;
        i+=j-1;
    }
    cout << ans << endl;
}

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

using namespace std;

int N;
int cnt, a[100009];

void Ans (bool ok)
{
    if (ok) printf ("Yes\n");
    else printf ("No\n");
    exit (0);
}

/*int cnt[109], a[109], ap[109];
bool maybe[109][109];
void back (int pos, int ma)
{
    if (pos == N + 1)
    {
        for (int i=1; i<=N; i++)
        {
            cnt[i] = 0;
            for (int j=1; j<=N; j++)
                if (j != i)
                    cnt[i] += (++ap[a[j]] == 1);
            for (int j=1; j<=N; j++)
                ap[a[j]] = 0;
        }
        sort (cnt + 1, cnt + N + 1);
        int times = 0;
        for (int i=1; i<=N; i++)
            if (cnt[i] == cnt[1])
                times = i;
        maybe[cnt[1]][times] = 1;
        return ;
    }
    for (a[pos] = 1; a[pos] <= ma + 1; a[pos] ++)
        back (pos + 1, max (ma, a[pos]));
}*/

bool isOk (int mini, int cnt)
{
    if (cnt == N) return (mini <= N / 2 || mini == N - 1);
    if (mini <= (N - 1) / 2) return (cnt <= mini);
    if (mini >= N - 1) return 0;
    int st, dr = mini;
    if (N % 2 == 0)
    {
        if (mini == N / 2) st = 2;
        else st = 2 + 2 * (mini - N / 2);
    }
    else st = 1 + 2 * (mini - N / 2);
    return (st <= cnt && cnt <= dr);
}

/*void brute (int N)
{
    back (1, 0);
    for (int i=1; i<=N; i++, printf ("\n"))
        for (int j=1; j<=N; j++)
            printf ("%d", maybe[i][j]);
    printf ("\n\n");
    for (int i=1; i<=N; i++, printf ("\n"))
        for (int j=1; j<=N; j++)
            printf ("%d", isOk (i, j));
    for (int i=1; i<=N; i++)
        for (int j=1; j<=N; j++)
            if (isOk (i, j) != maybe[i][j])
            {
                printf ("WA (%d, %d)\n", i, j);
                exit (0);
            }
    printf ("OK\n");
    exit (0);
}*/

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
//brute (N);
for (int i=1; i<=N; i++)
    scanf ("%d", &a[i]);
sort (a + 1, a + N + 1);
if (a[N] - a[1] > 1) Ans (0);
for (int i=1; i<=N; i++)
    if (a[i] == a[1])
        cnt = i;
Ans (isOk (a[1], cnt));
return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll, ll>
#define pb push_back
#define ll long long
#define ld long double	
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
ll power(ll num, ll g, ll mod) {
	if (g == 0)return 1;
	if (g % 2 == 1)return (num * power((num * num) % mod, g / 2, mod)) % mod;
	return power( (num * num) % mod, g / 2, mod);
}


int main(){
	int a[6];
	int ans = -1;
	FOR1(i, 5){
		cin >> a[i];
		if (a[i]==0){
			ans = i;
		}
	}	
	cout << ans;
}

Measured memory_bytes: 3620
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; scanf("%d", &N);
    vector<string> U(N);
    for(int i=0; i<N; i++) cin >> U[i];
    int M; scanf("%d", &M);
    vector<string> T(M);
    for(int i=0; i<M; i++) cin >> T[i];

    bool open = false;
    for(int i=0; i<M; i++) {
        auto ptr = find(U.begin(), U.end(), T[i]);
        if(ptr == U.end()) {
            printf("Unknown %s\n", T[i].c_str());
        }
        else {
            open ^= true;
            if(open) {
                printf("Opened by %s\n", T[i].c_str());
            }
            else {
                printf("Closed by %s\n", T[i].c_str());
            }
        }
    }
    
    return 0;
}



Measured memory_bytes: 3352
"use strict"

const f = (A, B) => {
  return Math.max(String(A).length, String(B).length);
}

function Main(input) {
  input = parseInt(input.trim(), 10);
  const max = Math.floor(Math.sqrt(input));

  let ret = 1e10;
  for(let i=0; i<=max; i++){
    if(input%i === 0){
      let A = input / i;
      let k = f(A, i);
      if(k < ret) ret = k;
    }
  }

  console.log(ret);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21320
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    ll a,b,c,d,e,f,g,h;cin>>a>>b>>c>>d>>e>>f>>g>>h;
    string s,t,u;cin>>s>>t>>u;
    while(a){
        ll k=a%10;
        if(k==7)dame("Yes");
        a/=10;
    }
    out("No");
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
const int INF = 0x3f3f3f3f;

int A[2000005], B[2000005], C[10005];

int main(){
	int n, temp = 0;
	cin >> n;
	for(int i = 1; i <= n; i++)	scanf("%d", A + i);
	for(int i = 1; i <= n; i++)	C[A[i]]++;
	for(int i = 0; i < 10000; i++){
		temp += C[i];
		C[i] = temp;
	}
	for(int i = n; i > 0; i--){
		B[C[A[i]]] = A[i];
		C[A[i]]--;
	}
	for(int i = 1; i <= n; i++){
		if(i > 1)
			printf(" ");
		printf("%d", B[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 18840
#include <stdio.h>

int main(void) {
  
  int time[5];
  scanf("%d\n%d\n%d\n%d\n%d\n", &time[0], &time[1], &time[2], &time[3], &time[4]);
  
  int min_r = 1 << 29;
  int min_index = -1;
  for(int i = 0; i < 5; ++i) {
    
    int r = time[i] % 10;
    if(min_r > r && r != 0) {
      min_r = r;
      min_index = i;
    }
    
  }
  
  int total_time = 0;
  for(int i = 0; i < 5; ++i) {
    
    if(min_index == i) total_time += time[i];
    else {
      int r = time[i] % 10;
      if(r == 0) total_time += time[i];
      else total_time += (time[i] / 10 + 1) * 10;
    }
    
  }
  
  printf("%d\n", total_time);

  return 0; 
  
}

Measured memory_bytes: 128
#include <stdio.h>
int n,G[101][101];
int d[101];
int T = 0;
int F[101] = {0};
int k = 0;

void visit(int u) {
  int i,j,v;
  T++;
  d[u] = T;

  for(v=0;v<n;v++) {
    if(G[u][v] == 1 && d[v] == 0 ) {
      visit(v);
    }
  }

  T++;
  F[u] = T;

}



int main() {


  int i,j,k,l,u,a,t;

  for(i=0;i<n;i++) d[i] = 0;

  scanf("%d",&n);

  for(i=0;i<n+1;i++)
    for(j=0;j<n+1;j++) {
      G[i][j] = 0;

    }

  for(i=0;i<n;i++){

    scanf("%d %d ",&k,&u);
    //    printf("u = %d\n",u);

    for(j=0;j<u;j++) {
      scanf("%d",&a);
      G[k -1][a-1] = 1;
      // printf("G[%d][%d] = 1\n",i,k-1);
    }
  }
  for(i=0;i<n;i++) {
    if(d[i] == 0)
    visit (i);
  }

  for(i=0;i<n;i++) {
    printf("%d %d %d\n",i+1,d[i],F[i]);
  }
  return 0;


}

Measured memory_bytes: 636
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <cstdio>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}


int main()
{
    int n;
    cin>>n;
    vector<int>h(n);
    rep(i,0,n)
        cin>>h[i];
    int dp[100001];
    for(int i=0;i<n;i++)
        dp[i]=10e5;
    dp[0]=0;
    for(int i=1;i<=n;i++)
    {
        if(i>1)
            dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
        else if(i==1)
            dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
    }
    cout<<dp[n-1]<<endl;
    return 0;
}



Measured memory_bytes: 1024
s = input()
d = ["dream", "dreamer", "erase", "eraser"]
s = s[::-1]
can = False
for i in range(len(d)):
    d[i] = d[i][::-1]
while(s != ""):
    for i in range(4):
        if s[0:len(d[i])] == d[i]:
            s = s[len(d[i]):]
            break
    else:
        break
else:
    can = True
if can == True:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
constexpr int IINF = INT_MAX;

vector<vector<int> > g;
vector<int> p, lo, up, ans;

void dfs(int v, int pre){
    if(p[v] >= 0){
        lo[v] = max(lo[v], p[v]);
        up[v] = min(up[v], p[v]);
    }
    for(auto u : g[v]){
        if(u==pre) continue;
        lo[u] = lo[v]-1;
        up[u] = up[v]+1;
        dfs(u,v);
        lo[v] = max(lo[v], lo[u]-1);
        up[v] = min(up[v], up[u]+1);
    }
}

bool bfs(int root){
    if(lo[root] > up[root]) return false;
    ans[root] = lo[root];
    vector<bool> visited(g.size(),false);
    queue<int> que;
    que.push(root);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        visited[v] = true;
        for(auto u : g[v]){
            if(visited[u]) continue;
            if(lo[u] <= ans[v]-1 && up[u] >= ans[v]-1){
                ans[u] = ans[v]-1;
                que.push(u);
            }
            else if(lo[u] <= ans[v]+1 && up[u] >= ans[v]+1){
                ans[u] = ans[v]+1;
                que.push(u);
            }
            else{
                return false;
            }
        }
    }
    return true;
}

int main() {
    int n, k, root = -1;
    cin >> n;
    g.resize(n);
    lo.resize(n,-IINF/2);
    up.resize(n,IINF/2);
    ans.resize(n,-1);
    p.resize(n,-1);
    for(int i=0;i<n-1;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cin >> k;
    for(int i=0;i<k;i++){
        int v;
        cin >> v;
        cin >> p[--v];
        root = v;
    }
    dfs(root, -1);
    if(bfs(root)){
        cout << "Yes" << endl;
        for(int i=0;i<n;i++){
            cout << ans[i] << endl;
        }
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}


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

typedef long long ll;
typedef long double ld;

using namespace std;

const ll maxn = 200 * 1001;
const ll INF = 1e18;
const ll mod = 1e9+7;

vector<ll> g[maxn];
ll a[maxn], b[maxn];
ll n , m , k;
ll c[maxn], ans = 1;
ll par[maxn];

void dfs(ll u)
{
    ans = (ans * (k - c[par[u]])) % mod;
    c[par[u]]++;
    c[u]++;
    for(ll i = 0; i < g[u].size(); i++)
        if(g[u][i] != par[u])
        {
            c[g[u][i]] = 1;
            par[g[u][i]] = u;
            dfs(g[u][i]);
        }
}

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

    cin>> n >> k;
    for(ll i = 1; i < n; i++)
    {
        ll v, u; cin>> v >> u;
        g[v].push_back(u);
        g[u].push_back(v);
    }

    dfs(1);
    cout<< ans;
}







Measured memory_bytes: 14976
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________
	int r;
	cin >> r;
	cout << r*r << en;



	return 0;
}



Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main() {
  int W,a,b;
  cin >> W >> a >> b;
  int mi = min(a,b);
  int ans;
  if (mi == a) {
    ans = b-a-W;
    if (ans < 0) {
      ans = 0;
    }
  }
  else if (mi == b) {
    ans = a-b-W;
    if (ans < 0){
      ans = 0;
    }
  }
  cout << ans << endl;
}
        
        

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

int n;
vector<int> g[100];
bool used[100];

int dfs(int now){
    int res = 0;
    used[now] = true;
    for(auto &nxt : g[now]){
        if(!used[nxt]){
            res = max(res, dfs(nxt));
        }
    }
    used[now] = false;
    return res+1;
}

int main(){
    while(cin >> n, n){
        for(int i=0;i<100;i++) g[i].clear();
        for(int i=0;i<n;i++){
            int a, b;
            cin >> a >> b;
            a--; b--;
            g[a].push_back(b);
            g[b].push_back(a);
        }
        int ans = 0;
        for(int i=0;i<100;i++){
            ans = max(ans, dfs(i));
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3016
fun main (args: Array<String>) {
    val userInput : String = readLine()!!
    val userMoney : Int    = userInput.toInt()
    val fiveHundredCoins:Int = Math.floor(userMoney.toDouble()/500.0).toInt()
    val fiveYenCoins : Int  = Math.floor((userMoney.toDouble() - (fiveHundredCoins*500).toDouble()) / 5.0).toInt()
    println(fiveHundredCoins*1000 + fiveYenCoins * 5)
}

Measured memory_bytes: 29816
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 998244353;


int main() {
    string S;
    int K;
    cin >> S >> K;
    int cnt = 0;
    for(int i = 0; i < S.size(); i++){
        if(S.at(i) == '1'){
            cnt++;
        }else{
            break;
        }
    }
    if(cnt >= K){
        cout << '1' << endl;
    }else{
        cout << S.at(cnt) << endl;
    }
}

Measured memory_bytes: 256
var tbd = "TBD";
var hs = "Heisei";

function Main(input){
	input = input.split("/").map(a=>~~a);
  var y = input[0];
  var m = input[1];
  var d = input[2];
  
  if(y >= 2020)return tbd;
  if(y <= 2018)return hs;
  
  if(m >= 5)return tbd;
  
  return hs;
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
2019/11/01
`);

Measured memory_bytes: 7372
#include <cstdio>
#include <cmath>

using namespace std;
int min(int a, int b){
	if(a > b) return b;
	else return a;
}
int max(int a, int b){
	if(a > b) return a;
	else return b;
}

int N;
int A[3];
int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		int v;
		scanf("%d", &v);
		int m = v % 3;
		A[m]++;
	}
	if(A[1] == 0 && A[2] == 0){
		printf("1\n");
	}else{
		int minv = min(A[1], A[2]);
		int maxv = max(A[1], A[2]);
		int ans = A[0] + minv + min(maxv, minv + 3);
		printf("%d\n", ans);
	}
}
	

Measured memory_bytes: 1028
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll dr[100100];
ll dl[100100];
ll ans[100100];

int main(){
	clr(dr,0);
	clr(dl,0);
	clr(ans,0);
  string s;
  cin>>s;
  rep(i,0,s.sz){
  	if(s[i]=='R'){
  		dr[i+1]++;
  		dr[i+1]+=dr[i];
  	}
  }
  per(i,0,s.sz){
  	if(s[i]=='L'){
  		dl[i+1]++;
  		dl[i+1]+=dl[i+2];
  	}
  }
  rep(i,0,s.sz-1){
  	if(s[i]=='R'&&s[i+1]=='L'){
  		ll p = i+1;
  		ans[p]+=(dr[p]+1)/2;
  		ans[p+1]+=dr[p]/2;
  		ans[p+1]+=(dl[p+1]+1)/2;
  		ans[p]+=dl[p+1]/2;
  	}
  }
  rep(i,1,s.sz+1){
  	cout << ans[i];
  	if(i!=s.sz)cout << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const int MAX = 510000;
const ll MOD = 1000000007;
const ll N_MAX = 100100;
vector<ll> arr(N_MAX);

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void Eratosthenes(){
	for(int i = 2; i < N_MAX; i++){
		arr[i] = 1;
	}
	for(int i = 2; i < sqrt(N_MAX); i++){
		if(arr[i]){
			for(int j = 0; i * (j + 2) < N_MAX; j++){
				arr[i *(j + 2)] = 0;
			}
		}
	}
    //arr[i]=1が素数
}

int main() {
    ll N,M;
    cin >> N >> M;
    ll tmp=M;
    COMinit();
    Eratosthenes();
    vector<ll> cnt;
    for(int i=0;i<=ceil(sqrt(M));i++){
        if(arr[i]!=1) continue;
        else{
            ll ct=0;
            while(tmp%i==0){
                tmp/=i;
                ct++;
            }
            if(ct!=0)cnt.push_back(ct);

        }
    }
    if(tmp!=1)cnt.push_back(1);
    ll ans=1;
    for(int i=0;i<cnt.size();i++){
        ans=(ans*COM(N+cnt[i]-1,cnt[i]))%MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12928
//https://atcoder.jp/contests/agc005/tasks/agc005_a
//A - STring
//累積和s,tのカウント、tの時点でtが多い分は残る
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    string x; cin>>x;
    ll tn=0,sn=0;
    ll ans=0;
    REP(i,x.size()){
        if(x[i]=='T'){
            ++tn;
            ans=max(ans,tn-sn);
        } else {
            ++sn;
        }
    }
    cout<<ans*2<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
const int MAXN = 55;

int n, p, a[MAXN];

ll f[MAXN][2] = {0};
void solve() {
	f[0][0] = 1;
	for( int i = 1; i <= n; ++i ) {
		for( int j = 0; j < 2; ++j ) {
			int b = a[i];
			f[i][j] += f[i-1][j];
			f[i][j] += f[i-1][j^b];
		}
	}
	printf( "%lld\n", f[n][p] );
}

int main() {
	scanf( "%d%d", &n, &p );
	for( int i = 1; i <= n; ++i ) {
		scanf( "%d", a+i );
		a[i] = a[i] & 1;
	}
	solve();
	return 0;
}


Measured memory_bytes: 256
#coding:utf-8
s = input()
ls_s = []
Skip = 0
s2 = ""
for i in range(len(s)-1):
    if Skip:
        Skip = 0
    elif s[i:i+2] == "BC":
        s2 += 'W'
        Skip = 11
    elif s[i] == "A":
        s2 += 'B'
    else:
        ls_s.append(s2)
        s2 = ""
ls_s.append(s2)
#print (ls_s)
        
def bw(s):
    ls = []
    cnt_b =0
    for i in range(len(s)):
        if s[i] == "W":
            ls.append(cnt_b)
        else:
            cnt_b+=1
    return sum(ls)
sm = 0
for s2 in ls_s:
    sm += bw(s2)
print (sm)


Measured memory_bytes: 5484
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;


int main(void) {
	int n,t;
	cin >> n >> t;
	int ans=100000;
	for(int i=0; i<n; i++){
		int tm,cst;
		cin >> cst >> tm;
		if(tm<=t)ans=ans<cst?ans:cst;
	}
	if(ans==100000){
		cout << "TLE" << endl;
		return 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, Q;
ll B[100005];
ll C[100005];
unordered_map<ll, ll> U;

int main() {
  INCANT;
  cin >> N;
  int a;
  ll sum=0;
  rep(i, N) {
    cin >> a;
    U[a]++;
    sum+=a;
  }
  cin >> Q;
  rep(i, Q) {
    cin >> B[i] >> C[i];
  }
  rep(i, Q) {
    sum+=U[B[i]]*(C[i]-B[i]);
    U[C[i]]+=U[B[i]];
    U[B[i]]=0ll;
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 8536
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007
int acs(const void* a, const void* b) { return *(int*)a - *(int*)b; } // 1,2,3,4
int des(const void* a, const void* b) { return *(int*)b - *(int*)a; } // 8,7,6,5
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } // a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } // aaa,aab
//temmie_のsnippet

#define N 101

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

	return 0;
}

Measured memory_bytes: 1708
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  (B) <= (A) && (A) <= (C)
#define AIN(A, B, C) assert(IN(A, B, C))
void solve(){
     int n;
     cin>>n;
     set<string>s;
     for(int i=0;i<n;i++){
     	string ss;
     	cin>>ss;
     	s.insert(ss);
     }
     cout<<s.size();
}
int main() {
    ios;
	int t=1;
	//cin>>t;
	while(t--)solve();
 
    
}


Measured memory_bytes: 19284
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define sz(a) int(a.size())
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
#define lson l,mid,p<<1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps=1e-8;
const int mod=1e9+7;
const int N=1e5+10;
const int inf=1e9;
int n,q,a[N];
int main(){
    //ios::sync_with_stdio(false);
    //freopen("in","r",stdin);
    scanf("%d",&n);
    ll ans=0;
    rep(i,1,n){
        int x;
        scanf("%d",&x);
        a[x]++;
        ans+=x;
    }
    scanf("%d",&q);
    rep(i,1,q){
        int b,c;
        scanf("%d%d",&b,&c);
        ans-=1ll*b*a[b];
        ans+=1ll*c*a[b];
        a[c]+=a[b];
        a[b]=0;
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 4196
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <tuple>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<tuple<int, int, int>> data(M);
    int p, y;

    REP(i, M)
    {
        cin >> p >> y;
        data.at(i) = make_tuple(y, p, i);
    }

    sort(data.begin(), data.end());

    vector<pair<int, int>> id(M);
    map<int, int> cnt;
    REP(i, M)
    {
        int p, y, idx;
        tie(y, p, idx) = data.at(i);
        cnt[p]++;
        id.at(idx) = make_pair(p, cnt[p]);
    }

    REP(i, M)
    {
        cout << setw(6) << setfill('0') << id.at(i).first;
        cout << setw(6) << setfill('0') << id.at(i).second << endl;
    }
}

Measured memory_bytes: 8192
N=int(input())
W=[]
same=[]
counter=0
for i in range(N):
    W.append(input())

for i in range(len(W)):
    for x in range(i+1,len(W)):
        if W[i]==W[x]:
            same.append(W[i])
  
for i in range(len(W)-1):
    if len(same)!=0:
        counter=0
        break
    
    if W[i][-1]==W[i+1][0]:
        counter+=1
        
        
    if W[i][-1]!=W[i+1][0]:
        counter+=0
        
if counter==len(W)-1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/priank/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vector<vi> e,d;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

void dfs(vi &d,lli u,lli p,lli h)
{
    d[u]=h;
    for(auto x:e[u])
    {
        if(x!=p)
            dfs(d,x,u,h+1);
    }
}

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{
    lli s,t;
    cin>>n>>s>>t;
    e.resize(n+1,vi());
    d.resize(2,vi(n+1,INF));

    fo(i,n-1)
    {
        cin>>u>>v;
        e[u].pb(v);
        e[v].pb(u);
    }

    dfs(d[0],s,-1,0);
    dfs(d[1],t,-1,0);

    lli ans=0;

    repA(i,1,n)
    {
        if(d[0][i]>=d[1][i])
            continue;

        // if(d[0][i]%2==0)
        // {
            ans=max(ans,d[1][i]-1);
        //     continue;
        // }

    }

    cout<<ans<<endl;

}   aryanc403();
    return 0;
}


Measured memory_bytes: 10480
#include<bits/stdc++.h>
#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
#define ff first
#define ss second
/*----------------------------------------------------------------------*/

const int N = 1e5+5;
ll arr[N], arr2[N], b[N];

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n; cin>>n;
    FOR(i, 0, n+1) {
    	cin>>arr[i];
    	arr2[i] = arr[i];
    }
    FOR(i, 0, n) {
    	cin>>b[i];
    }
    ll ans = 0, mainans = 0;
    FOR(i, 0, n) {
    	ll tmp = min(b[i], arr[i]);
    	arr[i] -= tmp;
    	b[i] -= tmp;
    	ans += tmp;

    	tmp = min(b[i], arr[i+1]);
    	arr[i+1] -= tmp;
    	b[i] -= tmp;
    	ans += tmp;
    }
    mainans = ans;
    ans = 0;
    RFOR(i, n-1, 0) {
    	ll tmp = min(b[i], arr2[i+1]);
    	arr2[i+1] -= tmp;
    	b[i] -= tmp;
    	ans += tmp;

    	tmp = min(b[i], arr2[i]);
    	arr2[i] -= tmp;
    	b[i] -= tmp;
    	ans += tmp;
    }
    cout<<max(mainans, ans);

    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    int n, d, x;
    cin >> n;
    cin  >> d >> x;
    int a[n];
    rep(i, n)cin >> a[i];

    int res = x + n;
    rep(i, n)res+=(d-1)/a[i];

    cout << res << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    String s = "";
    s += sc.next();
    s += sc.next();
    s += sc.next();

    int a = Integer.parseInt(s);

    if ((a % 4) == 0) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }

  }
}

Measured memory_bytes: 39272
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Map;
import java.util.TreeMap;

public final class Main {
  public static void main(final String[] args) throws Exception {
    int max = 0;
    final Map<String, int[]> map = new TreeMap<>();

    try (final BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      for (int n = Integer.parseInt(br.readLine()); n > 0; n--) {
        final String s = br.readLine();
        final int[] c = map.get(s);
        if (c == null) {
          map.put(s, new int[] { 1 });
          if (max == 0) {
            max++;
          }
        } else {
          if (++c[0] > max) {
            max = c[0];
          };
        }
      }
    }
    try (final PrintWriter pw = new PrintWriter(System.out)) {
      for (Map.Entry<String, int[]> e : map.entrySet()) {
        if (e.getValue()[0] == max) {
          pw.println(e.getKey());
        }
      }
      pw.flush();
    }
  }
}


Measured memory_bytes: 57720
#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 <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <complex>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
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
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second.first
#define T4 second.second.second

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1.0e-9

int main(){
	int d;
	while(cin >> d){
		int ret=0;
		REP(i, 600/d)ret += i*i*d*d*d;
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int fp[200001]={1};
int main()
{
	int a=0,b=1;
	long long ans=0;
	string s;
	cin>>s;
    reverse(s.begin(),s.end());
    for(int i=0;i<s.length();i++)
	{
        a=(a+b*(s[i]-'0'))%2019;
		b=b*10%2019;
        ans+=fp[a];
        fp[a]++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3792