akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

//ostream& operator << (ostream &a, const vector<int> &b) {
//    for (auto k : b) cout << k << " ";
//    return a;
//}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")s
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    vector<int> a(3);
    for (int i =0 ; i < 3; i++) cin >> a[i];
    sort(all(a));
    if (a[0] == a[1] && a[1] != a[2]) {
        cout << "Yes\n";
        return 0;
    }
    if (a[1] == a[2] && a[1] != a[0]) {
        cout << "Yes\n";
        return 0;
    }
    cout << "No\n";
}
/*
*/


Measured memory_bytes: 888
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> C(H);
    rep(i, H) cin >> C[i];
    int res = 0;
    for(int hbit = 0; hbit < (1 << H); hbit++) {
        for(int wbit = 0; wbit < (1 << W); wbit++) {
            auto mp = C;
            rep(i, H) if(hbit & (1 << i)) { rep(j, W) mp[i][j] = '*'; }
            rep(i, W) if(wbit & (1 << i)) { rep(j, H) mp[j][i] = '*'; }
            int cnt = 0;
            rep(i, H) rep(j, W) {
                if(mp[i][j] == '#')
                    cnt++;
            }
            if(cnt == K)
                res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3632
program main

  implicit none

  integer    :: n, k, i, j
  integer(8),allocatable :: h(:)
  integer(8) :: sumh
  
  read(*,*) n,k
  allocate( h(n) )
  read(*,*) h
  call quicksort1( h, 1, n ) 

  sumh = 0

  if( n - k > 0 ) then
    do i = 1 ,n-k
      sumh = sumh + h(i)
    end do
  end if

  write(*,*) sumh

end program main

recursive subroutine quicksort1(a, first, last)
  implicit none
  integer(8),intent(inout)::a(*)
  integer,intent(in)::first,last
  !
  ! Original
  ! https://gist.github.com/t-nissie/479f0f16966925fa29ea
  !
  integer(8)::x,t
  integer::i,j

  x = a((first+last)/2)
  i = first
  j = last
  do
     do while (a(i) < x)
        i=i+1
     end do
     do while (x < a(j))
        j=j-1
     end do
     if (i >= j) exit
     t = a(i)
     a(i) = a(j)
     a(j) = t
     i=i+1
     j=j-1
  end do
  if (first < i-1) call quicksort1(a, first, i-1)
  if (j+1 < last)  call quicksort1(a, j+1, last)

  return
end subroutine quicksort1


Measured memory_bytes: 2304
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    (*PQR,) = map(int, readline().split())
    ans = sum(PQR) - max(PQR)
    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
# Foods Loved by Everyone
N,M = gets.chomp.split(" ").map(&:to_i)
K = []
array = []
ans = 0
for i in 0..N-1 do
    K[i] = gets.chomp.split(" ").map(&:to_i)
end
for i in 0..N-1 do
    for j in 1..K[i].length-1 do 
        array.push(K[i][j]) 
    end 
end
for i in 1..M do
    if array.count(i) == N
        ans = ans + 1
    end
end
puts ans

Measured memory_bytes: 3836
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        //String S = sc.next();

        int sec = 1900*M +(N-M)*100;
        
        int res = sec * (int)Math.pow(2,M);
        System.out.println(res);
        
        
                
            

        }
        
        

        
        
        }

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

