akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
	string w;
	cin >> w;
	auto p = vector<bool>('z' + 1);
	int cnt = 0;
	for(auto c : w){
		if(p[c]) --cnt;
		else ++cnt;
		p[c] = !p[c];
	}
	cout << (cnt == 0 ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int M = 1e9 + 7, N = 3003, R = 2e5 + 7;

pi a[N];

int dp[N], f[R], inv[R], fi[R];
int C(int n, int k) {
	return f[n] * fi[k] % M * fi[n - k] % M;
}
int go(int x, int y) {
	return C(x+y, x);
}

signed main()
{
	IO_OP;
	
	f[0] = 1;
	for(int i=1;i<R;i++)
		f[i] = f[i-1] * i % M;
	inv[1] = 1;
	for(int i=2;i<R;i++)
		inv[i] = M - M / i * inv[M % i] % M;
	fi[0] = 1;
	for(int i=1;i<R;i++)
		fi[i] = fi[i-1] * inv[i] % M;

	int h, w, n;
	cin >> h >> w >> n;
	for(int i=0;i<n;i++)
		cin >> a[i].F >> a[i].S;
	sort(a, a+n); 	
	int ans = go(h - 1, w - 1);
	for(int i=0;i<n;i++) {
		dp[i] = -go(a[i].F - 1, a[i].S - 1);
		for(int j=0;j<i;j++) {
			int x = a[i].F - a[j].F, y = a[i].S - a[j].S;
			if(x >= 0 && y >= 0)
				dp[i] -= dp[j] * go(x, y) % M;
		}
		dp[i] %= M;
		ans += dp[i] * go(h - a[i].F, w - a[i].S) % M;
	}
	ans = (ans % M + M) % M;
	cout << ans << endl;
}





Measured memory_bytes: 4992
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = new String[3];
    for(int i=0; i<3; i++) {
      str = in.readLine().split("");
      System.out.print(str[i]);
    }
  }
}

Measured memory_bytes: 32944
N = int(input())
A = list(map(int, input().split()))
C = [0] * N
for a in A:
    C[a] += 1
