akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

string p = "pairwise coprime";
string s = "setwise coprime";
string n = "not coprime";

int gcd(int a, int b) {
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

int gcd_arr(vector<int> &a) {
    int n = a.size();
    for (int i = n - 2; i >= 0; i--) {
        a[i] = gcd(a[i], a[i + 1]);
    }
    return a.front();
}

map<long long int, long long int> prime_factor(long long int n) {
    map<long long int, long long int> ret;
    for (long long int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

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

    vector<int> A(N);
    map<int, int> prime;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        // map<ll, ll> tmp = prime_factor(A[i]);
        // for (auto tm : tmp) {
        // prime[tm.first] += 1;
        // }
    }

    vector<int> A_tmp = A;
    if (gcd_arr(A_tmp) != 1) {
        cout << n << endl;
        return 0;
    }

    for (int i = 0; i < N; i++) {
        map<ll, ll> tmp = prime_factor(A[i]);
        for (auto tm : tmp) {
            prime[tm.first] += 1;
            if (prime[tm.first] != 1) {
                cout << s << endl;
                return 0;
            }
        }
    }

    // for (auto pr : prime) {
    // if (pr.second != 1) {
    // cout << s << endl;
    // return 0;
    // }
    // }

    cout << p << endl;

    return 0;
}


Measured memory_bytes: 11180
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(void) {
    int x,a;
    cin >> x >> a;
    if(x<a)cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}


Measured memory_bytes: 256
def B(n, x, a):
    i = 0
    sum_n = 0
    while i < n:
        sum_n += a[i]
        if sum_n > x:
            break
        i += 1

    return i+1


if __name__ == "__main__":
    n, x = map(int, input().split())
    a = list(map(int, input().split()))

    print(B(n, x, a))


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main() {
    int a,b,c,d,s1,s2;
    cin >> a >> b >> c >> d ;
    s1 = a * b;
    s2 = c * d;
    if (s1 >= s2){
        cout << s1 << endl;
    } else {
        cout << s2 << endl;
    }
    return 0;
}

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define LL long long

const int maxn = 100000000;
char G[1005][1005];
int d1[1005][1005];
int d2[1005][1005];
int d3[1005][1005];
int d4[1005][1005];

int H,W;

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

bool valid(int x,int y){
    return (x >=0 && x < H && y>=0 && y < W);
}

int searching1(int x,int y){
    int &ans = d1[x][y];
    if(G[x][y] == '#') return (ans = 0);
    if(ans > 0) return ans;
    ans = -1;
    int k = maxn;
    _for(i,0,2){
        int nx = dx[i] + x;int ny = dy[i] + y;
        if(valid(nx,ny) && d1[nx][ny] != -1){
            k = min(k,searching1(nx,ny) + 1);
        }
    }
    return (ans = k);
}

int searching2(int x,int y){
    int &ans = d2[x][y];
    if(G[x][y] == '#') return (ans = 0);
    if(ans > 0) return ans;
    ans = -1;
    int k = maxn;
    _for(i,2,4){
        int nx = dx[i] + x;int ny = dy[i] + y;
        if(valid(nx,ny) && d2[nx][ny] != -1){
            k = min(k,searching2(nx,ny) + 1);
        }
    }
    return (ans = k);
}

int searching3(int x,int y){
    int &ans = d3[x][y];
    if(G[x][y] == '#') return (ans = 0);
    if(ans > 0) return ans;
    ans = -1;
    int k = maxn;
    _for(i,4,6){
        int nx = dx[i] + x;int ny = dy[i] + y;
        if(valid(nx,ny) && d3[nx][ny] != -1){
            k = min(k,searching3(nx,ny) + 1);
        }
    }
    return (ans = k);
}

int searching4(int x,int y){
    int &ans = d4[x][y];
    if(G[x][y] == '#') return (ans = 0);
    if(ans > 0) return ans;
    ans = -1;
    int k = maxn;
    _for(i,6,8){
        int nx = dx[i] + x;int ny = dy[i] + y;
        if(valid(nx,ny) && d4[nx][ny] != -1){
            k = min(k,searching4(nx,ny) + 1);
        }
    }
    return (ans = k);
}


int main()
{
    scanf("%d %d",&H,&W);
    getchar();
    _for(i,0,H){
        _for(j,0,W){
            G[i][j] = getchar();
        }
        getchar();
    }

    _for(i,0,H){
        _for(j,0,W){
            if(G[i][j] == '.' && d1[i][j] == 0){
                searching1(i,j);
            }
        }
    }

    for(int i = H-1;i>=0;i--){
        for(int j = W-1;j>=0;j--){
            if(G[i][j] == '.' && d2[i][j] == 0){
                searching2(i,j);
            }
        }
    }

    for(int i = H-1;i>=0;i--){
        _for(j,0,W-1){
            if(G[i][j] == '.' && d3[i][j] == 0){
                searching3(i,j);
            }
        }
    }

     _for(i,0,H){
        for(int j = W-1;j>=0;j--){
            if(G[i][j] == '.' && d4[i][j] == 0){
                searching4(i,j);
            }
        }
    }

    int min_ans = 0;
     _for(i,0,H){
        _for(j,0,W){
            min_ans = max(min_ans,min(d4[i][j],min(d3[i][j],min(d1[i][j],d2[i][j]))));
        }
    }

    printf("%d\n",min_ans);
    return 0;
}


Measured memory_bytes: 17152
/**
 *   
 *   Date: 22 December 2019
 *   Time: 18:24:25
**/
#pragma GCC optimize("O3")
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cmath>
#include <cstring>
#include<queue>
#include<stack>
#include<climits>
#include<iomanip>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > matrix;
ll const mod=1000000007;

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll n,d=0;
	cin>>n;
	if(n&1ll)
	{
		d=0;
		cout<<d<<endl;
		return 0;
	}
	n/=2;
	for(ll i=5;(n/i)>=1;i*=5)
	{
		d+=(n/i);
	}
	cout<<d<<endl;

return 0;
}

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