bool isPoor(int a, int b, int c) {
    if ((a == b && b == c) || (a != b && b != c && c != a)) {
        return false;
    } else {
        return true;
    }
}

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    cout << (isPoor(a, b, c) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



int main(){fastio
    ll k;cin>>k;
    string s;cin>>s;
    if((ll)s.size()<=k){
        cout<<s<<endl;
    }else{
        rep(i,0,k-1){
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 3656
#include <iostream>
#include <vector>

using namespace std;

int main(){
    vector <int> a;
    int n, m, count_n = 1;
    cin >> n;
    for (int i = 0, k; i < n; i++){
        cin >> k;
        a.push_back(k);
    }
    m = a[0];

    for (int i = 1; i < n; i++){
        if (m >= a[i]){
            m = a[i];
            count_n++;
        }
    }

    cout << count_n << endl;
}


Measured memory_bytes: 1400
#include<stdio.h>
#include<cstdio>
#include<algorithm>

using namespace std;

#define MAX_N 50005
#define MAX_C 10005
#define MAX_M 21

int dp[MAX_M][MAX_N];
int n,m;
int v[MAX_M];

int solve(int n,int m){
  //fill(dp[0],dp[0]+MAX_N+1,0);
  //printf("haitteru!");
  for(int i=0;i<=n;i++){
    dp[0][i]=0;
    dp[1][i]=i;
  }
  for(int i=0;i<=m;i++){
    dp[i][0]=0;
  }
  //printf("haitteru!");
  //printf("n=%d,m=%d\n",n,m);
  for(int i=2;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(j<v[i]){
        dp[i][j]=dp[i-1][j];
        //printf("(%d,%d)=%d\n",i,j,dp[i][j]);
      }else{
        dp[i][j]=min(dp[i-1][j],dp[i][j-v[i]]+1);
        //printf("(%d,%d)=%d\n",i,j,dp[i][j]);
      }
    }
  }
  return dp[m][n];
}

int main()
{
  scanf("%d%d",&n,&m);
  for(int i=0;i<m;i++) scanf("%d",&v[i+1]);

  int res=solve(n,m);

  printf("%d\n",res);

  return 0;
}

Measured memory_bytes: 5124
import std.stdio;
import std.conv;
import std.algorithm;
import std.range;
import std.string;
import std.typecons;
import std.math;
import std.random;
import std.range;
import std.functional;
import std.container;

class t
{
    sizediff_t left, right, parent;
    int depth;
    this()
    {
        parent = left = right = -1;
    }
}
void rrr(t[] tt, t a, int d)
{
    a.depth = d;
    if (a.right != -1)
    {
        rrr(tt, tt[a.right], d);
    }
    if (a.left != -1)
    {
        rrr(tt, tt[a.left], d + 1);
    }
}
void main()
{
    auto c = readln.strip.to!int;
    auto tt = new t[c];
    foreach (i; 0..c)
        tt[i] = new t();
    size_t l = 0;
    foreach (i; 0..c)
    {
        auto a = readln().strip.split(" ").map!(to!int).array;
        foreach (k, j; a[2..$])
        {
            if (k == 0)
            {
                tt[a[0]].left = j;
            }
            else
            {
                tt[l].right = j;
            }
            l = j;
            tt[j].parent = a[0];
        }
    }
    foreach (i; 0..c)
    {
        if (tt[i].parent ==  -1)
        {
            rrr(tt, tt[i], 0);
        }
    }
    foreach (i, t; tt)
    {
        writef("node %d: parent = %d, depth = %d, ", i, t.parent, t.depth);
        if (t.parent == -1)
        {
            write("root");
        }
        else if (t.left == -1)
        {
            write("leaf");
        }
        else
        {
            write("internal node");
        }
        bool f = false;
        write(", [");
        auto j = t.left;
        while (j != -1)
        {
            writef("%d", j);
            j = tt[j].right;
            if (j != -1)
            {
                write(", ");
            }
        }
        write("]");
        writeln();
    }
}



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

using namespace std;
const int N = 1000005;

long long floorOfHalf(long long x){
	return x / 2;
}

long long ceilOfHalf(long long x){
	return (x + 1) / 2;
}

long long Max(long long x, long long y, long long z){
	return max(x,max(y,z));
}

long long Min(long long x, long long y, long long z){
	return min(x,min(y,z));
}

long long interval(long long x, long long y, long long z){
	return Max(x, y, z) - Min(x, y, z);
}

long long get3(long long X1, long long Y1, long long X2, long long Y2){
	long long v1 = interval(X1 * Y1, X2 * floorOfHalf(Y2), X2 * ceilOfHalf(Y2));
	long long v2 = interval(X1 * Y1, floorOfHalf(X2) * Y2, ceilOfHalf(X2) * Y2);
	return min(v1,v2);
}

long long get2(long long X1, long long Y1, long long X2, long long Y2){
	return min(get3(X1, Y1, X2, Y2),get3(X2,Y2,X1,Y1));
}

long long X, Y;

void init(){
	scanf("%lld%lld",&X,&Y);
	long long res = LONG_MAX;
	for(long long x = 0; x <= X; x++)
		res = min(res, get2(x, Y, X - x, Y));
	for(long long y = 0; y <= Y; y++)
		res = min(res, get2(X, y, X, Y - y));
	cout << res << endl;
}

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

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

using namespace std;

typedef long long ll;

int n;
ll k;
int a[202020];
int f[202020];
int d[202020];

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = n; i >= 1; i--) {
		f[i] = d[a[i]];
		d[a[i]] = i;
	}
	int p = 1;
	int c = 1;
	while (true) {
		if (f[p] != 0) {
			p = f[p];
		} else {
			p = d[a[p]];
			c++;
		}
		if (p == n) break;
		p++;
	}
	k %= c;
	p = 1;
	c = 1;
	while (c < k) {
		if (f[p] != 0) {
			p = f[p];
		} else {
			p = d[a[p]];
			c++;
		}
		p++;
	}
	vector<int> u;
	set<int> s;
	for (int i = p; i <= n; i++) {
		if (s.count(a[i])) {
			while (s.count(a[i])) {
				s.erase(u.back());
				u.pop_back();
			}
		} else {
			u.push_back(a[i]);
			s.insert(a[i]);
		}
	}
	for (auto x : u) cout << x << " ";
	cout << "\n";
}


Measured memory_bytes: 14068
#include<stdio.h>
#include<string>
#include<iostream>
#include<set>
using namespace std;

int main()
{
    string s;
    cin>>s;
    set<char> s1;
    for(int i=0;i<s.length();i++)
    {
        s1.insert(s[i]);
    }
    if(s1.size() == s.length())
        printf("yes");
    else
        printf("no");
    return 0;
}



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

int main(){
  int n;
  cin >> n;
  if(!(n%2)){
    string s;
    cin >> s;
    int d = 0;
    for(int i=0; i<n/2; i++){
      if(s.at(i) != s.at(i+n/2)){
        cout << "No" << endl;
        d++;
        break;
      }
    }
    if(!d){
      cout << "Yes" << endl;
    }
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}

template <typename Func>
struct FixPoint : Func {
    inline constexpr FixPoint(Func &&f) noexcept : Func(forward<Func>(f)) {}

    template <typename... Args>
    inline decltype(auto) operator()(Args &&... args) const {
        return Func::operator()(*this, forward<Args>(args)...);
    }
};

template< typename Func >
inline decltype(auto) makeFixPoint(Func &&f) {
    return FixPoint< Func >{forward< Func >(f)};
}
// }}} End Header

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

    var(string , s);

    int left = 0;
    int right = s.length() - 1;
    int cnt = 0;
    for (; left < right; ++left, --right) {
        if (s[left] != s[right]) {
            ++cnt;
        }
    }

    print(cnt);

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define SF scanf
#define PF printf
using namespace std;
void Read(int &x){
	char c;
	bool flag=0;
	while(c=getchar(),c!=EOF&&(c<'0'||c>'9')&&c!='-');
	if(c=='-'){	c=getchar();flag=1;}
	x=c-'0';
	while(c=getchar(),c!=EOF&&c>='0'&&c<='9')x=x*10+c-'0';
	if(flag)x=-x;
} 

#define MAXN 1010
long long n,ans1,ans2,ans;
bool flag=0;
int main(){
	SF("%lld",&n);
	if(n%2==0){
		PF("%lld %lld %lld\n",n,n,n/2);
		return 0;
	}
	for(int i=1;i<=3500&&flag==0;i++)
		for(int j=1;j<=3500&flag==0;j++)
			if((4*i*j-j*n-i*n)>0&&((i*j*n)%(4*i*j-i*n-j*n))==0){
				ans=(i*j*n)/(4*i*j-i*n-j*n);
				ans1=i;
				ans2=j;
				break;
			}
	PF("%lld %lld %lld\n",ans,ans1,ans2);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{ 
int a,b,e,f,g,j,k,l,m,n;
cin >> a >> b;
e = (a%1000-a%100);
f = (a%10000-a%1000);
g = (a%100000-a%10000);
j = (b%1000-b%100);
k = (b%10000-b%1000);
l = (b%100000-b%10000);
if(g+f+e+f/100+g/10000-a >=0){m=(g+f+e)/100;}
else{m=(g+f+e)/100+1;}
if(b-(l+k+j+k/100+l/10000) <0){n=1-(l+k+j)/100;}
else{n=-(l+k+j)/100;}
printf ("%d",1-m-n);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <complex>

using namespace std;

typedef complex<double> P;

#define X real()
#define Y imag()

//¼üp1p3Æüªp2p4Ìð·»è
//1ÂÌüªp1p3ÆA»êÉÜÜêÈ¢2_p2,p4ÉÂ¢ÄAp1p3Æp1p2Ap1p3Æp1p4A»ê¼êÉÂ¢ÄOÏðßÄ»ÌÏðæé
//OÏÌ³ÍxNgÌÈ·pÌsinÉËéÌÅAp2,p4Ì»ê¼êªp1p3Ì¶É é©EÉ é©ªí©é
//³Èçð·µÄ¢È¢AÈçð·µÄ¢éA0Èç¼üã
double is_intersected(P p1,P p2,P p3,P p4) {

  return (((p3.X-p1.X)*(p2.Y-p1.Y)-(p3.Y-p1.Y)*(p2.X-p1.X))*((p3.X-p1.X)*(p4.Y-p1.Y)-(p3.Y-p1.Y)*(p4.X-p1.X)));

}

int main() {

  double xa,ya,xb,yb,xc,yc,xd,yd;

  //¼üACÆüªBDA é¢ÍüªACÆ¼üBDªð·µÄ¢êÎÊp`
  while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd)!=EOF) {

    P a(xa,ya),b(xb,yb),c(xc,yc),d(xd,yd);

    if(is_intersected(a,b,c,d)>0.0 || is_intersected(b,a,d,c)>0.0) cout << "NO" << endl;

    else cout << "YES" << endl;

  }

  return 0;

}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define INF (1<<29)
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=1e5;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int N,M,R;
int d[201][201];
int r[9];
int A,B,C;
int res;
bool used [9];

void floyd(){
    for(int k=1;k<=N;k++){
        for(int i=1;i<=N;i++){
            for(int j=1;j<=N;j++){
                if(d[i][j]>d[i][k]+d[k][j]) d[i][j]=d[i][k]+d[k][j];
            }
        }
    }
}
//R!の順列を表現
void dfs(int c,int las,int dist) { //c:何回目,las:今の場所,dist:今の距離
    if(c==R+1) {
        res=min(res,dist);
        return;
    }
    for(int i=1;i<=R;i++)if(!used[i]) {
        used[i]=true;
        if(las==-1)dfs(c+1,i,0);
        else dfs(c+1,i,dist+d[r[las]][r[i]]);
        used[i]=false;
    }
}

void solve(){
    floyd();
    
    res=INF;
    dfs(1,-1,0);
}

int main () {
    cin>>N>>M>>R;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            if(i!=j)d[i][j]=INF;
        }
    }
    for(int i=1;i<=R;i++)cin>>r[i];
    
    for(int i=1;i<=M;i++){
        cin>>A>>B>>C;
        d[A][B]=d[B][A]=C;
    }
    
    solve();
    
    cout<<res<<"\n";
}


