akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int N;
  cin>>N;
  vector<string> S(N);
  rep(i,N)cin>>S[i];
  string ans="Yes";
  rep(i,N-1){
    if(S[i].back()!=S[i+1].front())ans="No";
  }
  rep(i,N){
    for(int j=i+1;j<N;j++){
      if(S[i]==S[j]){
        ans="No";
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<int, P> Pint;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k>0){
        if(k%2==1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k/=2;
    }
    return ans;
}
int main()
{
	
	int n;
  ll h[101];
  vector<ll> hs;
  cin>>n;
  for(int i=1; i<=n; i++){
    cin>>h[i]; hs.push_back(h[i]);
  }
  sort(hs.begin(), hs.end());
  hs.erase(unique(hs.begin(), hs.end()), hs.end());
  ll dp[2][100][100]={};
  vector<Pint> v;
  for(int i=hs.size()-1; i>=0; i--){
    bool nuo[102]={}, nuo2[102]={};
    for(int j=1; j<=n; j++){
      if(hs[i]<=h[j]) nuo[j]=1;
    }
    int l;
    for(int j=0; j<=n; j++){
      if(!nuo[j] && nuo[j+1]) l=j;
      if(nuo[j] && !nuo[j+1]){
        bool ok=0;
        for(int k=l+1; k<=j; k++){
          if(hs[i]==h[k]){
            ok=1;
            break;
          }
        }
        if(ok) v.push_back(Pint(hs[i], P(l+1, j)));
      }
    }
  }
  bool used[100]={};
  for(int i=0; i<v.size(); i++){
    int l=v[i].second.first, r=v[i].second.second, d0=v[i].first;
    //cout<<l<<" "<<r<<" "<<d0<<endl;
    bool no=1;
    dp[1][l][r]=2;
    ll prod=1, prod1=1;
    int ct=0;
    bool nuo=0;
    int ct2=0;
    for(int j=0; j<i; j++){
      int l1=v[j].second.first, r1=v[j].second.second;
      if(l>l1 || r1>r) continue;
      if(used[j]) continue;
      used[j]=1;
      no=0;
      if(r1!=l1) nuo=1;
      int d1=v[j].first;
      dp[1][l][r]*=(dp[1][l1][r1]*powmod(2ll, d1-d0-1)%MOD);
      dp[1][l][r]%=MOD;
      prod*=(dp[0][l1][r1]+dp[1][l1][r1]*powmod(2ll, d1-d0)%MOD);
      prod%=MOD;
      prod1*=(dp[1][l1][r1]*powmod(2ll, d1-d0)%MOD);
      prod1%=MOD;
      ct+=(r1-l1+1);
      ct2++;
    }
    if(no){
      dp[0][l][r]=(powmod(2ll, r-l+1)-2+MOD)%MOD;
    }else{
      if(nuo) dp[0][l][r]=((prod-prod1+MOD)*powmod(2ll, r-l+1-ct)%MOD+dp[1][l][r]*500000004%MOD*(powmod(2ll, r-l+1-ct+ct2)+MOD-2)%MOD)%MOD;
      else dp[0][l][r]=dp[1][l][r]*500000004%MOD*(powmod(2ll, r-l+1)+MOD-2)%MOD;
    }
    if(r-l+1==n){
      ll ans=dp[0][l][r]+dp[1][l][r]*powmod(2ll, d0-1)%MOD;
      ans%=MOD;
      cout<<ans<<endl;
    }
  }
	return 0;
}

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

int main(){
  long int i,j,n,k,wa=0,kai,kari;
  cin>>n>>k;
  long int a[n],f[n];
  for(i=0;i<n;i++){
    cin>>a[i];
    wa+=a[i];
  }
  for(i=0;i<n;i++){
    cin>>f[i];
  }
  sort(a,a+n);
  sort(f,f+n);
  kai=wa-k;
  if(kai<=0){
    cout<<0;
    return 0;
  }
  /* A さんの年齢の候補を表す区間を、[left, right) と表します */
    /* A さんは、left 歳以上 right 歳未満、right 歳自体は候補に含まれないことに注意 */
  long int left = 0, right = 1000000000000;

    /* A さんの年齢を 1 つに絞れないうちは繰り返す */
    while (right - left > 1) {
        long int mid = (right + left) / 2; // 区間の真ん中

      kari=0;
      for(i=0;i<n;i++){
        kari+=min(a[i],mid/f[n-1-i]);
      }
      
        /* 回答に応じて、年齢を絞る */
        if (kari<kai) left = mid; // mid 歳以上なら、mid 歳以上 right 歳以下になるように
        else right = mid; // mid 歳未満なら、left 歳以上 mid 歳未満になるように
    }
  
  cout<<right;
}


Measured memory_bytes: 3456
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
		//System.out.print(" ");
		Scanner scan = new Scanner(System.in);
		String word = "";		//???????????????string
		int[] shuffleBegin = new int[100]; //?????£?????????????§????
		String odai = "";
		String temp = "";
		String kansei = "";
		while(!temp.equals("-")){
			temp = scan.next();
			if(temp.equals("-")){
				break;
			}
			odai = temp;
			char[] odaiChar = odai.toCharArray();
			int odaiNagasa = odai.length();
//			T.add(tem) ;
			int kai = scan.nextInt();
			for(int i=0; i<kai; i++){
				shuffleBegin[i] = scan.nextInt();
				
			}
			for(int i =0;i<kai; i++){
				for(int ii=0; ii<(odaiNagasa - shuffleBegin[i]) ; ii++){
					word = word + odaiChar[ii + shuffleBegin[i]];
//					System.out.println(word);
				}
				for(int ii=0; ii<shuffleBegin[i]; ii++){
					word = word + odaiChar[ii];
//					System.out.println(word);
				}
			odaiChar = word.toCharArray();
			kansei = word;
			word = "";
			}
			System.out.println(kansei);		
			
		}
	}
}

