akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
    long w,h,n;
    cin>>w>>h>>n;
    long w_min=0,h_min=0;
    for(int i=0; i<n; i++){
        long x,y,a;
        cin>>x>>y>>a;
        if(a==1&&x>w_min)
            w_min=x;
        if(a==2&&x<w)
            w=x;
        if(a==3&&y>h_min)
            h_min=y;
        if(a==4&&y<h)
            h=y;
    }
    cout<<max((long)0,h-h_min)*max((long)0,w-w_min);
}

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

int main() {
    int n, k, x, i, l=0;
    cin >> n >> k;

    for (i=0; i<n; i++) {
        cin >> x;
        l += 2*min(x, abs(x-k));
    }
    cout << l << endl;
}

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

int main(){
int n,k,d;
cin >> n >> k;
vector<int> vec(n,0);


for (int i = 0; i < k; i++){    
    cin >> d ;
 for (int j = 0; j < d; j++){     
     int A;
     cin >> A;
     vec[A-1]++;
 }
}

int ans=0;
for (int i = 0; i < n; i++){
if(vec[i]==0) ans++;
}

cout << ans << endl;
return 0;


}








Measured memory_bytes: 3640
def main():
  t_list = []
  for i in range(5):
    t_list.append(int(input()))
  t_list = sorted(t_list, key=lambda x: (x + 9) % 10)[::-1]
  time = 0
  for i in range(4):
    time += 10 * ((t_list[i] + 9) // 10)
  time += t_list[4]
  print(time)


if __name__ == "__main__":
  main()


Measured memory_bytes: 3060
#include<stdio.h>
int main(){
  int A[101], n, i, j, t, sw = 0;

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

  for ( i = 1; i <= n; i++ ){
    for ( j = n; j >= i+1; j-- ){
      if ( A[j] < A[j-1] ){
	t = A[j]; A[j] = A[j-1]; A[j-1] = t;
	sw++;
      }
    }
  }

  for ( i = 1; i <= n; i++ ){
    if (i>1) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
  printf("%d\n", sw);

  return 0;
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,n,k,b[200010]={0},t=0,ans=0,x,m=0;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		b[a]++;
	} 
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++)
		if(b[i])t++;
	for(int i=1;i<=n;i++)
	{
		if(t-m<=k){cout<<ans;return 0;} 
		else
		{
			if(b[i])
		    { 
			ans+=b[i];
		    m++;
		    } 
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

ll gcd(ll a, ll b){
  ll temp;
	while (a % b != 0){
		temp = b;
		b = a % b;
		a = temp;
	}
	return b;
}

ll lcm(ll a, ll b){
  return a * b / gcd(a,b);
}

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};

int main(){
    int N,A,B,C,D;
    string S;
    cin >> N >> A >> B >> C >> D;
    cin >> S;

    A-=1;B-=1;C-=1;D-=1;

    for(int i=A; i<C; i++){
        if (S[i]=='#' && S[i+1]=='#'){
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i=B; i<D; i++){
        if (S[i]=='#' && S[i+1]=='#'){
            cout << "No" << endl;
            return 0;
        }
    }
    if (C < D) {
        cout << "Yes" << endl;
        return 0;
    }else{
        for(int i=B-1; i<D; i++){
            if (S[i]=='.' && S[i+1]=='.' && S[i+2]=='.'){
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
        return 0;
    }
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll R, G, B, N;
    cin >> R >> G >> B >> N;
    ll cnt = 0;
    rep(r, 3001) {
        rep(g, 3001) {
            ll b = (N - r * R - g * G) % B, ans = N - r * R - g * G;
            if (ans >= 0 && b == 0) {
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int maxn=100005;
struct SHIT
{
    int one,two;
    bool operator<(const SHIT  &b)const {
        if(this->one!=b.one) return (this->one<b.one);
        return (this->two<b.two);
    }
}shit[maxn];
bool cmp(SHIT a,SHIT b)
{
    if(a.one+a.two!=b.one+b.two)
        return a.one+a.two<b.one+b.two;
    return a.one<b.one;
}
map<SHIT,bool>mp;
int main()
{
    int n;
    mp.clear();
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&shit[i].one,&shit[i].two);
        mp[shit[i]]=1;
    }
    if(!(shit[1].one==shit[2].two&&shit[1].two==shit[2].one&&shit[1].one==0&&shit[1].two!=0)){
        puts("-1");
        return 0;
    }
    int mn=shit[1].two;
    int ans=2*n-2;
    for(int i=3;i<=n;i++)
    {
        if(shit[i].one==0||shit[i].two==0||shit[i].one+shit[i].two<mn){
            puts("-1");
            return 0;
        }
    }
    sort(shit+1,shit+n+1,cmp);
    for(int i=1,j;i<=n;i=j)
    {
        j=i+1;
        while(j<=n&&shit[j].one+shit[j].two==shit[i].one+shit[i].two)
            j++;
        for(int k=i;k<j;k++)
            mp[shit[k]]=1;
        int last=0,left=0;
        for(int k=i,tk;k<j;k=tk)
        {
            tk=k+1;
            while(tk<j&&shit[tk].one==shit[k].one){
                tk++;
            }
            int now=tk-k;
            bool one=0,two=0;
            SHIT tmp1,tmp2;
            tmp1.one=shit[k].one-1;
            tmp1.two=shit[k].two-1;
            if(mp.count(tmp1)){
                ans-=now;
                if(last+1!=shit[k].one)
                    now=0;
                else now=min(now,left);
                last=shit[k].one;
                left=now;
 
                continue;
                one=1;two=1;
            }
 
 
            tmp1.one=shit[k].one-1;
            tmp1.two=shit[k].two+1;
            tmp2.one=shit[k].one+1;
            tmp2.two=shit[k].two-1;
 
 
 
            one=one|mp.count(tmp1);
            two=two|mp.count(tmp2);
 
            tmp1.two--;
            tmp2.one--;
            one=one|mp.count(tmp1);
            two=two|mp.count(tmp2);
 
            if(shit[k].one==0)one=1;
            if(shit[k].two==0) two=1;
            if(one==0||two==0){
                puts("-1");
                return 0;
            }
            int del=0;
            if(last+1==shit[k].one){
                del=min(now,left);
                ans-=del;
            }
            tmp1.two--;
 
            last=shit[k].one;
            left=now;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000001
#define pi 3.141592653589793
#define pii pair<int , int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack <int>
#define stll stack <ll>
#define mseti set <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(20)//use fixed before stp
#define endl '\n'
int main()
{  
    FAST
    ll n,m;
    cin>>n>>m;
    char ch[n+2][m+2];
    ll a[n+2][m+2];
    for(ll i=0;i<=n+1;i++)
    {
        for(ll j=0;j<=m+1;j++)
        {
            ch[i][j]='#';
            a[i][j]=0;
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            cin>>ch[i][j];
        }
    }
    a[1][1]=1;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            if(ch[i][j]=='.')
            {
                a[i][j]+=a[i-1][j]+a[i][j-1];
            }
            a[i][j]%=mod;
        }
    }
    cout<<a[n][m];
}

Measured memory_bytes: 9088
A=list()
B=list()
n,m=map(int,input().split())
if m==0:
  print([0, 10, 100][n - 1])
  exit()
for i in range(m):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
  if a==1 and b==0 and n!=1:
    print(-1)
    exit()
for i in range(1000):
  c=str(i)
  if len(c)==n:
    for j in range(m):
      if c[A[j]-1]!=str(B[j]):
        break
      if j==m-1:
        print(i)
        exit()
print(-1)

Measured memory_bytes: 9184
<?php
    $status = array();
    fscanf(STDIN, "%d %d", $N, $M);
    while(true)
    {
        $stdin = trim(fgets(STDIN));
        if ($stdin === '') 
        {
            break;
        }
        $status[] = explode(' ', $stdin);
    }
    //
    $status_sum = array();
    for($i=0; $i<$N; $i++)
    {
        $status_sum[0][$i] =  $status[$i][0] + $status[$i][1] + $status[$i][2];
        $status_sum[1][$i] = -$status[$i][0] + $status[$i][1] + $status[$i][2];
        $status_sum[2][$i] =  $status[$i][0] - $status[$i][1] + $status[$i][2];
        $status_sum[3][$i] =  $status[$i][0] + $status[$i][1] - $status[$i][2];
        $status_sum[4][$i] =  $status[$i][0] - $status[$i][1] - $status[$i][2];
        $status_sum[5][$i] = -$status[$i][0] + $status[$i][1] - $status[$i][2];
        $status_sum[6][$i] = -$status[$i][0] - $status[$i][1] + $status[$i][2];
        $status_sum[7][$i] = -$status[$i][0] - $status[$i][1] - $status[$i][2];
    }
    //
    $result = array();
    for($i=0; $i<8; $i++)
    {
        rsort($status_sum[$i]);
        $result[$i] = array_sum(array_slice($status_sum[$i], 0, $M));
    }
    //
    echo max($result);
?>

Measured memory_bytes: 5620
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

void solve_A(); void solve_B(); void solve_C(); void solve_D();

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    /*
     solve_A();
     //*/
    
    //*
     solve_B();
     //*/
    
    
    /*
     solve_C();
     //*/
    
    /*
    solve_D();
     //*/
	return 0;
}

void solve_A(){
    ll N; cin >> N;
    cout << N/3 << endl;
}

void solve_B(){
    ll N; cin >> N;
    vector<char> S(N);
    for(auto &in:S) cin >> in;
    bool f1,f2,f3,f4;
    f1 = f2 = f3 = f4 = false;
    for(int i = 0; i < N;i++){
        if(S[i] == 'P') f1 = true;
        if(S[i] == 'W') f2 = true;
        if(S[i] == 'G') f3 = true;
        if(S[i] == 'Y') f4 = true;
    }
    if(f4){
        cout << "Four" << endl;
    }else{
        cout << "Three" << endl;
    }
}

void solve_C(){
    
}

void solve_D(){
    
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <math.h>
#define ll long long
#define bool int

using namespace std;

int main()
{
    ll int a[3],i,sum=0;
    for(i=0;i<3;i++)
    cin>>a[i];
     sort(a,a+3,greater<int>());
    sum+=a[0]-a[1];
    sum+=a[1]-a[2];
    cout<<sum<<endl;
    return 0;
}



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

int main() {
  string s;
  cin>>s;
  int n = s.length();
  for (int i=0; i<n; i++) {
    if (s[i] == '?') {
      cout<<'D';
    } else {
      cout<<s[i];
    }
  }
  cout<<endl;
}

Measured memory_bytes: 3756
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int H = int.Parse(s[0]);
        int W = int.Parse(s[1]);
        string[] map = new string[H + 2];
        for(int i = 0; i < W+ 2; i++)
        {
            map[0] += ".";
            map[H + 1] += ".";
        }
        for (int i = 1; i <= H; i++)
            map[i] = "." + Console.ReadLine() + ".";

        for (int y = 1; y <= H; y++)
        {
            for (int x = 1; x <= W; x++)
            {
                if (map[y][x] == '#')
                    Console.Write('#');
                else
                {
                    int sum = 0;
                    if (map[y - 1][x - 1] == '#') sum++;
                    if (map[y - 1][x] == '#') sum++;
                    if (map[y - 1][x + 1] == '#') sum++;
                    if (map[y][x + 1] == '#') sum++;
                    if (map[y + 1][x + 1] == '#') sum++;
                    if (map[y + 1][x] == '#') sum++;
                    if (map[y + 1][x - 1] == '#') sum++;
                    if (map[y][x - 1] == '#') sum++;
                    Console.Write(sum);
                }
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;

void DFS(vector<int>& vecCount, Graph& vecG, vector<bool>& vecSeen, int cur)
{
    vecSeen[cur] = true;

    for(auto next : vecG[cur]){
        if(vecSeen[next])
            continue;

        vecCount[next] += vecCount[cur];
        DFS(vecCount, vecG, vecSeen, next);
    }
}

int main()
{
    int n, q;
    cin >> n >> q;

    Graph vecG(n);
    for(int i=0; i<n-1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        vecG[a].push_back(b);
        vecG[b].push_back(a);   // 無向グラフ
    }

    vector<int> vecCount(n, 0);
    for(int i=0; i<q; i++){
        int p, x;
        cin >> p >> x;
        p--;
        vecCount[p] += x;
    }

    vector<bool> vecSeen(n, false);
    DFS(vecCount, vecG, vecSeen, 0);

    for(int i=0; i<n-1; i++){
        cout << vecCount[i] << " ";
    }
    cout << vecCount[n-1] << endl;

    return 0;
}

Measured memory_bytes: 29696
l,r = map(int, input().split())

if r-l >= 2019:
  print(0)
  exit(0)
  
ans = 100000000
for i in range(l+1, r+1):
  for j in range(l, i):
    ans = min(ans, (i*j)%2019)
    
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>

int main() {

    int n, k;
    char s[50];

    scanf("%d %d", &n, &k);
    scanf("%s", s);

    s[k - 1] = s[k - 1] + 32;

    printf("%s", s);

    return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cmath>
#include <cstdio>
#include <string>

using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
LL MOD = 1000000007;

int main() {
    string s,t;
    cin >> s >> t; 
    int N = s.size();
    int M = t.size();
    vector<vector<int> > dp(N+1, vector<int> (M+1, 0)), prev(N+1, vector<int>(M+1, 0));
    for(int i=0; i<s.size(); i++)
        for(int j=0; j<t.size(); j++) {
            char x = s[i];
            char y = t[j];
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]); 
            if(x == y) {
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1);

            }
            if(dp[i+1][j+1] == dp[i+1][j]) prev[i+1][j+1] = 0;
            else if(dp[i+1][j+1] == dp[i][j+1]) prev[i+1][j+1] = 1;
            else prev[i+1][j+1] = 2;

        }
    string ans(dp[N][M], 'a');
    int i=N, j=M;
    int iter = dp[N][M] - 1;
    while(iter >= 0) {
        //cout << i << " " << j << " " << iter << endl;
        if(prev[i][j] == 2) {
            ans[iter] = s[i-1];
            iter--;
            i--;
            j--;
            continue;
        }
        if(prev[i][j] == 0) j--;
        else i--;
    

    }


    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 70912
N = int(input())
B_start_cnt = 0
A_end_cnt = 0
AB_cnt = 0
BA_cnt = 0
for i in range(N):
    s = input()
    if s[0] == "B" and s[-1] == "A":
        BA_cnt += 1
    if s[0] == "B" and s[-1] != "A":
        B_start_cnt += 1
    if s[-1] == "A" and s[0] != "B":
        A_end_cnt += 1
    AB_cnt += s.count('AB')
ans = AB_cnt

if BA_cnt == 0:
    ans += min(A_end_cnt,B_start_cnt)
elif max(A_end_cnt,B_start_cnt)>0:
    ans += BA_cnt+min(A_end_cnt,B_start_cnt)
else:
    ans += BA_cnt-1
print(ans)

Measured memory_bytes: 3064
N = gets.to_i
A = gets.split.map(&:to_i)

B = A.map{|a| [a/400, 8].min }.uniq
s = B.size
r = A.count{|a| [a/400, 8].min == 8 }

if s == 1
  if B[0] == 8
    puts "1 #{r}"
  else
    puts "1 1"
  end
else
  if B.max == 8
    puts "#{s-1} #{s-1+r}"
  else 
    puts "#{s} #{s}"
  end
end

Measured memory_bytes: 1788
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
int main(void){

	long long a[100000];
	long long c, d;
	int k;
	int n, m;
	int s, t;
	long long x, y, z;
	long long mid, left, right;

	scanf("%d %lld %lld", &n,&x,&y);
	s = 0;
	right = 0;
	for (int i = 0; i < n; i++){
		scanf("%lld", &a[i]);
		if (right < a[i])right = a[i];
	}
	right = right / y;
	right = right + 2;
	left = 0;
	for (; left + 1 != right;){
		mid = (left + right) / 2;
		z = mid;
		c = 0;
		for (int i = 0; i < n; i++){
			if (a[i] > mid*y){
				d = (a[i] - (mid*y) - 1) / (x - y);
				d++;
				c = c + d;
			}
		}
		if (c > mid){
			left = mid;
		}
		else{
			right = mid;
		}
	}
	printf("%lld\n",right);

	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i=0; i<N; i++) {
    cin >> p.at(i);
  }
  int ans=0;
  for (int j=0; j<N-2; j++) {
    if (p.at(j)<p.at(j+1) && p.at(j+1)<p.at(j+2)) {
      ans=ans+1;
    }
    if (p.at(j+2)<p.at(j+1) && p.at(j+1)<p.at(j)) {
      ans=ans+1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3616
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static final int INF = 0xFFFFFFF;
	static long[][] hash = new long[32][32];
	static long finish;

	public static void main(String[] args) {
		Random rnd = new Random();
		for (int i = 0; i < 32; ++i) {
			for (int j = 0; j < 32; ++j) {
				hash[i][j] = rnd.nextLong();
			}
		}
		for (int i = 0; i < 4; ++i) {
			for (int j = 2; j <= 7; ++j) {
				finish ^= hash[i * 8 + j - 1][i * 8 + j];
			}
		}
		int T = sc.nextInt();
		for (int i = 0; i < T; ++i) {
			System.out.println(solve());
		}
	}

	static int solve() {
		ArrayList<Board> cur = new ArrayList<Board>();
		HashSet<Long> hashes = new HashSet<Long>();
		cur.add(new Board());
		hashes.add(cur.get(0).h);
		int i = 0;
		for (; !cur.isEmpty(); ++i) {
			ArrayList<Board> next = new ArrayList<Board>();
			for (Board b : cur) {
				if (b.h == finish) return i;
				for (int j = 1; j < 32; ++j) {
					if (b.f[j] == INF && (b.f[j - 1] & 7) != 7) {
						Board created = new Board(b, j);
						if (hashes.contains(created.h)) continue;
						hashes.add(created.h);
						next.add(created);
					}
				}
			}
			cur = next;
		}
		return -1;
	}

	static class Board {
		int[] f;
		long h;

		Board() {
			f = new int[32];
			for (int i = 0; i < 4; ++i) {
				for (int j = 1; j <= 7; ++j) {
					int v = sc.nextInt();
					int suit = v / 10 - 1;
					int num = v % 10;
					int card = suit * 8 + num;
					if (num == 1) {
						f[i * 8 + j] = INF;
						f[suit * 8] = card;
					} else {
						f[i * 8 + j] = card;
						h ^= hash[i * 8 + j][card];
					}
				}
			}
		}

		Board(Board orig, int pos) {
			this.f = orig.f.clone();
			this.h = orig.h;
			for (int i = 0; i < 32; ++i) {
				if (orig.f[i] == orig.f[pos - 1] + 1) {
					this.f[i] = INF;
					this.h ^= hash[i][orig.f[pos - 1] + 1];
				}
			}
			this.f[pos] = orig.f[pos - 1] + 1;
			this.h ^= hash[pos][orig.f[pos - 1] + 1];
		}
	}
}

Measured memory_bytes: 90216
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1073741824
#pragma GCC optimization ("O3")
using namespace std;
int main()
{
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long long int n,c = 0;
    cin >> n;
    if (n%2 != 0)
    {
        cout << 0;
        return 0;
    }
    n = n/2;
    for(long long int i=5;n/i>=1;i*=5)
    {
      c+=(n/i);
    }
    cout << c;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[5];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>x>>y;

    A[1] = 300000;
    A[2] = 200000;
    A[3] = 100000;

    if(x==1&&y==1){
        cout<<"1000000\n";
        return 0;
    }

    if(x<=3&&y<=3){
        cout<<A[x]+A[y]<<"\n";
        return 0;
    }
    else if(x<=3){
        cout<<A[x]<<"\n";
        return 0;
    }
    else if(y<=3){
        cout<<A[y]<<"\n";
        return 0;
    }
    else cout<<0<<"\n";

    return 0;
}


Measured memory_bytes: 256
#表計算を行うプログラムを作成。

r,c=gets.split(" ").map(&:to_i)
h = Array.new(r+1).map{Array.new(c+1,0)} 

for i in 0..r-1                                       # 変数 i を1からr-1まで増やして繰り返し処理する。(arrayゼロから始めるから)
    
a= gets.split.map(&:to_i)
    for j in 0..c-1                                   # 変数 i を0からc-1回まで増やして繰り返し処理する。
    h[i][j] =  a[j]                                   # array のループひとつづつ足していく
    h[i][c] += a[j]
    h[r][j] += a[j]
    h[r][c] += a[j]
    end
end
for i in 0..r                                       #本ループをくりかえす   row 
    for j in 0..c                                   #本ループをくりかえす   column
      print " " unless j == 0
      print h[i][j]                                 #全体結果
    end
    puts                                            #段落あける
  end




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

int a[300000];
int d[300000];
int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    if (n == 0)
        cout<<"0";
    else{
	
	    d[1] = a[1];  
	    int len = 1;
	    for (int i = 2; i <= n; i++){
	        if (a[i] <= d[len])
				d[++len] = a[i];   
	        else{
	            int j = upper_bound(d + 1, d + len + 1, a[i]) - d;  
	            d[j] = a[i];
	        }
	    }
	    cout<<len;
	}
}

Measured memory_bytes: 1792
#pragma region Macros
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define IN(x, a, b) x >= a and x < b

using namespace std;
using ll = long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> constexpr T INF = numeric_limits<T>::max() / 2;
#pragma endregion

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

  int A, B;
  cin >> A >> B;
  cout << max(0, A - B * 2) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int n,m,a,b,i;bool s[200005],t[200005];
int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++){
		scanf("%d%d",&a,&b);
		if(a==1) s[b]=1;
		if(b==n) t[a]=1;
	}
	for(i=2;i<n;i++)
		if(s[i]&&t[i]){
			printf("POSSIBLE\n");
			return 0;
		}
	printf("IMPOSSIBLE\n");
	return 0;
}

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

int main() {
int n;
int a[100];
int b[100] ={0};
int c=0;
cin >> n;
for(int i=0;i<n;i++){
    cin >> a[i];
    b[a[i]-1]++;
}
for(int i=0;i<100;i++){
    if(b[i]>0){
        c+=1;
    }
}

cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
AC, BC, MC = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
M = [tuple(map(int, input().split())) for _ in range(MC)]

ans = min(A) + min(B)
for x, y, c in M:
    ans = min(ans, A[x - 1] + B[y - 1] - c)
print(ans)

Measured memory_bytes: 29556
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <math.h>
#include <ctype.h>

int main(void) {

    char a;
    scanf("%s", &a);

    if ((isupper(a) == 0)&&(islower(a) != 0)){
        printf("a\n");
    } else if ((isupper(a) != 0)&&(islower(a) == 0)){
        printf("A\n");
    } else {
        return -1;
    }
    
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int k,s;
	cin >> k >> s;
	int ct=0;
	REP(i,k+1){
		REP(j,k+1){
			int z = s - i - j;
			if(z >= 0 && z <= k)ct++;
		}
	}
		cout << ct << endl;

  return 0;
}


Measured memory_bytes: 256
import math
N = int(input())
x=0
t=0
n=0
pre_t=1
pre_n=1
for i in range(N):
    t,n = map(int,input().split())
    if(pre_t > t or pre_n > n):
        mul = max(-(-pre_t//t),-(-pre_n//n))
        t *= mul
        n *= mul
    pre_t = t
    pre_n = n
    x = t+n
print(x)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

inline void deb(int n)
{
    cout << "deb" << n << endl;
}
int main()
{
    string s, t;
    cin >> s >> t;

    int slen = s.length (), tlen = t.length();
    string tmp;
    int fi = -1;
    for (int i = 0; i <= slen - tlen; i++) {
        bool f = true;
        for (int j = 0; j < tlen; j++) {
            if (s[i + j] == t[j] or s[i + j] == '?') continue;
            f = false; break;
        }
        if (f) fi = i;
    }

    if (fi < 0) return cout << "UNRESTORABLE" << endl, 0;

    for (int i = 0; i < slen; i++) {
        if (i == fi) {
            cout << t;
            i += tlen - 1;
            continue;
        }
        if (s[i] == '?') cout << "a";
        else cout << s[i];
    }
    cout << endl;

    return 0;
}


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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair

using namespace std;

using uint=unsigned int;
using ll=long long;

uint xor128(){
	static uint d[]={1145141919,1919810893,810893364,364114514};
	uint t=d[0]^(d[0]<<11);
	REP(i,3)
		d[i]=d[i+1];
	return d[3]=d[3]^(d[3]>>19)^(t^(t>>8));
}

struct Node{
	Node *l,*r;
	uint pri;
	int s,v,mn;
} buf[200000];

using NP=Node*;

NP newNode(int v){
	static int c=0;
	buf[c]=Node{NULL,NULL,xor128(),1,v,v};
	return &buf[c++];
}

const int inf=1145141919;

inline int Mini(NP x){
	return x?x->mn:inf;
}

inline int Size(NP x){
	return x?x->s:0;
}

inline NP Update(NP x){
	x->s=Size(x->l)+Size(x->r)+1;
	x->mn=min({x->v,Mini(x->l),Mini(x->r)});
	return x;
}

inline NP LinkL(NP x,NP l){
	x->l=l;
	return Update(x);
}

inline NP LinkR(NP x,NP r){
	x->r=r;
	return Update(x);
}

inline NP CutL(NP x){
	x->l=NULL;
	x->s=1;
	x->mn=x->v;
	if(x->r){
		x->s+=x->r->s;
		x->mn=x->mn<x->r->mn?x->mn:x->r->mn;
	}
	return x;
}

inline NP CutR(NP x){
	x->r=NULL;
	x->s=1;
	x->mn=x->v;
	if(x->l){
		x->s+=x->l->s;
		x->mn=x->mn<x->l->mn?x->mn:x->l->mn;
	}
	return x;
}

inline NP Merge(NP a,NP b){
	if(!a)
		return b;
	else if(!b)
		return a;
	else if(a->pri>b->pri)
		return LinkR(a,Merge(a->r,b));
	else
		return LinkL(b,Merge(a,b->l));
}

using Res=Node;

inline Res Split(NP x,int k){
	if(k<=0)
		return Res{NULL,x};
	else if(x->s<=k)
		return Res{x,NULL};
	else if(k<=Size(x->l)){
		Res s=Split(x->l,k);
		return Res{s.l,Merge(s.r,CutL(x))};
	}else{
		Res s=Split(x->r,k-Size(x->l)-1);
		return Res{Merge(CutR(x),s.l),s.r};
	}
}

inline void Set(NP x,int k,int v){
	int ls=Size(x->l);
	if(k<ls)
		Set(x->l,k,v);
	else if(k==ls)
		x->v=v;
	else
		Set(x->r,k-ls-1,v);
	Update(x);
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

NP t[200000];

int main(){
	int n=read(),q=read();
	REP(i,n)
		t[i]=newNode(read());
	while(n>1){
		int k=n/2;
		REP(i,k)
			t[i]=Merge(t[i*2],t[i*2+1]);
		if(k*2<n)
			t[k]=t[k*2];
		n=(n+1)/2;
	}
	NP root=t[0];
	REP(_,q){
		int x=read(),y=read(),z=read();
		if(x==0){
			Res s1=Split(root,y);
			Res s2=Split(s1.r,z+1-y-1);
			Res s3=Split(s2.r,1);
			root=Merge(Merge(s1.l,s3.l),Merge(s2.l,s3.r));
		}else if(x==1){
			Res s1=Split(root,y);
			Res s2=Split(s1.r,z+1-y);
			printf("%d\n",Mini(s2.l));
			root=Merge(s1.l,Merge(s2.l,s2.r));
		}else if(x==2){
			Set(root,y,z);
		}
	}
}

Measured memory_bytes: 11044
n, k = map(int,input().split())

if k % 2 == 1:
    x = 0
    for i in range(1,n+1):
        if i % k == 0:
            x += 1
    print(x**3)
else:
    x = 0
    for i in range(1,n+1):
        if i % k == 0:
            x += 1
    y = 0
    for i in range(1,n+1):
        if i % k == k//2:
            y += 1
    print(x**3 + y**3)

Measured memory_bytes: 8956
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.Scanner;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            int n = Integer.parseInt(sc.nextLine());
            int[][] m = new int[n][n];
            while (sc.hasNext()) {
                int[] u_k_vs = Stream.of(sc.nextLine().split(" "))
                        .mapToInt(Integer::parseInt)
                        .toArray();
                for (int i = 2; i < u_k_vs.length; i++) {
                    m[u_k_vs[0] - 1][u_k_vs[i] - 1] = 1;
                }
            }
            bfs(n, 0, m);
        } catch (NoSuchElementException
                | NumberFormatException e) {
            System.out.println(e);
        }
    }

    private static void bfs(int n, int start, int[][] m) {
        Queue<Integer> q = new ArrayBlockingQueue<>(n);
        q.add(start);
        int[] d = new int[n];
        Arrays.fill(d, -1);
        d[start] = 0;
        while (!q.isEmpty()) {
            int u = q.remove();
            for (int i = 0; i < n; i++) {
                if (m[u][i] == 0) {
                    continue;
                }
                if (d[i] != -1) {
                    continue;
                }
                d[i] = d[u] + 1;
                q.add(i);
            }
        }
        for (int i = 0; i < n; i++) {
            System.out.println((i + 1) + " " + d[i]);
        }
    }
}



Measured memory_bytes: 32404
#include<bits/stdc++.h>
using namespace std;
int a[100001];
clock_t start,end;
int main(){	
	int n;
	cin>>n;	
	while (n--)
	{
	    int t;
		 scanf("%d",&t);
		 a[t]++;
	 } 
	 int max=1;
	for (int i=0;i<100001-2;i++)
	   if (max<a[i]+a[i+1]+a[i+2])
	      max=a[i]+a[i+1]+a[i+2];
    cout<<max<<endl;
   return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class260
    {
        static void Main()
        {
            var NM = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int N = NM[0];
            int M = NM[1];
            var p = Console.ReadLine().Split().Select(x=>int.Parse(x)-1).ToList();
            var union = new Union_Find(N);
            for(int i = 0; i < M; i++)
            {
                var r = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                union.Unite(r[0] - 1, r[1] - 1);
            }
            int count = 0;
            for(int i = 0; i < N; i++)
            {
                if (union.IsSameGroup(i, p[i]))count++;
            }
            Console.WriteLine(count);
        }
    }
    public class Union_Find
    {
        private int[] data;
        public Union_Find(int size)
        {
            data = new int[size];
            for (int i = 0; i < size; i++) data[i] = -1;
        }
        public bool Unite(int x, int y)
        {
            x = Root(x);
            y = Root(y);
            if (x != y)
            {
                if (data[y] < data[x])
                {
                    var tmp = y;
                    y = x;
                    x = tmp;
                }
                data[x] += data[y];
                data[y] = x;
            }
            return x != y;
        }
        public bool IsSameGroup(int x, int y) => Root(x) == Root(y);
        public int Root(int x) => data[x] < 0 ? x : data[x] = Root(data[x]);
        public int getMem(int x) => -data[Root(x)];
    }
}


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


int main()
{
    char s[30] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

    int H,W;
    string S[30][30]={};

    cin>>H>>W;

    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin >>S[i][j];

            if(S[i][j]=="snuke"){
                int temp =j-1;
                cout << s[temp]<<i<<endl;
                return 0;
            }


        }
    }

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      final var n = Integer.parseInt(br.readLine());

      var sum = 0L;
      for (int i = 1; i < n; i++) {
        sum += (n - 1) / i;
      }

      System.out.println(sum);
    }
  }
}


Measured memory_bytes: 32616
import sys
input = sys.stdin.readline
N = int(input())
c2 = [int(input()) for _ in range(N)]
mod = 10**9+7
#圧縮
c = [c2[0]-1]
n = N
for i in range(1,N):
    if c2[i] == c2[i-1]:
        n -= 1
        continue
    c.append(c2[i]-1)

#used[i]:色iが最後に登場したindex
#初期値:-1
used = [-1]*(max(c)+1)
used[c[0]] = 0
#dp[i]:i番目まででの場合の数
dp = [0]*n
dp[0] = 1
for i in range(1,n):
    if used[c[i]] == -1:
        dp[i] = dp[i-1]
    else:
        dp[i] = (dp[i-1]+dp[used[c[i]]])%mod
    used[c[i]] = i

print(dp[-1])

Measured memory_bytes: 28408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
const ll C = 1e9+7; //10の9乗

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

    for(int i=1; i<=X; i++) {
        if((i*(i+1))/2 >= X) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
    vector<vector<char>> A(N,vector<char>(N)),B(M,vector<char>(M));
 for(int i=0;i<N;i++){
   for(int j=0;j<N;j++){
   cin>>A.at(i).at(j);
   }
      }
   for(int i=0;i<M;i++){
   for(int j=0;j<M;j++){
    cin>>B.at(i).at(j);
  }
   }
  bool ans=false;
  for(int i=0;i<N-M+1;i++){
    for(int j=0;j<N-M+1;j++){
      bool check=true;
      for(int k=0;k<M;k++){
        for(int l=0;l<M;l++){
          if(A.at(i+k).at(j+l)!=B.at(k).at(l)){
            check=false;
            break;
          }
        }
        if(!check){
          break;
        }
      }
      if(check){
        cout<<"Yes"<<endl;
        ans=true;
        break;
      }
    }
    if(ans) break;
  }
   if(!ans) cout<<"No"<<endl;
 }

Measured memory_bytes: 256
//
//  main.cpp
//  atcoderlcs
//
//  Created by r on 5/23/19.
//  Copyright © 2019 r. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
using namespace std;

//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007

string s, t;
int dp[3010][3010];
pair<int, int> p[3010][3010];

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> s >> t;
    p[1][1] = {numeric_limits<int>::min(), numeric_limits<int>::min()};
    for (int i = 1; i<=s.length(); i++) {
        for (int j = 1; j<=t.length(); j++) {
            if (s[i-1] == t[j-1]) {
                if (dp[i][j]<dp[i-1][j-1]+1) {
                    dp[i][j] = 1+dp[i-1][j-1];
                    p[i][j] = {i-1, j-1};
                }
            }
            if (dp[i][j]<dp[i-1][j]) {
                dp[i][j] = dp[i-1][j];
                p[i][j] = {i-1, j};
            }
            if (dp[i][j]<dp[i][j-1]) {
                dp[i][j] = dp[i][j-1];
                p[i][j] = {i, j-1};
            }
        }
    }
    string ans = "";
    pair<int, int> curr = {s.length(), t.length()};
    while (curr != make_pair(0, 0) && curr != make_pair(numeric_limits<int>::min(), numeric_limits<int>::min())) {
        if (p[curr.first][curr.second] == make_pair(curr.first-1, curr.second-1)) {
            ans+=s[curr.first-1];
        }
        curr = p[curr.first][curr.second];
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 106368
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

string a[]={"Sunny","Cloudy","Rainy"}; 
int main(){
    string s;
    cin>>s;
    if(s==a[0])cout<<a[1]<<endl;
    if(s==a[1])cout<<a[2]<<endl;
    if(s==a[2])cout<<a[0]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
#include<map>
#include<iostream>
#include<algorithm>
#define m(a,b) memset(a,b,sizeof(a));
using namespace std;
typedef long long LL;
typedef pair<int,int>PII;
const int inf = 1 << 30;
const int maxn = 1e5;
map<int,int>mp;
map<int,int>::iterator it;
int ans = 0;
int num[5] = {0};
bool check(int x){
	int k = 0;
	while(x){
		num[k++] = x%10;
		x/=10;
	}
	if(num[0]==num[4]&&num[1] == num[3]) return true;
	return false;
}
int main(){
	int n,m;
	cin >> n >> m;
	for(int i = n;i<=m;i++){
		if(check(i))
			ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
	string s1,s2;cin>>s1>>s2;
  	set<char> s;
  	int count=0;
  	for(int i=0;i<s1.length();i++)
    {
    	if(s1[i]!=s2[i]){
        	count++;
        }
    }
  	cout << count << endl;
}


Measured memory_bytes: 3916
import java.io.*;
import java.util.Scanner;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int[] a = new int[3];
		int[] b = new int[3];
		for (int i = 0; i < 3; i++) {
			a[i] = sc.nextInt() - 1;
			b[i] = sc.nextInt() - 1;
		}

		int[] cnt = new int[4];
		for (int i = 0; i < 3; i++) {
			cnt[a[i]]++;
			cnt[b[i]]++;
		}
		
		for (int i = 0; i < 4; i++) {
			if (cnt[i] > 2) {
				pr.println("NO");
				return;
			}
		}
		
		pr.println("YES");
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 21716
n=int(input())
hoge=[]
no=0

a=input()
hoge.append(a)
saigo=a[-1]

for i in range(n-1):
  a=input()
  hoge.append(a)
  if(hoge.count(a)>1):
    no=1
    break
  if(saigo==a[0]):
    saigo=a[-1]
  else:
    no=1
    break
  
if(no==0):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
N, M = map(int, input().split())
p_S = [input().split() for _ in range(M)]
 
AC = [False]*N
WA = [0]*N
 
# i番目の提出において、
# (1) まだACされておらず、提出がWAだった場合：WA += 1
# (2) まだACされておらず、提出がACだった場合：AC += 1 
# (3) すでにACされている場合：何もしない
for i in range(M):    
  num = int(p_S[i][0])-1
  if AC[num] == 0 and p_S[i][1] == 'WA': WA[num] += 1
  elif AC[num] == 0 and p_S[i][1] == 'AC': AC[num] = True
  else: continue

# ACを出した各問題において、初めてACを出すまでに出したWAの数の和を求める
s = 0
for i in range(N):
  if AC[i]:
    s += WA[i]
    
print(sum(AC), s)

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

using namespace std;

const int HUGEI = 2147483647;  // (1 << 31) - 1
const long long HUGEL = 9223372036854775807;  // (1 << 63) - 1
const string ABC = "abcdefghijklmnopqrstuvwxyz";

const long long MOD = 1000000007;
const int MAX = 100001;
long long fact[MAX];

void init_fact() {
    fact[0] = 1;
    for (int i = 1; i < MAX; i++) {
        fact[i] = fact[i - 1] * i % MOD;
    }
}

int main(void) {
    long long n, m;
    cin >> n >> m;
    init_fact();
    if (n == m) {
        long long res = 2 * fact[n] % MOD;
        res = res * fact[m] % MOD;
        cout << res << endl;
    } else if (abs(n - m) == 1) {
        long long res = fact[n] * fact[m] % MOD;
        cout << res << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <limits>
#include <cstdlib>
#include <regex>
using namespace std;

double inf = numeric_limits<double>::infinity();

#define REP(i,n) for(int i=0;i<n;i++)
using LL = long long int;
LL GCD(LL a,LL b){ if(a<b) return GCD(b,a); else if(a%b==0) return b; else return GCD(b,a%b); }
LL LCM(LL a,LL b){ return (a/GCD(a,b))*b; }


int main() {
    string s;
    cin >> s;
    int cnt = 0;
    REP(i,6) {
        if (s[i] == '1') cnt++;
    }
    
    cout << cnt << endl;
}


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

// 小数点以下桁数
// fixed << setprecision(i)

int gcd(int a,int b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int a,int b){return (int64_t)a*b/gcd(a, b);}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//   for(auto x : v) cout << x << " "; cout << "\n";    // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }

int main()
{
  int x;
  cin >> x;
  cout << (x >= 30 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }

int main() {
	string s;
	cin >> s;
	s.push_back('d');
	int n = s.size();
	bool con = false;
	int sa = 0;
	ll res = 0;
	REP(i, n) {
		if (con) {
			if (s[i] == 'A') {
				sa++;
			}
			else if (s[i] == 'B') {
				if (s[i + 1] == 'C') {
					res += sa;
					i++;
				}
				else {
					con = false;
					sa = 0;
				}
			}
			else {
				con = false;
				sa = 0;
			}
		}
		else {
			if (s[i] == 'A') {
				con = true;
				sa = 1;
			}
		}
	}
	put(res);
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
signed main(){
    string s;
    cin>>s;
    long long sum=0;
    for(int i=0;i<s.size();i++){
        sum+=s[i]-'0';
    }
    if(sum%9==0){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return(0);
}

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

int main() {
	// your code goes here
	int n;
  	string s,t;
	cin>>n>>s>>t;
	
  	string ans="";
  for(int i=0;i<n;i++){
  ans+=s[i];
  ans+=t[i]; 
  }
  cout<<ans<<endl;	
  	return 0;
}

Measured memory_bytes: 256
import math

N, D = map(int, input().strip().split())

X = []

for i in range(N):
  X.append(list(map(int, input().strip().split())))

count = 0
for i in range(N):
  p1 = X[i]
  for j in range(i + 1, N):
    p2 = X[j]

    total = 0
    for k in range(D):
      total += abs(pow(p1[k] - p2[k], 2))

    total = math.sqrt(total)
    if total == int(total):
      count += 1

print(count)

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
	int a,b;
	while(1){
		scanf("%d %d", &a, &b);
		if(a==0 && b==0)break;
		if(b < a){
			int tmp = a;
			a = b;
			b = tmp;
		}
		printf("%d %d\n", a, b);
	}
	return 0;
}

Measured memory_bytes: 2656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  ll n, a, b;
  cin >> n >> a >> b;

  ll dist = abs(a - b);
  bool isEven = dist % 2 == 0;

  ll ans;
  if (isEven) {
    ans = dist / 2;
  } else {
    ans = min(a - 1, n - b) + (b - a - 1) / 2 + 1;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256