Measured memory_bytes: 384
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    map<uint64_t, uint64_t> mp;
    for (auto& x: a) {
        mp[x]++;
    }

    uint64_t sum = 0;
    for (pair<uint64_t, uint64_t> p: mp) {
        if (p.second != 1) {
            sum += p.second * (p.second - 1) / 2;
        }
    }

    for (const auto& g: a) {
        auto x = mp[g];
        uint64_t ans = sum - x * (x - 1) / 2
            + (((x - 1) * (x - 2) / 2) > 0 ? ((x - 1) * (x - 2) / 2) : 0);
        cout<< ans << endl;
    }
}


Measured memory_bytes: 10240
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
ll h, w; 
bool can(pair<ll, ll> po){return (0 <= po.first && po.first < h && 0 <= po.second && po.second < w ? true : false);}
int main(){
	cin >> h >> w;
	ll a[h][w], dp[h][h];
	for(ll i = 0; i < h; i++)for(ll j = 0; j < w; j++)cin >> a[i][j];
	for(ll i = 0; i < h; i++)for(ll j = 0; j < h; j++)dp[i][j] = 0;
	dp[0][0] = a[0][0];
	for(ll count = 0; count < h + w - 2; count++){
		ll nextdp[h][h];
		for(ll i = 0; i < h; i++)for(ll j = 0; j < h; j++)nextdp[i][j] = 0;
		for(ll i = 0; i < h; i++){
			for(ll j = 0; j < h; j++){
				auto po = pair<ll, ll>(i, count - i), yo = pair<ll, ll>(j, count - j);
				if(!can(po) || !can(yo)) continue;
				ll dh[] = {1, 0}, dw[] = {0, 1};
				for(ll p = 0; p < 2; p++){
					for(ll y = 0; y < 2; y++){
						auto nextpo = po, nextyo = yo;
						nextpo.first += dh[p];
						nextpo.second += dw[p];
						nextyo.first += dh[y];
						nextyo.second += dw[y];
						if(!can(nextpo) || !can(nextyo)) continue;
						nextdp[nextpo.first][nextyo.first] = max(nextdp[nextpo.first][nextyo.first], dp[po.first][yo.first] + a[nextpo.first][nextpo.second] + a[nextyo.first][nextyo.second] - (nextpo == nextyo ? a[nextpo.first][nextpo.second] : 0));
					}
				}
			}
		}
		for(ll i = 0; i < h; i++)for(ll j = 0; j < h; j++)dp[i][j] = nextdp[i][j];
	}
	cout << dp[h - 1][h - 1] << endl;
	return 0;
}

