akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const static int MOD = 1000000007;

int main(){
	int N, P;
	scanf("%d %d\n", &N, &P);
	char S[N+1];
	scanf("%s", S);
	int digit[N];
	for (int i = 0; i < N; ++i) digit[i] = S[i] - '0';
	ll answer = 0;
	if(P == 2){
		for (int i = 0; i < N; ++i){
			if(digit[i] == 0 || digit[i] == 2 || digit[i] == 4 || digit[i] == 6 || digit[i] == 8){
				answer += i+1;
			}
		}
		printf("%lld\n", answer);
		return 0;
	}else if(P == 5){
		for (int i = 0; i < N; ++i){
			if(digit[i] == 0 || digit[i] == 5){
				answer += i+1;
			}
		}
		printf("%lld\n", answer);
		return 0;
	}else{
		int ten = 1, r[N];
		r[N-1] = digit[N-1] % P;
		for (int i = N - 2; i >= 0; --i)
		{
			ten = ten*10 % P;
			r[i] = (r[i+1] + ten*digit[i]) % P;
		}
		sort(r, r + N);
		answer += distance(r, upper_bound(r, r + N, 0));
		int *it = r;
		while(it != r + N){
			ll same = distance(it, upper_bound(r, r + N, *it));
			answer += same*(same - 1) >> 1;
			it = upper_bound(r, r + N, *it);
		}
		printf("%lld\n", answer);
	}
	return 0;
}

Measured memory_bytes: 1920
N = int(input())
hint_array = [list(map(int, input().split())) for i in range(N)]
hint_array = sorted(hint_array, key=lambda x: -x[2])
can_center_array = [[0] * 101 for i in range(101)]

x, y, h = hint_array[0]
for i in range(101):
    for j in range(101):
        can_center_array[i][j] = h + abs(i - x) + abs(j - y)
# print(can_center_array)
# exit()
for hint in hint_array[1:]:
    x, y, h = hint
    # print(x,y,h,"hoge")
    ans_x = 0
    ans_y = 0
    ans_h = 0
    can_put_num = 0
    for i in range(101):
        for j in range(101):
            if can_center_array[i][j] == 0:
                continue
            if can_center_array[i][j] == (h + abs(i - x) + abs(j - y)):
                can_put_num += 1
                if can_put_num == 1:
                    ans_x = i
                    ans_y = j
                    ans_h = can_center_array[i][j]
            else:
                can_center_array[i][j] = 0
    if can_put_num == 1:
        print(ans_x, ans_y, ans_h)
        exit()

Measured memory_bytes: 42736
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=4e3+10;
const int mod=998244353;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n,k,C[N][N],pw[N],f[N][N],s[N][N];
void init() {
    const int n=4e3;
    for(int i=0;i<=n;i++) {
        C[i][0]=1;
        for(int j=1;j<=i;j++) C[i][j]=add(C[i-1][j],C[i-1][j-1]);
    }
    pw[0]=1;for(int i=1;i<=n;i++) pw[i]=2ll*pw[i-1]%mod;
    auto calc=[&](int x) {
                  for(int i=0;i<=n;i++) s[x][i]=add(i?s[x][i-1]:0,f[x][i]);
              };
    f[0][0]=1,calc(0);
    for(int i=1;i<=n;i++) {
        for(int j=0;j<=n;j++) f[i][j]=add(f[i-1][j],j?2ll*s[i-1][j-1]%mod:0);
        calc(i);
    }
}
int g(int i,int j) {
    if(i==0) return j==0;
    return C[i+j-1][i-1];
}
int solve(int x,int z,int n) {
    int ret=0;
    for(int i=0;i<=n;i++) inc(ret,1ll*f[z][i]*g(x-z-z,n-i)%mod);
    return ret;
}
int solve(int x) {
    int y=0,z=0;
    for(int i=1;i<=k;i++) {
        int j=x-i;
        if(i==j) ++y;
        else if(i<j&&j<=k) ++z;
    }
    int ret=solve(k-y,z,n);
    if(y) inc(ret,solve(k-y,z,n-1));
    return ret;
}
int main() {
    k=gi(),n=gi(),init();
    for(int i=2;i<=2*k;i++) printf("%d\n",solve(i));
    return 0;
}


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

