akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n;
string str;

int main(){
	cin >> n;
	
	ll ans = 0;
	ll cnt = 0;
	ll cnta = 0;
	ll cntb = 0;
	for(ll i = 1; i <= n; i++){
		cin >> str;
		for(ll j = 1; j < str.size(); j++){
			if(str[j-1] == 'A' && str[j] == 'B'){ans++;}
		}
		if(str[0] == 'B' && str[str.size()-1] == 'A'){cnt++;}
		else{
			if(str[str.size()-1] == 'A'){cnta++;}
			if(str[0] == 'B'){cntb++;}
		}
	}

	ans += cnt + min(cnta, cntb);
	if(cnt > 0 && cnta == 0 && cntb == 0){ans--;}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int a = 0, b = 0, e;
	string s;
	cin >> s;
	for (int h = 0; h < s.size(); h++) {
		if (s[h] == 'A' && a == 0) {
			a++;
		}
		if (a > 0) {
			a++;
		}
		if (a > 0 && s[h] == 'Z') {
			b = max(a, b);
		}
	}
	cout << b - 1 << endl;
	cin >> e;
}

Measured memory_bytes: 640
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;



void solve()
{
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    int i;
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a.begin(), a.end());
    int diff = a[n-1]-a[0];
    if (diff > 1) {
        printf("No\n");
    }
    else if (diff == 1) {
        int cnt = 0;
        for (i = 0; i < n; i++) {
            if (a[0] == a[i]) cnt++;
        }
        if (n-cnt >= (a[n - 1] - cnt) * 2 && (a[n - 1] - cnt) > 0) {
            printf("Yes\n");
        }
        else {
            printf("No\n");
        }
    }
    else {
        if (a[0] == n - 1) {
            printf("Yes\n");
        }
        else if (n >= a[0] * 2) {
            printf("Yes\n");
        }
        else {
            printf("No\n");
        }
    }

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 640
N,A,B,C = map(int,input().split())
l = []
for i in range(N):
  l.append(int(input()))
l.sort()

def tots(X, n):
    if (int(X/n)):
        return tots(int(X/n), n)+str(X%n)
    return str(X%n)

tnum = 0
ans = float("inf")
target = [A,B,C]
for i in range(4**N):
  #N本の竹の行き先の振り分け
  wake = [[],[],[],[]]
  ts = "0"*(N-len(tots(i,4)))+tots(i,4)
  for j in range(N):
    wake[int(ts[j])].append(l[j])
  if 0 == len(wake[0]) or 0 == len(wake[1]) or 0 == len(wake[2]):
    continue 
  #合成して行き先との長さの差をたしわせる
  c = 0
  for j in range(3):
    c +=abs(target[j] - sum(wake[j]))      
  tnum = len(wake[0])+len(wake[1])+len(wake[2])
  ans = min(ans,c+10*(tnum-3))  

if A in l and B in l and C in l:
  ans = 0
print(ans)  

Measured memory_bytes: 3064
import numpy as np
N, W = map(int, input().split())

items = [tuple(map(int, input().split())) for _ in range(N)]

dp = np.full(N*1000 +1, W+1) #横軸を価値の値に変換する
dp[0] = 0

for i, (w, v) in enumerate(items):
    dp[v:] = np.minimum(dp[v:], dp[:-v]+w)

print(np.max(np.where(dp <= W)))


