akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{	int a,b;
  cin>>a>>b;bool ok=true;
 char A[a][a];char B[b][b];
 for(int i=0;i<a;i++)
   for(int j=0;j<a;j++)cin>>A[i][j];
 for(int i=0;i<b;i++)
   for(int j=0;j<b;j++)cin>>B[i][j];
 for(int i=0;i<a-b;i++)
 {
   for(int j=0;j<a-b;j++)
   {	ok =true;
     for(int k=0;k<b;k++)
     {
       for(int l=0;l<b;l++)
       {
         	ok=ok & (A[i+k][j+l] == B[k][l]);
       }
     }
    if(ok)break;
   }
   if(ok)break;
 }
 if(ok)cout<<"Yes";
 else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0 ; i<(n) ; ++i)
#define rep1(i,n) for (int i=1 ; i<=(n) ; ++i)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
typedef long long ll;
using namespace std;

int main(){
  string c;
  cin >>  c;
  if(c>="a" && c<="z"){
    cout << "a" << endl;
  }else if(c>="A" && c<="Z"){
    cout << "A" << endl;
  }
  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 3e5;
int n, mod;
ll up[N], down[N], ans[N];
vector<int> G[N];
void dfs(int x, int f) {
	down[x] = 1;
	for (int u: G[x]) {
		if (u == f) continue;
		dfs(u, x);
		(down[x] *= down[u] + 1) %= mod;
	}
}
void dfs1(int x, int f) { //cout << x << ",";
	if (G[x].end() != find(G[x].begin(), G[x].end(), f))
		G[x].erase(find(G[x].begin(), G[x].end(), f));
	vector<ll> pre, suf;
	pre.resize(G[x].size() + 1);
	suf.resize(G[x].size() + 1);
	for (int i = 0; i < G[x].size(); ++i) {
		int u = G[x][i];
		pre[i] = down[u] + 1;
	}
	if (G[x].size())
		suf[G[x].size() - 1] = pre[G[x].size() - 1];
	for (int i = G[x].size() - 2; i >= 0; --i)
		suf[i] = suf[i + 1] * pre[i] % mod;
	for (int i = 1; i < G[x].size(); ++i)
		pre[i] = pre[i - 1] * pre[i] % mod;
	for (int i = 0; i < G[x].size(); ++i) {
		int u = G[x][i];
		ll tmp = up[x];
		if (i) tmp = tmp * pre[i - 1] % mod;
		if (i < G[x].size() - 1) tmp = tmp * suf[i + 1] % mod;
		(tmp += 1) %= mod;
		up[u] = tmp;
	}
	for (int u: G[x]) dfs1(u, x);
}
int main() {
	cin >> n >> mod;
	for (int i = 1; i < n; ++i) {
		int x, y;
		scanf("%d %d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	up[1] = 1;
	dfs(1, 0); 
	dfs1(1, 0);
	for (int i = 1; i <= n; ++i) {
		ll ans = up[i] * down[i] % mod;
		printf("%lld\n", ans);
	}
}



Measured memory_bytes: 29312
# Contest No.: ABC173
# Problem No.: B
# Solver:      JEMINI
# Date:        20200705

import sys
import heapq

def main():
    n = int(input())
    a, b, c, d = 0, 0, 0, 0

    for i in range(n):
        temp = input()
        if temp == "AC":
            a += 1
        elif temp == "WA":
            b += 1
        elif temp == "TLE":
            c += 1
        else:
            d += 1

    print("AC x", a)
    print("WA x", b)
    print("TLE x", c)
    print("RE x", d)
    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 69944
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 30
#define EPS 1e-9
 
class Point{
public:
    double x,y,z;
    Point(){}
    Point(double x,double y,double z) : x(x),y(y),z(z) {}
};
 
double getDistance(const Point &a,const Point &b){
    return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2)+pow(a.z-b.z,2));
}
 
istream &operator >> (istream &is,Point &p){
    is >> p.x >> p.y >> p.z;
    return is;
}
 
int main(){
    int N;
    Point point[MAX];
    while(cin >> N, N){
	double x = 0, y = 0, z = 0;
	for(int i = 0 ; i < N ; i++){
	    cin >> point[i];
	    x += point[i].x;
	    y += point[i].y;
	    z += point[i].z;
	}
	x /= N; y /= N; z /= N;
	int pos = -1;
	double d = 0.8, ans = 0;
	Point p(x,y,z);
	while(d > EPS){
	    for(int i = 0 ; i < 150 ; i++){
		ans = 0;
		for(int j = 0 ; j < N ; j++){
		    double dist = getDistance(p,point[j]);
		    if(ans < dist){
			ans = dist;
			pos = j;
		    }
		}
		p.x += (point[pos].x-p.x)*d;
		p.y += (point[pos].y-p.y)*d;
		p.z += (point[pos].z-p.z)*d;
	    }
	    d /= 2;
	}
	printf("%.6f\n",ans);
    }
    return 0;
}

Measured memory_bytes: 3184
def solve(n, a, b, c):
    res = 0
    for i in range(n):
        if (i + 1 < n) and (a[i+1] == a[i] + 1):
            res += c[a[i]-1]
        res += b[a[i]-1]
    return res

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
print(solve(n, a, b, c))

Measured memory_bytes: 3064
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
using namespace std;
using lint = long long;
template<class T> using grid = vector<vector<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
static const lint MOD = (lint)1e9+7;

int main()
{
    string S;
    cin >> S;

    for (int i = 0; i < SZ(S); i += 2)
    {
        if (!(S[i] == 'R' || S[i] == 'U' || S[i] == 'D'))
        {
            cout << "No" << endl;
            return 0;
        }
    }

    for (int i = 1; i < SZ(S); i += 2)
    {
        if (!(S[i] == 'L' || S[i] == 'U' || S[i] == 'D'))
        {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N, Q = map(int, input().split())

path = [[] for _ in range(N)]

for _ in range(N-1) :
    a, b, c, d = (int(i) for i in input().split())
    path[a-1].append((b-1, c-1, d))
    path[b-1].append((a-1, c-1, d))

# doublingに必要なKを求める
for K in range(18) :
    if 2 ** K >= N :
        break

# dfs
parent = [[-1] * N for _ in range(K)]
rank = [-1 for _ in range(N)]

rank[0] = 0
queue = [0]

while queue :
    cur = queue.pop()
    for nex, _, _ in path[cur] :
        if rank[nex] < 0 :
            queue.append(nex)
            parent[0][nex] = cur
            rank[nex] = rank[cur] + 1

# doubling        
for i in range(1, K) :
    for j in range(N) :
        if parent[i-1][j] > 0 :
            parent[i][j] = parent[i-1][parent[i-1][j]]

# lca
def lca(a, b) :
    if rank[a] > rank[b] :
        a, b = b, a

    diff = rank[b] - rank[a]
    i = 0
    while diff > 0 :
        if diff & 1 :
            b = parent[i][b]
        diff >>= 1
        i += 1
        
    if a == b :
        return a

    for i in range(K-1, -1, -1) :
        if parent[i][a] != parent[i][b] :
            a = parent[i][a]
            b = parent[i][b]

    return parent[0][a]

# Queryの先読み
schedule = [[] for _ in range(N)]
for i in range(Q) : 
    x, y, u, v = map(int, input().split())
    x, u, v = x-1, u-1, v-1
    l = lca(u, v)
    schedule[u].append((i, 1, x, y))
    schedule[v].append((i, 1, x, y))
    schedule[l].append((i, -2, x, y))

ret = [0] * Q
C = [0] * (N-1)
D = [0] * (N-1)

def dfs(cur, pre, tot) :
    for i, t, c, d in schedule[cur] :
        ret[i] += t * (tot - D[c] + C[c] * d)
    
    for nex, c, d in path[cur] :
        if nex == pre :
            continue
        C[c] += 1
        D[c] += d
        dfs(nex, cur, tot + d)
        C[c] -= 1
        D[c] -= d

dfs(0, -1, 0)
   
for i in range(Q) :
    print(ret[i])

Measured memory_bytes: 179672
#include<bits/stdc++.h>
using namespace std;
int n,m,x,y,a[110][110],b[110][110],f[10000000],p;
char s[110][110];
inline int pos(int i,int j,int k,int l)
{
	return ((i*(n-x+1)+j)*y+k)*(m-y+1)+l+1;
}
inline void maxx(int &x,int y)
{
	x=max(x,y);
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k,l,u,v,w;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
	  scanf("%s",&s[i][0]+1);
	for(i=1;i<=n;i++)
	  for(j=1;j<=m;j++)
	    {
		 a[i][j]=a[i][j-1]+(s[i][j]=='o');
		 b[i][j]=b[i-1][j]+(s[i][j]=='o');
		 if(s[i][j]=='E')
		   x=i,y=j;
		}
	for(i=0;i<x;i++)
	  for(j=0;j<=n-x;j++)
	    for(k=0;k<y;k++)
	      for(l=0;l<=m-y;l++)
	        {
			 w=f[pos(i,j,k,l)];
			 p=max(p,w);
			 if(x-i-1>j)
			   maxx(f[pos(i+1,j,k,l)],w+a[x-i-1][min(y+l,m-k)]-a[x-i-1][max(y-k,l+1)-1]);
			 if(x+j+1<=n-i)
			   maxx(f[pos(i,j+1,k,l)],w+a[x+j+1][min(y+l,m-k)]-a[x+j+1][max(y-k,l+1)-1]);
			 if(y-k-1>l)
			   maxx(f[pos(i,j,k+1,l)],w+b[min(x+j,n-i)][y-k-1]-b[max(x-i,j+1)-1][y-k-1]);
			 if(y+l+1<=m-k)
			   maxx(f[pos(i,j,k,l+1)],w+b[min(x+j,n-i)][y+l+1]-b[max(x-i,j+1)-1][y+l+1]);
			}
	printf("%d\n",p);
	return 0;
}


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

int main(){


  int M,D,cnt=0,i,j,k,l;
  cin >> M >> D;
  for(l=4;l<=M;l++){
   for(k=22;k<=D;k++){
    i = k/10;
    j = k%10;
    if(i>=2 && j>=2){
      if(i*j == l)
        cnt++;
    }
   }  
  }
  cout << cnt;
  return 0;
}


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

using ll = long long;
using pii = pair<int, int>; using pll = pair<ll, ll>;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)

template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ s >> p.first >> p.second; return s;}

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

    string ans;

    vector<ll> x(12);
    vector<ll> s(x.size());
    x[0] = 1;
    for (int i = 1; i < x.size(); i++) {
        x[i] = x[i-1] * 26;
        s[i] = s[i-1] + x[i];
    }

    for (int i = 1; i < x.size(); i++) {
        if (N <= s[i]) {
            N -= s[i-1]+1;
            for (int j = 1; j <= i; j++) {
                ans += 'a' + (N % 26);
                N /= 26;
            }
            break;
        }
    }
    reverse(ans.begin(), ans.end());

    cout << ans << endl;
}


Measured memory_bytes: 3588
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args){
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int A = sc.nextInt();
		int B = sc.nextInt();
		out.println(A*B-(A+B-1));
		out.flush();
	}
}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 21204
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#define IFD(...)
#ifndef NDEBUG
#define NDEBUG
#endif
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <cassert>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <boost/hana/functional/fix.hpp>
using boost::hana::fix;
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, b, a) for (int i = (b); i >= (a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int n;
    cin >> n;
    vector<int> a_s(n);
    rep(i, n) cin >> a_s[i];

    int b = 1;
    rep(i, n)
    {
        if (a_s[i] == b)
        {
            ++b;
        }
    }
    if (b == 1)
    {
        cout << -1 << endl;
        return 0;
    }
    cout << n - b + 1 << endl;

    return 0;
}


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

int main()
{
  string a, b, c; cin >> a >> b >> c;
  if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cout << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cout << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x,n) rep(__i,n) pri(x,__i);
#define prar(x,b,e) repr(__i,b,e) pri(x,__i);

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int tab[512][512];

int main() {
	int H = in();
	int W = in();
	int h = in();
	int w = in();
	
	if (H % h == 0 && W % w == 0) {
		cout << "No" << endl;
		return 0;
	}
	
	int n = (H / h) * (W / w);
	int minus = -999917231;
	int r = h * w - 1;
	if (r <= 0) {
		cout << "No" << endl;
		return 0;
	}
	int plus = -minus / r;
	if (minus % r == 0) plus--;
	
	ll sum = 0;
	rep(i,H) {
		rep(k,W) {
			if ((i+1) % h == 0 && (k+1) % w == 0) {
				sum += minus;
			}
			else {
			 	sum += plus;
			}
		}
	}
	if (sum <= 0) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	rep(i,H) {
		rep(k,W) {
			if ((i+1) % h == 0 && (k+1) % w == 0) {
				cout << minus;
			}
			else {
				cout << plus;
			}
			if (k < W - 1) cout << " ";
			else cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 2816
def rally(n, x):
    if not len(x) == n:
        return "==== pleas input based on n times in one line ===="
    else:
        mini = round(sum(x)/n)
        new_list = []
        for i in x:
            r = (i - mini)**2
            new_list.append(r)
        return (sum(new_list))


n = int(input())
x = list(map(int, input().split())) #input based on n
print(rally(n, x))



Measured memory_bytes: 3060
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
	int a,b,ans;
	string op;
	while(1)
	{
	cin >> a >> op >>b;
	if(op == "?")
	{
		break;
	}

	else if(op == "-")
	{
		ans = a-b;
	}

	else if(op == "*")
	{
		ans = a*b;
	}

	else if(op == "/")
	{
		ans = a/b;
	}
	if(op == "+")
		{
			ans = a+b;
		}

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

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

int main() {
  string S;
  cin >> S;
  if (S == "Sunny") cout << "Cloudy" << endl;
  else if (S == "Cloudy") cout << "Rainy" << endl;
  else if (S == "Rainy") cout << "Sunny" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
using namespace std;
 
int main() {
    string a;cin >> a;
    int cnt,est;
    cnt = 0;
    est = 0;
    size_t ant = a.size();
    for(int i=0;i<ant;i++){
        if(a[i]=='A' || a[i] == 'G' || a[i] == 'C' || a[i] == 'T'){
            cnt++;
            continue;
        }else{
            est = max(est,cnt);
            cnt = 0;
            continue;
        }
    }
    est = max(est,cnt);


    cout << est << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
typedef long long int ll ;
typedef vector< ll > vi ;
typedef pair<ll, ll > ii ;
int main()
{
    int n , x ;
    cin >> n >> x ;
    int a[n+1] ;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> a[i] ;
    }
    ll ans = 0;
    if(a[0] > x )
        ans += a[0] - x , a[0] = x ;
    for(int i = 1 ; i < n ; i ++ )
    {
        if( a[i] + a[i-1] > x )
        {
            ans += ( a[i] + a[i-1] ) - x;
            a[i] = a[i] -  (( a[i] + a[i-1] ) - x);
        }

    }
    cout << ans <<endl ;
}


Measured memory_bytes: 640
// WeirdBugsButOkay

#include <bits/stdc++.h>
 
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
 
using namespace std;

ll pow3(ll a,ll b,ll m=1000000007)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}

void solve()
{
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    ll p[a+1],q[b+1],r[c+1];
    for(ll i=1;i<a+1;i++)
        cin>>p[i];
    for(ll i=1;i<b+1;i++)
        cin>>q[i];
    for(ll i=1;i<c+1;i++)
        cin>>r[i];
    sort(p+1,p+a+1);
    sort(q+1,q+b+1);
    sort(r+1,r+c+1);
    reverse(p+1,p+a+1);
    reverse(q+1,q+b+1);
    reverse(r+1,r+c+1);
    p[0]=q[0]=r[0]=1000000000;
    ll k=x;
    ll l=y;
    ll ans=0;
    for(ll i=1;i<k+1;i++)
        ans+=p[i];
    for(ll i=1;i<l+1;i++)
        ans+=q[i];
    for(ll i=1;i<x+y+1&&i<c+1;i++)
    {
        if(r[i]<p[k]&&r[i]<q[l])
            break;
        else
        {
            if(p[k]<=q[l])
            {
                ans+=(r[i]-p[k]);
                k--;
            }
            else
            {
                ans+=(r[i]-q[l]);
                l--;
            }
        }
    }
    cout<<ans<<endl;
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll q=1;
    //cin>>q;
    for(ll i=0;i<q;i++)
    {
        solve();
    }
    return 0;
}

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  
  if(a.at(a.size()-1) == b.at(0) && b.at(b.size()-1) == c.at(0)){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		//????¨?????????£?¨?
		int sum = 0; //????¨????
		//n??????
		int n = sc.nextInt();
		//m??????
		int m = sc.nextInt();
		//A 2?¬??????????????????£?¨?
		int [][] A = new int[n][m];
		//B ???????????£?¨?
		int [] B = new int[m];
		//A???2?¬?????????????????´?
		for(int i = 0; i < n;i++){
			for(int j = 0; j < m; j++){
				A[i][j] = sc.nextInt();
				//A?????????????????????
				//System.out.println(A[i][j]);
			}
		}
		//B????????????????´?
		for(int i = 0; i < m; i++){
			B[i] = sc.nextInt();
		}
		//???????????¨???
		for(int i = 0; i < n; i++){
			sum = 0; //?????????
			for(int j = 0; j < m; j++){
				sum += A[i][j] * B[j];
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 40644
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

#define ROOT -1


/*****************************************************************************/
class Vertex
{
public:
    explicit Vertex(int p = -1, int l = INF) : pre(p), low(l){}
    int pre, low, parent = ROOT;
    bool visited = false;
};


/*****************************************************************************/
class Graph
{
private:
    int bridge = 0, time = 0;
    vector<vector<int>> edge;
    vector<Vertex> vertex;

    void dfs(int now)
    {
        vertex[now].visited = true;
        vertex[now].pre = vertex[now].low = ++time;

        for (int next : edge[now]) {
            if (!vertex.at(next).visited) {
                vertex[next].parent = now;
                dfs(next);
                vertex[now].low = min(vertex[now].low, vertex[next].low);
                if (vertex[next].low > vertex[now].pre) {
//                    cout << "now(" << now+1 << ") to next(" << next+1 << ") is bridge." << endl;
                    ++bridge;
                }
            } else if (next != vertex[now].parent) {
                vertex[now].low = min(vertex[now].low, vertex[next].pre);
            }
        }
    }

public:
    explicit Graph(int v)
    {
        edge = vector<vector<int>>(v);
        vertex = vector<Vertex>(v);
    }

    void add_edge(int from, int to)
    {
        edge[from].push_back(to);
        edge[to].push_back(from);
    }

    int low_link()
    {
        dfs(0);
        return bridge;
    }
};


/*****************************************************************************/
int main()
{
    int N, M; cin >> N >> M;
    Graph g = Graph(N);
    rep (i, 0, M) {
        int a, b; cin >> a >> b;
        --a; --b;
        g.add_edge(a, b);
    }
    cout << g.low_link() << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner stdin = new Scanner(System.in);

		int inN = stdin.nextInt();
		int[] nameCount = new int[5];
		for (int i = 0; i < inN; i++) {
			int index = getIndex(stdin.next());
			if (index >= 0) {
				nameCount[index]++;
			}
		}

		final char[][] firstArray = {
			{
				'M', 'A', 'R'
			}, {
				'M', 'A', 'C'
			}, {
				'M', 'A', 'H'
			}, {
				'M', 'R', 'C'
			}, {
				'M', 'R', 'H'
			}, {
				'M', 'C', 'H'
			}, {
				'A', 'R', 'C'
			}, {
				'A', 'R', 'H'
			}, {
				'A', 'C', 'H'
			}, {
				'R', 'C', 'H'
			}
		};

		long count = 0;
		for (char[] array : firstArray) {
			long pattern = 1;
			for (char first : array) {
				pattern *= nameCount[getIndex(first)];
			}
			count += pattern;
		}

		System.out.println(count);
	}

	private static int getIndex(char first) {
		switch (first) {
			case 'M':
				return 0;
			case 'A':
				return 1;
			case 'R':
				return 2;
			case 'C':
				return 3;
			case 'H':
				return 4;
			default:
				return -1;
		}
	}

	private static int getIndex(String name) {
		char first = name.charAt(0);
		return getIndex(first);
	}
}


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

int main() {
  int x ,n , c , k,j=0;
  cin >> x >> n ;
  if(n==0){
    cout << x ;
    return 0 ;
  }
  vector <int> p(n);
  for(int i=0; i < n ; i++){
    cin >> p.at(i) ;
  }
  sort(p.begin(), p.end());
  int min = 102 ;
  for(int i=0; i <= 101 ; i++){
    if(j < n){
      if(i == p.at(j)){
        j++ ;
        continue ;
      }
    }
    if(abs(x - i) < min ){
      min = abs(x - i) ;
      c = i ;
    }
    else if(abs(x - i) == min ){
      if(i < c) {
        min = abs(x - i) ;
        c = i;
      }
    }
  }
  for(int i=0; i <= 101 ; i++){
    if(abs(x + i) < min ){
      min = abs(x + i) ;
      c = -1 * i ;
    }
    else if(abs(x + i) == min ){
      if(-1 * i < c) {
        min = abs(x + i) ;
        c = -1 * i;
      }
    }
  }
  
  cout << c;
  

}


Measured memory_bytes: 3596
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	li := make([]int, 3)

	sc.Scan()
	N, _ := strconv.Atoi(sc.Text())

	for i := 0; i < N; i++ {
		for j := 0; j < 3; j++ {
			sc.Scan()
			x, _ := strconv.Atoi(sc.Text())
			li[j] = x
		}
		sort.Ints(li)

		switch li[2]*li[2] == li[1]*li[1]+li[0]*li[0] {
		case true:
			fmt.Println("YES")
		case false:
			fmt.Println("NO")
		default:
		}
	}

}



Measured memory_bytes: 1100
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define pop(v) (v).back(); (v).pop_back()
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_1
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

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

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

    lint x,y,z;
    cin>>x>>y>>z;
    x-=z;
    co(x/(y+z));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}
int n,m;
int a[50],b[50];
bool g[50][50];
bool flag[50];
void solve(int v){
    flag[v]=true;
    for(int i=0;i<n;i++){
        if(g[v][i]==true && flag[i]==false){
            solve(i);
        }
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        g[a[i]][b[i]]=g[b[i]][a[i]]=true;
    }
    int ans=0;
    for(int i=0;i<m;i++){
        g[a[i]][b[i]]=g[b[i]][a[i]]=false;
        for(int j=0;j<n;j++)flag[j]=false;
        solve(0);
        bool maki=false;
        for(int j=0;j<n;j++){
            if(!flag[j]){
                maki=true;
            }
        }
        if(maki)ans++;
        g[a[i]][b[i]]=g[b[i]][a[i]]=true;
    }
    cout << ans<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int			long long
#define ll 			long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define INF		10000000000000
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define dep(i,a,b)	for(int i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  200005

ll n;
ll h[N];
ll a[N];
vi bit;

ll query(ll r){
	ll ret=-INF;
	for(;r>=0;r=(r&(r+1))-1){
		ret=max(ret,bit[r]);
	}
	return ret;
}

void update(ll idx, ll val){
	for(;idx<n;idx=idx|(idx+1)){
		bit[idx]=max(bit[idx],val);
	}
}

void solve()
{
	cin>>n;
	rep(i,0,n){
		cin>>h[i];
		h[i]--;
	}	
	rep(i,0,n){
		cin>>a[i];
	}
	bit.assign(n,0);
	ll ans=0;
	rep(i,0,n){
		if(h[i]>0){
			ll curr= query(h[i]-1);
			ans=max(ans,curr+a[i]);
			update(h[i],curr+a[i]);
		}
		else{
			ans=max(ans,a[i]);
			update(h[i],a[i]);
		}
	}
	cout<<ans<<endl;
}

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

Measured memory_bytes: 7948
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#define ll long long
using namespace std;
int k;
void init(){scanf("%d",&k);}
vector<int>decompose(ll x){
	vector<int>tmp;
	while(x)tmp.push_back(x%10),x/=10;
	return tmp;
}
ll to_number(vector<int>x){
	ll tmp=0;
	for(int i=x.size()-1;~i;--i)(tmp*=10)+=x[i];
	return tmp;
}
ll sum(ll x){
	ll s=0;
	while(x)s+=x%10,x/=10;
	return s;
}
inline ll f(ll x){
	vector<int>dx=decompose(x);
	double mn=1e18;ll ne=-1;
	for(int i=0;i<dx.size();++i)
	for(int d=dx[i];d<=9;++d){
		vector<int>dy=dx;
		dy[i]=d;for(int j=0;j<i;++j)dy[j]=9;
		ll y=to_number(dy),sy=sum(y);
		if((double)y/sy<mn)mn=(double)y/sy,ne=y;
	}
	return ne;
}
void solve(){
	ll s=1;
	for(int i=1;i<=k;++i,s=f(s+1))printf("%lld\n",s);
}
int main(){
	init();
	solve();
	return 0;
}

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

int main()
{
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  ll ans = min(A, K);
  ll num = A + B;
  ans -= max(0ll, K - num);
  cout << ans << "\n";
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#define ll long long
using namespace std;

int main() 
{
    ll n, W;
    cin >> n >> W;
    vector<ll>  w(n), v(n);
    vector<vector<ll>>  dp(n, vector<ll>(W + 1, 0));
    for(ll i = 0; i < n; i++)
        cin >> w.at(i) >> v.at(i);
    
    for(ll i = w.at(0); i < W + 1; i++)
        dp.at(0).at(i) = v.at(0);
    for(ll i = 1; i < n; i++) {
        for(ll j = 0; j < W + 1; j++) {
            dp.at(i).at(j) = dp.at(i - 1).at(j);
            if((j - w.at(i) >= 0) && (dp.at(i - 1).at(j - w.at(i)) + v.at(i) > dp.at(i).at(j)))
                dp.at(i).at(j) = dp.at(i - 1).at(j - w.at(i)) + v.at(i);
        }
    }

    cout << dp.at(n - 1).at(W) << endl;
    
}

Measured memory_bytes: 79488
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    for (int i = k; i < n; i++)
    {
        if(a[i] > a[i-k]){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
    
    
    
    return 0;
}

Measured memory_bytes: 4764
#include<bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define ext(x) { cout<<x<<endl; return 0; }
#define D(x) cout<<"D: "<<#x<<'='<<x<<endl;
#define R(x, l) cout<<"R: Array "<<#x<<endl; rep(i, 0, l) cout<<' '<<i<<':'<<*(x+i)<<endl;
#define pb push_back
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
inline int max(int cnt, ...);
inline int min(int cnt, ...);
set<int> st;
signed main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n = next<int>();
	if (n == 2) ext(1);
	st.insert(n);
	st.insert(n-1);
	for(int i = 2; i*i <= n; i++)
	{
		int tmp = n;
		while(!(tmp%i)) tmp /= i;
		if (tmp%i == 1) st.insert(i);
		if (!((n-1)%i)) st.insert((n-1)/i);
	}
	cout<<st.size()<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}
inline int max(int cnt, ...)
{
	int mx = -1e18;
	va_list l;
	va_start(l, cnt);
	while(cnt--) mx = max(mx, va_arg(l, int));
	va_end(l);
	return mx;
}
inline int min(int cnt, ...)
{
	int mn = 1e18;
	va_list l;
	va_start(l, cnt);
	while(cnt--) mn = min(mn, va_arg(l, int));
	va_end(l);
	return mn;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1e+9
typedef long long ll;

int main(){
    ll n;
    cin>>n;
    ll a[n],color[9];
    memset(color,0,sizeof(color));
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<400){color[0]++;}
        else if(a[i]<800){color[1]++;}
        else if(a[i]<1200){color[2]++;}
        else if(a[i]<1600){color[3]++;}
        else if(a[i]<2000){color[4]++;}
        else if(a[i]<2400){color[5]++;}
        else if(a[i]<2800){color[6]++;}
        else if(a[i]<3200){color[7]++;}
        else {color[8]++;}
    }
    ll ans1=0,ans2=0;
    
    for(int i=0;i<8;i++){
        if(color[i])ans2++;
    }
    ans1=ans2;
    while(1){
        if(color[8]>0){
            color[8]--;
            ans1++;
        }else{
            break;
        }
    }
    if(ans2==0)ans2=1;
    cout<<ans2<<" "<<ans1<<endl;
    
}

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

namespace ABC
{
    class ProgramD
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            var n = int.Parse(inputs[0]);
            var k = int.Parse(inputs[1]);
            var l = int.Parse(inputs[2]);

            var ufr = new UnionFind(n);
            var uft = new UnionFind(n);

            for (var i = 0; i < k; i++)
            {
                var inputs1 = Console.ReadLine().Split(" ");
                var p = int.Parse(inputs1[0]) - 1;
                var q = int.Parse(inputs1[1]) - 1;
                ufr.unite(p, q);
            }

            for (var i = 0; i < l; i++)
            {
                var inputs1 = Console.ReadLine().Split(" ");
                var r = int.Parse(inputs1[0]) - 1;
                var s = int.Parse(inputs1[1]) - 1;
                uft.unite(r, s);
            }

            var list = new Dictionary<(int, int), int>();
            for (var i = 0; i < n; i++)
            {
                var r1 = ufr.root(i);
                var r2 = uft.root(i);
                var x = (r1, r2);
                // Console.WriteLine(x);
                if (list.ContainsKey(x))
                    list[x]++;
                else
                    list.Add(x, 1);
            }

            var result = new int[n];
            for (var i = 0; i < n; i++)
            {
                var r1 = ufr.root(i);
                var r2 = uft.root(i);
                var x = (r1, r2);
                result[i] = list[x];
            }

            Console.WriteLine(string.Join(" ", result));
        }

        public class UnionFind
        {
            int[] par, rank;

            // 初期化
            // par[i]=iの場合、根である
            public UnionFind(int n)
            {
                par = new int[n];
                rank = new int[n];
                for (var i = 0; i < n; i++)
                {
                    par[i] = i;
                    rank[i] = 0;
                }
            }

            // 木の根を求める
            public int root(int x)
            {
                if (par[x] == x)
                {
                    return x;
                }
                else
                {
                    par[x] = root(par[x]);
                    return par[x];
                }
            }

            // 2頂点が同じ集合か
            public bool same(int x, int y)
            {
                return root(x) == root(y);
            }

            // 集合の併合(ランク考慮あり)
            public void unite(int x, int y)
            {
                var nx = root(x);
                var ny = root(y);
                if (nx == ny) return;
                if (rank[nx] < rank[ny])
                {
                    par[nx] = ny;
                }
                else
                {
                    par[ny] = nx;
                    if (rank[nx] == rank[ny])
                        rank[nx]++;
                }
            }
        }
    }
}


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

int main () {

    long long A, B, C, K;
    cin >> A >> B >> C >> K;

    long long even = A - B;
    long long odd = (B + C) - (A + C);

    long long ans = ((K % 2 == 0)? even : odd);
    
    if (abs(ans) > 1e18) cout << "Unfair" << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int win,cur;
    cin>>win>>cur;
    win = (win - 2*cur);
    if(win < 0){
        cout<<"0\n";
    }
    else{
        cout<<win<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

const int MAX = 1e5 + 10;
int parent[MAX], size[MAX];

void make(int n){
	parent[n] = n;
}

int find(int n){
	if(n == parent[n])
		return n;
	return parent[n] = find(parent[n]);			// Path Compression
}

void unionset(int a, int b){
	a = find(a);
	b = find(b);
	if(a != b){
		if(a < b)
			parent[b] = a;
		else
			parent[a] = b;
	}
}


int32_t main(){
	int n, m;
	cin >> n >> m;
	vector<pair<int,int>> v(n);
	for(auto &x : v)
		cin >> x.F >> x.S;
		
	sort(v.begin(),v.end(),[&](pair<int,int> &a, pair<int,int> &b){
			if(a.S != b.S)
				return a.S > b.S;
			return a.F < b.F;
		});
	
	int used[m+2];
	memset(used,0,sizeof used);
	int ans = 0;
	
	for(int i = 0; i <= m; i++)
		parent[i] = i;
	
	for(int i = 0; i < n; i++){
		if(m-v[i].F < 0)
			continue;
		if(!used[m-v[i].F]){
			used[m-v[i].F] = 1;
			if(m-v[i].F-1 >= 0)
				unionset(m-v[i].F,m-v[i].F-1);
			ans += v[i].S;
		}
		else{
			int p = find(m-v[i].F);
			if(used[p])
				continue;
			used[p] = 1;
			if(p-1 >= 0)
				unionset(p,p-1);
			ans += v[i].S;
		}
	}
	cout << ans << endl; 

	return 0;
}



Measured memory_bytes: 3328
#include <stdio.h>


int linerSearch(int A[], int n, int key){
  int i = 0;
  A[n] = key;
  while (A[i] != key) {
    i++;
  }
  return i != n;
}


int main(int argc, char const *argv[]) {
  int n;
  int A[10000+1];
  int q;
  int key;
  int sum= 0;

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

  scanf("%d", &q);
  for(int i = 0; i < q; i++)  {
    scanf("%d", &key);
    if (linerSearch(A, n, key))  sum++;
  }
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 2744
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s;

int main(){
	cin >> s;
	int sum = 0, pos = 0, num;
	REP(i, s.size() - 1){
		int n = 11 - i;
		if (s[i] >= '0'&&s[i] <= '9'){
			if (1 <= n&&n <= 6)sum += (s[i] - '0')*(n + 1);
			else sum += (s[i] - '0')*(n - 5);
		}
		else pos = n;
	}
	vector<int> vi;
	REP(i, 10){
		if (pos == 0){
			if (sum % 11 <= 1)num = 0;
			else num = 11 - sum % 11;
			if (i == num){
				cout << i << endl;
				return 0;
			}
		}
		else{
			if (1 <= pos&&pos <= 6)sum += i*(pos + 1);
			else sum += i*(pos - 5);
			if (sum % 11 <= 1)num = 0;
			else num = 11 - sum % 11;
			if (s[s.size() - 1] - '0' == num)vi.push_back(i);
			if (1 <= pos&&pos <= 6)sum -= i*(pos + 1);
			else sum -= i*(pos - 5);
		}
	}
	if (vi.size() >= 2)cout << "MULTIPLE" << endl;
	else cout << vi[0] << endl;
}

Measured memory_bytes: 3192
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//CODE
void solve(void)
{
  int A,B;
  cin>>A>>B;
  int N = B - A;
  int SUM = 0;
  for (int i = 0; i < N; i++)
  {
    SUM += i;
  }
  cout<<SUM - A<<endl;
  
  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

//<equation> ::= <formula> "=" <formula>
//<formula>  ::= "T" | "F" |
//"a" | "b" | "c" | "d" | "e" | "f" |
//"g" | "h" | "i" | "j" | "k" |
//"-" <formula> |
//"(" <formula> "*" <formula> ")" |
//"(" <formula> "+" <formula> ")" |
//"(" <formula> "->" <formula> ")"

typedef string::const_iterator Cursor;

bool expression(Cursor&);
bool formula(Cursor&);

bool expression(Cursor &c){
    bool left = formula(c);
    c++;
    bool right = formula(c);
    return left == right;
}

map<char,bool> vmap;
bool formula(Cursor &c){
    if(*c == 'T'){
        c++;
        return true;
    }else if(*c == 'F'){
        c++;
        return false;
    }else if(*c == '-'){
        c++;
        return not formula(c);
    }else if(*c == '('){
        c++;
        bool left = formula(c);
        if(*c == '*'){
            c++;
            bool right = formula(c);
            c++;
            return left and right;
        }else if(*c == '+'){
            c++;
            bool right = formula(c);
            c++;
            return left or right;
        }else if(*c == '-'){
            // ->
            c++;c++;
            bool right = formula(c);
            c++;
            return not (left and (not right));
        }
    }else{
        return vmap[*(c++)];
    }
}

int main(){
    const char c[] = {'a','b','c','d','e','f','g','h','i','j','k'};
    const int N = 11;
    while(true){
        bool ok = true;
        string st;
        getline(cin,st);
        if(st == "#") break;
        for(int s=0;s<(1 << N);s++){
            for(int i=0;i<N;i++){
                if(s & (1 << i)){
                    vmap[c[i]] = true;
                }else{
                    vmap[c[i]] = false;;
                }
            }
            Cursor c = st.begin();
            if(not expression(c)){
                ok = false;
            }
        }
        if(ok){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin >> a >> b;
	int d = 2;
	int sum = 0;
	while(d--){
		if(a>b){
			sum+=a;
			a=a-1;
		}
		else if(a<b){
			sum+=b;
			b=b-1;
		}
		else if(a==b && d==2){
			sum = a+b;
		}
		else{
			sum+=a;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3624
def main():
    s=list(input())
    s_rev = reversed(s)
    h = 0
    t = -1
    for num,i in enumerate(s):
        if i =='A':
            h = num
            break
    for num,i in enumerate(s_rev):
        if i == 'Z':
            t = len(s)-num
            break
    print(t-h)
if __name__ == '__main__':
    main()

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

int main() {
  int value1;
  int value2;
  int value3;
  int value4;
  
  cin >> value1 >> value2 >> value3 >> value4;
  
  int left = value1 + value2;
  int right = value3 + value4;
  
  if (left == right)
  {
    cout << "Balanced" << endl;
  }
  else if (left > right)
  {
    cout << "Left" << endl;
  }
  else
  {
    cout << "Right" << endl;
  }
}



Measured memory_bytes: 256