Measured memory_bytes: 1152
#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>p(n);
    vector<int>c(n);
    for (int i = 0; i < n; i++)
    {
        cin>>p[i];
        p[i]--;
    }
    for (int i = 0; i < n; i++)
    {
        cin>>c[i];
    }
    vector<vector<int>>vp(n,vector<int>());
    for (int i = 0; i < n; i++)
    {
        int x=p[i];
        while(1){
            vp[i].push_back(x);
            x=p[x];
            if(x==p[i]) break;
        }
    }
    /*for (int i = 0; i < n; i++)
    {
        cerr<<vp[i].size()<<endl;
    }*/
    
    vector<vector<int>>rui(n,vector<int>(1,0));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < vp[i].size(); j++)
        {
            rui[i].push_back(rui[i].back()+c[vp[i][j]]);
        }
        
    }
   /* for (int i = 0; i < n; i++)
    {
        cerr<<rui[i].size()<<endl;
    }*/
    
    int ans=-INF;
    for (int i = 0; i < n; i++)
    {
        //if(rui[i][n]<0 ) continue;
        int tmp3=-INF;
        int tmp4=0;
        int N=(int)vp[i].size();
        int cnt=0;
        for (int j = 0; j < N; j++)
        {
            if(j+1>k) break;
            cnt=rui[i][j+1];
            int c=(k-j-1)/N;
            if(rui[i][N] > 0){
            cnt+=rui[i][N]*c;
            }
             chmax(ans,cnt);
        }
        
        
    }
    cout<<ans<<endl;
    
    return 0;
}

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