Measured memory_bytes: 14908
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  string s;
  cin >> s;
  int n = sz(s);
  ll res = 0;
  ll sumb = 0;
  rep(i,n) {
    if (s[i] == 'W') res += sumb;
    else sumb++;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 640
H = int(input())

ans = H
cnt = 1

def attack(h, ans, cnt):
    if h==1:
        return(ans)
    else:
        if h%2==0:
            ans += (1*cnt)
        h = h//2
        cnt *= 2
        return attack(h, ans, cnt)

ans = attack(H, ans, cnt)

print(ans)

Measured memory_bytes: 3060
import 'dart:io';

void main() {
  int n = int.parse(stdin.readLineSync());
  List lList =
      stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  List lList1 = lList..sort((a, b) => a.compareTo(b));

  int count;
  count = 0;

  for (int a = 0; a < n; a++) {
    for (int b = a + 1; b < n; b++) {
      for (int c = b + 1; c < n; c++) {
        if (lList1[a] != lList1[b] && lList1[b] != lList1[c]) {
          if (lList1[a] + lList1[b] > lList1[c]) {
            count++;
          }
        }
      }
    }
  }
  int ans = count;
  print(ans);
}

Measured memory_bytes: 13248
n=int(input())

tuples=[]

for _ in range(n):
    obj=input().split(" ")
    obj[0]=int(obj[0])
    obj[1]=int(obj[1])
    obj[3]=int(obj[3])
    tuples.append(obj)

tuples=sorted(tuples)

for t in tuples:
    print(t[0],t[1],t[2],t[3],t[4])



Measured memory_bytes: 39268
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

ull n;

int main() {
    fastio();

    cin >> n;

    if (n % 2) {
        cout << 0 << endl;
    } else {
        ull c = 0, c5 = 0;

        for (ull d = 50; d <= n; d *= 5) {
            c5 += n / d;
        }
        cout << c5 + n / 10 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define per(i,x,y) for (int i=(x); i>=(y); i--)
#define ll long long
#define ld long double
#define inf 1000000000
#define INF 1000000000000000000ll
#define pii pair<int,int>
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define sqr(x) ((x)*(x))
#define cmin(x,y) (x)=(((y)<(x))?(y):(x))
#define cmax(x,y) (x)=(((y)>(x))?(y):(x))
using namespace std;
const ld pi=acos(-1);
const ld eps=1e-8;
//////////////////////// header files ////////////////////////
ll read(){
	char ch=getchar(); ll x=0; int op=1;
	for (; !isdigit(ch); ch=getchar()) if (ch=='-') op=-1;
	for (; isdigit(ch); ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
void write(ll a){
	if (a<0) putchar('-'),a=-a;
	if (a>=10) write(a/10); putchar(a%10+'0');
}
////////////////////////// fast i/o //////////////////////////
#define N 505
int A,B,a[N][N],n,m,x,y;
//#define local
int main(){
#ifdef local
	freopen("test.in","r",stdin); freopen("test.out","w",stdout);
#endif
	A=read()-1,B=read()-1;
	n=100,m=100; cout<<"100 100\n";
	rep (i,1,n) rep (j,1,50) a[i][j]=0;//黑
	rep (i,1,n) rep (j,51,m) a[i][j]=1;//白
	x=1,y=1;
	while (A--){
		a[x][y]=1; y+=2; if (y>50) x+=2,y=1;
	}
	x=1,y=52;
	while (B--){
		a[x][y]=0; y+=2; if (y>m) x+=2,y=52;
	}
	rep (i,1,n){ rep (j,1,m) cout<<(a[i][j]?'.':'#'); cout<<endl; }
	return 0;
}
//sample data:
/*
2 3

7 8

1 1

3 14
*/

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

int main() {
    int n; cin >> n;
    vector<long long> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    long long all = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            all += d[i] * d[j];
        }
    }
    cout << all << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        while (true) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            
            if (x == 0 && y == 0) { break; }
            
            // if (x > y) {
            //     System.out.println(y + " " + x);
            // } else {
            //     System.out.println(x + " " + y);
            // }
            System.out.println( (x < y) ? (x + " " + y) : (y + " " + x) );
            
        }
        
    }
}


Measured memory_bytes: 36536
X=int(input())
if X>=400 and X<=599:
    print("8")
elif X>=600 and X<=799:
    print("7")
elif X>=800 and X<=999:
    print("6")
elif X>=1000 and X<=1199:
    print("5")
elif X>=1200 and X<=1399:
    print("4")
elif X>=1400 and X<=1599:
    print("3")
elif X>=1600 and X<=1799:
    print("2")
elif X>=1800 and X<=1999:
    print("1")

Measured memory_bytes: 9204
package main

import (
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	const m int = 1e9 + 7
	pow := func(x, n int) int {
		res := 1
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % m
			}
			x = x * x % m
		}
		return res
	}
	var n, k, s int
	Fscan(_r, &n, &k)
	ans := make([]int, k+1)
	for i := k; i > 0; i-- {
		v := pow(k/i, n)
		for j := 2 * i; j <= k; j += i {
			v -= ans[j]
		}
		ans[i] = v % m
		s += i * ans[i]
	}
	Fprint(_w, (s%m+m)%m)
}

func main() { run(os.Stdin, os.Stdout) }


Measured memory_bytes: 2592
string = gets.chomp