Measured memory_bytes: 45892
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let n = scan!(usize);
    let vs = scan!(usize;;);
    let rev = vs.iter().rev().collect::<Vec<_>>();

    let mut ans = 0;
    for i in 0..rev.len() {
        let mut enable = true;
        for j in i + 1..rev.len() {
            if rev[i] < rev[j] {
                enable = false
            }
        }
        if enable {
            ans += 1
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    new_s=""
    for ss in s:
        if ss!='x':
            new_s+=ss
    if new_s[::-1]!=new_s:
        print(-1)
        sys.exit()
    right=len(s)-1
    left=0
    ans=0
    while right-left>0:
        if s[right]!=s[left]:
            if s[right]=='x':
                ans+=1
                right-=1
            elif s[left]=='x':
                ans+=1
                left+=1
        else:
            right-=1
            left+=1
    print(ans)



if __name__=='__main__':
    main()

Measured memory_bytes: 3316
n = int(input())
h = [int(i) for i in input().split()]
ans = 1
s = h[0]
for i in range(1, n):
    if h[i] - s <= -2:
        ans = 0
        break
    elif h[i] - s >= 2:
        s = h[i]
print("Yes") if ans == 1 else print("No")

Measured memory_bytes: 14252
import math

n = int(input())
lst = [int(i) for i in input().split()]
lst.sort(reverse=True)
primes = set()
flag = True
for i in range(n):
  num = lst[i]
  count = 0
  while num % 2 == 0:
    num //= 2
    count += 1
    if pow(2, count) in primes:
      flag = False
      break
    primes.add(pow(2, count))
  f = 3
  while f <= math.sqrt(lst[i]) and flag:
    count = 0
    while num % f == 0:
      num //= f
      count += 1
      if pow(f, count) in primes:
        flag = False
        break
      primes.add(pow(f, count))
    f += 2
  if num == 1:
    continue
  if num in primes or not flag:
    flag = False
    break
  primes.add(num)
if not flag:
  a = lst[0]
  for i in range(1, n):
    b = lst[i]
    c = math.gcd(a, b)
    a = c
  if a != 1:
    print('not coprime')
  else:
    print('setwise coprime')
else:
  print('pairwise coprime')


Measured memory_bytes: 197364
import java.util.*;
import java.lang.*;

class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int count = 1;

        for(int i = 0; i < N-1; i++){
          if(S.charAt(i) != S.charAt(i+1)){
            count ++;
          }
        }

        System.out.println(count);
    }
}







Measured memory_bytes: 24720
#include<bits/stdc++.h>
using namespace std;
int c[105],t[105];
int n,m,mn=10000000;
int main(){
  	cin>>n>>m;for(int i=1;i<=n;i++){cin>>c[i]>>t[i];mn=min(mn,t[i]);}
  	if(mn>m){cout<<"TLE";return 0;}
  	int mnn=1000000;
  	for(int i=1;i<=n;i++){
    	if(t[i]<=m)mnn=min(mnn,c[i]);
    }
  	cout<<mnn;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

int toIndex(char c)
{
	if (c == 'R')return 0;
	if (c == 'G')return 1;
	if (c == 'B')return 2;

	//cout << "nazo : " << c << endl;
	return 0;
}

void solve()
{
	int n;
	string s;
	cin >> n >> s;

	ll ans = 0;

	{
		ll cnt[3] = { 0, 0, 0 };
		for(const auto& c : s)
		{
			cnt[toIndex(c)]++;
		}
		ans = cnt[0] * cnt[1] * cnt[2];
	}

	for(int diff = 1; diff <= n / 2; ++diff)
	{
		for(int i = 0; i <= n - 1 - diff * 2; ++i)
		{
			int j = i + diff;
			int k = j + diff;
			if(s[i] != s[j] && s[i] != s[k] && s[j] != s[k])
			{
				ans--;
			}
		}
	}

	cout << ans << endl;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3620
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
    	ACBC146V.A();
    }
}