//def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    map<ll, ll> dict;
    ll n;
    cin >> n;
    ll t;
    rep(i, n) {
        cin >> t;
        dict[t] ^= 1;
    }
    ll ans = 0;
    for_each(all(dict), [&](auto x) {
        ans += x.second;
    });
    out(ans);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;

#define pb push_back
#define ff first
#define ss second
#define SIZE 200005
#define INF int(2e9 + 9)
#define BIG_INF ll(1e18 + 9)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define _sz(v) int((v).size())
#define sqr(x) (x) * (x)
#define cube(x) (x) * (x) * (x)



//#pragma GCC optimize("Ofast")



int T = 1, n, m, a[SIZE];

string s;


int binpow(int a, int b)
{
    int res = 1;

    while(b)
    {
        if(b & 1)
            res *= a;
        a *= a;
        b >>= 1;
    }

    return res;
}



void solve()
{
    cin >> n;

    int ans = n;
    ans += binpow(n, 2);
    ans += binpow(n, 3);
    cout << ans;
    return;
}


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    while(T--)
    {
        solve();
    }




    return 0;
}


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

#define ll long
#define ld double
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define setpr(pp) fixed<<setprecision(pp)
#define FOR(I,N) for(I=0;I<N;++I)
#define MS0(x) memset(x,0,sizeof(x))
#define MS1(x) memset(x,-1,sizeof(x))
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod	%1000000007
#define pi 3.141592653
#define NL -5000000

int p[1000005];

int main()
{	IOS;
	ll n,x,i,cnt=0;
	cin>>n;
	MS0(p);
	FOR(i,n)
	{
		cin>>x;
		p[x]++;
	}
	for(i=1;i<=1000000;++i)
	{
		if(p[i]==0)
			continue;
		ll j=i+i;
		while(j<=1000000)
		{
			p[j]=0;
			j+=i;
		}
		if(p[i]==1)
			cnt++;
	}
	cout<<cnt;
}


Measured memory_bytes: 7520
#include <bits/stdc++.h>
 
#define TRACE(x) cerr << #x << " = " << x << endl
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
#define SZ(x) (int)(x).size()
 
using namespace std;
 
typedef unsigned long long ll;
typedef pair<int, int> pii;
 
template<class Num>
Num mabs(Num A){
  if(A < 0) return -A;
  return A;
}

const int N = 2005, mod = 1e9 + 7;

inline int add(int a, int b){
  int ret = a + b;
  if(ret >= mod) ret -= mod;
  return ret;
}

inline int sub(int a, int b){
  int ret = a - b;
  if(ret < 0) ret += mod;
  return ret;
}

int n;

int main(){
  scanf("%d", &n);
    
  int des = 1, dev = 1, os = 1;
  for(int i = 1; i <= n; i++){
    des = (ll)des * 10ll % mod;
    dev = (ll)dev * 9ll % mod;
    os = (ll)os * 8ll % mod;
  }
  
  dev = (ll)dev * 2ll % mod;
  
  int ans = sub(des, dev);
  ans = add(ans, os);
  
  printf("%d\n", ans);
  
  return 0;
}


Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <list>
#include <deque>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;
ll mod = 1e9+7;

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> id(m);
    vector<int> p(m), y(m);
    for( int i = 0; i < m; i++ ) {
        cin >> p[i] >> y[i];
        id[i] = make_pair( y[i], p[i] );
    }
    vector<int> num(n+1, 0);
    sort( id.begin(), id.end() );
    vector<map<int, int>> vm(n+1);
    for( int i = 0; i < m; i++ ) {
        vm[id[i].second][id[i].first] = num[id[i].second]+1;
        num[id[i].second]++;
    }
    for( int i = 0; i < m; i++ ) {
        printf( "%06d%06d\n", p[i], vm[p[i]][y[i]]);
    }

    return 0;  
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,K,ans=0;
  cin>>N>>K;
  vector<int> A(N);
  for(int &i:A)cin>>i;
  for(int i=0;i<=K && i<=N;i++){
    for(int j=0;j+i<=K && i+j<=N;j++){
      priority_queue<int,vector<int>,greater<int>> Q;
      int sum=0;
      for(int k=0;k<i;k++){
        Q.push(A[k]);
        sum+=A[k];
      }
      for(int k=0;k<j;k++){
        Q.push(A[N-1-k]);
        sum+=A[N-1-k];
      }
      for(int k=0;i+j+k<K && k<i+j;k++){
        if(Q.top()>=0)break;
        sum-=Q.top();
        Q.pop();
      }
      ans=max(ans,sum);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <tuple>

using namespace std;

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

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

int main() {

    
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> gl(n);
    vector<ll> gr(n);
    
    ll div = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        if (i == 0)
        {
            gl[i] = a[i];
            continue;
        }
        gl[i] = gcd(gl[i - 1], a[i]);
    }
    
    for (int i = 0; i < n; ++i)
    {
        if (i == 0)
        {
            gr[n - 1 - i] = a[n - 1 - i];
            continue;
        }
        gr[n - 1 - i] = gcd(gr[n - i], a[n - 1 - i]);
    }
    
    ll ret = 0;
    ret = max(ret, gl[n - 2]);
    ret = max(ret, gr[1]);
    for (int i = 0; i < n - 2; ++i)
    {
        ret = max(ret, gcd(gl[i], gr[i + 2]));
    }
    
    
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        String alfabet = "abcdefghijhlmnopqrstuvwxyz";

        Scanner sc = new Scanner(System.in);
        String c = sc.nextLine();
        int index = alfabet.indexOf(c.charAt(0));

        System.out.println(alfabet.charAt(index + 1));
    }
}