string s;
bool vis[30];

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> s;
    if(s.length() < 26){
        for(int i = 0;i < s.length();i++){
            vis[s[i] - 'a'] = true;
        } 
        for(int i = 0;i < 26;i++){
            if(!vis[i]){
                s = s + (char)('a' + i);
                cout << s << endl;
                break;
            }
        }
    }else{
        int len = s.length();
        for(int i = len - 2;i >= 0;i--){
            int id = -1;
            for(int j = i + 1;j < len;j++){
                if(s[j] > s[i]){
                    if(id == -1){
                        id = j;
                    }else{
                        if(s[j] < s[id]){
                            id = j;
                        }
                    }
                }
            } 
            if(id != -1){
                swap(s[i], s[id]);
                s = s.substr(0, i + 1);
                cout << s << endl;
                return 0;
            }
        }
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        double x1 = scan.nextDouble();	// １つ目の座標を代入
        double y1 = scan.nextDouble();	
        
        double x2 = scan.nextDouble();	// ２つ目の座標を代入
        double y2 = scan.nextDouble();	
            
            		// 結果を表示
        System.out.println( dist( x1, y1, x2, y2 ) );
    }
            
            
            	// (x1,y1)-(x2,y2)の直線距離を計算するメソッド
        private static double dist( double x1, double y1, double x2, double y2 ){
            	double l;
            	double dx, dy;
            
            		// x座標の差を計算してdxに代入
           		dx = x2 - x1;
            		// y座標の差を計算してdyに代入
            	dy = y2 - y1;
           
           		// ２点間の距離を計算してlに代入
            	l = Math.sqrt( dx * dx + dy * dy );
           
            		// 計算した距離を返す
            	return l;
        }


}



Measured memory_bytes: 28088
/**********************************************
 *Author*        :jxf378440404
 *Created Time*  : 2018/10/27 20:00:29

*********************************************/

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
const int Inf = 1 << 30;

int a[MaxN + 5];