class ACBC146V {
	static Scanner sc = new Scanner(System.in);
	static void A() {
		String s = sc.next();
		final String[] WEEK = new String[]{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
		for (int i = 0; i < WEEK.length; i++) {
			if(WEEK[i].equals(s)) {
				System.out.println(7 - i);
			}
		}
	}
}

Measured memory_bytes: 21844
program name
    implicit none
    character(:),allocatable:: s
    integer(4):: n,i,cnt

    read*, n
    allocate(character(n):: s)
    read*, s
    cnt = 0
    do i=1,n-1
        cnt = max(cnt,snum(s(1:i), s(i+1:n)))
    end do
    print*, cnt

contains
function snum(s1, s2) result(ret)
    implicit none
    character(*):: s1, s2
    integer(4):: ret,i
    logical:: is1(ichar('a'):ichar('z')),is2(ichar('a'):ichar('z'))

    is1(:) = .false.
    is2(:) = .false.
    do i=1,len(s1)
        is1(ichar(s1(i:i))) = .true.
    end do
    do i=1,len(s2)
        is2(ichar(s2(i:i))) = .true.
    end do

    ret = 0
    do i=ichar('a'),ichar('z')
        if (is1(i) .and. is2(i)) ret=ret+1
    end do
end function snum
end program name

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long int;
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; }
const ll INF = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;

int main() {
    ll x,y,z,k;
    ll X[1005],Y[1005],Z[1005];
    vector<ll> cake1,cake2;
    cin >> x >> y >> z >> k;
    rep(i,x) cin >> X[i];
    rep(i,y) cin >> Y[i];
    rep(i,z) cin >> Z[i];
    rep(i,x){
        rep(j,y){
            cake1.push_back(X[i]+Y[j]);
        }
    }
    ll c = 0;
    SORT(cake1);
    rep(i,min(x*y,k)){
        rep(j,min(z,k)){
            cake2.push_back(cake1[x*y-i-1]+Z[z-j-1]);
            c++;
        }
    }
    SORT(cake2);
    rep(i,k) PRINT(cake2[c-i-1]);
}

Measured memory_bytes: 43108
#include <iostream>

using namespace std;

int main(){
  string s;
  cin >> s;
  
  int A = 1000000, Z = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'A' && i < A) A = i;
    if(s[i] == 'Z' && i > Z) Z = i;
  }
  
  cout << Z - A + 1;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

const int COINS[] = { 500, 100, 50, 10, 5, 1 };

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		n = 1000 - n;
		int answer = 0;
		for(int i = 0; n > 0; i++){
			while(n >= COINS[i]){
				n -= COINS[i];
				answer++;
			}
		}
		printf("%d\n", answer);
	}
	return 0;
}

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

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

int main(){
	int h,w;
	cin >> h >> w;
	char field[1005][1005];
	rep(i,h)rep(j,w) cin >> field[i][j];
	queue<pair<int,int>> que;
	int dist[1005][1005];
	rep(i,h)rep(j,w){
		dist[i][j] = -1;
		if(field[i][j] == '#'){
			que.push(make_pair(i,j));
			dist[i][j] = 0;
		}
	}
	
	while(!que.empty()){
		auto p = que.front();
		que.pop();
		rep(i,4){
			int ny = p.first + dy[i];
			int nx = p.second + dx[i];
			if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
			if(dist[ny][nx] != -1) continue;
			if(field[ny][nx] == '.'){
				que.push(make_pair(ny,nx));
				dist[ny][nx] = dist[p.first][p.second] + 1;
			}
		}
	}
	
	int ans = 0;
	rep(i,h)rep(j,h) ans = max(ans, dist[i][j]);
	
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13328
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let s = get!(String).chars().collect::<Vec<_>>();
    let len = s.len();
    let mut i = 0;
    while i + 1 < len {
        if s[i] == s[i+1] {
            println!("{} {}", i+1, i+2);
            return;
        } else if i+2 < len && s[i] == s[i+2] {
            println!("{} {}", i+1, i+3);
            return;
        }
        i += 1;
    }
    println!("{} {}", -1, -1);
}

Measured memory_bytes: 4352
import * as fs from 'fs';

const M = 10 ** 9 + 7;
const Mb = BigInt(M);

function modX(num: number) {
  return num % M;
}

function modX2(num1: number, num2: number) {
  return Number((BigInt(num1) * BigInt(num2)) % Mb);
}