Measured memory_bytes: 19796
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);

#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)

class Point{
public:
	double x, y;
	Point(double x=0, double y=0):x(x), y(y){}

	Point operator + (Point p){ return Point(x + p.x, y + p.y); }
	Point operator - (Point p){ return Point(x - p.x, y - p.y); }
	Point operator * (double a){ return Point(a * x, a * y); }
	Point operator / (double a){ return Point(x / a, y / a); }

	double abs() { return sqrt(norm()); }
	double norm() { return x * x + y * y;}
	bool operator < (const Point &p) const {
		// first x, second y
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}
};

typedef Point Vector;

struct Segment{
public:
	Point p1, p2;
	Segment(Point p1, Point p2){
		this->p1 = p1;
		this->p2 = p2;
	}
};

double dot(Vector a, Vector b){
	//|a||b|cos(theta)
	return a.x * b.x + a.y * b.y;
}
double cross(Vector a, Vector b){
	//|a||b|cos(theta)
	return a.x * b.y - a.y * b.x;
}

// Orthogonal
bool isOrthogonal(Vector a, Vector b){
	return equals(dot(a, b), 0.0);
}
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2){
	return isOrthogonal(a1 - a2, b1- b2);
}

// Orthogonal
bool isParallel(Vector a, Vector b){
	return equals(cross(a, b), 0.0);
}
bool isParallel(Point a1, Point a2, Point b1, Point b2){
	return isParallel(a1 - a2, b1- b2);
}

// ???p????????????s???????????????????????????
Point project(Segment s, Point p){
	// ??\??????????????????
	// t = |hypo|cos??
	// cos?? = dot(hypo,base)/|hypo||base|
	// project = s.p1 + base/|base| * t
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + base * r;
}

// ???p????????????s???????§°?????¨?????????
Point reflection(Segment s, Point p){
    Point pr = project(s, p);
	return p + (pr - p) * 2.0;
}

int Q;
Point p1, p2;

int main() {
	cin >> p1.x >> p1.y >> p2.x >> p2.y;
	cin >> Q;

	rep(i, Q){
		Point pp;
		cin >> pp.x >> pp.y;
		Point rf = reflection(Segment(p1, p2), pp);
		fprintf(stdout, "%.10f %.10f\n", rf.x, rf.y);
	}
}

Measured memory_bytes: 3216
#include <iomanip>
#include <iostream>
int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    // fixed で指数表示ではなく小数点表示
    // setprecision で精度を指定
    std::cout << std::fixed << std::setprecision(5);
    double r;
    std::cin >> r;
    std::cout << r * 6.28318530717958623200 << std::endl;
    return 0;
}

Measured memory_bytes: 3816
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }

LL getGain(LL r, LL s, LL p, char c){
    if(c == 's') return r;
    if(c == 'p') return s;
    if(c == 'r') return p;
    return 0;
}

LL solve(LL r, LL s, LL p, string str){
    LL n = str.size();
    vector<LL> win(n+1);
    vector<LL> lose(n+1);
    for(LL i = 0; i < n; ++i){
        if(i == 0 || str[i-1] != str[i]){
            win[i+1] = max(win[i+1], win[i] + getGain(r,s,p,str[i]));
            lose[i+1] = max(lose[i+1], win[i]);
        }else{
            win[i+1] = max(win[i+1], lose[i] + getGain(r,s,p,str[i]));
            lose[i+1] = max(lose[i+1], win[i]);
        }
    }
    return max(win[n], lose[n]);
}