int main()
{
	int n,p,q;
	LL ans;
	while(~scanf("%d",&n)){
		for(int i = 1;i <= n;i++) scanf("%d",&a[i]);
		sort(a + 1,a + 1 + n);
		p = 1;q = n;
		ans = abs(a[1] - a[n]);
		for(int i = 2;i <= n / 2;i++){
			ans += (LL)abs(a[p] - a[n - i + 1]) + (LL)abs(a[q] - a[i]);
			p++;
			q--;
		}
		if(n & 1){
			ans += (LL) max(abs(a[n / 2 + 1] - a[q]) , abs(a[n / 2 + 1] - a[p]));
		}
		printf("%lld\n",ans);
	}
    return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

string s;

int solve(int idx){
  if(idx>=s.length()) return -1;
  if(s[idx]!='m') return -1;
  idx++;
  if(idx>=s.length()) return -1;
  if(s[idx]!='e'){
    idx=solve(idx);
    if(idx==-1) return -1;
  }
  if(idx>=s.length()) return -1;
  if(s[idx]!='e') return -1;
  idx++;
  if(idx>=s.length()) return -1;
  if(s[idx]!='w'){
    idx=solve(idx);
    if(idx==-1) return -1;
  }
  if(idx>=s.length()) return -1;
  if(s[idx]!='w') return -1;
  return idx+1;
}

int main(){
  cin >> s;
  if(solve(0)==s.length()) cout << "Cat" << endl;
  else cout << "Rabbit" << endl;
  return 0;
}



Measured memory_bytes: 3204
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


typedef pair<int,int> pint;
int N;
int a[55];

vector<pint> solve() {
  vector<pint> res;
  int pMax = 0, mMax = 0;
  int pMaxInd = -1, mMaxInd = -1;
  for (int i = 0; i < N; ++i) {
	if (a[i] > 0) if (chmax(pMax, a[i])) pMaxInd = i;
	if (a[i] < 0) if (chmax(mMax, -a[i])) mMaxInd = i;
  }
  if (pMax == 0 && mMax == 0) return res;

  if (pMax > mMax) {
	for (int i = 0; i < N; ++i) {
	  if (a[i] <= 0) {
		a[i] += a[pMaxInd];
		res.push_back(pint(pMaxInd, i));
	  }
	}
  }
  else {
	for (int i = 0; i < N; ++i) {
	  if (a[i] >= 0) {
		a[i] += a[mMaxInd];
		res.push_back(pint(mMaxInd, i));
	  }
	}
  }

  if (pMax > mMax) {
	for (int i = 1; i < N; ++i) {
	  res.push_back(pint(i-1, i));
	}
  }
  else {
	for (int i = N-2; i >= 0; --i) {
	  res.push_back(pint(i+1, i));
	}
  }
  return res;
}

int main() {
  while (cin >> N) {
	for (int i = 0; i < N; ++i) cin >> a[i];
	vector<pint> res = solve();
	cout << res.size() << endl;
	for (int i = 0; i < res.size(); ++i) {
	  cout << res[i].first+1 << " " << res[i].second+1 << endl;
	}
  }
}


















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

int main() {
	long long n,k;
	cin >> n >> k;
	long long mod=1000000007;
	long long ans=0;
	long long a[n+2];
	a[0]=0;
	for(long long i=1;i<=n+1;i++){
		a[i]=a[i-1]+i-1;
	}
	for(long long i=k;i<=n+1;i++){
		ans+=(((a[n+1]-a[n-i+1])-(a[i]-a[0])+1)%mod);
		ans=ans%mod;
	}
	cout << ans << endl;
}


Measured memory_bytes: 5088
N = int(input())
ans = 0
cnt = [[0 for j in range(10)] for i in range(10)]
for i in range(1, N+1):
	s = str(i)
	a,b = int(s[0]), int(s[-1])
	cnt[a][b] += 1

for i in range(10):
	for j in range(10):
		ans += cnt[i][j] * cnt[j][i]
print(ans)

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

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define dbg(x) std::cerr<<#x<<" = " << (x) << std::endl
#define pnl(x) std::cout << x << "\n"

typedef	std::vector<int>	vi;
typedef std::pair<int,int>	ii;
typedef std::vector<std::string>	vs;
typedef std::vector<ii>	vii;
typedef std::vector<long long>	vl;
typedef	long long ll;


const int	NB_D = 4;
const int	DY[] = {-1, 1, 0, 0};
const int	DX[] = {0, 0, -1, 1};

int		main(void)
{
	std::ios_base::sync_with_stdio(false);
	int	N, Y;
	std::cin >> N >> Y;
	int	cpy = Y;
	int		count[3] = {};
	if (Y % 1000 != 0)
	{
		return 0;
	}
	count[0] = Y / 1000;
	count[1] += std::min(count[0] / 5, std::max(0, (count[0] - N ) / 4));
	count[0] -= 5 * count[1];
	

	count[2] += std::min(count[0] / 10, std::max(0, (count[0] + count[1] - N) / 9));
	count[0] -= 10 * count[2];


	count[2] += std::min(count[1] / 2, std::max(0, ((count[2] + count[0] + count[1] - N))));
	count[1] -= 2 * count[2];
	if (count[0] + count[1] + count[2] != N)
		pnl("-1 -1 -1");
	else
		std::cout << count[2] << " " << count[1] << " " << count[0] << std::endl;
}



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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    char a, b;
    cin >> a >> b;

    // 処理
    // 出力
    // HH	H
    // HD	D
    // DH	D
    // DD	H
    if (a == b) {
        cout << "H" << endl;
    } else {
        cout << "D" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
'use strict';

const chunks = [];
process.stdin.on("data", chunk => {
  chunks.push(chunk);
});
process.stdin.on("end", () => {
  const body = Buffer.concat(chunks).toString("utf8");
  main(body.trim());
});

function main(data) {
  const lines = data.split('\n');
  const firstLine = lines[0].split(' ').map(c => parseInt(c, 10));
  const N = firstLine[0]; // Attendees
  const K = firstLine[1]; // Points
  const Q = firstLine[2]; // Correct answers

  // Count only winners.
  const points = [];
  for (let i = 0; i < N; i++) {
    points.push(0);
  }

  for (let i = 0; i < Q; i++) {
    // -1 because one-indexed -> zero-indexed.
    const winner = parseInt(lines[1 + i], 10) - 1;
    points[winner]++;
  }

  for (let i = 0; i < N; i++) {
    if (K - (Q - points[i]) > 0) {
      console.log('Yes');
    } else {
      console.log('No');
    }
  }
}


Measured memory_bytes: 33584
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define All(obj) (obj).begin(),(obj).end()

using namespace std;


int main() {
	speed;
	int n;
	vector<int> p;
	cin >> n;
	rep(i, n) {
		int b;
		cin >> b;
		p.push_back(b);
	}
	sort(All(p));
	int sum = 0;
	int& last = p.back();
	rep(i, n - 1) {
		sum += p.at(i);
	}
	sum += last / 2;
	cout << sum;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

A, B = [int(x) for x in input().split()]


def saisho_kouyakusu(a, b):
    a, b = max(a, b), min(a, b)
    if a%b==0:
        return b
    else:
        return saisho_kouyakusu(b,a%b)

skys=saisho_kouyakusu(A,B)
Ad=A/skys
print(int(Ad*B))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[5];
  int sum=0;
  for(int i=0;i<5;i++){
    cin>>a[i];
    if(a[i]<40){
      sum+=40;
    }else{
      sum+=a[i];
    }
  }
  cout<<sum/5<<endl;
  return 0;
}

Measured memory_bytes: 1160
S = input()
list = [100 for i in range(len(S))]
list.append(100)
cnt = 0
min = 0
if S[0] == "<":
	cnt = 1
	list[0] = 0
if S[-1] == ">":
	list[len(S)] = 0
for i in range(len(S)-1):
	if S[i] == ">" and S[i+1] == "<":
		list[i+1] = 0
		cnt = 1
for i in range(len(S)):
	if S[i] == "<":
		if list[i] == 0:
			cnt = 1
		list[i+1] = cnt
		cnt += 1
#print("lsit",list)

for i in range(len(S)-1):
	if S[len(S) - i - 1] == ">" and S[len(S) - i - 2] == "<":
		list[len(S) - i-1] = max(list[len(S) - i-1],list[len(S) - i]+1)
	elif S[len(S) - i - 1] == ">":
		list[len(S) - i-1] = list[len(S) - i]+1		
if S[0] == ">":
	list[0] = list[1] + 1
#print(list)
print(sum(list))

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

mod = 998244353
fact = [1] * (n + 1)
ifact = [1] * (n + 1)

for i in range(n):
    fact[i + 1] = fact[i] * (i + 1) % mod
    ifact[i + 1] = pow(fact[i + 1], mod - 2, mod)


def comb(x, y):
    if y < 0 or y > x:
        return 0
    return (fact[x] * ifact[x - y] * ifact[y]) % mod


mm = [1]
for _ in range(n + 1):
    mm.append(mm[-1] * (m - 1) % mod)

ans = 0
for i in range(k + 1):
    ans += m * comb(n - 1, i) * mm[n - 1 - i]
    ans %= mod

print(ans)


Measured memory_bytes: 93368
a,b = map(int,input().split())

def func(a):
    if a%4==0:
        a = a
    elif a%4==1:
        a = 1
    elif a%4==2:
        a = 4*(a//4) + 3
    else:
        a = 0
    return a

x,y = func(a-1), func(b)
print(x^y)


Measured memory_bytes: 2940
n,k = map(int,input().split())
s = list(input())
 
l0 = []
l1 = []
pred = s[0]
if s[0] == "0":
    l0.append(1)
    l1.append(0)
else:
    l1.append(1)
 
for i in range(1,n):
    if pred == s[i]:
        if s[i] == "0":
            l0[-1] += 1
        else:
            l1[-1] += 1
    else:
        if s[i] == "0":
            l0.append(1)
        else:
            l1.append(1)
    pred = s[i]
if s[-1] == "0":    
    l1.append(0)
 
ans = sum(l0[:k])+sum(l1[:k+1])
tmp = ans
for i in range(k,min(len(l0),len(l1))):
    tmp -= l0[i-k]
    tmp -= l1[i-k]
    tmp += l0[i]
    tmp += l1[i+1]
    ans = max(ans, tmp)
print(ans)

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

using namespace std;

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

    int N, Q;
    string S;
    cin >> N >> S >> Q;

    vector<set<int>> A(26);
    for (int i = 0; i < N; i++) {
        A[S[i] - 'a'].insert(i);
    }

    while (Q--) {
        int op;
        cin >> op;

        if (op == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;

            for (auto&& a : A) {
                a.erase(i);
            }
            A[c - 'a'].insert(i);

        } else {
            int l, r;
            cin >> l >> r;
            l--, r--;

            int res = 0;
            for (auto&& a : A) {
                if (a.lower_bound(l) != a.upper_bound(r)) {
                    res++;
                }
            }

            cout << res << '\n';
        }
    }
}

Measured memory_bytes: 24184
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}
long long lopow(ll a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a ;
        n >>= 1;
    }
    return res;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;

int main(){
  ll N;cin>>N;
  vector<ll> A(N);
  rep(i,N)cin>>A[i];
  ll tot=1;
  ll zero=0;
  rep(i,N){
    if(A[i]==0)zero++;
  }
  if(zero>0)cout<<0<<endl;
  else{
    rep(i,N){
      if(A[i]<=1000000000000000000/tot){
        tot *=A[i];
      }
      else{
        tot = -1;
        break;
      }
    }
    
    cout<<tot<<endl;
  }
  
  
  
}


Measured memory_bytes: 4056
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define sz(x) int(x.size())
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

int main(){
	string s,t;
	cin>>s>>t;
	int n = sz(s), m=sz(t);
	vector<vector<int>> is(26);
	rep(i,n)
		is[s[i]-'a'].push_back(i);
	rep(i,n)
		is[s[i]-'a'].push_back(i+n);
	ll ans=0;
	int p = 0;
	rep(i,m){
		int c = t[i]-'a';
		if(sz(is[c])==0){
			puts("-1");
			return 0;
		}
		p=*lower_bound(is[c].begin(),is[c].end(), p)+1;
		if(p>=n){
			p-=n;
			ans+=n;
		}
	}
	ans+=p;
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1724
#include<iostream>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    int ans  =0;
    for(int i=0; i<N; i++){
        int h;
        cin >> h;
        if(h >= K) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                             \
  cerr << __LINE__ << ": " << #x << " = {";          \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) { \
    cerr << ((hoge) ? "," : "") << x[hoge];          \
  }                                                  \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W, K;
  cin >> H >> W >> K;
  int sum[H + 1][W + 1];
  fill(sum[0], sum[0] + W + 1, 0);
  for (int i = 0; i < H + 1; i++) sum[i][0] = 0;
  for (int i = 0; i < H; i++) {
    string S;
    cin >> S;
    for (int j = 0; j < W; j++) {
      sum[i + 1][j + 1] = S[j] - '0';
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      sum[i + 1][j + 1] += sum[i + 1][j];
    }
  }
  for (int j = 0; j < W; j++) {
    for (int i = 0; i < H; i++) {
      sum[i + 1][j + 1] += sum[i][j + 1];
    }
  }
  int ans = INT_MAX;
  for (int s = 0; s < (1 << (H - 1)); s++) {
    int a = __builtin_popcount(s);
    vector<int> ii = {0};
    for (int i = 0; i < H; i++)
      if ((s >> i) & 1) ii.push_back(i + 1);
    ii.push_back(H);
    int l = 0;
    for (int j = 1; j <= W; j++) {
      int cnt_max = 0;
      for (int k = 1; k < ii.size(); k++) {
        cnt_max = max(cnt_max, sum[ii[k]][j] - sum[ii[k]][l] - sum[ii[k - 1]][j]
                                   + sum[ii[k - 1]][l]);
      }
      if (cnt_max > K) {
        if (l == j - 1) {
          j = W + 1;
          a = INT_MAX;
          break;
        }
        a++;
        l = j - 1;
      }
    }
    ans = min(ans, a);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3664
import itertools
n, m, x = map(int, input().split())
T = [list(map(int, input().split())) for _ in range(n)]

flag1 = True
ans = -1

for i in range(1, n + 1):
    if i == 1:
        for j in range(n):
            flag = True
            for k in range(m):
                if T[j][k + 1] < x:
                    flag = False
                    break

            if flag == True and flag1 == True:
                ans = T[j][0]
                flag1 = False
            elif flag == True:
                ans = min(ans, T[j][0])

    else:
        tmp = list(itertools.combinations(range(1, n + 1), i))
        for j in range(len(tmp)):
            flag = True
            M = [0] * m
            tmp1 = 0
            for k in range(len(tmp[j])):
                for l in range(m):
                    M[l] = M[l] + T[tmp[j][k] - 1][l + 1]
                tmp1 = tmp1 + T[tmp[j][k] - 1][0]

            for k in range(m):
                if M[k] < x:
                    flag = False
                    break

            if flag == True and flag1 == True:
                ans = tmp1
                flag1 = False
            elif flag == True:
                ans = min(ans, tmp1)

print(ans)

Measured memory_bytes: 9276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n){
        cin >> a[i];
    }
    ll c = 0;
    if(n % 2){
        for(ll i = n-1; i >= 0; i -= 2){
            cout << a[i] << (c+1 == n ? "\n" : " ");
            c++;
        }
        for(ll i = 1; i < n; i += 2){
            cout << a[i] << (c+1 == n ? "\n" : " ");
            c++;
        }
    }else{
        for(ll i = n-1; i >= 0; i -= 2){
            cout << a[i] << (c+1 == n ? "\n" : " ");
            c++;
        }
        for(ll i = 0; i < n; i += 2){
            cout << a[i] << (c+1 == n ? "\n" : " ");
            c++;
        }
    }
    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        // 入力を受け付けるためのダミーです.
        var N = int.Parse(Console.ReadLine());

        var list = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();

        list.Sort( (A, B) => B - A );

        var first = list.First();
        bool result = first < list.Sum() - first;

        Console.Write(result == false ? "No" : "Yes");
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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;
}

int main() {
  int A, B;
  cin >> A >> B;
  if((A+B)%2==0){
    cout << (A+B)/2 << endl;
  }else{
    cout << "IMPOSSIBLE" << endl;
    
  }
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

class SegTreeMin {
private:
    const int INF = (1LL << 31) - 1;
    int n;  // width of bottom
    vector<int> dat;

public:
    SegTreeMin(int _n) {
        n = 1;
        while (n < _n) n *= 2;
        dat.clear();
        dat.resize(2 * n - 1, INF);
    }

    void update(int k, int a) {
        k += n - 1;
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }

    // get min value in [a, b)
    // dat[k] corresponds to [l, r)
    int query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return INF;
        if (a <= l && r <= b) return dat[k];
        return min(query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r));
    }

    int query(int a, int b) { return query(a, b, 0, 0, n); }
};