using namespace std;

int main()
{
    int n, M=-1, k, p=0, g=0;
    cin >> n;
    char C[n][n];
    for (int i = 0; i < n; i++)
    {
        for (int y = 0; y < n; y++)
        {
            cin >> C[i][y];
            if (C[i][y] == '#')
            {
                g = 1;
            }
        }
    }
    if (g == 0)
    {
        cout << -1;
        return 0;
    }
    for (int i = 0; i < n; i++)
    {
        k = 0;
        for (int y = 0; y < n; y++)
        {
            if (C[i][y] == '#')
            {
                k++;
            }
        }
        k--;
        for (int y = 0; y < n; y++)
        {
            if (C[y][i] == '#')
            {
                k++;
                break;
            }
        }
        M = max(M, k);
    }
    for (int y = 0; y < n; y++)
    {
        k = 0;
        for (int i = 0; i < n; i++)
        {
            if (C[i][y] == '#')
            {
                k++;
            }
        }
        if (k == n)
        {
            p++;
        }
    }
    cout << n-M + n - p;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
int a[N];

int main(){
	//freopen("in.txt","r",stdin);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int res = 0;
	for(int i=1;i<=n;i++){
		if(a[i]==i){
			swap(a[i],a[i+1]);
			res++;
		}
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long n,k,ans,md=1e9+7;
int main()
{
	cin>>n>>k;
	for(long long i=k;i<=n+1;i++)
	{
		long long l=0,r=i-1,nw1,nw2;
		nw1=(l+r)*(r-l+1ll)/2ll;
		r=n;
		l=r-i+1ll;
		nw2=(l+r)*(r-l+1ll)/2ll;
		ans+=nw2-nw1+1;
		ans%=md;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
int a[100000], b[100000];

int main() {
    scanf("%d", &n);
    forn(i, n) {
        int x;
        scanf("%d", &x);
        while (x > 1) {
            if (x % 2 == 1) b[i] = 1;
            ++a[i];
            x = (x + 1) / 2;
        }
    }
    int ans = a[0];
    for (int i = 1; i < n; ++i) {
        ans += max(0, a[i] - a[i - 1]);
    }
    forn(i, n) if (b[i]) {
        b[i] = 0;
        if (i > 0 && a[i] <= a[i - 1]) {
            if (i < n - 1 && a[i] <= a[i + 1]) {
                b[i] = 1;
            }
        }
    }
    forn(i, n - 1) if (b[i] == 1 && b[i + 1] == 1) {
        b[i] = 0;
        b[i + 1] = 0;
        ans += 1;
    }
    forn(i, n) ans += b[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
N = int(input())
S = input()
v = [0] * 26
for i in range(0, N):
    v[ord(S[i]) - 97] += 1
wa = 1

for i in range(len(v)):
    wa *= (v[i] + 1)
print((wa - 1) % (10 ** 9 + 7))

Measured memory_bytes: 3188
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#define ls p << 1
#define rs p << 1|1
#define mid ((l+r)>>1)
using namespace std;
struct point {
	int x, id;
}a[111000];
int mxnn[110000<<2], minn[110000<<2];
void build(int l, int r, int p) {
	if(l == r) {
		mxnn[p] = minn[p] = a[l].x;
		return; 
	}
	build(l, mid, ls);
	build(mid+1, r, rs);
	mxnn[p] = max(mxnn[ls], mxnn[rs]);
	minn[p] = min(minn[ls], minn[rs]);
}
int querymn(int l, int r, int p, int x, int y) {
	if(x <= l && y >= r) {
		return minn[p];
	}
	int ret = 1<<30;
	if(x <= mid) ret = querymn(l, mid, ls, x, y);
	if(y > mid) ret = min(ret, querymn(mid+1, r, rs, x, y));
	return ret;
}
int querymx(int l, int r, int p, int x, int y) {
	if(x <= l && y >= r) {
		return mxnn[p];
	}
	int ret = 1<<30;
	ret = -ret;
	if(x <= mid) ret = querymx(l, mid, ls, x, y);
	if(y > mid) ret = max(ret, querymx(mid+1, r, rs, x, y));
	return ret;
}
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i ++ ) scanf("%d", &a[i].x), a[i].id = i;
	build(1, n, 1);
	int anss = 1<<30;
	for(int i = 1; i+k-1 <= n; i ++ ) {
		int ans = 0;
		int minn = querymn(1, n, 1, i, i+k-1);
		int mxn = querymx(1, n, 1, i, i+k-1);
		if(minn < 0) ans += -minn;
		if(mxn > 0) ans += mxn;
		if(minn < 0 && mxn > 0) ans+=min(-minn, mxn);
		//printf("%d %d %d\n", i, i+k-1, ans);
		anss = min(ans, anss);
	}
	printf("%d\n", anss);
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int k,s;
	cin >> k >> s;
	int cnt = 0;
	rep(i,0,k+1){
		rep(j,0,k+1){
			int tar = s - (i + j);
			cnt += (tar >= 0 && tar <= k);
		}
	}
	cout << cnt << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
ll INF = 1000000007;

//-----------------//
  #define amin main
//-----------------//

ll exp(ll x, ll n)
{if(n==0) return 1;if(n==1) return x%INF;if(n%2==0) return exp((x*x)%INF,n/2); else return(x*exp((x*x)%INF,n/2))%INF;}


int amin()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t,i,j;
	ll a,b,c;
	cin>>a>>b>>c;
	ll k;
	cin>>k;
	ll x = a/c;
	ll y = b/c;
	ll z = a/b;
	ll cnt = 0;

	ll f = 0;
	while(b<=a && f!=1)
	{
		b = b*2;
		z = a/b;
		cnt++;
		if(cnt>k)
		{
			f = 1;break;

		}
	}
	while(c<=a)
	{
		c = c*2;
		x = a/c;
		cnt++;
		if(cnt>k)
		{
			f = 1;
			break;
		}
	}
	y = b/c;
	while(c<=b && f!=1)
	{
		c = c*2;
		y = b/c;
		cnt++;
		if(cnt>k)
		{
			f = 1;
			break;
		}
	}
	z = a/b;
	
	//cout<<cnt<<endl;
	//cout<<a<<" "<<b<<" "<<c<<endl;
	if(f==1)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;


	


	
	

	
	


	
	return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<string.h>

int mysubstr( char *t, const char *s, int pos, int len )
{
    if( pos < 0 || len < 0 || len > strlen(s) )
        return -1;
    for( s += pos; *s != '\0' && len > 0; len-- )
        *t++ = *s++;
    *t = '\0';
    return 0;
}

int main(void){
    int len,i;
    char s[100],t[100],u[100];

    scanf("%s",s);

    len = strlen(s);

    for(i=0;i<len;i++){
        t[i]= 'x';
    }

  	mysubstr(u,t,0,len);
  
    printf("%s",u);
}

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


int main() {
long N;
cin>>N;
vector<long> x(N+1);
for(int i=0;i<N+1;i++) cin>>x[i];
long X=x[0];
if(N==1){
  cout<<abs(x[1]-x[0])<<endl;
  return 0;
}
sort(x.begin(),x.end());
long ans=gcd(x[1]-x[0],x[2]-x[1]);
for(int i=0;i<N-2;i++){
  long tmp=gcd(x[i+1]-x[i],x[i+2]-x[1]);
  ans = gcd(ans,tmp);
}
cout<<ans<<endl;
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    vector<Int> res;
    Int n, m;
    while (cin >> n >> m and n) {
        vector<Int> a(n + 1, 0), b(m + 1, 0);
        for (Int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        for (Int i = 1; i <= m; i++) {
            cin >> b[i];
        }
        for (Int i = 0; i < n; i++) {
            a[i + 1] += a[i];
        }
        for (Int i = 0; i < m; i++) {
            b[i + 1] += b[i];
        }
        vector<Int> c;
        for (Int i = 0; i < n; i++) {
            for (Int j = i + 1; j <= n; j++) {
                c.push_back(a[j] - a[i]);
            }
        }
        map<Int, Int> mp;
        for (Int i = 0; i < m; i++) {
            for (Int j = i + 1; j <= m; j++) {
                mp[b[j] - b[i]]++;
            }
        }
        Int cnt = 0;
        for (Int i = 0; i < (Int)c.size(); i++) {
            cnt += mp[c[i]];
        }
        res.push_back(cnt);
    }
    for (Int i = 0; i < (Int)res.size(); i++) {
        dump(res[i]);
    }
    return 0;
}



Measured memory_bytes: 30752
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)

	m := int(math.Pow10(12))-1
	nn := int(math.Ceil(math.Sqrt(float64(n))))
	for i := 1; i <= nn; i++ {
		if n%i == 0 {
			r := i + n/i - 2
			if m > r {
				m = r
			}
		}
	}
	fmt.Println(m)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin>>s;
    ll a=0,m=0;
    for(ll i=0;i<s.size();i++)
    {
        if(s[i]=='R')
            {
                a++;
                m=max(a,m);
            }
        else
        {
            a=0;
        }
    }
    cout<<m<<"\n";
    return 0;
}


Measured memory_bytes: 3616
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

    public static void main(String[] args) throws Exception {
        PrintWriter out = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = br.readLine().split(" ");
        int N = Integer.parseInt(lines[0]);
        int M = Integer.parseInt(lines[1]);
        out.println(N*(N-1)/2 + M*(M-1)/2);
        out.flush();
        out.close();
        br.close();
    }
}

Measured memory_bytes: 21076
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
int main() {
    string n;
    cin >> n;
    if(n[0] == '7' || n[1] == '7' || n[2] == '7') dunk("Yes");
    else dunk("No");
    return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    int cnt = 1;
    int ans = 0;
    while (cnt < b) {
        cnt += a - 1;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

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

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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int total = 0;

  rep(i, n) {
    int x;
    cin >> x;
    int b = abs(x - k);
    if (x < b) {
      total += x * 2;
    } else {
      total += b * 2;
    }
  }
  cout << total << endl;
  return 0;
}

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

using namespace std;

int n;
vector<int> p;
vector<int> x;
vector<vector<int> > c;

int work (int node) {
    vector<pair<int, int> > res;
    for (int child : c[node]) {
        int ret = work(child);
        if (ret == -1) return -1; 
        res.push_back({x[child], ret});
    }   
    set<pair<int, int> > dp = {{0, 0}};
    for (auto p : res) {
        set<pair<int, int> > dp2;
        for (auto q : dp) {
            int a = p.first + q.first, b = p.second + q.second;
            if (a > b) swap(a, b); 
            if (a <= x[node]) dp2.insert({a, b});
            a = p.first + q.second, b = p.second + q.first;
            if (a > b) swap(a, b); 
            if (a <= x[node]) dp2.insert({a, b});
        }   
        dp = dp2;
    }   
    int minn = 0x7fffffff;
    for (auto q : dp) {
        if (q.second <= x[node]) minn = min(minn, q.first);
        else minn = min(minn, q.second);
    }   
//  cout << node << ' ' << minn << endl;
    if (minn == 0x7fffffff) return -1; 
    return minn;
}

int main () {
    cin >> n;
    p.resize(n);
    x.resize(n);
    c.resize(n);
    for (int i = 1; i < n; i ++) {
        int p; cin >> p;
        c[p-1].push_back(i);
    }   
    for (int i = 0; i < n; i ++) {
        cin >> x[i];
    }   
    if (work(0) != -1) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;

return 0;
}

Measured memory_bytes: 512
import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np
 
def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W
 
# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

N = i_inpl()
A = l_inpl()
d = defaultdict(int)

for Ai in A:
    d[Ai] += 1

for k, v in d.items():
    while v > 2:
        v -= 2
    d[k] = v

print(len(d) - (len([v for v in d.values() if v == 2])%2 == 1))

Measured memory_bytes: 63920
// https://atcoder.jp/contests/abc042/tasks/abc042_b

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define FOR(i,L,R) for (int i = L; i < R; i++)

int main(){
    int n;
    scanf("%d%*d", &n);
    char s[101][101];
    FOR(i, 0, n)
        scanf("%s", &s[i]);
    qsort(s, n, sizeof(s[0]), strcmp);
    FOR(i, 0, n)
        printf("%s", s[i]);
}

Measured memory_bytes: 252
#include<stdio.h>
int main(){

  char s[4];
  scanf("%s",s);
  int i,c[27]={0};
  for(i=0;i<4;i++)
    c[s[i]-'A']++;
  for(i=0;i<27;i++){
    if(c[i]==2||c[i]==0);
    else{
      puts("No\n");
      return 0;
    }
  }
  puts("Yes\n");
  return 0;
}



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

a, b, c, d = 0, 0, 0, 0
for _ in range(N):
    s = input()
    if s[0]=="B" and s[-1]=="A":
        a += 1
    elif s[0]=="B":
        b += 1
    elif s[-1]=="A":
        c += 1
    d += s.count("AB")

ans = d
if b==c==0:
    ans += max(0, a-1)
else:
    ans += a + min(b, c)
print(ans)

Measured memory_bytes: 3064
io = STDIN
n=io.gets.to_i
a=io.gets.split.map(&:to_i)
hash={}
hash.default=0
a.each do |aa|
  hash[aa]+=1
end
ans=0
(0..10**5).each_cons(3) do |x,y,z|
  ans=[ans,hash[x]+hash[y]+hash[z]].max
end
puts ans


Measured memory_bytes: 14724
from collections import deque
que=deque(input())
rev=False
for _ in range(int(input())):
    t=input()
    if t=='1':
        rev=not rev
    else:
        tt,f,c=t.split()
        if (f=='1' and rev==False)  or (f=='2' and rev):
            que.appendleft(c)
        else:
            que.append(c)
if rev:
    que.reverse()

print(''.join(que))
        


Measured memory_bytes: 74200
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,z,w;
  cin>>n>>z>>w;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  if(n>1)
    cout<<max(abs(a[n-1]-w),abs(a[n-2]-a[n-1]));
  else
    cout<<abs(a[n-1]-w);
}

Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn main(){
    let mut line = read_as_vec::<u32>();
    line.sort();

    println!("{}", (line[0]*line[1]) as f64/2.0);
}


Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
const int INF = 1000000000;

int main()
{
	int a;
	cin >> a;
	if (a == 7 || a == 5 || a == 3) puts("YES");
	else puts("NO");
}


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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vec;
typedef vector<P> pvec;
typedef vector<vector<int>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<int> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<int,vector<int>,greater<int>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const ll INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001); // 10^(-10)

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec G(nmax);





void solve4ts()
{
    
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int mi=a[0];
    int ans=0;
    rep(i,n){
        chmax(mi,a[i]);
        ans+=max(0LL,mi-a[i]);
    }
    cout<<ans<<endl;
    
    
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve4ts();
}

/*

g++ -std=c++1z code.cpp
./a.out

*/

Measured memory_bytes: 9504
n=io.read("*n","*l")
m={}
combination=0
for i=1,n do
    a=io.read("*n")
    if not m[i+a] then
        m[i+a]=0
    end
    if m[i-a] then
        combination=combination+m[i-a]
    end
    m[i+a]=m[i+a]+1
end
print(combination)

Measured memory_bytes: 14816
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static boolean isBingo(boolean B[][]){
		for(int i = 0 ; i < 3 ; ++i){
			boolean check = true;
			for(int j = 0 ; j < 3 ; ++j){
				if(!B[i][j]){
					check = false;
				}
			}
			if(check)return true;
			check = true;
			for(int j = 0 ; j < 3 ; ++j){
				if(!B[j][i]){
					check = false;
				}
			}
			if(check)return true;
		}
		boolean check = true;
		for(int i = 0 ; i < 3 ; ++i){
			if(!B[i][i]){
				check = false;
			}
		}
		if(check)return true;
		check = true;
		for(int i = 0 ; i < 3 ; ++i){
			if(!B[i][2 - i]){
				check = false;
			}
		}
		return check;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A[][] = new int[3][3];
		for(int i = 0 ; i < 3 ; ++i){
			for(int j = 0 ; j < 3 ; ++j){
				A[i][j] = sc.nextInt();
			}
		}
		int N = sc.nextInt();
		boolean B[][] = new boolean[3][3];
		for(int a = 0 ; a < N ; ++a){
			int b = sc.nextInt();
			for(int i = 0 ; i < 3 ; ++i){
				for(int j = 0 ; j < 3 ; ++j){
					if(A[i][j] == b){
						B[i][j] = true;
					}
				}
			}
		}
//		System.out.println(Arrays.deepToString(B));
		if(isBingo(B)){
			System.out.println("Yes");
		}else{
			System.out.println("No");			
		}
	}
}


Measured memory_bytes: 25172
import sys;sys.setrecursionlimit(int(1e7))

N = int(input())
ABC = [tuple(map(int,input().split())) for _ in range(N-1)]
Q,K = map(int,input().split())
XY = [tuple(map(int,input().split())) for _ in range(Q)]

tree = [[] for _ in range(N+1)]

for abc in ABC:
    tree[abc[0]].append([abc[1],abc[2]])
    tree[abc[1]].append([abc[0],abc[2]])

def DFS(v,p,d):
    tree[v][0].append(d)
    for e in tree[v]:
        if e[0] != p:
            DFS(e[0], v, d + e[1])

DFS(K,0,0)

for i in range(Q):
    print(tree[XY[i][0]][0][2] + tree[XY[i][1]][0][2])

Measured memory_bytes: 164712
// 2_abc142_b
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int ans = 0;
    rep(i, n){
        int h;
        cin >> h;
        if(h >= k) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using pq = priority_queue<int>;
template<class T>
using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int under = (1 << 31);
int upper = under - 1;
ll UNDER = (1LL << 63);
ll UPPER = UNDER - 1;
const int MOD = 1e9 + 7;
const long double pi = 3.141592653589793;
int main() {
	int n;
	cin >> n;
	VL Lucas(n + 1, -1);
	Lucas[0] = 2;
	Lucas[1] = 1;
	REP(i, 2, n + 1) {
		Lucas[i] = Lucas[i - 1] + Lucas[i - 2];
	}
	cout << Lucas[n] << endl;
	return 0;
}

Measured memory_bytes: 256
const input = require("fs").readFileSync("/dev/stdin", "utf8");
// const input = 'ABC';

function Main(input) {
  const nextContest = {
    ARC: 'ABC',
    ABC: 'ARC'
  }

  console.log(nextContest[input.trim()])
}

// Don't edit this line!
Main(input);

Measured memory_bytes: 30128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;

ll a[100005];
vii v[100005];

ll dfs(int at,int p)
{
	vll v1;
	if(v[at].size()==1)return a[at];
	tr(v[at],it)
	{
		int to=*it;
		if(to!=p)
		v1.pb(dfs(to,at));
	}
	if(v1.size()==1)
	{
		if(a[at]==v1[0])
		return a[at];
		ol("NO");
		exit(0);
	}
	ll s=0,mx=0;
	tr(v1,it)s+=(*it),mx=max(mx,*it);
	if(s-a[at]<0||mx>a[at]||2*a[at]-s<0)
	{
		ol("NO");
		exit(0);
	}
	
	return 2*a[at]-s;

}

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;

rep(i,1,n)cin>>a[i];
int rt=1;
rep(i,1,n-1)
{
	int x,y;
	cin>>x>>y;
	v[x].pb(y);
	v[y].pb(x);
	if(v[x].size()>1)rt=x;
	if(v[y].size()>1)rt=y;
}

if(n==2)
{
	if(a[1]==a[2])ol("YES");
	else ol("NO");
	return 0;
}
if(!dfs(rt,0))ol("YES");
else ol("NO");

return 0;
}


Measured memory_bytes: 15872
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

using P = pair<int,int>;

int H, W;
vector<string> cells;

bool is_valid(P& p) {
    int x = p.first;
    int y = p.second;
    return 0 <= x && x <= W-1 && 0 <= y && y <= H-1;
}

bool is_passed(P& p) {
    int x = p.first;
    int y = p.second;
    return cells[y][x] == '#';
}

int main(void)
{
    cin.sync_with_stdio(false);
    cin >> H >> W;
    cells.resize(H);
    REP(h,H) cin >> cells[h];

    P prev{-1,-1};
    P p{0,0};
    P goal{W-1,H-1};
    cells[p.second][p.first] = '.';
    bool ok = true;
    while(p != goal) {
        P p_r = p; p_r.first += 1; 
        bool move = false;
        while (is_valid(p_r) && is_passed(p_r)) {
            cells[p_r.second][p_r.first] = '.';
            p = p_r;
            move = true;
        }
        P p_d = p; p_d.second += 1; 
        while (is_valid(p_d) && is_passed(p_d)) {
            cells[p_d.second][p_d.first] = '.';
            p = p_d;
            move = true;
        }
        if (!move) {
            ok = false;
            break;
        }
    }
    REP(h,H) {
        REP(w,W) {
            P p{w,h};
            if (is_passed(p)) ok = false;
        }
    }

    if (ok) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    
    return 0;
}


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

typedef long long ll;

int main(){
	ll n = 50;
	ll k;
	cin >> k;
	ll a[52];
	for(int i = 0 ; i < n ; i ++){
		a[i] = n-1+k/n;
	}
	for(int i = 0 ; i < k%n ; i ++){
		a[i] -= k%n;
		a[i] += n+1;
	}
	for(int i = k%n ; i < n ; i ++){
		a[i] -= k%n;
	}
	cout << n << endl;
	for(int i = 0 ; i < n ; i ++){
		cout << a[i] << ((i+1==n)?'\n':' ');
	}
}



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

int main(){
    int N;
    cin >> N;
    long long T[5] = {0};
    for(int i=0;i<N;i++){
        string S;
        cin >> S;
        switch (S.at(0))
        {
        case 'M':
            T[0]++;
            break;
        case 'A':
            T[1]++;
            break;
        case 'R':
            T[2]++;
            break;
        case 'C':
            T[3]++;
            break;
        case 'H':
            T[4]++;
            break;
        default:
            break;
        }
    }
    long long sum = 0;
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            for(int k=j+1;k<5;k++){
                sum += T[i] * T[j] * T[k];
            }
        }
    }
    cout << sum;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int n, m; cin >> n >> m;
  vector<vector<int>> es(n);
  rep(i, m) {
    int v, u; cin >> v >> u;
    v--, u--;
    es[u].emplace_back(v);
  }
  vector<int> dp(n);
  vector<int> se(n);
  function<int(int)> dfs = [&](int u) {
    if (se[u]) return dp[u];
    se[u] = true;
    int ret = 0;
    each(v, es[u]) {
      amax(ret, dfs(v) + 1);
    }
    return dp[u] = ret;
  };
  rep(i, n) dfs(i);
  int ans = 0;
  rep(i, n) amax(ans, dp[i]);
  cout << ans << '\n';
}


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