function main(input) {
  input = input.split("\n");
  const N = parseInt(input[0]);
  const AList = input[1].split(' ').map(i => parseInt(i));
  let ans = 0;
  let sum = 0;
  for (let i = 1; i < N; i++) {
    sum += AList[i - 1];
    sum = modX(sum);
    ans += modX2(AList[i], sum);
    ans = modX(ans);
  }
  console.log('%s', ans);
}

main(fs.readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 60444
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define FOR(i,n) for(int i = 0; i < n; i++)
#define FORa(i,a,b) for(int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a,n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define UP(s) transform(s.begin(),s.end(),s.begin(),::toupper)

//-------------------------------------------------------//

int main() {
	int x, n, temp, best = 102;
	bool b[102];
	cin >> x >> n;
		
	FOR(i, 102) b[i] = false;	
	
	FOR(i, n) {
		cin >> temp;
		b[temp] = true;
	}
	
	for(int i = 0; i <= 101; i++) {
		if(!b[i] && abs(x-i) < abs(x-best)) {
			best = i;
		}
	}
	
	cout << best << endl;
	
	return 0;
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

signed main() {
  int A, B;
  cin >> A >> B;
  FOR(i, 1, 4) {
    if ((A * B * i) % 2 == 1) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;


public class B{
	
	public static void Main(){
	
		long n = Int64.Parse(Console.ReadLine());
		
		string[] word = new string[n];
		for( int i = 0; i < n; i++ ){
			word[i] = Console.ReadLine();
		}
		
		bool result = true;
		List<string> used = new List<string>();		
		used.Add(word[0]);
		for( int i = 1; i < n; i++ ){
			
			if( used.Contains(word[i]) ){
				result = false;
				break;
			}
			used.Add(word[i]);
			
			char last = (word[i-1])[(word[i-1]).Length - 1];
			if( last != (word[i])[0] ){
				result = false;
				break;
			}
			
		}
		
		Console.WriteLine( result ? "Yes" : "No" );
		
	}

}

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

const int maxn=100010;
int du[maxn];
int n,root;
struct Edge
{
	int v,next;
}	e[maxn<<1];
int g[maxn],tot;
int fa[maxn];
bool has[maxn];
int ans;
void addedge(int x,int y)
{
	tot++;
	e[tot].v=y;
	e[tot].next=g[x];
	g[x]=tot;
}
void dfs(int t)
{
	int son=du[t];
	if (fa[t]!=0)	son--;
	for (int i=g[t];i;i=e[i].next)
	if (e[i].v!=fa[t])
	{
		fa[e[i].v]=t;
		dfs(e[i].v);
		if (has[e[i].v])	son--,has[t]=true;
	}
	if (son>1)
	{
		ans+=son-1;
		has[t]=true;
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		x++;y++;
		addedge(x,y);
		addedge(y,x);
		du[x]++;
		du[y]++;
		if (du[x]>2)	root=x;
	}
	if (!root)
	{
		printf("1\n");
		return 0;
	}
	ans=0;
	fa[root]=0;
	dfs(root);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5120
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
ans = n+1-2
for i in range(1,1000001):
    if n % i == 0:
        j = n//i
        ans = min(ans, i+j-2)
print(ans)


Measured memory_bytes: 3064
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,copy
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
ab = [inpl() for _ in range(n)]
ab.sort()
if n%2:
    l = ab[n//2][0]
    ab.sort(key = lambda x:x[1])
    r = ab[n//2][1]
    print(r-l+1)
else:
    l1 = ab[n//2-1][0]
    l2 = ab[n//2][0]
    ab.sort(key = lambda x:x[1])
    r1 = ab[n//2-1][1]
    r2 = ab[n//2][1]
    print((r2+r1)-(l2+l1)+1)

Measured memory_bytes: 114684
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

//aのb乗を1000000007で割った余りを求める
llint power(llint a, llint b) {
	if (b == 1)return a;
	if (b == 0)return 1;
	llint tmp = power(a, b / 2);
	tmp *= tmp;
	tmp %= 1000000007;
	if (b % 2 == 1) {
		tmp *= a;
		tmp %= 1000000007;
	}
	return tmp;
}

int main() {
	int n;
	cin >> n;
	int nn = n;
	vint ans;
	int cnt = 1;
	for (int i = 2; i * i <= nn; i++) {
		if (n % i == 0) {
			ans.push_back(i);
			n /= i;
			while (n % i == 0) {
				cnt *= i;
				n /= i;
			}
		}
	}
	if (n != 1)ans.push_back(n);
	rep(i, ans.size()) {
		cnt *= (ans[i] - 1);
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3156
#include <stdio.h>
#include <cstdio>
#include <vector>
#include <iostream>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

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

int main(){
	vector<int> a(2);
	REP(i, 2) cin >> a[i];
	if (a[0] <= a[1]){
		printf("%d\n", a[0]);
	}else{
		printf("%d\n", a[0]-1);
	}
}


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

int main(){
	int a,b,c,d,e; cin>>a>>b>>c>>d>>e;
	if(a==0) cout << 1 << endl;
	else if(b==0) cout << 2 << endl;
	else if(c==0) cout << 3 << endl;
	else if(d==0) cout << 4 << endl;
	else cout << 5 << endl;
}

Measured memory_bytes: 3620
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); 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; }


int main(){
    ll n, a, b; cin >> n >> a >> b;
    vector<ll>X(n); rep(i, n)cin >> X[i];

    ll sum = 0;
    rep(i, n-1){
        sum += min((X[i+1] - X[i])*a, b);
    }
    cout << sum << ln;
}

Measured memory_bytes: 3900
//
// main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

int main() {
	ll H, W, h, w;
	cin >> H >> W >> h >> w;
	if (H % h == 0 && W % w == 0) {
		cout << "No" << endl;
		return 0;
	}
	bool swapped = false;
	if (W % w == 0) {
		swap(H, W);
		swap(h, w);
		swapped = true;
	}
	auto ans = make_vec_nd((ll)0, W, H);
	ll large = 1000000000;
	rep(y,0,H) {
		rep(x,0,W) {
			if (x % w == 0) {
				ans[x][y] = large - 1;
			} else if (x % w == w - 1) {
				ans[x][y] = -large;
			} else {
				ans[x][y] = 0;
			}
		}
	}
	if (swapped) {
		auto ans0 = ans;
		ans = make_vec_nd((ll)0, H, W);
		rep(y,0,H) {
			rep(x,0,W) {
				ans[y][x] = ans0[x][y];
			}
		}
		swap(W, H);
		swap(w, h);
	}
	cout << "Yes" << endl;
	rep(y,0,H) {
		rep(x,0,W) {
			cout << ans[x][y];
			if (x != W-1) {
				cout << " ";
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 8832
#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
typedef vector<string> S;
int n,m,k;string s;
map<string,int> cost;
map<string,S> recipe;
int dfs(string t){
	int ans=0;
	S vs=recipe[t];
	if(!vs.empty()){
		for(S::iterator it=vs.begin();it<vs.end();it++){ans+=dfs(vs.at(it-vs.begin()));}
		cost[t]=min(cost[t],ans);
		return cost[t];
	}else{
		return cost[t];
	}
	
}
int main()
{
	while(cin>>n&&n){
		cost.clear();recipe.clear();
		for(int i=0;i<n;i++){
			int tmp;
			cin>>s>>tmp;
			cost[s]=tmp;
		}
		cin>>m;
		for(int i=0;i<m;i++){
			S vs;vs.clear();
			string t;cin>>s>>k;
			while(k--){cin>>t;vs.push_back(t);}
			recipe[s]=vs;
		}
		cin>>s;
		cout<<dfs(s)<<endl;
	}
    return 0;
}

Measured memory_bytes: 1232
n,m=map(int,input().split())
a=[input()for i in range(n)]
b=[input()for i in range(m)]
cnt=False
for i in range(n-m+1):
    for j in range(n-m+1):
        t=[k[j:j+m]for k in a[i:i+m]]
        if t==b:
            cnt=True
print("Yes" if cnt else "No")


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;

int main() {
    ll h, w;    cin >> h >> w;
    ll d;   cin >> d;

    ll **a = new ll*[h];
    for (ll i = 0; i < h; i++)
        a[i] = new ll[w];

    vector<P> c(h*w+1);
    for (ll i = 0; i < h; i++) {
        for (ll j = 0; j < w; j++) {
            cin >> a[i][j];
            c[a[i][j]] = P(i, j);
        }
    }

    vector<ll> dp(h*w+1, 0);

    for (int k = 1; k <= h*w-d; k++) {
        dp[k+d] = abs(c[k+d].first - c[k].first) + abs(c[k+d].second - c[k].second) +dp[k];
    }


    ll q;   cin >> q;
    for (int i = 0; i < q; i++) {
        ll l, r;    cin >> l >> r;
        cout << dp[r] - dp[l] << endl;
    }

    return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    auto a = vector<vector<int>>(2, vector<int>(n, 0));
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> a[i][j];
        }
    }
    
    auto dp= vector<vector<int>>(2, vector<int>(n, 0));
    dp[0][0]=a[0][0];
    dp[1][0]=a[1][0] + a[0][0];
    for (int j = 1; j < n; j++)
    {
           dp[0][j]=dp[0][j-1]+a[0][j];
           dp[1][j]=max(dp[0][j],dp[1][j-1])+a[1][j];        
    }
    
    cout << dp[1][n-1];
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <limits>


using namespace std;


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

    int factors[1001];
    memset(factors, 0, sizeof(factors));

    for (int i = N; i >= 2; i--) {
        int x = i;
        while (x > 1) {
            for (int j = 2; j <=i; j++)
                if (x % j == 0) {
                    x /= j;
                    factors[j]++;
                    break;
                }
        }
    }

    long ans = 1;
    for (int i = 2; i <= N; i++) {
        if (factors[i] != 0) {
            // cout << i << ": " << factors[i] << endl;
            ans *= (factors[i] + 1);
            ans %= 1000000000 + 7;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
using namespace std;
int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	string a,b,c;
	a=S[0];
	b=S[1];
	c=S[2];
	bool af=false,bf=false,cf=false;
		if (a=="a"){
			af = true;
			}
		if (a=="b"){
			bf = true;
			}
		if (a=="c"){
			cf = true;
			}
		if (b=="a"){
			af = true;
			}
		if (b=="b"){
			bf = true;
			}
		if (b=="c"){
			cf = true;
			}
		if (c=="a"){
			af = true;
			}
		if (c=="b"){
			bf = true;
			}
		if (c=="c"){
			cf = true;
			}
	if (af==bf&&af==cf){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
let n, a, b, c = Scanf.scanf " %d %d %d %d" @@ fun n a b c -> n, a, b, c
let ls = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let f m l =
  let len = ref 0 in
  let c = ref 0 in
  for i = 0 to n - 1 do
    if m lsr i land 1 = 1 then
      (len := !len + ls.(i); incr c)
  done;
  max 0 (!c - 1) * 10 + (abs @@ l - !len)
let g i j k = f i a + f j b + f k c
let ans = ref max_int
let _ =
  for i = 1 to 255 do
    for j = 1 to 255 do
      if i land j = 0 then
        for k = 1 to 255 do
          if i land k = 0 && j land k = 0 then
            ans := min !ans @@ g i j k
        done
    done
  done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 512
# 入力
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

s = ns()

ai = s.index("A")
zi = len(s) - s[::-1].index("Z") - 1

print(zi - ai + 1)

Measured memory_bytes: 3516
#include <stdio.h>
#include <limits.h>

#define MAX 200000
#define INF INT_MAX
typedef long long ll;

void merge(int*, int, int, int);
void mergesort(int*, int, int);

ll ans;

int n, a[MAX];

int main(){
  int i;

  scanf("%d" ,&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d" ,a + i);
  }
  mergesort(a,0,n);
  printf("%lld\n" ,ans);

  return 0;
}

void merge(int a[], int left, int mid, int right){
  int n1 = mid - left, n2 = right - mid;
  int L[n1+1], R[n2+1], i, j, k;
 
  for(i = 0 ; i < n1 ; i++){
    L[i] = a[left + i];
  }
 
  for(i = 0 ; i < n2 ; i++){
    R[i] = a[mid + i];
  }
 
  L[n1] = R[n2] = INF;
 
  for(i = 0, j = 0, k = left ; k < right ; k++){
    if(i < n1 && (j == n2 || L[i] <= R[j])){
      a[k] = L[i++];
    }else{
      ans += (n1 + n2) / 2 - i;
      a[k] = R[j++];
    }
  }
}
 
void mergesort(int a[], int left, int right){
  int mid;
 
  if(left + 1 < right){
    mid = (left + right) / 2;
    mergesort(a, left, mid);
    mergesort(a, mid, right);
    merge(a, left, mid, right);
  }
}

Measured memory_bytes: 2156
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=(a);i<=(int)(n);++i)
#define lpd(i,a,n) for(int i=(a);i>=(int)(n);--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 200002;
int n,a[N],ans[N];
pii tree[2][4*N];
struct interval {
    int l,r;
    pii mn;
    bool operator < (interval x) const{
        return mn.f > x.mn.f;
    }
};

void build(int i, int l, int r){
    if(l == r){
        tree[l&1][i] = mp(a[l], l);
        return;
    }
    int mid = (l+r)/2;
    build(2*i, l, mid);
    build(2*i+1, mid+1, r);
    tree[0][i] = min(tree[0][2*i], tree[0][2*i+1]);
    tree[1][i] = min(tree[1][2*i], tree[1][2*i+1]);
}

pii query(int i, int start, int end, int l, int r, bool parity){
    if(l <= start && r >= end) return tree[parity][i];
    if(r < start || l > end) return mp(infi,infi);
    int mid = (start+end)/2;
    return min(query(2*i,start,mid,l,r,parity), query(2*i+1,mid+1,end,l,r,parity));
}

int main(){
    readi(n);
    lp(i,1,n) readi(a[i]);
    lp(i,0,1) lp(j,0,4*N-1) tree[i][j] = mp(infi,infi);
    build(1,1,n);

    priority_queue<interval> q;
    q.push({1,n,query(1,1,n, 1, n, 1)});
    lp(i,1,n){
        interval curr = q.top(); q.pop();
        ans[i] = curr.mn.f;
        pii nxt = query(1,1,n, curr.mn.s+1, curr.r, !(curr.mn.s & 1));
        ans[++i] = nxt.f;

        if(curr.mn.s > curr.l) q.push({curr.l, curr.mn.s-1, query(1,1,n, curr.l, curr.mn.s-1, curr.l&1)});
        if(nxt.s > curr.mn.s+1) q.push({curr.mn.s+1, nxt.s-1, query(1,1,n, curr.mn.s+1, nxt.s-1, (curr.mn.s+1)&1)});
        if(nxt.s < curr.r) q.push({nxt.s+1, curr.r, query(1,1,n, nxt.s+1, curr.r, (nxt.s+1)&1)});
    }

    lp(i,1,n) printf("%d ", ans[i]);
}

/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/


Measured memory_bytes: 16372
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        int[][] a = new int[n][n];
        int[][] dist = new int[n][n];
        boolean[][] via = new boolean[n][n];
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++) {
                a[i][j] = in.ni();
                dist[i][j] = a[i][j];
                via[i][j] = false;
            }
        }
        for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if(k==i||k==j) continue;
                    if(dist[i][j]>=dist[i][k]+dist[k][j]){
                        dist[i][j] = dist[i][k]+dist[k][j];
                        via[i][j] = true;
                    }
                }
            }
        }
        boolean flag = true;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(a[i][j]!=dist[i][j]) flag = false;
            }
        }
        long sum = 0;
        if(flag){
            for (int i = 0; i < n; i++) {
                for (int j = i; j < n; j++) {
                    if(!via[i][j]) sum += dist[i][j];
                }
            }
        }else sum = -1;
        out.println(sum);
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 33156
#include <bits/stdc++.h>
#define rin(i,a,b) for(register int i=(a);i<=(b);++i)
#define irin(i,a,b) for(register int i=(a);i>=(b);--i)
#define trav(i,a) for(register int i=head[a];i;i=e[i].nxt)
typedef long long LL;
using std::cin;
using std::cout;
using std::endl;

inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=100005;
const LL MOD=1e9+7;

int n,cnt[26];
char s[MAXN];

int main(){
	n=read();
	scanf("%s",s+1);
	rin(i,1,n){
		++cnt[s[i]-'a'];
	}
	LL ans=1;
	rin(i,0,25) ans=ans*(cnt[i]+1)%MOD;
	printf("%lld\n",(ans-1+MOD)%MOD);
	return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll x;
    cin >> x;
    cout << 1 - x << endl;
 
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

const int N = 2e5 + 5;

int n, K;
int a[N], Q[N];
boolean ismx[N], ismi[N];

int main() {
	scanf("%d%d", &n, &K);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
	}
	int st = 1, ed = 0;
	for (int i = n; i; i--) {
		while (st <= ed && Q[st] >= i + K)
			st++;
		while (st <= ed && a[Q[ed]] > a[i])
			ed--;
		Q[++ed] = i;
		ismi[i] = (st == ed);
	}
	st = 1, ed = 0;
	for (int i = 1; i <= n; i++) {
		while (st <= ed && Q[st] <= i - K)
			st++;
		while (st <= ed && a[Q[ed]] < a[i])
			ed--;
		Q[++ed] = i;
		ismx[i] = (st == ed);
	}
	int qaq = 0;
	for (int i = 1, j = 1; i <= n; i = j) {
		++j;
		while (a[j] > a[j - 1])
			j++;
		qaq += (j - i >= K);
	}
	int ans = n - K + 1 - max(qaq - 1, 0);
	for (int i = K + 1; i <= n; i++) {
		ans -= ismi[i - K] && ismx[i];
	}
	printf("%d\n", ans);
	return 0;
}


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

int ps[1010];

int main () {

    int N;
    cin >> N;

    for (int i = 2; i <= N; i++) {
        int x = i, p = 2;

        while (x > 1) {
            while (x % p == 0) {
                ps[p]++;
                x /= p;
            }
            p++;
        }
    }

    long long ans = 1LL;

    for (int i = 0; i <= N; i++) {
        ans = 1LL * (ans * (ps[i] + 1)) % 1000000007;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// finish date: 2018/07/20
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;

//最大公約数
ll gcd(ll a, ll b) {
    if (a < 0) a = -a;
    if (b < 0) b = -b;
    if (a < b) {
        swap(a, b);
    }
    ll r = 1; //0以外であれば何でも
    while (r != 0) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int main() {
    int T;
    cin >> T;
    rep(i, T) {
        ll A, B, C, D;
        cin >> A >> B >> C >> D;
        if (A < B || B > D || A % B > C) {
            cout << "No" << endl;
            continue;
        }
        if (C + 1 >= B || D % B == 0) {
            cout << "Yes" << endl;
            continue;
        }

        ll G = gcd(D % B, B);
        if (G == 1) {
            cout << "No" << endl;
            continue;
        } else {
            ll n = (C - A % B) / G;
            if (A % B + (n + 1) * G >= B) {
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
//                if (A > C) {
//                    A = A % B;
//                }
//            A %= G;
//            ll n = (ceil(((double) C + 1 - A) / G));
//            ll check = A + n * G;
//            if (check < B) {
//                cout << "No" << endl;
//            } else {
//                cout << "Yes" << endl;
//            }
        }
    }

    return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define str string
#define ld long double
#define vec vector
#define vll vec<ll>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()
#define kai "\n"
#define yuque priority_queue
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mie min_element
#define mae max_element
#define tos to_string
#define sep setprecision
#define lob lower_bound
#define upb upper_bound
#define nep next_permutation
#define MOD 1000000007999ll
#define MIN (1e-10)
#define equal(a,b) (abs((a)-(b))<MIN)
#define v2 ten
#define chokusen senbun
#define kakkei vec<ten>
using namespace std;
void solve();
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed;
	solve();
}
struct pea{
	ll f,s;
	bool operator<(const pea &p)const{
		return f!=p.f?f<p.f:s<p.s;
	};
};
struct tri{
	ll f,s,t;
	bool operator<(const tri &p)const{return f<p.f;};
};
class ten{
public:
	ld x,y;
	ten operator+(ten p){return{x+p.x,y+p.y};}
	ten operator-(ten p){return{x-p.x,y-p.y};}
	ten operator*(ld k){return{k*x,k*y};}
	ten operator/(ld k){return{x/k,y/k};}
	ld abs(){return sqrt(abs2());}
	ld abs2(){return x*x+y*y;};
	bool operator<(const ten &p)const{return x!=p.x?x<p.x:y<p.y;};
	bool operator==(const ten &p)const{
		return (-MIN<x-p.x)&&(x-p.x<MIN)&&(-MIN<y-p.y)&&(y-p.y<MIN);
	};
	ld naiseki(v2 b){return x*b.x+y*b.y;}
	ld gaiseki(v2 b){return x*b.y-y*b.x;}
};
struct senbun{ten p1,p2;};
struct en{ten o;ld r;};
bool floyd(vec<vll> &d){
	ll n=d.size();
	rep(i,0,n)d[i][i]=0;
	rep(k,0,n){
		rep(i,0,n){
			if(d[i][k]!=MOD){
				rep(j,0,n){
					if(d[k][j]!=MOD){
						d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
					}
				}
			}
		}
	}
	bool b=true;
	rep(i,0,n)if(d[i][i]<0)b=false;
	return b;
}
void solve(){
	ll v,e;cin>>v>>e;
	vec<vll> d(v,vll(v,MOD));
	rep(i,0,e){
		ll s,t,w;
		cin>>s>>t>>w;
		d[s][t]=w;
	}
	if(!floyd(d))cout<<"NEGATIVE CYCLE"<<kai;
	else{
  	rep(i,0,v){
	  	if(d[i][0]!=MOD)cout<<d[i][0];
  		else cout<<"INF";
	  	rep(j,1,v){
  			if(d[i][j]!=MOD)cout<<' '<<d[i][j];
  			else cout<<" INF";
  		}
  		cout<<kai;
	  }
	}
}


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

int main(){
	int N, K;
	cin >> N >> K;
	int height[N];
	for(int i = 0; i < N; i++)
		cin >> height[i];
	sort(height, height+N);
	int dh[N-K+1];
	for(int i = K-1; i < N; i++)
		dh[i-K+1] = height[i] - height[i-K+1];
	int minh = dh[0];
	for(int i = 0; i < N-K+1; i++)
		minh = min(minh, dh[i]);
	cout << minh << endl;
	return 0;
}

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

int main(){
    int N, ans;
    cin >> N;
    vector<int> s(N);
    for(int i = 0; i < N; ++i) cin >> s[i];
    sort(s.begin(), s.end());
    int res = 0;
    for(int i = 0; i < N; ++i){
        res += s[i];
    }
    ans = 0;
    if(res % 10 != 0) cout << res << endl;
    else{
        for(int i = 0; i < N; ++i){
            if(s[i] % 10 != 0){
                ans = res - s[i];
                break;
            }
        }
        if(ans % 10 == 0) cout << "0" << endl;
        else cout << ans << endl;

    }
}

Measured memory_bytes: 256