# { "A" => ["A", "A"], "S" => ["S", "S"] } => [2, 2]
result = string.split(//)
          .group_by { |e| e }
          .map { |k,v| v.size }
          .all? { |e| e == 2 }

puts result ? 'Yes' : 'No'

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
ll inf = 100000000;
typedef pair<ll, ll> P;
int main() {
	int n, m;
	cin >> n >> m;
	P p[25];
	for (int i = 0; i < m; i++) {
		cin >> p[i].first>>p[i].second;
	}
	for (int i = 0; i < 1000; i++) {
		int keta = 1;
		vector<int>b(1,i%10);
		int x = i / 10;
		while (x) {
			keta++;
			b.push_back(x % 10);
			x = x / 10;
		}
		if (keta != n) {
			continue;
		}
		reverse(b.begin(), b.end());
		bool ok = true;
		for (int j = 0; j < m; j++) {
			if (b[p[j].first - 1] != p[j].second) {
				ok = false;
			}
		}
		if (ok) {
			cout << i << endl;
			return 0;
		}

	}
	cout << "-1" << endl;
	return 0;
}


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

int main()
{
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int tmp;
    cin >> tmp;
    if (tmp % 2 == 0 && tmp % 3 != 0 && tmp % 5 != 0)
    {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline

def main():
    while True:
        a, b = map(int, input().split())
        if a==0 and b ==0:
            sys.exit()
        s = range(1, a+1)
        count = 0
        kumi = [[0,0,0]]
        for i in s:
            for k in s:
                for j in s:
                    if i + k + j == b and i != k and k != j and i != j:
                        flag = True
                        for ku in kumi:
                            if i in ku and k in ku and j in ku:
                                flag = False
                                break
                        if flag:
                            kumi.append([i,k,j])
                            count += 1
        print(count)
    
if __name__ == "__main__":
    main()
    


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
#define PI 3.14159265358979323846
ll power(ll a, ll b){ll res=1;a=a%mod; while(b){if(b&1)res=(res*a)%mod; a=(a*a)%mod;b/=2;}return res;}
ll invmod(ll a){return power(a,mod-2);}

int main(void)
{
	FIO	
	long double r;
	cin>>r;
	r=6.28318*r;
	cout<<r<<"\n";
	return 0;
}

Measured memory_bytes: 3808
#include <iostream>
#include <cstdlib>

using namespace std;
int main()
{
  long long int k,a,b;
  cin >>k;
  cin >>a;
  cin >>b;
  long long int bis = 1;
  if((b-a) < 2){
    bis = bis + k;
  }else{
    while(1){
      if(k == 0){
        break;
      }else if(k == 1){
        bis++;
        break;
      }else if(a + 2 <= bis + k){
        k = k - (a - bis);
        bis = a;
        bis = bis +(k/2)*(b-a);
        k = k%2;
      if(k == 0){
        break;
      }else if(k == 1){
        bis++;
        break;
      }
      }else{
        bis = bis + k;
        break;
      }
   }
  }
  cout << bis << endl;
  }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>
#include <algorithm>
#define llint long long
#define eps 1e-9

using namespace std;
typedef pair<double, llint> P;
typedef pair<P, P> S;

struct vec2d{
	double x, y;
	vec2d(){}
	vec2d(double x, double y){
		this->x = x, this->y = y;
	}
	double add(double a, double b){
		if(fabs(a+b) < eps * (fabs(a)+fabs(b))) return 0.0;
		return a+b;
	}
	vec2d operator+(vec2d ope){
		return vec2d(add(x, ope.x), add(y, ope.y));
	}
	vec2d operator-(vec2d ope){
		return vec2d(add(x, -ope.x), add(y, -ope.y));
	}
	vec2d operator*(double t){
		return vec2d(x*t, y*t);
	}
	vec2d operator/(double t){
		return vec2d(x/t, y/t);
	}
	double dot(vec2d ope){
		return add(x*ope.x, y*ope.y);
	}
	double cross(vec2d ope){
		return add(x*ope.y, -y*ope.x);
	}
};

bool isOnS(vec2d p, vec2d q, vec2d x)
{	
	return (p-x).cross(q-x) == 0 && (p-x).dot(q-x) <= 0;
}
bool isCrossSS(vec2d p, vec2d q, vec2d r, vec2d s, double &t)
{
	if((q-p).cross(s-r) == 0){
		return isOnS(p, q, r) || isOnS(p, q, s) || isOnS(r, s, p) || isOnS(r, s, q);
	}
	t = (r-p).cross(s-r) / (q-p).cross(s-r);
	vec2d x = p + (q-p)*t;
	return isOnS(p, q, x) && isOnS(r, s, x);
}

llint T;
llint n;
vec2d s, t;
llint l[105], o[105];
vec2d p[105], q[105];
vector<pair<double, llint> > vec;

int main(void)
{
	cin >> T;
	for(int z = 0; z < T; z++){
		cin >> s.x >> s.y >> t.x >> t.y;
		cin >> n;
		for(int i = 1; i <= n; i++){
			cin >> p[i].x >> p[i].y >> q[i].x >> q[i].y >> o[i] >> l[i];
			if(o[i] == 0) l[i] = 1 - l[i];
		}
		
		vec.clear();
		for(int i = 1; i <= n; i++){
			double a;
			if(isCrossSS(s, t, p[i], q[i], a)) vec.push_back(P(a, l[i]));
		}
		sort(vec.begin(), vec.end());
		
		///for(int i = 0; i < vec.size(); i++) cout << vec[i].first << " " << vec[i].second << endl;
		
		llint ans = 0;
		for(int i = 1; i < vec.size(); i++){
			if(vec[i].second != vec[i-1].second) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3156
class dice:
    def __init__(self, pip):
        self.pip = pip
        
    def move(self,dir):
        if str(dir) == "E":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[3],self.pip[0],self.pip[5],self.pip[2]
        elif str(dir) == "W":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[2],self.pip[5],self.pip[0],self.pip[3]
        elif str(dir) == "N":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[1],self.pip[5],self.pip[0],self.pip[4]
        elif str(dir) == "S":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[4],self.pip[0],self.pip[5],self.pip[1]

d = dice(list(map(int,input().split())))
n = int(input())

for i in range(n):
    
    top, front = map(int,input().split())
    
    for j in range(6):
        if d.pip[1] == front:
            break
        d.move("S")
        if j == 3:
            d.move("E")
            d.move("S")
    
    for j in range(3):
        if d.pip[0] == top:
            break
        d.move("E")
    
    print(d.pip[2])

Measured memory_bytes: 7764
#include<bits/stdc++.h>
#define INF 2000000000
#define int long long int
#define MOD 1000000007
#define pb push_back
#define cin1(n) (cin >> n)
#define cin2(a,b) (cin >> a >> b)
#define cin3(a,b,c) (cin >> a >> b >> c)
#define cout(n) (cout << n << endl)
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define fr first 
#define sc second 
#define EPS (1e-10)




using namespace std;

typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<pair<int,int>> vpii;
typedef vector<string> vs;
typedef vector<vector<string>> vss;
typedef pair<int,int> pii;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int n,m;
int a,b;
int p,q;

int half(int s,int t) {
	return s/2 + t/2;
}

signed main() {
	int c; cin3(a,b,c);

	int ans = 0;
	while(1){
		 if (a % 2 == 1 or b % 2 == 1 or c % 2 == 1) {
			cout(ans);
			return 0;
		}else if (a == b and b == c and c == a) {
			cout(-1);
			return 0;
		}
		int ha,hb,hc;
		ha = half(b,c);
		hb = half(a,c);
		hc = half(b,a);
		a = ha;
		b = hb;
		c = hc;
		ans++;
		
	}
	return 0;
}





Measured memory_bytes: 256
#include <iostream> 
#include <cstdio>
#include <vector>
#include <stdlib.h>
#include <deque>

using namespace std;

#define For(i , a , b) for (int i = a , _b = b ; i <= _b ; ++i)
#define Ford(i , a  ,b) for (int i = a , _b = b : i >= _b ; --i)
#define Rep(i , n) for (int i = 0 , _n = n ; i < _n ; ++i)
#define sz(A) ((int)A.size())
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)

typedef pair<int , int> pt;

const int maxn = 100000 + 123;
int n, m;
vector<int> V[maxn];

void ReadData() {
	cin >> n >> m;
	For(i,1,m) {
		int u, v; cin >> u >> v;
		V[u].push_back(v);
		V[v].push_back(u);
	}
}

bool was[maxn];
deque<int> d;
void Process() {
	int u;
	For(i,1,n) if (sz(V[u]) > 0) {
		u = i;
		break;
	}
	
	int z = u;
	was[u] = 1;
	d.push_back(u);
	while (true) {
		int v = -1;
		for (int x : V[z]) if (!was[x]) {
			v = x;
			break;
		}
		if (v == -1) break;
		was[v] = 1;
		d.push_front(v);
		z = v;
 	}

 	z = u;
 	while (true) {
 		int v = -1;
 		for (int x : V[z]) if (!was[x]) {
 			v = x;
 			break;
 		}
 		if (v == -1) break;
 		was[v] = 1;
 		d.push_back(v);
 		z = v;
 	}

 	cout << sz(d) << endl;
 	for (deque<int>::iterator it = d.begin(); it != d.end(); it++) cout << (*it) << " "; cout << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	//freopen("input.inp" , "r" , stdin);
	ReadData();
	Process();

	return 0;

}			

Measured memory_bytes: 6784
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    static int n, a, b, c;
    static int A,B,C;
    public static void main(String[] args) {
        while(read()){

        }
    }

    static boolean read(){
        if(!sc.hasNext())return false;
        n = sc.nextInt();
        for(int i = 0; i < n; i++){
            a = sc.nextInt();
            b = sc.nextInt();
            c = sc.nextInt();
            solve();
        }
        return true;
    }

    static void solve(){
        /*if(a == 0 || b == 0 || c == 0){
            System.out.println("NO");
        }*/

        if(a != 0 && b != 0 && c!= 0){
            A = a * a;
            B = b * b;
            C = c * c;
            if(A == B + C){
                System.out.println("YES");
            }else if(B == A + C){
                System.out.println("YES");
            }else if(C == A + B){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }


    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define mp make_pair
#define ll long long
using namespace std;

int main() {
  
   string s;
   cin>>s;
   int c=0,count[34344]={0};
   for(int i=0;i<4;i++){
       int k=s[i]-'A';
       count[k]++;
   }
   for(int i=0;i<26;i++) {
       if(count[i]==2) {
           c++;
       }
   }
   if(c==2) {
       cout<<"Yes";
       return 0;
   }
   cout<<"No";
}

Measured memory_bytes: 384
#include <cstdio>

#define MAXN 100002
int main(void)
{
	#if DEBUG
	freopen("_in","r",stdin);
	#endif
	int i,N,*bucket,x;
	bucket=new int [MAXN];
	for(i=0;i<MAXN;i++)
		bucket[i]=0;

	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%d",&x);
		bucket[x]++;
		bucket[x+2]++;
		bucket[x+1]++;
	}

	x=-1;
	for(i=0;i<MAXN;i++)
	{
		if(bucket[i]>x)
			x=bucket[i];
	}

	printf("%d\n",x);
	delete [] bucket;
	return 0;

}

Measured memory_bytes: 640
//NEVER GIVE UP I AM GOING TO IMPROVE ONE DAY.
//PRACTICE,PRACTICE,PRACTICE!!!
#include<bits/stdc++.h>
#define int long long int
// #define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1e18
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
const int M=1000000007;
const double pi = acos(-1.0);
using namespace std;
// cout<<"Case #"<<test-t<<":"<<" "<<ans<<endl;
int32_t main(){
    fast;
    int t;
    t=1;
    // cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        int i,ans=0;
        for(i=0;i<n;i++){
            cin>>a[i];
            if((i+1)%2 && a[i]%2){
                ans++;
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3508
#include<iostream>
using namespace std;struct P{float x,y;int operator-=(P&a){x-=a.x;y-=a.y;}};P A,B,C,S,G;int X(P S){C.x=(B.y*S.x-B.x*S.y)/(A.x*B.y-A.y*B.x);C.y=(A.y*S.x-A.x*S.y)/(A.y*B.x-A.x*B.y);return C.x>0&&C.y>0&&C.x+C.y<1;}main(){cin>>A.x;while(cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y>>S.x>>S.y>>G.x>>G.y){A-=C;B-=C;S-=C;G-=C;X(S)^X(G)?cout<<"OK":cout<<"NG";cout<<endl;}return 0;}

Measured memory_bytes: 940
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    s[3] = '8';
    cout << s << endl;

    return 0;
}


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

#define ll long long
#define met(a, x) memset(a,x,sizeof(a))
using namespace std;
double a[110], b[110];
const double eps = 1e-10;
int n;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    ll cnt=0;
    for(int i=1;i<=n;i++){
        ll x;
        cin>>x;
        cnt^=x;
    }
    if(cnt==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

string incl( vector<string>& A, vector<string>& B, int n, int m ) {
	bool result = false;

	for( int i = 0; i < n-m+1; ++i ) {
		for( int j = 0; j < n-m+1; ++j ) {
			bool matched = true;

			for( int p = 0; p < m; ++p ) {
				for( int q = 0; q < m; ++q ) {
					if( A[i+p][j+q] != B[p][q] ) {
						matched = false;
						break;
					}
				}

				if( !matched ) { break; }
			}

			if( matched ) {
				result = true;
				break;
			}
		}

		if( result ) { break; }
	}

	return result ? "Yes" : "No";
}

int main() {
	ios_base::sync_with_stdio( false );

	int N, M;
	cin >> N >> M;

	vector<string> A( N );
	vector<string> B( M );
	for( auto& v: A ) { cin >> v; }
	for( auto& v: B ) { cin >> v; }

	cout << incl( A, B, N, M ) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner scan = new java.util.Scanner(System.in);
		long n = scan.nextInt();
		scan.close();
		long power = 1;
		for(int i = 1; i <= n; i++) {
			power *= i;
			power = power % 1000000007;
		}
		System.out.print(power);
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>

using namespace std;

#define rep(i,n,m) for(int i=n;i<(int)(m);i++)

void sort_erase(vector<int> &num);


int dps(int start, vector<vector<bool>>& graph, vector<bool>& pass) {

	bool end=true;
	int cnt = 0;

	rep(i, 0, pass.size()) 	if (pass[i]==false)end = false;

	if (end)return 1;


	rep(i, 0, graph.size()) {

		if (graph[start][i])if (!pass[i]) {
			pass[i] = true;
			cnt += dps(i, graph, pass);
			pass[i] = false;
		}



	}

	return cnt;

}



int main() {
	
	int n, m;
	int a, b;
	
	cin >> n >> m;
	
	vector<vector<bool>>graph(n,vector<bool>(n,false));
	vector<bool>pass(n, false);
	pass[0] = true;

	rep(i, 0, m) {
		cin >> a >> b;
		graph[a-1][b-1] = true;
		graph[b-1][a-1] = true;
	}


	cout << dps(0, graph, pass) << endl;
	

	return 0;
}

void sort_erase(vector<int> &num) {
	std::sort(num.begin(), num.end());
	num.erase(std::unique(num.begin(), num.end()), num.end());
}

Measured memory_bytes: 256
#pragma GCC optimize(2)

#include "bits/stdc++.h"

using namespace std;

#define all(a) begin(a), end(a)
#define MOD 1000000007
#define PII pair<int, int>
#define complete_unique(a) a.erase(unique(begin(a), end(a)), end(a))
#define mst(x, a) memset(x, a, sizeof(x))
typedef vector<int> VI;
typedef long long ll;

ll quick_pow(ll a, ll b) {
    long long res = 1;
    while (b) {
        if (b & 1)
            res = a * res;
        a = a * a;
        b >>= 1;
    }
    return res;
}

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

bool is_prime(int n) {
    if (n == 0) return false;
    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    int j = sqrt(n);
    for (int i = 2; i <= j; ++i) {
        if (n % i == 0) return false;
    }
    return true;
}

ll reverse_num(ll n) {
    ll x = 0, t = n;
    while (t != 0) {
        x = x * 10 + t % 10;
        t /= 10;
    }
    return x;
}


const int N = 1e6 + 100;
int n, q;
int nums[N], res[N], visited[N], tree[N];
struct Query {
    int l, r;
    int pos;
} ask[N];

bool cmp(Query q1, Query q2) {
    return q1.r < q2.r;
}

int lowbit(int x) {
    return x & -x;
}

void add(int i, int val) {
    while (i <= n) {
        tree[i] += val;
        i += lowbit(i);
    }
}

int query(int r) {
    int result = 0;
    while (r) {
        result += tree[r];
        r -= lowbit(r);
    }
    return result;
}

int query(int l, int r) {
    return query(r) - query(l);
}

void solve() {
    //    freopen("C:\\Users\\26019\\Downloads\\P1195_4.in", "r", stdin);
    //    fclose(stdin);
    cin >> n >> q;
    for (int i = 1; i <= n; ++i) {
        cin >> nums[i];
    }
    for (int i = 1; i <= q; ++i) {
        cin >> ask[i].l >> ask[i].r;
        ask[i].pos = i;
    }
    sort(ask + 1, ask + 1 + q, cmp);
    int next = 1;
    for (int i = 1; i <= q; ++i) {
        for (int j = next; j <= ask[i].r; ++j) {
            if (visited[nums[j]]) {
                add(visited[nums[j]], -1);
            }
            add(j, 1);
            visited[nums[j]] = j;
        }
        next = ask[i].r + 1;
        res[ask[i].pos] = query(ask[i].l - 1, ask[i].r);
    }
    for (int i = 1; i <= q; ++i) {
        cout << res[i] << endl;
    }
}

int main() {
    // 加速输入和输出
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}



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

int main(){
    int N;
    int64_t A = 2, B = 1, C = 0;

    cin >> N;
    if(N <= 86 && N > 1){
        for(int i=1; i< N; i++){
        C = A + B;
        A = B;
        B = C;
        }
    }
    else if(N == 1){
        C = B;
    }

    cout << C << endl;
}

Measured memory_bytes: 256
#if 0



#endif // 0

#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
const int MAXN = (int) 1e5 + 10;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;

int n,k;
int w[MAXN];

bool is_judge(int x){
    int cnt=0,cur=0;
    int p=1;
    while(p<=n){
        while(p<=n){
            if(cur+w[p]>x) break;
            cur+=w[p++];
        }
        cur=0;
        cnt++;
    }
    return cnt<=k;
}

void work(){
    scanf("%d%d",&n,&k);
    int L=1,R=1000000000;
    for(int i=1;i<=n;i++){
        scanf("%d",&w[i]);
        L=max(L,w[i]);
    }
    int ans=0;
    while(L<=R){
        int mid=(L+R)>>1;
        if(is_judge(mid)){
            R=mid-1;
            ans=mid;
        }
        else{
            L=mid+1;
        }
    }
    printf("%d\n",ans);
}

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





Measured memory_bytes: 3156
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;
int main(void){
    vector <int> T,P,X;
    int n,m,sum;
    
    scanf("%d",&n);
    T.resize(n);
    for(int i=0; i<n; i++){
        scanf("%d",&T[i]);
    }
    scanf("%d",&m);
    P.resize(m);
    X.resize(m);
    for(int i=0; i<m; i++){
        scanf("%d %d",&P[i],&X[i]);
    }
    
    sum = 0;
    for(int i=0; i<T.size(); i++){
        sum += T[i];
    }
    //printf("%d\n",sum);
    for(int i=0; i<P.size(); i++){
        printf("%d\n",sum + X[i] - T[P[i] - 1]);
    }
    
    
    return 0;    
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(12);
  std::cerr << std::fixed << std::setprecision(12);

  int W, H, x, y, u, v;

  std::cin >> W >> H >> x >> y;

  u = W - x;
  v = H - y;

  std::cout << 1LL * W * H / 2.0L << ' ' << (u == x && v == y ? 1 : 0) << std::endl;

  return 0;
}


Measured memory_bytes: 256
n, x, y = map(int, input().split())

dis_list = [0] * (n - 1)

for i in range(1, n):
    for j in range(i + 1, n + 1):
        dis_list[min(abs(j - i), abs(x - i) + 1 + abs(y - j), abs(y - i) + 1 + abs(x - j)) - 1] += 1

for i in dis_list:
    print(i)

Measured memory_bytes: 3444
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String	strIn = parseStdin();

		if (strIn != null) {
			int	max = Integer.parseInt(strIn);
			for (int n = 0; n < max; n++) {
				strIn = parseStdin();
				sub(strIn.toCharArray());
			}
		}
	}

	private static void sub(char[] strIn) {
		String	strMin = null;
		String	strMax = null;

		Arrays.sort(strIn);

		strMin = String.valueOf(strIn);
		strMax = reverse(strMin);

		System.out.println(Long.parseLong(strMax) - Long.parseLong(strMin));
	}

	private static String reverse(String str) {
		char[]	buff = str.toCharArray();
		int		nLen = str.length();
		char	c    = 0;

		for(int n1 = 0, n2 = nLen - 1; n1 < n2; n1++, n2--) {
			c        = buff[n1];
			buff[n1] = buff[n2];
			buff[n2] = c;
		}

		return String.valueOf(buff);
	}
	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

Measured memory_bytes: 16864
import java.util.*;

public class Main{
	public static void solve(int n){
		double x = (double) n/2;
		while( Math.abs( x*x*x-n ) >= 0.00001*n ){
			x = 2*x/3 + n/(3*x*x);
		}
		System.out.printf("%.6f%n", x);
	}
	
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		while( n != -1 ){
			solve(n);
			n = stdIn.nextInt();
		}
	}
}

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

using namespace std;

int n, a;
string s, t;

void calc(int p, int c){
  if(a <= c) return;
  if(p == n){
    a = min(a, c);
    return;
  }
  if(s[p] == t[p]){
    calc(p+1, c);
    return;
  }
  int d = t[p] - s[p];
  for(int i=p;i<n;i++){
    for(int j=p;j<=i;j++) s[j] = ((s[j] - '0') + d + 10) % 10 + '0';
    calc(p+1, c+1);
    for(int j=p;j<=i;j++) s[j] = ((s[j] - '0') - d + 10) % 10 + '0';
  }
}

main(){
  while(cin >> n && n){
    cin >> s >> t;
    a = n;
    calc(0, 0);
    cout << a << endl;
  }
}

Measured memory_bytes: 1200
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}

void main()
{
  int h, w; readV(h, w);
  dchar[][] s; readC(h, s);

  auto isBakudan(int i, int j)
  {
    if (i < 0 || i >= h || j < 0 || j >= w) return false;
    return s[i][j] == '#';
  }

  foreach (i; 0..h)
    foreach (j; 0..w) {
      if (s[i][j] == '#') continue;
      int r = 0;
      foreach (di; -1..2)
        foreach (dj; -1..2)
          if (di != 0 || dj != 0) r += isBakudan(i+di, j+dj);
      s[i][j] = cast(dchar)('0'+r);
    }

  foreach (si; s) writeln(si);
}


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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

#define p(a, b) make_pair(a, b)

int N;
vector<int> T[100001];
int costAoki[100001];
bool visited[100001];

void calcCostAoki(int root)
{
	queue<pair<int, int> > q;
	
	repc(i, 1, N) visited[i] = false;

	q.push(p(root, 0));
	visited[root] = true;
	costAoki[root] = 0;

	while (!q.empty()) {
		pair<int, int> item = q.front(); q.pop();
		int current = item.first;
		int cost = item.second + 1;
		int size = T[current].size();

		rep(i, size) {
			int next = T[current][i];
			if (!visited[next]) {
				costAoki[next] = cost;
				visited[next] = true;
				q.push(p(next, cost));
			}
		}
	}
}

int costTakahashi[100001];

void calcCostTakahashi(int root)
{
	queue<pair<int, int> > q;

	repc(i, 1, N) visited[i] = false;

	q.push(p(root, 0));
	visited[root] = true;
	costTakahashi[root] = 0;

	while (!q.empty()) {
		pair<int, int> item = q.front(); q.pop();
		int current = item.first;
		int cost = item.second + 1;
		int size = T[current].size();

		rep(i, size) {
			int next = T[current][i];
			if (!visited[next]) {
				costTakahashi[next] = cost;
				visited[next] = true;
				q.push(p(next, cost));
			}
		}
	}
}

int destTakahashi(int root)
{
	pair<int, int> ret = p(-1, -1);

	repc(i, 1, N) {
		int cost = ret.second;

		if (costAoki[i] <= costTakahashi[i]) continue;
		if (cost < costAoki[i]) {
			ret.first = i;
			ret.second = costAoki[i];
		}
	}

	return ret.first;
}

int main()
{
	int u, v, dest;

	cin >> N >> u >> v;
	rep(i, N - 1) {
		int A, B;
		cin >> A >> B;
		T[A].push_back(B);
		T[B].push_back(A);
	}

	calcCostTakahashi(u);
	calcCostAoki(v);
	dest = destTakahashi(u);

	cout << costAoki[dest] - 1 << endl;

	return 0;
}

Measured memory_bytes: 6784
//Bingo

#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
using ll = long long;
#define range(a) (a).begin(),(a).end()


int main (){
    bool flag=false,at[9]={false};
    int A[9]; rep(i,0,9)cin >> A[i];
    int N; cin >> N;
    int b[N]; rep(i,0,N)cin >> b[i];
    rep(i,0,N){
        rep(j,0,9){
            if(A[j]==b[i])at[j]=true;
        }
    }
    if(at[0]&&at[1]&at[2])flag=true;
    if(at[3]&&at[4]&at[5])flag=true;
    if(at[6]&&at[7]&at[8])flag=true;
    if(at[0]&&at[3]&at[6])flag=true;
    if(at[1]&&at[4]&at[7])flag=true;
    if(at[2]&&at[5]&at[8])flag=true;
    if(at[0]&&at[4]&at[8])flag=true;
    if(at[2]&&at[4]&at[6])flag=true;
    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define PR pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;

#define MAX 100005
int A[MAX];

int main(){
  int n,k;
  cin>>n>>k;
  for(int i=1; i<=n; i++){
    cin>>A[i];
  }
  int ans=0;
  int kk=k-1;
  
  if(n%kk==1||n%kk==0){
    ans=n/kk;
  }else{
    ans=n/kk+1;
  }
  
  if(k==2){
    ans=n-1;
  }
  
  cout<<ans<<en
}


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

#define FOR(a,b,c) for (int a=(b);a<(c);++a)
#define REP(i,n) FOR(i,0,n)
#define ll long long
#define pii pair<int,int>
#define x first
#define y second
#define pb push_back
#define lf double

using namespace std;

const int MAX = (int)1e6 + 5;

int main(){
	int n;
	scanf ("%d",&n);
	int a=0;
	REP(i,n+2){
		a=(a*10+7)%n;
		if (a==0){
			printf ("%d\n",i+1);
			return 0;
		}
	}
	puts ("-1");
	
	return 0;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n; cin >> n; std::vector<int> p(n + 2);
	for(int i = 1; i <= n; i++) cin >> p[i];
	
	std::vector<std::vector<int>> dp(n + 3, std::vector<int>(4, (1 << 30)));
	for(int i = 0; i < 4; i++) dp[0][i] = i;
	for(int i = 0; i <= n; i++) {
		for(int j = 0; j < 4; j++) {
			for(int k = 0; k < 4; k++) {
				if(j + k < p[i + 1]) continue;
				int tmp = (i == n - 1 ? 1 : 2);
				
				dp[i + 1][k] = std::min(dp[i + 1][k], dp[i][j] + tmp * k);
			}
		}
	}
	
	cout << std::min({dp[n][0], dp[n][1], dp[n][2], dp[n][3]}) << endl;
	return 0;
}



Measured memory_bytes: 3272
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private static bool Solve(int N, int M, Tuple<int, int>[] tuples)
        {
            var islands = new HashSet<int>[N];
            for (int i = 0; i < N; ++i) { islands[i] = new HashSet<int>(); }
            foreach (var tuple in tuples)
            {
                int a = tuple.Item1;
                int b = tuple.Item2;
                islands[a].Add(b);
                islands[b].Add(a);
            }
            var distances = Enumerable.Repeat(int.MaxValue, N).ToArray();
            distances[0] = 0;
            var queue = new Queue<int>();
            queue.Enqueue(0);
            while (queue.Count > 0)
            {
                int a = queue.Dequeue();
                foreach (int b in islands[a])
                {
                    if (distances[b] > distances[a] + 1)
                    {
                        queue.Enqueue(b);
                        distances[b] = distances[a] + 1;
                    }
                }
            }
            return distances[N - 1] == 2;
        }
        static void Main(string[] args)
        {
            int[] values1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int N = values1[0];
            int M = values1[1];
            var tuples = new Tuple<int, int>[M];
            for (int i = 0; i < M; ++i)
            {
                int[] values2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                tuples[i] = new Tuple<int, int>(values2[0] - 1, values2[1] - 1);
            }
            Console.WriteLine(Solve(N, M, tuples) ? "POSSIBLE" : "IMPOSSIBLE");
        }
    }
}


Measured memory_bytes: 68376
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#ifndef print
#define print(...)
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
//const int mod = 998244353;
const int mod = 1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk = clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) { uniform_int_distribution<int> uid(0, lim - 1); return uid(rang); }
int powm(int a, int b) { int res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }

int a[100005];

int32_t main() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	int n; cin >> n;
	for (int i = 0; i <= n; ++i)
		cin >> a[i];
	int su = 0;
	for (int i = 0; i <= n; ++i) {
		su += a[i];
	}
	if (su == 0) {
		cout << 0 << '\n';
		return 0;
	} 
	int l = 1;
	int to = 0;
	for (int i = 0; i <= n; ++i) {
		if (a[i] > l) {
			cout << -1 << '\n';
			return 0;
		}
		to += l;
		l -= a[i];
		su -= a[i];
		if (su <= 2 * l) {
			to += su;
			for (int j = i + 1; j <= n; ++j)
				to += a[j] * (j - (i + 1));
			break;
		}
		l *= 2;
	}
	cout << to << '\n';
}

Measured memory_bytes: 4432
#include <stdio.h>

int main()
{
	int i, N, K, x[101];
	scanf("%d", &N);
	scanf("%d", &K);
	for (i = 1; i <= N; i++) scanf("%d", &(x[i]));
	
	int sum = 0;
	for (i = 1; i <= N; i++) {
		if (x[i] <= K / 2) sum += x[i];
		else sum += K - x[i];
	}
	printf("%d\n", sum * 2);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	long long int n,mymin,mymax;cin>>n>>mymin>>mymax;
  	if(mymin>mymax){cout<<0<<endl;return 0;}
  	if(mymin!=mymax && n==1){cout<<0<<endl;return 0;}
  	if(mymin==mymax && n==1){cout<<1<<endl;return 0;}
  
  	cout<<mymax*(n-1)+mymin-(mymin*(n-1)+mymax)+1<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main(){
    string s;
    cin >> s;
    if(s[0]>='a'&&s[0]<='z'){
        cout << "a" << endl;
    }
    else{
        cout << "A" << endl;
    }



    return 0;
}

Measured memory_bytes: 3624
def main():
  
  n = int(input())
  res = input()
  
  dic = {"J":0, "O":1, "I":2}
  zo = [0,1]
  dp =[[[0 for j in zo] for o in zo] for i in zo]
  
  res1 = dic[res[0]]
  
  if res1 == 0:
    for o in zo:
      for i in zo:
        dp[1][o][i] = 1
  elif res1 == 1:
    for i in zo:
      dp[1][1][i] = 1
  else:
    for o in zo:
      dp[1][o][1] = 1
  
  for d in range(1, n):
    resd = dic[res[d]]
    new = [[[0 for i in zo] for o in zo] for j in zo]
    new[0][0][0] = 0
    new[1][1][1] = sum([dp[x][y][z] for x in zo for y in zo for z in zo])
    new[0][0][1] = sum([dp[x][y][1] for x in zo for y in zo]) if resd == 2 else 0
    new[0][1][0] = sum([dp[x][1][y] for x in zo for y in zo]) if resd == 1 else 0
    new[1][0][0] = sum([dp[1][x][y] for x in [0,1] for y in [0,1]]) if resd == 0 else 0
    new[0][1][1] = sum([dp[x][1][y] + dp[x][y][1] for x in zo for y in zo]) - sum(dp[x][1][1] for x in zo) if resd in [1, 2] else 0
    new[1][0][1] = sum([dp[1][x][y] + dp[x][y][1] for x in zo for y in zo]) - sum(dp[1][x][1] for x in zo) if resd in [0, 2] else 0
    new[1][1][0] = sum([dp[x][1][y] + dp[1][x][y] for x in zo for y in zo]) - sum(dp[1][1][x] for x in zo) if resd in [0, 1] else 0
    dp = new
  
  ans = 0
  for i in zo:
    for j in zo:
      for k in zo:
        ans += dp[i][j][k]
  
  print(ans % 10007)

main()


Measured memory_bytes: 5652
# author:  Taichicchi
# created: 21.09.2020 23:02:12

import sys
from collections import Counter

n = int(input())

v = list(map(int, input().split()))

ans1 = 0

c1 = Counter(v[::2])

c1_max = max(c1, key=c1.get)

for i in v[::2]:
    if i != c1_max:
        ans1 += 1

c2 = Counter(v[1::2])

c2_max = max(c2, key=c2.get)

if c1_max == c2_max:
    if len(c2) > 1:
        c2.pop(c2_max)
        c2_max = max(c2, key=c2.get)
    else:
        c2_max += 1

for i in v[1::2]:
    if i != c2_max:
        ans1 += 1

ans2 = 0

c1 = Counter(v[1::2])

c1_max = max(c1, key=c1.get)

for i in v[1::2]:
    if i != c1_max:
        ans2 += 1

c2 = Counter(v[::2])

c2_max = max(c2, key=c2.get)

if c1_max == c2_max:
    if len(c2) > 1:
        c2.pop(c2_max)
        c2_max = max(c2, key=c2.get)
    else:
        c2_max += 1

for i in v[::2]:
    if i != c2_max:
        ans2 += 1

print(min(ans1, ans2))


Measured memory_bytes: 25572
mod = 10**9 + 7

N = int(input())

dp = [[0]*4 for _ in range(N+1)]
dp[1] = [1]*4
for i in range(1,N+1):
    for j in range(4):
        dp[i][j] += sum(dp[i-1])
        dp[i][j] %= mod
    # AGC GAC ACG 
    if i >= 2:
        dp[i][1] -= dp[i-2][0] + dp[i-2][2]
        dp[i][2] -= dp[i-2][0]
    # A?GC AG?C (AGGC)
    if i >= 3:
        dp[i][1] -= dp[i-3][0]*3
        dp[i][2] += dp[i-3][2]

ans = sum(dp[N]) % mod
print(ans)

Measured memory_bytes: 3064
N = int(input())
s = input()

l = len(s)

c = 0

if l%2 == 1:
    print('No')
else:
    for i in range(l//2):
        if s[i] == s[i+l//2]:
            c  =c+1
    if c == l//2:
        print('Yes')
    else:       
        print('No')

Measured memory_bytes: 3060