using namespace std;

const int NMAX = 200000 + 5;

int N;
vector <int> tomTree[NMAX];
vector <int> jerryTree[NMAX];

int tomCnt;
int tomH[NMAX];
int tomFathers[19][NMAX];
int tomFirst[NMAX];
int tomLast[NMAX];

void dfsPrepareTomTree(int node) {
    tomFirst[node] = ++tomCnt;
    if (tomFathers[0][node])
        tomTree[node].erase(find(tomTree[node].begin(), tomTree[node].end(), tomFathers[0][node]));
    
    for (int i = 1; i < 19; ++ i)
        tomFathers[i][node] = tomFathers[i - 1][tomFathers[i - 1][node]];
    
    for (auto it: tomTree[node]) {
        tomH[it] = 1 + tomH[node];
        tomFathers[0][it] = node;
        dfsPrepareTomTree(it);  
    }
    tomLast[node] = tomCnt;
}

int moveCloser(int t, int j) {
    if (t == j) // No need to move
        return t;
    else if (tomFirst[t] <= tomFirst[j] && tomFirst[j] <= tomLast[t]) { // Move in a son
        int st = 1, dr = tomTree[t].size() - 1;
        int ans = 0;
        while (st <= dr) {
            int mid = (st + dr) >> 1;
            if (tomFirst[tomTree[t][mid]] <= tomFirst[j])
                ans = mid, st = mid + 1;
            else
                dr = mid - 1;
        }
        return tomTree[t][ans];
    }
    else // Move in the father
        return tomFathers[0][t];
}