int const MAX_N = 200010;
int n;
int a[MAX_N];
int pos[MAX_N];
SegTreeMin seg(MAX_N);

// [l, r)
int dfs(int l, int r) {
    // cout << l << " " << r << endl;
    if (l == r) return 0;
    // if (l + 1 == r) return a[l];
    int x = seg.query(l, r);
    int idx = pos[x];
    return x * (r - idx) * (idx - l + 1) + dfs(l, idx) + dfs(idx + 1, r);
}

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

    cin >> n;
    rep(i, n) cin >> a[i];

    rep(i, n) {
        pos[a[i]] = i;
        seg.update(i, a[i]);
    }

    cout << dfs(0, n) << endl;

}


Measured memory_bytes: 98048
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

const int maxn = 1e5 + 5;
int dp[maxn][4], n;
string s;

int f(int i, int x){
    if(i == n) return x == 3;
    if(dp[i][x] != -1){
        return dp[i][x];
    }
    int ret = 0;
    if(s[i] == 'A'){
        if(x == 0) ret = add(ret, f(i + 1, 1));
        ret = add(ret, f(i + 1, x));
    }
    else if(s[i] == 'B'){
        if(x == 1) ret = add(ret, f(i + 1, 2));
        ret = add(ret, f(i + 1, x));
    }
    else if(s[i] == 'C'){
        if(x == 2) ret = add(ret, f(i + 1, 3));
        ret = add(ret, f(i + 1, x));
    }
    else{
        if(x == 0) ret = add(ret, f(i + 1, 1));
        ret = add(ret, f(i + 1, x));
        if(x == 1) ret = add(ret, f(i + 1, 2));
        ret = add(ret, f(i + 1, x));
        if(x == 2) ret = add(ret, f(i + 1, 3));
        ret = add(ret, f(i + 1, x));
    }
    return dp[i][x] = ret;
}

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

  cin >> s;
  n = s.size();
  memset(dp, -1, sizeof dp);
  cout << f(0, 0);
}