if N % 2 == 1:
    if C[0] != 1:
        print(0)
        exit()
    for i in range(2, N, 2):
        if C[i] != 2:
            print(0)
            exit()
    print(2 ** ((N - 1) // 2) % 1000000007)
else:
    for i in range(1, N, 2):
        if C[i] != 2:
            print(0)
            exit()
    print(2 ** (N // 2) % 1000000007)


Measured memory_bytes: 13880
def resolve():
    def popcnt(x):
        return bin(x).count("1")

    N = int(input())
    Xs = input()
    X = int(Xs, 2)
    d = popcnt(X)

    lut = [0] * N
    for i in range(1, N):
        Xi = i % popcnt(i)
        lut[i] = lut[Xi] + 1

    dp = d+1
    dm = d-1
    mp = X % dp
    mm = X % dm if dm else 0
    # print(lut)
    # print(format(X, 'b'))

    ans = []
    for i in range(N):
        mask = 1 << (N-i-1)
        Xi = X ^ mask
        _ans = 0
        if Xs[i] == '1':
            if dm:
                m = (mm - pow(2, N-i-1, dm)) % dm
                _ans = lut[m] + 1
            # m = (mm - mask) % dm
        else:
            # m = (mp + mask) % dp
            m = (mp + pow(2, N-i-1, dp)) % dp
            _ans = lut[m] + 1
        ans.append(_ans)
    print(*ans, sep='\n')

resolve()

Measured memory_bytes: 15676
#include "bits/stdc++.h"

using namespace std;

int main() {
    int count[26];
    for (int i = 0; i < 26; ++i) count[i] = 0;
    string s; cin >> s;
    for (int i = 0; i < s.size(); ++i) count[s[i] - 'A']++;
    int ans = 0;
    for (int i = 0; i < 26; ++i) if (count[i] == 2) ++ans;
    cout << ((ans == 2) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

int n;
std::vector<int> p;
std::string S;

int main(int argc, char const* argv[])
{
    std::cin >> n;
    int tmp;
    while (std::cin >> tmp) {
        p.push_back(tmp);
    }
    int result = 0;
    for (int i = 0; i < n-2; i++) {
        int max = std::max(std::max(p[i], p[i+1]), p[i+2]);
        int min = std::min(std::min(p[i], p[i+1]), p[i+2]);
        if (max != p[i+1] && min != p[i+1]) {
            result++;
        }
    }
    std::cout << result << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	
	if(x+r>W||x-r<0)
	{
		printf("No\n");
	}
	else if(y+r>H||y-r<0)
	{
		printf("No\n");
	}
	else
	{
	printf("Yes\n");
	}
	return 0;
}


Measured memory_bytes: 1996
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int main(void){
    // Your code here!
    int N, M;
    vector<vector<long long>> sche;
    
    cin >> N >> M;
    for(int i = 0; i < M; i++){
       vector<long long> temp(2, 0);
       cin >> temp[0] >> temp[1];
       sche.push_back(temp);
    }
    
    sort(sche.begin(), sche.end(), [](vector<long long> a, vector<long long>b){
        return a[1] < b[1];
    });
    
    int i = 0;
    int end = 0;
    int count = 0;
    while(i < M){
        if(sche[i][0] >= end){
            end = sche[i][1];
            count++;
        }
        i++;
    }
    
    cout << count << endl;
    
    return 0;    
}


Measured memory_bytes: 6836
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n, x, t;
    cin >> n >> x >> t;
    if (n%x == 0){
        cout << (n/x) * t << endl;
    }
    else {
        cout << (n/x +1) * t << endl; 
    }
}


Measured memory_bytes: 3544
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws IOException
	{
		int n=nextInt();
		HashSet<String> set=new HashSet<>();
		while(n-->0)
			set.add(nextLine());
		out.println(set.size());
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  ll a, b, c;
  scanf("%lld %lld %lld", &a, &b, &c);

  long double ra = sqrtl(a);
  long double rb = sqrtl(b);
  // long double rc = sqrtl(c);

  if (c > a + b + 2 * ra * rb) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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



signed main()
{

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

    string a;
    cin>>a;
    int n=a.length();
    int z=1;
    int rem=0;
    for(int i=n-1;i>=0;i--)
    {
        rem+=(a[i]-'0')*z%9;
        rem%=9;
        z=(z*10)%9;
    }
    if(rem==0)
        cout<<"Yes";
    else
        cout<<"No";

}       


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

int main() {
  int n, k; cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ans = 0;
  n -= k;
  ans++;
  k--;
  while (n > 0) {
    n -= k;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

template <ll Mod>
struct modint {
  ll n;

  modint(const ll x = 0) : n(x) { while (n < 0) n += Mod; n %= Mod; }
  modint operator+(const modint r) const { return modint(*this) += r; }
  modint operator-(const modint r) const { return modint(*this) -= r; }
  modint operator*(const modint r) const { return modint(*this) *= r; }
  modint operator/(const modint r) const { return modint(*this) /= r; }
  modint &operator+=(const modint r) {
    n += r.n;
    if (n >= Mod) n -= Mod;
    return *this;
  }
  modint &operator-=(const modint r) {
    if (n < r.n) n += Mod;
    n -= r.n;
    return *this;
  }
  modint &operator*=(const modint r) { n = n * r.n % Mod; return *this; }
  modint &operator/=(const modint r) { return *this *= r.inv(); }
  modint pow(ll x) const {
    modint<Mod> ret(1), tmp(*this);
    while (x) {
      if (x&1) ret *= tmp;
      tmp *= tmp;
      x >>= 1;
    }
    return ret;
  }
  modint inv() const { return pow(Mod-2); }
  friend ostream& operator<<(ostream& os, const modint& obj) { return os << obj.n; }
  friend istream& operator>>(istream& is, modint& obj) { ll t; is >> t; obj = modint(t); return is; }
};
//constexpr ll mod = 1000000007;
constexpr ll mod = 998'244'353;
using mint = modint<mod>;

// T modint
template<class T>
struct Combination {
  vector<T> fact, inv_fact;
  Combination(ll n) : fact(n+1), inv_fact(n+1) {
    fact[0] = T(1);
    for (ll i = 1; i <= n; i++) fact[i] = fact[i-1] * static_cast<T>(i);
    inv_fact[n] = fact[n].inv();
    for (ll i = n; i > 0; i--) inv_fact[i-1] = inv_fact[i] * static_cast<T>(i);
  }

  T P(ll n, ll k) const {
    return fact[n] * inv_fact[n-k];
  }

  T C(ll n, ll k) const {
    return fact[n] * inv_fact[n-k] * inv_fact[k];
  }

  T H(ll n, ll k) const {
    return C(n+k-1, n-1);
  }
};

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

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

  mint ans(0);
  Combination<mint> com(n);
  rep(i, n+1) {
    ll d = (k-a*i);
    if (d >= 0 and d%b == 0) {
      ll j = d/b;
      if (j > n) continue;
      ans += com.C(n, i) * com.C(n, j);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std ; 
#define ll long long
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
#define test  ll int tcase ; cin>>tcase ; while(tcase--) 
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


int main(){
    io ; 
    int n ,x ; cin>>x>>n ; 
  if(n==0){ 
    cout<<x ;
    return 0 ; 
  }
    map<int,bool>present ; 
    for(int i=1  ; i<=100 ; i++){
        present[i]=false ; 
    }
    for(int i = 0;  i<n ; i++){
        int p ;cin>>p  ;
        present[p]=true ; 
    }
  if(present[x]==false){
     cout<<x ; return 0 ; 
  }
   
   int i=x-1,j=x+1 ; int flag1=1;int flag2=1; ; int left =INT_MAX ; int right=INT_MAX ; 
   while(flag1 and flag2){
       if(present[i]==false){
           flag1=0 ; left=i ; 
       }
       if(present[j]==false){
           flag2=0 ; right = j ; 
       }
       i-- ; j++ ; 
   } 
   
   int ans = 0 ; 
   if(flag1==0 and flag2==1){
       ans = left ;
   }else if(flag2==0 and flag1==1){
       ans = right ; 
   }else{
       ans = left ;
   }

   cout<<ans  ;  

}

Measured memory_bytes: 3664
a, b, c, d = map(int, input())

def i_to_sign(n):
    if n > 0:
        return "+"
    else:
        return "-"

for bits in range(2**3):
    plus = [1] * 3
    for i in range(3):
        if (1 << i & bits) == 0:
            plus[i] = -1
    
    result = a + (b * plus[0]) + (c * plus[1]) + (d * plus[2])

    if result == 7:
        print("{}{}{}{}{}{}{}=7".format(
            a, i_to_sign(plus[0]),
            b, i_to_sign(plus[1]),
            c, i_to_sign(plus[2]),
            d
        ))
        exit()

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

int main(){
    int n,p,s=0,m=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p;
        s+=p;
        m=max(m,p);
    }
    cout<<s-m/2<<endl;
    return 0;
}

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

name_capital = {
    'M': 0,
    'A': 0,
    'R': 0,
    'C': 0,
    'H': 0,
}
name_list = ['M', 'A', 'R', 'C', 'H']
for _ in range(N):
    name = input()
    for word in name_list:
        if name[0] == word:
            name_capital[word] += 1
            break

nv = list(name_capital.values())
N2 = len(nv)
answer = 0
for i in range(N2-2):
    for j in range(i+1, N2-1):
        for k in range(j+1, N2):
            answer += nv[i] * nv[j] * nv[k]

print(answer)


Measured memory_bytes: 3064
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

type point struct {
	x, y int
}

type pointList []point

type xList struct{ pointList }
type yList struct{ pointList }

func (a pointList) Len() int      { return len(a) }
func (a pointList) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

func (a xList) Less(i, j int) bool { return a.pointList[i].x < a.pointList[j].x }
func (a yList) Less(i, j int) bool { return a.pointList[i].y < a.pointList[j].y }

func main() {
	sc.Split(bufio.ScanWords)

	N, K := scanInt(), scanInt()
	L := make(pointList, N)
	for i := 0; i < N; i++ {
		L[i].x, L[i].y = scanInt(), scanInt()
	}
	sort.Sort(xList{L})

	ans := int(math.Pow10(18)) * 4
	for i := 0; i < N-1; i++ {
		for j := i + 1; j < N; j++ {
			M := j - i + 1
			if M < K {
				continue
			}

			L2 := make(pointList, M)
			for k := 0; k < M; k++ {
				L2[k].x, L2[k].y = L[i+k].x, L[i+k].y
			}
			sort.Sort(yList{L2})

			xrange := L[j].x - L[i].x
			for k := 0; k < M-K+1; k++ {
				yrange := L2[k+K-1].y - L2[k].y
				if new := xrange * yrange; new < ans {
					ans = new
				}
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2204
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
int main(){
    char a,b;
    cin >> a >> b;
    if(a == b) cout << 'H' << endl;
    else cout << 'D' << endl;
    return 0;
}


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

ll gcd(ll a, ll b) {
  ll smaller = min(a, b);
  ll bigger = max(a, b);
  ll surplus = bigger % smaller;
  if (surplus == 0) return smaller;
  if(smaller == 0) return bigger;
  surplus = gcd(smaller, surplus);
  return surplus;
}

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

Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
using namespace std;

int main()
{
	int n;
	int k;
	int h[100100];
	int cnt = 0;

	cin >> n>>k;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		if (h[i] >= k) {
			cnt = cnt + 1;
		}
	}
	
	cout << cnt;
}

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

using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
const ll LIM = 1e13;
int main(){
    ll n,k;
    cin >> n>>k;
    ll a[n];
    ll i,j,h;
    ll sum=0;
    for(i=0;i<n;i++){
        cin >> a[i];
        sum +=a[i];
    }
    ll cnt;
    ll ret = 0;
    for(i=1;i*i<=sum;i++){
        if(sum%i==0){
            ll num = sum/i;
            cnt=0;
            vector<ll> v(n);
            for(j=0;j<n;j++){
                v[j]=a[j]%num;
            }
            sort(v.begin(),v.end());
            ll tmp = 0;
            vector<ll> w(n);
            for(h=0;h<n;h++){
                w[h] = v[h]+tmp;
                tmp=w[h];
            }
            tmp=0;
            vector<ll> x(n);
            for(h=n-1;h>=0;h--){
                x[h] = (num-v[h])+tmp;
                tmp = x[h];
            }
            for(h=0;h<n-1;h++){
                if(max(w[h],x[h+1])<=k)ret = max(num,ret);
            }
            num = i;
            cnt = 0;
            for(j = 0; j < n; j++) {
                v[j] = a[j] % num;
            }
            sort(v.begin(), v.end());
            tmp = 0;
            for(h = 0; h < n; h++) {
                w[h] = v[h] + tmp;
                tmp = w[h];
            }
            tmp = 0;
            for(h = n - 1; h >= 0; h--) {
                x[h] = (num - v[h]) + tmp;
                tmp = x[h];
            }
            for(h = 0; h < n - 1; h++) {
                if(max(w[h], x[h + 1]) <= k) ret = max(num, ret);
            }
        }
    }
    cout << ret << endl;
    return 0;
}

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

using namespace std;

const long long inf = 1ll << 60;

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> p(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
  }
  vector<int> q(n + 1);
  for (int i = 1; i <= n; ++i) {
    q[p[i]] = i;
  }
  vector<long long> dp(n + 1, inf);
  dp[0] = 0;
  for (int i = 1; i <= n; ++i) {
    vector<long long> new_dp(n + 1, inf);
    for (int j = 0; j < i; ++j) {
      if (dp[j] != inf) {
        if (q[i] > q[j]) {
          new_dp[i] = min(new_dp[i], dp[j]);
          new_dp[j] = min(new_dp[j], dp[j] + b);
        } else {
          new_dp[j] = min(new_dp[j], dp[j] + a);
        }
      }
    }
    swap(dp, new_dp);
  }
  cout << *min_element(dp.begin(), dp.end()) << "\n";
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cstdlib>
#include <iomanip>

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

const long long INF = 1LL << 60;

// 入力
int N;
long long h[110000][3];

// DP テーブル
long long dp[110000][3];

int main() 
{
	long long N, M;
	cin >> N >> M;
	if (N == 2 || M == 2) {
		cout << 0 << endl;
		exit(0);
	}

	if (N == 1 && M == 1) {
		cout << 1 << endl;
		exit(0);
	}

	if (N == 1 || M == 1) {
		if (N == 1) {
			cout << M - 2 << endl;
		}
		else {
			cout << N - 2 << endl;
		}
		exit(0);
	}

	cout << (N - 2) * (M - 2) << endl;
}


Measured memory_bytes: 256
import sys
from collections import Counter
sys.setrecursionlimit(10**7)
mo=10**9+7
n=10**5

n,a,b=map(int,input().split())
x=[int(i) for i in input().split()]
ans=0
pre=x[0]
for i in range(1,n):
    cur=x[i]
    if (cur-pre)*a>b:
        ans+=b
        
    else:
        ans+=(cur-pre)*a
    pre=cur
    
print(ans)


Measured memory_bytes: 62832
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

#define Max 110000

int A[Max];
int N;

int main(int argc, const char * argv[]) {
    N = inputValue();
    A[0] = 0;
    A[N+1] = 0;
    inputArray(A+1, N);

    ll total = 0;
    repd(i, 1, N+2) {
        total += abs(A[i-1] - A[i]);
    }

    repd(i, 1, N+1) {
        ll ans = total - abs(A[i-1] - A[i]) - abs(A[i]-A[i+1]) + abs(A[i-1]-A[i+1]);
        output(ans);
    }

    return 0;
}

Measured memory_bytes: 1664
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();

		Long[] lifes = new Long[N];
		for (int i=0; i < N; i++) {
			lifes[i] = scan.nextLong();
		}
		Arrays.sort(lifes, Collections.reverseOrder());

		for (int i=0; i < K; i++) {
			if (i >= N) break;
			lifes[i] = Long.valueOf(0);
		}
		long ans = 0;
		for (long i : lifes) {
			ans += i;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 96148
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word
// kuch ni ho rha to kya pta binary search ho
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
#define sz 100005
ll inf = 1e18;
ll power(ll x, ll n, ll mod)
{
  ll res = 1;
  x %= mod;
  while (n)
  {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res%mod;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  ll n;
  cin>>n;
  ll x,y;
  vector<pair<ll,ll>>v;
  for(ll i=0;i<n;i++)
  {
    cin>>x>>y;
    v.push_back({x,y});
  }
  bool f=0;
  for(ll i=2;i<n;i++)
  {
    if(v[i].first==v[i].second && v[i-1].first==v[i-1].second && v[i-2].first==v[i-2].second)
      f=1;
  }
  if(f)
    cout<<"Yes\n";
  else
    cout<<"No\n";
  return 0;
}

Measured memory_bytes: 3656
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
bool solve(int x,int y,int c);
int ux[2][8]={{0,1,2,3,0,1,2,3},
	      {0,1,0,1,0,1,0,1}};
int uy[2][8]={{0,0,0,0,1,1,1,1},
	      {0,0,1,1,2,2,3,3}};
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
int w,h,n;
int b[105][105];
int xs,ys,xg,yg;
int main(void){
  while(1){
    scanf("%d %d",&w,&h);
    if(!w && !h) break;
    memset(b,0,sizeof(b));
    scanf("%d %d %d %d",&xs,&ys,&xg,&yg);
    scanf("%d",&n);
    int c,d,tx,ty;
    for(int i=0;i<n;i++){
      scanf("%d %d %d %d",&c,&d,&tx,&ty);
      for(int j=0;j<8;j++){
	b[tx+ux[d][j]][ty+uy[d][j]]=c;
      }
    }
    if(b[xs][ys]!=0 && b[xg][yg]!=0 && b[xs][ys]==b[xg][yg] && solve(xs,ys,b[xs][ys])) puts("OK");
    else puts("NG");
  }
}

bool solve(int x,int y,int c){
  if(x==xg && y==yg) return true;
  b[x][y]=0;
  for(int i=0;i<4;i++){
    int nx=x+dx[i];
    int ny=y+dy[i];
    if(0<nx && nx<=w && 0<ny && ny<=h){
      if(b[nx][ny]==c){
	if(solve(nx,ny,c)) return true;
      }
    }
  }
  return false;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define MAXN 200005
using namespace  std;
string n;
int sum = 0;
string::iterator it;

int t(char a)
{
	switch(a)
	{
		case '0': return 0; break;
		case '1': return 1; break;
		case '2': return 2; break;
		case '3': return 3; break;
		case '4': return 4; break;
		case '5': return 5; break;
		case '6': return 6; break;
		case '7': return 7; break;
		case '8': return 8; break;
		case '9': return 9; break;
	}
}

int main()
{
	//cout << sum << endl;
	cin >> n;
	//int i = 0;
	//cout << n.length() << endl;
	for(it = n.begin(); it != n.end(); it++)
	{
		//cout << sum << endl;
		//cout << t(*it) << endl;
		sum += t(*it);
		//cout << n[i] << endl;
		//cout << sum << endl;
		if(sum >= 9)
			sum -= 9;
	}
	//cout << sum << endl;
	if(sum == 0)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  ll mx = -1;
  for (int i = 0; i < 1 << N; i++) {
    ll ibitcount = bitset<32>(i).count();
    if (ibitcount < K) continue;
    ll cost = 0;
    ll now = -1;
    ll now_max = 0;
    vector<ll> tmp(N);
    REP(j, N) {
      
      if ((i & 1 << j) == false) {
        now_max = max(now_max, A[j]);
        continue;
      }
      cost += now_max < A[j] ? 0 : now_max - A[j] + 1;
      tmp[j] = max(A[j],now_max + 1);
      REP(k, j+1) {
        now_max = max(now_max, A[j]);
        now_max = max(now_max, tmp[j]);
      }
    }
    if (mx == -1) {
      mx = cost;
    } else {
      mx = min(cost, mx);
    }
  }
  cout << mx << endl;
}

Measured memory_bytes: 256
import bisect
import sys
input = sys.stdin.readline


n, q = map(int, input().split())
events = [list(map(int, input().split())) for _ in range(n)]
events.sort(key=lambda x: x[2])

departures = [int(input()) for _ in range(q)]


ans = ['-1'] * q
skip = [-1] * q

for start, end, pos in events:
    left = bisect.bisect_left(departures, start-pos)
    right = bisect.bisect_left(departures, end-pos)

    while left < right:
        if skip[left] == -1:
            ans[left] = str(pos)
            skip[left] = right
            left += 1

        else:
            left = skip[left]

print('\n'.join(ans))


Measured memory_bytes: 121436
#include<stdio.h>

int main(){
    char c;
    int i=0;
    scanf("%c", &c);
    if(c=='a'){
        i = 1;
    }
    if (c == 'e')
    {
        i = 1;
    }
    if (c == 'i')
    {
        i = 1;
    }
    if (c == 'o')
    {
        i = 1;
    }
    if (c == 'u')
    {
        i = 1;
    }
    if(i==1){
        printf("vowel\n");
    }else
    {
        printf("consonant \n");
    }
    

    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<functional>
#include<cstring>
#include<iostream>
#include<cmath>
#include<queue>
#include<cctype>
#include<string>
#include<cstdlib>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define INF 2100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
int dp[4545][4545],leng[4545],tenko[4545];
int main(void)
{
	int n,m,hi;
	cin>>n>>m;
	rep(i,0,n) cin>>leng[i];
	rep(i,0,m) cin>>tenko[i];
	rep(i,0,m+1)rep(j,0,n+1) dp[i][j]=INF;
	dp[0][0]=0;
	rep(i,0,m+1) {
		rep(j,0,n+1) {
			if(dp[i][j]!=INF) {
				if(i+1<=m)dp[i+1][j]=min(dp[i][j],dp[i+1][j]);
				hi=tenko[i]*leng[j];
				if(i+1<=m&&j+1<=n)dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+hi);
			}
		}
	}
	int mn=INF;
	rep(i,0,m+1) mn=min(mn,dp[i][n]);
	cout<<mn<<endl;
	return 0;
}

Measured memory_bytes: 10112
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>
#include <string>
#include <random>
typedef long long ll;
#define pb push_back
#define pf push_front
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vll vector <ll>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define sz(x) (int)x.size()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 3e5;
const ll INF = 1e9;
const ll kek=998244353;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    if (a<=9&&b<10)
        cout<<a*b;
    else
        cout<<-1;}





Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,a[1000];
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n-1;i++)
		cout<<a[n-i-1]<<" ";
	cout<<a[0]<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>

using namespace std;

int main(){
    int n,a,b,cnt,c;
    cnt=0;
    c=0;
    string s;
    cin>>n>>a>>b>>s;
    for(int i=0;i<s.length();++i){
        switch(s[i]){
            case 'a':
                if(cnt<a+b){
                    cout<<"Yes"<<endl;
                    cnt++;
                }
                else{
                    cout<<"No"<<endl;
                }
                break;
            case  'b':
                if(cnt<a+b&&c<b){
                    cout<<"Yes"<<endl;
                    cnt++;
                    c++;
                }else{
                    cout<<"No"<<endl;
                }
                break;
            case 'c':
                cout<<"No"<<endl;
                break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 896
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = I.nextInt();
		String S = I.next();
		String T = I.next();
		int ans = N*2;
		int sub = 0;
		for (int L = 0; L < N; L++) {
			if (S.charAt(L)==T.charAt(0)){
				int cur = 1;
				boolean good=true;
				for (int next = L+1; next < N; next++) {
					if (T.charAt(next-L)!=S.charAt(next)) {
						good=false;
						break;
					} 
					cur++;
				}
				if (good) {
					sub=cur;
					break; //First ever overlapping substring is best
				} 
			}
		}
		O.pln(ans-sub);
	}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 25592
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()

	ans := 1
	for {
		if ans*2 > N {
			break
		}
		ans *= 2
	}
	out(ans)
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
int g[100010],a[100010],n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		g[i]=gcd(g[i-1],a[i]);
	}
	int ans=0;
	for(int i=n;i>=1;i--)
	{
		ans=max(ans,gcd(g[i-1],g[i+1]));
		g[i]=gcd(g[i+1],a[i]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
from collections import deque

def main():
    N, K = input_nums()
    V = input_nums()
    maxv = 0
    for total in range(min(N, K)+1):
        for a in range(total+1):
            D = deque(V)
            gems = []
            b = total - a
            for i in range(a):
                gems.append(D.pop())
            for i in range(b):
                gems.append(D.popleft())
            gems.sort(reverse=True)
            d = K - (a+b)
            for i in range(d):
                if len(gems) > 0:
                    a = gems.pop()
                    if a < 0:
                        continue
                    else:
                        gems.append(a)
                        break
            maxv = max(maxv, sum(gems))
    print(maxv)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3436
#D 素数の公約数-> 素因数分解で共通な素因数を求めて個数を入力
import sys
a, b = map(int, input().split())

#素因数分解(2以降)
def factorization(n):
    arr = []
    tmp = n
    #2から√n でnを割る ･･･割れた回数を指数として追加
    for i in range(2, int(n ** 0.5 // 1) + 1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            arr.append([i, cnt])
    if tmp != 1:  #割り切れなかったとき
        arr.append([tmp, 1])
    if arr == []: #素数の場合(割れなかった場合)
        arr.append([n, 1])
    return arr

a = factorization(a)
b = factorization(b)
ans = 1
# print(a, b)
if a[0][0] == b[0][0] == 1:
    print(ans)
    sys.exit()
for i in a:
    for j in b:
        if i[0] == j[0]:
            ans += 1
print(ans)

Measured memory_bytes: 9492
#include <cstdio>
using namespace std;

int main() {
  int ans;
  int n;
  scanf("%d", &n);
  if(n % 1000 == 0) {
    ans = 0;
  } else {
    ans = 1000 - n % 1000;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1716
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  string S,T;
  cin >> S >> T;
  vector<int> s(26,0),t(26,0);
  for(int i = 0; i < S.length(); ++i){
    s[S[i]-'a']++;
    t[T[i]-'a']++;
  }
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  for(int i = 0; i < 26; ++i){
    if(s[i] != t[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 900
N, M = map(int, input().split())


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]
        self.size = [1]*n

    def find(self, x):
        if self.par[x] != x:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return
        if self.size[x] > self.size[y]:
            x, y = y, x
        self.par[x] = y
        self.size[y] += self.size[x]


uf = UnionFind(N)

for i in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    uf.union(A, B)
print(max(uf.size))


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

int gcd(int b, int a) {
	int r = a % b;
	while (r > 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

signed main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(a.begin(), a.end());
	int g = a[0], m = a[n-1];	

	for (int i = 0; i < n; i++) {
		g = gcd(g, a[i]);
	}

	if (k % g == 0 and k <= m) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
}


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

using namespace std;

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

const int MM = 1e9 + 7;
const double eps = 1e-8;

char s[200020];

int main(){
	scanf("%s", s);
	int l = strlen(s);
	for(int i = 1; i < l; i++){
		if (s[i-1] == s[i]){
			cout<<i<<' '<<i+1<<endl;
			return 0;
		}
	}
	for(int i = 2; i < l; i++){
		if (s[i-2] == s[i]){
			cout<<i-1<<' '<<i+1<<endl;
			return 0;
		}
	}
	cout<<-1<<' '<<-1<<endl;
	return 0;
} 

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){

	int a,b,c;
	cin>>a>>b>>c;

	if(c<b){swap(c,b);}
	if(b<a){swap(b,a);}
	if(c<b){swap(c,b);}

	cout<<a<<" "<<b<<" "<<c<<endl;

	return 0;
}


Measured memory_bytes: 3100
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=305;
const int mod=998244353;
int n,m,bin[MAXN];
bitset<MAXN> bi[MAXN];
int main()
{
	bin[0]=1;for(int i=1;i<MAXN;i++)bin[i]=(bin[i-1]<<1)%mod;
	n=read();m=read();
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)bi[i][j]=read();
	for(int i=1,p=1;i<=n&&p<=m;i++,p++)
	{
		int u=i;for(int j=i+1;j<=n;j++)if(bi[j][p]){u=j;break;}
		swap(bi[i],bi[u]);if(!bi[i][p]){--i;continue;}
		for(int j=i+1;j<=n;j++)if(bi[j][p])bi[j]^=bi[i];
	}int cnt=0;
	for(int i=1;i<=n;i++)if(bi[i].any())++cnt;
	cnt=n-cnt;
	int val=(bin[n]-bin[cnt]+mod)%mod;
	pr2(1LL*val*bin[m-1]%mod);
	return 0;
}



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

long inv(int a, int m) {
    long i = 1, j = 0;
    for(int b = m; a > 1; swap(i, j), swap(a, b)) {
        j = (j + b / a * (m - i)) % m;
        b %= a;
    }
    return i;
}
long f[111111] = {1};
int a[111111];
int main() {
    int n, k, p = 1e9 + 7;
    cin >> n >> k;
    for(int i = 0; i < n; i++)
        scanf("%d", a + i);
    sort(a, a + n);
    for(int i = 0; i < n; i++)
        f[i + 1] = f[i] * (i + 1) % p;
    long r = 0;
    for(int i = 0; i < n; i++) {
        if(i >= k - 1)
            (r += f[i] * a[i] % p * inv(f[k - 1] * f[i - k + 1] % p, p)) %= p;
        if(n - i >= k)
            (r += (p - f[n - i - 1]) * a[i] % p *
                  inv(f[k - 1] * f[n - i - k] % p, p)) %= p;
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 1408
N = int(input())
word = []
flag = 0
for i in range(N):
  now = input()
  if i == 0:
    word.append(now)
  else:
    check = word[i-1]
    if now[0] != check[len(check)-1]:
      flag = 1
      print("No")
      break
    for j in range(len(word)):
      if now == word[j]:
        flag = 1
        print("No")
        break
    word.append(now)
if flag == 0:
  print("Yes")
      

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define mod 998244353
using namespace std;

ll gcd(ll a,ll b){
	if(b==0)return a;return gcd(b,a%b);
}
ll expo(ll base,ll pow){
    ll ans = 1;
    while(pow!=0){
        if(pow&1==1){ans = ans*base;}
        base *= base;pow/=2;}return ans;
}
ll inv(ll x){return expo(x,mod-2);}

int vis[123];

void dfs(vector <vector <int> > vec, int n, pair <int,int> p1){
     vis[n] = 1;
     for(int i = 0; i < vec[n].size(); i++){
         int x = vec[n][i];
         pair <int,int> p2 = make_pair(x, n);
         pair <int,int> p3 = make_pair(n, x);
         if(p1 == p2 || p1 == p3) continue;
         if(!vis[x]){
            dfs(vec, x, p1);
         }
     }
}

int main(){
    //freopen("ip.txt", "rt", stdin);
    //freopen("op.txt", "wt", stdout);
    int n, k1;
    cin >> n >> k1;
    vector <int> vecx, vecy;
    vector <pair<int, int> > vec;
    for(int i = 0; i < n; i++){
        int x1, y1;
        cin >> x1 >> y1;
        vecx.push_back(x1);
        vecy.push_back(y1);
        vec.push_back({x1, y1});
    }

    sort(vecx.begin(), vecx.end());
    sort(vecy.begin(), vecy.end());

    sort(vec.begin(), vec.end());
    ll ans = 9e18;

    for(int i = 0; i < vecy.size(); i++){
        for(int j = i; j < vecy.size(); j++){
            for(int k = 0; k < vecx.size(); k++){
                int n1 = 0;
                int ymin = vecy[i], ymax = vecy[j];
                int xmin = vecx[k], xmax;

                for(int i1 = 0; i1 < vec.size(); i1++){
                    //cout << n1 << " " << k1 << endl;
                    if(ymin <= vec[i1].second && vec[i1].second <= ymax){
                       if(xmin <= vec[i1].first){
                          n1++;
                          if(n1 >= k1){
                             xmax = vec[i1].first;
                             break;
                          }
                       }
                    }
                }
                if(n1 < k1) continue;
                //cout << ymin << " " << ymax << " " << xmin << " " << xmax << endl;
                ll ans1 = (1LL*ymax - 1LL*ymin)*(1LL*xmax - 1LL*xmin);
                if(ans1 < ans) ans = ans1;
            }
        }
    }
    cout << ans;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 200111

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

int grundy(int a, int k){
	if(a < k)
		return 0;

	if(a % k == 0)
		return a / k;

	int x = a / k + 1;
	a -= (a % k) / x * x;

	if(a % k == 0)
		return a / k;

	return grundy(a - x, k);
}

int main(){
	int n;
	scanf("%d", &n);
	
	int cur = 0;
	while(n--){
		int a, k;
		scanf("%d%d", &a, &k);
		cur ^= grundy(a, k);
	}

	if(cur != 0)
		printf("Takahashi\n");
	else
		printf("Aoki\n");
	
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for((i)=1;(i)<=(n);(i)++)
using namespace std;
string st;
int dp[305][305][305],n,m,i,j,k;
int main(){
	cin>>st>>m;n=st.length();st=" "+st;
	rep(i,n) dp[i][i][0]=1;
	rep(i,n-1) if(st[i]==st[i+1]) dp[i][i+1][0]=2; else dp[i][i+1][1]=2;
	for(i=n;i>=1;i--){
		for(j=i+1;j<=n;j++){
			for(k=0;k<=m;k++){
				dp[i][j][k]=max(dp[i][j][k],max(dp[i+1][j][k],dp[i][j-1][k]));
				if(i+1<=j-1&&st[i]==st[j]) dp[i][j][k]=max(dp[i][j][k],dp[i+1][j-1][k]+2);
				if(i+1<=j-1&&k) dp[i][j][k]=max(dp[i][j][k],dp[i+1][j-1][k-1]+2);
			}
		}
	}
	int ans=0;
	for(k=0;k<=m;k++) ans=max(ans,dp[1][n][k]);
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    string a[n],b[n],c[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        c[i] = b[i] = a[i];
    }
    //c[n]はそのままの形で保存

    //bubblesort
    for(int i = 0; i < n; i++){
        for(int j = n-1; j >= i+1; j--){
            if(a[j][1] < a[j-1][1]){
                string tmp = a[j];
                a[j] = a[j-1];
                a[j-1] = tmp;
            }
        }
    }

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

    //bubblesort stable judge
    bool bst = true;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int p = 0; p < n; p++){
                for(int q = p+1; q < n; q++){
                    if(c[i][1] == c[j][1] && c[i] == a[q] && c[j] == a[p]){
                        bst = false;
                    }
                }
            }
        }
    }
    if(bst){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }

    //selectionsort
    for(int i = 0; i < n; i++){
        int minj = i;
        for(int j = i; j < n; j++){
            if(b[j][1] < b[minj][1]){
                minj = j;
            }
        }
        string tmp = b[i];
        b[i] = b[minj];
        b[minj] = tmp;
    }
    for(int i = 0; i < n-1; i++){
        cout << b[i] << " ";
    }
    cout << b[n-1] << endl;

    //selectionsort stable judge
    bool sst = true;
    for(int i = 0; i < n; i++){
        if(a[i] != b[i]){
            sst = false;
        }
    }
    if(sst){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
    return 0;
}


Measured memory_bytes: 3204
#!/usr/bin/env python3
import sys


def solve(N: int, s: "List[str]"):
    x = 0; a = 0; b = 0
    ans2 = 0
    for i in s:
        ans2 += i.count('AB')
        if(i[0] == 'B' and i[-1] == 'A'):
            x += 1
        elif(i[-1] == 'A'):
            a += 1
        elif(i[0] == 'B'):
            b += 1
    
    #####    AC2   ####
    ans1 = max(0,x-1) + min(a,b)
    if((a > 0 or b >0) and x > 0):
        ans1 += 1
    
    print(ans1+ans2)
    
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
#include <stdio.h>
int main(){
  int d,n,k;
  scanf("%d %d",&d,&n);
  if(n==100){n++;}
  if(d==0){k=n;}
  else if(d==1){k=n*100;}
  else{k=n*10000;}
  printf("%d\n",k);
}

Measured memory_bytes: 1724
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)

//union-find
#define UFLIMIT (1<<17)
int unicnt[UFLIMIT+10];//正ならcnt、非正なら根のindex
void ufinit(int n){rep(i,0,n)unicnt[i]=1;}
int root(int x){return unicnt[x]<=0?-(unicnt[x]=-root(-unicnt[x])):x;}
int same(int x,int y){return root(x)==root(y);}
void uni(int x,int y){if((x=root(x))==(y=root(y)))return;if(unicnt[x]<unicnt[y]){int t=x;x=y;y=t;}unicnt[x]+=unicnt[y];unicnt[y]=-x;}
#undef UFLIMIT

ll d4[]={0,1,0,-1,0};
int main(){
	ll w,h;
	while(scanf("%lld%lld",&w,&h),w){
		char s[30][30]={};
		ufinit(w*h);
		rep(i,1,h+1)scanf(" %s",s[i]+1);
		rep(i,1,h+1)rep(j,1,w+1)if(s[i][j]=='.'||s[i][j]=='@'){
			rep(k,0,4){
				ll ii=i+d4[k];
				ll jj=j+d4[k+1];
				if(s[ii][jj]=='.'||s[ii][jj]=='@')uni((i-1)*w+(j-1),(ii-1)*w+(jj-1));
			}
		}
		rep(i,1,h+1)rep(j,1,w+1)if(s[i][j]=='@')printf("%lld\n",unicnt[root((i-1)*w+(j-1))]);
	}
}


Measured memory_bytes: 2032