inline int lca(int a, int b) {
    if (tomH[a] > tomH[b])
        swap(a, b);
    for (int i = 18; i >= 0; -- i)
        if ((1 << i) <= tomH[b] - tomH[a])
            b = tomFathers[i][b];
    if (a == b)
        return a; 
    for (int i = 18; i >= 0; -- i)
        if (tomFathers[i][a] != tomFathers[i][b])
            a = tomFathers[i][a], b = tomFathers[i][b];
    return tomFathers[0][a];
}

inline int getDist(int a, int b) {
    return tomH[a] + tomH[b] - 2 * tomH[lca(a, b)];
}

const int INF = 2E9 + 256;
bool easyWinJerry[NMAX];

bool jerryVis[NMAX];
int play(int t, int j) { // Jerry moves
    if (t == j)
        return 0;
    if (easyWinJerry[j])
        return INF;
    jerryVis[j] = true;

    int longest = 2 * getDist(t, j);
    for (auto it: jerryTree[j])
        if (!jerryVis[it])
            longest = max(longest, 2 + play(moveCloser(t, it), it));
    jerryVis[j] = false;
    return longest;
}

int main() {
    //freopen("data.in", "r", stdin);
    ios_base :: sync_with_stdio(false);

    int t, j;
    cin >> N >> j >> t;
    for (int i = 1; i < N; ++ i) {
        int a, b;
        cin >> a >> b;
        jerryTree[a].push_back(b);
        jerryTree[b].push_back(a);
    }
    for (int i = 1; i < N; ++ i) {
        int a, b;
        cin >> a >> b;
        tomTree[a].push_back(b);
        tomTree[b].push_back(a);
    }
    dfsPrepareTomTree(t);

    for (int i = 1; i <= N; ++ i)
        for (auto it: jerryTree[i]) {
            int d = getDist(i, it);
            if (d >= 3)
                easyWinJerry[i] = easyWinJerry[it] = true;
        }

    int ans = play(t, j);
    if (ans >= INF)
        cout << "-1\n";
    else
        cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 48252
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100000+20
  int c[MAXN]={0};
typedef struct Node{
  int num;
  long long year;
  int t;
  int st;
}city;
bool cmp1(Node s1,Node s2){
  if(s1.num == s2.num){
    return (s1.year<s2.year)?true:false;
  }else{
    return (s1.num<s2.num)?true:false;
  }
}
bool cmp2(Node s1,Node s2){
      return (s1.t<s2.t)?true:false;
}
int fx(int n){
  int rst = 0;
  if(n == 0)
  return 1;
  while(n>0){
    n/=10;
    rst++;
  }
  return rst;
}
city b[MAXN];
int main(){
  int n,m;
  cin>>n>>m;
 
  for(int i=1;i<=m;i++){
    cin>>b[i].num>>b[i].year;
    b[i].t = i;
  }
  sort(b+1,b+m+1,cmp1);
 
  for(int i = 1;i<=m;i++){
    b[i].st = c[b[i].num];
    c[b[i].num]++;
  }
  sort(b+1,b+m+1,cmp2);
  for(int i =1;i<=m;i++){
    int x = fx(b[i].num);
    int y = fx(b[i].st+1);
    // cout<<x<<" "<<y<<endl;
    while(x<6){
      cout<<'0';
      x++;
    }
    cout<<b[i].num;
    while(y<6){
      cout<<'0';
      y++;
    }
    cout<<b[i].st+1<<endl;
    // cout<<b[i].num<<" "<<b[i].year<<" "<<b[i].st<<endl;
  }
}

Measured memory_bytes: 4224
n = int(input())
s = list(input())
if n%2==0:
  a = s[:n//2]
  b = s[n//2:]
  for i in range(n//2):
    if a[i]==b[i]:
      pass
    else:
      print("No")
      break
  else:
    print("Yes")
else:
  print("No")

  

Measured memory_bytes: 3060
//-----by LY02------------------------------------
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
//------------------------------------------------

int w[110],v[110];
long long dp[110][100010];

//------------------------------------------------
int main() {
//------------------------------------------------
//	freopen("In.txt","r",stdin);
//	freopen("Out.txt","w",stdout);
//------------------------------------------------
	ios::sync_with_stdio(0);
	cin.tie(0);
//------------------------------------------------

int n,k;
cin>>n>>k;

for(int i=0;i<n;i++)
	cin>>w[i]>>v[i];
memset(dp,-1,sizeof(dp));
dp[0][0]=0;
dp[0][w[0]]=v[0];
for(int i=1;i<n;i++)
{
	for(int j=0;j<=k;j++)
	{
		if(dp[i-1][j]==-1) continue;
		dp[i][j]=max(dp[i-1][j] , dp[i][j]);
		if(j+w[i]>k) continue;
		dp[i][j+w[i]]=max(dp[i-1][j]+v[i] , dp[i][j+w[i]]);
	}
//	cout<<i<<" : \n";
//	for(int j=0;j<=k;j++)
//	{
//		if(dp[i][j]==-1) continue;
//		cout<<j<<" "<<dp[i][j]<<endl;
//	}
}
long long ans=0;
for(int i=0;i<=k;i++)
{
	if(dp[n-1][i]==-1) continue;
	ans=max(dp[n-1][i],ans);
}
cout<<ans<<endl;

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





//-----by LY02------------------------------------


Measured memory_bytes: 86272
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
inline char gc() {
//	return getchar();
	static char buf[100000],*l=buf,*r=buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void rd(T &x) {
	x=0; int f=1,ch=gc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=gc();}
	x*=f;
}
typedef long long ll;
const int mod=1e9+7;
const int maxn=5000+5,maxm=5000+5;
int n,m;
int pow2[maxm],inv2[maxm];
int dp[maxn][maxm],sum[maxn][maxm];
int main() {
	rd(n),rd(m);
	pow2[0]=1,pow2[1]=2;
	inv2[0]=1,inv2[1]=(mod+1)>>1;
	for(int i=2;i<=m;++i) {
		pow2[i]=(ll)pow2[i-1]*pow2[1]%mod;
		inv2[i]=(ll)inv2[i-1]*inv2[1]%mod;
	}
	for(int i=1;i<=m;++i) {
		dp[1][i]=pow2[i];
		sum[1][i]=(sum[1][i-1]+(ll)dp[1][i]*i%mod*inv2[i])%mod;
	}
	for(int i=2;i<=n;++i) for(int j=1;j<=m;++j) {
		dp[i][j]=((ll)dp[i-1][j]*(j+1)+(ll)sum[i-1][j-1]*pow2[j-1])%mod;
		sum[i][j]=(sum[i][j-1]+(ll)dp[i][j]*j%mod*inv2[j])%mod;
	}
	printf("%d\n",dp[n][m]);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int l, r;
  int counter = 0;
  for(int i=0; i<N; i++){
    cin >> l >> r;
    counter += r - l + 1;
  }
  
  cout << counter << endl;
}


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

const int N = 2000;
string f[N];
ll s[N][N];
ll in[4][N][N];
int gone[N][N];
int h, w, q; 
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

/*
 2
3 1
 0
*/

int deg(int y, int x) {
  int c = 0;
  for(int d = 0; d < 4; d++) {
    int sy = y + dy[d];
    int sx = x + dx[d];
    if(sy < 0 || h <= sy || sx < 0 || w <= sx) continue;
    if(f[sy][sx] == '0') continue;
    c++;
  }
  return c;
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> h >> w >> q;
  for(int i = 0; i < h; i++) cin >> f[i];

  for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) {
    if(gone[i][j]) continue;
    if(deg(i, j) > 1) continue;
    if(f[i][j] == '0') continue;
    gone[i][j] = 1;
    s[i][j]++;

    queue<pair<int, int>> que;
    que.emplace(i, j);
    while(que.size()) {
      int y = que.front().first, x = que.front().second;
      que.pop();
      for(int d = 0; d < 4; d++) {
        int sy = y + dy[d];
        int sx = x + dx[d];
        if(sy < 0 || h <= sy || sx < 0 || w <= sx) continue;
        if(gone[sy][sx]) continue;
        if(f[sy][sx] == '0') continue;
        gone[sy][sx] = 1;
        in[d][sy][sx]++;
        que.emplace(sy, sx);
      }
    }
  }

  // for(int i = 0; i < h; i++) {for(int j = 0; j < w; j++) cerr << s[i][j] << " "; cerr << endl;}

  for(int i = 1; i < h; i++) for(int j = 0; j < w; j++) s[i][j] += s[i - 1][j];
  for(int i = 0; i < h; i++) for(int j = 1; j < w; j++) s[i][j] += s[i][j - 1];

  // for(int i = 0; i < h; i++) {for(int j = 0; j < w; j++) cerr << s[i][j] << " "; cerr << endl;}
  
  for(int d = 0; d < 4; d++) {
    if(d % 2) for(int i = 1; i < h; i++) for(int j = 0; j < w; j++) in[d][i][j] += in[d][i - 1][j];
    else for(int i = 0; i < h; i++) for(int j = 1; j < w; j++) in[d][i][j] += in[d][i][j - 1];
  }

  for(int i = 0; i < q; i++) {
    int i1, j1, i2, j2; cin >> i1 >> j1 >> i2 >> j2;
    i1--; j1--; i2--; j2--;
    ll ans = 0;
    // cerr << endl << " i = " << i << endl;
    ans += s[i2][j2];
    // cerr << ans << endl;
    if(j1) ans -= s[i2][j1 - 1];
    if(i1) ans -= s[i1 - 1][j2];
    if(j1 && i1) ans += s[i1 - 1][j1 - 1];
    // cerr << ans << endl;
    ans += in[0][i1][j2];
    if(j1) ans -= in[0][i1][j1 - 1];
    // cerr << ans << endl;
    ans += in[2][i2][j2];
    if(j1) ans -= in[2][i2][j1 - 1];
    // cerr << ans << endl;
    ans += in[1][i2][j1];
    if(i1) ans -= in[1][i1 - 1][j1];
    // cerr << ans << endl;
    ans += in[3][i2][j2];
    if(i1) ans -= in[3][i1 - 1][j2];
    // cerr << ans << endl;
    // cerr << endl << endl;

    cout << ans << endl;
  }
}

/*
 2
3 1
 0
*/


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

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

    if (S[2] == S[3] && S[4] == S[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

typedef long long ll;

int main(){
  int N;
  cin >> N;
  string str; 
  cin >> str;
  for(int i=0; i<str.size(); i++){
    int dif=str[i]-'A';
    int res=(dif+N)%26;
    str[i]='A'+res;
    cout << str[i];
  }
  cout << endl;
}

Measured memory_bytes: 256