int main(){
    LL n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    LL ans = 0;
    for(LL i = 0; i < k; ++i){
        string str;
        for(LL j = i; j < t.size(); j += k){
            str += t[j];
        }
        ans += solve(r, s, p, str);
    }
    cout << ans << endl;
    return 0;
}



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

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

  int n, h; cin >> n; cin >> h; int arr[n+h]; int sf[n+h];
  for (int i = 0; i < n+h; i++) {
    cin >> arr[i];
    sf[i] = 1000000000;
  }
  sf[0] = 0;
  for (int i = 0; i < n-1; i++) {
      for (int j = 1; j <= h; j++) {
          if (abs(arr[i]-arr[i+j]) + sf[i] < sf[i + j]) {
              sf[i+j] = sf[i] + abs(arr[i]-arr[i+j]);
          }
      }
  }
  cout << sf[n-1];
  
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<ctime>
#include<cstdlib>
#define INF long long int(1e18+1)
#define MAX 200001
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;
vector<int>a[200001];
int main() {
	int n, m;
	cin >> n >> m;
	int x, y;
	vector<bool>done(n + 1, 0);
	rep(i, 0, m) {
		cin >> x >> y;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	int s;
	int ans = 0;
	rep(i, 1, n + 1) {
		if (done[i])continue;
		queue<int>que;
		done[i] = true;
		int total = 1;
		for (auto q : a[i])que.push(q);
		while (!que.empty()) {
			s = que.front();
			if (done[s]) {
				que.pop();
				continue;
			}
			done[s] = true;
			total++;
			for (auto qq : a[s])que.push(qq);
			que.pop();
		}
		ans = max(ans, total);
	}
	cout << ans << endl;
}



Measured memory_bytes: 15036
def linearSearch(A, k):
    for a in A:
        if a == k:
            return True
    return False

n = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(i) for i in input().split()]
C = 0
for t in T:
    if linearSearch(S, t):
        C += 1
print(C)


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

int main(){
    int n;
    cin >> n;
    char s[n];
    for(int i=0;i<n;i++) cin >> s[i];
    int w[n]={},e[n]={};
    w[0]=e[0]=0;
    for(int i=1;i<n;i++){
        if(s[i-1]=='W') w[i]++;
        w[i]+=w[i-1];
    }
    for(int i=n-2;i>=0;i--){
        if(s[i+1]=='E') e[i]++;
        e[i]+=e[i+1];
    }
    int ans=1e9;
    for(int i=0;i<n;i++){
        ans=min(ans,w[i]+e[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2944
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
s=sum(A)
Q=int(input())
cnt=Counter(A)
for _ in range(Q):
    b,c=map(int,input().split())
    if b in cnt:
        s-=cnt[b]*b
        s+=cnt[b]*c
        print(s)
        if c in cnt:
            cnt[c]+=cnt[b]
            cnt[b]=0
        else:
            cnt[c]=cnt[b]
            cnt[b]=0
    else:
        print(s)

Measured memory_bytes: 21288
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <sstream>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll pow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = pow(N, P/2);
        return t*t;
    }
    return N * pow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}

int main() {
   int n;cin>>n;
   string w[100];
   set<string>s;
   bool flag=1;
   rep(i,n){
       cin>>w[i];
       if(s.find(w[i])!=s.end())flag=0;
       s.insert(w[i]);
   }
       
   rep(i,n-1){
       if(w[i][w[i].size()-1]!=w[i+1][0])flag=0;
   }
   if(flag)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;

}

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

signed main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  vector<int> X(N);
  for( int i = 0; i < N; i++ ) cin >> X.at(i);
  
  int ans = 0;
  int kyori;
  for( int i = 1; i < N; i++ ){
    kyori = X.at(i) - X.at(i-1);
    ans += min( kyori*A, B);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <map>
#include <cstdio>
using namespace std;


int main(void) {
	int a, b;
	cin >> a >> b;

	if (a + b == 15) {
		cout << "+" << endl;
	}
	else if (a*b == 15) {
		cout << "*" << endl;
	}
	else {
		cout << "x" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int N = sc.nextInt();
		long L = sc.nextLong();
		long T = sc.nextLong();
		int[] x = new int[N];
		boolean[] w = new boolean[N];
		ArrayList<Integer> cw = new ArrayList<>();
		ArrayList<Integer> ccw = new ArrayList<>();
		for(int i=0; i<N; i++) {
			x[i] = sc.nextInt();
			w[i] = sc.nextInt()==1;
			if(w[i])
				cw.add(x[i]);
			else
				ccw.add(x[i]);
		}
		Collections.reverse(cw);
		
		if(cw.size()==0 || ccw.size()==0) {
			for(int i=0; i<N; i++) {
				pw.println((x[i]+(w[i]? T%L : L-(T%L)))%L);
			}
		} else {
			long t=0;
			boolean dirCW = true;
			int cwIdx=0;
			int ccwIdx=0;
			int lane1 = -1, lane2 = -1;
			boolean dir1=false;
			while(t<2*L) {
				if(cwIdx==0 && ccwIdx==0) {
					t += (ccw.get(0)-cw.get(0)+L) % L;
					cwIdx++;
					ccwIdx++;
				} else if(dirCW) {
					int next = ccw.get(ccwIdx%ccw.size()) - ccw.get((ccwIdx-1)%ccw.size());
					if(next<=0)
						next += L;
					t += next;
					ccwIdx++;
				} else {
					int next = cw.get((cwIdx-1)%cw.size()) - cw.get(cwIdx%cw.size());
					if(next<=0)
						next += L;
					t += next;
					cwIdx++;
				}
				if(lane1==-1 && t>=2*(T%L)) {
					lane1 = dirCW ? cw.get((cwIdx-1)%cw.size()) : ccw.get((ccwIdx-1)%ccw.size());
					dir1 = dirCW;
				}
				if(lane2==-1 && t>=2*L) {
					lane2 = dirCW ? cw.get((cwIdx-1)%cw.size()) : ccw.get((ccwIdx-1)%ccw.size());
				}
				dirCW ^= true;
			}
			int gap2 = Arrays.binarySearch(x, lane2) - Arrays.binarySearch(x, cw.get(0));
			
			int[] pos = new int[N];
			for(int i=0; i<N; i++)
				pos[i] = (int)((x[i]+(w[i]? T%L : L-(T%L)))%L);
			Arrays.sort(pos);
			
			lane1 = (int)((lane1 + (dir1 ? T : L-(T%L)))%L);
			int idx = Arrays.binarySearch(pos, lane1);
			if(idx<N-1 && pos[idx]==pos[idx+1] && !dir1)
				idx++;
			idx = (idx - Arrays.binarySearch(x, cw.get(0)) + N)%N;
			idx = (int)((idx + ((long)gap2+N)*(T/L))%N);
			
			
			long cnt = 0;
			for(int ccwx : ccw) {
				long dis = (ccwx-cw.get(0)+L)%L;
				cnt = (cnt + (2*T + L-dis)/L)%N;
			}
			
			int cidx = (Arrays.binarySearch(pos, (int)((cw.get(0)+T)%L)) - Arrays.binarySearch(x, cw.get(0)) - (int)cnt + N + N)%N;
			
			for(int i=0; i<N; i++)
				pw.println(pos[(cidx+i)%N]);
		}
		
		sc.close();
		pw.close();
	}
}


Measured memory_bytes: 92292
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var A = new long[M];
            var B = new long[M];

            for (var i = 0; i < M; ++i)
            {
                var ab = Sarray();
                A[i] = ab[0] - 1;
                B[i] = ab[1] - 1;
            }
            var ans = 0L;
            for (var i = 0; i < M; ++i)
            {
                var graph = new long[N, N];
                for (var j = 0; j < M; ++j)
                {
                    if (j == i) continue;
                    graph[A[j], B[j]] = 1;
                    graph[B[j], A[j]] = 1;
                }
                var cmp = new bool[N];
                dfs(graph, cmp, 0);
                if (cmp.Count(c => c) != N)
                    ++ans;
            }
            WriteLine(ans);
            //Out.Flush();
        }
        static void dfs(long[,] graph, bool[] cmp, long r)
        {
            if (cmp[r]) return;
            cmp[r] = true;
            for (var i = 0; i < graph.GetLength(1); ++i)
            {
                if (graph[r, i] != 0)
                    dfs(graph, cmp, i);
            }
        }
    }
}