Measured memory_bytes: 6736
N=int(input())
mod=998244353

FACT=[1]
for i in range(1,N+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(N,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

POW=[1]
for i in range(N):
    POW.append(POW[-1]*2%mod)

def Combi(a,b):
    return FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod

SC=0
for i in range(N//2+1,N+1):
    SC+=Combi(N,i)*POW[N-i]

print((pow(3,N,mod)-SC*2)%mod)

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

#define int long long
#define DEBUG(x) cerr <<#x<<":"<<x<<endl;
#define DEBUG2(x, y) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define DEBUG3(x, y, z) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define DEBUGVC(x) cerr <<#x<<": "; for(auto a:x) cerr << a <<" "; cerr << endl;
#define DEBUGMP(x) cerr <<#x<<":"<<endl; for(auto a:x) cerr << a.first <<" "<< a.second << endl;
#define MAX_N (1000006)
#define INF (1LL << 60)
const int MOD = (int)1e9+7;


signed main() {
    while(1) {
        int n;
        cin >> n;
        if(n==0) return 0;
        vector<int> a(n);
        for(int i=0; i<n; i++) cin >> a[i];
        sort(a.begin(), a.end());
        int ans = INF;
        for(int i=0; i<n-1; i++){
            int d = abs(a[i]-a[i+1]);
            ans = min(ans, d);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
long long int arr[1000001];
long long int num[1000001];
  void fib(int n)
  {for(int i=2;i<=n;i++)
  arr[i]=min(arr[i-1]+abs(num[i]-num[i-1]),arr[i-2]+abs(num[i]-num[i-2]));
  }
int main()
{ int n;
  arr[0]=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++)
  scanf("%d",&num[i]);
  arr[1]=abs(num[1]-num[0]);
   fib(n);
 cout<<arr[n-1];
 
}

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

int main(void)
{
	int n; cin >> n;
	int x[n]; rep(i, n) cin >> x[i];
	int sum, ans;

	ans = (int)1e9;
	rep(i, 100) 
	{
		sum = 0;
		rep(j, n)
			sum += (x[j] - (i + 1)) * (x[j] - (i + 1));
		ans = min(ans, sum);
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  if(N % 2 == 0) {
    double a = N;
    cout << fixed << setprecision(7) << a / (2 * a) << endl;
  }
  else {
    double a = N;
    cout << fixed << setprecision(7) << (a + 1) / (2 * a) << endl;
  }
}

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

scores = [[0, False] for _ in range(n+1)]

for _ in range(m):
    p, S = input().split()
    p = int(p)

    if scores[p][1]:
        continue

    if S == "AC":
        scores[p][1] = True
        continue

    if S == "WA":
        scores[p][0] += 1

score = pena = 0
for count, ac in scores:
    if ac:
        score += 1
        pena += count

print(score, pena)


Measured memory_bytes: 13172
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h1 = sc.nextInt();
		int m1 = sc.nextInt();
		int h2 = sc.nextInt();
		int m2 = sc.nextInt();
		int k = sc.nextInt();
		int time = (60*h2) + m2 - (60*h1) - m1;
		if (time > k) {
			System.out.println(time-k);
			return;
		} else {
			System.out.println(0);
		}


	}

}


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

int main() {
	int n;
	cin >> n;
	vector < pair < int, int> > a(n);
	vector < int > b(n);
	for ( int i = 0; i < n; i++ ) {
		cin >> a[i].first;
		a[i].second = i;
	} 
	sort( a.begin(), a.end() );
	int mx1 = a[n / 2].first, mx2 = a[n / 2 - 1].first;
	for ( int i = 0; i < n; i++ ) {
		if ( i >= n / 2 ) {
			b[ a[i].second ] = mx2;
		}
		else {
			b[ a[i].second ] = mx1;			
		}
	}
	for ( auto i: b ) cout << i << '\n';
}


Measured memory_bytes: 4480
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define Yes()           printf("Yes\n")
#define No()            printf("No\n")
#define YES()           printf("YES\n")
#define NO()            printf("NO\n")
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int n, h, w; cin >> n >> h >> w;
  int ans = 0;
  rep(i, n) {
    int a, b; cin >> a >> b;
    if (a >= h && b >= w) ans++;
  }
  outl(ans);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 888
#include <stdio.h>

int main(){
	int i;
	char in[20];
	
	/*
	for(i = 0; i < 20; i++){
		in[i] = '\0';
	}
	*/
	
	scanf("%s", in);
	
	for(i = 19; i > -1; i--){
		if(in[i] != '\0'){
			printf("%c", in[i]);
		}
	}
	
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 0
// 解答不能.
// hakusye氏.
// https://atcoder.jp/contests/abc158/submissions/10646289
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){
    int n, p;
    scanf("%d %d", &n, &p);
    char c[202020];
    scanf("%s", c);
    string s(c);
    LL ans = 0;
    if(p == 5 || p == 2){
        LL cnt = 1;
        rep(i, n) if((s[i] - '0') % p == 0) ans += i + 1;
    }else{
        // mod p の個数を格納.
        vector<int> pnum(p, 0);
        // 割り切れている場合は Uiのみで簡潔してるため.
        pnum[0] = 1;
        int base = 1, sum = 0;
        repr(i, n - 1, 0){
            sum = (sum + base * (s[i] - '0')) % p;
            ans += pnum[sum]++;
            base = base * 10 % p;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 640
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

long long N;
string S = "";
string A = "";
int flag = 0;
map<string, int> hashTable;

int main() {
	scanf("%lld", &N);
	cin >> S;
	hashTable[S] = 1;
	for(int i = 0; i < N - 1; i++) {
		cin >> A;
		if(hashTable[A] == 1) {
			flag = 1;
		}
		if(A[0] != S[S.size() - 1]) {
			flag = 1;
		}
		S = A;
		hashTable[A] = 1;
	}
	if(flag) {
		printf("No\n");
	}
	else {
		printf("Yes\n");
	}

	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include <stdio.h>

int main()

{

  int n,m,l;
  int i,j,k;
  int box1[100][100]={{0}};
  int box2[100][100]={{0}};

  long box3[100][100]={{0}};
    
  scanf("%d%d%d",&n,&m,&l);
    
  for(i=0; i<n; i++)
    {
      for(j=0; j<m; j++)
	{
	  scanf("%d",&box1[i][j]);
        }
    }
    
  for(i=0; i<m; i++)
    {
      for(j=0; j<l; j++)
	{
	  scanf("%d",&box2[i][j]);
        }
    }
    
  for(i=0; i<n; i++)
    {
      for(j=0; j<l; j++)
	{
	  for(k=0; k<m; k++)
	    {
	      box3[i][j] += box1[i][k]*box2[k][j];
            }
        }
    }
    
  for(i=0; i<n; i++)
    {
      for(j=0; j<l; j++)
	{

	  printf("%ld",box3[i][j]);

	  if(j == l-1)  printf("\n");

	  else  printf(" ");
        }
    }
    
  return 0;
}



Measured memory_bytes: 2108
N, A, B = map(int, input().split())
H = [int(input()) for i in range(N)]
    
def f(x):
    s = sum([- (- max(0, h - x * B) // (A - B)) for h in H])
    if s <= x:
        return True
    else:
        return False
    
l = 0
r = 10 ** 9 + 7
while l < r:
    m = (l + r) // 2
    if f(m):
        r = m
    else:
        l = m + 1
    # print(r, l, m)
        
print(r)

Measured memory_bytes: 11060
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(void) {
	int k;
	string str;
	cin >> k >> str;

	for (int i = 0; i < str.size(); i++) {
		if (i >= k) {
			cout << "..." << flush;
			break;
		}
		cout << str[i] << flush;

	}

	cout << endl;
	return 0;

}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a)  (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  int n,a,b,c,d; cin >> n >> a >> b >> c >> d;
  a--;b--;c--;d--;
  string s; cin >> s;
  int end = max(c,d);
  for (int i = a; i < end; i++) {
    if(s[i] == '#' && s[i-1] == '#'){
      std::cout << "No" << '\n';
      return 0;
    }
  }
  if (c < d) {
    std::cout << "Yes" << '\n';
    return 0;
  }

  string ans = "No";
  for (int i = b; i <= d; i++) {
    if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.'){
      ans = "Yes";
      break;
    }
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long int k;
    cin>>k;
    long int a[n],dp[k+1];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<a[0];i++)
    {
        dp[i]=0;
    }
    for(int i=a[0];i<=k;i++)
    {
        for(int j=0;j<n;j++)
        {
            dp[i]=0;
            if(i>=a[j])
            {
                if((1+dp[i-a[j]])%2)
                {
                    dp[i]=1;
                    break;
                }
            }
        }
    }
    if(dp[k]%2)
    {
        cout<<"First";
    }else
    {
        cout<<"Second";
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  int X, Y, ans, min, max;
  cin >> X >> Y;
  ans = 0;
  min = 2 * X;
  max = 4 * X;
  if (Y % 2 != 0) {
    printf("No\n");
  }
  else if (min <= Y && Y <= max) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double eps = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1};

int main() {
	int n;
	while (cin >> n, n) {
		int ans = 0;
		string pre = "", now;
		rep(i, n) {
			cin >> now;
			if (pre[0] != now[0] && pre[1] == now[1]) ans++;
			pre = now;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, 0, n) cin >> h[i];
  sort(h.rbegin(), h.rend());

  ll ans = 0;
  rep(i, k, n) ans += h[i];
  cout << ans << endl;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	cout << (n - 2) * 180 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

template <class T>
inline void read(T &x)
{
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

std::string n;
int f[1010][10];
int dig[1010];
int k, len;

int dfs(int dep, bool isLimit, int status)
{
    if (status > k) return 0;
    if (!dep)   return status == k;
    if (!isLimit && ~f[dep][status])   return f[dep][status];
    int ans = 0, bit = isLimit ? dig[dep] : 9;
    for (int i = 0; i <= bit; ++i)
    {
        if (i) ans += dfs(dep - 1, isLimit && i == bit, status + 1);
        else    ans += dfs(dep - 1, isLimit && i == bit, status);
    }
    if (!isLimit)   f[dep][status] = ans;
    return ans;
}

int main()
{
    memset(f, -1, sizeof(f));
    std::cin >> n;
    read(k);
    len = n.size();
    for (int i = 0; i < len; ++i)   dig[len - i] = n[i] - 48;
    printf("%d\n", dfs(len, true, 0));
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

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

int digsum(int x) {
	return x == 0 ? 0 : (x%10)+digsum(x/10);
}

int main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    int n;
    cin >> n;
    int ans = INF;
    FOR(a, 1, n-1) {
    	int s = digsum(a)+digsum(n-a);
    	ans = min(ans, s);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256