Measured memory_bytes: 14176
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    int n;
    cin >> n;
    tuple<string, int, int> v[n];
    forn(i, 0, n) {
        string s;
        int p;
        cin >> s >> p;
        v[i] = {s, -p, i+1};
    }
    sort(v, v+n);
    forn(i, 0, n) {
        cout << get<2>(v[i]) << endl;
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;

int main(void)
{
        string s;
        string ans;
        cin >> s;
        for(int i = 0; i < s.size(); i +=2) ans.push_back(s[i]);
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
queue<int> q1,q2,q3;
int main() {
    int h,w,num=0;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++){
        cin>>s[i];
        for(int j=0;j<w;j++){
            if(s[i][j]=='.'){
                num++;
            }
        }
    }

    int a,b,c;
    bool maki[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            maki[i][j]=false;
        }
    }
    /*int dis[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            dis[i][j]=1e9;
        }
    }*/
    
    q1.push(0);
    q2.push(0);
    q3.push(0);
    maki[0][0]=true;
    while(!q1.empty()){
        a=q1.front();
        b=q2.front();
        c=q3.front();
        c++;
        /*dis[a][b]=min(dis[a][b],c);
        c=dis[a][b];*/
        
        q1.pop();
        q2.pop();
        q3.pop();
        if(a==h-1&&b==w-1){
            break;
        }
        if(b){
            if(maki[a][b-1]==0&&s[a][b-1]=='.'){
                q1.push(a);
                q2.push(b-1);
                q3.push(c);
                maki[a][b-1]=true;
            }
        }
        if(a){
            if(maki[a-1][b]==0&&s[a-1][b]=='.'){
                q1.push(a-1);
                q2.push(b);
                q3.push(c);
                maki[a-1][b]=true;
            }
        }
        if(a!=h-1){
            if(maki[a+1][b]==0&&s[a+1][b]=='.'){
                q1.push(a+1);
                q2.push(b);
                q3.push(c);
                maki[a+1][b]=true;
            }
        }
        if(b!=w-1){
            if(maki[a][b+1]==0&&s[a][b+1]=='.'){
                q1.push(a);
                q2.push(b+1);
                q3.push(c);
                maki[a][b+1]=true;
            }
        }
    }
    if(!(a==h-1&&b==w-1)){
        cout<<-1<<endl;
        return 0;
    }
    cout << num-c <<endl;
    return 0;
}


Measured memory_bytes: 256